/*
- * Copyright (C) 2003 the ffmpeg project
+ * Copyright (C) 2003 The FFmpeg project
*
* This file is part of Libav.
*
#include <stdlib.h>
#include <string.h>
+#include "libavutil/imgutils.h"
+
#include "avcodec.h"
#include "bytestream.h"
+#include "internal.h"
#include "roqvideo.h"
static void roqvideo_decode_frame(RoqContext *ri)
roq_qcell *qcell;
int64_t chunk_start;
- while (bytestream2_get_bytes_left(&ri->gb) > 0) {
+ while (bytestream2_get_bytes_left(&ri->gb) >= 8) {
chunk_id = bytestream2_get_le16(&ri->gb);
chunk_size = bytestream2_get_le32(&ri->gb);
chunk_arg = bytestream2_get_le16(&ri->gb);
RoqContext *s = avctx->priv_data;
s->avctx = avctx;
+
+ if (avctx->width % 16 || avctx->height % 16) {
+ avpriv_request_sample(avctx, "Dimensions not being a multiple of 16");
+ return AVERROR_PATCHWELCOME;
+ }
+
s->width = avctx->width;
s->height = avctx->height;
- s->last_frame = &s->frames[0];
- s->current_frame = &s->frames[1];
- avctx->pix_fmt = PIX_FMT_YUV444P;
+
+ s->last_frame = av_frame_alloc();
+ s->current_frame = av_frame_alloc();
+ if (!s->current_frame || !s->last_frame) {
+ av_frame_free(&s->current_frame);
+ av_frame_free(&s->last_frame);
+ return AVERROR(ENOMEM);
+ }
+
+ avctx->pix_fmt = AV_PIX_FMT_YUV444P;
return 0;
}
static int roq_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
+ void *data, int *got_frame,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
RoqContext *s = avctx->priv_data;
- int copy= !s->current_frame->data[0];
+ int copy = !s->current_frame->data[0] && s->last_frame->data[0];
+ int ret;
- s->current_frame->reference = 3;
- if (avctx->reget_buffer(avctx, s->current_frame)) {
+ if ((ret = ff_reget_buffer(avctx, s->current_frame)) < 0) {
av_log(avctx, AV_LOG_ERROR, " RoQ: get_buffer() failed\n");
- return -1;
+ return ret;
}
- if(copy)
- av_picture_copy((AVPicture*)s->current_frame, (AVPicture*)s->last_frame,
- avctx->pix_fmt, avctx->width, avctx->height);
+ if (copy) {
+ ret = av_frame_copy(s->current_frame, s->last_frame);
+ if (ret < 0)
+ return ret;
+ }
bytestream2_init(&s->gb, buf, buf_size);
roqvideo_decode_frame(s);
- *data_size = sizeof(AVFrame);
- *(AVFrame*)data = *s->current_frame;
+ if ((ret = av_frame_ref(data, s->current_frame)) < 0)
+ return ret;
+ *got_frame = 1;
/* shuffle frames */
FFSWAP(AVFrame *, s->current_frame, s->last_frame);
{
RoqContext *s = avctx->priv_data;
- /* release the last frame */
- if (s->last_frame->data[0])
- avctx->release_buffer(avctx, s->last_frame);
- if (s->current_frame->data[0])
- avctx->release_buffer(avctx, s->current_frame);
+ av_frame_free(&s->current_frame);
+ av_frame_free(&s->last_frame);
return 0;
}
AVCodec ff_roq_decoder = {
.name = "roqvideo",
+ .long_name = NULL_IF_CONFIG_SMALL("id RoQ video"),
.type = AVMEDIA_TYPE_VIDEO,
- .id = CODEC_ID_ROQ,
+ .id = AV_CODEC_ID_ROQ,
.priv_data_size = sizeof(RoqContext),
.init = roq_decode_init,
.close = roq_decode_end,
.decode = roq_decode_frame,
- .capabilities = CODEC_CAP_DR1,
- .long_name = NULL_IF_CONFIG_SMALL("id RoQ video"),
+ .capabilities = AV_CODEC_CAP_DR1,
};