va: vp9dec: Do not re-create context for dynamical resolution change.
authorHe Junyan <junyan.he@intel.com>
Wed, 14 Jul 2021 06:43:51 +0000 (14:43 +0800)
committerVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Thu, 15 Jul 2021 09:42:51 +0000 (09:42 +0000)
The driver for VP9 should have the ability to handle the dynamical resolution
changes. So if only the resolution changes, we should not re-create the config
and context in negotiation.

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

sys/va/gstvavp9dec.c

index 6d20bb1..a66e764 100644 (file)
@@ -508,6 +508,7 @@ gst_va_vp9_dec_negotiate (GstVideoDecoder * decoder)
   GstVaVp9Dec *self = GST_VA_VP9_DEC (decoder);
   GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
   GstVp9Decoder *vp9dec = GST_VP9_DECODER (decoder);
+  gboolean need_open;
 
   /* Ignore downstream renegotiation request. */
   if (!self->need_negotiation)
@@ -515,16 +516,42 @@ gst_va_vp9_dec_negotiate (GstVideoDecoder * decoder)
 
   self->need_negotiation = FALSE;
 
-  if (gst_va_decoder_is_open (base->decoder)
-      && !gst_va_decoder_close (base->decoder))
-    return FALSE;
+  need_open = TRUE;
+  /* The driver for VP9 should have the ability to handle the dynamical
+     resolution changes. So if only the resolution changes, we should not
+     re-create the config and context. */
+  if (gst_va_decoder_is_open (base->decoder)) {
+    VAProfile cur_profile;
+    guint cur_rtformat;
+    gint cur_width, cur_height;
+
+    if (!gst_va_decoder_get_config (base->decoder, &cur_profile,
+            &cur_rtformat, &cur_width, &cur_height))
+      return FALSE;
 
-  if (!gst_va_decoder_open (base->decoder, base->profile, base->rt_format))
-    return FALSE;
+    if (base->profile == cur_profile && base->rt_format == cur_rtformat) {
+      if (!gst_va_decoder_change_resolution (base->decoder, base->width,
+              base->height))
+        return FALSE;
 
-  if (!gst_va_decoder_set_format (base->decoder, base->width, base->height,
-          NULL))
-    return FALSE;
+      GST_INFO_OBJECT (self, "dynamical resolution changes from %dx%d to"
+          " %dx%d", cur_width, cur_height, base->width, base->height);
+
+      need_open = FALSE;
+    } else {
+      if (!gst_va_decoder_close (base->decoder))
+        return FALSE;
+    }
+  }
+
+  if (need_open) {
+    if (!gst_va_decoder_open (base->decoder, base->profile, base->rt_format))
+      return FALSE;
+
+    if (!gst_va_decoder_set_format (base->decoder, base->width, base->height,
+            NULL))
+      return FALSE;
+  }
 
   if (base->output_state)
     gst_video_codec_state_unref (base->output_state);