From 458ac4a693efcae3c3b18f03c4e7959cc5003abc Mon Sep 17 00:00:00 2001 From: He Junyan Date: Wed, 14 Jul 2021 14:43:51 +0800 Subject: [PATCH] va: vp9dec: Do not re-create context for dynamical resolution change. 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: --- sys/va/gstvavp9dec.c | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/sys/va/gstvavp9dec.c b/sys/va/gstvavp9dec.c index 6d20bb1..a66e764 100644 --- a/sys/va/gstvavp9dec.c +++ b/sys/va/gstvavp9dec.c @@ -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); -- 2.7.4