v4l2slh264dec: Factor out bitstream allocation
authorNicolas Dufresne <nicolas.dufresne@collabora.com>
Mon, 29 Jun 2020 17:23:12 +0000 (13:23 -0400)
committerNicolas Dufresne <nicolas.dufresne@collabora.com>
Thu, 2 Jul 2020 16:21:51 +0000 (12:21 -0400)
No functional changes.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1395>

sys/v4l2codecs/gstv4l2codech264dec.c

index 81fcdb3..eec5c44 100644 (file)
@@ -724,36 +724,46 @@ gst_v4l2_codec_h264_dec_new_sequence (GstH264Decoder * decoder,
 }
 
 static gboolean
-gst_v4l2_codec_h264_dec_start_picture (GstH264Decoder * decoder,
-    GstH264Picture * picture, GstH264Slice * slice, GstH264Dpb * dpb)
+gst_v4l2_codec_h264_dec_ensure_bitstream (GstV4l2CodecH264Dec * self)
 {
-  GstV4l2CodecH264Dec *self = GST_V4L2_CODEC_H264_DEC (decoder);
+  if (self->bitstream)
+    goto done;
 
-  /* FIXME base class should not call us if negotiation failed */
-  if (!self->sink_allocator)
-    return FALSE;
+  self->bitstream = gst_v4l2_codec_allocator_alloc (self->sink_allocator);
 
-  /* Ensure we have a bitstream to write into */
   if (!self->bitstream) {
-    self->bitstream = gst_v4l2_codec_allocator_alloc (self->sink_allocator);
-
-    if (!self->bitstream) {
-      GST_ELEMENT_ERROR (decoder, RESOURCE, NO_SPACE_LEFT,
-          ("Not enough memory to decode H264 stream."), (NULL));
-      return FALSE;
-    }
+    GST_ELEMENT_ERROR (self, RESOURCE, NO_SPACE_LEFT,
+        ("Not enough memory to decode H264 stream."), (NULL));
+    return FALSE;
+  }
 
-    if (!gst_memory_map (self->bitstream, &self->bitstream_map, GST_MAP_WRITE)) {
-      GST_ELEMENT_ERROR (decoder, RESOURCE, WRITE,
-          ("Could not access bitstream memory for writing"), (NULL));
-      g_clear_pointer (&self->bitstream, gst_memory_unref);
-      return FALSE;
-    }
+  if (!gst_memory_map (self->bitstream, &self->bitstream_map, GST_MAP_WRITE)) {
+    GST_ELEMENT_ERROR (self, RESOURCE, WRITE,
+        ("Could not access bitstream memory for writing"), (NULL));
+    g_clear_pointer (&self->bitstream, gst_memory_unref);
+    return FALSE;
   }
 
+done:
   /* We use this field to track how much we have written */
   self->bitstream_map.size = 0;
 
+  return TRUE;
+}
+
+static gboolean
+gst_v4l2_codec_h264_dec_start_picture (GstH264Decoder * decoder,
+    GstH264Picture * picture, GstH264Slice * slice, GstH264Dpb * dpb)
+{
+  GstV4l2CodecH264Dec *self = GST_V4L2_CODEC_H264_DEC (decoder);
+
+  /* FIXME base class should not call us if negotiation failed */
+  if (!self->sink_allocator)
+    return FALSE;
+
+  if (!gst_v4l2_codec_h264_dec_ensure_bitstream (self))
+    return FALSE;
+
   gst_v4l2_codec_h264_dec_fill_pps (self, slice->header.pps);
   gst_v4l2_codec_h264_dec_fill_scaling_matrix (self, slice->header.pps);
   gst_v4l2_codec_h264_dec_fill_decoder_params (self, &slice->header, picture,