diff mbox series

[FFmpeg-devel,44/45] avcodec/tiff: Make decoder init-threadsafe

Message ID 20201127010249.2724610-44-andreas.rheinhardt@gmail.com
State Accepted
Commit 1d2d91d1cfbd3fe31b1fbf84822aca5bc8187ac6
Headers show
Series [FFmpeg-devel,01/45] avcodec/a64multienc: Fix memleak upon init failure | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Nov. 27, 2020, 1:02 a.m. UTC
The only thing that stands in the way of adding the
FF_CODEC_CAP_INIT_THREADSAFE flag to the TIFF decoder is its usage
of ff_codec_open2_recursive(): This function requires its caller to hold
the lock for the mutex that guards initialization of AVCodecContexts
whose codecs have a non-threadsafe init function and only callers whose
codec does not have the FF_CODEC_CAP_INIT_THREADSAFE flag set hold said
lock (the others don't need to care about said lock). But one can set
the flag if one switches to avcodec_open2() at the same time.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/tiff.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Anton Khirnov Dec. 4, 2020, 12:11 p.m. UTC | #1
Quoting Andreas Rheinhardt (2020-11-27 02:02:48)
> The only thing that stands in the way of adding the
> FF_CODEC_CAP_INIT_THREADSAFE flag to the TIFF decoder is its usage
> of ff_codec_open2_recursive(): This function requires its caller to hold
> the lock for the mutex that guards initialization of AVCodecContexts
> whose codecs have a non-threadsafe init function and only callers whose
> codec does not have the FF_CODEC_CAP_INIT_THREADSAFE flag set hold said
> lock (the others don't need to care about said lock). But one can set
> the flag if one switches to avcodec_open2() at the same time.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavcodec/tiff.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Ok
diff mbox series

Patch

diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index 2e45464218..fa1f44ce1d 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -2168,7 +2168,7 @@  static av_cold int tiff_init(AVCodecContext *avctx)
     s->avctx_mjpeg->flags2 = avctx->flags2;
     s->avctx_mjpeg->dct_algo = avctx->dct_algo;
     s->avctx_mjpeg->idct_algo = avctx->idct_algo;
-    ret = ff_codec_open2_recursive(s->avctx_mjpeg, codec, NULL);
+    ret = avcodec_open2(s->avctx_mjpeg, codec, NULL);
     if (ret < 0) {
         return ret;
     }
@@ -2219,6 +2219,6 @@  AVCodec ff_tiff_decoder = {
     .close          = tiff_end,
     .decode         = decode_frame,
     .capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
-    .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
+    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
     .priv_class     = &tiff_decoder_class,
 };