mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-08 13:22:53 +02:00
avcodec/ituh263enc: Make static initializations thread-safe
This already makes several encoders (namely FLV, H.263, H.263+ and
RealVideo 1.0 and 2.0 and SVQ1) that use this init-threadsafe.
It also makes the Snow encoder init-threadsafe; it was already marked
as such since commit d49210788b
, because
it was thought to be harmless if one and the same object was
initialized by multiple threads at the same time.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
This commit is contained in:
parent
ad184c8e36
commit
fea1f42e5f
@ -107,7 +107,7 @@ AVCodec ff_flv_encoder = {
|
||||
.init = ff_mpv_encode_init,
|
||||
.encode2 = ff_mpv_encode_picture,
|
||||
.close = ff_mpv_encode_end,
|
||||
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
|
||||
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
|
||||
.pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P,
|
||||
AV_PIX_FMT_NONE},
|
||||
.priv_class = &flv_class,
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include <limits.h>
|
||||
|
||||
#include "libavutil/attributes.h"
|
||||
#include "libavutil/thread.h"
|
||||
#include "avcodec.h"
|
||||
#include "mpegvideo.h"
|
||||
#include "mpegvideodata.h"
|
||||
@ -671,7 +672,7 @@ void ff_h263_encode_motion(PutBitContext *pb, int val, int f_code)
|
||||
}
|
||||
}
|
||||
|
||||
static av_cold void init_mv_penalty_and_fcode(MpegEncContext *s)
|
||||
static av_cold void init_mv_penalty_and_fcode(void)
|
||||
{
|
||||
int f_code;
|
||||
int mv;
|
||||
@ -754,22 +755,23 @@ static av_cold void init_uni_h263_rl_tab(const RLTable *rl, uint8_t *len_tab)
|
||||
}
|
||||
}
|
||||
|
||||
static av_cold void h263_encode_init_static(void)
|
||||
{
|
||||
static uint8_t rl_intra_table[2][2 * MAX_RUN + MAX_LEVEL + 3];
|
||||
|
||||
ff_rl_init(&ff_rl_intra_aic, rl_intra_table);
|
||||
ff_h263_init_rl_inter();
|
||||
|
||||
init_uni_h263_rl_tab(&ff_rl_intra_aic, uni_h263_intra_aic_rl_len);
|
||||
init_uni_h263_rl_tab(&ff_h263_rl_inter, uni_h263_inter_rl_len);
|
||||
|
||||
init_mv_penalty_and_fcode();
|
||||
}
|
||||
|
||||
av_cold void ff_h263_encode_init(MpegEncContext *s)
|
||||
{
|
||||
static int done = 0;
|
||||
static AVOnce init_static_once = AV_ONCE_INIT;
|
||||
|
||||
if (!done) {
|
||||
static uint8_t rl_intra_table[2][2 * MAX_RUN + MAX_LEVEL + 3];
|
||||
done = 1;
|
||||
|
||||
ff_rl_init(&ff_rl_intra_aic, rl_intra_table);
|
||||
ff_h263_init_rl_inter();
|
||||
|
||||
init_uni_h263_rl_tab(&ff_rl_intra_aic, uni_h263_intra_aic_rl_len);
|
||||
init_uni_h263_rl_tab(&ff_h263_rl_inter, uni_h263_inter_rl_len);
|
||||
|
||||
init_mv_penalty_and_fcode(s);
|
||||
}
|
||||
s->me.mv_penalty= mv_penalty; // FIXME exact table for MSMPEG4 & H.263+
|
||||
|
||||
s->intra_ac_vlc_length =s->inter_ac_vlc_length = uni_h263_inter_rl_len;
|
||||
@ -817,6 +819,8 @@ av_cold void ff_h263_encode_init(MpegEncContext *s)
|
||||
s->y_dc_scale_table=
|
||||
s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
|
||||
}
|
||||
|
||||
ff_thread_once(&init_static_once, h263_encode_init_static);
|
||||
}
|
||||
|
||||
void ff_h263_encode_mba(MpegEncContext *s)
|
||||
|
@ -4738,7 +4738,7 @@ AVCodec ff_h263_encoder = {
|
||||
.init = ff_mpv_encode_init,
|
||||
.encode2 = ff_mpv_encode_picture,
|
||||
.close = ff_mpv_encode_end,
|
||||
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
|
||||
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
|
||||
.pix_fmts= (const enum AVPixelFormat[]){AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE},
|
||||
.priv_class = &h263_class,
|
||||
};
|
||||
@ -4774,7 +4774,7 @@ AVCodec ff_h263p_encoder = {
|
||||
.encode2 = ff_mpv_encode_picture,
|
||||
.close = ff_mpv_encode_end,
|
||||
.capabilities = AV_CODEC_CAP_SLICE_THREADS,
|
||||
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
|
||||
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
|
||||
.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
|
||||
.priv_class = &h263p_class,
|
||||
};
|
||||
|
@ -79,7 +79,7 @@ AVCodec ff_rv10_encoder = {
|
||||
.init = ff_mpv_encode_init,
|
||||
.encode2 = ff_mpv_encode_picture,
|
||||
.close = ff_mpv_encode_end,
|
||||
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
|
||||
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
|
||||
.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
|
||||
.priv_class = &rv10_class,
|
||||
};
|
||||
|
@ -76,7 +76,7 @@ AVCodec ff_rv20_encoder = {
|
||||
.init = ff_mpv_encode_init,
|
||||
.encode2 = ff_mpv_encode_picture,
|
||||
.close = ff_mpv_encode_end,
|
||||
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
|
||||
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
|
||||
.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
|
||||
.priv_class = &rv20_class,
|
||||
};
|
||||
|
@ -688,7 +688,7 @@ AVCodec ff_svq1_encoder = {
|
||||
.init = svq1_encode_init,
|
||||
.encode2 = svq1_encode_frame,
|
||||
.close = svq1_encode_end,
|
||||
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
|
||||
.pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV410P,
|
||||
AV_PIX_FMT_NONE },
|
||||
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user