From 6887e772016c5e4ab9f82228f9ca95d6c7eb3d70 Mon Sep 17 00:00:00 2001 From: He Junyan Date: Wed, 14 Jul 2021 14:27:34 +0800 Subject: [PATCH] va: decoder: Add helper functions to get and change the resolution. 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: --- sys/va/gstvadecoder.c | 49 +++++++++++++++++++++++++++++++++++++++++++ sys/va/gstvadecoder.h | 8 +++++++ 2 files changed, 57 insertions(+) diff --git a/sys/va/gstvadecoder.c b/sys/va/gstvadecoder.c index 17c814a076..14ef2ba20e 100644 --- a/sys/va/gstvadecoder.c +++ b/sys/va/gstvadecoder.c @@ -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; +} diff --git a/sys/va/gstvadecoder.h b/sys/va/gstvadecoder.h index c6e31e26d4..7fadd26445 100644 --- a/sys/va/gstvadecoder.h +++ b/sys/va/gstvadecoder.h @@ -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