Commit dc9ea089 authored by Youness Alaoui's avatar Youness Alaoui

Use a Queue in gstnicesrc to avoid multiple read_callbacks overwriting the out buffer

parent 67de01c9
...@@ -184,6 +184,7 @@ gst_nice_src_init (GstNiceSrc *src, GstNiceSrcClass *g_class) ...@@ -184,6 +184,7 @@ gst_nice_src_init (GstNiceSrc *src, GstNiceSrcClass *g_class)
src->mainloop = g_main_loop_new (src->mainctx, FALSE); src->mainloop = g_main_loop_new (src->mainctx, FALSE);
src->unlocked = FALSE; src->unlocked = FALSE;
src->idle_source = NULL; src->idle_source = NULL;
src->outbufs = g_queue_new ();
} }
static void static void
...@@ -196,14 +197,16 @@ gst_nice_src_read_callback (NiceAgent *agent, ...@@ -196,14 +197,16 @@ gst_nice_src_read_callback (NiceAgent *agent,
{ {
GstBaseSrc *basesrc = GST_BASE_SRC (data); GstBaseSrc *basesrc = GST_BASE_SRC (data);
GstNiceSrc *nicesrc = GST_NICE_SRC (basesrc); GstNiceSrc *nicesrc = GST_NICE_SRC (basesrc);
GstBuffer *buffer = NULL;
GST_LOG_OBJECT (agent, "Got buffer, getting out of the main loop"); GST_LOG_OBJECT (agent, "Got buffer, getting out of the main loop");
nicesrc->flow_ret = gst_pad_alloc_buffer (basesrc->srcpad, nicesrc->offset, 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) { if (nicesrc->flow_ret == GST_FLOW_OK) {
memcpy (nicesrc->outbuf->data, buf, len); memcpy (buffer->data, buf, len);
nicesrc->outbuf->size = len; buffer->size = len;
g_queue_push_tail (nicesrc->outbufs, buffer);
} }
g_main_loop_quit (nicesrc->mainloop); g_main_loop_quit (nicesrc->mainloop);
...@@ -277,7 +280,6 @@ gst_nice_src_create ( ...@@ -277,7 +280,6 @@ gst_nice_src_create (
GST_LOG_OBJECT (nicesrc, "create called"); GST_LOG_OBJECT (nicesrc, "create called");
nicesrc->outbuf = NULL;
nicesrc->offset = offset; nicesrc->offset = offset;
GST_OBJECT_LOCK (basesrc); GST_OBJECT_LOCK (basesrc);
...@@ -287,12 +289,12 @@ gst_nice_src_create ( ...@@ -287,12 +289,12 @@ gst_nice_src_create (
} }
GST_OBJECT_UNLOCK (basesrc); GST_OBJECT_UNLOCK (basesrc);
if (g_queue_is_empty (nicesrc->outbufs))
g_main_loop_run (nicesrc->mainloop); 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"); GST_LOG_OBJECT (nicesrc, "Got buffer, pushing");
*buffer = nicesrc->outbuf;
return nicesrc->flow_ret; return nicesrc->flow_ret;
} else { } else {
GST_LOG_OBJECT (nicesrc, "Got interrupting, returning wrong-state"); GST_LOG_OBJECT (nicesrc, "Got interrupting, returning wrong-state");
...@@ -318,6 +320,10 @@ gst_nice_src_dispose (GObject *object) ...@@ -318,6 +320,10 @@ gst_nice_src_dispose (GObject *object)
g_main_context_unref (src->mainctx); g_main_context_unref (src->mainctx);
src->mainctx = NULL; src->mainctx = NULL;
if (src->outbufs)
g_queue_free (src->outbufs);
src->outbufs = NULL;
GST_CALL_PARENT (G_OBJECT_CLASS, dispose, (object)); GST_CALL_PARENT (G_OBJECT_CLASS, dispose, (object));
} }
......
...@@ -69,7 +69,7 @@ struct _GstNiceSrc ...@@ -69,7 +69,7 @@ struct _GstNiceSrc
GMainLoop *mainloop; GMainLoop *mainloop;
guint64 offset; guint64 offset;
GstFlowReturn flow_ret; GstFlowReturn flow_ret;
GstBuffer *outbuf; GQueue *outbufs;
gboolean unlocked; gboolean unlocked;
GSource *idle_source; GSource *idle_source;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment