Actually connect and read.

This commit is contained in:
Michael Jumper 2013-08-09 13:03:01 -07:00
parent 832e4d3d16
commit 6cc6808eb7

View File

@ -37,14 +37,63 @@
#include <guacamole/client.h> #include <guacamole/client.h>
#include <pulse/simple.h>
#include <pulse/error.h>
void* guac_pa_read_audio(void* data) { void* guac_pa_read_audio(void* data) {
pa_sample_spec spec;
pa_simple* stream;
int error;
/* Get client */ /* Get client */
guac_client* client = (guac_client*) data; 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"); 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; return NULL;
} }