• Hendrik Leppkes's avatar
    avcodec: disallow hwaccel with frame threads · 31741aec
    Hendrik Leppkes authored
    HWAccels with frame threads are fundamentally flawed in avcodecs current
    design, and there are several known problems ranging from image corruption
    to driver crashes.
    
    These problems come down to two design problems in the interaction of
    threads and HWAccel decoding:
    
    (1)
    While avcodec prevents parallel decoding and as such simultaneous access
    to the hardware accelerator from the decoding threads, it cannot account
    for the user code and its access to the hardware surfaces and the hardware
    itself.
    
    This can result in image corruption or even driver crashes if the
    user code locks image surfaces while they are being used by the decoder
    threads as reference frames.
    
    The current HWAccel API does not offer any way to ensure exclusive access
    to the hardware or the surfaces if frame threading is used.
    
    (2)
    Initialization of the HWAccel with frame threads is non-trivial, and many
    decoders had and still have issues that cause excess calls to the
    get_format callback.
    
    This will potentially cause duplicate HWAccel initialization, which in
    extreme cases can even lead to driver crashes if the HWAccel is
    re-initialized while the user code is actively accessing the hardware
    surfaces associated with it, or lead to image corruption due to lost
    reference frames.
    
    While both of these issues are solvable, fixing (1) would at least require
    a huge API redesign which would move a lot of complexity into the user
    code.
    
    The only reason the combination of frame threads and HWAccel was
    considered useful is to allow a seamless fallback to multi-threaded
    software decoding if the HWAccel is not available, however the issues
    outlined above far outweigh this.
    
    The proper solution for a fallback is to re-open the AVCodecContext with
    threading enabled if the HWAccel failed, which is a practice commonly used
    by various user applications using avcodec today already.
    Reviewed-by: 's avatarGwenole Beauchesne <gb.devel@gmail.com>
    Reviewed-by: 's avatarwm4 <nfxjfg@googlemail.com>
    Signed-off-by: 's avatarHendrik Leppkes <h.leppkes@gmail.com>
    31741aec
Name
Last commit
Last update
compat Loading commit data...
doc Loading commit data...
libavcodec Loading commit data...
libavdevice Loading commit data...
libavfilter Loading commit data...
libavformat Loading commit data...
libavresample Loading commit data...
libavutil Loading commit data...
libpostproc Loading commit data...
libswresample Loading commit data...
libswscale Loading commit data...
presets Loading commit data...
tests Loading commit data...
tools Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
.travis.yml Loading commit data...
COPYING.GPLv2 Loading commit data...
COPYING.GPLv3 Loading commit data...
COPYING.LGPLv2.1 Loading commit data...
COPYING.LGPLv3 Loading commit data...
CREDITS Loading commit data...
Changelog Loading commit data...
INSTALL.md Loading commit data...
LICENSE.md Loading commit data...
MAINTAINERS Loading commit data...
Makefile Loading commit data...
README.md Loading commit data...
RELEASE Loading commit data...
arch.mak Loading commit data...
cmdutils.c Loading commit data...
cmdutils.h Loading commit data...
cmdutils_common_opts.h Loading commit data...
cmdutils_opencl.c Loading commit data...
common.mak Loading commit data...
configure Loading commit data...
ffmpeg.c Loading commit data...
ffmpeg.h Loading commit data...
ffmpeg_dxva2.c Loading commit data...
ffmpeg_filter.c Loading commit data...
ffmpeg_opt.c Loading commit data...
ffmpeg_qsv.c Loading commit data...
ffmpeg_vdpau.c Loading commit data...
ffmpeg_videotoolbox.c Loading commit data...
ffplay.c Loading commit data...
ffprobe.c Loading commit data...
ffserver.c Loading commit data...
ffserver_config.c Loading commit data...
ffserver_config.h Loading commit data...
library.mak Loading commit data...
version.sh Loading commit data...