1 /******************************************************************************
2 *
3 * Copyright (C) 2012 Ittiam Systems Pvt Ltd, Bangalore
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 ******************************************************************************/
18 /**
19 *******************************************************************************
20 * @file
21 *  ihevcd_statistics.h
22 *
23 * @brief
24 *  Contains macros for generating stats about hevc decoder
25 *
26 * @author
27 *  Naveen SR
28 *
29 * @par List of Functions:
30 *
31 * @remarks
32 *  None
33 *
34 *******************************************************************************
35 */
36 
37 #ifndef _IHEVCD_STATISTICS_H_
38 #define _IHEVCD_STATISTICS_H_
39 
40 #include <stdio.h>
41 #include "ihevc_typedefs.h"
42 #include "iv.h"
43 #include "ivd.h"
44 #include "ihevcd_cxa.h"
45 #include "ithread.h"
46 
47 #include "ihevc_defs.h"
48 #include "ihevc_structs.h"
49 
50 #include "ihevc_cabac_tables.h"
51 #include "ihevcd_defs.h"
52 
53 #include "ihevcd_structs.h"
54 #include "ihevcd_iquant_itrans_recon_ctb.h"
55 #include "ihevcd_statistics.h"
56 
57 #define STATISTICS_ENABLE 0
58 
59 #if STATISTICS_ENABLE
60 
61 typedef struct
62 {
63     UWORD32 num_4x4_dst;
64     UWORD32 num_4x4;
65     UWORD32 num_8x8;
66     UWORD32 num_16x16;
67     UWORD32 num_32x32;
68     UWORD32 num_64x64;
69 }stat_trans_t;
70 
71 typedef struct
72 {
73     /* 4x4 Subblock count */
74     UWORD32 trans_4x4_dst[1];
75     UWORD32 trans_4x4[1];
76     UWORD32 trans_8x8[4];
77     UWORD32 trans_16x16[16];
78     UWORD32 trans_32x32[64];
79 }stat_sblk_histogram_t;
80 
81 typedef struct
82 {
83     /* 4x4 Subblock count */
84     UWORD32 trans_4x4_dst[16];
85     UWORD32 trans_4x4[16];
86     UWORD32 trans_8x8[64];
87     UWORD32 trans_16x16[256];
88     UWORD32 trans_32x32[1024];
89 }stat_coeff_histogram_t;
90 
91 typedef struct
92 {
93     stat_trans_t stat_num_all_trans_block[2]; /* Y and UV */
94     stat_trans_t stat_num_coded_trans_block[2]; /* Y and UV */
95     stat_trans_t stat_num_coded_dc_block[2]; /* Y and UV */
96     stat_trans_t stat_num_coded_one_coeff_block[2]; /* Y and UV */
97     stat_sblk_histogram_t stat_last_sblk_pos_histogram; /* Y + UV */
98     stat_sblk_histogram_t stat_num_coded_sblk_histogram; /* Y + UV */
99     stat_coeff_histogram_t stat_num_coded_coeff_histogram; /* Y + UV */
100     UWORD32   stat_pu_all_size_hist[16][16]; /* PU Sizes [Width from 4 to 64 in steps of 4] [Height from 4 to 64 in steps of 4]*/
101     UWORD32   stat_pu_skip_size_hist[16][16]; /* PU sizes for skip [Width from 4 to 64 in steps of 4] [Height from 4 to 64 in steps of 4]*/
102     UWORD32   stat_pu_inter_size_hist[16][16]; /* PU sizes for inter [Width from 4 to 64 in steps of 4] [Height from 4 to 64 in steps of 4]*/
103     UWORD32   stat_pu_intra_size_hist[16][16]; /* PU sizes for intra [Width from 4 to 64 in steps of 4] [Height from 4 to 64 in steps of 4]*/
104     UWORD32   stat_pu_bipred_size_hist[16][16]; /* PU sizes for bipred [Width from 4 to 64 in steps of 4] [Height from 4 to 64 in steps of 4]*/
105     UWORD32   stat_pu_merge_size_hist[16][16]; /* PU sizes for merge [Width from 4 to 64 in steps of 4] [Height from 4 to 64 in steps of 4]*/
106     UWORD32   stat_pu_zeromv_size_hist[16][16]; /* PU sizes for Zero MV [Width from 4 to 64 in steps of 4] [Height from 4 to 64 in steps of 4]*/
107     UWORD32   stat_pu_zeromvfpel_size_hist[16][16]; /* PU sizes for Zero MV (includes subpel less than +/- 1 full pel units [Width from 4 to 64 in steps of 4] [Height from 4 to 64 in steps of 4]*/
108     UWORD32 last_sblk_pos_x; /* Last sblk pos of transform block in processing */
109     UWORD32 last_sblk_pos_y;
110     UWORD32 num_coded_sblk;
111     UWORD32 num_coded_coeffs;
112 }statistics_t;
113 
114 void ihevcd_update_num_all_trans_blocks(TRANSFORM_TYPE e_trans_type, WORD32 c_idx);
115 void ihevcd_update_num_trans_blocks(TRANSFORM_TYPE e_trans_type, WORD32 c_idx, WORD32 update_type);
116 void ihevcd_update_sblk_and_coeff_histogram(TRANSFORM_TYPE e_trans_type, WORD32 t_skip_or_tq_bypass);
117 void ihevcd_sblk_pos_init();
118 void ihevcd_sblk_pos_update(TRANSFORM_TYPE e_trans_type, WORD32 t_skip_or_tq_bypass, UWORD32 sblk_x, UWORD32 sblk_y);
119 void ihevcd_print_transform_statistics();
120 void ihevcd_update_coeff_count();
121 void ihevcd_update_pu_size(pu_t *ps_pu);
122 void ihevcd_update_pu_skip_size(pu_t *ps_pu);
123 #endif //STATISTICS_ENABLE
124 
125 #if STATISTICS_ENABLE
126 #define STATS_INIT()  ihevcd_init_statistics();
127 #define STATS_UPDATE_ALL_TRANS(e_trans_type, c_idx) ihevcd_update_num_all_trans_blocks(e_trans_type, c_idx);
128 #define STATS_UPDATE_CODED_TRANS(e_trans_type, c_idx, update_type) ihevcd_update_num_trans_blocks(e_trans_type, c_idx, update_type);
129 #define STATS_PRINT() ihevcd_print_statistics();
130 #define STATS_INIT_SBLK_AND_COEFF_POS() ihevcd_sblk_pos_init();
131 #define STATS_LAST_SBLK_POS_UPDATE(e_trans_type, t_skip_or_tq_bypass, sblk_x, sblk_y) ihevcd_sblk_pos_update(e_trans_type, t_skip_or_tq_bypass, sblk_x, sblk_y);
132 #define STATS_UPDATE_SBLK_AND_COEFF_HISTOGRAM(e_trans_type, t_skip_or_tq_bypass) ihevcd_update_sblk_and_coeff_histogram(e_trans_type, t_skip_or_tq_bypass);
133 #define STATS_UPDATE_COEFF_COUNT() ihevcd_update_coeff_count();
134 #define STATS_UPDATE_PU_SIZE(ps_pu) ihevcd_update_pu_size(ps_pu);
135 #define STATS_UPDATE_PU_SKIP_SIZE(ps_pu) ihevcd_update_pu_skip_size(ps_pu);
136 #else
137 #define STATS_INIT()  ;
138 #define STATS_UPDATE_ALL_TRANS(e_trans_type, c_idx) ;
139 #define STATS_UPDATE_CODED_TRANS(e_trans_type, c_idx, update_type) ;
140 #define STATS_PRINT() ;
141 #define STATS_INIT_SBLK_AND_COEFF_POS() ;
142 #define STATS_LAST_SBLK_POS_UPDATE(e_trans_type, t_skip_or_tq_bypass, sblk_x, sblk_y) ;
143 #define STATS_UPDATE_SBLK_AND_COEFF_HISTOGRAM(e_trans_type, t_skip_or_tq_bypass) ;
144 #define STATS_UPDATE_COEFF_COUNT() ;
145 #define STATS_UPDATE_PU_SIZE(ps_pu) ;
146 #define STATS_UPDATE_PU_SKIP_SIZE(ps_pu) ;
147 #endif
148 
149 #endif /* _IHEVCD_STATISTICS_H_ */
150