Revision d268bed2

View differences:

libavcodec/h264.c
45 45
//#undef NDEBUG
46 46
#include <assert.h>
47 47

  
48
static const uint8_t rem6[52]={
49
0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3,
48
static const uint8_t rem6[QP_MAX_MAX+1]={
49
0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3,
50 50
};
51 51

  
52
static const uint8_t div6[52]={
53
0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
52
static const uint8_t div6[QP_MAX_MAX+1]={
53
0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,
54 54
};
55 55

  
56 56
static const enum PixelFormat hwaccel_pixfmt_list_h264_jpeg_420[] = {
......
769 769

  
770 770
static void init_dequant8_coeff_table(H264Context *h){
771 771
    int i,q,x;
772
    const int max_qp = 51 + 6*(h->sps.bit_depth_luma-8);
772 773
    h->dequant8_coeff[0] = h->dequant8_buffer[0];
773 774
    h->dequant8_coeff[1] = h->dequant8_buffer[1];
774 775

  
......
778 779
            break;
779 780
        }
780 781

  
781
        for(q=0; q<52; q++){
782
        for(q=0; q<max_qp+1; q++){
782 783
            int shift = div6[q];
783 784
            int idx = rem6[q];
784 785
            for(x=0; x<64; x++)
......
791 792

  
792 793
static void init_dequant4_coeff_table(H264Context *h){
793 794
    int i,j,q,x;
795
    const int max_qp = 51 + 6*(h->sps.bit_depth_luma-8);
794 796
    for(i=0; i<6; i++ ){
795 797
        h->dequant4_coeff[i] = h->dequant4_buffer[i];
796 798
        for(j=0; j<i; j++){
......
802 804
        if(j<i)
803 805
            continue;
804 806

  
805
        for(q=0; q<52; q++){
807
        for(q=0; q<max_qp+1; q++){
806 808
            int shift = div6[q] + 2;
807 809
            int idx = rem6[q];
808 810
            for(x=0; x<16; x++)
......
1003 1005

  
1004 1006
    ff_h264_decode_init_vlc();
1005 1007

  
1008
    h->sps.bit_depth_luma = 8;
1006 1009
    h->pixel_size = 1;
1007 1010

  
1008 1011
    h->thread_context[0] = h;
......
1771 1774
                    for(i=16; i<16+8; i++){
1772 1775
                        if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){
1773 1776
                            uint8_t * const ptr= dest[(i&4)>>2] + block_offset[i];
1774
                            ff_svq3_add_idct_c(ptr, h->mb + i*16, uvlinesize, ff_h264_chroma_qp[s->qscale + 12] - 12, 2);
1777
                            ff_svq3_add_idct_c(ptr, h->mb + i*16, uvlinesize, ff_h264_chroma_qp[0][s->qscale + 12] - 12, 2);
1775 1778
                        }
1776 1779
                    }
1777 1780
                }
......
2589 2592

  
2590 2593
    h->last_qscale_diff = 0;
2591 2594
    tmp = h->pps.init_qp + get_se_golomb(&s->gb);
2592
    if(tmp>51){
2595
    if(tmp>51+6*(h->sps.bit_depth_luma-8)){
2593 2596
        av_log(s->avctx, AV_LOG_ERROR, "QP %u out of range\n", tmp);
2594 2597
        return -1;
2595 2598
    }
libavcodec/h264.h
108 108
 */
109 109
#define DELAYED_PIC_REF 4
110 110

  
111
#define QP_MAX_MAX (51 + 2*6)           // The maximum supported qp
111 112

  
112 113
/* NAL unit types */
113 114
enum {
......
354 355
     */
355 356
    PPS pps; //FIXME move to Picture perhaps? (->no) do we need that?
356 357

  
357
    uint32_t dequant4_buffer[6][52][16]; //FIXME should these be moved down?
358
    uint32_t dequant8_buffer[2][52][64];
358
    uint32_t dequant4_buffer[6][QP_MAX_MAX+1][16]; //FIXME should these be moved down?
359
    uint32_t dequant8_buffer[2][QP_MAX_MAX+1][64];
359 360
    uint32_t (*dequant4_coeff[6])[16];
360 361
    uint32_t (*dequant8_coeff[2])[64];
361 362

  
......
603 604
}H264Context;
604 605

  
605 606

  
606
extern const uint8_t ff_h264_chroma_qp[52];
607
extern const uint8_t ff_h264_chroma_qp[3][QP_MAX_MAX+1]; ///< One chroma qp table for each supported bit depth (8, 9, 10).
607 608

  
608 609
/**
609 610
 * Decode SEI
libavcodec/h264_cabac.c
689 689
    MpegEncContext * const s = &h->s;
690 690
    int i;
691 691
    const int8_t (*tab)[2];
692
    const int slice_qp = av_clip(s->qscale - 6*(h->sps.bit_depth_luma-8), 0, 51);
692 693

  
693 694
    if( h->slice_type_nos == FF_I_TYPE ) tab = cabac_context_init_I;
694 695
    else                                 tab = cabac_context_init_PB[h->cabac_init_idc];
695 696

  
696 697
    /* calculate pre-state */
697 698
    for( i= 0; i < 460; i++ ) {
698
        int pre = 2*(((tab[i][0] * s->qscale) >>4 ) + tab[i][1]) - 127;
699
        int pre = 2*(((tab[i][0] * slice_qp) >>4 ) + tab[i][1]) - 127;
699 700

  
700 701
        pre^= pre>>31;
701 702
        if(pre > 124)
......
1630 1631
        if(get_cabac_noinline( &h->cabac, &h->cabac_state[60 + (h->last_qscale_diff != 0)])){
1631 1632
            int val = 1;
1632 1633
            int ctx= 2;
1634
            const int max_qp = 51 + 6*(h->sps.bit_depth_luma-8);
1633 1635

  
1634 1636
            while( get_cabac_noinline( &h->cabac, &h->cabac_state[60 + ctx] ) ) {
1635 1637
                ctx= 3;
1636 1638
                val++;
1637
                if(val > 102){ //prevent infinite loop
1639
                if(val > 2*max_qp){ //prevent infinite loop
1638 1640
                    av_log(h->s.avctx, AV_LOG_ERROR, "cabac decode of qscale diff failed at %d %d\n", s->mb_x, s->mb_y);
1639 1641
                    return -1;
1640 1642
                }
......
1646 1648
                val= -((val + 1)>>1);
1647 1649
            h->last_qscale_diff = val;
1648 1650
            s->qscale += val;
1649
            if(((unsigned)s->qscale) > 51){
1650
                if(s->qscale<0) s->qscale+= 52;
1651
                else            s->qscale-= 52;
1651
            if(((unsigned)s->qscale) > max_qp){
1652
                if(s->qscale<0) s->qscale+= max_qp+1;
1653
                else            s->qscale-= max_qp+1;
1652 1654
            }
1653 1655
            h->chroma_qp[0] = get_chroma_qp(h, 0, s->qscale);
1654 1656
            h->chroma_qp[1] = get_chroma_qp(h, 1, s->qscale);
libavcodec/h264_cavlc.c
921 921
        int dquant;
922 922
        GetBitContext *gb= IS_INTRA(mb_type) ? h->intra_gb_ptr : h->inter_gb_ptr;
923 923
        const uint8_t *scan, *scan8x8;
924
        const int max_qp = 51 + 6*(h->sps.bit_depth_luma-8);
924 925

  
925 926
        if(IS_INTERLACED(mb_type)){
926 927
            scan8x8= s->qscale ? h->field_scan8x8_cavlc : h->field_scan8x8_cavlc_q0;
......
934 935

  
935 936
        s->qscale += dquant;
936 937

  
937
        if(((unsigned)s->qscale) > 51){
938
            if(s->qscale<0) s->qscale+= 52;
939
            else            s->qscale-= 52;
940
            if(((unsigned)s->qscale) > 51){
938
        if(((unsigned)s->qscale) > max_qp){
939
            if(s->qscale<0) s->qscale+= max_qp+1;
940
            else            s->qscale-= max_qp+1;
941
            if(((unsigned)s->qscale) > max_qp){
941 942
                av_log(h->s.avctx, AV_LOG_ERROR, "dquant out of range (%d) at %d %d\n", dquant, s->mb_x, s->mb_y);
942 943
                return -1;
943 944
            }
libavcodec/h264_ps.c
57 57
 {2, 1},
58 58
};
59 59

  
60
const uint8_t ff_h264_chroma_qp[52]={
61
    0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,
62
   12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,
63
   28,29,29,30,31,32,32,33,34,34,35,35,36,36,37,37,
64
   37,38,38,38,39,39,39,39
60
#define QP(qP,depth) ( (qP)+6*((depth)-8) )
61

  
62
#define CHROMA_QP_TABLE_END(d) \
63
     QP(0,d),  QP(1,d),  QP(2,d),  QP(3,d),  QP(4,d),  QP(5,d),\
64
     QP(6,d),  QP(7,d),  QP(8,d),  QP(9,d), QP(10,d), QP(11,d),\
65
    QP(12,d), QP(13,d), QP(14,d), QP(15,d), QP(16,d), QP(17,d),\
66
    QP(18,d), QP(19,d), QP(20,d), QP(21,d), QP(22,d), QP(23,d),\
67
    QP(24,d), QP(25,d), QP(26,d), QP(27,d), QP(28,d), QP(29,d),\
68
    QP(29,d), QP(30,d), QP(31,d), QP(32,d), QP(32,d), QP(33,d),\
69
    QP(34,d), QP(34,d), QP(35,d), QP(35,d), QP(36,d), QP(36,d),\
70
    QP(37,d), QP(37,d), QP(37,d), QP(38,d), QP(38,d), QP(38,d),\
71
    QP(39,d), QP(39,d), QP(39,d), QP(39,d)
72

  
73
const uint8_t ff_h264_chroma_qp[3][QP_MAX_MAX+1] = {
74
    {
75
        CHROMA_QP_TABLE_END(8)
76
    },
77
    {
78
        0, 1, 2, 3, 4, 5,
79
        CHROMA_QP_TABLE_END(9)
80
    },
81
    {
82
        0, 1, 2, 3,  4,  5,
83
        6, 7, 8, 9, 10, 11,
84
        CHROMA_QP_TABLE_END(10)
85
    },
65 86
};
66 87

  
67 88
static const uint8_t default_scaling4[2][16]={
......
419 440
}
420 441

  
421 442
static void
422
build_qp_table(PPS *pps, int t, int index)
443
build_qp_table(PPS *pps, int t, int index, const int depth)
423 444
{
424 445
    int i;
425
    for(i = 0; i < 52; i++)
426
        pps->chroma_qp_table[t][i] = ff_h264_chroma_qp[av_clip(i + index, 0, 51)];
446
    const int max_qp = 51 + 6*(depth-8);
447
    for(i = 0; i < max_qp+1; i++)
448
        pps->chroma_qp_table[t][i] = ff_h264_chroma_qp[depth-8][av_clip(i + index, 0, max_qp)];
427 449
}
428 450

  
429 451
int ff_h264_decode_picture_parameter_set(H264Context *h, int bit_length){
430 452
    MpegEncContext * const s = &h->s;
431 453
    unsigned int pps_id= get_ue_golomb(&s->gb);
432 454
    PPS *pps;
455
    const int qp_bd_offset = 6*(h->sps.bit_depth_luma-8);
433 456

  
434 457
    if(pps_id >= MAX_PPS_COUNT) {
435 458
        av_log(h->s.avctx, AV_LOG_ERROR, "pps_id (%d) out of range\n", pps_id);
......
494 517

  
495 518
    pps->weighted_pred= get_bits1(&s->gb);
496 519
    pps->weighted_bipred_idc= get_bits(&s->gb, 2);
497
    pps->init_qp= get_se_golomb(&s->gb) + 26;
498
    pps->init_qs= get_se_golomb(&s->gb) + 26;
520
    pps->init_qp= get_se_golomb(&s->gb) + 26 + qp_bd_offset;
521
    pps->init_qs= get_se_golomb(&s->gb) + 26 + qp_bd_offset;
499 522
    pps->chroma_qp_index_offset[0]= get_se_golomb(&s->gb);
500 523
    pps->deblocking_filter_parameters_present= get_bits1(&s->gb);
501 524
    pps->constrained_intra_pred= get_bits1(&s->gb);
......
514 537
        pps->chroma_qp_index_offset[1]= pps->chroma_qp_index_offset[0];
515 538
    }
516 539

  
517
    build_qp_table(pps, 0, pps->chroma_qp_index_offset[0]);
518
    build_qp_table(pps, 1, pps->chroma_qp_index_offset[1]);
540
    build_qp_table(pps, 0, pps->chroma_qp_index_offset[0], h->sps.bit_depth_luma);
541
    build_qp_table(pps, 1, pps->chroma_qp_index_offset[1], h->sps.bit_depth_luma);
519 542
    if(pps->chroma_qp_index_offset[0] != pps->chroma_qp_index_offset[1])
520 543
        pps->chroma_qp_diff= 1;
521 544

  

Also available in: Unified diff