Revision a7702890

View differences:

libavcodec/bitstream.h
177 177
    unsigned int bit_buf;
178 178
    int bit_left;
179 179

  
180
#ifdef STATS
181
    st_out_bit_counts[st_current_index] += n;
182
#endif
183 180
    //    printf("put_bits=%d %x\n", n, value);
184 181
    assert(n == 32 || value < (1U << n));
185 182

  
libavcodec/mpegvideo.c
1371 1371
{
1372 1372
    MpegEncContext *s = avctx->priv_data;
1373 1373

  
1374
#ifdef STATS
1375
    print_stats();
1376
#endif
1377

  
1378 1374
    ff_rate_control_uninit(s);
1379 1375

  
1380 1376
    MPV_common_end(s);
libavcodec/msmpeg4.c
89 89
static uint8_t rl_length[NB_RL_TABLES][MAX_LEVEL+1][MAX_RUN+1][2];
90 90
#endif //CONFIG_ENCODERS
91 91

  
92
#ifdef STATS
93

  
94
const char *st_names[ST_NB] = {
95
    "unknown",
96
    "dc",
97
    "intra_ac",
98
    "inter_ac",
99
    "intra_mb",
100
    "inter_mb",
101
    "mv",
102
};
103

  
104
int st_current_index = 0;
105
unsigned int st_bit_counts[ST_NB];
106
unsigned int st_out_bit_counts[ST_NB];
107

  
108
#define set_stat(var) st_current_index = var;
109

  
110
void print_stats(void)
111
{
112
    unsigned int total;
113
    int i;
114

  
115
    printf("Input:\n");
116
    total = 0;
117
    for(i=0;i<ST_NB;i++)
118
        total += st_bit_counts[i];
119
    if (total == 0)
120
        total = 1;
121
    for(i=0;i<ST_NB;i++) {
122
        printf("%-10s : %10.1f %5.1f%%\n",
123
               st_names[i],
124
               (double)st_bit_counts[i] / 8.0,
125
               (double)st_bit_counts[i] * 100.0 / total);
126
    }
127
    printf("%-10s : %10.1f %5.1f%%\n",
128
           "total",
129
           (double)total / 8.0,
130
           100.0);
131

  
132
    printf("Output:\n");
133
    total = 0;
134
    for(i=0;i<ST_NB;i++)
135
        total += st_out_bit_counts[i];
136
    if (total == 0)
137
        total = 1;
138
    for(i=0;i<ST_NB;i++) {
139
        printf("%-10s : %10.1f %5.1f%%\n",
140
               st_names[i],
141
               (double)st_out_bit_counts[i] / 8.0,
142
               (double)st_out_bit_counts[i] * 100.0 / total);
143
    }
144
    printf("%-10s : %10.1f %5.1f%%\n",
145
           "total",
146
           (double)total / 8.0,
147
           100.0);
148
}
149

  
150
#else
151

  
152
#define set_stat(var)
153

  
154
#endif
155

  
156 92
static void common_init(MpegEncContext * s)
157 93
{
158 94
    static int inited=0;
......
509 445
    mv = &mv_tables[s->mv_table_index];
510 446

  
511 447
    code = mv->table_mv_index[(mx << 6) | my];
512
    set_stat(ST_MV);
513 448
    put_bits(&s->pb,
514 449
             mv->table_mv_bits[code],
515 450
             mv->table_mv_code[code]);
......
545 480

  
546 481
    if (!s->mb_intra) {
547 482
        /* compute cbp */
548
        set_stat(ST_INTER_MB);
549 483
        cbp = 0;
550 484
        for (i = 0; i < 6; i++) {
551 485
            if (s->block_last_index[i] >= 0)
......
636 570
                     cbpy_tab[cbp>>2][0]);
637 571
        }else{
638 572
            if (s->pict_type == I_TYPE) {
639
                set_stat(ST_INTRA_MB);
640 573
                put_bits(&s->pb,
641 574
                         ff_msmp4_mb_i_table[coded_cbp][1], ff_msmp4_mb_i_table[coded_cbp][0]);
642 575
            } else {
......
646 579
                         table_mb_non_intra[cbp][1],
647 580
                         table_mb_non_intra[cbp][0]);
648 581
            }
649
            set_stat(ST_INTRA_MB);
650 582
            put_bits(&s->pb, 1, 0);             /* no AC prediction yet */
651 583
            if(s->inter_intra_pred){
652 584
                s->h263_aic_dir=0;
......
924 856
    const uint8_t *scantable;
925 857

  
926 858
    if (s->mb_intra) {
927
        set_stat(ST_DC);
928 859
        msmpeg4_encode_dc(s, block[0], n, &dc_pred_dir);
929 860
        i = 1;
930 861
        if (n < 4) {
......
934 865
        }
935 866
        run_diff = 0;
936 867
        scantable= s->intra_scantable.permutated;
937
        set_stat(ST_INTRA_AC);
938 868
    } else {
939 869
        i = 0;
940 870
        rl = &rl_table[3 + s->rl_table_index];
......
943 873
        else
944 874
            run_diff = 1;
945 875
        scantable= s->inter_scantable.permutated;
946
        set_stat(ST_INTER_AC);
947 876
    }
948 877

  
949 878
    /* recalculate block_last_index for M$ wmv1 */
......
1572 1501
    uint32_t * const mb_type_ptr= &s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride ];
1573 1502

  
1574 1503
    if (s->pict_type == P_TYPE) {
1575
        set_stat(ST_INTER_MB);
1576 1504
        if (s->use_skip_mb_code) {
1577 1505
            if (get_bits1(&s->gb)) {
1578 1506
                /* skip mb */
......
1598 1526

  
1599 1527
        cbp = code & 0x3f;
1600 1528
    } else {
1601
        set_stat(ST_INTRA_MB);
1602 1529
        s->mb_intra = 1;
1603 1530
        code = get_vlc2(&s->gb, ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS, 2);
1604 1531
        if (code < 0)
......
1623 1550
            s->rl_table_index = decode012(&s->gb);
1624 1551
            s->rl_chroma_table_index = s->rl_table_index;
1625 1552
        }
1626
        set_stat(ST_MV);
1627 1553
        h263_pred_motion(s, 0, 0, &mx, &my);
1628 1554
        if (msmpeg4_decode_motion(s, &mx, &my) < 0)
1629 1555
            return -1;
......
1634 1560
        *mb_type_ptr = MB_TYPE_L0 | MB_TYPE_16x16;
1635 1561
    } else {
1636 1562
//printf("I at %d %d %d %06X\n", s->mb_x, s->mb_y, ((cbp&3)? 1 : 0) +((cbp&0x3C)? 2 : 0), show_bits(&s->gb, 24));
1637
        set_stat(ST_INTRA_MB);
1638 1563
        s->ac_pred = get_bits1(&s->gb);
1639 1564
        *mb_type_ptr = MB_TYPE_INTRA;
1640 1565
        if(s->inter_intra_pred){
......
1673 1598
        qadd=0;
1674 1599

  
1675 1600
        /* DC coef */
1676
        set_stat(ST_DC);
1677 1601
        level = msmpeg4_decode_dc(s, n, &dc_pred_dir);
1678 1602

  
1679 1603
        if (level < 0){
......
1709 1633
        } else {
1710 1634
            scan_table = s->intra_scantable.permutated;
1711 1635
        }
1712
        set_stat(ST_INTRA_AC);
1713 1636
        rl_vlc= rl->rl_vlc[0];
1714 1637
    } else {
1715 1638
        qmul = s->qscale << 1;
......
1728 1651
        }
1729 1652
        if(!scan_table)
1730 1653
            scan_table = s->inter_scantable.permutated;
1731
        set_stat(ST_INTER_AC);
1732 1654
        rl_vlc= rl->rl_vlc[s->qscale];
1733 1655
    }
1734 1656
  {
libavcodec/wmv2.c
207 207

  
208 208
    if (!s->mb_intra) {
209 209
        /* compute cbp */
210
        set_stat(ST_INTER_MB);
211 210
        cbp = 0;
212 211
        for (i = 0; i < 6; i++) {
213 212
            if (s->block_last_index[i] >= 0)
......
244 243
#endif
245 244

  
246 245
        if (s->pict_type == I_TYPE) {
247
            set_stat(ST_INTRA_MB);
248 246
            put_bits(&s->pb,
249 247
                     ff_msmp4_mb_i_table[coded_cbp][1], ff_msmp4_mb_i_table[coded_cbp][0]);
250 248
        } else {
......
252 250
                     wmv2_inter_table[w->cbp_table_index][cbp][1],
253 251
                     wmv2_inter_table[w->cbp_table_index][cbp][0]);
254 252
        }
255
        set_stat(ST_INTRA_MB);
256 253
        put_bits(&s->pb, 1, 0);         /* no AC prediction yet */
257 254
        if(s->inter_intra_pred){
258 255
            s->h263_aic_dir=0;
libavformat/gif.c
113 113
    unsigned int bit_buf;
114 114
    int bit_cnt;
115 115

  
116
#ifdef STATS
117
    st_out_bit_counts[st_current_index] += n;
118
#endif
119 116
    //    printf("put_bits=%d %x\n", n, value);
120 117
    assert(n == 32 || value < (1U << n));
121 118

  
libavutil/common.h
339 339
#    define FASTDIV(a,b)   ((a)/(b))
340 340
#endif
341 341

  
342
/* define it to include statistics code (useful only for optimizing
343
   codec efficiency */
344
//#define STATS
345

  
346
#ifdef STATS
347

  
348
enum {
349
    ST_UNKNOWN,
350
    ST_DC,
351
    ST_INTRA_AC,
352
    ST_INTER_AC,
353
    ST_INTRA_MB,
354
    ST_INTER_MB,
355
    ST_MV,
356
    ST_NB,
357
};
358

  
359
extern int st_current_index;
360
extern unsigned int st_bit_counts[ST_NB];
361
extern unsigned int st_out_bit_counts[ST_NB];
362

  
363
void print_stats(void);
364
#endif
365

  
366 342
/* misc math functions */
367 343
extern FF_IMPORT_ATTR const uint8_t ff_log2_tab[256];
368 344

  

Also available in: Unified diff