~ubuntu-branches/ubuntu/lucid/ffmpeg/lucid-security

« back to all changes in this revision

Viewing changes to libavcodec/cavsdec.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2009-03-13 09:18:28 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20090313091828-n4ktby5eca487uhv
Tags: 3:0.svn20090303-1ubuntu1+unstripped1
merge from ubuntu.jaunty branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
 ****************************************************************************/
54
54
 
55
55
static inline void store_mvs(AVSContext *h) {
56
 
    h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + 0] = h->mv[MV_FWD_X0];
57
 
    h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + 1] = h->mv[MV_FWD_X1];
58
 
    h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + 2] = h->mv[MV_FWD_X2];
59
 
    h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + 3] = h->mv[MV_FWD_X3];
 
56
    h->col_mv[h->mbidx*4 + 0] = h->mv[MV_FWD_X0];
 
57
    h->col_mv[h->mbidx*4 + 1] = h->mv[MV_FWD_X1];
 
58
    h->col_mv[h->mbidx*4 + 2] = h->mv[MV_FWD_X2];
 
59
    h->col_mv[h->mbidx*4 + 3] = h->mv[MV_FWD_X3];
60
60
}
61
61
 
62
62
static inline void mv_pred_direct(AVSContext *h, cavs_vector *pmv_fw,
144
144
               ff_cavs_dequant_shift[qp], i))
145
145
        return -1;
146
146
    h->s.dsp.cavs_idct8_add(dst,block,stride);
 
147
    h->s.dsp.clear_block(block);
147
148
    return 0;
148
149
}
149
150
 
293
294
    if(mb_type != P_SKIP)
294
295
        decode_residual_inter(h);
295
296
    ff_cavs_filter(h,mb_type);
296
 
    *h->col_type = mb_type;
 
297
    h->col_type_base[h->mbidx] = mb_type;
297
298
}
298
299
 
