msdkav1enc: Remove reorder TU workaround

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3225>
This commit is contained in:
Mengkejiergeli Ba 2022-10-18 03:36:23 +00:00 committed by GStreamer Marge Bot
parent 78a7c6318a
commit c989d023fd
4 changed files with 2 additions and 133 deletions

View file

@ -220,103 +220,6 @@ profile_to_string (gint profile)
return NULL;
}
static gint
gst_msdkav1enc_find_show_frame (GstMsdkAV1Enc * thiz, guint8 * data, gsize size,
gsize * offset)
{
guint8 *end;
guint32 consumed;
GstAV1OBU obu;
GstAV1ParserResult res;
if (!data || !size)
return -1;
end = data + size;
*offset = 0;
while (data < end) {
res = gst_av1_parser_identify_one_obu (thiz->parser,
data, end - data, &obu, &consumed);
if (res != GST_AV1_PARSER_OK)
return -1;
*offset += consumed;
switch (obu.obu_type) {
case GST_AV1_OBU_FRAME_HEADER:
/* check show_existing_frame flag */
if (0x80 & *(obu.data))
return 1;
case GST_AV1_OBU_FRAME:
/* check show_frame flag */
if (0x10 & *(obu.data))
return 1;
default:
break;
}
data += consumed;
}
return 0;
}
static gboolean
gst_msdkav1enc_pre_finish (GstMsdkEnc * encoder, GstBuffer ** buf,
guint8 * data, gsize size)
{
GstMsdkAV1Enc *thiz = GST_MSDKAV1ENC (encoder);
gsize offset = 0;
gint ret = 0;
gsize avail_size;
GstBuffer *adapt_buf = NULL;
*buf = NULL;
if (data && size) {
adapt_buf = gst_buffer_new_allocate (NULL, size, NULL);
gst_buffer_fill (adapt_buf, 0, data, size);
gst_adapter_push (thiz->adapter, adapt_buf);
}
avail_size = gst_adapter_available (thiz->adapter);
if (avail_size) {
guint8 *parse_data = (guint8 *) gst_adapter_map (thiz->adapter, avail_size);
ret = gst_msdkav1enc_find_show_frame (thiz,
parse_data, avail_size, &offset);
gst_adapter_unmap (thiz->adapter);
if (ret == 1) {
*buf = gst_adapter_take_buffer (thiz->adapter, offset);
return TRUE;
} else if (ret == 0) {
return TRUE;
} else {
return FALSE;
}
}
return TRUE;
}
static void
gst_msdkav1enc_flush_frames (GstMsdkEnc * encoder)
{
GstVideoCodecFrame *frame;
GstBuffer *out_buf = NULL;
while (1) {
if (!gst_msdkav1enc_pre_finish (encoder, &out_buf, NULL, 0))
break;
if (!out_buf)
break;
frame = gst_video_encoder_get_oldest_frame (GST_VIDEO_ENCODER (encoder));
frame->output_buffer = out_buf;
gst_video_codec_frame_unref (frame);
gst_video_encoder_finish_frame (GST_VIDEO_ENCODER (encoder), frame);
}
return;
}
static GstCaps *
gst_msdkav1enc_set_src_caps (GstMsdkEnc * encoder)
{
@ -407,14 +310,6 @@ gst_msdkav1enc_get_property (GObject * object, guint prop_id, GValue * value,
static void
gst_msdkav1enc_finalize (GObject * object)
{
GstMsdkAV1Enc *thiz = GST_MSDKAV1ENC (object);
if (thiz->parser)
gst_av1_parser_free (thiz->parser);
if (thiz->adapter)
gst_adapter_clear (thiz->adapter);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@ -438,8 +333,6 @@ gst_msdkav1enc_class_init (GstMsdkAV1EncClass * klass)
encoder_class->set_src_caps = gst_msdkav1enc_set_src_caps;
encoder_class->qp_max = 255;
encoder_class->qp_min = 0;
encoder_class->pre_finish = gst_msdkav1enc_pre_finish;
encoder_class->flush_frames = gst_msdkav1enc_flush_frames;
gst_msdkenc_install_common_properties (encoder_class);
@ -483,6 +376,4 @@ gst_msdkav1enc_init (GstMsdkAV1Enc * thiz)
thiz->num_tile_cols = PROP_TILE_COL_DEFAULT;
thiz->b_pyramid = PROP_B_PYRAMID_DEFAULT;
thiz->p_pyramid = PROP_P_PYRAMID_DEFAULT;
thiz->adapter = gst_adapter_new ();
thiz->parser = gst_av1_parser_new ();
}

View file

@ -64,9 +64,6 @@ struct _GstMsdkAV1Enc
mfxExtAV1BitstreamParam ext_av1_bs_param;
mfxExtAV1ResolutionParam ext_av1_res_param;
mfxExtAV1TileParam ext_av1_tile_param;
GstAdapter *adapter;
GstAV1Parser *parser;
};
struct _GstMsdkAV1EncClass

View file

@ -1067,7 +1067,6 @@ static GstFlowReturn
gst_msdkenc_finish_frame (GstMsdkEnc * thiz, MsdkEncTask * task,
gboolean discard)
{
GstMsdkEncClass *klass = GST_MSDKENC_GET_CLASS (thiz);
GstVideoCodecFrame *frame;
GList *list;
@ -1095,25 +1094,14 @@ gst_msdkenc_finish_frame (GstMsdkEnc * thiz, MsdkEncTask * task,
task->output_bitstream.Data + task->output_bitstream.DataOffset;
gsize size = task->output_bitstream.DataLength;
if (klass->pre_finish) {
if (!klass->pre_finish (thiz, &out_buf, data, size))
return GST_FLOW_ERROR;
if (!out_buf) {
gst_msdkenc_reset_task (task);
g_list_free_full (list, (GDestroyNotify) gst_video_codec_frame_unref);
return GST_FLOW_OK;
}
} else {
out_buf = gst_buffer_new_allocate (NULL, size, NULL);
gst_buffer_fill (out_buf, 0, data, size);
}
frame = gst_msdkenc_find_best_frame (thiz, list, &task->output_bitstream);
if (!frame) {
/* just pick the oldest one */
frame = gst_video_encoder_get_oldest_frame (GST_VIDEO_ENCODER (thiz));
}
out_buf = gst_buffer_new_allocate (NULL, size, NULL);
gst_buffer_fill (out_buf, 0, data, size);
frame->output_buffer = out_buf;
frame->pts =
gst_util_uint64_scale (task->output_bitstream.TimeStamp, GST_SECOND,
@ -1234,7 +1222,6 @@ gst_msdkenc_flush_frames (GstMsdkEnc * thiz, gboolean discard)
mfxSession session;
MsdkEncTask *task;
guint i, t;
GstMsdkEncClass *klass = GST_MSDKENC_GET_CLASS (thiz);
if (!thiz->tasks)
return;
@ -1268,8 +1255,6 @@ gst_msdkenc_flush_frames (GstMsdkEnc * thiz, gboolean discard)
gst_msdkenc_finish_frame (thiz, &thiz->tasks[t], discard);
t = (t + 1) % thiz->num_tasks;
}
if (klass->flush_frames)
klass->flush_frames (thiz);
}
static gboolean

View file

@ -194,10 +194,6 @@ struct _GstMsdkEncClass
/* Allow sub class set extra frame parameters */
void (*set_extra_params) (GstMsdkEnc * encoder, GstVideoCodecFrame * frame);
gboolean (*pre_finish) (GstMsdkEnc * encoder, GstBuffer **buf,
guint8 *data, gsize size);
void (*flush_frames) (GstMsdkEnc * encoder);
guint qp_max;
guint qp_min;
};