va: Add and use gst_va_base_dec_process_output().

This function will copy the frame, if it's needed, and will apply buffer flags.

The function is used by all the decoders.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3480>
This commit is contained in:
Víctor Manuel Jáquez Leal 2022-11-23 18:14:30 +01:00
parent 765adf5325
commit de5b76a922
9 changed files with 72 additions and 55 deletions

View file

@ -946,6 +946,8 @@ gst_va_av1_dec_output_picture (GstAV1Decoder * decoder,
{ {
GstVaAV1Dec *self = GST_VA_AV1_DEC (decoder); GstVaAV1Dec *self = GST_VA_AV1_DEC (decoder);
GstVaBaseDec *base = GST_VA_BASE_DEC (decoder); GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
GstVideoDecoder *vdec = GST_VIDEO_DECODER (decoder);
gboolean ret;
g_assert (picture->frame_hdr.show_frame || g_assert (picture->frame_hdr.show_frame ||
picture->frame_hdr.show_existing_frame); picture->frame_hdr.show_existing_frame);
@ -956,7 +958,7 @@ gst_va_av1_dec_output_picture (GstAV1Decoder * decoder,
if (self->last_ret != GST_FLOW_OK) { if (self->last_ret != GST_FLOW_OK) {
gst_av1_picture_unref (picture); gst_av1_picture_unref (picture);
gst_video_decoder_drop_frame (GST_VIDEO_DECODER (self), frame); gst_video_decoder_drop_frame (vdec, frame);
return self->last_ret; return self->last_ret;
} }
@ -968,12 +970,12 @@ gst_va_av1_dec_output_picture (GstAV1Decoder * decoder,
frame->output_buffer = gst_buffer_ref (pic->gstbuffer); frame->output_buffer = gst_buffer_ref (pic->gstbuffer);
} }
if (base->copy_frames) ret = gst_va_base_dec_process_output (base, frame, 0);
gst_va_base_dec_copy_output_buffer (base, frame);
gst_av1_picture_unref (picture); gst_av1_picture_unref (picture);
return gst_video_decoder_finish_frame (GST_VIDEO_DECODER (self), frame); if (ret)
return gst_video_decoder_finish_frame (vdec, frame);
return GST_FLOW_ERROR;
} }
static gboolean static gboolean

View file

@ -1027,3 +1027,28 @@ fail:
GST_ERROR_OBJECT (base, "Failed copy output buffer."); GST_ERROR_OBJECT (base, "Failed copy output buffer.");
return FALSE; return FALSE;
} }
gboolean
gst_va_base_dec_process_output (GstVaBaseDec * base, GstVideoCodecFrame * frame,
GstVideoBufferFlags buffer_flags)
{
GstVideoDecoder *vdec = GST_VIDEO_DECODER (base);
if (base->copy_frames)
gst_va_base_dec_copy_output_buffer (base, frame);
if (buffer_flags != 0) {
#ifndef GST_DISABLE_GST_DEBUG
gboolean interlaced =
(buffer_flags & GST_VIDEO_BUFFER_FLAG_INTERLACED) != 0;
gboolean tff = (buffer_flags & GST_VIDEO_BUFFER_FLAG_TFF) != 0;
GST_TRACE_OBJECT (base,
"apply buffer flags 0x%x (interlaced %d, top-field-first %d)",
buffer_flags, interlaced, tff);
#endif
GST_BUFFER_FLAG_SET (frame->output_buffer, buffer_flags);
}
return TRUE;
}

View file

@ -132,5 +132,7 @@ void gst_va_base_dec_get_preferred_format_and_caps_features (Gs
GstCapsFeatures ** capsfeatures); GstCapsFeatures ** capsfeatures);
gboolean gst_va_base_dec_copy_output_buffer (GstVaBaseDec * base, gboolean gst_va_base_dec_copy_output_buffer (GstVaBaseDec * base,
GstVideoCodecFrame * codec_frame); GstVideoCodecFrame * codec_frame);
gboolean gst_va_base_dec_process_output (GstVaBaseDec * base,
GstVideoCodecFrame * frame,
GstVideoBufferFlags buffer_flags);
G_END_DECLS G_END_DECLS

View file

