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  *    Edward Lin <edward.lin@intel.com>
27  *
28  */
29 #ifndef _TNG_PICMGMT_H_
30 #define _TNG_PICMGMT_H_
31 
32 #include "img_types.h"
33 #include "tng_hostcode.h"
34 
35 
36 #define SHIFT_MTX_MSG_PICMGMT_SUBTYPE                      (0)
37 #define MASK_MTX_MSG_PICMGMT_SUBTYPE                      (0xff << SHIFT_MTX_MSG_PICMGMT_SUBTYPE)
38 #define SHIFT_MTX_MSG_PICMGMT_DATA                             (8)
39 #define MASK_MTX_MSG_PICMGMT_DATA                             (0xffffff << SHIFT_MTX_MSG_PICMGMT_DATA)
40 
41 #define SHIFT_MTX_MSG_RC_UPDATE_QP                             (0)
42 #define MASK_MTX_MSG_RC_UPDATE_QP                             (0x3f << SHIFT_MTX_MSG_RC_UPDATE_QP)
43 #define SHIFT_MTX_MSG_RC_UPDATE_BITRATE                    (6)
44 #define MASK_MTX_MSG_RC_UPDATE_BITRATE                    (0x03ffffff << SHIFT_MTX_MSG_RC_UPDATE_BITRATE)
45 
46 #define SHIFT_MTX_MSG_PROVIDE_REF_BUFFER_USE         (0)
47 #define MASK_MTX_MSG_PROVIDE_REF_BUFFER_USE         (0xff << SHIFT_MTX_MSG_PROVIDE_REF_BUFFER_USE)
48 #define SHIFT_MTX_MSG_PROVIDE_REF_BUFFER_SLOT       (8)
49 #define MASK_MTX_MSG_PROVIDE_REF_BUFFER_SLOT       (0xff << SHIFT_MTX_MSG_PROVIDE_REF_BUFFER_SLOT)
50 #define SHIFT_MTX_MSG_PROVIDE_REF_BUFFER_LT            (16)
51 #define MASK_MTX_MSG_PROVIDE_REF_BUFFER_LT            (0xff << SHIFT_MTX_MSG_PROVIDE_REF_BUFFER_LT)
52 
53 #define SHIFT_MTX_MSG_PROVIDE_CODED_BUFFER_SLOT  (0)
54 #define MASK_MTX_MSG_PROVIDE_CODED_BUFFER_SLOT  (0x0f << SHIFT_MTX_MSG_PROVIDE_CODED_BUFFER_SLOT)
55 #define SHIFT_MTX_MSG_PROVIDE_CODED_BUFFER_SIZE   (4)
56 #define MASK_MTX_MSG_PROVIDE_CODED_BUFFER_SIZE   (0x0fffffff << SHIFT_MTX_MSG_PROVIDE_CODED_BUFFER_SLOT)
57 
58 
59 typedef enum _pic_mgmt_type_
60 {
61     IMG_PICMGMT_REF_TYPE=0,
62     IMG_PICMGMT_GOP_STRUCT,
63     IMG_PICMGMT_SKIP_FRAME,
64     IMG_PICMGMT_EOS,
65     IMG_PICMGMT_FLUSH,
66     IMG_PICMGMT_QUANT,
67 } IMG_PICMGMT_TYPE;
68 
69 /*!
70  ***********************************************************************************
71  *
72  * Description        : PIC_MGMT - SetNextRefType parameters
73  *
74  ************************************************************************************/
75 typedef struct tag_IMG_PICMGMT_REF_DATA {
76     IMG_FRAME_TYPE  eFrameType;                     //!< Type of the next reference frame (IDR, I, P)
77 } IMG_PICMGMT_REF_DATA;
78 
79 /*!
80  ***********************************************************************************
81  *
82  * Description        : PIC_MGMT - IMG_V_SetGopStructure parameters
83  *
84  ************************************************************************************/
85 typedef struct tag_IMG_PICMGMT_GOP_DATA {
86     IMG_UINT8  ui8BFramePeriod;    //!< B-period
87     IMG_UINT32 ui32IFramePeriod;   //!< I-period
88 } IMG_PICMGMT_GOP_DATA;
89 
90 /*!
91  ***********************************************************************************
92  *
93  * Description        : PIC_MGMT - IMG_V_SkipFrame parameters
94  *
95  ************************************************************************************/
96 typedef struct tag_IMG_PICMGMT_SKIP_DATA {
97     IMG_BOOL8   b8Process;          //!< Process skipped frame (to update MV) ?
98 } IMG_PICMGMT_SKIP_DATA;
99 
100 /*!
101  ***********************************************************************************
102  *
103  * Description        : PIC_MGMT - IMG_V_EndOfStream parameters
104  *
105  ************************************************************************************/
106 typedef struct tag_IMG_PICMGMT_EOS_DATA {
107     IMG_UINT32  ui32FrameCount; //!< Number of frames in the stream (incl. skipped)
108 } IMG_PICMGMT_EOS_DATA;
109 
110 /*!
111  ***********************************************************************************
112  *
113  * Description        : PIC_MGMT - IMG_V_RCUpdate parameters
114  *
115  ************************************************************************************/
116 typedef struct tag_IMG_PICMGMT_RC_UPDATE_DATA {
117     IMG_UINT32  ui32BitsPerFrame;         //!< Number of bits in a frame
118     IMG_UINT8   ui8VCMIFrameQP;        //!< VCM I frame QP
119 } IMG_PICMGMT_RC_UPDATE_DATA;
120 
121 /*!
122  ***********************************************************************************
123  *
124  * Description        : PIC_MGMT - IMG_V_FlushStream parameters
125  *
126  ************************************************************************************/
127 typedef struct tag_IMG_PICMGMT_FLUSH_STREAM_DATA
128 {
129     IMG_UINT32  ui32FlushAtFrame;       //!< Frame Idx to flush the encoder
130 } IMG_PICMGMT_FLUSH_STREAM_DATA;
131 
132 /*!
133  ***********************************************************************************
134  *
135  * Description        : PIC_MGMT - IMG_V_SetCustomScalingValues parameters
136  *
137  ************************************************************************************/
138 typedef struct tag_IMG_PICMGMT_CUSTOM_QUANT_DATA
139 {
140     IMG_UINT32  ui32Values;             //!< Address of custom quantization values
141     IMG_UINT32  ui32Regs4x4Sp;      //!< Address of custom quantization register values for 4x4 Sp
142     IMG_UINT32  ui32Regs8x8Sp;      //!< Address of custom quantization register values for 8x8 Sp
143     IMG_UINT32  ui32Regs4x4Q;       //!< Address of custom quantization register values for 4x4 Q
144     IMG_UINT32  ui32Regs8x8Q;       //!< Address of custom quantization register values for 8x8 Q
145 } IMG_PICMGMT_CUSTOM_QUANT_DATA;
146 
147 /*!
148 ***********************************************************************************
149 @Description        : PROVIDE_BUFFER - Details of the source picture buffer
150 ************************************************************************************/
151 typedef struct tag_IMG_SOURCE_BUFFER_PARAMS {
152     IMG_UINT32      ui32PhysAddrYPlane_Field0;      //!< Source pic phys addr (Y plane, Field 0)
153     IMG_UINT32      ui32PhysAddrUPlane_Field0;      //!< Source pic phys addr (U plane, Field 0)
154     IMG_UINT32      ui32PhysAddrVPlane_Field0;      //!< Source pic phys addr (V plane, Field 0)
155     IMG_UINT32      ui32PhysAddrYPlane_Field1;      //!< Source pic phys addr (Y plane, Field 1)
156     IMG_UINT32      ui32PhysAddrUPlane_Field1;      //!< Source pic phys addr (U plane, Field 1)
157     IMG_UINT32      ui32PhysAddrVPlane_Field1;      //!< Source pic phys addr (V plane, Field 1)
158     IMG_UINT32      ui32HostContext;                //!< Host context value
159     IMG_UINT8       ui8DisplayOrderNum;             //!< Number of frames in the stream (incl. skipped)
160     IMG_UINT8       ui8SlotNum;                     //!< Number of frames in the stream (incl. skipped)
161     IMG_UINT8       uiReserved1;
162     IMG_UINT8       uiReserved2;
163 } IMG_SOURCE_BUFFER_PARAMS;
164 
165 
166 /*!
167 ***********************************************************************************
168 @Description        : PROVIDE_BUFFER - Details of the reference picture buffer
169 ************************************************************************************/
170 typedef struct tag_IMG_BUFFER_REF_DATA {
171     IMG_INT8    i8HeaderSlotNum;                        //!< Slot from which to read the slice header (-1 if none)
172     IMG_BOOL8   b8LongTerm;                                     //!< Flag identifying the reference as long-term
173 } IMG_BUFFER_REF_DATA;
174 
175 /*!
176 ***********************************************************************************
177 @Description        : PROVIDE_BUFFER - Details of the coded buffer
178 ************************************************************************************/
179 typedef struct tag_IMG_BUFFER_CODED_DATA {
180     IMG_UINT32  ui32Size;           //!< Size of coded buffer in bytes
181     IMG_UINT8   ui8SlotNum;             //!< Slot in firmware that this coded buffer should occupy
182 } IMG_BUFFER_CODED_DATA;
183 
184 /*!
185  * *****************************************************************************
186  * @details    PROVIDE_REF_BUFFER - Purpose of the reference buffer
187  * @brief      Purpose of the reference buffer
188  *****************************************************************************/
189 typedef enum _buffer_type_
190 {
191 	IMG_BUFFER_REF0 = 0,
192 	IMG_BUFFER_REF1,
193 	IMG_BUFFER_RECON,
194 } IMG_REF_BUFFER_TYPE;
195 
196 
197 /***********************************************************************************
198 @PICMGMT - functions
199 ************************************************************************************/
200 VAStatus tng_picmgmt_update(context_ENC_p ctx, IMG_PICMGMT_TYPE eType, unsigned int ref);
201 
202 /***********************************************************************************
203 @PROVIDE_BUFFER - functions
204 ************************************************************************************/
205 
206 IMG_UINT32 tng_send_codedbuf(context_ENC_p ctx, IMG_UINT32 ui32SlotIndex);
207 IMG_UINT32 tng_send_source_frame(context_ENC_p ctx, IMG_UINT32 ui32SlotIndex, IMG_UINT32 ui32DisplayOrder);
208 IMG_UINT32 tng_send_rec_frames(context_ENC_p ctx, IMG_INT8 i8HeaderSlotNum, IMG_BOOL bLongTerm);
209 IMG_UINT32 tng_send_ref_frames(context_ENC_p ctx, IMG_UINT32 ui32RefIndex, IMG_BOOL bLongTerm);
210 
211 #endif //_TNG_PICMGMT_H_
212