mirror of https://git.ffmpeg.org/ffmpeg.git
avcodec/mpegvideo_enc: Make mpv_encode_defaults thread-safe
This is a prerequisite for making any encoder that uses ff_mpv_encode_init() init-threadsafe; it already makes the AMV, the MJPEG and the MPEG-1/2 encoders init-threadsafe. Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
This commit is contained in:
parent
27eea249cc
commit
44bb776f13
|
@ -415,7 +415,7 @@ AVCodec ff_mjpeg_encoder = {
|
|||
.encode2 = ff_mpv_encode_picture,
|
||||
.close = ff_mpv_encode_end,
|
||||
.capabilities = AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_FRAME_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_YUVJ420P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_NONE
|
||||
},
|
||||
|
@ -441,7 +441,7 @@ AVCodec ff_amv_encoder = {
|
|||
.init = ff_mpv_encode_init,
|
||||
.encode2 = amv_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_YUVJ420P, AV_PIX_FMT_NONE
|
||||
},
|
||||
|
|
|
@ -1199,7 +1199,7 @@ AVCodec ff_mpeg1video_encoder = {
|
|||
.pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P,
|
||||
AV_PIX_FMT_NONE },
|
||||
.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SLICE_THREADS,
|
||||
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
|
||||
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
|
||||
.priv_class = &mpeg1_class,
|
||||
};
|
||||
|
||||
|
@ -1217,7 +1217,7 @@ AVCodec ff_mpeg2video_encoder = {
|
|||
AV_PIX_FMT_YUV422P,
|
||||
AV_PIX_FMT_NONE },
|
||||
.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SLICE_THREADS,
|
||||
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
|
||||
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
|
||||
.priv_class = &mpeg2_class,
|
||||
};
|
||||
#endif /* CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER */
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include "libavutil/mem_internal.h"
|
||||
#include "libavutil/pixdesc.h"
|
||||
#include "libavutil/opt.h"
|
||||
#include "libavutil/thread.h"
|
||||
#include "avcodec.h"
|
||||
#include "dct.h"
|
||||
#include "idctdsp.h"
|
||||
|
@ -249,18 +250,24 @@ static void update_duplicate_context_after_me(MpegEncContext *dst,
|
|||
#undef COPY
|
||||
}
|
||||
|
||||
static void mpv_encode_init_static(void)
|
||||
{
|
||||
for (int i = -16; i < 16; i++)
|
||||
default_fcode_tab[i + MAX_MV] = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the given MpegEncContext to defaults for encoding.
|
||||
* the changed fields will not depend upon the prior state of the MpegEncContext.
|
||||
*/
|
||||
static void mpv_encode_defaults(MpegEncContext *s)
|
||||
{
|
||||
int i;
|
||||
static AVOnce init_static_once = AV_ONCE_INIT;
|
||||
|
||||
ff_mpv_common_defaults(s);
|
||||
|
||||
for (i = -16; i < 16; i++) {
|
||||
default_fcode_tab[i + MAX_MV] = 1;
|
||||
}
|
||||
ff_thread_once(&init_static_once, mpv_encode_init_static);
|
||||
|
||||
s->me.mv_penalty = default_mv_penalty;
|
||||
s->fcode_tab = default_fcode_tab;
|
||||
|
||||
|
|
Loading…
Reference in New Issue