From 4a4823b9728fbb944e05d89e0fee681ab5b33e25 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=ADctor=20Manuel=20J=C3=A1quez=20Leal?= Date: Tue, 26 Oct 2021 16:05:24 +0200 Subject: [PATCH] va: Delay decoders downstream negotiation. Delay decoders downstream negotiation just before an output frame needs to be allocated. This is required, are least for H.264 and H.265 decoders, since codec_data might trigger a new sequence before finishing upstream negotiation, and sink pad caps need to set before setting source pad caps, particularly to forward HDR fields. The other decoders are changed too in order to keep the same structure among them. Part-of: --- subprojects/gst-plugins-bad/sys/va/gstvah264dec.c | 15 ++++++++------- subprojects/gst-plugins-bad/sys/va/gstvah265dec.c | 15 ++++++++------- subprojects/gst-plugins-bad/sys/va/gstvampeg2dec.c | 15 ++++++++------- subprojects/gst-plugins-bad/sys/va/gstvavp8dec.c | 15 ++++++++------- subprojects/gst-plugins-bad/sys/va/gstvavp9dec.c | 15 ++++++++------- 5 files changed, 40 insertions(+), 35 deletions(-) diff --git a/subprojects/gst-plugins-bad/sys/va/gstvah264dec.c b/subprojects/gst-plugins-bad/sys/va/gstvah264dec.c index 617aabc..fddd8fb 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvah264dec.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvah264dec.c @@ -495,6 +495,13 @@ gst_va_h264_dec_new_picture (GstH264Decoder * decoder, GstVideoDecoder *vdec = GST_VIDEO_DECODER (decoder); GstVaBaseDec *base = GST_VA_BASE_DEC (decoder); + if (base->need_negotiation) { + if (!gst_video_decoder_negotiate (vdec)) { + GST_ERROR_OBJECT (self, "Failed to negotiate with downstream"); + return GST_FLOW_NOT_NEGOTIATED; + } + } + self->last_ret = gst_video_decoder_allocate_output_frame (vdec, frame); if (self->last_ret != GST_FLOW_OK) goto error; @@ -746,13 +753,7 @@ gst_va_h264_dec_new_sequence (GstH264Decoder * decoder, const GstH264SPS * sps, base->min_buffers = self->dpb_size + 4; /* dpb size + scratch surfaces */ - if (negotiation_needed) { - base->need_negotiation = TRUE; - if (!gst_video_decoder_negotiate (GST_VIDEO_DECODER (self))) { - GST_ERROR_OBJECT (self, "Failed to negotiate with downstream"); - return GST_FLOW_NOT_NEGOTIATED; - } - } + base->need_negotiation = negotiation_needed; return GST_FLOW_OK; } diff --git a/subprojects/gst-plugins-bad/sys/va/gstvah265dec.c b/subprojects/gst-plugins-bad/sys/va/gstvah265dec.c index 8f0c7ed..05d55fc 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvah265dec.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvah265dec.c @@ -855,6 +855,13 @@ gst_va_h265_dec_new_picture (GstH265Decoder * decoder, GstBuffer *output_buffer; GstVideoDecoder *vdec = GST_VIDEO_DECODER (decoder); + if (base->need_negotiation) { + if (!gst_video_decoder_negotiate (vdec)) { + GST_ERROR_OBJECT (self, "Failed to negotiate with downstream"); + return GST_FLOW_NOT_NEGOTIATED; + } + } + output_buffer = gst_video_decoder_allocate_output_buffer (vdec); if (!output_buffer) { self->last_ret = GST_FLOW_ERROR; @@ -1118,13 +1125,7 @@ gst_va_h265_dec_new_sequence (GstH265Decoder * decoder, const GstH265SPS * sps, base->min_buffers = self->dpb_size + 4; /* dpb size + scratch surfaces */ - if (negotiation_needed) { - base->need_negotiation = TRUE; - if (!gst_video_decoder_negotiate (GST_VIDEO_DECODER (self))) { - GST_ERROR_OBJECT (self, "Failed to negotiate with downstream"); - return GST_FLOW_NOT_NEGOTIATED; - } - } + base->need_negotiation = negotiation_needed; { /* FIXME: We don't have parser API for sps_range_extension, so diff --git a/subprojects/gst-plugins-bad/sys/va/gstvampeg2dec.c b/subprojects/gst-plugins-bad/sys/va/gstvampeg2dec.c index 78e6d90..b064cc7 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvampeg2dec.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvampeg2dec.c @@ -278,13 +278,7 @@ gst_va_mpeg2_dec_new_sequence (GstMpeg2Decoder * decoder, base->min_buffers = 2 + 4; /* max num pic references + scratch surfaces */ - if (negotiation_needed) { - base->need_negotiation = TRUE; - if (!gst_video_decoder_negotiate (GST_VIDEO_DECODER (self))) { - GST_ERROR_OBJECT (self, "Failed to negotiate with downstream"); - return GST_FLOW_NOT_NEGOTIATED; - } - } + base->need_negotiation = negotiation_needed; return GST_FLOW_OK; } @@ -299,6 +293,13 @@ gst_va_mpeg2_dec_new_picture (GstMpeg2Decoder * decoder, GstVaBaseDec *base = GST_VA_BASE_DEC (decoder); GstVideoDecoder *vdec = GST_VIDEO_DECODER (decoder); + if (base->need_negotiation) { + if (!gst_video_decoder_negotiate (vdec)) { + GST_ERROR_OBJECT (self, "Failed to negotiate with downstream"); + return GST_FLOW_NOT_NEGOTIATED; + } + } + ret = gst_video_decoder_allocate_output_frame (vdec, frame); if (ret != GST_FLOW_OK) goto error; diff --git a/subprojects/gst-plugins-bad/sys/va/gstvavp8dec.c b/subprojects/gst-plugins-bad/sys/va/gstvavp8dec.c index 2df289c..bd88ba8 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvavp8dec.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvavp8dec.c @@ -177,13 +177,7 @@ gst_va_vp8_dec_new_sequence (GstVp8Decoder * decoder, base->min_buffers = 3 + 4; /* max num pic references + scratch surfaces */ - if (negotiation_needed) { - base->need_negotiation = TRUE; - if (!gst_video_decoder_negotiate (GST_VIDEO_DECODER (self))) { - GST_ERROR_OBJECT (self, "Failed to negotiate with downstream"); - return GST_FLOW_NOT_NEGOTIATED; - } - } + base->need_negotiation = negotiation_needed; return GST_FLOW_OK; } @@ -197,6 +191,13 @@ gst_va_vp8_dec_new_picture (GstVp8Decoder * decoder, GstVideoDecoder *vdec = GST_VIDEO_DECODER (decoder); GstVaBaseDec *base = GST_VA_BASE_DEC (decoder); + if (base->need_negotiation) { + if (!gst_video_decoder_negotiate (vdec)) { + GST_ERROR_OBJECT (self, "Failed to negotiate with downstream"); + return GST_FLOW_NOT_NEGOTIATED; + } + } + self->last_ret = gst_video_decoder_allocate_output_frame (vdec, frame); if (self->last_ret != GST_FLOW_OK) goto error; diff --git a/subprojects/gst-plugins-bad/sys/va/gstvavp9dec.c b/subprojects/gst-plugins-bad/sys/va/gstvavp9dec.c index f713382..042f79a 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvavp9dec.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvavp9dec.c @@ -179,13 +179,7 @@ gst_va_vp9_new_sequence (GstVp9Decoder * decoder, base->min_buffers = GST_VP9_REF_FRAMES; - if (negotiation_needed) { - base->need_negotiation = TRUE; - if (!gst_video_decoder_negotiate (GST_VIDEO_DECODER (self))) { - GST_ERROR_OBJECT (self, "Failed to negotiate with downstream"); - return GST_FLOW_NOT_NEGOTIATED; - } - } + base->need_negotiation = negotiation_needed; return GST_FLOW_OK; } @@ -229,6 +223,13 @@ gst_va_vp9_dec_new_picture (GstVp9Decoder * decoder, if (ret != GST_FLOW_OK) return ret; + if (base->need_negotiation) { + if (!gst_video_decoder_negotiate (vdec)) { + GST_ERROR_OBJECT (self, "Failed to negotiate with downstream"); + return GST_FLOW_NOT_NEGOTIATED; + } + } + ret = gst_video_decoder_allocate_output_frame (vdec, frame); if (ret != GST_FLOW_OK) goto error; -- 2.7.4