From ebcfd0ce05c7697606f6b6ae522d0cb0e9b86b17 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim-Philipp=20M=C3=BCller?= Date: Tue, 10 Jul 2012 00:39:37 +0100 Subject: [PATCH] basesrc: provide fallback in case a create function doesn't know about provided buffers In 0.11 the caller may provide a buffer to be filled by the source to pull_range/get_range/create, but it's easy to miss this new case when porting code from 0.10. Provide fallback that copies the created data into the provided buffer for now. This makes oggdemux in pull-mode work with dataurisrc. --- libs/gst/base/gstbasesrc.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/libs/gst/base/gstbasesrc.c b/libs/gst/base/gstbasesrc.c index 8bf8c49..c57eacc 100644 --- a/libs/gst/base/gstbasesrc.c +++ b/libs/gst/base/gstbasesrc.c @@ -2280,6 +2280,7 @@ gst_base_src_get_range (GstBaseSrc * src, guint64 offset, guint length, GstBaseSrcClass *bclass; GstClockReturn status; GstBuffer *res_buf; + GstBuffer *in_buf; bclass = GST_BASE_SRC_GET_CLASS (src); @@ -2325,7 +2326,7 @@ again: "calling create offset %" G_GUINT64_FORMAT " length %u, time %" G_GINT64_FORMAT, offset, length, src->segment.time); - res_buf = *buf; + res_buf = in_buf = *buf; ret = bclass->create (src, offset, length, &res_buf); @@ -2343,6 +2344,25 @@ again: if (G_UNLIKELY (ret != GST_FLOW_OK)) goto not_ok; + /* fallback in case the create function didn't fill a provided buffer */ + if (in_buf != NULL && res_buf != in_buf) { + GstMapInfo info; + gsize copied_size; + + GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, src, "create function didn't " + "fill the provided buffer, copying"); + + gst_buffer_map (in_buf, &info, GST_MAP_WRITE); + copied_size = gst_buffer_extract (res_buf, 0, info.data, info.size); + gst_buffer_unmap (in_buf, &info); + gst_buffer_set_size (in_buf, copied_size); + + gst_buffer_copy_into (in_buf, res_buf, GST_BUFFER_COPY_METADATA, 0, -1); + + gst_buffer_unref (res_buf); + res_buf = in_buf; + } + /* no timestamp set and we are at offset 0, we can timestamp with 0 */ if (offset == 0 && src->segment.time == 0 && GST_BUFFER_DTS (res_buf) == -1 && !src->is_live) { -- 2.7.4