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_process.h
25*
26* @brief
27*  Contains functions for codec thread
28*
29* @author
30*  ittiam
31*
32* @remarks
33*  None
34*
35*******************************************************************************
36*/
37
38#ifndef IH264E_PROCESS_H_
39#define IH264E_PROCESS_H_
40
41/*****************************************************************************/
42/* Function Declarations                                                     */
43/*****************************************************************************/
44
45/**
46******************************************************************************
47*
48*  @brief This function generates sps, pps set on request
49*
50*  @par   Description
51*  When the encoder is set in header generation mode, the following function
52*  is called. This generates sps and pps headers and returns the control back
53*  to caller.
54*
55*  @param[in]    ps_codec
56*  pointer to codec context
57*
58*  @return      success or failure error code
59*
60******************************************************************************
61*/
62IH264E_ERROR_T    ih264e_generate_sps_pps
63        (
64            codec_t   *ps_codec
65        );
66
67/**
68*******************************************************************************
69*
70* @brief   initialize entropy context.
71*
72* @par Description:
73*  Before invoking the call to perform to entropy coding the entropy context
74*  associated with the job needs to be initialized. This involves the start
75*  mb address, end mb address, slice index and the pointer to location at
76*  which the mb residue info and mb header info are packed.
77*
78* @param[in] ps_proc
79*  Pointer to the current process context
80*
81* @returns error status
82*
83* @remarks none
84*
85*******************************************************************************
86*/
87IH264E_ERROR_T ih264e_init_entropy_ctxt(process_ctxt_t *ps_proc);
88
89/**
90*******************************************************************************
91*
92* @brief entry point for entropy coding
93*
94* @par Description
95*  This function calls lower level functions to perform entropy coding for a
96*  group (n rows) of mb's. After encoding 1 row of mb's,  the function takes
97*  back the control, updates the ctxt and calls lower level functions again.
98*  This process is repeated till all the rows or group of mb's (which ever is
99*  minimum) are coded
100*
101* @param[in] ps_proc
102*  process context
103*
104* @returns  error status
105*
106* @remarks
107* NOTE : It is assumed that this routine is invoked at the start of a slice,
108* so the slice header is generated by default.
109*
110*******************************************************************************
111*/
112IH264E_ERROR_T ih264e_entropy(process_ctxt_t *ps_proc);
113
114/**
115*******************************************************************************
116*
117* @brief Packs header information of a mb in to a buffer
118*
119* @par Description:
120*  After the deciding the mode info of a macroblock, the syntax elements
121*  associated with the mb are packed and stored. The entropy thread unpacks
122*  this buffer and generates the end bit stream.
123*
124* @param[in] ps_proc
125*  Pointer to the current process context
126*
127* @returns error status
128*
129* @remarks none
130*
131*******************************************************************************
132*/
133IH264E_ERROR_T ih264e_pack_header_data
134    (
135        process_ctxt_t *ps_proc
136    );
137
138/**
139*******************************************************************************
140*
141* @brief   update process context after encoding an mb. This involves preserving
142* the current mb information for later use, initialize the proc ctxt elements to
143* encode next mb.
144*
145* @par Description:
146*  This function performs house keeping tasks after encoding an mb.
147*  After encoding an mb, various elements of the process context needs to be
148*  updated to encode the next mb. For instance, the source, recon and reference
149*  pointers, mb indices have to be adjusted to the next mb. The slice index of
150*  the current mb needs to be updated. If mb qp modulation is enabled, then if
151*  the qp changes the quant param structure needs to be updated. Also to encoding
152*  the next mb, the current mb info is used as part of mode prediction or mv
153*  prediction. Hence the current mb info has to preserved at top/top left/left
154*  locations.
155*
156* @param[in] ps_proc
157*  Pointer to the current process context
158*
159* @returns none
160*
161* @remarks none
162*
163*******************************************************************************
164*/
165WORD32 ih264e_update_proc_ctxt
166    (
167        process_ctxt_t *ps_proc
168    );
169
170/**
171*******************************************************************************
172*
173* @brief   initialize process context.
174*
175* @par Description:
176*  Before dispatching the current job to process thread, the process context
177*  associated with the job is initialized. Usually every job aims to encode one
178*  row of mb's. Basing on the row indices provided by the job, the process
179*  context's buffer ptrs, slice indices and other elements that are necessary
180*  during core-coding are initialized.
181*
182* @param[in] ps_proc
183*  Pointer to the current process context
184*
185* @returns error status
186*
187* @remarks none
188*
189*******************************************************************************
190*/
191IH264E_ERROR_T ih264e_init_proc_ctxt(process_ctxt_t *ps_proc);
192
193/**
194*******************************************************************************
195*
196* @brief This function performs luma & chroma padding
197*
198* @par Description:
199*
200* @param[in] ps_proc
201*  Process context corresponding to the job
202*
203* @param[in] pu1_curr_pic_luma
204*  Pointer to luma buffer
205*
206* @param[in] pu1_curr_pic_chroma
207*  Pointer to chroma buffer
208*
209* @param[in] i4_mb_x
210*  mb index x
211*
212* @param[in] i4_mb_y
213*  mb index y
214*
215* @param[in] i4_pad_ht
216*  number of rows to be padded
217*
218* @returns  error status
219*
220* @remarks none
221*
222*******************************************************************************
223*/
224IH264E_ERROR_T ih264e_pad_recon_buffer
225    (
226        process_ctxt_t *ps_proc,
227        UWORD8 *pu1_curr_pic_luma,
228        UWORD8 *pu1_curr_pic_chroma,
229        WORD32 i4_mb_x,
230        WORD32 i4_mb_y,
231        WORD32 i4_pad_ht
232    );
233
234/**
235*******************************************************************************
236*
237* @brief This function performs luma half pel planes generation
238*
239* @par Description:
240*
241* @param[in] ps_proc
242*  Process context corresponding to the job
243*
244* @returns  error status
245*
246* @remarks none
247*
248*******************************************************************************
249*/
250IH264E_ERROR_T ih264e_halfpel_generation
251    (
252        process_ctxt_t *ps_proc,
253        UWORD8 *pu1_curr_pic_luma,
254        WORD32 i4_mb_x,
255        WORD32 i4_mb_y
256    );
257
258/**
259*******************************************************************************
260*
261* @brief This function performs luma & chroma core coding for a set of mb's.
262*
263* @par Description:
264*  The mb to be coded is taken and is evaluated over a predefined set of modes
265*  (intra (i16, i4, i8)/inter (mv, skip)) for best cost. The mode with least cost
266*  is selected and using intra/inter prediction filters, prediction is carried out.
267*  The deviation between src and pred signal constitutes error signal. This error
268*  signal is transformed (hierarchical transform if necessary) and quantized. The
269*  quantized residue is packed in to entropy buffer for entropy coding. This is
270*  repeated for all the mb's enlisted under the job.
271*
272* @param[in] ps_proc
273*  Process context corresponding to the job
274*
275* @returns  error status
276*
277* @remarks none
278*
279*******************************************************************************
280*/
281WORD32 ih264e_process(process_ctxt_t *ps_proc);
282
283/**
284*******************************************************************************
285*
286* @brief
287*  Function to update rc context after encoding
288*
289* @par   Description
290*  This function updates the rate control context after the frame is encoded.
291*  Number of bits consumed by the current frame, frame distortion, frame cost,
292*  number of intra/inter mb's, ... are passed on to rate control context for
293*  updating the rc model.
294*
295* @param[in] ps_codec
296*  Handle to codec context
297*
298* @param[in] ctxt_sel
299*  frame context selector
300*
301* @param[in] pic_cnt
302*  pic count
303*
304* @returns i4_stuffing_byte
305*  number of stuffing bytes (if necessary)
306*
307* @remarks
308*
309*******************************************************************************
310*/
311WORD32 ih264e_update_rc_post_enc(codec_t *ps_codec, WORD32 ctxt_sel, WORD32 pic_cnt);
312
313/**
314*******************************************************************************
315*
316* @brief
317*  entry point of a spawned encoder thread
318*
319* @par Description:
320*  The encoder thread dequeues a proc/entropy job from the encoder queue and
321*  calls necessary routines.
322*
323* @param[in] pv_proc
324*  Process context corresponding to the thread
325*
326* @returns  error status
327*
328* @remarks
329*
330*******************************************************************************
331*/
332WORD32 ih264e_process_thread(void *pv_proc);
333
334#endif /* IH264E_PROCESS_H_ */
335