Switch to normal PulseAudio API.

This commit is contained in:
Michael Jumper 2013-08-09 15:11:31 -07:00
parent 6cc6808eb7
commit 88f62df0f3
5 changed files with 33 additions and 88 deletions

View File

@ -37,7 +37,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <pthread.h>
#include <rfb/rfbclient.h> #include <rfb/rfbclient.h>
@ -107,10 +106,6 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
vnc_guac_client_data* guac_client_data; vnc_guac_client_data* guac_client_data;
#ifdef ENABLE_PULSE
pthread_t pa_read_thread;
#endif
int read_only; int read_only;
/* Set up libvncclient logging */ /* Set up libvncclient logging */
@ -180,16 +175,11 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
"Audio will be encoded as %s", "Audio will be encoded as %s",
guac_client_data->audio->encoder->mimetype); guac_client_data->audio->encoder->mimetype);
/* Create a thread to read audio data */ /* Require threadsafe sockets if audio enabled */
if (pthread_create(&pa_read_thread, NULL, guac_pa_read_audio, guac_socket_require_threadsafe(client->socket);
(void*) client)) {
guac_protocol_send_error(client->socket,
"Error initializing PulseAudio read thread");
guac_socket_flush(client->socket);
return 1;
}
guac_client_data->audio_read_thread = &pa_read_thread; /* Start audio stream */
guac_pa_start_stream(client);
} }
@ -198,9 +188,6 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
guac_client_log_info(client, guac_client_log_info(client,
"No available audio encoding. Sound disabled."); "No available audio encoding. Sound disabled.");
/* Require threadsafe sockets if audio enabled */
guac_socket_require_threadsafe(client->socket);
} /* end if audio enabled */ } /* end if audio enabled */
#endif #endif

View File

@ -42,6 +42,8 @@
#include <guacamole/audio.h> #include <guacamole/audio.h>
#include <rfb/rfbclient.h> #include <rfb/rfbclient.h>
#include <pulse/pulseaudio.h>
extern char* __GUAC_CLIENT; extern char* __GUAC_CLIENT;
typedef struct vnc_guac_client_data { typedef struct vnc_guac_client_data {
@ -67,9 +69,9 @@ typedef struct vnc_guac_client_data {
guac_audio_stream* audio; guac_audio_stream* audio;
/** /**
* PulseAudio read thread. * PulseAudio event loop.
*/ */
pthread_t* audio_read_thread; pa_threaded_mainloop* pa_mainloop;
} vnc_guac_client_data; } vnc_guac_client_data;

View File

@ -39,7 +39,6 @@
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <iconv.h> #include <iconv.h>
#include <pthread.h>
#include <rfb/rfbclient.h> #include <rfb/rfbclient.h>
@ -130,13 +129,9 @@ int vnc_guac_client_free_handler(guac_client* client) {
rfbClient* rfb_client = guac_client_data->rfb_client; rfbClient* rfb_client = guac_client_data->rfb_client;
#ifdef ENABLE_PULSE #ifdef ENABLE_PULSE
if (guac_client_data->audio_enabled) { /* If audio enabled, stop streaming */
if (guac_client_data->audio_enabled)
/* Wait for audio read thread to join */ guac_pa_stop_stream(client);
if (guac_client_data->audio_read_thread)
pthread_join(*(guac_client_data->audio_read_thread), NULL);
}
#endif #endif
/* Free encodings string, if used */ /* Free encodings string, if used */

View File

@ -37,64 +37,19 @@
#include <guacamole/client.h> #include <guacamole/client.h>
#include <pulse/simple.h> #include <pulse/pulseaudio.h>
#include <pulse/error.h>
void* guac_pa_read_audio(void* data) { void guac_pa_start_stream(guac_client* client) {
pa_sample_spec spec; /* STUB */
pa_simple* stream; guac_client_log_info(client, "Starting audio stream");
int error;
/* Get client */
guac_client* client = (guac_client*) data;
/* Init sample spec */
spec.format = PA_SAMPLE_S16LE;
spec.rate = 44100;
spec.channels = 2;
/* Create new stream */
stream = pa_simple_new(NULL, /* Name of server */
"Guacamole", /* Name of client */
PA_STREAM_RECORD, NULL, /* Direction and device */
"Audio", /* Name of stream */
&spec, NULL, NULL, /* Stream options */
&error);
/* Fail on error */
if (stream == NULL) {
guac_client_log_error(client, "Unable to connect to PulseAudio: %s",
pa_strerror(error));
return NULL;
}
/* Start streaming */
guac_client_log_info(client, "Streaming audio from PulseAudio");
while (client->state == GUAC_CLIENT_RUNNING) {
uint8_t buffer[1024];
guac_client_log_info(client, "Reading...");
/* Read packet of audio data */
if (pa_simple_read(stream, buffer, sizeof(buffer), &error) < 0) {
guac_client_log_error(client, "Unable to read from PulseAudio: %s",
pa_strerror(error));
return NULL;
}
/* STUB: Write data */
guac_client_log_info(client, "Would write %i", sizeof(buffer));
} }
/* Close stream */ void guac_pa_stop_stream(guac_client* client) {
guac_client_log_info(client, "Streaming from PulseAudio finished");
pa_simple_free(stream);
return NULL; /* STUB */
guac_client_log_info(client, "Audio stream finished");
} }

View File

@ -39,12 +39,18 @@
#define __GUAC_VNC_PULSE_H #define __GUAC_VNC_PULSE_H
/** /**
* Read thread which transfers PCM data read from PulseAudio to the audio * Starts streaming audio from PulseAudio to the given Guacamole client.
* encoder in use.
* *
* @param data Pointer to the active guac_client. * @param client The client to stream data to.
*/ */
void* guac_pa_read_audio(void* data); void guac_pa_start_stream(guac_client* client);
/**
* Stops streaming audio from PulseAudio to the given Guacamole client.
*
* @param client The client to stream data to.
*/
void guac_pa_stop_stream(guac_client* client);
#endif #endif