Skip to content

Commit

Permalink
libs: audio: Fix gst_audio_buffer_truncate meta handling
Browse files Browse the repository at this point in the history
In the non-interleaved case, it made `buffer` writable but then changed
the meta of the non-writable buffer.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/1035>
  • Loading branch information
heftig committed Feb 15, 2021
1 parent 319da90 commit 297a5f0
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion gst-libs/gst/audio/audio.c
Expand Up @@ -290,6 +290,10 @@ gst_audio_buffer_truncate (GstBuffer * buffer, gint bpf, gsize trim,
if (samples == orig_samples)
return buffer;

GST_DEBUG ("Truncating %" G_GSIZE_FORMAT " to %" G_GSIZE_FORMAT
" (trim start %" G_GSIZE_FORMAT ", end %" G_GSIZE_FORMAT ")",
orig_samples, samples, trim, orig_samples - trim - samples);

if (!meta || meta->info.layout == GST_AUDIO_LAYOUT_INTERLEAVED) {
/* interleaved */
ret = gst_buffer_copy_region (buffer, GST_BUFFER_COPY_ALL, trim * bpf,
Expand All @@ -301,7 +305,7 @@ gst_audio_buffer_truncate (GstBuffer * buffer, gint bpf, gsize trim,
} else {
/* non-interleaved */
ret = gst_buffer_make_writable (buffer);
meta = gst_buffer_get_audio_meta (buffer);
meta = gst_buffer_get_audio_meta (ret);
meta->samples = samples;
for (i = 0; i < meta->info.channels; i++) {
meta->offsets[i] += trim * bpf / meta->info.channels;
Expand Down

0 comments on commit 297a5f0

Please sign in to comment.