v4l2codecs: h264: Only set SPS control if needed
authorEzequiel Garcia <ezequiel@collabora.com>
Wed, 30 Sep 2020 17:34:15 +0000 (14:34 -0300)
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Tue, 2 Mar 2021 22:03:34 +0000 (22:03 +0000)
Given V4L2 controls are cached in V4L2, there is no need
to set them if they don't change. Set the SPS control
only if a new sequence was received by the parser.

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

sys/v4l2codecs/gstv4l2codech264dec.c

index bd802eb2872243ed1f1638d9f2de7019d3cdf22a..618752583dcd318d6bf4b6572d9be61a775865a5 100644 (file)
@@ -74,6 +74,7 @@ struct _GstV4l2CodecH264Dec
   gint min_pool_size;
   gboolean has_videometa;
   gboolean need_negotiation;
+  gboolean need_sequence;
   gboolean copy_frames;
 
   struct v4l2_ctrl_h264_sps sps;
@@ -789,6 +790,7 @@ gst_v4l2_codec_h264_dec_new_sequence (GstH264Decoder * decoder,
   }
 
   gst_v4l2_codec_h264_dec_fill_sequence (self, sps);
+  self->need_sequence = TRUE;
 
   if (negotiation_needed) {
     self->need_negotiation = TRUE;
@@ -1016,11 +1018,6 @@ gst_v4l2_codec_h264_dec_submit_bitstream (GstV4l2CodecH264Dec * self,
 
   /* *INDENT-OFF* */
   struct v4l2_ext_control control[] = {
-    {
-      .id = V4L2_CID_STATELESS_H264_SPS,
-      .ptr = &self->sps,
-      .size = sizeof (self->sps),
-    },
     {
       .id = V4L2_CID_STATELESS_H264_PPS,
       .ptr = &self->pps,
@@ -1038,6 +1035,7 @@ gst_v4l2_codec_h264_dec_submit_bitstream (GstV4l2CodecH264Dec * self,
     },
     { },
     { },
+    { },
   };
   /* *INDENT-ON* */
 
@@ -1073,8 +1071,16 @@ gst_v4l2_codec_h264_dec_submit_bitstream (GstV4l2CodecH264Dec * self,
     goto done;
   }
 
-  /* Always set SPS, PPS, SCALING_MATRIX and DECODE_PARAMS */
-  count = 4;
+  /* Always set PPS, SCALING_MATRIX and DECODE_PARAMS */
+  count = 3;
+
+  if (self->need_sequence) {
+    control[count].id = V4L2_CID_STATELESS_H264_SPS;
+    control[count].ptr = &self->sps;
+    control[count].size = sizeof (self->sps);
+    count++;
+    self->need_sequence = FALSE;
+  }
 
   /* If it's not slice-based then it doesn't support per-slice controls. */
   if (is_slice_based (self)) {