From 6cc6808eb7add91c680120f9eadf0aa45877cb8c Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 9 Aug 2013 13:03:01 -0700 Subject: [PATCH] Actually connect and read. --- src/protocols/vnc/pulse.c | 51 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/src/protocols/vnc/pulse.c b/src/protocols/vnc/pulse.c index 657c023b..3c502685 100644 --- a/src/protocols/vnc/pulse.c +++ b/src/protocols/vnc/pulse.c @@ -37,14 +37,63 @@ #include +#include +#include + void* guac_pa_read_audio(void* data) { + pa_sample_spec spec; + pa_simple* stream; + int error; + /* Get client */ guac_client* client = (guac_client*) data; - /* STUB */ + /* 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 */ + guac_client_log_info(client, "Streaming from PulseAudio finished"); + pa_simple_free(stream); + return NULL; }