* 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
#define TM2_DELTAS 64
typedef struct TM2Context {
AVCodecContext *avctx;
- AVFrame pic;
+ AVFrame *pic;
GetBitContext gb;
- DSPContext dsp;
+ BswapDSPContext bdsp;
/* TM2 streams */
int *tokens[TM2_NUM_STREAMS];
switch (magic) {
case TM2_OLD_HEADER_MAGIC:
- av_log_missing_feature(ctx->avctx, "TM2 old header", 1);
+ avpriv_request_sample(ctx->avctx, "Old TM2 header");
return 0;
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;
}
}
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;
av_log(avctx, AV_LOG_ERROR, "Cannot allocate temporary buffer\n");
return AVERROR(ENOMEM);
}
- p->reference = 1;
- p->buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
- if ((ret = avctx->reget_buffer(avctx, p)) < 0) {
+
+ if ((ret = ff_reget_buffer(avctx, p)) < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
av_free(swbuf);
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;
- *(AVFrame*)data = l->pic;
+ ret = av_frame_ref(data, l->pic);
av_free(swbuf);
- return buf_size;
+ return (ret < 0) ? ret : buf_size;
}
static av_cold int decode_init(AVCodecContext *avctx)
}
l->avctx = avctx;
- l->pic.data[0] = NULL;
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));
if (!l->Y1_base || !l->Y2_base || !l->U1_base ||
!l->V1_base || !l->U2_base || !l->V2_base ||
!l->last || !l->clast) {
- av_freep(l->Y1_base);
- av_freep(l->Y2_base);
- av_freep(l->U1_base);
- av_freep(l->U2_base);
- av_freep(l->V1_base);
- av_freep(l->V2_base);
- av_freep(l->last);
- av_freep(l->clast);
+ av_freep(&l->Y1_base);
+ av_freep(&l->Y2_base);
+ av_freep(&l->U1_base);
+ av_freep(&l->U2_base);
+ av_freep(&l->V1_base);
+ av_freep(&l->V2_base);
+ av_freep(&l->last);
+ av_freep(&l->clast);
return AVERROR(ENOMEM);
}
l->Y1 = l->Y1_base + l->y_stride * 4 + 4;
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);
}
- if (pic->data[0])
- avctx->release_buffer(avctx, pic);
+ av_frame_free(&l->pic);
return 0;
}
AVCodec ff_truemotion2_decoder = {
.name = "truemotion2",
+ .long_name = NULL_IF_CONFIG_SMALL("Duck TrueMotion 2.0"),
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_TRUEMOTION2,
.priv_data_size = sizeof(TM2Context),
.close = decode_end,
.decode = decode_frame,
.capabilities = CODEC_CAP_DR1,
- .long_name = NULL_IF_CONFIG_SMALL("Duck TrueMotion 2.0"),
};