va: Add and use gst_va_base_dec_process_output().
authorVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Wed, 23 Nov 2022 17:14:30 +0000 (18:14 +0100)
committerVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Thu, 1 Dec 2022 18:54:14 +0000 (18:54 +0000)
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>

subprojects/gst-plugins-bad/sys/va/gstvaav1dec.c
subprojects/gst-plugins-bad/sys/va/gstvabasedec.c
subprojects/gst-plugins-bad/sys/va/gstvabasedec.h
subprojects/gst-plugins-bad/sys/va/gstvah264dec.c
subprojects/gst-plugins-bad/sys/va/gstvah265dec.c
subprojects/gst-plugins-bad/sys/va/gstvajpegdec.c
subprojects/gst-plugins-bad/sys/va/gstvampeg2dec.c
subprojects/gst-plugins-bad/sys/va/gstvavp8dec.c
subprojects/gst-plugins-bad/sys/va/gstvavp9dec.c

index 2c1bb79..fafddba 100644 (file)
@@ -946,6 +946,8 @@ gst_va_av1_dec_output_picture (GstAV1Decoder * decoder,
 {
   GstVaAV1Dec *self = GST_VA_AV1_DEC (decoder);
   GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
+  GstVideoDecoder *vdec = GST_VIDEO_DECODER (decoder);
+  gboolean ret;
 
   g_assert (picture->frame_hdr.show_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) {
     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;
   }
 
@@ -968,12 +970,12 @@ gst_va_av1_dec_output_picture (GstAV1Decoder * decoder,
     frame->output_buffer = gst_buffer_ref (pic->gstbuffer);
   }
 
-  if (base->copy_frames)
-    gst_va_base_dec_copy_output_buffer (base, frame);
-
+  ret = gst_va_base_dec_process_output (base, frame, 0);
   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
index 749c6a4..f4c8c1a 100644 (file)
@@ -1027,3 +1027,28 @@ fail:
   GST_ERROR_OBJECT (base, "Failed copy output buffer.");
   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;
+}
index 47fa2dd..7cb645c 100644 (file)
@@ -132,5 +132,7 @@ void                  gst_va_base_dec_get_preferred_format_and_caps_features (Gs
                                                            GstCapsFeatures ** capsfeatures);
 gboolean              gst_va_base_dec_copy_output_buffer  (GstVaBaseDec * base,
                                                            GstVideoCodecFrame * codec_frame);
-
+gboolean              gst_va_base_dec_process_output      (GstVaBaseDec * base,
+                                                           GstVideoCodecFrame * frame,
+                                                           GstVideoBufferFlags buffer_flags);
 G_END_DECLS
index 559c5d5..756e673 100644 (file)
@@ -121,33 +121,24 @@ gst_va_h264_dec_output_picture (GstH264Decoder * decoder,
 {
   GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
   GstVaH264Dec *self = GST_VA_H264_DEC (decoder);
+  GstVideoDecoder *vdec = GST_VIDEO_DECODER (decoder);
+  gboolean ret;
 
   GST_LOG_OBJECT (self,
       "Outputting picture %p (poc %d)", picture, picture->pic_order_cnt);
 
   if (self->last_ret != GST_FLOW_OK) {
     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;
   }
 
-  if (base->copy_frames)
-    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);
-  }
-
+  ret = gst_va_base_dec_process_output (base, frame, picture->buffer_flags);
   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
index 45b6c78..51da017 100644 (file)
@@ -232,7 +232,9 @@ gst_va_h265_dec_output_picture (GstH265Decoder * decoder,
 {
   GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
   GstVaH265Dec *self = GST_VA_H265_DEC (decoder);
+  GstVideoDecoder *vdec = GST_VIDEO_DECODER (decoder);
   GstVaDecodePicture *va_pic;
+  gboolean ret;
 
   va_pic = gst_h265_picture_get_user_data (picture);
   g_assert (va_pic->gstbuffer);
@@ -243,18 +245,18 @@ gst_va_h265_dec_output_picture (GstH265Decoder * decoder,
   if (self->last_ret != GST_FLOW_OK) {
     gst_h265_picture_unref (picture);
     _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;
   }
 
   gst_buffer_replace (&frame->output_buffer, va_pic->gstbuffer);
 
-  if (base->copy_frames)
-    gst_va_base_dec_copy_output_buffer (base, frame);
-
+  ret = gst_va_base_dec_process_output (base, frame, picture->buffer_flags);
   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
index 2a00cb6..0ceb04a 100644 (file)
@@ -327,12 +327,12 @@ static GstFlowReturn
 gst_va_jpeg_dec_output_picture (GstJpegDecoder * decoder,
     GstVideoCodecFrame * frame)
 {
-  GstVideoDecoder *vdec = GST_VIDEO_DECODER (decoder);
   GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
+  GstVideoDecoder *vdec = GST_VIDEO_DECODER (decoder);
 
-  if (base->copy_frames)
-    gst_va_base_dec_copy_output_buffer (base, frame);
-  return gst_video_decoder_finish_frame (vdec, frame);
+  if (gst_va_base_dec_process_output (base, frame, 0))
+    return gst_video_decoder_finish_frame (vdec, frame);
+  return GST_FLOW_ERROR;
 }
 
 /* @XXX: Checks for drivers that can do color convertion to nv12
index 06020e4..1db97ba 100644 (file)
@@ -568,27 +568,18 @@ gst_va_mpeg2_dec_output_picture (GstMpeg2Decoder * decoder,
 {
   GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
   GstVaMpeg2Dec *self = GST_VA_MPEG2_DEC (decoder);
+  GstVideoDecoder *vdec = GST_VIDEO_DECODER (decoder);
+  gboolean ret;
 
   GST_LOG_OBJECT (self,
       "Outputting picture %p (poc %d)", picture, picture->pic_order_cnt);
 
-  if (base->copy_frames)
-    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);
-  }
-
+  ret = gst_va_base_dec_process_output (base, frame, picture->buffer_flags);
   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
index 0b78231..2197000 100644 (file)
@@ -445,6 +445,8 @@ gst_va_vp8_dec_output_picture (GstVp8Decoder * decoder,
 {
   GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
   GstVaVp8Dec *self = GST_VA_VP8_DEC (decoder);
+  GstVideoDecoder *vdec = GST_VIDEO_DECODER (decoder);
+  gboolean ret;
 
   GST_LOG_OBJECT (self,
       "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) {
     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;
   }
 
-  if (base->copy_frames)
-    gst_va_base_dec_copy_output_buffer (base, frame);
-
+  ret = gst_va_base_dec_process_output (base, frame, 0);
   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
index 136de0c..fce95ab 100644 (file)
@@ -506,15 +506,17 @@ gst_va_vp9_dec_output_picture (GstVp9Decoder * decoder,
 {
   GstVaBaseDec *base = GST_VA_BASE_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);
 
-  if (base->copy_frames)
-    gst_va_base_dec_copy_output_buffer (base, frame);
-
+  ret = gst_va_base_dec_process_output (base, frame, 0);
   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 *