From ea8b372ceb8b9b8c0d26613bb0bf8c5366e75a9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Manuel=20J=C3=A1quez=20Leal?= Date: Sat, 17 Jul 2021 20:45:48 +0200 Subject: [PATCH] va: Refactor _format_changed() to _config_is_equal(). Change gst_va_decoder_format_changed() to gst_va_decoder_config_is_equal(), which is more similar with other GStreamer API. The function call is replaced but it has to be negated because the return value is the opposite. Part-of: --- sys/va/gstvaav1dec.c | 4 ++-- sys/va/gstvadecoder.c | 29 ++++++++++++++++++----------- sys/va/gstvadecoder.h | 10 +++++----- sys/va/gstvah264dec.c | 2 +- sys/va/gstvah265dec.c | 2 +- sys/va/gstvampeg2dec.c | 2 +- sys/va/gstvavp8dec.c | 2 +- sys/va/gstvavp9dec.c | 2 +- 8 files changed, 30 insertions(+), 23 deletions(-) diff --git a/sys/va/gstvaav1dec.c b/sys/va/gstvaav1dec.c index 8afd91c70a..5b02cbc488 100644 --- a/sys/va/gstvaav1dec.c +++ b/sys/va/gstvaav1dec.c @@ -103,7 +103,7 @@ gst_va_av1_dec_negotiate (GstVideoDecoder * decoder) self->need_negotiation = FALSE; /* Do not re-create the context if only the frame size changes */ - if (gst_va_decoder_format_changed (base->decoder, base->profile, + if (!gst_va_decoder_config_is_equal (base->decoder, base->profile, base->rt_format, self->max_width, self->max_height)) { if (gst_va_decoder_is_open (base->decoder) && !gst_va_decoder_close (base->decoder)) @@ -265,7 +265,7 @@ gst_va_av1_dec_new_sequence (GstAV1Decoder * decoder, self->seq = *seq_hdr; - if (gst_va_decoder_format_changed (base->decoder, profile, + if (!gst_va_decoder_config_is_equal (base->decoder, profile, rt_format, seq_hdr->max_frame_width_minus_1 + 1, seq_hdr->max_frame_height_minus_1 + 1)) { base->profile = profile; diff --git a/sys/va/gstvadecoder.c b/sys/va/gstvadecoder.c index 44d4e6dbfa..0f97232520 100644 --- a/sys/va/gstvadecoder.c +++ b/sys/va/gstvadecoder.c @@ -698,6 +698,24 @@ gst_va_decoder_decode (GstVaDecoder * self, GstVaDecodePicture * pic) return gst_va_decoder_decode_with_aux_surface (self, pic, FALSE); } +gboolean +gst_va_decoder_config_is_equal (GstVaDecoder * self, VAProfile new_profile, + guint new_rtformat, gint new_width, gint new_height) +{ + gboolean ret; + + g_return_val_if_fail (GST_IS_VA_DECODER (self), FALSE); + + /* @TODO: Check if current buffers are large enough, and reuse + * them */ + GST_OBJECT_LOCK (self); + ret = (self->profile == new_profile && self->rt_format == new_rtformat + && self->coded_width == new_width && self->coded_height == new_height); + GST_OBJECT_UNLOCK (self); + + return ret; +} + static gboolean _destroy_buffers (GstVaDecodePicture * pic) { @@ -807,17 +825,6 @@ gst_va_decode_picture_dup (GstVaDecodePicture * pic) return dup; } -gboolean -gst_va_decoder_format_changed (GstVaDecoder * decoder, VAProfile new_profile, - guint new_rtformat, gint new_width, gint new_height) -{ - /* @TODO: Check if current buffers are large enough, and reuse - * them */ - return !(decoder->profile == 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) diff --git a/sys/va/gstvadecoder.h b/sys/va/gstvadecoder.h index 60bb63d0c2..204721cd7a 100644 --- a/sys/va/gstvadecoder.h +++ b/sys/va/gstvadecoder.h @@ -86,6 +86,11 @@ gboolean gst_va_decoder_decode (GstVaDecoder * self, gboolean gst_va_decoder_decode_with_aux_surface (GstVaDecoder * self, GstVaDecodePicture * pic, gboolean use_aux); +gboolean gst_va_decoder_config_is_equal (GstVaDecoder * decoder, + VAProfile new_profile, + guint new_rtformat, + gint new_width, + gint new_height); GstVaDecodePicture * gst_va_decode_picture_new (GstVaDecoder * self, GstBuffer * buffer); @@ -94,11 +99,6 @@ VASurfaceID gst_va_decode_picture_get_aux_surface (GstVaDecodePicture void gst_va_decode_picture_free (GstVaDecodePicture * pic); GstVaDecodePicture * gst_va_decode_picture_dup (GstVaDecodePicture * pic); -gboolean gst_va_decoder_format_changed (GstVaDecoder * decoder, - VAProfile new_profile, - guint new_rtformat, - gint new_width, - gint new_height); gboolean gst_va_decoder_get_config (GstVaDecoder * decoder, VAProfile * profile, guint * rt_format, diff --git a/sys/va/gstvah264dec.c b/sys/va/gstvah264dec.c index bb4b2c77a3..4f1d08c9db 100644 --- a/sys/va/gstvah264dec.c +++ b/sys/va/gstvah264dec.c @@ -673,7 +673,7 @@ gst_va_h264_dec_new_sequence (GstH264Decoder * decoder, const GstH264SPS * sps, if (rt_format == 0) return FALSE; - if (gst_va_decoder_format_changed (base->decoder, profile, + if (!gst_va_decoder_config_is_equal (base->decoder, profile, rt_format, sps->width, sps->height)) { base->profile = profile; base->rt_format = rt_format; diff --git a/sys/va/gstvah265dec.c b/sys/va/gstvah265dec.c index 63f50be6a1..304f4fd5f6 100644 --- a/sys/va/gstvah265dec.c +++ b/sys/va/gstvah265dec.c @@ -1053,7 +1053,7 @@ gst_va_h265_dec_new_sequence (GstH265Decoder * decoder, const GstH265SPS * sps, if (rt_format == 0) return FALSE; - if (gst_va_decoder_format_changed (base->decoder, profile, + if (!gst_va_decoder_config_is_equal (base->decoder, profile, rt_format, sps->width, sps->height)) { base->profile = profile; base->rt_format = rt_format; diff --git a/sys/va/gstvampeg2dec.c b/sys/va/gstvampeg2dec.c index 6fe0169f03..c282c25894 100644 --- a/sys/va/gstvampeg2dec.c +++ b/sys/va/gstvampeg2dec.c @@ -252,7 +252,7 @@ gst_va_mpeg2_dec_new_sequence (GstMpeg2Decoder * decoder, if (rt_format == 0) return FALSE; - if (gst_va_decoder_format_changed (base->decoder, profile, + if (!gst_va_decoder_config_is_equal (base->decoder, profile, rt_format, width, height)) { base->profile = profile; base->rt_format = rt_format; diff --git a/sys/va/gstvavp8dec.c b/sys/va/gstvavp8dec.c index d9b266b659..c3a6394244 100644 --- a/sys/va/gstvavp8dec.c +++ b/sys/va/gstvavp8dec.c @@ -165,7 +165,7 @@ gst_va_vp8_dec_new_sequence (GstVp8Decoder * decoder, /* VP8 always use 8 bits 4:2:0 */ rt_format = VA_RT_FORMAT_YUV420; - if (gst_va_decoder_format_changed (base->decoder, profile, + if (!gst_va_decoder_config_is_equal (base->decoder, profile, rt_format, frame_hdr->width, frame_hdr->height)) { base->profile = profile; base->width = frame_hdr->width; diff --git a/sys/va/gstvavp9dec.c b/sys/va/gstvavp9dec.c index dcecd8daed..0340e1e4de 100644 --- a/sys/va/gstvavp9dec.c +++ b/sys/va/gstvavp9dec.c @@ -166,7 +166,7 @@ gst_va_vp9_new_sequence (GstVp9Decoder * decoder, if (rt_format == 0) return FALSE; - if (gst_va_decoder_format_changed (base->decoder, profile, + if (!gst_va_decoder_config_is_equal (base->decoder, profile, rt_format, frame_hdr->width, frame_hdr->height)) { base->profile = profile; base->width = frame_hdr->width;