712
712
if (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME)) {
713
713
/* wait for the referenced mb row to be finished */
714
int mb_row = FFMIN(s->mb_height - 1,
715
s->mb_y + ((yoff + my + 5 + 8 * height) >> 4));
714
int mb_row = s->mb_y + ((yoff + my + 5 + 8 * height) >> 4);
716
715
AVFrame *f = dir ? &s->next_picture_ptr->f : &s->last_picture_ptr->f;
717
716
ff_thread_await_progress(f, mb_row, 0);
1364
static void rv34_decoder_free(RV34DecContext *r)
1366
av_freep(&r->intra_types_hist);
1367
r->intra_types = NULL;
1368
av_freep(&r->tmp_b_block_base);
1369
av_freep(&r->mb_type);
1370
av_freep(&r->cbp_luma);
1371
av_freep(&r->cbp_chroma);
1372
av_freep(&r->deblock_coefs);
1376
static int rv34_decoder_alloc(RV34DecContext *r)
1378
r->intra_types_stride = r->s.mb_width * 4 + 4;
1380
r->cbp_chroma = av_malloc(r->s.mb_stride * r->s.mb_height *
1381
sizeof(*r->cbp_chroma));
1382
r->cbp_luma = av_malloc(r->s.mb_stride * r->s.mb_height *
1383
sizeof(*r->cbp_luma));
1384
r->deblock_coefs = av_malloc(r->s.mb_stride * r->s.mb_height *
1385
sizeof(*r->deblock_coefs));
1386
r->intra_types_hist = av_malloc(r->intra_types_stride * 4 * 2 *
1387
sizeof(*r->intra_types_hist));
1388
r->mb_type = av_mallocz(r->s.mb_stride * r->s.mb_height *
1389
sizeof(*r->mb_type));
1391
if (!(r->cbp_chroma && r->cbp_luma && r->deblock_coefs &&
1392
r->intra_types_hist && r->mb_type)) {
1393
rv34_decoder_free(r);
1394
return AVERROR(ENOMEM);
1397
r->intra_types = r->intra_types_hist + r->intra_types_stride * 4;
1403
static int rv34_decoder_realloc(RV34DecContext *r)
1405
rv34_decoder_free(r);
1406
return rv34_decoder_alloc(r);
1364
1410
static int rv34_decode_slice(RV34DecContext *r, int end, const uint8_t* buf, int buf_size)
1366
1412
MpegEncContext *s = &r->s;
1378
1424
if ((s->mb_x == 0 && s->mb_y == 0) || s->current_picture_ptr==NULL) {
1379
if(s->width != r->si.width || s->height != r->si.height){
1380
av_log(s->avctx, AV_LOG_DEBUG, "Changing dimensions to %dx%d\n", r->si.width,r->si.height);
1425
if (s->width != r->si.width || s->height != r->si.height) {
1428
av_log(s->avctx, AV_LOG_WARNING, "Changing dimensions to %dx%d\n",
1429
r->si.width, r->si.height);
1381
1430
MPV_common_end(s);
1382
1431
s->width = r->si.width;
1383
1432
s->height = r->si.height;
1384
1433
avcodec_set_dimensions(s->avctx, s->width, s->height);
1385
if(MPV_common_init(s) < 0)
1387
r->intra_types_stride = s->mb_width*4 + 4;
1388
r->intra_types_hist = av_realloc(r->intra_types_hist, r->intra_types_stride * 4 * 2 * sizeof(*r->intra_types_hist));
1389
r->intra_types = r->intra_types_hist + r->intra_types_stride * 4;
1390
r->mb_type = av_realloc(r->mb_type, r->s.mb_stride * r->s.mb_height * sizeof(*r->mb_type));
1391
r->cbp_luma = av_realloc(r->cbp_luma, r->s.mb_stride * r->s.mb_height * sizeof(*r->cbp_luma));
1392
r->cbp_chroma = av_realloc(r->cbp_chroma, r->s.mb_stride * r->s.mb_height * sizeof(*r->cbp_chroma));
1393
r->deblock_coefs = av_realloc(r->deblock_coefs, r->s.mb_stride * r->s.mb_height * sizeof(*r->deblock_coefs));
1394
av_freep(&r->tmp_b_block_base);
1434
if ((err = MPV_common_init(s)) < 0)
1436
if ((err = rv34_decoder_realloc(r)) < 0)
1396
1439
s->pict_type = r->si.type ? r->si.type : AV_PICTURE_TYPE_I;
1397
1440
if(MPV_frame_start(s, s->avctx) < 0)
1512
1556
avctx->has_b_frames = 1;
1513
1557
s->low_delay = 0;
1515
if (MPV_common_init(s) < 0)
1559
if ((ret = MPV_common_init(s)) < 0)
1518
1562
ff_h264_pred_init(&r->h, CODEC_ID_RV40, 8, 1);
1526
1570
ff_rv40dsp_init(&r->rdsp, &r->s.dsp);
1529
r->intra_types_stride = 4*s->mb_stride + 4;
1530
r->intra_types_hist = av_malloc(r->intra_types_stride * 4 * 2 * sizeof(*r->intra_types_hist));
1531
r->intra_types = r->intra_types_hist + r->intra_types_stride * 4;
1533
r->mb_type = av_mallocz(r->s.mb_stride * r->s.mb_height * sizeof(*r->mb_type));
1535
r->cbp_luma = av_malloc(r->s.mb_stride * r->s.mb_height * sizeof(*r->cbp_luma));
1536
r->cbp_chroma = av_malloc(r->s.mb_stride * r->s.mb_height * sizeof(*r->cbp_chroma));
1537
r->deblock_coefs = av_malloc(r->s.mb_stride * r->s.mb_height * sizeof(*r->deblock_coefs));
1573
if ((ret = rv34_decoder_alloc(r)) < 0)
1539
1576
if(!intra_vlcs[0].cbppattern[0].bits)
1540
1577
rv34_init_tables();
1545
1582
int ff_rv34_decode_init_thread_copy(AVCodecContext *avctx)
1547
1585
RV34DecContext *r = avctx->priv_data;
1549
1587
r->s.avctx = avctx;
1551
1589
if (avctx->internal->is_copy) {
1552
r->cbp_chroma = av_malloc(r->s.mb_stride * r->s.mb_height *
1553
sizeof(*r->cbp_chroma));
1554
r->cbp_luma = av_malloc(r->s.mb_stride * r->s.mb_height *
1555
sizeof(*r->cbp_luma));
1556
r->deblock_coefs = av_malloc(r->s.mb_stride * r->s.mb_height *
1557
sizeof(*r->deblock_coefs));
1558
r->intra_types_hist = av_malloc(r->intra_types_stride * 4 * 2 *
1559
sizeof(*r->intra_types_hist));
1560
r->mb_type = av_malloc(r->s.mb_stride * r->s.mb_height *
1561
sizeof(*r->mb_type));
1563
if (!(r->cbp_chroma && r->cbp_luma && r->deblock_coefs &&
1564
r->intra_types_hist && r->mb_type)) {
1565
av_freep(&r->cbp_chroma);
1566
av_freep(&r->cbp_luma);
1567
av_freep(&r->deblock_coefs);
1568
av_freep(&r->intra_types_hist);
1569
av_freep(&r->mb_type);
1570
r->intra_types = NULL;
1571
return AVERROR(ENOMEM);
1574
r->intra_types = r->intra_types_hist + r->intra_types_stride * 4;
1575
1590
r->tmp_b_block_base = NULL;
1577
memset(r->mb_type, 0, r->s.mb_stride * r->s.mb_height *
1578
sizeof(*r->mb_type));
1580
MPV_common_init(&r->s);
1591
if ((err = MPV_common_init(&r->s)) < 0)
1593
if ((err = rv34_decoder_alloc(r)) < 0)
1591
1605
if (dst == src || !s1->context_initialized)
1608
if (s->height != s1->height || s->width != s1->width) {
1610
s->height = s1->height;
1611
s->width = s1->width;
1612
if ((err = MPV_common_init(s)) < 0)
1614
if ((err = rv34_decoder_realloc(r)) < 0)
1594
1618
if ((err = ff_mpeg_update_thread_context(dst, src)))
1708
1732
if(last && s->current_picture_ptr){
1709
1733
if(r->loop_filter)
1710
1734
r->loop_filter(r, s->mb_height - 1);
1711
if (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME))
1712
ff_thread_report_progress(&s->current_picture_ptr->f,
1713
s->mb_height - 1, 0);
1714
1735
ff_er_frame_end(s);
1715
1736
MPV_frame_end(s);
1738
if (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME))
1739
ff_thread_report_progress(&s->current_picture_ptr->f, INT_MAX, 0);
1716
1741
if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
1717
1742
*pict = *(AVFrame*)s->current_picture_ptr;
1718
1743
} else if (s->last_picture_ptr != NULL) {
1733
1758
RV34DecContext *r = avctx->priv_data;
1735
1760
MPV_common_end(&r->s);
1737
av_freep(&r->intra_types_hist);
1738
r->intra_types = NULL;
1739
av_freep(&r->tmp_b_block_base);
1740
av_freep(&r->mb_type);
1741
av_freep(&r->cbp_luma);
1742
av_freep(&r->cbp_chroma);
1743
av_freep(&r->deblock_coefs);
1761
rv34_decoder_free(r);