[FFmpeg-devel] [PATCH] avcodec/decode: Return EAGAIN instead of overwriting unused packet

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Mon Jul 10 17:25:04 EEST 2023


Anton Khirnov:
> Quoting Andreas Rheinhardt (2023-07-10 01:36:41)
>> Should fix #10457, a regression caused by
>> 69516ab3e917a6e91d26e38d04183c60fd71cbab.
>>
>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
>> ---
>> I am not sure about this one. The problem is that avcodec_send_packet()
>> and avcodec_receive_frame() must not return EAGAIN at the same time.
>> If buffer_frame contains a frame when entering avcodec_send_packet(),
>> the next call to avcodec_receive_frame() will not return EAGAIN.
>> But is this actually guaranteed if buffer_pkt is not empty?
> 
> It's not guaranteed, but I believe the correct interpretation of the
> "must not return EAGAIN at the same time" line is that
> send->receive->send must make progress and not be 3x EAGAIN.
> 
> 
>>
>>  libavcodec/decode.c | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>> diff --git a/libavcodec/decode.c b/libavcodec/decode.c
>> index 269633ce10..6595c3ca34 100644
>> --- a/libavcodec/decode.c
>> +++ b/libavcodec/decode.c
>> @@ -666,6 +666,9 @@ int attribute_align_arg avcodec_send_packet(AVCodecContext *avctx, const AVPacke
>>      if (avpkt && !avpkt->size && avpkt->data)
>>          return AVERROR(EINVAL);
>>  
>> +    if (!AVPACKET_IS_EMPTY(avci->buffer_pkt))
>> +        return AVERROR(EAGAIN);
>> +
>>      av_packet_unref(avci->buffer_pkt);
> 
> This unref here becomes redundant.
> 
> Otherwise looks good, thanks.
> 

Will apply with the unref removed.

- Andreas



More information about the ffmpeg-devel mailing list