History

lavc/vaapi_encode_av1: implement write_extra_header callback

This can be used to insert a metadata OBU to the stream later.

Haihao Xiang committed 2 years ago

Commit 7f3ba6b1 parent 9c6c4f31 file · +41 −1Browse files

Unified · Split

libavcodec/vaapi_encode_av1.c+41−1
@@ -41,6 +41,8 @@ typedef struct VAAPIEncodeAV1Context { · 40 unmodified lines
4141 VAAPIEncodeContext common;
4242 AV1RawOBU sh; /**< sequence header.*/
4343 AV1RawOBU fh; /**< frame header.*/
44+ AV1RawOBU mh[4]; /**< metadata header.*/
45+ int nb_mh;
4446 CodedBitstreamContext *cbc;
4547 CodedBitstreamFragment current_obu;
4648 VAConfigAttribValEncAV1 attr;
@@ -659,6 +661,8 @@ static int vaapi_encode_av1_init_picture_params(AVCodecContext *avctx, · 612 unmodified lines
659661 2 : 1));
660662 }
661663
664+ priv->nb_mh = 0;
665+
662666 end:
663667 ff_cbs_fragment_reset(obu);
664668 return ret;
@@ -735,6 +739,39 @@ end: · 70 unmodified lines
735739 return ret;
736740 }
737741
742+static int vaapi_encode_av1_write_extra_header(AVCodecContext *avctx,
743+ VAAPIEncodePicture *pic,
744+ int index, int *type,
745+ char *data, size_t *data_len)
746+{
747+ VAAPIEncodeAV1Context *priv = avctx->priv_data;
748+ CodedBitstreamFragment *obu = &priv->current_obu;
749+ AV1RawOBU *mh_obu;
750+ char mh_data[MAX_PARAM_BUFFER_SIZE];
751+ size_t mh_data_len;
752+ int ret = 0;
753+
754+ if (index >= priv->nb_mh)
755+ return AVERROR_EOF;
756+
757+ mh_obu = &priv->mh[index];
758+ ret = vaapi_encode_av1_add_obu(avctx, obu, AV1_OBU_METADATA, mh_obu);
759+ if (ret < 0)
760+ goto end;
761+
762+ ret = vaapi_encode_av1_write_obu(avctx, mh_data, &mh_data_len, obu);
763+ if (ret < 0)
764+ goto end;
765+
766+ memcpy(data, mh_data, MAX_PARAM_BUFFER_SIZE * sizeof(char));
767+ *data_len = mh_data_len;
768+ *type = VAEncPackedHeaderRawData;
769+
770+end:
771+ ff_cbs_fragment_reset(obu);
772+ return ret;
773+}
774+
738775 static const VAAPIEncodeProfile vaapi_encode_av1_profiles[] = {
739776 { AV_PROFILE_AV1_MAIN, 8, 3, 1, 1, VAProfileAV1Profile0 },
740777 { AV_PROFILE_AV1_MAIN, 10, 3, 1, 1, VAProfileAV1Profile0 },
@@ -762,6 +799,8 @@ static const VAAPIEncodeType vaapi_encode_type_av1 = { · 21 unmodified lines
762799
763800 .slice_params_size = sizeof(VAEncTileGroupBufferAV1),
764801 .init_slice_params = &vaapi_encode_av1_init_slice_params,
802+
803+ .write_extra_header = &vaapi_encode_av1_write_extra_header,
765804 };
766805
767806 static av_cold int vaapi_encode_av1_init(AVCodecContext *avctx)
@@ -776,7 +815,8 @@ static av_cold int vaapi_encode_av1_init(AVCodecContext *avctx) · 8 unmodified lines
776815
777816 ctx->desired_packed_headers =
778817 VA_ENC_PACKED_HEADER_SEQUENCE |
779− VA_ENC_PACKED_HEADER_PICTURE;
818+ VA_ENC_PACKED_HEADER_PICTURE |
819+ VA_ENC_PACKED_HEADER_MISC; // Metadata
780820
781821 if (avctx->profile == AV_PROFILE_UNKNOWN)
782822 avctx->profile = priv->profile;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t