blob: 4c3de2323d7e7dea9a33d7b16e49e89329e1cac4 [file] [log] [blame]
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301/******************************************************************************
2 *
3 * Copyright (C) 2015 The Android Open Source Project
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 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19*/
20
21/**
22*******************************************************************************
23* @file
24* ih264e_globals.h
25*
26* @brief
27* Contains declarations of global variables for H264 encoder
28*
29* @author
30* Ittiam
31*
32* @remarks
33*
34*******************************************************************************
35*/
36
37#ifndef IH264E_GLOBALS_H_
38#define IH264E_GLOBALS_H_
39
40
41/*****************************************************************************/
42/* Extern global declarations */
43/*****************************************************************************/
44
45/**
46******************************************************************************
47* @brief Computes the lamda for varying quantizer scales that would be used to
48* compute the RD cost while deciding on the MB modes.
49* input : qp
50* output : lambda
51* @remarks lambda = 0.85 * pow(2, (qp - 12)/3), when SSD is used as metric
52* for computing distortion (Bit rate estimation for cost function of H.264/
53* AVC by Mohd Golam Sarwer et. al.) If the use of distortion metric is SAD
54* rather than SSD in the stage of encoding, consider sqrt(lambda) simply to
55* adjust lambda for the lack of squaring operation in the error computation
56* (from rate distortion optimization for video compression by sullivan).
57******************************************************************************
58*/
59extern const UWORD16 gu2_qp_lambda[52];
60
61/**
62******************************************************************************
63* @brief Computes the lamda for varying quantizer scales that would be used to
64* compute the RD cost while deciding on the MB modes.
65* input : qp
66* output : lambda
67* @remarks lambda = pow(2, (qp - 12)/6). When Lagrangian multiplier is disabled
68* the same constant is used across mode decision and mv decisions.
69******************************************************************************
70*/
71extern const UWORD8 gu1_qp0[52];
72
73/**
74******************************************************************************
75* @brief unsigned exp. goulumb codelengths to assign cost to a coefficient of
76* mb types.
77* input : Integer
78* output : codelength
79* @remarks Refer sec. 9-1 in h264 specification
80******************************************************************************
81*/
82extern const UWORD8 u1_uev_codelength[32];
83
84/**
85******************************************************************************
86* @brief Look up table to assign cost to a coefficient of a residual block
87* basing on its surrounding coefficients
88* input : Numbers of T1's
89* output : coeff_cost
90* @remarks Refer Section 2.3 Elimination of single coefficients in inter
91* macroblocks in document JVT-O079
92******************************************************************************
93*/
94extern const UWORD8 gu1_coeff_cost[6];
95
96/**
97******************************************************************************
98* @brief Indices map to raster scan for luma 4x4 block
99* input : scan index
100* output : scan location
101* @remarks The scan order assumes the stride to access the next row is 16
102******************************************************************************
103*/
104extern const UWORD8 gu1_luma_scan_order[16];
105
106/**
107******************************************************************************
108* @brief Indices map to raster scan for chroma AC block
109* input : scan index
110* output : scan location
111* @remarks The scan order assumes the stride to access the next row is 32
112******************************************************************************
113*/
114extern const UWORD8 gu1_chroma_scan_order[15];
115
116/**
117******************************************************************************
118* @brief Indices map to raster scan for luma 4x4 dc block
119* input : scan index
120* output : scan location
121* @remarks The scan order assumes the stride to access the next row is 16
122******************************************************************************
123*/
124extern const UWORD8 gu1_luma_scan_order_dc[16];
125
126/**
127******************************************************************************
128* @brief Indices map to raster scan for chroma 2x2 dc block
129* input : scan index
130* output : scan location
131* @remarks The scan order assumes the stride to access the next row is 16
132******************************************************************************
133*/
134extern const UWORD8 gu1_chroma_scan_order_dc[4];
135
136
137/**
138******************************************************************************
139* @brief choice of motion vectors to be used during mv prediction
140* input : formatted reference idx comparison metric
141* output : mv prediction has to be median or a simple straight forward selec
142* tion from neighbors.
143* @remarks If only one of the candidate blocks has a reference frame equal to
144 the current block then use the same block as the final predictor. A simple
145 look up table to assist this mv prediction condition
146******************************************************************************
147*/
148extern const WORD8 gi1_mv_pred_condition[8];
149
150
151/**
152******************************************************************************
153* @brief maps the h264 quantizer to the mpeg2 quantizer scale
154* input : h264 qp
155* output : eqvivalent mpeg 2 qp
156* @remarks mpeg2qscale = 2 ^ [((h264qp - 12) / 6) + 1]
157******************************************************************************
158*/
159extern const UWORD8 gau1_h264_to_mpeg2_qmap[H264_QP_ELEM];
160
161/**
162******************************************************************************
163* @brief maps the mpeg2 quantizer to the h264 quantizer scale
164* input : mpeg2 qp
165* output : eqvivalent h264q p
166* @remarks MPEG-2 dequantization: (2*QFij + k)*Wij*qscale/32
167* k = 0 (for intra) k = sign(QFij)
168* H.264 dequantization: (QFij*R(QP%6,i,j))>>(6 - QP/6)
169*
170* Excluding the portion of R(QP%6,i,j) that is due to
171* the DCT scale factors, the 6 entries after dividing by 64 (2^6)
172* correspond to dequant values of
173* 2.5, 2.8125, 3.125, 3.5625, 3.9375, 4.4375.
174* (a=0.5 b=sqrt(2/5) - refer to JVT-B038.doc)
175*
176* Assuming that h264Qp=12 corresponds to MPEG2 qscale of 2
177* (the actual mapping seems to be to MPEG2 qscale of 2.5),
178* and the fact that the effective h264 quantizer changes by
179* a factor of 2 for every 6 steps, the following mapping is
180* obtained:
181* h264qp = 6*(log2(mpeg2qscale/2)) + 12.
182*
183* Note that the quant matrix entry assumed for the above
184* equality is 16. Hence when the mpeg2 quant matrix entries
185* are all 16, this lookup can be used as is (which is the
186* default inter quant matrix in mpeg-2).
187******************************************************************************
188*/
189extern const UWORD8 gau1_mpeg2_to_h264_qmap[MPEG2_QP_ELEM];
190
191
192#endif /* IH264E_GLOBALS_H_ */