* Duck TrueMotion2 decoder.
*/
+#include <inttypes.h>
+
#include "avcodec.h"
+#include "bswapdsp.h"
#include "bytestream.h"
#include "get_bits.h"
-#include "dsputil.h"
#include "internal.h"
#define TM2_ESCAPE 0x80000000
typedef struct TM2Context {
AVCodecContext *avctx;
- AVFrame pic;
+ AVFrame *pic;
GetBitContext gb;
- DSPContext dsp;
+ BswapDSPContext bdsp;
/* TM2 streams */
int *tokens[TM2_NUM_STREAMS];
huff.nums = av_mallocz(huff.max_num * sizeof(int));
huff.bits = av_mallocz(huff.max_num * sizeof(uint32_t));
huff.lens = av_mallocz(huff.max_num * sizeof(int));
+ if (!huff.nums || !huff.bits || !huff.lens) {
+ res = AVERROR(ENOMEM);
+ goto out;
+ }
res = tm2_read_tree(ctx, 0, 0, &huff);
code->bits = huff.max_bits;
code->length = huff.max_num;
code->recode = av_malloc(code->length * sizeof(int));
+ if (!code->recode) {
+ res = AVERROR(ENOMEM);
+ goto out;
+ }
for (i = 0; i < code->length; i++)
code->recode[i] = huff.nums[i];
}
}
+
+out:
/* free allocated memory */
av_free(huff.nums);
av_free(huff.bits);
case TM2_NEW_HEADER_MAGIC:
return 0;
default:
- av_log(ctx->avctx, AV_LOG_ERROR, "Not a TM2 header: 0x%08X\n", magic);
+ av_log(ctx->avctx, AV_LOG_ERROR, "Not a TM2 header: 0x%08"PRIX32"\n",
+ magic);
return AVERROR_INVALIDDATA;
}
}
if (len == 0)
return 4;
- if (len >= INT_MAX/4-1 || len < 0 || len > buf_size) {
+ if (len >= INT_MAX / 4 - 1 || len < 0 || skip > buf_size) {
av_log(ctx->avctx, AV_LOG_ERROR, "Error, invalid stream size.\n");
return AVERROR_INVALIDDATA;
}
TM2Context * const l = avctx->priv_data;
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size & ~3;
- AVFrame * const p = &l->pic;
+ AVFrame * const p = l->pic;
int offset = TM2_HEADER_SIZE;
int i, t, ret;
uint8_t *swbuf;
- swbuf = av_malloc(buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ swbuf = av_malloc(buf_size + AV_INPUT_BUFFER_PADDING_SIZE);
if (!swbuf) {
av_log(avctx, AV_LOG_ERROR, "Cannot allocate temporary buffer\n");
return AVERROR(ENOMEM);
return ret;
}
- l->dsp.bswap_buf((uint32_t*)swbuf, (const uint32_t*)buf, buf_size >> 2);
+ l->bdsp.bswap_buf((uint32_t *) swbuf, (const uint32_t *) buf,
+ buf_size >> 2);
if ((ret = tm2_read_header(l, swbuf)) < 0) {
av_free(swbuf);
l->cur = !l->cur;
*got_frame = 1;
- ret = av_frame_ref(data, &l->pic);
+ ret = av_frame_ref(data, l->pic);
av_free(swbuf);
return (ret < 0) ? ret : buf_size;
}
l->avctx = avctx;
- avcodec_get_frame_defaults(&l->pic);
avctx->pix_fmt = AV_PIX_FMT_BGR24;
- ff_dsputil_init(&l->dsp, avctx);
+ l->pic = av_frame_alloc();
+ if (!l->pic)
+ return AVERROR(ENOMEM);
+
+ ff_bswapdsp_init(&l->bdsp);
l->last = av_malloc(4 * sizeof(*l->last) * (w >> 2));
l->clast = av_malloc(4 * sizeof(*l->clast) * (w >> 2));
static av_cold int decode_end(AVCodecContext *avctx)
{
TM2Context * const l = avctx->priv_data;
- AVFrame *pic = &l->pic;
int i;
av_free(l->last);
av_free(l->V2_base);
}
- av_frame_unref(pic);
+ av_frame_free(&l->pic);
return 0;
}
.init = decode_init,
.close = decode_end,
.decode = decode_frame,
- .capabilities = CODEC_CAP_DR1,
+ .capabilities = AV_CODEC_CAP_DR1,
};