This can be used to insert a metadata OBU to the stream later.
Unified · Split
| @@ -41,6 +41,8 @@ typedef struct VAAPIEncodeAV1Context { · 40 unmodified lines | |||
| 41 | VAAPIEncodeContext common; | 41 | VAAPIEncodeContext common; |
| 42 | AV1RawOBU sh; /**< sequence header.*/ | 42 | AV1RawOBU sh; /**< sequence header.*/ |
| 43 | AV1RawOBU fh; /**< frame header.*/ | 43 | AV1RawOBU fh; /**< frame header.*/ |
| 44 | AV1RawOBU mh[4]; /**< metadata header.*/ | ||
| 45 | int nb_mh; | ||
| 44 | CodedBitstreamContext *cbc; | 46 | CodedBitstreamContext *cbc; |
| 45 | CodedBitstreamFragment current_obu; | 47 | CodedBitstreamFragment current_obu; |
| 46 | VAConfigAttribValEncAV1 attr; | 48 | VAConfigAttribValEncAV1 attr; |
| @@ -659,6 +661,8 @@ static int vaapi_encode_av1_init_picture_params(AVCodecContext *avctx, · 612 unmodified lines | |||
| 659 | 2 : 1)); | 661 | 2 : 1)); |
| 660 | } | 662 | } |
| 661 | 663 | ||
| 664 | priv->nb_mh = 0; | ||
| 665 | |||
| 662 | end: | 666 | end: |
| 663 | ff_cbs_fragment_reset(obu); | 667 | ff_cbs_fragment_reset(obu); |
| 664 | return ret; | 668 | return ret; |
| @@ -735,6 +739,39 @@ end: · 70 unmodified lines | |||
| 735 | return ret; | 739 | return ret; |
| 736 | } | 740 | } |
| 737 | 741 | ||
| 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 | |||
| 738 | static const VAAPIEncodeProfile vaapi_encode_av1_profiles[] = { | 775 | static const VAAPIEncodeProfile vaapi_encode_av1_profiles[] = { |
| 739 | { AV_PROFILE_AV1_MAIN, 8, 3, 1, 1, VAProfileAV1Profile0 }, | 776 | { AV_PROFILE_AV1_MAIN, 8, 3, 1, 1, VAProfileAV1Profile0 }, |
| 740 | { AV_PROFILE_AV1_MAIN, 10, 3, 1, 1, VAProfileAV1Profile0 }, | 777 | { AV_PROFILE_AV1_MAIN, 10, 3, 1, 1, VAProfileAV1Profile0 }, |
| @@ -762,6 +799,8 @@ static const VAAPIEncodeType vaapi_encode_type_av1 = { · 21 unmodified lines | |||
| 762 | 799 | ||
| 763 | .slice_params_size = sizeof(VAEncTileGroupBufferAV1), | 800 | .slice_params_size = sizeof(VAEncTileGroupBufferAV1), |
| 764 | .init_slice_params = &vaapi_encode_av1_init_slice_params, | 801 | .init_slice_params = &vaapi_encode_av1_init_slice_params, |
| 802 | |||
| 803 | .write_extra_header = &vaapi_encode_av1_write_extra_header, | ||
| 765 | }; | 804 | }; |
| 766 | 805 | ||
| 767 | static av_cold int vaapi_encode_av1_init(AVCodecContext *avctx) | 806 | 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 | |||
| 776 | 815 | ||
| 777 | ctx->desired_packed_headers = | 816 | ctx->desired_packed_headers = |
| 778 | VA_ENC_PACKED_HEADER_SEQUENCE | | 817 | VA_ENC_PACKED_HEADER_SEQUENCE | |
| 779 | VA_ENC_PACKED_HEADER_PICTURE; | 818 | VA_ENC_PACKED_HEADER_PICTURE | |
| 819 | VA_ENC_PACKED_HEADER_MISC; // Metadata | ||
| 780 | 820 | ||
| 781 | if (avctx->profile == AV_PROFILE_UNKNOWN) | 821 | if (avctx->profile == AV_PROFILE_UNKNOWN) |
| 782 | avctx->profile = priv->profile; | 822 | avctx->profile = priv->profile; |