ih264e_me.h revision a2b49e5f0574dee76f81507f288143d83a4b7c1a
1/******************************************************************************
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_me.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_ME_H_
38#define IH264E_ME_H_
39
40/*****************************************************************************/
41/* Function Macros                                                           */
42/*****************************************************************************/
43
44/**
45******************************************************************************
46 *  @brief      compute median of 3 elements (a, b, c) and store the output
47 *  in to result. This is used for mv prediction
48******************************************************************************
49 */
50
51#define MEDIAN(a, b, c, result) if (a > b){\
52                                    if (b > c)\
53                                        result = b;\
54                                    else {\
55                                        if (a > c)\
56                                            result = c;\
57                                        else \
58                                            result = a;\
59                                    }\
60                                }\
61                                else {\
62                                    if (c > b)\
63                                        result = b;\
64                                    else {\
65                                        if (c > a)\
66                                            result = c;\
67                                        else \
68                                            result = a;\
69                                    }\
70                                }
71
72
73
74/*****************************************************************************/
75/* Extern Function Declarations                                              */
76/*****************************************************************************/
77
78/**
79*******************************************************************************
80*
81* @brief
82*  This function populates the length of the codewords for motion vectors in the
83*  range (-search range, search range) in pixels
84*
85* @param[in] ps_me
86*  Pointer to me ctxt
87*
88* @param[out] pu1_mv_bits
89*  length of the codeword for all mv's
90*
91* @remarks The length of the code words are derived from signed exponential
92* goloumb codes.
93*
94*******************************************************************************
95*/
96void ih264e_init_mv_bits
97    (
98        me_ctxt_t *ps_me
99    );
100
101/**
102*******************************************************************************
103*
104* @brief The function gives the skip motion vector
105*
106* @par Description:
107*  The function gives the skip motion vector
108*
109* @param[in] ps_left_mb_pu
110*  pointer to left mb motion vector info
111*
112* @param[in] ps_top_row_pu
113*  pointer to top & top right mb motion vector info
114*
115* @param[out] ps_pred_mv
116*  pointer to candidate predictors for the current block
117*
118* @returns The x & y components of the MV predictor.
119*
120* @remarks The code implements the logic as described in sec 8.4.1.1 in H264
121*   specification.
122*
123*******************************************************************************
124*/
125void ih264e_find_skip_motion_vector
126    (
127        process_ctxt_t *ps_proc,
128        UWORD32 u4_for_me
129    );
130
131/**
132*******************************************************************************
133*
134* @brief motion vector predictor
135*
136* @par Description:
137*  The routine calculates the motion vector predictor for a given block,
138*  given the candidate MV predictors.
139*
140* @param[in] ps_left_mb_pu
141*  pointer to left mb motion vector info
142*
143* @param[in] ps_top_row_pu
144*  pointer to top & top right mb motion vector info
145*
146* @param[out] ps_pred_mv
147*  pointer to candidate predictors for the current block
148*
149* @returns  The x & y components of the MV predictor.
150*
151* @remarks The code implements the logic as described in sec 8.4.1.3 in H264
152*   specification.
153*   Assumptions : 1. Assumes Single reference frame
154*                 2. Assumes Only partition of size 16x16
155*
156*******************************************************************************
157*/
158void ih264e_get_mv_predictor
159        (
160            enc_pu_t *ps_left_mb_pu,
161            enc_pu_t *ps_top_row_pu,
162            mv_t *ps_pred_mv
163        );
164
165/**
166*******************************************************************************
167*
168* @brief This function computes the best motion vector for the current mb
169*
170* @par Description:
171*  This function currently does nothing except set motion vectors from external
172*  source
173*
174* @param[in] ps_proc
175*  Process context corresponding to the job
176*
177* @returns  none
178*
179* @remarks none
180*
181*******************************************************************************
182*/
183void ih264e_compute_me
184    (
185        process_ctxt_t *ps_proc
186    );
187
188/**
189*******************************************************************************
190*
191* @brief This function initializes me ctxt
192*
193* @par Description:
194*  Before dispatching the current job to me thread, the me context associated
195*  with the job is initialized.
196*
197* @param[in] ps_proc
198*  Process context corresponding to the job
199*
200* @returns  none
201*
202* @remarks none
203*
204*******************************************************************************
205*/
206void ih264e_init_me(process_ctxt_t *ps_proc);
207
208/**
209*******************************************************************************
210*
211* @brief This function performs motion estimation for the current NMB
212*
213* @par Description:
214*  Intializes input and output pointers required by the function ih264e_compute_me
215*  and calls the function ih264e_compute_me in a loop to process NMBs.
216*
217* @param[in] ps_proc
218*  Process context corresponding to the job
219*
220* @returns
221*
222* @remarks none
223*
224*******************************************************************************
225*/
226void ih264e_compute_me_nmb
227    (
228        process_ctxt_t *ps_proc,
229        UWORD32 u4_nmb_count
230    );
231
232/**
233*******************************************************************************
234*
235* @brief This function performs MV prediction
236*
237* @par Description:
238*
239* @param[in] ps_proc
240*  Process context corresponding to the job
241*
242* @returns  none
243*
244* @remarks none
245*  This function will update the MB availability since intra inter decision
246*  should be done before the call
247*
248*******************************************************************************
249*/
250void ih264e_mv_pred
251    (
252        process_ctxt_t *ps_proc
253    );
254
255/**
256*******************************************************************************
257*
258* @brief This function approximates Pred. MV
259*
260* @par Description:
261*
262* @param[in] ps_proc
263*  Process context corresponding to the job
264*
265* @returns  none
266*
267* @remarks none
268*  Motion estimation happens at nmb level. For cost calculations, mv is appro
269*  ximated using this function
270*
271*******************************************************************************
272*/
273void ih264e_mv_pred_me
274    (
275        process_ctxt_t *ps_proc
276    );
277
278#endif /* IH264E_ME_H_ */
279