From 16aa82d6e7f18ffef6087186d88ee97773b6e703 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 15 Dec 2008 12:02:26 +0000 Subject: [PATCH] examples/app/: Fix example to unref after emiting the push-buffer action. Original commit message from CVS: * examples/app/appsrc-ra.c: (feed_data): * examples/app/appsrc-seekable.c: (feed_data): * examples/app/appsrc-stream.c: (read_data): * examples/app/appsrc-stream2.c: (feed_data): Fix example to unref after emiting the push-buffer action. * gst-libs/gst/app/gstappsrc.c: (gst_app_src_class_init), (gst_app_src_push_buffer_full), (gst_app_src_push_buffer), (gst_app_src_push_buffer_action): Don't take the ref on the buffer in push-buffer action because it's too awkward for bindings. Fixes #564482. --- ChangeLog | 14 ++++++++ common | 2 +- examples/app/appsrc-ra.c | 1 + examples/app/appsrc-seekable.c | 1 + examples/app/appsrc-stream.c | 1 + examples/app/appsrc-stream2.c | 1 + gst-libs/gst/app/gstappsrc.c | 58 +++++++++++++++++++++++----------- 7 files changed, 59 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5adf759b42..11491f15e4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2008-12-15 Wim Taymans + + * examples/app/appsrc-ra.c: (feed_data): + * examples/app/appsrc-seekable.c: (feed_data): + * examples/app/appsrc-stream.c: (read_data): + * examples/app/appsrc-stream2.c: (feed_data): + Fix example to unref after emiting the push-buffer action. + + * gst-libs/gst/app/gstappsrc.c: (gst_app_src_class_init), + (gst_app_src_push_buffer_full), (gst_app_src_push_buffer), + (gst_app_src_push_buffer_action): + Don't take the ref on the buffer in push-buffer action because it's too + awkward for bindings. Fixes #564482. + 2008-12-13 Edward Hervey * m4/Makefile.am: diff --git a/common b/common index 24efb72e9a..2c4d28a75c 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit 24efb72e9a01364c6ea90b70ef2bb7049af980b4 +Subproject commit 2c4d28a75c26e572b94a967901254caff83d85c4 diff --git a/examples/app/appsrc-ra.c b/examples/app/appsrc-ra.c index 1611616edd..aa4962fe54 100644 --- a/examples/app/appsrc-ra.c +++ b/examples/app/appsrc-ra.c @@ -92,6 +92,7 @@ feed_data (GstElement * appsrc, guint size, App * app) GST_DEBUG ("feed buffer %p, offset %" G_GUINT64_FORMAT "-%u", buffer, app->offset, size); g_signal_emit_by_name (app->appsrc, "push-buffer", buffer, &ret); + gst_buffer_unref (buffer); app->offset += size; diff --git a/examples/app/appsrc-seekable.c b/examples/app/appsrc-seekable.c index e0325888cc..7137d13e1d 100644 --- a/examples/app/appsrc-seekable.c +++ b/examples/app/appsrc-seekable.c @@ -95,6 +95,7 @@ feed_data (GstElement * appsrc, guint size, App * app) GST_DEBUG ("feed buffer %p, offset %" G_GUINT64_FORMAT "-%u", buffer, app->offset, len); g_signal_emit_by_name (app->appsrc, "push-buffer", buffer, &ret); + gst_buffer_unref (buffer); app->offset += len; diff --git a/examples/app/appsrc-stream.c b/examples/app/appsrc-stream.c index d5edceb874..870d707c7f 100644 --- a/examples/app/appsrc-stream.c +++ b/examples/app/appsrc-stream.c @@ -102,6 +102,7 @@ read_data (App * app) GST_DEBUG ("feed buffer %p, offset %" G_GUINT64_FORMAT "-%u", buffer, app->offset, len); g_signal_emit_by_name (app->appsrc, "push-buffer", buffer, &ret); + gst_buffer_unref (buffer); if (ret != GST_FLOW_OK) { /* some error, stop sending data */ return FALSE; diff --git a/examples/app/appsrc-stream2.c b/examples/app/appsrc-stream2.c index 8f691a2e9f..866b0504cd 100644 --- a/examples/app/appsrc-stream2.c +++ b/examples/app/appsrc-stream2.c @@ -102,6 +102,7 @@ feed_data (GstElement * appsrc, guint size, App * app) GST_DEBUG ("feed buffer %p, offset %" G_GUINT64_FORMAT "-%u", buffer, app->offset, len); g_signal_emit_by_name (app->appsrc, "push-buffer", buffer, &ret); + gst_buffer_unref (buffer); app->offset += len; diff --git a/gst-libs/gst/app/gstappsrc.c b/gst-libs/gst/app/gstappsrc.c index 3bec52f2ca..27848080b2 100644 --- a/gst-libs/gst/app/gstappsrc.c +++ b/gst-libs/gst/app/gstappsrc.c @@ -127,6 +127,8 @@ static gboolean gst_app_src_do_seek (GstBaseSrc * src, GstSegment * segment); static gboolean gst_app_src_is_seekable (GstBaseSrc * src); static gboolean gst_app_src_check_get_range (GstBaseSrc * src); static gboolean gst_app_src_do_get_size (GstBaseSrc * src, guint64 * size); +static GstFlowReturn gst_app_src_push_buffer_action (GstAppSrc * appsrc, + GstBuffer * buffer); static guint gst_app_src_signals[LAST_SIGNAL] = { 0 }; @@ -302,7 +304,8 @@ gst_app_src_class_init (GstAppSrcClass * klass) * @buffer: a buffer to push * * Adds a buffer to the queue of buffers that the appsrc element will - * push to its source pad. This function will take ownership of @buffer. + * push to its source pad. This function does not take ownership of the + * buffer so the buffer needs to be unreffed after calling this function. * * When the block property is TRUE, this function can block until free space * becomes available in the queue. @@ -335,7 +338,7 @@ gst_app_src_class_init (GstAppSrcClass * klass) basesrc_class->check_get_range = gst_app_src_check_get_range; basesrc_class->get_size = gst_app_src_do_get_size; - klass->push_buffer = gst_app_src_push_buffer; + klass->push_buffer = gst_app_src_push_buffer_action; klass->end_of_stream = gst_app_src_end_of_stream; } @@ -916,20 +919,9 @@ gst_app_src_get_max_bytes (GstAppSrc * appsrc) return result; } -/** - * gst_app_src_push_buffer: - * @appsrc: a #GstAppSrc - * @buffer: a #GstBuffer to push - * - * Adds a buffer to the queue of buffers that the appsrc element will - * push to its source pad. This function takes ownership of the buffer. - * - * Returns: #GST_FLOW_OK when the buffer was successfuly queued. - * #GST_FLOW_WRONG_STATE when @appsrc is not PAUSED or PLAYING. - * #GST_FLOW_UNEXPECTED when EOS occured. - */ -GstFlowReturn -gst_app_src_push_buffer (GstAppSrc * appsrc, GstBuffer * buffer) +static GstFlowReturn +gst_app_src_push_buffer_full (GstAppSrc * appsrc, GstBuffer * buffer, + gboolean steal_ref) { gboolean first = TRUE; @@ -979,6 +971,8 @@ gst_app_src_push_buffer (GstAppSrc * appsrc, GstBuffer * buffer) } GST_DEBUG_OBJECT (appsrc, "queueing buffer %p", buffer); + if (!steal_ref) + gst_buffer_ref (buffer); g_queue_push_tail (appsrc->queue, buffer); appsrc->queued_bytes += GST_BUFFER_SIZE (buffer); g_cond_broadcast (appsrc->cond); @@ -990,19 +984,47 @@ gst_app_src_push_buffer (GstAppSrc * appsrc, GstBuffer * buffer) flushing: { GST_DEBUG_OBJECT (appsrc, "refuse buffer %p, we are flushing", buffer); - gst_buffer_unref (buffer); + if (steal_ref) + gst_buffer_unref (buffer); g_mutex_unlock (appsrc->mutex); return GST_FLOW_WRONG_STATE; } eos: { GST_DEBUG_OBJECT (appsrc, "refuse buffer %p, we are EOS", buffer); - gst_buffer_unref (buffer); + if (steal_ref) + gst_buffer_unref (buffer); g_mutex_unlock (appsrc->mutex); return GST_FLOW_UNEXPECTED; } } +/** + * gst_app_src_push_buffer: + * @appsrc: a #GstAppSrc + * @buffer: a #GstBuffer to push + * + * Adds a buffer to the queue of buffers that the appsrc element will + * push to its source pad. This function takes ownership of the buffer. + * + * Returns: #GST_FLOW_OK when the buffer was successfuly queued. + * #GST_FLOW_WRONG_STATE when @appsrc is not PAUSED or PLAYING. + * #GST_FLOW_UNEXPECTED when EOS occured. + */ +GstFlowReturn +gst_app_src_push_buffer (GstAppSrc * appsrc, GstBuffer * buffer) +{ + return gst_app_src_push_buffer_full (appsrc, buffer, TRUE); +} + +/* push a buffer without stealing the ref of the buffer. This is used for the + * action signal. */ +static GstFlowReturn +gst_app_src_push_buffer_action (GstAppSrc * appsrc, GstBuffer * buffer) +{ + return gst_app_src_push_buffer_full (appsrc, buffer, FALSE); +} + /** * gst_app_src_end_of_stream: * @appsrc: a #GstAppSrc