~ubuntu-branches/ubuntu/trusty/libav/trusty

« back to all changes in this revision

Viewing changes to libavcodec/h264_cavlc.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler, Jonathan Nieder, Reinhard Tartler
  • Date: 2011-05-13 12:31:33 UTC
  • mfrom: (1.2.2 upstream)
  • mto: (1.3.4 sid)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20110513123133-zqcsj91sf5489y4s
Tags: 4:0.7~beta2-1
[ Jonathan Nieder ]
* only install doc/APIChanges in *-dev and libav-doc packages
* move note on source package lineage to README.Debian
* install NEWS.Debian in libavcodec-dev
* use dpkg source format 3.0 (quilt)
* allow "debian/rules clean" as unprivileged user

[ Reinhard Tartler ]
* New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
488
488
            zeros_left= get_vlc2(gb, (total_zeros_vlc-1)[ total_coeff ].table, TOTAL_ZEROS_VLC_BITS, 1);
489
489
    }
490
490
 
491
 
    scantable += zeros_left + total_coeff - 1;
492
 
    if(n >= LUMA_DC_BLOCK_INDEX){
493
 
        block[*scantable] = level[0];
494
 
        for(i=1;i<total_coeff && zeros_left > 0;i++) {
495
 
            if(zeros_left < 7)
496
 
                run_before= get_vlc2(gb, (run_vlc-1)[zeros_left].table, RUN_VLC_BITS, 1);
497
 
            else
498
 
                run_before= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2);
499
 
            zeros_left -= run_before;
500
 
            scantable -= 1 + run_before;
501
 
            block[*scantable]= level[i];
502
 
        }
503
 
        for(;i<total_coeff;i++) {
504
 
            scantable--;
505
 
            block[*scantable]= level[i];
506
 
        }
507
 
    }else{
508
 
        block[*scantable] = (level[0] * qmul[*scantable] + 32)>>6;
509
 
        for(i=1;i<total_coeff && zeros_left > 0;i++) {
510
 
            if(zeros_left < 7)
511
 
                run_before= get_vlc2(gb, (run_vlc-1)[zeros_left].table, RUN_VLC_BITS, 1);
512
 
            else
513
 
                run_before= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2);
514
 
            zeros_left -= run_before;
515
 
            scantable -= 1 + run_before;
516
 
            block[*scantable]= (level[i] * qmul[*scantable] + 32)>>6;
517
 
        }
518
 
        for(;i<total_coeff;i++) {
519
 
            scantable--;
520
 
            block[*scantable]= (level[i] * qmul[*scantable] + 32)>>6;
521
 
        }
 
491
#define STORE_BLOCK(type) \
 
492
    scantable += zeros_left + total_coeff - 1; \
 
493
    if(n >= LUMA_DC_BLOCK_INDEX){ \
 
494
        ((type*)block)[*scantable] = level[0]; \
 
495
        for(i=1;i<total_coeff && zeros_left > 0;i++) { \
 
496
            if(zeros_left < 7) \
 
497
                run_before= get_vlc2(gb, (run_vlc-1)[zeros_left].table, RUN_VLC_BITS, 1); \
 
498
            else \
 
499
                run_before= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2); \
 
500
            zeros_left -= run_before; \
 
501
            scantable -= 1 + run_before; \
 
502
            ((type*)block)[*scantable]= level[i]; \
 
503
        } \
 
504
        for(;i<total_coeff;i++) { \
 
505
            scantable--; \
 
506
            ((type*)block)[*scantable]= level[i]; \
 
507
        } \
 
508
    }else{ \
 
509
        ((type*)block)[*scantable] = ((int)(level[0] * qmul[*scantable] + 32))>>6; \
 
510
        for(i=1;i<total_coeff && zeros_left > 0;i++) { \
 
511
            if(zeros_left < 7) \
 
512
                run_before= get_vlc2(gb, (run_vlc-1)[zeros_left].table, RUN_VLC_BITS, 1); \
 
513
            else \
 
514
                run_before= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2); \
 
515
            zeros_left -= run_before; \
 
516
            scantable -= 1 + run_before; \
 
517
            ((type*)block)[*scantable]= ((int)(level[i] * qmul[*scantable] + 32))>>6; \
 
518
        } \
 
519
        for(;i<total_coeff;i++) { \
 
520
            scantable--; \
 
521
            ((type*)block)[*scantable]= ((int)(level[i] * qmul[*scantable] + 32))>>6; \
 
522
        } \
 
523
    }
 
524
 
 
525
    if (h->pixel_shift) {
 
526
        STORE_BLOCK(int32_t)
 
527
    } else {
 
528
        STORE_BLOCK(int16_t)
522
529
    }
523
530
 
