va: decoder: Add helper functions to get and change the resolution.
authorHe Junyan <junyan.he@intel.com>
Wed, 14 Jul 2021 06:27:34 +0000 (14:27 +0800)
committerVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Thu, 15 Jul 2021 09:42:51 +0000 (09:42 +0000)
Some codecs such as VP9, its config and context have the ability to
dynamically. When we only change the width and height, no need to
re-create the config and context. The helper function can just change
the resolution without re-creating config and context.

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

sys/va/gstvadecoder.c
sys/va/gstvadecoder.h

index 17c814a..14ef2ba 100644 (file)
@@ -346,6 +346,34 @@ gst_va_decoder_set_format (GstVaDecoder * self, gint coded_width,
   return TRUE;
 }
 
+gboolean
+gst_va_decoder_change_resolution (GstVaDecoder * self, gint coded_width,
+    gint coded_height)
+{
+  g_return_val_if_fail (GST_IS_VA_DECODER (self), FALSE);
+
+  if (!gst_va_decoder_is_open (self)) {
+    GST_ERROR_OBJECT (self, "decoder has not been opened yet");
+    return FALSE;
+  }
+
+  GST_OBJECT_LOCK (self);
+  if (self->context == VA_INVALID_ID) {
+    GST_OBJECT_UNLOCK (self);
+    GST_INFO_OBJECT (self, "decoder does not have a format");
+    return FALSE;
+  }
+  GST_OBJECT_UNLOCK (self);
+
+
+  GST_OBJECT_LOCK (self);
+  self->coded_width = coded_width;
+  self->coded_height = coded_height;
+  GST_OBJECT_UNLOCK (self);
+
+  return TRUE;
+}
+
 static gboolean
 _get_codec_caps (GstVaDecoder * self)
 {
@@ -779,3 +807,24 @@ gst_va_decoder_format_changed (GstVaDecoder * decoder, VAProfile new_profile,
       decoder->rt_format == new_rtformat &&
       decoder->coded_width == new_width && decoder->coded_height == new_height);
 }
+
+gboolean
+gst_va_decoder_get_config (GstVaDecoder * decoder, VAProfile * profile,
+    guint * rt_format, gint * width, gint * height)
+{
+  g_return_val_if_fail (decoder, FALSE);
+
+  if (!gst_va_decoder_is_open (decoder))
+    return FALSE;
+
+  if (profile)
+    *profile = decoder->profile;
+  if (rt_format)
+    *rt_format = decoder->rt_format;
+  if (width)
+    *width = decoder->coded_width;
+  if (height)
+    *height = decoder->coded_height;
+
+  return TRUE;
+}
index c6e31e2..7fadd26 100644 (file)
@@ -48,6 +48,9 @@ gboolean              gst_va_decoder_set_format           (GstVaDecoder * self,
                                                            gint coded_width,
                                                            gint coded_height,
                                                            GArray * surfaces);
+gboolean              gst_va_decoder_change_resolution    (GstVaDecoder * self,
+                                                           gint coded_width,
+                                                           gint coded_height);
 GstCaps *             gst_va_decoder_get_srcpad_caps      (GstVaDecoder * self);
 GstCaps *             gst_va_decoder_get_sinkpad_caps     (GstVaDecoder * self);
 gboolean              gst_va_decoder_has_profile          (GstVaDecoder * self,
@@ -92,5 +95,10 @@ gboolean              gst_va_decoder_format_changed       (GstVaDecoder * decode
                                                            guint new_rtformat,
                                                            gint new_width,
                                                            gint new_height);
+gboolean              gst_va_decoder_get_config           (GstVaDecoder * decoder,
+                                                           VAProfile * profile,
+                                                           guint * rt_format,
+                                                           gint * width,
+                                                           gint * height);
 
 G_END_DECLS