mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-04-14 00:58:38 +02:00
avcodec/mobiclip: Make decoder init-threadsafe
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
This commit is contained in:
parent
866c2ef183
commit
ee1ddd308b
@ -23,6 +23,7 @@
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
#include "libavutil/avassert.h"
|
#include "libavutil/avassert.h"
|
||||||
|
#include "libavutil/thread.h"
|
||||||
|
|
||||||
#include "avcodec.h"
|
#include "avcodec.h"
|
||||||
#include "bytestream.h"
|
#include "bytestream.h"
|
||||||
@ -274,8 +275,32 @@ typedef struct MobiClipContext {
|
|||||||
static VLC rl_vlc[2];
|
static VLC rl_vlc[2];
|
||||||
static VLC mv_vlc[2][16];
|
static VLC mv_vlc[2][16];
|
||||||
|
|
||||||
|
static av_cold void mobiclip_init_static(void)
|
||||||
|
{
|
||||||
|
INIT_VLC_STATIC_FROM_LENGTHS(&rl_vlc[0], MOBI_RL_VLC_BITS, 104,
|
||||||
|
bits0, sizeof(*bits0),
|
||||||
|
syms0, sizeof(*syms0), sizeof(*syms0),
|
||||||
|
0, 0, 1 << MOBI_RL_VLC_BITS);
|
||||||
|
INIT_VLC_STATIC_FROM_LENGTHS(&rl_vlc[1], MOBI_RL_VLC_BITS, 104,
|
||||||
|
bits0, sizeof(*bits0),
|
||||||
|
syms1, sizeof(*syms1), sizeof(*syms1),
|
||||||
|
0, 0, 1 << MOBI_RL_VLC_BITS);
|
||||||
|
for (int i = 0; i < 2; i++) {
|
||||||
|
static VLC_TYPE vlc_buf[2 * 16 << MOBI_MV_VLC_BITS][2];
|
||||||
|
for (int j = 0; j < 16; j++) {
|
||||||
|
mv_vlc[i][j].table = &vlc_buf[(16 * i + j) << MOBI_MV_VLC_BITS];
|
||||||
|
mv_vlc[i][j].table_allocated = 1 << MOBI_MV_VLC_BITS;
|
||||||
|
ff_init_vlc_from_lengths(&mv_vlc[i][j], MOBI_MV_VLC_BITS, mv_len[j],
|
||||||
|
mv_bits[i][j], sizeof(*mv_bits[i][j]),
|
||||||
|
mv_syms[i][j], sizeof(*mv_syms[i][j]), sizeof(*mv_syms[i][j]),
|
||||||
|
0, INIT_VLC_USE_NEW_STATIC, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static av_cold int mobiclip_init(AVCodecContext *avctx)
|
static av_cold int mobiclip_init(AVCodecContext *avctx)
|
||||||
{
|
{
|
||||||
|
static AVOnce init_static_once = AV_ONCE_INIT;
|
||||||
MobiClipContext *s = avctx->priv_data;
|
MobiClipContext *s = avctx->priv_data;
|
||||||
|
|
||||||
if (avctx->width & 15 || avctx->height & 15) {
|
if (avctx->width & 15 || avctx->height & 15) {
|
||||||
@ -298,25 +323,7 @@ static av_cold int mobiclip_init(AVCodecContext *avctx)
|
|||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
INIT_VLC_STATIC_FROM_LENGTHS(&rl_vlc[0], MOBI_RL_VLC_BITS, 104,
|
ff_thread_once(&init_static_once, mobiclip_init_static);
|
||||||
bits0, sizeof(*bits0),
|
|
||||||
syms0, sizeof(*syms0), sizeof(*syms0),
|
|
||||||
0, 0, 1 << MOBI_RL_VLC_BITS);
|
|
||||||
INIT_VLC_STATIC_FROM_LENGTHS(&rl_vlc[1], MOBI_RL_VLC_BITS, 104,
|
|
||||||
bits0, sizeof(*bits0),
|
|
||||||
syms1, sizeof(*syms1), sizeof(*syms1),
|
|
||||||
0, 0, 1 << MOBI_RL_VLC_BITS);
|
|
||||||
for (int i = 0; i < 2; i++) {
|
|
||||||
static VLC_TYPE vlc_buf[2 * 16 << MOBI_MV_VLC_BITS][2];
|
|
||||||
for (int j = 0; j < 16; j++) {
|
|
||||||
mv_vlc[i][j].table = &vlc_buf[(16 * i + j) << MOBI_MV_VLC_BITS];
|
|
||||||
mv_vlc[i][j].table_allocated = 1 << MOBI_MV_VLC_BITS;
|
|
||||||
ff_init_vlc_from_lengths(&mv_vlc[i][j], MOBI_MV_VLC_BITS, mv_len[j],
|
|
||||||
mv_bits[i][j], sizeof(*mv_bits[i][j]),
|
|
||||||
mv_syms[i][j], sizeof(*mv_syms[i][j]), sizeof(*mv_syms[i][j]),
|
|
||||||
0, INIT_VLC_USE_NEW_STATIC, NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1343,5 +1350,5 @@ AVCodec ff_mobiclip_decoder = {
|
|||||||
.flush = mobiclip_flush,
|
.flush = mobiclip_flush,
|
||||||
.close = mobiclip_close,
|
.close = mobiclip_close,
|
||||||
.capabilities = AV_CODEC_CAP_DR1,
|
.capabilities = AV_CODEC_CAP_DR1,
|
||||||
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
|
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user