[FFmpeg-devel] [PATCH v2] avcodec/hw_base_encode: restrict size of next_prev
Lynne
dev at lynne.ee
Sun Dec 22 21:26:18 EET 2024
On 22/12/2024 17:24, Lynne via ffmpeg-devel wrote:
> On 22/12/2024 05:25, Benjamin Cheng via ffmpeg-devel wrote:
>> Some drivers are more strict about the size of the reference lists given
>> (i.e. VAOn12 [1]). The next_prev list is used to handle multiple "L0"
>> references in AV1 encode. Restrict the size of next_prev based on the
>> value of ref_l0 when the GOP structure is initialized.
>>
>> [1] https://github.com/intel/cartwheel-ffmpeg/issues/278
>>
>> v2: fix indentation issues
>> ---
>> libavcodec/hw_base_encode.c | 7 +++++--
>> libavcodec/hw_base_encode.h | 4 ++++
>> 2 files changed, 9 insertions(+), 2 deletions(-)
>>
>> diff --git a/libavcodec/hw_base_encode.c b/libavcodec/hw_base_encode.c
>> index 4d8bf4fe71..b790091d7d 100644
>> --- a/libavcodec/hw_base_encode.c
>> +++ b/libavcodec/hw_base_encode.c
>> @@ -190,12 +190,12 @@ static void
>> hw_base_encode_add_next_prev(FFHWBaseEncodeContext *ctx,
>> return;
>> }
>> - if (ctx->nb_next_prev < MAX_PICTURE_REFERENCES) {
>> + if (ctx->nb_next_prev < ctx->ref_l0) {
>> ctx->next_prev[ctx->nb_next_prev++] = pic;
>> ++pic->ref_count[0];
>> } else {
>> --ctx->next_prev[0]->ref_count[0];
>> - for (i = 0; i < MAX_PICTURE_REFERENCES - 1; i++)
>> + for (i = 0; i < ctx->ref_l0 - 1; i++)
>> ctx->next_prev[i] = ctx->next_prev[i + 1];
>> ctx->next_prev[i] = pic;
>> ++pic->ref_count[0];
>> @@ -662,6 +662,9 @@ int
>> ff_hw_base_init_gop_structure(FFHWBaseEncodeContext *ctx,
>> AVCodecContext *av
>> uint32_t ref_l0, uint32_t ref_l1,
>> int flags, int prediction_pre_only)
>> {
>> + ctx->ref_l0 = FFMIN(ref_l0, MAX_PICTURE_REFERENCES);
>> + ctx->ref_l1 = FFMIN(ref_l1, MAX_PICTURE_REFERENCES);
>> +
>> if (flags & FF_HW_FLAG_INTRA_ONLY || avctx->gop_size <= 1) {
>> av_log(avctx, AV_LOG_VERBOSE, "Using intra frames only.\n");
>> ctx->gop_size = 1;
>> diff --git a/libavcodec/hw_base_encode.h b/libavcodec/hw_base_encode.h
>> index e30b1e60ad..e768579722 100644
>> --- a/libavcodec/hw_base_encode.h
>> +++ b/libavcodec/hw_base_encode.h
>> @@ -193,6 +193,10 @@ typedef struct FFHWBaseEncodeContext {
>> int end_of_stream;
>> int p_to_gpb;
>> + // The number of L0/L1 references supported by the driver.
>> + int ref_l0;
>> + int ref_l1;
>> +
>> // Whether the driver supports ROI at all.
>> int roi_allowed;
>
> Looks fine, I'll push this soon.
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
Thanks, pushed.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_0xA2FEA5F03F034464.asc
Type: application/pgp-keys
Size: 624 bytes
Desc: OpenPGP public key
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20241223/b9de44e3/attachment.key>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature.asc
Type: application/pgp-signature
Size: 236 bytes
Desc: OpenPGP digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20241223/b9de44e3/attachment.sig>
More information about the ffmpeg-devel
mailing list