summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2013-11-22 09:25:53 +0100
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2013-11-22 14:40:08 +0100
commitb83262a1c025d0775d0f73c87341d71d7f1c3996 (patch)
tree83ff5ad98c39b25f718c7c7bb96d0a9470612208 /src
parenta60894a1f1c1fba4d7244a9b2a52f322e3ed9e12 (diff)
downloadcmumble-b83262a1c025d0775d0f73c87341d71d7f1c3996.tar.gz
cmumble-b83262a1c025d0775d0f73c87341d71d7f1c3996.tar.bz2
cmumble-b83262a1c025d0775d0f73c87341d71d7f1c3996.zip
audio: Pull and send the recorded buffer from the main thread
Tests showed this lets the appsink pull more buffers, since the streaming thread is not blocked due to network write.
Diffstat (limited to 'src')
-rw-r--r--src/audio.c25
-rw-r--r--src/cmumble.c5
-rw-r--r--src/cmumble.h1
3 files changed, 30 insertions, 1 deletions
diff --git a/src/audio.c b/src/audio.c
index d77434b..a373871 100644
--- a/src/audio.c
+++ b/src/audio.c
@@ -62,6 +62,29 @@ pull_buffer(GstAppSink *sink, gpointer user_data)
return GST_FLOW_OK;
}
+static gboolean
+idle(gpointer user_data)
+{
+ struct cmumble *cm = user_data;
+ GstAppSink *sink;
+
+ while ((sink = g_async_queue_try_pop(cm->async_queue)) != NULL)
+ pull_buffer(sink, cm);
+
+ return FALSE;
+}
+
+static GstFlowReturn
+new_buffer(GstAppSink *sink, gpointer user_data)
+{
+ struct cmumble *cm = user_data;
+
+ g_async_queue_push(cm->async_queue, sink);
+ g_idle_add(idle, cm);
+
+ return GST_FLOW_OK;
+}
+
static int
setup_recording_gst_pipeline(struct cmumble *cm)
{
@@ -88,7 +111,7 @@ setup_recording_gst_pipeline(struct cmumble *cm)
gst_app_sink_set_emit_signals(cm->audio.sink, TRUE);
gst_app_sink_set_drop(cm->audio.sink, FALSE);;
- g_signal_connect(sink, "new-buffer", G_CALLBACK(pull_buffer), cm);
+ g_signal_connect(sink, "new-buffer", G_CALLBACK(new_buffer), cm);
caps = gst_caps_new_simple("audio/x-celt",
"rate", G_TYPE_INT, SAMPLERATE,
diff --git a/src/cmumble.c b/src/cmumble.c
index 247d661..0b3a6f5 100644
--- a/src/cmumble.c
+++ b/src/cmumble.c
@@ -358,6 +358,10 @@ int main(int argc, char **argv)
cm.loop = g_main_loop_new(NULL, FALSE);
cm.callbacks = (const callback_t *) &callbacks;
+ cm.async_queue = g_async_queue_new_full(g_free);
+ if (cm.async_queue == NULL)
+ return 1;
+
cmumble_commands_init(&cm);
if (cmumble_connection_init(&cm, host, port) < 0)
return 1;
@@ -375,6 +379,7 @@ int main(int argc, char **argv)
cmumble_io_fini(&cm);
cmumble_audio_fini(&cm);
cmumble_connection_fini(&cm);
+ g_async_queue_unref(cm.async_queue);
return 0;
}
diff --git a/src/cmumble.h b/src/cmumble.h
index 847b384..2dac580 100644
--- a/src/cmumble.h
+++ b/src/cmumble.h
@@ -22,6 +22,7 @@ struct cmumble {
const struct cmumble_command *commands;
GMainLoop *loop;
+ GAsyncQueue *async_queue;
uint32_t session;
gboolean authenticated;