Actually receive data.

This commit is contained in:
Michael Jumper 2013-08-09 16:43:30 -07:00
parent 8bbd28d9c9
commit 83a575d7b9

View File

@ -41,19 +41,88 @@
#include "client.h" #include "client.h"
static void __stream_read_callback(pa_stream* stream, size_t length,
void* data) {
guac_client* client = (guac_client*) data;
const void* buffer;
/* Read data */
pa_stream_peek(stream, &buffer, &length);
guac_client_log_info(client, "STUB: Received %i bytes", length);
/* Advance buffer */
pa_stream_drop(stream);
}
static void __stream_state_callback(pa_stream* stream, void* data) {
guac_client* client = (guac_client*) data;
switch (pa_stream_get_state(stream)) {
case PA_STREAM_UNCONNECTED:
guac_client_log_info(client,
"PulseAudio stream currently unconnected");
break;
case PA_STREAM_CREATING:
guac_client_log_info(client, "PulseAudio stream being created...");
break;
case PA_STREAM_READY:
guac_client_log_info(client, "PulseAudio stream now ready");
break;
case PA_STREAM_FAILED:
guac_client_log_info(client, "PulseAudio stream connection failed");
break;
case PA_STREAM_TERMINATED:
guac_client_log_info(client, "PulseAudio stream terminated");
break;
default:
guac_client_log_info(client,
"Unknown PulseAudio stream state: 0x%x",
pa_stream_get_state(stream));
}
}
static void __context_get_sink_info_callback(pa_context* context, static void __context_get_sink_info_callback(pa_context* context,
const pa_sink_info* info, int is_last, void* data) { const pa_sink_info* info, int is_last, void* data) {
guac_client* client = (guac_client*) data; guac_client* client = (guac_client*) data;
pa_stream* stream;
pa_sample_spec spec;
/* If information retrieval failed, stop */ /* Stop if end of list reached */
if (is_last < 0) { if (is_last)
guac_client_log_error(client, "Unable to retrieve sink information");
return; return;
}
guac_client_log_info(client, "Starting streaming from \"%s\"",
info->description);
/* Set format */
spec.format = PA_SAMPLE_S16LE;
spec.rate = info->sample_spec.rate;
spec.channels = info->sample_spec.channels;
/* Create stream */
stream = pa_stream_new(context, "Guacamole Audio", &spec,
&(info->channel_map));
/* Set stream callbacks */
pa_stream_set_state_callback(stream, __stream_state_callback, client);
pa_stream_set_read_callback(stream, __stream_read_callback, client);
/* Start stream */ /* Start stream */
guac_client_log_info(client, "Starting stream (STUB)"); pa_stream_connect_record(stream, info->monitor_source_name, NULL,
0 /* FIXME: PA_STREAM_DONT_INHIBIT_AUTO_SUSPEND */);
} }
@ -139,7 +208,7 @@ void guac_pa_start_stream(guac_client* client) {
/* Create context */ /* Create context */
context = pa_context_new( context = pa_context_new(
pa_threaded_mainloop_get_api(client_data->pa_mainloop), pa_threaded_mainloop_get_api(client_data->pa_mainloop),
"Guacamole"); "Guacamole Audio");
/* Set up context */ /* Set up context */
pa_context_set_state_callback(context, __context_state_callback, client); pa_context_set_state_callback(context, __context_state_callback, client);