You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-15 14:13:16 +02:00
avcodec/mpeg4video: Make initializing RLTable thread-safe
Up until now the RLTable ff_mpeg4_rl_intra was initialized by both mpeg4 decoder and encoder (except the VLCs that are only used by the decoder). This is an obstacle to making these codecs init-threadsafe, so move initializing this to a single function that is guarded by a dedicated AVOnce. Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
This commit is contained in:
committed by
Andreas Rheinhardt
parent
fea1f42e5f
commit
d99707b42a
@@ -20,12 +20,24 @@
|
|||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "libavutil/thread.h"
|
||||||
|
|
||||||
#include "mpegutils.h"
|
#include "mpegutils.h"
|
||||||
#include "mpegvideo.h"
|
#include "mpegvideo.h"
|
||||||
#include "mpeg4video.h"
|
#include "mpeg4video.h"
|
||||||
#include "mpeg4data.h"
|
#include "mpeg4data.h"
|
||||||
|
|
||||||
uint8_t ff_mpeg4_static_rl_table_store[3][2][2 * MAX_RUN + MAX_LEVEL + 3];
|
static av_cold void mpeg4_init_rl_intra(void)
|
||||||
|
{
|
||||||
|
static uint8_t mpeg4_rl_intra_table[2][2 * MAX_RUN + MAX_LEVEL + 3];
|
||||||
|
ff_rl_init(&ff_mpeg4_rl_intra, mpeg4_rl_intra_table);
|
||||||
|
}
|
||||||
|
|
||||||
|
av_cold void ff_mpeg4_init_rl_intra(void)
|
||||||
|
{
|
||||||
|
static AVOnce init_static_once = AV_ONCE_INIT;
|
||||||
|
ff_thread_once(&init_static_once, mpeg4_init_rl_intra);
|
||||||
|
}
|
||||||
|
|
||||||
int ff_mpeg4_get_video_packet_prefix_length(MpegEncContext *s)
|
int ff_mpeg4_get_video_packet_prefix_length(MpegEncContext *s)
|
||||||
{
|
{
|
||||||
|
@@ -129,6 +129,7 @@ extern const int8_t ff_mpeg4_intra_level[102];
|
|||||||
extern const int8_t ff_mpeg4_intra_run[102];
|
extern const int8_t ff_mpeg4_intra_run[102];
|
||||||
|
|
||||||
extern RLTable ff_mpeg4_rl_intra;
|
extern RLTable ff_mpeg4_rl_intra;
|
||||||
|
void ff_mpeg4_init_rl_intra(void);
|
||||||
|
|
||||||
/* Note this is identical to the intra rvlc except that it is reordered. */
|
/* Note this is identical to the intra rvlc except that it is reordered. */
|
||||||
extern RLTable ff_rvlc_rl_inter;
|
extern RLTable ff_rvlc_rl_inter;
|
||||||
@@ -180,8 +181,6 @@ int ff_mpeg4_frame_end(AVCodecContext *avctx, const uint8_t *buf, int buf_size);
|
|||||||
*/
|
*/
|
||||||
int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my);
|
int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my);
|
||||||
|
|
||||||
extern uint8_t ff_mpeg4_static_rl_table_store[3][2][2 * MAX_RUN + MAX_LEVEL + 3];
|
|
||||||
|
|
||||||
#if 0 //3IV1 is quite rare and it slows things down a tiny bit
|
#if 0 //3IV1 is quite rare and it slows things down a tiny bit
|
||||||
#define IS_3IV1 s->codec_tag == AV_RL32("3IV1")
|
#define IS_3IV1 s->codec_tag == AV_RL32("3IV1")
|
||||||
#else
|
#else
|
||||||
|
@@ -3378,9 +3378,11 @@ av_cold void ff_mpeg4videodec_static_init(void) {
|
|||||||
static int done = 0;
|
static int done = 0;
|
||||||
|
|
||||||
if (!done) {
|
if (!done) {
|
||||||
ff_rl_init(&ff_mpeg4_rl_intra, ff_mpeg4_static_rl_table_store[0]);
|
static uint8_t mpeg4_rvlc_rl_tables[2][2][2 * MAX_RUN + MAX_LEVEL + 3];
|
||||||
ff_rl_init(&ff_rvlc_rl_inter, ff_mpeg4_static_rl_table_store[1]);
|
|
||||||
ff_rl_init(&ff_rvlc_rl_intra, ff_mpeg4_static_rl_table_store[2]);
|
ff_mpeg4_init_rl_intra();
|
||||||
|
ff_rl_init(&ff_rvlc_rl_inter, mpeg4_rvlc_rl_tables[0]);
|
||||||
|
ff_rl_init(&ff_rvlc_rl_intra, mpeg4_rvlc_rl_tables[1]);
|
||||||
INIT_FIRST_VLC_RL(ff_mpeg4_rl_intra, 554);
|
INIT_FIRST_VLC_RL(ff_mpeg4_rl_intra, 554);
|
||||||
INIT_VLC_RL(ff_rvlc_rl_inter, 1072);
|
INIT_VLC_RL(ff_rvlc_rl_inter, 1072);
|
||||||
INIT_FIRST_VLC_RL(ff_rvlc_rl_intra, 1072);
|
INIT_FIRST_VLC_RL(ff_rvlc_rl_intra, 1072);
|
||||||
|
@@ -1285,7 +1285,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
|
|||||||
|
|
||||||
init_uni_dc_tab();
|
init_uni_dc_tab();
|
||||||
|
|
||||||
ff_rl_init(&ff_mpeg4_rl_intra, ff_mpeg4_static_rl_table_store[0]);
|
ff_mpeg4_init_rl_intra();
|
||||||
|
|
||||||
init_uni_mpeg4_rl_tab(&ff_mpeg4_rl_intra, uni_mpeg4_intra_rl_bits, uni_mpeg4_intra_rl_len);
|
init_uni_mpeg4_rl_tab(&ff_mpeg4_rl_intra, uni_mpeg4_intra_rl_bits, uni_mpeg4_intra_rl_len);
|
||||||
init_uni_mpeg4_rl_tab(&ff_h263_rl_inter, uni_mpeg4_inter_rl_bits, uni_mpeg4_inter_rl_len);
|
init_uni_mpeg4_rl_tab(&ff_h263_rl_inter, uni_mpeg4_inter_rl_bits, uni_mpeg4_inter_rl_len);
|
||||||
|
Reference in New Issue
Block a user