1 /*
2  * Copyright (c) 2011 Intel Corporation. All Rights Reserved.
3  * Copyright (c) Imagination Technologies Limited, UK
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sub license, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice (including the
14  * next paragraph) shall be included in all copies or substantial portions
15  * of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
21  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  *
25  * Authors:
26  *    Elaine Wang <elaine.wang@intel.com>
27  *    Zeng Li <zeng.li@intel.com>
28  *    Edward Lin <edward.lin@intel.com>
29  *
30  */
31 #ifndef _TNG_HOSTCODE_H_
32 #define _TNG_HOSTCODE_H_
33 
34 #include "img_types.h"
35 #include "hwdefs/coreflags.h"
36 #include "psb_drv_video.h"
37 #include "psb_surface.h"
38 #include "tng_cmdbuf.h"
39 #include "tng_hostdefs.h"
40 #include "tng_hostheader.h"
41 #include "tng_jpegES.h"
42 #include "tng_slotorder.h"
43 
44 #define tng__max(a, b) ((a)> (b)) ? (a) : (b)
45 #define tng__min(a, b) ((a) < (b)) ? (a) : (b)
46 
47 #define F_MASK(basename)  (MASK_##basename)
48 #define F_SHIFT(basename) (SHIFT_##basename)
49 #define F_ENCODE(val,basename)  (((val)<<(F_SHIFT(basename)))&(F_MASK(basename)))
50 #define F_EXTRACT(val,basename) (((val)&(F_MASK(basename)))>>(F_SHIFT(basename)))
51 #define F_INSERT(word,val,basename) (((word)&~(F_MASK(basename))) | (F_ENCODE((val),basename)))
52 
53 #define COMM_CMD_DATA_BUF_NUM   (20)
54 #define TOPAZHP_MAX_HIGHCMD_DATASIZE    256
55 #define COMM_CMD_DATA_BUF_SIZE  (TOPAZHP_MAX_HIGHCMD_DATASIZE)
56 #define COMM_WB_DATA_BUF_SIZE          (64)
57 
58 #define COMM_CMD_CODED_BUF_NUM     (4)
59 #define COMM_CMD_FRAME_BUF_NUM     (16)
60 #define COMM_CMD_PICMGMT_BUF_NUM (4)
61 
62 /**************** command buffer count ****************/
63 typedef struct context_ENC_cmdbuf_s {
64     unsigned int ui32LowCmdCount;           //!< count of low-priority commands sent to TOPAZ
65     unsigned int ui32HighCmdCount;          //!< count of high-priority commands sent to TOPAZ
66     unsigned int ui32HighWBReceived;        //!< count of high-priority commands received from TOPAZ
67     unsigned int ui32LastSync;                    //!< Last sync value sent
68 } context_ENC_cmdbuf;
69 
70 typedef struct context_ENC_mem_s {
71     struct psb_buffer_s bufs_mtx_context;
72     struct psb_buffer_s bufs_seq_header; //pSeqHeaderMem //!< Partially coded Sequence header
73     struct psb_buffer_s bufs_sub_seq_header; //pSubSetSeqHeaderMem //!< Partially coded Subset sequence header for H264 mvc
74     struct psb_buffer_s bufs_sei_header;  //pAUDHeaderMem + pSEIBufferingPeriodHeaderMem + pSEIPictureTimingHeaderMem
75     struct psb_buffer_s bufs_pic_template;  //+ apPicHdrTemplateMem[4]
76     struct psb_buffer_s bufs_slice_template; //apSliceParamsTemplateMem[NUM_SLICE_TYPES];
77     struct psb_buffer_s bufs_lowpower_params;
78 
79     struct psb_buffer_s bufs_above_params;  //psAboveParams[TOPAZHP_NUM_PIPES] //!< Picture level parameters (supplied by driver)
80     struct psb_buffer_s bufs_recon_pictures;  //apsReconPictures[MAX_PIC_NODES_ARRAYSIZE];// three reference pictures (2 input and 1 output)
81     struct psb_buffer_s bufs_colocated;  //apsColocated[MAX_PIC_NODES_ARRAYSIZE];// three colocated vector stores (2 input and 1 output)
82     struct psb_buffer_s bufs_mv;  //apsMV[MAX_MV_ARRAYSIZE];          // two colocated vector stores
83     struct psb_buffer_s bufs_interview_mv;  //apsInterViewMV[2];
84 
85     struct psb_buffer_s bufs_src_phy_addr;   //apSrcPhysAddr;
86 
87     // WEIGHTED PREDICTION
88     struct psb_buffer_s bufs_weighted_prediction;  //apsWeightedPredictionMem[MAX_SOURCE_SLOTS_SL];
89     struct psb_buffer_s bufs_flat_gop;  //pFlatGopStruct;        //!< Flat MiniGop structure
90     struct psb_buffer_s bufs_hierar_gop;  //pHierarGopStruct; //!< Hierarchical MiniGop structure
91 
92 #ifdef LTREFHEADER
93     struct psb_buffer_s bufs_lt_ref_header;  //pLtRefHeader[MAX_SOURCE_SLOTS_SL];
94 #endif
95 
96     struct psb_buffer_s bufs_custom_quant;
97     struct psb_buffer_s bufs_slice_map;  //IMG_BUFFER* apsSliceMap[MAX_SOURCE_SLOTS_SL];  //!< Slice map of the source picture
98 
99     /*  | MVSetingsB0 | MVSetingsB1 | ... | MVSetings Bn |  */
100     struct psb_buffer_s bufs_mv_setting_btable;  //pMVSettingsBTable;// three colocated vector stores (2 input and 1 output)
101     struct psb_buffer_s bufs_mv_setting_hierar;  //pMVSettingsHierarchical;
102     struct psb_buffer_s bufs_recon_buffer;  //psReconBuffer;
103     struct psb_buffer_s bufs_patch_recon_buffer;  //psPatchedReconBuffer;
104 
105     struct psb_buffer_s bufs_first_pass_out_params; //sFirstPassOutParamBuf[MAX_SOURCE_SLOTS_SL]; //!< Output Parameters of the First Pass
106 #ifndef EXCLUDE_BEST_MP_DECISION_DATA
107     struct psb_buffer_s bufs_first_pass_out_best_multipass_param; //sFirstPassOutBestMultipassParamBuf[MAX_SOURCE_SLOTS_SL]; //!< Output Selectable Best MV Parameters of the First Pass
108 #endif
109     struct psb_buffer_s bufs_mb_ctrl_in_params;      //sMBCtrlInParamsBuf[MAX_SOURCE_SLOTS_SL]; //!< Input Parameters to the second pass
110 
111     struct psb_buffer_s bufs_ref_frames;
112 
113     //defined for dual-stream
114     struct psb_buffer_s bufs_lowpower_data;
115     struct psb_buffer_s bufs_lowpower_reg;
116 } context_ENC_mem;
117 
118 typedef struct context_ENC_mem_size_s {
119     IMG_UINT32 mtx_context;
120     IMG_UINT32 seq_header;       //pSeqHeaderMem //!< Partially coded Sequence header
121                                                  //+ pSubSetSeqHeaderMem //!< Partially coded Subset sequence header for H264 mvc
122     IMG_UINT32 sei_header;        //pAUDHeaderMem + pSEIBufferingPeriodHeaderMem + pSEIPictureTimingHeaderMem
123     IMG_UINT32 pic_template;      //+ apPicHdrTemplateMem[4]
124     IMG_UINT32 slice_template;    //apSliceParamsTemplateMem[NUM_SLICE_TYPES];
125     IMG_UINT32 writeback;
126 
127     IMG_UINT32 above_params;  //psAboveParams[TOPAZHP_NUM_PIPES] //!< Picture level parameters (supplied by driver)
128     IMG_UINT32 recon_pictures;  //apsReconPictures[MAX_PIC_NODES_ARRAYSIZE];// three reference pictures (2 input and 1 output)
129     IMG_UINT32 colocated;          //apsColocated[MAX_PIC_NODES_ARRAYSIZE];// three colocated vector stores (2 input and 1 output)
130     IMG_UINT32 mv;                   //apsMV[MAX_MV_ARRAYSIZE];          // two colocated vector stores
131     IMG_UINT32 interview_mv;    //apsInterViewMV[2];
132 
133     IMG_UINT32 src_phy_addr;   //apSrcPhysAddr;
134 
135     // WEIGHTED PREDICTION
136     IMG_UINT32 weighted_prediction;  //apsWeightedPredictionMem[MAX_SOURCE_SLOTS_SL];
137     IMG_UINT32 flat_gop;  //pFlatGopStruct;        //!< Flat MiniGop structure
138     IMG_UINT32 hierar_gop;  //pHierarGopStruct; //!< Hierarchical MiniGop structure
139 
140 #ifdef LTREFHEADER
141     IMG_UINT32 lt_ref_header;  //pLtRefHeader[MAX_SOURCE_SLOTS_SL];
142 #endif
143 
144     IMG_UINT32 custom_quant;
145     IMG_UINT32 slice_map;  //IMG_BUFFER* apsSliceMap[MAX_SOURCE_SLOTS_SL];  //!< Slice map of the source picture
146 
147     /*  | MVSetingsB0 | MVSetingsB1 | ... | MVSetings Bn |  */
148     IMG_UINT32 mv_setting_btable;  //pMVSettingsBTable;// three colocated vector stores (2 input and 1 output)
149     IMG_UINT32 mv_setting_hierar;  //pMVSettingsHierarchical;
150     IMG_UINT32 recon_buffer;  //psReconBuffer;
151     IMG_UINT32 patch_recon_buffer;  //psPatchedReconBuffer;
152     IMG_UINT32 first_pass_out_params; //!< Output Parameters of the First Pass
153 #ifndef EXCLUDE_BEST_MP_DECISION_DATA
154     IMG_UINT32 first_pass_out_best_multipass_param;//!< Output Selectable Best MV Parameters of the First Pass
155 #endif
156     IMG_UINT32 mb_ctrl_in_params;
157 
158     //defined for dual-stream
159     IMG_UINT32 lowpower_params;
160     IMG_UINT32 lowpower_data;
161 /****************************************/
162     IMG_UINT32 coded_buf;
163 
164 } context_ENC_mem_size;
165 
166 /**************** surface buffer infor ****************/
167 typedef struct context_ENC_frame_buf_s {
168     object_surface_p  src_surface;
169     object_surface_p  rec_surface;
170 #ifdef _TNG_FRAMES_
171     object_surface_p  ref_surface;
172     object_surface_p  ref_surface1;
173 #else
174     object_surface_p  ref_surface[16];
175 #endif
176     object_buffer_p   coded_buf;
177 
178     IMG_UINT8         ui8SourceSlotReserved;
179     IMG_UINT8         ui8CodedSlotReserved;
180 
181     // save previous settings
182     object_surface_p    previous_src_surface;
183     object_surface_p    previous_ref_surface;
184     object_surface_p    previous_dest_surface; /* reconstructed surface */
185     object_buffer_p     previous_coded_buf;
186     object_buffer_p     pprevious_coded_buf;
187 
188     IMG_UINT16  ui16BufferStride;  //!< input buffer stride
189     IMG_UINT16  ui16BufferHeight;  //!< input buffer width
190 } context_ENC_frame_buf;
191 
192 typedef struct CARC_PARAMS_s
193 {
194     IMG_BOOL    bCARC;
195     IMG_INT32   i32CARCBaseline;
196     IMG_UINT32  ui32CARCThreshold;
197     IMG_UINT32  ui32CARCCutoff;
198     IMG_UINT32  ui32CARCNegRange;
199     IMG_UINT32  ui32CARCNegScale;
200     IMG_UINT32  ui32CARCPosRange;
201     IMG_UINT32  ui32CARCPosScale;
202     IMG_UINT32  ui32CARCShift;
203 } CARC_PARAMS;
204 
205 typedef  struct _LOWPOWER_PARAMS {
206     IMG_UINT32 host_context;
207     IMG_UINT32 codec;
208     IMG_UINT32 data_saving_buf_handle;    /*TTM buffer handle*/
209     IMG_UINT32 data_saving_buf_size;        /*MTX RAM size - Firmware Size. Maximum value is 64K*/
210     IMG_UINT32 reg_saving_buf_handle;      /*TTM buffer handle. One page is enough.*/
211     IMG_UINT32 reg_saving_buf_size;
212 } LOWPOWER_PARAMS;
213 
214 typedef struct _H264_PICMGMT_UP_PARAMS {
215     IMG_INT8 updated;
216     IMG_INT8 ref_type;
217     IMG_INT8 gop_struct;
218     IMG_INT8 skip_frame;
219 
220     IMG_INT8 eos;
221     IMG_INT8 rc_updated;
222     IMG_INT8 flush;
223     IMG_INT8 quant;
224 } H264_PICMGMT_UP_PARAMS;
225 
226 /*!
227  *    \ADAPTIVE_INTRA_REFRESH_INFO_TYPE
228  *    \brief Structure for parameters requierd for Adaptive intra refresh.
229  */
230 typedef struct
231 {
232     IMG_INT8   *pi8AIR_Table;
233     IMG_INT32   i32NumAIRSPerFrame;
234     IMG_INT16   i16AIRSkipCnt;
235     IMG_UINT16  ui16AIRScanPos;
236     IMG_INT32   i32SAD_Threshold;
237 } ADAPTIVE_INTRA_REFRESH_INFO_TYPE;
238 
239 
240 struct context_ENC_s {
241     object_context_p obj_context; /* back reference */
242     context_ENC_mem_size ctx_mem_size;
243     context_ENC_frame_buf ctx_frame_buf;
244     context_ENC_mem ctx_mem[2];
245     context_ENC_cmdbuf ctx_cmdbuf[2];
246     IMG_UINT32  ui32FrameCount[2];
247 
248     struct psb_buffer_s bufs_writeback;
249 
250     IMG_FRAME_TYPE eFrameType;
251     IMG_FRAME_TYPE ePreFrameType;
252 
253     IMG_CODEC eCodec;
254     CARC_PARAMS  sCARCParams;
255     IMG_ENC_CAPS sCapsParams;
256     IMG_ENCODE_FEATURES sEncFeatures;
257     H264_CROP_PARAMS sCropParams;
258     H264_VUI_PARAMS sVuiParams;
259     FRAME_ORDER_INFO sFrameOrderInfo;
260     // Adaptive Intra Refresh Control structure
261     ADAPTIVE_INTRA_REFRESH_INFO_TYPE sAirInfo;
262 
263     IMG_UINT32  ui32RawFrameCount;
264     IMG_UINT32  ui32HalfWayBU[NUM_SLICE_TYPES];
265     IMG_UINT32  ui32LastPicture;
266 
267     IMG_UINT32  ui32CoreRev;
268     IMG_UINT32  ui32StreamID;
269     IMG_UINT32  ui32FCode;
270     IMG_UINT32  ui32BasicUnit;
271     IMG_UINT8   ui8ProfileIdc;
272     IMG_UINT8   ui8LevelIdc;
273     IMG_UINT8   ui8FieldCount;
274     IMG_UINT8   ui8VPWeightedImplicitBiPred;
275     IMG_UINT8   ui8MaxNumRefFrames;
276     IMG_UINT8   i8CQPOffset;
277     IMG_INT     iFineYSearchSize;
278 
279     IMG_UINT8   aui8CustomQuantParams4x4[6][16];
280     IMG_UINT8   aui8CustomQuantParams8x8[2][64];
281     IMG_UINT32  ui32CustomQuantMask;
282 
283     IMG_BOOL    bInsertPicHeader;
284     IMG_UINT32  ui32PpsScalingCnt;
285 
286     /**************** FIXME: unknown ****************/
287     IMG_UINT    uiCbrBufferTenths;           //TOPAZHP_DEFAULT_uiCbrBufferTenths
288 
289     /**************** IMG_VIDEO_PARAMS ****************/
290     IMG_BOOL16 bVPAdaptiveRoundingDisable;
291     IMG_INT16  ui16UseCustomScalingLists;
292     IMG_UINT8  ui8RefSpacing;
293     IMG_BOOL   bUseDefaultScalingList;
294     IMG_BOOL   bEnableLossless;
295     IMG_BOOL   bLossless8x8Prefilter;
296     IMG_BOOL   bEnableCumulativeBiases;
297 
298     /*!
299      ***********************************************************************************
300      * Description        : Video encode context
301      ************************************************************************************/
302     /* stream level params */
303     IMG_STANDARD  eStandard;                //!< Video standard
304     IMG_UINT16  ui16SourceWidth;             //!< source frame width
305     IMG_UINT16  ui16SourceHeight;            //!< source frame height
306     IMG_UINT16  ui16Width;             //!< target output width
307     IMG_UINT16  ui16FrameHeight;  //!< target output height
308     IMG_UINT16  ui16PictureHeight;     //!< target output height
309     IMG_UINT16  ui16BufferStride;              //!< input buffer stride
310     IMG_UINT16  ui16BufferHeight;             //!< input buffer width
311     IMG_UINT8   ui8FrameRate;
312 
313     IMG_UINT32  ui32DebugCRCs;
314     IMG_FORMAT  eFormat;            //!< Pixel format of the source surface
315 
316     /* Numbers of array elements that will be allocated */
317     IMG_INT32   i32PicNodes;
318     IMG_INT32   i32MVStores;
319     IMG_INT32   i32CodedBuffers;
320 
321     /* slice control parameters */
322 
323     /* per core params */
324     PIC_PARAMS  sPicParams;  //!< Picture level parameters (supplied by driver)
325     IMG_BOOL    bWeightedPrediction;
326     IMG_UINT8   ui8WeightedBiPred;
327     IMG_UINT8   ui8CustomQuantSlot;
328 
329     /* these values set at picture level & written in at slice */
330     IMG_UINT32  ui32IPEControl;         //!< common bits IPE control register for entire picture
331     IMG_UINT32  ui32PredCombControl;    //!< common bits of Predictor-combiner control register for entire picture
332     IMG_BOOL    bCabacEnabled;          //!< FLAG to enable Cabac mode
333     IMG_UINT32  ui32CabacBinLimit;      //!< Min Bin Limit after which the Topaz hardware would encode MB as IPCM
334     IMG_UINT32  ui32CabacBinFlex;       //!< Max Flex-Limit, the Topaz-HW will encode MB as IPCM after (BinLimit+BinFlex)
335 
336     IMG_UINT32  ui32FirstPicFlags;
337     IMG_UINT32  ui32NonFirstPicFlags;
338 
339     IMG_BOOL    bIsInterlaced;
340     IMG_BOOL    bIsInterleaved;
341     IMG_BOOL    bTopFieldFirst;
342     IMG_BOOL    bArbitrarySO;
343     IMG_UINT32  ui32NextSlice;
344     IMG_UINT8   ui8SlicesPerPicture;
345     IMG_UINT8   ui8DeblockIDC;
346     //  We want to keep track of the basic unit size, as it is needed in deciding the number of macroblocks in a kick
347     IMG_UINT32  ui32KickSize;
348     IMG_UINT32  ui32VopTimeResolution;
349     IMG_UINT32  ui32IdrPeriod;
350     IMG_UINT32  ui32IntraCnt;
351     IMG_UINT32  ui32IntraCntSave;
352     IMG_BOOL    bMultiReferenceP;
353     IMG_BOOL    bSpatialDirect;
354     IMG_UINT8   ui8MPEG2IntraDCPrecision; // Only used in MPEG2, 2 bit field (0 = 8 bit, 1 = 9 bit, 2 = 10 bit and 3=11 bit precision). Set to zero for other encode standards.
355 
356     IMG_MV_SETTINGS sMVSettingsIdr;
357     IMG_MV_SETTINGS sMVSettingsNonB[MAX_BFRAMES + 1];
358 
359     /*  | MVSetingsB0 | MVSetingsB1 | ... | MVSetings Bn |  */
360     IMG_BOOL    b_is_mv_setting_hierar;
361 
362     // Source slots
363     IMG_FRAME  *apsSourceSlotBuff[MAX_SOURCE_SLOTS_SL]; // Source slots
364     IMG_UINT32 aui32SourceSlotPOC[MAX_SOURCE_SLOTS_SL]; // POCs of frames in slots
365     IMG_UINT32 ui32pseudo_rand_seed;
366     IMG_UINT8  ui8SlotsInUse;                           // Number of source slots used
367     IMG_UINT8  ui8SlotsCoded;                          // Number of coded slots used
368 
369     IMG_BOOL   bSrcAllocInternally;                        // True for internal source frame allocation
370 
371     // Coded slots
372     //IMG_CODED_BUFFER *  apsCodedSlotBuff[MAX_CODED_BUFFERS];        // Coded slots
373     IMG_BOOL  bCodedAllocInternally;                      // True for internal coded frame allocation
374     //IMG_CODED_BUFFER *  apsInternalCoded[MAX_CODED_BUFFERS];        // Frames placed in slots when using internal coded frame allocation
375 
376 
377     IMG_UINT32  ui32FlushAtFrame;
378     IMG_UINT32  ui32FlushedAtFrame;
379     IMG_UINT32  ui32EncodeSent;
380     IMG_UINT32  ui32EncodeRequested;
381     IMG_UINT32  ui32FramesEncoded;
382     IMG_BOOL    bEncoderIdle;       // Indicates that the encoder is waiting for data, Set to true at start of encode
383     IMG_BOOL    bAutoEncode;
384     IMG_BOOL    bSliceLevel;
385     IMG_BOOL    bAborted;
386 
387     IMG_UINT32  ui32ReconPOC;
388     IMG_UINT32  ui32NextRecon;
389     IMG_UINT32  ui32BuffersStatusReg;
390 
391     IMG_RC_PARAMS   sRCParams;
392     IMG_BIAS_TABLES sBiasTables;
393     IMG_BIAS_PARAMS sBiasParams;
394 
395     IMG_UINT8  ui8H263SourceFormat;
396 
397     IMG_BOOL   bOverlapping;
398     IMG_BOOL   bInsertSeqHeader;
399 
400     IMG_UINT32 ui32EncodePicProcessing;
401     IMG_UINT8  ui8ExtraWBRetrieved;
402 
403     IMG_UINT8   ui8EnableSelStatsFlags;   //!< Flags to enable selective first-pass statistics gathering by the hardware. Bit 1 - First Stage Motion Search Data, Bit 2 - Best Multipass MB Decision Data, Bit 3 - Best Multipass Motion Vectors. (First stage Table 2 motion vectors are always switched on)
404 
405     IMG_BOOL   bEnableInpCtrl;  //!< Enable Macro-block input control
406     IMG_BOOL   bEnableAIR;      //!< Enable Adaptive Intra Refresh
407     IMG_BOOL   bEnableCIR;	//!< Enable Cyclic Intra Refresh
408     IMG_INT32  i32NumAIRMBs;    //!< n = Max number of AIR MBs per frame, 0 = _ALL_ MBs over threshold will be marked as AIR Intras, -1 = Auto 10%
409     IMG_INT32  i32AIRThreshold; //!< n = SAD Threshold above which a MB is a AIR MB candidate,  -1 = Auto adjusting threshold
410     IMG_INT16  i16AIRSkipCnt;   //?!< n = Number of MBs to skip in AIR Table between frames, -1 = Random (0 - NumAIRMbs) skip between frames in AIR table
411     // INPUT CONTROL
412     IMG_UINT16 ui16IntraRefresh;
413     IMG_INT32  i32LastCIRIndex;
414 
415     IMG_BOOL   bEnableHostBias;
416     IMG_BOOL   bEnableHostQP;
417 
418     IMG_BOOL   bCustomScaling;
419     IMG_BOOL   bPpsScaling;
420     IMG_BOOL   bH2648x8Transform;
421     IMG_BOOL   bH264IntraConstrained;
422     IMG_UINT32 ui32VertMVLimit;
423     IMG_BOOL16 bLimitNumVectors;
424 //    IMG_BOOL16 bDisableBitStuffing;
425     IMG_UINT8  ui8CodedSkippedIndex;
426     IMG_UINT8  ui8InterIntraIndex;
427     // SEI_INSERTION
428     IMG_BOOL   bInsertHRDParams;
429     //
430     IMG_UINT32 uChunksPerMb;
431     IMG_UINT32 uMaxChunks;
432     IMG_UINT32 uPriorityChunks;
433 
434     IMG_UINT8  ui8SourceSlotReserved;
435     IMG_UINT8  ui8CodedSlotReserved;
436     IMG_UINT8  ui8SliceReceivedInFrame;
437 
438     /* Low latency stuff */
439     IMG_UINT8  ui8ActiveCodedBuffer;
440     IMG_UINT8  ui8BasePipe;
441     IMG_UINT8  ui8PipesToUse;
442     IMG_UINT32 ui32ActiveBufferBytesCoded;
443     IMG_UINT32 ui32AcriveBufferPreviousBytes;
444 
445     IMG_UINT8  ui8HighestStorageNumber;
446 
447     IMG_BOOL   bEnableMVC;         //!< True if MVC is enabled. False by default
448     IMG_UINT16 ui16MVCViewIdx;     //!< View Idx of this MVC view
449     IMG_BOOL   bHighLatency;
450     IMG_UINT32 uMBspS;
451     IMG_BOOL   bSkipDuplicateVectors;
452     IMG_BOOL   bNoOffscreenMv;
453     IMG_BOOL   idr_force_flag;
454 
455     IMG_BOOL   bNoSequenceHeaders;
456     IMG_BOOL   bUseFirmwareALLRC; //!< Defines if aLL RC firmware to be loaded
457 
458 
459     //JPEG encode buffer sizes
460     uint32_t jpeg_pic_params_size;
461     uint32_t jpeg_header_mem_size;
462     uint32_t jpeg_header_interface_mem_size;
463 
464     //JPEG encode context data
465     TOPAZHP_JPEG_ENCODER_CONTEXT *jpeg_ctx;
466 
467     /* Save actual H263 width/height */
468     IMG_UINT16 h263_actual_width;
469     IMG_UINT16 h263_actual_height;
470 
471     uint32_t buffer_size;
472     uint32_t initial_buffer_fullness;
473 
474     /* qp/maxqp/minqp/bitrate/intra_period */
475     uint32_t rc_update_flag;
476     IMG_UINT16 max_qp;
477 };
478 
479 typedef struct context_ENC_s *context_ENC_p;
480 
481 #define SURFACE_INFO_SKIP_FLAG_SETTLED 0X80000000
482 #define GET_SURFACE_INFO_skipped_flag(psb_surface) ((int) (psb_surface->extra_info[5]))
483 #define SET_SURFACE_INFO_skipped_flag(psb_surface, value) psb_surface->extra_info[5] = (SURFACE_INFO_SKIP_FLAG_SETTLED | value)
484 #define CLEAR_SURFACE_INFO_skipped_flag(psb_surface) psb_surface->extra_info[5] = 0
485 
486 VAStatus tng_CreateContext(object_context_p obj_context,
487                            object_config_p obj_config,
488                            unsigned char is_JPEG);
489 
490 //VAStatus tng_InitContext(context_ENC_p ctx);
491 
492 void tng_DestroyContext(
493     object_context_p obj_context,
494     unsigned char is_JPEG);
495 
496 VAStatus tng_BeginPicture(context_ENC_p ctx);
497 VAStatus tng_EndPicture(context_ENC_p ctx);
498 
499 void tng_setup_slice_params(
500     context_ENC_p  ctx, IMG_UINT16 YSliceStartPos,
501     IMG_UINT16 SliceHeight, IMG_BOOL IsIntra,
502     IMG_BOOL  VectorsValid, int bySliceQP);
503 
504 VAStatus tng__send_encode_slice_params(
505     context_ENC_p ctx,
506     IMG_BOOL IsIntra,
507     IMG_UINT16 CurrentRow,
508     IMG_UINT8  DeblockIDC,
509     IMG_UINT32 FrameNum,
510     IMG_UINT16 SliceHeight,
511     IMG_UINT16 CurrentSlice);
512 
513 VAStatus tng_RenderPictureParameter(context_ENC_p ctx);
514 void tng__setup_enc_profile_features(context_ENC_p ctx, IMG_UINT32 ui32EncProfile);
515 VAStatus tng__patch_hw_profile(context_ENC_p ctx);
516 void tng_reset_encoder_params(context_ENC_p ctx);
517 unsigned int tng__get_ipe_control(IMG_CODEC  eEncodingFormat);
518 void tng__UpdateRCBitsTransmitted(context_ENC_p ctx);
519 void tng__trace_in_params(IMG_MTX_VIDEO_CONTEXT* psMtxEncCtx);
520 void tng__trace_mtx_context(IMG_MTX_VIDEO_CONTEXT* psMtxEncCtx);
521 VAStatus tng__alloc_init_buffer(
522     psb_driver_data_p driver_data,
523     unsigned int size,
524     psb_buffer_type_t type,
525     psb_buffer_p buf);
526 
527 #endif  //_TNG_HOSTCODE_H_
528