From 832e4d3d16cc2ff13bee2d803674cbcf1d170da7 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 9 Aug 2013 11:58:29 -0700 Subject: [PATCH] Add stub PulseAudio handling code, replace old usage with new read thread. --- src/protocols/vnc/Makefile.am | 4 +-- src/protocols/vnc/client.c | 18 +++-------- src/protocols/vnc/client.h | 7 +---- src/protocols/vnc/guac_handlers.c | 7 ++--- src/protocols/vnc/pulse.c | 51 +++++++++++++++++++++++++++++++ src/protocols/vnc/pulse.h | 50 ++++++++++++++++++++++++++++++ 6 files changed, 110 insertions(+), 27 deletions(-) create mode 100644 src/protocols/vnc/pulse.c create mode 100644 src/protocols/vnc/pulse.h diff --git a/src/protocols/vnc/Makefile.am b/src/protocols/vnc/Makefile.am index 42441e80..ef792c7a 100644 --- a/src/protocols/vnc/Makefile.am +++ b/src/protocols/vnc/Makefile.am @@ -55,8 +55,8 @@ noinst_HEADERS = \ # Optional PulseAudio support if ENABLE_PULSE -libguac_client_vnc_la_SOURCES += pa_handlers.c -noinst_HEADERS += pa_handlers.h +libguac_client_vnc_la_SOURCES += pulse.c +noinst_HEADERS += pulse.h endif libguac_client_vnc_la_LDFLAGS = -version-info 0:0:0 @VNC_LIBS@ @CAIRO_LIBS@ @PULSE_LIBS@ diff --git a/src/protocols/vnc/client.c b/src/protocols/vnc/client.c index 5e7fcb89..99a2bbea 100644 --- a/src/protocols/vnc/client.c +++ b/src/protocols/vnc/client.c @@ -51,7 +51,7 @@ #include "guac_handlers.h" #ifdef ENABLE_PULSE -#include "pa_handlers.h" +#include "pulse.h" #endif /* Client plugin arguments */ @@ -108,7 +108,7 @@ int guac_client_init(guac_client* client, int argc, char** argv) { vnc_guac_client_data* guac_client_data; #ifdef ENABLE_PULSE - pthread_t pa_read_thread, pa_send_thread; + pthread_t pa_read_thread; #endif int read_only; @@ -182,25 +182,15 @@ int guac_client_init(guac_client* client, int argc, char** argv) { /* Create a thread to read audio data */ if (pthread_create(&pa_read_thread, NULL, guac_pa_read_audio, - (void*) guac_client_data)) { + (void*) client)) { guac_protocol_send_error(client->socket, - "Error initializing PulseAudio thread"); + "Error initializing PulseAudio read thread"); guac_socket_flush(client->socket); return 1; } guac_client_data->audio_read_thread = &pa_read_thread; - /* Create a thread to send audio data */ - if (pthread_create(&pa_send_thread, NULL, guac_pa_send_audio, - (void*) guac_client_data)) { - guac_protocol_send_error(client->socket, - "Error initializing PulseAudio thread"); - guac_socket_flush(client->socket); - return 1; - } - - guac_client_data->audio_send_thread = &pa_send_thread; } /* Otherwise, audio loading failed */ diff --git a/src/protocols/vnc/client.h b/src/protocols/vnc/client.h index d787be28..194eb0ec 100644 --- a/src/protocols/vnc/client.h +++ b/src/protocols/vnc/client.h @@ -67,15 +67,10 @@ typedef struct vnc_guac_client_data { guac_audio_stream* audio; /** - * Handle to the audio read thread. + * PulseAudio read thread. */ pthread_t* audio_read_thread; - /** - * Handle to the audio send thread. - */ - pthread_t* audio_send_thread; - } vnc_guac_client_data; #endif diff --git a/src/protocols/vnc/guac_handlers.c b/src/protocols/vnc/guac_handlers.c index a859ae8f..a639cce2 100644 --- a/src/protocols/vnc/guac_handlers.c +++ b/src/protocols/vnc/guac_handlers.c @@ -49,7 +49,7 @@ #include "convert.h" #ifdef ENABLE_PULSE -#include "pa_handlers.h" +#include "pulse.h" #endif int vnc_guac_client_handle_messages(guac_client* client) { @@ -132,13 +132,10 @@ int vnc_guac_client_free_handler(guac_client* client) { #ifdef ENABLE_PULSE if (guac_client_data->audio_enabled) { - /* Wait for audio read and send threads to join */ + /* Wait for audio read thread to join */ if (guac_client_data->audio_read_thread) pthread_join(*(guac_client_data->audio_read_thread), NULL); - if (guac_client_data->audio_send_thread) - pthread_join(*(guac_client_data->audio_send_thread), NULL); - } #endif diff --git a/src/protocols/vnc/pulse.c b/src/protocols/vnc/pulse.c new file mode 100644 index 00000000..657c023b --- /dev/null +++ b/src/protocols/vnc/pulse.c @@ -0,0 +1,51 @@ + +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is libguac-client-vnc. + * + * The Initial Developer of the Original Code is + * Michael Jumper. + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include + +void* guac_pa_read_audio(void* data) { + + /* Get client */ + guac_client* client = (guac_client*) data; + + /* STUB */ + guac_client_log_info(client, "Streaming audio from PulseAudio"); + + return NULL; + +} + diff --git a/src/protocols/vnc/pulse.h b/src/protocols/vnc/pulse.h new file mode 100644 index 00000000..5ccd92b4 --- /dev/null +++ b/src/protocols/vnc/pulse.h @@ -0,0 +1,50 @@ + +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is libguac-client-vnc. + * + * The Initial Developer of the Original Code is + * Michael Jumper. + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef __GUAC_VNC_PULSE_H +#define __GUAC_VNC_PULSE_H + +/** + * Read thread which transfers PCM data read from PulseAudio to the audio + * encoder in use. + * + * @param data Pointer to the active guac_client. + */ +void* guac_pa_read_audio(void* data); + +#endif +