diff options
author | Tim-Philipp Müller <tim@centricular.com> | 2021-01-04 13:40:20 +0000 |
---|---|---|
committer | Tim-Philipp Müller <tim@centricular.com> | 2021-01-04 15:05:44 +0000 |
commit | a89b4757f6c6aaddb916b2d2e6b01a96ada78a57 (patch) | |
tree | 2fee68f7cf8c804c99e1e0d0cf1c8d5ef38f5c1d | |
parent | 0fdc1ca818a4d03e187b2467cf23fa4196ccb94d (diff) | |
download | gstreamer-plugins-base-a89b4757f6c6aaddb916b2d2e6b01a96ada78a57.tar.gz |
tagdemux: resize and trim buffer in place to fix interaction with oggdemux
Elements operating in pull mode may optionally pass a buffer to
pull_range that should be filled with the data. The only element
that does that at the moment is oggdemux operating in pull mode.
tagdemux currently creates a sub-buffer whenever a buffer pulled
from upstream (filesrc, usually) needs to be trimmed. This creates
a new buffer, however, so disregards any passed-in buffer from a
downstream oggdemux.
This would cause assertion failures and playback problems for
ogg files that contain ID3 tags at the end.
Fixes https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/issues/848
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/995>
-rw-r--r-- | gst-libs/gst/tag/gsttagdemux.c | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/gst-libs/gst/tag/gsttagdemux.c b/gst-libs/gst/tag/gsttagdemux.c index f54585750..8164c0d2f 100644 --- a/gst-libs/gst/tag/gsttagdemux.c +++ b/gst-libs/gst/tag/gsttagdemux.c @@ -377,7 +377,8 @@ gst_tag_demux_trim_buffer (GstTagDemux * tagdemux, GstBuffer ** buf_ref, guint trim_start = 0; guint out_size, bsize; guint64 out_offset, boffset; - gboolean need_sub = FALSE; + gboolean need_fixup = FALSE; + gboolean is_writable; bsize = out_size = gst_buffer_get_size (buf); boffset = out_offset = GST_BUFFER_OFFSET (buf); @@ -402,7 +403,7 @@ gst_tag_demux_trim_buffer (GstTagDemux * tagdemux, GstBuffer ** buf_ref, if (out_offset + out_size > v1tag_offset) { out_size = v1tag_offset - out_offset; - need_sub = TRUE; + need_fixup = TRUE; } } } @@ -421,11 +422,16 @@ gst_tag_demux_trim_buffer (GstTagDemux * tagdemux, GstBuffer ** buf_ref, } else { out_offset -= tagdemux->priv->strip_start; } - need_sub = TRUE; + need_fixup = TRUE; } - if (need_sub) { - if (out_size != bsize || !gst_buffer_is_writable (buf)) { + if (!need_fixup) + goto done; + + is_writable = gst_buffer_is_writable (buf); + + if (out_size != bsize || !is_writable) { + if (!is_writable) { GstBuffer *sub; GST_DEBUG_OBJECT (tagdemux, "Sub-buffering to trim size %d offset %" @@ -444,15 +450,23 @@ gst_tag_demux_trim_buffer (GstTagDemux * tagdemux, GstBuffer ** buf_ref, *buf_ref = buf = sub; *buf_size = out_size; } else { - GST_DEBUG_OBJECT (tagdemux, "Adjusting buffer from size %d offset %" + GST_DEBUG_OBJECT (tagdemux, "Resizing buffer to trim size %d offset %" G_GINT64_FORMAT " to %d offset %" G_GINT64_FORMAT, bsize, boffset, out_size, out_offset); - } - GST_BUFFER_OFFSET (buf) = out_offset; - GST_BUFFER_OFFSET_END (buf) = out_offset + out_size; + gst_buffer_resize (buf, trim_start, out_size); + } + } else { + GST_DEBUG_OBJECT (tagdemux, "Adjusting buffer from size %d offset %" + G_GINT64_FORMAT " to %d offset %" G_GINT64_FORMAT, + bsize, boffset, out_size, out_offset); } + GST_BUFFER_OFFSET (buf) = out_offset; + GST_BUFFER_OFFSET_END (buf) = out_offset + out_size; + +done: + return TRUE; no_out_buffer_end: |