v4l2codecs: Fix bytesused value
authorNicolas Dufresne <nicolas.dufresne@collabora.com>
Sun, 16 Feb 2020 22:48:12 +0000 (17:48 -0500)
committerNicolas Dufresne <nicolas.dufresne@collabora.com>
Tue, 31 Mar 2020 13:34:05 +0000 (09:34 -0400)
Pass the actual amount of bytes we have copied into the bitstream buffer. Also
unmap the memory before queuing.

sys/v4l2codecs/gstv4l2codech264dec.c
sys/v4l2codecs/gstv4l2decoder.c
sys/v4l2codecs/gstv4l2decoder.h

index 732b06a..70660b3 100644 (file)
@@ -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;
index a438108..1ab52ea 100644 (file)
@@ -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),
index 33faed2..7335224 100644 (file)
@@ -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);