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.
This commit is contained in:
Tim-Philipp Müller 2012-07-10 00:39:37 +01:00
parent 82eb275ef9
commit ebcfd0ce05

View file

@ -2280,6 +2280,7 @@ gst_base_src_get_range (GstBaseSrc * src, guint64 offset, guint length,
GstBaseSrcClass *bclass; GstBaseSrcClass *bclass;
GstClockReturn status; GstClockReturn status;
GstBuffer *res_buf; GstBuffer *res_buf;
GstBuffer *in_buf;
bclass = GST_BASE_SRC_GET_CLASS (src); bclass = GST_BASE_SRC_GET_CLASS (src);
@ -2325,7 +2326,7 @@ again:
"calling create offset %" G_GUINT64_FORMAT " length %u, time %" "calling create offset %" G_GUINT64_FORMAT " length %u, time %"
G_GINT64_FORMAT, offset, length, src->segment.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); ret = bclass->create (src, offset, length, &res_buf);
@ -2343,6 +2344,25 @@ again:
if (G_UNLIKELY (ret != GST_FLOW_OK)) if (G_UNLIKELY (ret != GST_FLOW_OK))
goto not_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 */ /* no timestamp set and we are at offset 0, we can timestamp with 0 */
if (offset == 0 && src->segment.time == 0 if (offset == 0 && src->segment.time == 0
&& GST_BUFFER_DTS (res_buf) == -1 && !src->is_live) { && GST_BUFFER_DTS (res_buf) == -1 && !src->is_live) {