diff --git a/libavcodec/ylc.c b/libavcodec/ylc.c index 81a57741c7..3230c56dac 100644 --- a/libavcodec/ylc.c +++ b/libavcodec/ylc.c @@ -31,6 +31,7 @@ #include "get_bits.h" #include "huffyuvdsp.h" #include "internal.h" +#include "thread.h" #include "unary.h" typedef struct YLCContext { @@ -282,6 +283,7 @@ static int decode_frame(AVCodecContext *avctx, int TL[4] = { 128, 128, 128, 128 }; int L[4] = { 128, 128, 128, 128 }; YLCContext *s = avctx->priv_data; + ThreadFrame frame = { .f = data }; const uint8_t *buf = avpkt->data; int ret, x, y, toffset, boffset; AVFrame * const p = data; @@ -303,7 +305,7 @@ static int decode_frame(AVCodecContext *avctx, if (toffset >= boffset || boffset >= avpkt->size) return AVERROR_INVALIDDATA; - if ((ret = ff_get_buffer(avctx, p, 0)) < 0) + if ((ret = ff_thread_get_buffer(avctx, &frame, 0)) < 0) return ret; av_fast_malloc(&s->table_bits, &s->table_bits_size, @@ -447,6 +449,24 @@ static int decode_frame(AVCodecContext *avctx, return avpkt->size; } +#if HAVE_THREADS +static int init_thread_copy(AVCodecContext *avctx) +{ + YLCContext *s = avctx->priv_data; + + memset(&s->vlc[0], 0, sizeof(VLC)); + memset(&s->vlc[1], 0, sizeof(VLC)); + memset(&s->vlc[2], 0, sizeof(VLC)); + memset(&s->vlc[3], 0, sizeof(VLC)); + s->table_bits = NULL; + s->table_bits_size = 0; + s->bitstream_bits = NULL; + s->bitstream_bits_size = 0; + + return 0; +} +#endif + static av_cold int decode_end(AVCodecContext *avctx) { YLCContext *s = avctx->priv_data; @@ -470,7 +490,8 @@ AVCodec ff_ylc_decoder = { .id = AV_CODEC_ID_YLC, .priv_data_size = sizeof(YLCContext), .init = decode_init, + .init_thread_copy = ONLY_IF_THREADS_ENABLED(init_thread_copy), .close = decode_end, .decode = decode_frame, - .capabilities = AV_CODEC_CAP_DR1, + .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS, };