From a73c6d7fb6e3ad3e4dcc29db987453f0c8647d49 Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Tue, 5 Sep 2023 22:14:42 +0900 Subject: [PATCH] vp9decoder: Port to GstCodecPicture struct Part-of: --- .../gst-libs/gst/codecs/gstvp9decoder.c | 6 +- .../gst-libs/gst/codecs/gstvp9decoder.h | 2 +- .../gst-libs/gst/codecs/gstvp9picture.c | 57 +------------------ .../gst-libs/gst/codecs/gstvp9picture.h | 38 +++++++------ .../sys/d3d11/gstd3d11vp9dec.cpp | 2 +- .../sys/nvcodec/gstnvvp9dec.cpp | 3 +- .../sys/v4l2codecs/gstv4l2codecvp9dec.c | 30 ++++++---- .../gst-plugins-bad/sys/va/gstvavp9dec.c | 3 +- 8 files changed, 52 insertions(+), 89 deletions(-) diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/codecs/gstvp9decoder.c b/subprojects/gst-plugins-bad/gst-libs/gst/codecs/gstvp9decoder.c index 9dfd8e1d65..2c309ae12c 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/codecs/gstvp9decoder.c +++ b/subprojects/gst-plugins-bad/gst-libs/gst/codecs/gstvp9decoder.c @@ -492,11 +492,11 @@ gst_vp9_decoder_handle_frame (GstVideoDecoder * decoder, goto unmap_and_error; } - picture->system_frame_number = pic_to_dup->system_frame_number; + GST_CODEC_PICTURE_COPY_FRAME_NUMBER (picture, pic_to_dup); } else { picture = gst_vp9_picture_new (); picture->frame_hdr = frame_hdr; - picture->system_frame_number = frame->system_frame_number; + GST_CODEC_PICTURE_FRAME_NUMBER (picture) = frame->system_frame_number; picture->data = map.data; picture->size = map.size; @@ -552,7 +552,7 @@ gst_vp9_decoder_handle_frame (GstVideoDecoder * decoder, /* If subclass didn't update output state at this point, * marking this picture as a discont and stores current input state */ if (priv->input_state_changed) { - picture->discont_state = gst_video_codec_state_ref (self->input_state); + gst_vp9_picture_set_discont_state (picture, self->input_state); priv->input_state_changed = FALSE; } diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/codecs/gstvp9decoder.h b/subprojects/gst-plugins-bad/gst-libs/gst/codecs/gstvp9decoder.h index 1a6a79f569..b88c0df5ba 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/codecs/gstvp9decoder.h +++ b/subprojects/gst-plugins-bad/gst-libs/gst/codecs/gstvp9decoder.h @@ -89,7 +89,7 @@ struct _GstVp9DecoderClass * * Optional. Called whenever new #GstVp9Picture is created. * Subclass can set implementation specific user data on the #GstVp9Picture - * via gst_vp9_picture_set_user_data() + * via gst_vp9_picture_set_user_data * * Since: 1.18 */ diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/codecs/gstvp9picture.c b/subprojects/gst-plugins-bad/gst-libs/gst/codecs/gstvp9picture.c index e3e09c33f7..a6ba845a0e 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/codecs/gstvp9picture.c +++ b/subprojects/gst-plugins-bad/gst-libs/gst/codecs/gstvp9picture.c @@ -22,26 +22,13 @@ #endif #include "gstvp9picture.h" +#include "gstcodecpicture-private.h" GST_DEBUG_CATEGORY_EXTERN (gst_vp9_decoder_debug); #define GST_CAT_DEFAULT gst_vp9_decoder_debug GST_DEFINE_MINI_OBJECT_TYPE (GstVp9Picture, gst_vp9_picture); -static void -_gst_vp9_picture_free (GstVp9Picture * picture) -{ - GST_TRACE ("Free picture %p", picture); - - if (picture->notify) - picture->notify (picture->user_data); - - if (picture->discont_state) - gst_video_codec_state_unref (picture->discont_state); - - g_free (picture); -} - /** * gst_vp9_picture_new: * @@ -58,53 +45,13 @@ gst_vp9_picture_new (void) gst_mini_object_init (GST_MINI_OBJECT_CAST (pic), 0, GST_TYPE_VP9_PICTURE, NULL, NULL, - (GstMiniObjectFreeFunction) _gst_vp9_picture_free); + (GstMiniObjectFreeFunction) gst_codec_picture_free); GST_TRACE ("New picture %p", pic); return pic; } -/** - * gst_vp9_picture_set_user_data: - * @picture: a #GstVp9Picture - * @user_data: private data - * @notify: (closure user_data): a #GDestroyNotify - * - * Sets @user_data on the picture and the #GDestroyNotify that will be called when - * the picture is freed. - * - * If a @user_data was previously set, then the previous set @notify will be called - * before the @user_data is replaced. - */ -void -gst_vp9_picture_set_user_data (GstVp9Picture * picture, gpointer user_data, - GDestroyNotify notify) -{ - g_return_if_fail (GST_IS_VP9_PICTURE (picture)); - - if (picture->notify) - picture->notify (picture->user_data); - - picture->user_data = user_data; - picture->notify = notify; -} - -/** - * gst_vp9_picture_get_user_data: - * @picture: a #GstVp9Picture - * - * Gets private data set on the picture via - * gst_vp9_picture_set_user_data() previously. - * - * Returns: (transfer none): The previously set user_data - */ -gpointer -gst_vp9_picture_get_user_data (GstVp9Picture * picture) -{ - return picture->user_data; -} - /** * gst_vp9_dpb_new: (skip) * diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/codecs/gstvp9picture.h b/subprojects/gst-plugins-bad/gst-libs/gst/codecs/gstvp9picture.h index 4c60491872..70bc859f7e 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/codecs/gstvp9picture.h +++ b/subprojects/gst-plugins-bad/gst-libs/gst/codecs/gstvp9picture.h @@ -21,6 +21,7 @@ #define __GST_VP9_PICTURE_H__ #include +#include #include #include @@ -36,22 +37,13 @@ typedef struct _GstVp9Picture GstVp9Picture; struct _GstVp9Picture { /*< private >*/ - GstMiniObject parent; - - /* From GstVideoCodecFrame */ - guint32 system_frame_number; + GstCodecPicture parent; GstVp9FrameHeader frame_hdr; /* raw data and size (does not have ownership) */ const guint8 * data; gsize size; - - /* decoder input state if this picture is discont point */ - GstVideoCodecState *discont_state; - - gpointer user_data; - GDestroyNotify notify; }; GST_CODECS_API @@ -89,13 +81,27 @@ gst_clear_vp9_picture (GstVp9Picture ** picture) } } -GST_CODECS_API -void gst_vp9_picture_set_user_data (GstVp9Picture * picture, - gpointer user_data, - GDestroyNotify notify); +static inline void +gst_vp9_picture_set_user_data (GstVp9Picture * picture, gpointer user_data, + GDestroyNotify notify) +{ + gst_codec_picture_set_user_data (GST_CODEC_PICTURE (picture), + user_data, notify); +} -GST_CODECS_API -gpointer gst_vp9_picture_get_user_data (GstVp9Picture * picture); +static inline gpointer +gst_vp9_picture_get_user_data (GstVp9Picture * picture) +{ + return gst_codec_picture_get_user_data (GST_CODEC_PICTURE (picture)); +} + +static inline void +gst_vp9_picture_set_discont_state (GstVp9Picture * picture, + GstVideoCodecState * discont_state) +{ + gst_codec_picture_set_discont_state (GST_CODEC_PICTURE (picture), + discont_state); +} /******************* * GstVp9Dpb * diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11vp9dec.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11vp9dec.cpp index 444307a78c..b0878958d6 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11vp9dec.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11vp9dec.cpp @@ -781,7 +781,7 @@ gst_d3d11_vp9_dec_output_picture (GstVp9Decoder * decoder, } if (!gst_d3d11_decoder_process_output (inner->d3d11_decoder, vdec, - picture->discont_state, picture->frame_hdr.width, + GST_CODEC_PICTURE (picture)->discont_state, picture->frame_hdr.width, picture->frame_hdr.height, view_buffer, &frame->output_buffer)) { GST_ERROR_OBJECT (self, "Failed to copy buffer"); goto error; diff --git a/subprojects/gst-plugins-bad/sys/nvcodec/gstnvvp9dec.cpp b/subprojects/gst-plugins-bad/sys/nvcodec/gstnvvp9dec.cpp index 69370a5ff4..5a3b7146df 100644 --- a/subprojects/gst-plugins-bad/sys/nvcodec/gstnvvp9dec.cpp +++ b/subprojects/gst-plugins-bad/sys/nvcodec/gstnvvp9dec.cpp @@ -744,7 +744,8 @@ gst_nv_vp9_dec_output_picture (GstVp9Decoder * decoder, } ret = gst_nv_decoder_finish_surface (self->decoder, - vdec, picture->discont_state, surface, &frame->output_buffer); + vdec, GST_CODEC_PICTURE (picture)->discont_state, surface, + &frame->output_buffer); if (ret != GST_FLOW_OK) goto error; diff --git a/subprojects/gst-plugins-bad/sys/v4l2codecs/gstv4l2codecvp9dec.c b/subprojects/gst-plugins-bad/sys/v4l2codecs/gstv4l2codecvp9dec.c index 164015519c..807b3f8960 100644 --- a/subprojects/gst-plugins-bad/sys/v4l2codecs/gstv4l2codecvp9dec.c +++ b/subprojects/gst-plugins-bad/sys/v4l2codecs/gstv4l2codecvp9dec.c @@ -273,17 +273,20 @@ gst_v4l2_codecs_vp9_dec_fill_refs (GstV4l2CodecVp9Dec * self, if (reference_frames && reference_frames->pic_list[h->ref_frame_idx[0]]) { ref_pic = reference_frames->pic_list[h->ref_frame_idx[0]]; - self->v4l2_vp9_frame.last_frame_ts = ref_pic->system_frame_number * 1000; + self->v4l2_vp9_frame.last_frame_ts = + GST_CODEC_PICTURE_FRAME_NUMBER (ref_pic) * 1000; } if (reference_frames && reference_frames->pic_list[h->ref_frame_idx[1]]) { ref_pic = reference_frames->pic_list[h->ref_frame_idx[1]]; - self->v4l2_vp9_frame.golden_frame_ts = ref_pic->system_frame_number * 1000; + self->v4l2_vp9_frame.golden_frame_ts = + GST_CODEC_PICTURE_FRAME_NUMBER (ref_pic) * 1000; } if (reference_frames && reference_frames->pic_list[h->ref_frame_idx[2]]) { ref_pic = reference_frames->pic_list[h->ref_frame_idx[2]]; - self->v4l2_vp9_frame.alt_frame_ts = ref_pic->system_frame_number * 1000; + self->v4l2_vp9_frame.alt_frame_ts = + GST_CODEC_PICTURE_FRAME_NUMBER (ref_pic) * 1000; } } @@ -796,7 +799,7 @@ gst_v4l2_codec_vp9_dec_end_picture (GstVp9Decoder * decoder, gst_memory_resize (self->bitstream, 0, bytesused); frame = gst_video_decoder_get_frame (GST_VIDEO_DECODER (self), - picture->system_frame_number); + GST_CODEC_PICTURE_FRAME_NUMBER (picture)); g_return_val_if_fail (frame, FALSE); flow_ret = gst_buffer_pool_acquire_buffer (GST_BUFFER_POOL (self->src_pool), @@ -811,7 +814,8 @@ gst_v4l2_codec_vp9_dec_end_picture (GstVp9Decoder * decoder, } request = gst_v4l2_decoder_alloc_request (self->decoder, - picture->system_frame_number, self->bitstream, frame->output_buffer); + GST_CODEC_PICTURE_FRAME_NUMBER (picture), self->bitstream, + frame->output_buffer); gst_video_codec_frame_unref (frame); @@ -903,11 +907,11 @@ gst_v4l2_codec_vp9_dec_duplicate_picture (GstVp9Decoder * decoder, GstVp9Picture *new_picture; GST_DEBUG_OBJECT (decoder, "Duplicate picture %u", - picture->system_frame_number); + GST_CODEC_PICTURE_FRAME_NUMBER (picture)); new_picture = gst_vp9_picture_new (); new_picture->frame_hdr = picture->frame_hdr; - new_picture->system_frame_number = frame->system_frame_number; + GST_CODEC_PICTURE_FRAME_NUMBER (new_picture) = frame->system_frame_number; if (GST_MINI_OBJECT_FLAG_IS_SET (picture, FLAG_PICTURE_HOLDS_BUFFER)) { GstBuffer *output_buffer = gst_vp9_picture_get_user_data (picture); @@ -942,16 +946,18 @@ gst_v4l2_codec_vp9_dec_output_picture (GstVp9Decoder * decoder, GstV4l2CodecVp9Dec *self = GST_V4L2_CODEC_VP9_DEC (decoder); GstVideoDecoder *vdec = GST_VIDEO_DECODER (decoder); GstV4l2Request *request = NULL; + GstCodecPicture *codec_picture = GST_CODEC_PICTURE (picture); gint ret; - if (picture->discont_state) { + if (codec_picture->discont_state) { if (!gst_video_decoder_negotiate (vdec)) { GST_ERROR_OBJECT (vdec, "Could not re-negotiate with updated state"); return FALSE; } } - GST_DEBUG_OBJECT (self, "Output picture %u", picture->system_frame_number); + GST_DEBUG_OBJECT (self, "Output picture %u", + codec_picture->system_frame_number); if (!GST_MINI_OBJECT_FLAG_IS_SET (picture, FLAG_PICTURE_HOLDS_BUFFER)) request = gst_vp9_picture_get_user_data (picture); @@ -971,7 +977,8 @@ gst_v4l2_codec_vp9_dec_output_picture (GstVp9Decoder * decoder, if (gst_v4l2_request_failed (request)) { GST_ELEMENT_ERROR (self, STREAM, DECODE, - ("Failed to decode frame %u", picture->system_frame_number), (NULL)); + ("Failed to decode frame %u", codec_picture->system_frame_number), + (NULL)); goto error; } @@ -986,7 +993,8 @@ gst_v4l2_codec_vp9_dec_output_picture (GstVp9Decoder * decoder, /* This may happen if we duplicate a picture witch failed to decode */ if (!frame->output_buffer) { GST_ELEMENT_ERROR (self, STREAM, DECODE, - ("Failed to decode frame %u", picture->system_frame_number), (NULL)); + ("Failed to decode frame %u", codec_picture->system_frame_number), + (NULL)); goto error; } diff --git a/subprojects/gst-plugins-bad/sys/va/gstvavp9dec.c b/subprojects/gst-plugins-bad/sys/va/gstvavp9dec.c index ec1c7037d4..0a60081966 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvavp9dec.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvavp9dec.c @@ -506,7 +506,8 @@ gst_va_vp9_dec_output_picture (GstVp9Decoder * decoder, GST_LOG_OBJECT (self, "Outputting picture %p", picture); - ret = gst_va_base_dec_process_output (base, frame, picture->discont_state, 0); + ret = gst_va_base_dec_process_output (base, + frame, GST_CODEC_PICTURE (picture)->discont_state, 0); gst_vp9_picture_unref (picture); if (ret)