summaryrefslogtreecommitdiff
path: root/gst/gstnicesrc.c
diff options
context:
space:
mode:
authorYouness Alaoui <youness.alaoui@collabora.co.uk>2011-06-23 19:05:31 -0400
committerYouness Alaoui <youness.alaoui@collabora.co.uk>2011-06-23 19:05:31 -0400
commitdc9ea0899e400403d010d9d49fc2dce624b60e7f (patch)
treef102aa7f916b8b154b8755a740161b452d0f46f8 /gst/gstnicesrc.c
parent67de01c9a1e8642bc0a327d9311a48e542114a1b (diff)
downloadlibnice-dc9ea0899e400403d010d9d49fc2dce624b60e7f.tar.gz
Use a Queue in gstnicesrc to avoid multiple read_callbacks overwriting the out buffer
Diffstat (limited to 'gst/gstnicesrc.c')
-rw-r--r--gst/gstnicesrc.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/gst/gstnicesrc.c b/gst/gstnicesrc.c
index b86f096..e8c4d0a 100644
--- a/gst/gstnicesrc.c
+++ b/gst/gstnicesrc.c
@@ -184,6 +184,7 @@ gst_nice_src_init (GstNiceSrc *src, GstNiceSrcClass *g_class)
src->mainloop = g_main_loop_new (src->mainctx, FALSE);
src->unlocked = FALSE;
src->idle_source = NULL;
+ src->outbufs = g_queue_new ();
}
static void
@@ -196,14 +197,16 @@ gst_nice_src_read_callback (NiceAgent *agent,
{
GstBaseSrc *basesrc = GST_BASE_SRC (data);
GstNiceSrc *nicesrc = GST_NICE_SRC (basesrc);
+ GstBuffer *buffer = NULL;
GST_LOG_OBJECT (agent, "Got buffer, getting out of the main loop");
nicesrc->flow_ret = gst_pad_alloc_buffer (basesrc->srcpad, nicesrc->offset,
- len, GST_PAD_CAPS (basesrc->srcpad), &nicesrc->outbuf);
+ len, GST_PAD_CAPS (basesrc->srcpad), &buffer);
if (nicesrc->flow_ret == GST_FLOW_OK) {
- memcpy (nicesrc->outbuf->data, buf, len);
- nicesrc->outbuf->size = len;
+ memcpy (buffer->data, buf, len);
+ buffer->size = len;
+ g_queue_push_tail (nicesrc->outbufs, buffer);
}
g_main_loop_quit (nicesrc->mainloop);
@@ -277,7 +280,6 @@ gst_nice_src_create (
GST_LOG_OBJECT (nicesrc, "create called");
- nicesrc->outbuf = NULL;
nicesrc->offset = offset;
GST_OBJECT_LOCK (basesrc);
@@ -287,12 +289,12 @@ gst_nice_src_create (
}
GST_OBJECT_UNLOCK (basesrc);
- g_main_loop_run (nicesrc->mainloop);
+ if (g_queue_is_empty (nicesrc->outbufs))
+ g_main_loop_run (nicesrc->mainloop);
- if (nicesrc->outbuf) {
+ *buffer = g_queue_pop_head (nicesrc->outbufs);
+ if (*buffer != NULL) {
GST_LOG_OBJECT (nicesrc, "Got buffer, pushing");
-
- *buffer = nicesrc->outbuf;
return nicesrc->flow_ret;
} else {
GST_LOG_OBJECT (nicesrc, "Got interrupting, returning wrong-state");
@@ -318,6 +320,10 @@ gst_nice_src_dispose (GObject *object)
g_main_context_unref (src->mainctx);
src->mainctx = NULL;
+ if (src->outbufs)
+ g_queue_free (src->outbufs);
+ src->outbufs = NULL;
+
GST_CALL_PARENT (G_OBJECT_CLASS, dispose, (object));
}