* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "libavutil/thread.h"
+
+#include "config.h"
+
#include "avcodec.h"
#include "get_bits.h"
#include "bswapdsp.h"
#include "motionpixels_tablegen.h"
typedef struct HuffCode {
- int code;
uint8_t size;
uint8_t delta;
} HuffCode;
static av_cold int mp_decode_init(AVCodecContext *avctx)
{
+ av_unused static AVOnce init_static_once = AV_ONCE_INIT;
MotionPixelsContext *mp = avctx->priv_data;
int w4 = (avctx->width + 3) & ~3;
int h4 = (avctx->height + 3) & ~3;
return AVERROR_INVALIDDATA;
}
- motionpixels_tableinit();
mp->avctx = avctx;
ff_bswapdsp_init(&mp->bdsp);
mp->changes_map = av_mallocz_array(avctx->width, h4);
if (!mp->frame)
return AVERROR(ENOMEM);
+#if !CONFIG_HARDCODED_TABLES
+ ff_thread_once(&init_static_once, motionpixels_tableinit);
+#endif
+
return 0;
}
}
}
-static int mp_get_code(MotionPixelsContext *mp, GetBitContext *gb, int size, int code)
+static int mp_get_code(MotionPixelsContext *mp, GetBitContext *gb, int size)
{
while (get_bits1(gb)) {
++size;
av_log(mp->avctx, AV_LOG_ERROR, "invalid code size %d/%d\n", size, mp->max_codes_bits);
return AVERROR_INVALIDDATA;
}
- code <<= 1;
- if (mp_get_code(mp, gb, size, code + 1) < 0)
+ if (mp_get_code(mp, gb, size) < 0)
return AVERROR_INVALIDDATA;
}
if (mp->current_codes_count >= mp->codes_count) {
return AVERROR_INVALIDDATA;
}
- mp->codes[mp->current_codes_count ].code = code;
mp->codes[mp->current_codes_count++].size = size;
return 0;
}
for (i = 0; i < mp->codes_count; ++i)
mp->codes[i].delta = get_bits(gb, 4);
mp->current_codes_count = 0;
- if ((ret = mp_get_code(mp, gb, 0, 0)) < 0)
+ if ((ret = mp_get_code(mp, gb, 0)) < 0)
return ret;
if (mp->current_codes_count < mp->codes_count) {
av_log(mp->avctx, AV_LOG_ERROR, "too few codes\n");
goto end;
if (mp->codes_count > 1) {
- ret = ff_init_vlc_sparse(&mp->vlc, mp->max_codes_bits, mp->codes_count,
- &mp->codes[0].size, sizeof(HuffCode), 1,
- &mp->codes[0].code, sizeof(HuffCode), 4,
- &mp->codes[0].delta, sizeof(HuffCode), 1, 0);
+ /* The entries of the mp->codes array are sorted from right to left
+ * in the Huffman tree, hence -(int)sizeof(HuffCode). */
+ ret = ff_init_vlc_from_lengths(&mp->vlc, mp->max_codes_bits, mp->codes_count,
+ &mp->codes[mp->codes_count - 1].size, -(int)sizeof(HuffCode),
+ &mp->codes[mp->codes_count - 1].delta, -(int)sizeof(HuffCode), 1,
+ 0, 0, avctx);
if (ret < 0)
goto end;
}
return buf_size;
}
-AVCodec ff_motionpixels_decoder = {
+const AVCodec ff_motionpixels_decoder = {
.name = "motionpixels",
.long_name = NULL_IF_CONFIG_SMALL("Motion Pixels video"),
.type = AVMEDIA_TYPE_VIDEO,
.close = mp_decode_end,
.decode = mp_decode_frame,
.capabilities = AV_CODEC_CAP_DR1,
- .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
+ .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_INIT_THREADSAFE,
};