From b107c20198ebebf172a653f55948ff6d1993e931 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Sun, 16 Feb 2020 17:48:12 -0500 Subject: [PATCH] v4l2codecs: Fix bytesused value Pass the actual amount of bytes we have copied into the bitstream buffer. Also unmap the memory before queuing. --- sys/v4l2codecs/gstv4l2codech264dec.c | 10 ++++++++-- sys/v4l2codecs/gstv4l2decoder.c | 5 +++-- sys/v4l2codecs/gstv4l2decoder.h | 3 ++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/sys/v4l2codecs/gstv4l2codech264dec.c b/sys/v4l2codecs/gstv4l2codech264dec.c index 732b06a..70660b3 100644 --- a/sys/v4l2codecs/gstv4l2codech264dec.c +++ b/sys/v4l2codecs/gstv4l2codech264dec.c @@ -559,7 +559,8 @@ static void gst_v4l2_codec_h264_dec_reset_picture (GstV4l2CodecH264Dec * self) { if (self->bitstream) { - gst_memory_unmap (self->bitstream, &self->bitstream_map); + if (self->bitstream_map.memory) + gst_memory_unmap (self->bitstream, &self->bitstream_map); g_clear_pointer (&self->bitstream, gst_memory_unref); self->bitstream_map = (GstMapInfo) GST_MAP_INFO_INIT; } @@ -576,6 +577,7 @@ gst_v4l2_codec_h264_dec_end_picture (GstH264Decoder * decoder, GstV4l2Request *request; GstBuffer *buffer; GstFlowReturn flow_ret; + gsize bytesused; /* *INDENT-OFF* */ struct v4l2_ext_control control[] = { @@ -625,8 +627,12 @@ gst_v4l2_codec_h264_dec_end_picture (GstH264Decoder * decoder, return FALSE; } + bytesused = self->bitstream_map.size; + gst_memory_unmap (self->bitstream, &self->bitstream_map); + self->bitstream_map = (GstMapInfo) GST_MAP_INFO_INIT; + if (!gst_v4l2_decoder_queue_sink_mem (self->decoder, request, self->bitstream, - picture->system_frame_number)) { + picture->system_frame_number, bytesused)) { GST_ELEMENT_ERROR (decoder, RESOURCE, WRITE, ("Driver did not accept the bitstream data."), (NULL)); return FALSE; diff --git a/sys/v4l2codecs/gstv4l2decoder.c b/sys/v4l2codecs/gstv4l2decoder.c index a438108..1ab52ea 100644 --- a/sys/v4l2codecs/gstv4l2decoder.c +++ b/sys/v4l2codecs/gstv4l2decoder.c @@ -354,11 +354,12 @@ gst_v4l2_decoder_export_buffer (GstV4l2Decoder * self, gboolean gst_v4l2_decoder_queue_sink_mem (GstV4l2Decoder * self, - GstV4l2Request * request, GstMemory * mem, guint32 frame_num) + GstV4l2Request * request, GstMemory * mem, guint32 frame_num, + gsize bytesused) { gint ret; struct v4l2_plane plane = { - .bytesused = gst_memory_get_sizes (mem, NULL, NULL), + .bytesused = bytesused, }; struct v4l2_buffer buf = { .type = direction_to_buffer_type (GST_PAD_SINK), diff --git a/sys/v4l2codecs/gstv4l2decoder.h b/sys/v4l2codecs/gstv4l2decoder.h index 33faed2..7335224 100644 --- a/sys/v4l2codecs/gstv4l2decoder.h +++ b/sys/v4l2codecs/gstv4l2decoder.h @@ -69,7 +69,8 @@ gboolean gst_v4l2_decoder_export_buffer (GstV4l2Decoder * self, gboolean gst_v4l2_decoder_queue_sink_mem (GstV4l2Decoder * self, GstV4l2Request * request, GstMemory * mem, - guint32 frame_num); + guint32 frame_num, + gsize bytesused); gboolean gst_v4l2_decoder_dequeue_sink (GstV4l2Decoder * self); -- 2.7.4