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 | 41 | VAAPIEncodeContext common; |
| 42 | 42 | AV1RawOBU sh; /**< sequence header.*/ |
| 43 | 43 | AV1RawOBU fh; /**< frame header.*/ |
| 44 | + AV1RawOBU mh[4]; /**< metadata header.*/ | |
| 45 | + int nb_mh; | |
| 44 | 46 | CodedBitstreamContext *cbc; |
| 45 | 47 | CodedBitstreamFragment current_obu; |
| 46 | 48 | VAConfigAttribValEncAV1 attr; |
| @@ -659,6 +661,8 @@ static int vaapi_encode_av1_init_picture_params(AVCodecContext *avctx, · 612 unmodified lines | ||
| 659 | 661 | 2 : 1)); |
| 660 | 662 | } |
| 661 | 663 | |
| 664 | + priv->nb_mh = 0; | |
| 665 | + | |
| 662 | 666 | end: |
| 663 | 667 | ff_cbs_fragment_reset(obu); |
| 664 | 668 | return ret; |
| @@ -735,6 +739,39 @@ end: · 70 unmodified lines | ||
| 735 | 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 | 775 | static const VAAPIEncodeProfile vaapi_encode_av1_profiles[] = { |
| 739 | 776 | { AV_PROFILE_AV1_MAIN, 8, 3, 1, 1, VAProfileAV1Profile0 }, |
| 740 | 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 | 800 | .slice_params_size = sizeof(VAEncTileGroupBufferAV1), |
| 764 | 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 | 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 | 816 | ctx->desired_packed_headers = |
| 778 | 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 | 821 | if (avctx->profile == AV_PROFILE_UNKNOWN) |
| 782 | 822 | avctx->profile = priv->profile; |