av_log(h->avctx, AV_LOG_ERROR,
"position out of block bounds at pic %d MB(%d,%d)\n",
h->cur.poc, h->mbx, h->mby);
- return -1;
+ return AVERROR_INVALIDDATA;
}
dst[scantab[pos]] = (level_buf[coeff_num] * mul + round) >> shift;
}
const struct dec_2dvlc *r, int esc_golomb_order,
int qp, uint8_t *dst, int stride)
{
- int i, level_code, esc_code, level, run, mask;
+ int i, level_code, esc_code, level, run, mask, ret;
int16_t level_buf[65];
uint8_t run_buf[65];
int16_t *block = h->block;
level_buf[i] = level;
run_buf[i] = run;
}
- if (dequant(h, level_buf, run_buf, block, dequant_mul[qp],
- dequant_shift[qp], i))
- return -1;
+ if ((ret = dequant(h, level_buf, run_buf, block, dequant_mul[qp],
+ dequant_shift[qp], i)) < 0)
+ return ret;
h->cdsp.cavs_idct8_add(dst, block, stride);
- h->dsp.clear_block(block);
+ h->bdsp.clear_block(block);
return 0;
}
/* get coded block pattern */
int cbp = get_ue_golomb(&h->gb);
- if (cbp > 63) {
- av_log(h->avctx, AV_LOG_ERROR, "illegal inter cbp\n");
- return -1;
+ if (cbp > 63 || cbp < 0) {
+ av_log(h->avctx, AV_LOG_ERROR, "illegal inter cbp %d\n", cbp);
+ return AVERROR_INVALIDDATA;
}
h->cbp = cbp_tab[cbp][1];
pred_mode_uv = get_ue_golomb(gb);
if (pred_mode_uv > 6) {
av_log(h->avctx, AV_LOG_ERROR, "illegal intra chroma pred mode\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
ff_cavs_modify_mb_i(h, &pred_mode_uv);
/* get coded block pattern */
if (h->cur.f->pict_type == AV_PICTURE_TYPE_I)
cbp_code = get_ue_golomb(gb);
- if (cbp_code > 63) {
+ if (cbp_code > 63 || cbp_code < 0) {
av_log(h->avctx, AV_LOG_ERROR, "illegal intra cbp\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
h->cbp = cbp_tab[cbp_code][0];
if (h->cbp && !h->qp_fixed)
static int decode_pic(AVSContext *h)
{
+ int ret;
int skip_count = -1;
enum cavs_mb mb_type;
+ if (!h->top_qp) {
+ av_log(h->avctx, AV_LOG_ERROR, "No sequence header decoded yet\n");
+ return AVERROR_INVALIDDATA;
+ }
+
+ av_frame_unref(h->cur.f);
+
skip_bits(&h->gb, 16);//bbv_dwlay
if (h->stc == PIC_PB_START_CODE) {
h->cur.f->pict_type = get_bits(&h->gb, 2) + AV_PICTURE_TYPE_I;
if (h->cur.f->pict_type > AV_PICTURE_TYPE_B) {
av_log(h->avctx, AV_LOG_ERROR, "illegal picture type\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
/* make sure we have the reference frames we need */
if (!h->DPB[0].f->data[0] ||
(!h->DPB[1].f->data[0] && h->cur.f->pict_type == AV_PICTURE_TYPE_B))
- return -1;
+ return AVERROR_INVALIDDATA;
} else {
h->cur.f->pict_type = AV_PICTURE_TYPE_I;
if (get_bits1(&h->gb))
if (h->stream_revision > 0)
skip_bits(&h->gb, 1); //marker_bit
}
- /* release last B frame */
- if (h->cur.f->data[0])
- h->avctx->release_buffer(h->avctx, h->cur.f);
- ff_get_buffer(h->avctx, h->cur.f);
+ ret = ff_get_buffer(h->avctx, h->cur.f, h->cur.f->pict_type == AV_PICTURE_TYPE_B ?
+ 0 : AV_GET_BUFFER_FLAG_REF);
+ if (ret < 0)
+ return ret;
if (!h->edge_emu_buffer) {
int alloc_size = FFALIGN(FFABS(h->cur.f->linesize[0]) + 32, 32);
} while (ff_cavs_next_mb(h));
}
if (h->cur.f->pict_type != AV_PICTURE_TYPE_B) {
- if (h->DPB[1].f->data[0])
- h->avctx->release_buffer(h->avctx, h->DPB[1].f);
+ av_frame_unref(h->DPB[1].f);
FFSWAP(AVSFrame, h->cur, h->DPB[1]);
FFSWAP(AVSFrame, h->DPB[0], h->DPB[1]);
}
width = get_bits(&h->gb, 14);
height = get_bits(&h->gb, 14);
if ((h->width || h->height) && (h->width != width || h->height != height)) {
- av_log_missing_feature(h->avctx, "Width/height changing in CAVS", 0);
+ avpriv_report_missing_feature(h->avctx,
+ "Width/height changing in CAVS");
return AVERROR_PATCHWELCOME;
}
h->width = width;
h->low_delay = get_bits1(&h->gb);
h->mb_width = (h->width + 15) >> 4;
h->mb_height = (h->height + 15) >> 4;
- h->avctx->time_base.den = ff_mpeg12_frame_rate_tab[frame_rate_code].num;
- h->avctx->time_base.num = ff_mpeg12_frame_rate_tab[frame_rate_code].den;
+ h->avctx->framerate = ff_mpeg12_frame_rate_tab[frame_rate_code];
h->avctx->width = h->width;
h->avctx->height = h->height;
if (!h->top_qp)
AVSContext *h = avctx->priv_data;
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
- AVFrame *picture = data;
uint32_t stc = -1;
- int input_size;
+ int input_size, ret;
const uint8_t *buf_end;
const uint8_t *buf_ptr;
if (buf_size == 0) {
if (!h->low_delay && h->DPB[0].f->data[0]) {
*got_frame = 1;
- *picture = *h->DPB[0].f;
- if (h->cur.f->data[0])
- avctx->release_buffer(avctx, h->cur.f);
- FFSWAP(AVSFrame, h->cur, h->DPB[0]);
+ av_frame_move_ref(data, h->DPB[0].f);
}
return 0;
}
buf_ptr = buf;
buf_end = buf + buf_size;
for(;;) {
- buf_ptr = avpriv_mpv_find_start_code(buf_ptr, buf_end, &stc);
+ buf_ptr = avpriv_find_start_code(buf_ptr, buf_end, &stc);
if ((stc & 0xFFFFFE00) || buf_ptr == buf_end)
return FFMAX(0, buf_ptr - buf);
input_size = (buf_end - buf_ptr) * 8;
break;
case PIC_I_START_CODE:
if (!h->got_keyframe) {
- if(h->DPB[0].f->data[0])
- avctx->release_buffer(avctx, h->DPB[0].f);
- if(h->DPB[1].f->data[0])
- avctx->release_buffer(avctx, h->DPB[1].f);
+ av_frame_unref(h->DPB[0].f);
+ av_frame_unref(h->DPB[1].f);
h->got_keyframe = 1;
}
case PIC_PB_START_CODE:
*got_frame = 1;
if (h->cur.f->pict_type != AV_PICTURE_TYPE_B) {
if (h->DPB[1].f->data[0]) {
- *picture = *h->DPB[1].f;
+ if ((ret = av_frame_ref(data, h->DPB[1].f)) < 0)
+ return ret;
} else {
*got_frame = 0;
}
- } else
- *picture = *h->cur.f;
+ } else {
+ av_frame_move_ref(data, h->cur.f);
+ }
break;
case EXT_START_CODE:
//mpeg_decode_extension(avctx, buf_ptr, input_size);
AVCodec ff_cavs_decoder = {
.name = "cavs",
+ .long_name = NULL_IF_CONFIG_SMALL("Chinese AVS (Audio Video Standard) (AVS1-P2, JiZhun profile)"),
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_CAVS,
.priv_data_size = sizeof(AVSContext),
.decode = cavs_decode_frame,
.capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY,
.flush = cavs_flush,
- .long_name = NULL_IF_CONFIG_SMALL("Chinese AVS (Audio Video Standard) (AVS1-P2, JiZhun profile)"),
};