From 2f87392ee7962c02922befc7ec1790e729bb010d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sebastian=20Dr=C3=B6ge?= Date: Sun, 27 Nov 2016 12:40:53 +0200 Subject: [PATCH] rawbaseparse: Fix output buffer size trimming For frame->buffer, baseparse is doing that automatically for us. For frame->output_buffer it doesn't and assumes that the subclass is already doing that. Consistency! --- gst/rawparse/gstrawbaseparse.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/gst/rawparse/gstrawbaseparse.c b/gst/rawparse/gstrawbaseparse.c index 99d64dad09..5fb8e73c84 100644 --- a/gst/rawparse/gstrawbaseparse.c +++ b/gst/rawparse/gstrawbaseparse.c @@ -432,7 +432,7 @@ done: static GstBuffer * gst_raw_base_parse_align_buffer (GstRawBaseParse * raw_base_parse, - gsize alignment, GstBuffer * buffer) + gsize alignment, GstBuffer * buffer, gsize out_size) { GstMapInfo map; @@ -440,32 +440,32 @@ gst_raw_base_parse_align_buffer (GstRawBaseParse * raw_base_parse, if (map.size < sizeof (guintptr)) { gst_buffer_unmap (buffer, &map); - return buffer; + return NULL; } if (((guintptr) map.data) & (alignment - 1)) { GstBuffer *new_buffer; GstAllocationParams params = { 0, alignment - 1, 0, 0, }; - new_buffer = gst_buffer_new_allocate (NULL, - gst_buffer_get_size (buffer), ¶ms); + new_buffer = gst_buffer_new_allocate (NULL, out_size, ¶ms); /* Copy data "by hand", so ensure alignment is kept: */ - gst_buffer_fill (new_buffer, 0, map.data, map.size); + gst_buffer_fill (new_buffer, 0, map.data, out_size); - gst_buffer_copy_into (new_buffer, buffer, GST_BUFFER_COPY_METADATA, 0, -1); + gst_buffer_copy_into (new_buffer, buffer, GST_BUFFER_COPY_METADATA, 0, + out_size); GST_DEBUG_OBJECT (raw_base_parse, "We want output aligned on %" G_GSIZE_FORMAT ", reallocated", alignment); gst_buffer_unmap (buffer, &map); - gst_buffer_unref (buffer); return new_buffer; } gst_buffer_unmap (buffer, &map); - return buffer; + + return NULL; } static GstFlowReturn @@ -609,9 +609,17 @@ gst_raw_base_parse_handle_frame (GstBaseParse * parse, && (alignment = klass->get_alignment (raw_base_parse, GST_RAW_BASE_PARSE_CONFIG_CURRENT)) != 1) { - frame->out_buffer = + GstBuffer *aligned_buffer; + + aligned_buffer = gst_raw_base_parse_align_buffer (raw_base_parse, alignment, - gst_buffer_ref (frame->buffer)); + frame->out_buffer ? frame->out_buffer : frame->buffer, out_size); + + if (aligned_buffer) { + if (frame->out_buffer) + gst_buffer_unref (frame->out_buffer); + frame->out_buffer = aligned_buffer; + } } /* Set the duration of the output buffer, or if none exists, of -- 2.34.1