@ -121,33 +121,24 @@ gst_va_h264_dec_output_picture (GstH264Decoder * decoder,
{ {
GstVaBaseDec *base = GST_VA_BASE_DEC (decoder); GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
GstVaH264Dec *self = GST_VA_H264_DEC (decoder); GstVaH264Dec *self = GST_VA_H264_DEC (decoder);
GstVideoDecoder *vdec = GST_VIDEO_DECODER (decoder);
gboolean ret;
GST_LOG_OBJECT (self, GST_LOG_OBJECT (self,
"Outputting picture %p (poc %d)", picture, picture->pic_order_cnt); "Outputting picture %p (poc %d)", picture, picture->pic_order_cnt);
if (self->last_ret != GST_FLOW_OK) { if (self->last_ret != GST_FLOW_OK) {
gst_h264_picture_unref (picture); gst_h264_picture_unref (picture);
gst_video_decoder_drop_frame (GST_VIDEO_DECODER (self), frame); gst_video_decoder_drop_frame (vdec, frame);
return self->last_ret; return self->last_ret;
} }
if (base->copy_frames) ret = gst_va_base_dec_process_output (base, frame, picture->buffer_flags);
gst_va_base_dec_copy_output_buffer (base, frame);
if (picture->buffer_flags != 0) {
gboolean interlaced =
(picture->buffer_flags & GST_VIDEO_BUFFER_FLAG_INTERLACED) != 0;
gboolean tff = (picture->buffer_flags & GST_VIDEO_BUFFER_FLAG_TFF) != 0;
GST_TRACE_OBJECT (self,
"apply buffer flags 0x%x (interlaced %d, top-field-first %d)",
picture->buffer_flags, interlaced, tff);
GST_BUFFER_FLAG_SET (frame->output_buffer, picture->buffer_flags);
}
gst_h264_picture_unref (picture); gst_h264_picture_unref (picture);
return gst_video_decoder_finish_frame (GST_VIDEO_DECODER (self), frame); if (ret)
return gst_video_decoder_finish_frame (vdec, frame);
return GST_FLOW_ERROR;
} }
static void static void

View file

@ -232,7 +232,9 @@ gst_va_h265_dec_output_picture (GstH265Decoder * decoder,
{ {
GstVaBaseDec *base = GST_VA_BASE_DEC (decoder); GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
GstVaH265Dec *self = GST_VA_H265_DEC (decoder); GstVaH265Dec *self = GST_VA_H265_DEC (decoder);
GstVideoDecoder *vdec = GST_VIDEO_DECODER (decoder);
GstVaDecodePicture *va_pic; GstVaDecodePicture *va_pic;
gboolean ret;
va_pic = gst_h265_picture_get_user_data (picture); va_pic = gst_h265_picture_get_user_data (picture);
g_assert (va_pic->gstbuffer); g_assert (va_pic->gstbuffer);
@ -243,18 +245,18 @@ gst_va_h265_dec_output_picture (GstH265Decoder * decoder,
if (self->last_ret != GST_FLOW_OK) { if (self->last_ret != GST_FLOW_OK) {
gst_h265_picture_unref (picture); gst_h265_picture_unref (picture);
_replace_previous_slice (self, NULL, 0); _replace_previous_slice (self, NULL, 0);
gst_video_decoder_drop_frame (GST_VIDEO_DECODER (self), frame); gst_video_decoder_drop_frame (vdec, frame);
return self->last_ret; return self->last_ret;
} }
gst_buffer_replace (&frame->output_buffer, va_pic->gstbuffer); gst_buffer_replace (&frame->output_buffer, va_pic->gstbuffer);
if (base->copy_frames) ret = gst_va_base_dec_process_output (base, frame, picture->buffer_flags);
gst_va_base_dec_copy_output_buffer (base, frame);
gst_h265_picture_unref (picture); gst_h265_picture_unref (picture);
return gst_video_decoder_finish_frame (GST_VIDEO_DECODER (self), frame); if (ret)
return gst_video_decoder_finish_frame (vdec, frame);
return GST_FLOW_ERROR;
} }
static void static void

View file

@ -327,12 +327,12 @@ static GstFlowReturn
gst_va_jpeg_dec_output_picture (GstJpegDecoder * decoder, gst_va_jpeg_dec_output_picture (GstJpegDecoder * decoder,
GstVideoCodecFrame * frame) GstVideoCodecFrame * frame)
{ {
GstVideoDecoder *vdec = GST_VIDEO_DECODER (decoder);
GstVaBaseDec *base = GST_VA_BASE_DEC (decoder); GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
GstVideoDecoder *vdec = GST_VIDEO_DECODER (decoder);
if (base->copy_frames) if (gst_va_base_dec_process_output (base, frame, 0))
gst_va_base_dec_copy_output_buffer (base, frame); return gst_video_decoder_finish_frame (vdec, frame);
return gst_video_decoder_finish_frame (vdec, frame); return GST_FLOW_ERROR;
} }
/* @XXX: Checks for drivers that can do color convertion to nv12 /* @XXX: Checks for drivers that can do color convertion to nv12

View file

@ -568,27 +568,18 @@ gst_va_mpeg2_dec_output_picture (GstMpeg2Decoder * decoder,
{ {
GstVaBaseDec *base = GST_VA_BASE_DEC (decoder); GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
GstVaMpeg2Dec *self = GST_VA_MPEG2_DEC (decoder); GstVaMpeg2Dec *self = GST_VA_MPEG2_DEC (decoder);
GstVideoDecoder *vdec = GST_VIDEO_DECODER (decoder);
gboolean ret;
GST_LOG_OBJECT (self, GST_LOG_OBJECT (self,
"Outputting picture %p (poc %d)", picture, picture->pic_order_cnt); "Outputting picture %p (poc %d)", picture, picture->pic_order_cnt);
if (base->copy_frames) ret = gst_va_base_dec_process_output (base, frame, picture->buffer_flags);
gst_va_base_dec_copy_output_buffer (base, frame);
if (picture->buffer_flags != 0) {
gboolean interlaced =
(picture->buffer_flags & GST_VIDEO_BUFFER_FLAG_INTERLACED) != 0;
gboolean tff = (picture->buffer_flags & GST_VIDEO_BUFFER_FLAG_TFF) != 0;
GST_TRACE_OBJECT (self,
"apply buffer flags 0x%x (interlaced %d, top-field-first %d)",
picture->buffer_flags, interlaced, tff);
GST_BUFFER_FLAG_SET (frame->output_buffer, picture->buffer_flags);
}
gst_mpeg2_picture_unref (picture); gst_mpeg2_picture_unref (picture);
return gst_video_decoder_finish_frame (GST_VIDEO_DECODER (self), frame); if (ret)
return gst_video_decoder_finish_frame (vdec, frame);
return GST_FLOW_ERROR;
} }
static void static void

View file

@ -445,6 +445,8 @@ gst_va_vp8_dec_output_picture (GstVp8Decoder * decoder,
{ {
GstVaBaseDec *base = GST_VA_BASE_DEC (decoder); GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
GstVaVp8Dec *self = GST_VA_VP8_DEC (decoder); GstVaVp8Dec *self = GST_VA_VP8_DEC (decoder);
GstVideoDecoder *vdec = GST_VIDEO_DECODER (decoder);
gboolean ret;
GST_LOG_OBJECT (self, GST_LOG_OBJECT (self,
"Outputting picture %p (system_frame_number %d)", "Outputting picture %p (system_frame_number %d)",
@ -452,16 +454,16 @@ gst_va_vp8_dec_output_picture (GstVp8Decoder * decoder,
if (self->last_ret != GST_FLOW_OK) { if (self->last_ret != GST_FLOW_OK) {
gst_vp8_picture_unref (picture); gst_vp8_picture_unref (picture);
gst_video_decoder_drop_frame (GST_VIDEO_DECODER (self), frame); gst_video_decoder_drop_frame (vdec, frame);
return self->last_ret; return self->last_ret;
} }
if (base->copy_frames) ret = gst_va_base_dec_process_output (base, frame, 0);
gst_va_base_dec_copy_output_buffer (base, frame);
gst_vp8_picture_unref (picture); gst_vp8_picture_unref (picture);
return gst_video_decoder_finish_frame (GST_VIDEO_DECODER (self), frame); if (ret)
return gst_video_decoder_finish_frame (vdec, frame);
return GST_FLOW_ERROR;
} }
static void static void

View file

@ -506,15 +506,17 @@ gst_va_vp9_dec_output_picture (GstVp9Decoder * decoder,
{ {
GstVaBaseDec *base = GST_VA_BASE_DEC (decoder); GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
GstVaVp9Dec *self = GST_VA_VP9_DEC (decoder); GstVaVp9Dec *self = GST_VA_VP9_DEC (decoder);
GstVideoDecoder *vdec = GST_VIDEO_DECODER (decoder);
gboolean ret;
GST_LOG_OBJECT (self, "Outputting picture %p", picture); GST_LOG_OBJECT (self, "Outputting picture %p", picture);
if (base->copy_frames) ret = gst_va_base_dec_process_output (base, frame, 0);
gst_va_base_dec_copy_output_buffer (base, frame);
gst_vp9_picture_unref (picture); gst_vp9_picture_unref (picture);
return gst_video_decoder_finish_frame (GST_VIDEO_DECODER (self), frame); if (ret)
return gst_video_decoder_finish_frame (vdec, frame);
return GST_FLOW_ERROR;
} }
static GstVp9Picture * static GstVp9Picture *