524
531
    if(zeros_left<0){
535
542
    int partition_count;
536
543
    unsigned int mb_type, cbp;
537
544
    int dct8x8_allowed= h->pps.transform_8x8_mode;
 
545
    const int pixel_shift = h->pixel_shift;
538
546
 
539
547
    mb_xy = h->mb_xy = s->mb_x + s->mb_y*s->mb_stride;
540
548
 
541
549
    tprintf(s->avctx, "pic:%d mb:%d/%d\n", h->frame_num, s->mb_x, s->mb_y);
542
550
    cbp = 0; /* avoid warning. FIXME: find a solution without slowing
543
551
                down the code */
544
 
    if(h->slice_type_nos != FF_I_TYPE){
 
552
    if(h->slice_type_nos != AV_PICTURE_TYPE_I){
545
553
        if(s->mb_skip_run==-1)
546
554
            s->mb_skip_run= get_ue_golomb(&s->gb);
547
555
 
562
570
    h->prev_mb_skipped= 0;
563
571
 
564
572
    mb_type= get_ue_golomb(&s->gb);
565
 
    if(h->slice_type_nos == FF_B_TYPE){
 
573
    if(h->slice_type_nos == AV_PICTURE_TYPE_B){
566
574
        if(mb_type < 23){
567
575
            partition_count= b_mb_type_info[mb_type].partition_count;
568
576
            mb_type=         b_mb_type_info[mb_type].type;
570
578
            mb_type -= 23;
571
579
            goto decode_intra_mb;
572
580
        }
573
 
    }else if(h->slice_type_nos == FF_P_TYPE){
 
581
    }else if(h->slice_type_nos == AV_PICTURE_TYPE_P){
574
582
        if(mb_type < 5){
575
583
            partition_count= p_mb_type_info[mb_type].partition_count;
576
584
            mb_type=         p_mb_type_info[mb_type].type;
579
587
            goto decode_intra_mb;
580
588
        }
581
589
    }else{
582
 
       assert(h->slice_type_nos == FF_I_TYPE);
583
 
        if(h->slice_type == FF_SI_TYPE && mb_type)
 
590
       assert(h->slice_type_nos == AV_PICTURE_TYPE_I);
 
591
        if(h->slice_type == AV_PICTURE_TYPE_SI && mb_type)
584
592
            mb_type--;
585
593
decode_intra_mb:
586
594
        if(mb_type > 25){
587
 
            av_log(h->s.avctx, AV_LOG_ERROR, "mb_type %d in %c slice too large at %d %d\n", mb_type, av_get_pict_type_char(h->slice_type), s->mb_x, s->mb_y);
 
595
            av_log(h->s.avctx, AV_LOG_ERROR, "mb_type %d in %c slice too large at %d %d\n", mb_type, av_get_picture_type_char(h->slice_type), s->mb_x, s->mb_y);
588
596
            return -1;
589
597
        }
590
598
        partition_count=0;
605
613
        align_get_bits(&s->gb);
606
614
 
607
615
        // The pixels are stored in the same order as levels in h->mb array.
608
 
        for(x=0; x < (CHROMA ? 384 : 256); x++){
 
616
        for(x=0; x < (CHROMA ? 384 : 256)*h->sps.bit_depth_luma/8; x++){
609
617
            ((uint8_t*)h->mb)[x]= get_bits(&s->gb, 8);
610
618
        }
611
619
 
671
679
    }else if(partition_count==4){
672
680
        int i, j, sub_partition_count[4], list, ref[2][4];
673
681
 
674
 
        if(h->slice_type_nos == FF_B_TYPE){
 
682
        if(h->slice_type_nos == AV_PICTURE_TYPE_B){
675
683
            for(i=0; i<4; i++){
676
684
                h->sub_mb_type[i]= get_ue_golomb_31(&s->gb);
677
685
                if(h->sub_mb_type[i] >=13){
689
697
                h->ref_cache[1][scan8[12]] = PART_NOT_AVAILABLE;
690
698
            }
691
699
        }else{
692
 
            assert(h->slice_type_nos == FF_P_TYPE); //FIXME SP correct ?
 
700
            assert(h->slice_type_nos == AV_PICTURE_TYPE_P); //FIXME SP correct ?
693
701
            for(i=0; i<4; i++){
694
702
                h->sub_mb_type[i]= get_ue_golomb_31(&s->gb);
695
703
                if(h->sub_mb_type[i] >=4){
914
922
        int dquant;
915
923
        GetBitContext *gb= IS_INTRA(mb_type) ? h->intra_gb_ptr : h->inter_gb_ptr;
916
924
        const uint8_t *scan, *scan8x8;
 
925
        const int max_qp = 51 + 6*(h->sps.bit_depth_luma-8);
917
926
 
918
927
        if(IS_INTERLACED(mb_type)){
919
928
            scan8x8= s->qscale ? h->field_scan8x8_cavlc : h->field_scan8x8_cavlc_q0;
927
936
 
928
937
        s->qscale += dquant;
929
938
 
930
 
        if(((unsigned)s->qscale) > 51){
931
 
            if(s->qscale<0) s->qscale+= 52;
932
 
            else            s->qscale-= 52;
933
 
            if(((unsigned)s->qscale) > 51){
 
939
        if(((unsigned)s->qscale) > max_qp){
 
940
            if(s->qscale<0) s->qscale+= max_qp+1;
 
941
            else            s->qscale-= max_qp+1;
 
942
            if(((unsigned)s->qscale) > max_qp){
934
943
                av_log(h->s.avctx, AV_LOG_ERROR, "dquant out of range (%d) at %d %d\n", dquant, s->mb_x, s->mb_y);
935
944
                return -1;
936
945
            }
941
950
        if(IS_INTRA16x16(mb_type)){
942
951
            AV_ZERO128(h->mb_luma_dc+0);
943
952
            AV_ZERO128(h->mb_luma_dc+8);
 
953
            AV_ZERO128(h->mb_luma_dc+16);
 
954
            AV_ZERO128(h->mb_luma_dc+24);
944
955
            if( decode_residual(h, h->intra_gb_ptr, h->mb_luma_dc, LUMA_DC_BLOCK_INDEX, scan, h->dequant4_coeff[0][s->qscale], 16) < 0){
945
956
                return -1; //FIXME continue if partitioned and other return -1 too
946
957
            }
951
962
                for(i8x8=0; i8x8<4; i8x8++){
952
963
                    for(i4x4=0; i4x4<4; i4x4++){
953
964
                        const int index= i4x4 + 4*i8x8;
954
 
                        if( decode_residual(h, h->intra_gb_ptr, h->mb + 16*index, index, scan + 1, h->dequant4_coeff[0][s->qscale], 15) < 0 ){
 
965
                        if( decode_residual(h, h->intra_gb_ptr, h->mb + (16*index << pixel_shift), index, scan + 1, h->dequant4_coeff[0][s->qscale], 15) < 0 ){
955
966
                            return -1;
956
967
                        }
957
968
                    }
963
974
            for(i8x8=0; i8x8<4; i8x8++){
964
975
                if(cbp & (1<<i8x8)){
965
976
                    if(IS_8x8DCT(mb_type)){
966
 
                        DCTELEM *buf = &h->mb[64*i8x8];
 
977
                        DCTELEM *buf = &h->mb[64*i8x8 << pixel_shift];
967
978
                        uint8_t *nnz;
968
979
                        for(i4x4=0; i4x4<4; i4x4++){
969
980
                            if( decode_residual(h, gb, buf, i4x4+4*i8x8, scan8x8+16*i4x4,
976
987
                        for(i4x4=0; i4x4<4; i4x4++){
977
988
                            const int index= i4x4 + 4*i8x8;
978
989
 
979
 
                            if( decode_residual(h, gb, h->mb + 16*index, index, scan, h->dequant4_coeff[IS_INTRA( mb_type ) ? 0:3][s->qscale], 16) <0 ){
 
990
                            if( decode_residual(h, gb, h->mb + (16*index << pixel_shift), index, scan, h->dequant4_coeff[IS_INTRA( mb_type ) ? 0:3][s->qscale], 16) <0 ){
980
991
                                return -1;
981
992
                            }
982
993
                        }
990
1001
 
991
1002
        if(cbp&0x30){
992
1003
            for(chroma_idx=0; chroma_idx<2; chroma_idx++)
993
 
                if( decode_residual(h, gb, h->mb + 256 + 16*4*chroma_idx, CHROMA_DC_BLOCK_INDEX+chroma_idx, chroma_dc_scan, NULL, 4) < 0){
 
1004
                if( decode_residual(h, gb, h->mb + ((256 + 16*4*chroma_idx) << pixel_shift), CHROMA_DC_BLOCK_INDEX+chroma_idx, chroma_dc_scan, NULL, 4) < 0){
994
1005
                    return -1;
995
1006
                }
996
1007
        }
1000
1011
                const uint32_t *qmul = h->dequant4_coeff[chroma_idx+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp[chroma_idx]];
1001
1012
                for(i4x4=0; i4x4<4; i4x4++){
1002
1013
                    const int index= 16 + 4*chroma_idx + i4x4;
1003
 
                    if( decode_residual(h, gb, h->mb + 16*index, index, scan + 1, qmul, 15) < 0){
 
1014
                    if( decode_residual(h, gb, h->mb + (16*index << pixel_shift), index, scan + 1, qmul, 15) < 0){
1004
1015
                        return -1;
1005
1016
                    }
1006
1017
                }