Add stub PulseAudio handling code, replace old usage with new read thread.

This commit is contained in:
Michael Jumper 2013-08-09 11:58:29 -07:00
parent daa7823aed
commit 832e4d3d16
6 changed files with 110 additions and 27 deletions

View File

@ -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@

View File

@ -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 */

View File

@ -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

View File

@ -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

51
src/protocols/vnc/pulse.c Normal file
View File

@ -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 <guacamole/client.h>
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;
}

50
src/protocols/vnc/pulse.h Normal file
View File

@ -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