[FFmpeg-devel] [PATCH 2/2] lavc/pthread_frame: avoid leaving stale hwaccel state in worker threads

Marvin Scholz epirat07 at gmail.com
Thu Sep 15 11:12:09 EEST 2022


On 12 Sep 2022, at 8:59, Wang Bin wrote:

> Wang Bin <wbsecg1 at gmail.com> 于2022年9月12日周一 10:02写道:
>
>>
>>>      av_packet_unref(p->avpkt);
>>> @@ -655,6 +670,14 @@ void ff_thread_finish_setup(AVCodecContext *avctx) {
>>>          async_lock(p->parent);
>>>      }
>>>
>>> +    /* save hwaccel state for passing to the next thread;
>>> +     * this is done here so that this worker thread can wipe its own
>>> hwaccel
>>> +     * state after decoding, without requiring synchronization */
>>> +    av_assert0(!p->parent->stash_hwaccel);
>>> +    p->parent->stash_hwaccel         = avctx->hwaccel;
>>> +    p->parent->stash_hwaccel_context = avctx->hwaccel_context;
>>> +    p->parent->stash_hwaccel_priv    =
>>> avctx->internal->hwaccel_priv_data;
>>>
>>
>> Assertion failure when seeking. Step to reproduce:
>> ./ffmpeg -stream_loop -1 -an -hwaccel vaapi -i test.mp4 -f null >/dev/null
>>
>> Regards
>>
>>
>
> The change breaks hwaccel on all platforms. videotoolbox has another crash.
>

Can confirm this breaks videotoolbox, to reproduce simply do:

./ffmpeg -v debug -hwaccel videotoolbox -i ~/Downloads/HDR\ Mix\ 8k\ Dolby\ Vision-sLs6yYYDpTw.webm  -f null /dev/null

Trace:

* thread #30, name = 'com.apple.coremedia.rootQueue.47', queue = 'vtdecoder-callback-queue-0x10331f520', stop reason = EXC_BAD_ACCESS (code=1, address=0x10)
    frame #0: 0x0000000100d376b8 ffmpeg_g`videotoolbox_decoder_callback(opaque=0x0000000108c079c0, sourceFrameRefCon=0x0000000000000000, status=0, flags=0, image_buffer=0x0000600003300000, pts=CMTime @ 0x0000700005db5a00, duration=0 seconds) at videotoolbox.c:696:16 [opt]
   693 	    AVCodecContext *avctx = opaque;
   694 	    VTContext *vtctx = avctx->internal->hwaccel_priv_data;
   695 	
-> 696 	    if (vtctx->frame) {
   697 	        CVPixelBufferRelease(vtctx->frame);
   698 	        vtctx->frame = NULL;
   699 	    }
Target 0: (ffmpeg_g) stopped.

The hwaccel_priv_data is NULL here. It works fine when using -threads 1.

> Regards
> _______________________________________________
> 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".


More information about the ffmpeg-devel mailing list