#include <string.h>
#include <stdint.h>
+#include "libavutil/mem_internal.h"
+#include "libavutil/thread.h"
+
#include "avcodec.h"
#include "blockdsp.h"
#include "internal.h"
#include "thread.h"
#define MIMIC_HEADER_SIZE 20
+#define MIMIC_VLC_BITS 11
typedef struct MimicContext {
AVCodecContext *avctx;
BswapDSPContext bbdsp;
HpelDSPContext hdsp;
IDCTDSPContext idsp;
- VLC vlc;
/* Kept in the context so multithreading can have a constant to read from */
int next_cur_index;
int next_prev_index;
} MimicContext;
-static const uint32_t huffcodes[] = {
- 0x0000000a, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000000b,
- 0x0000001b, 0x00000038, 0x00000078, 0x00000079, 0x0000007a, 0x000000f9,
- 0x000000fa, 0x000003fb, 0x000007f8, 0x000007f9, 0x000007fa, 0x000007fb,
- 0x00000ff8, 0x00000ff9, 0x00000001, 0x00000039, 0x0000007b, 0x000000fb,
- 0x000001f8, 0x000001f9, 0x00000ffa, 0x00000ffb, 0x00001ff8, 0x00001ff9,
- 0x00001ffa, 0x00001ffb, 0x00003ff8, 0x00003ff9, 0x00003ffa, 0x00000000,
- 0x00000004, 0x0000003a, 0x000001fa, 0x00003ffb, 0x00007ff8, 0x00007ff9,
- 0x00007ffa, 0x00007ffb, 0x0000fff8, 0x0000fff9, 0x0000fffa, 0x0000fffb,
- 0x0001fff8, 0x0001fff9, 0x0001fffa, 0x00000000, 0x0000000c, 0x000000f8,
- 0x000001fb, 0x0001fffb, 0x0003fff8, 0x0003fff9, 0x0003fffa, 0x0003fffb,
- 0x0007fff8, 0x0007fff9, 0x0007fffa, 0x0007fffb, 0x000ffff8, 0x000ffff9,
- 0x000ffffa, 0x00000000, 0x0000001a, 0x000003f8, 0x000ffffb, 0x001ffff8,
- 0x001ffff9, 0x001ffffa, 0x001ffffb, 0x003ffff8, 0x003ffff9, 0x003ffffa,
- 0x003ffffb, 0x007ffff8, 0x007ffff9, 0x007ffffa, 0x007ffffb, 0x00000000,
- 0x0000003b, 0x000003f9, 0x00fffff8, 0x00fffff9, 0x00fffffa, 0x00fffffb,
- 0x01fffff8, 0x01fffff9, 0x01fffffa, 0x01fffffb, 0x03fffff8, 0x03fffff9,
- 0x03fffffa, 0x03fffffb, 0x07fffff8, 0x00000000, 0x000003fa, 0x07fffff9,
- 0x07fffffa, 0x07fffffb, 0x0ffffff8, 0x0ffffff9, 0x0ffffffa, 0x0ffffffb,
- 0x1ffffff8, 0x1ffffff9, 0x1ffffffa, 0x1ffffffb, 0x3ffffff8, 0x3ffffff9,
- 0x3ffffffa,
+static VLC block_vlc;
+
+static const uint8_t huffsyms[] = {
+ 0x10, 0x20, 0x30, 0x00, 0x11, 0x40, 0x50, 0x12, 0x13, 0x21, 0x31, 0x60,
+ 0x14, 0x15, 0x16, 0x22, 0x41, 0x17, 0x18, 0x23, 0x24, 0x25, 0x32, 0x42,
+ 0x51, 0x61, 0x70, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x26, 0x27,
+ 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x33, 0x34, 0x35, 0x36, 0x37,
+ 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x43, 0x44, 0x45, 0x46, 0x47,
+ 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x52, 0x53, 0x54, 0x55, 0x56,
+ 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x62, 0x63, 0x64, 0x65,
+ 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x71, 0x72, 0x73,
+ 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E,
};
static const uint8_t huffbits[] = {
- 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 2, 4, 5, 6, 7, 7, 7, 8,
- 8, 10, 11, 11, 11, 11, 12, 12, 2, 6, 7, 8,
- 9, 9, 12, 12, 13, 13, 13, 13, 14, 14, 14, 0,
- 3, 6, 9, 14, 15, 15, 15, 15, 16, 16, 16, 16,
- 17, 17, 17, 0, 4, 8, 9, 17, 18, 18, 18, 18,
- 19, 19, 19, 19, 20, 20, 20, 0, 5, 10, 20, 21,
- 21, 21, 21, 22, 22, 22, 22, 23, 23, 23, 23, 0,
- 6, 10, 24, 24, 24, 24, 25, 25, 25, 25, 26, 26,
- 26, 26, 27, 0, 10, 27, 27, 27, 28, 28, 28, 28,
- 29, 29, 29, 29, 30, 30, 30,
+ 2, 2, 3, 4, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8,
+ 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12,
+ 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 17, 17,
+ 17, 17, 18, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21,
+ 22, 22, 22, 22, 23, 23, 23, 23, 24, 24, 24, 24, 25, 25, 25, 25, 26, 26,
+ 26, 26, 27, 27, 27, 27, 28, 28, 28, 28, 29, 29, 29, 29, 30, 30, 30,
};
static const uint8_t col_zag[64] = {
av_frame_free(&ctx->frames[i].f);
}
- if (!avctx->internal->is_copy)
- ff_free_vlc(&ctx->vlc);
-
return 0;
}
+static av_cold void mimic_init_static(void)
+{
+ INIT_VLC_STATIC_FROM_LENGTHS(&block_vlc, MIMIC_VLC_BITS, FF_ARRAY_ELEMS(huffbits),
+ huffbits, 1, huffsyms, 1, 1, 0, 0, 4368);
+}
+
static av_cold int mimic_decode_init(AVCodecContext *avctx)
{
+ static AVOnce init_static_once = AV_ONCE_INIT;
MimicContext *ctx = avctx->priv_data;
- int ret, i;
-
- avctx->internal->allocate_progress = 1;
+ int i;
ctx->prev_index = 0;
ctx->cur_index = 15;
- if ((ret = init_vlc(&ctx->vlc, 11, FF_ARRAY_ELEMS(huffbits),
- huffbits, 1, 1, huffcodes, 4, 4, 0)) < 0) {
- av_log(avctx, AV_LOG_ERROR, "error initializing vlc table\n");
- return ret;
- }
ff_blockdsp_init(&ctx->bdsp, avctx);
ff_bswapdsp_init(&ctx->bbdsp);
ff_hpeldsp_init(&ctx->hdsp, avctx->flags);
for (i = 0; i < FF_ARRAY_ELEMS(ctx->frames); i++) {
ctx->frames[i].f = av_frame_alloc();
- if (!ctx->frames[i].f) {
- mimic_decode_end(avctx);
+ if (!ctx->frames[i].f)
return AVERROR(ENOMEM);
- }
}
+ ff_thread_once(&init_static_once, mimic_init_static);
+
return 0;
}
int value;
int coeff;
- vlc = get_vlc2(&ctx->gb, ctx->vlc.table, ctx->vlc.bits, 3);
+ vlc = get_vlc2(&ctx->gb, block_vlc.table, MIMIC_VLC_BITS, 3);
if (!vlc) /* end-of-block code */
return 0;
if (vlc == -1)
return buf_size;
}
-#if HAVE_THREADS
-static av_cold int mimic_init_thread_copy(AVCodecContext *avctx)
-{
- MimicContext *ctx = avctx->priv_data;
- int i;
-
- for (i = 0; i < FF_ARRAY_ELEMS(ctx->frames); i++) {
- ctx->frames[i].f = av_frame_alloc();
- if (!ctx->frames[i].f) {
- mimic_decode_end(avctx);
- return AVERROR(ENOMEM);
- }
- }
-
- return 0;
-}
-#endif
-
-AVCodec ff_mimic_decoder = {
+const AVCodec ff_mimic_decoder = {
.name = "mimic",
.long_name = NULL_IF_CONFIG_SMALL("Mimic"),
.type = AVMEDIA_TYPE_VIDEO,
.decode = mimic_decode_frame,
.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
.update_thread_context = ONLY_IF_THREADS_ENABLED(mimic_decode_update_thread_context),
- .init_thread_copy = ONLY_IF_THREADS_ENABLED(mimic_init_thread_copy),
+ .caps_internal = FF_CODEC_CAP_ALLOCATE_PROGRESS |
+ FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_INIT_THREADSAFE,
};