299
300
static void decode_mb_b(AVSContext *h, enum cavs_mb mb_type) {
311
312
    switch(mb_type) {
312
313
    case B_SKIP:
313
314
    case B_DIRECT:
314
 
        if(!(*h->col_type)) {
 
315
        if(!h->col_type_base[h->mbidx]) {
315
316
            /* intra MB at co-location, do in-plane prediction */
316
317
            ff_cavs_mv(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_BSKIP, BLK_16X16, 1);
317
318
            ff_cavs_mv(h, MV_BWD_X0, MV_BWD_C2, MV_PRED_BSKIP, BLK_16X16, 0);
319
320
            /* direct prediction from co-located P MB, block-wise */
320
321
            for(block=0;block<4;block++)
321
322
                mv_pred_direct(h,&h->mv[mv_scan[block]],
322
 
                            &h->col_mv[(h->mby*h->mb_width+h->mbx)*4 + block]);
 
323
                                 &h->col_mv[h->mbidx*4 + block]);
323
324
        break;
324
325
    case B_FWD_16X16:
325
326
        ff_cavs_mv(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_MEDIAN, BLK_16X16, 1);
337
338
        for(block=0;block<4;block++) {
338
339
            switch(sub_type[block]) {
339
340
            case B_SUB_DIRECT:
340
 
                if(!(*h->col_type)) {
 
341
                if(!h->col_type_base[h->mbidx]) {
341
342
                    /* intra MB at co-location, do in-plane prediction */
342
343
                    ff_cavs_mv(h, mv_scan[block], mv_scan[block]-3,
343
344
                            MV_PRED_BSKIP, BLK_8X8, 1);
346
347
                            MV_PRED_BSKIP, BLK_8X8, 0);
347
348
                } else
348
349
                    mv_pred_direct(h,&h->mv[mv_scan[block]],
349
 
                                   &h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + block]);
 
350
                                   &h->col_mv[h->mbidx*4 + block]);
350
351
                break;
351
352
            case B_SUB_FWD:
352
353
                ff_cavs_mv(h, mv_scan[block], mv_scan[block]-3,
414
415
    if(h->stc > 0xAF)
415
416
        av_log(h->s.avctx, AV_LOG_ERROR, "unexpected start code 0x%02x\n", h->stc);
416
417
    h->mby = h->stc;
 
418
    h->mbidx = h->mby*h->mb_width;
 
419
 
 
420
    /* mark top macroblocks as unavailable */
 
421
    h->flags &= ~(B_AVAIL|C_AVAIL);
417
422
    if((h->mby == 0) && (!h->qp_fixed)){
418
423
        h->qp_fixed = get_bits1(gb);
419
424
        h->qp = get_bits(gb,6);
427
432
    return 0;
428
433
}
429
434
 
430
 
static inline void check_for_slice(AVSContext *h) {
 
435
static inline int check_for_slice(AVSContext *h) {
431
436
    GetBitContext *gb = &h->s.gb;
432
437
    int align;
 
438
 
 
439
    if(h->mbx)
 
440
        return 0;
433
441
    align = (-get_bits_count(gb)) & 7;
 
442
    /* check for stuffing byte */
 
443
    if(!align && (show_bits(gb,8) == 0x80))
 
444
        get_bits(gb,8);
434
445
    if((show_bits_long(gb,24+align) & 0xFFFFFF) == 0x000001) {
435
446
        skip_bits_long(gb,24+align);
436
447
        h->stc = get_bits(gb,8);
437
448
        decode_slice_header(h,gb);
 
449
        return 1;
438
450
    }
 
451
    return 0;
439
452
}
440
453
 
441
454
/*****************************************************************************
446
459
 
447
460
static int decode_pic(AVSContext *h) {
448
461
    MpegEncContext *s = &h->s;
449
 
    int skip_count;
 
462
    int skip_count = -1;
450
463
    enum cavs_mb mb_type;
451
464
 
452
465
    if (!s->context_initialized) {
469
482
    } else {
470
483
        h->pic_type = FF_I_TYPE;
471
484
        if(get_bits1(&s->gb))
472
 
            skip_bits(&s->gb,16);//time_code
 
485
            skip_bits(&s->gb,24);//time_code
473
486
    }
474
487
    /* release last B frame */
475
488
    if(h->picture.data[0])
498
511
    if(s->low_delay)
499
512
        get_ue_golomb(&s->gb); //bbv_check_times
500
513
    h->progressive             = get_bits1(&s->gb);
501
 
    if(h->progressive)
502
 
        h->pic_structure = 1;
503
 
    else if(!(h->pic_structure = get_bits1(&s->gb) && (h->stc == PIC_PB_START_CODE)) )
 
514
    h->pic_structure = 1;
 
515
    if(!h->progressive)
 
516
        h->pic_structure = get_bits1(&s->gb);
 
517
    if(!h->pic_structure && h->stc == PIC_PB_START_CODE)
504
518
        skip_bits1(&s->gb);     //advanced_pred_mode_disable
505
519
    skip_bits1(&s->gb);        //top_field_first
506
520
    skip_bits1(&s->gb);        //repeat_first_field
523
537
    } else {
524
538
        h->alpha_offset = h->beta_offset  = 0;
525
539
    }
526
 
    check_for_slice(h);
527
540
    if(h->pic_type == FF_I_TYPE) {
528
541
        do {
 
542
            check_for_slice(h);
529
543
            decode_mb_i(h, 0);
530
544
        } while(ff_cavs_next_mb(h));
531
545
    } else if(h->pic_type == FF_P_TYPE) {
532
546
        do {
533
 
            if(h->skip_mode_flag) {
 
547
            if(check_for_slice(h))
 
548
                skip_count = -1;
 
549
            if(h->skip_mode_flag && (skip_count < 0))
534
550
                skip_count = get_ue_golomb(&s->gb);
535
 
                while(skip_count--) {
536
 
                    decode_mb_p(h,P_SKIP);
537
 
                    if(!ff_cavs_next_mb(h))
538
 
                        goto done;
539
 
                }
540
 
                mb_type = get_ue_golomb(&s->gb) + P_16X16;
541
 
            } else
542
 
                mb_type = get_ue_golomb(&s->gb) + P_SKIP;
543
 
            if(mb_type > P_8X8) {
544
 
                decode_mb_i(h, mb_type - P_8X8 - 1);
545
 
            } else
546
 
                decode_mb_p(h,mb_type);
 
551
            if(h->skip_mode_flag && skip_count--) {
 
552
                decode_mb_p(h,P_SKIP);
 
553
            } else {
 
554
                mb_type = get_ue_golomb(&s->gb) + P_SKIP + h->skip_mode_flag;
 
555
                if(mb_type > P_8X8)
 
556
                    decode_mb_i(h, mb_type - P_8X8 - 1);
 
557
                else
 
558
                    decode_mb_p(h,mb_type);
 
559
            }
547
560
        } while(ff_cavs_next_mb(h));
548
561
    } else { /* FF_B_TYPE */
549
562
        do {
550
 
            if(h->skip_mode_flag) {
 
563
            if(check_for_slice(h))
 
564
                skip_count = -1;
 
565
            if(h->skip_mode_flag && (skip_count < 0))
551
566
                skip_count = get_ue_golomb(&s->gb);
552
 
                while(skip_count--) {
553
 
                    decode_mb_b(h,B_SKIP);
554
 
                    if(!ff_cavs_next_mb(h))
555
 
                        goto done;
556
 
                }
557
 
                mb_type = get_ue_golomb(&s->gb) + B_DIRECT;
558
 
            } else
559
 
                mb_type = get_ue_golomb(&s->gb) + B_SKIP;
560
 
            if(mb_type > B_8X8) {
561
 
                decode_mb_i(h, mb_type - B_8X8 - 1);
562
 
            } else
563
 
                decode_mb_b(h,mb_type);
 
567
            if(h->skip_mode_flag && skip_count--) {
 
568
                decode_mb_b(h,B_SKIP);
 
569
            } else {
 
570
                mb_type = get_ue_golomb(&s->gb) + B_SKIP + h->skip_mode_flag;
 
571
                if(mb_type > B_8X8)
 
572
                    decode_mb_i(h, mb_type - B_8X8 - 1);
 
573
                else
 
574
                    decode_mb_b(h,mb_type);
 
575
            }
564
576
        } while(ff_cavs_next_mb(h));
565
577
    }
566
 
 done:
567
578
    if(h->pic_type != FF_B_TYPE) {
568
579
        if(h->DPB[1].data[0])
569
580
            s->avctx->release_buffer(s->avctx, (AVFrame *)&h->DPB[1]);
678
689
            //mpeg_decode_user_data(avctx,buf_ptr, input_size);
679
690
            break;
680
691
        default:
681
 
            if (stc >= SLICE_MIN_START_CODE &&
682
 
                stc <= SLICE_MAX_START_CODE) {
 
692
            if (stc <= SLICE_MAX_START_CODE) {
683
693
                init_get_bits(&s->gb, buf_ptr, input_size);
684
694
                decode_slice_header(h, &s->gb);
685
695
            }