1 /*
2 * Copyright (c) 2019-2021, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 
23 //!
24 //! \file     media_vp9_packet_defs.h
25 //! \brief    Defines for vp9 packets
26 //!
27 
28 #ifndef __MEDIA_VP9_PACKET_DEFS_H__
29 #define __MEDIA_VP9_PACKET_DEFS_H__
30 #include "media_feature_manager.h"
31 
32 namespace encode
33 {
34 //!
35 //! \struct    HcpPakObject
36 //! \brief     HCP pak object
37 //!
38 struct HcpPakObject
39 {
40     // DW0
41     struct
42     {
43         uint32_t DwordLength : 16;   //[15:0]
44         uint32_t SubOp       : 7;    //[22:16]
45         uint32_t Opcode      : 6;    //[28:23]
46         uint32_t Type        : 3;    //[31:29]
47     } DW0;
48 
49     //DW1
50     struct
51     {
52         uint32_t Split_flag_level2_level1part0 : 4;
53         uint32_t Split_flag_level2_level1part1 : 4;
54         uint32_t Split_flag_level2_level1part2 : 4;
55         uint32_t Split_flag_level2_level1part3 : 4;
56         uint32_t Split_flag_level1             : 4;
57         uint32_t Split_flag_level0             : 1;
58         uint32_t Reserved21_23                 : 3;
59         uint32_t CU_count_minus1               : 6;
60         uint32_t IsLastSBFrameflag             : 1;
61         uint32_t IsLastSBTileflag              : 1;
62     } DW1;
63 
64     //DW2
65     struct
66     {
67         uint32_t Current_SB_X_Addr : 16;
68         uint32_t Current_SB_Y_Addr : 16;
69     } DW2;
70 
71     //DW3
72     uint32_t Reserved_DW03 : 32;
73 };
74 C_ASSERT(MOS_BYTES_TO_DWORDS(sizeof(HcpPakObject)) == 4);
75 
76 //!
77 //! \struct    HucFrameCtrl
78 //! \brief     HUC frame contol
79 //!
80 struct HucFrameCtrl
81 {
82     uint32_t FrameType;             //0:INTRA, 1:INTER     // DW15
83     uint32_t ShowFrame;             // DW16
84     uint32_t ErrorResilientMode;    // DW17
85     uint32_t IntraOnly;             // DW18
86     uint32_t ContextReset;          // DW19
87     uint32_t LastRefFrameBias;      // DW20
88     uint32_t GoldenRefFrameBias;    // DW21
89     uint32_t AltRefFrameBias;       // DW22
90     uint32_t AllowHighPrecisionMv;  // DW23
91     uint32_t McompFilterMode;       // DW24
92     uint32_t TxMode;                // DW25
93     uint32_t RefreshFrameContext;   // DW26
94     uint32_t FrameParallelDecode;   // DW27
95     uint32_t CompPredMode;          // DW28
96     uint32_t FrameContextIdx;       // DW29
97     uint32_t SharpnessLevel;        // DW30
98     uint32_t SegOn;                 // DW31
99     uint32_t SegMapUpdate;          // DW32
100     uint32_t SegUpdateData;         // DW33
101     uint8_t  Rsvd[13];              // DW34-36, first byte of 37
102     uint8_t  log2TileCols;          // DW37
103     uint8_t  log2TileRows;          // DW37
104     uint8_t  Reserved[5];           // DW37 last byte, DW38
105 };
106 
107 //!
108 //! \struct    HucPrevFrameInfo
109 //! \brief     HUC definition: PrevFrameInfo
110 //!
111 struct HucPrevFrameInfo
112 {
113     uint32_t IntraOnly;    // DW39
114     uint32_t FrameWidth;   // DW40
115     uint32_t FrameHeight;  // DW41
116     uint32_t KeyFrame;     // DW42
117     uint32_t ShowFrame;    // DW43
118 };
119 
120 //!
121 //! \struct    HucProbDmem
122 //! \brief     HUC prob dmem
123 //!
124 struct HucProbDmem
125 {
126     uint32_t         HuCPassNum;
127     uint32_t         FrameWidth;
128     uint32_t         FrameHeight;
129     uint32_t         Rsvd32[6];
130     char             SegmentRef[CODEC_VP9_MAX_SEGMENTS];
131     uint8_t          SegmentSkip[CODEC_VP9_MAX_SEGMENTS];
132     uint8_t          SegCodeAbs;
133     uint8_t          SegTemporalUpdate;
134     uint8_t          LastRefIndex;
135     uint8_t          GoldenRefIndex;
136     uint8_t          AltRefIndex;
137     uint8_t          RefreshFrameFlags;
138     uint8_t          RefFrameFlags;
139     uint8_t          ContextFrameTypes;
140     HucFrameCtrl     FrameCtrl;
141     HucPrevFrameInfo PrevFrameInfo;
142     uint8_t          Rsvd[2];
143     uint8_t          FrameToShow;
144     uint8_t          LoadKeyFrameDefaultProbs;
145     uint32_t         FrameSize;
146     uint32_t         VDEncImgStateOffset;
147     uint32_t         RePak;
148     uint16_t         LFLevelBitOffset;
149     uint16_t         QIndexBitOffset;
150     uint16_t         SegBitOffset;
151     uint16_t         SegLengthInBits;
152     uint16_t         UnCompHdrTotalLengthInBits;
153     uint16_t         SegUpdateDisable;
154     int32_t          RePakThreshold[256];
155     uint16_t         PicStateOffset;
156     uint16_t         SLBBSize;
157     uint8_t          StreamInEnable;
158     uint8_t          StreamInSegEnable;
159     uint8_t          DisableDMA;
160     uint8_t          IVFHeaderSize;
161     uint8_t          PakOnlyEnable;
162     uint8_t          Reserved[43];
163 };
164 
165 //!
166 //! \struct    HucBrcInitDmem
167 //! \brief     HUC brc init dmem
168 //!
169 struct HucBrcInitDmem
170 {
171     uint32_t BRCFunc;               // 0: Init; 2: Reset
172     uint32_t ProfileLevelMaxFrame;  // Limit on maximum frame size based on selected profile and level, and can be user defined
173     uint32_t InitBufFullness;       // Initial buffer fullness
174     uint32_t BufSize;               // Buffer size
175     uint32_t TargetBitrate;         // Average(target) bit rate
176     uint32_t MaxRate;               // Maximum bit rate in bits per second (bps).
177     uint32_t MinRate;               // Minimum bit rate
178     uint32_t FrameRateM;            // Framerate numerator
179     uint32_t FrameRateD;            // Framerate denominator
180     uint32_t RSVD32[4];             // Reserved, MBZ
181 
182     uint16_t BRCFlag;               // BRC flag
183     uint16_t GopP;                  // number of P frames in a GOP
184     uint16_t Reserved;
185     uint16_t FrameWidth;            // Frame width
186     uint16_t FrameHeight;           // Frame height
187     uint16_t MinQP;                 // Minimum QP
188     uint16_t MaxQP;                 // Maximum QP
189     uint16_t LevelQP;               // Level QP
190     uint16_t GoldenFrameInterval;   // Golden frame interval
191     uint16_t EnableScaling;         // Enable resolution scaling
192     uint16_t OvershootCBR;          // default: 115, CBR overshoot percentage
193     uint16_t RSVD16[5];             // Reserved, MBZ
194 
195     int8_t InstRateThreshP0[4];     // Instant rate threshold for P frame
196     int8_t Reserved2[4];
197     int8_t InstRateThreshI0[4];
198     int8_t DevThreshPB0[8];         // Deviation threshold for P and B frame
199     int8_t DevThreshVBR0[8];        // Deviation threshold for VBR control
200     int8_t DevThreshI0[8];          // Deviation threshold for I frame
201 
202     uint8_t InitQPP;
203     uint8_t InitQPI;
204     uint8_t RSVD3;
205     uint8_t Total_Level;
206     uint8_t MaxLevel_Ratio[16];
207     uint8_t SlidingWindowEnable;
208     uint8_t SlidingWindowSize;
209     uint8_t RSVD8[47];              // Reserved, MBZ
210 };
211 
212 //!
213 //! \struct    HucBrcUpdateDmem
214 //! \brief     HUC brc update dmem
215 //!
216 struct HucBrcUpdateDmem
217 {
218     int32_t  UPD_TARGET_BUF_FULLNESS_U32;      // Passed by the driver
219     uint32_t UPD_FRAMENUM_U32;                 // Passed by the driver
220     int32_t  UPD_HRD_BUFF_FULLNESS_UPPER_I32;  // Passed by the driver
221     int32_t  UPD_HRD_BUFF_FULLNESS_LOWER_I32;  // Passed by the driver
222     uint32_t RSVD32[7];                        // mbz
223 
224     uint16_t UPD_startGAdjFrame_U16[4];        // Start global adjust frame (4 items)
225     uint16_t UPD_CurWidth_U16;                 // Current width
226     uint16_t UPD_CurHeight_U16;                // Current height
227     uint16_t UPD_Asyn_U16;
228     uint16_t UPD_VDEncImgStateOffset;          // The image state start position in bytes from the begining of Second Level BB
229     uint16_t UPD_SLBBSize;                     // Second level batch buffer total size in bytes
230     uint16_t UPD_PicStateOffset;               // The pic state offset in bytes from the beginning of second level batch buffer
231     uint16_t RSVD16[6];                        // mbz
232 
233     uint8_t UPD_OVERFLOW_FLAG_U8;              // Passed by the driver
234     uint8_t UPD_BRCFlag_U8;                    // BRC flag, 0 - nothing to report, others - BRCPIC\BRCCUR flag defines 1 - scene change, etc // RSVD on G10, remove when G11 drops dependency
235     uint8_t UPD_MaxNumPAKs_U8;                 // Maximum number of PAKs (default set to 4)
236     int8_t  UPD_CurrFrameType_U8;              // Current frame type (0:P, 1:B, 2:I)
237     uint8_t UPD_QPThreshold_U8[4];             // QP threshold (4 entries)
238     uint8_t UPD_gRateRatioThreshold_U8[6];     // Global rate ratio threshold (6 items)
239     int8_t  UPD_startGAdjMult_U8[5];           // Start global adjust mult (5 items)
240     int8_t  UPD_startGAdjDiv_U8[5];            // Start global adjust div (5 items)
241     int8_t  UPD_gRateRatioThresholdQP_U8[7];   // Global rate ratio threshold QP (7 items)
242     uint8_t UPD_DistThreshldI_U8[9];           // (N_DISTORION_THRESHLDS+1) distortion thresholds for I frames
243     uint8_t UPD_DistThreshldP_U8[9];           // (N_DISTORION_THRESHLDS+1) distortion thresholds for P frames
244     uint8_t UPD_DistThreshldB_U8[9];           // (N_DISTORION_THRESHLDS+1) distortion thresholds for B frames; no needed for Vp8 - to clean up
245     int8_t  UPD_MaxFrameThreshI_U8[5];         // Num qp threshld + 1 of multiplyers
246     int8_t  UPD_MaxFrameThreshP_U8[5];         // Num qp threshld + 1 of multiplyers
247     int8_t  UPD_MaxFrameThreshB_U8[5];         // Num qp threshld + 1 of multiplyers; no needed for Vp8 - to clean up
248     uint8_t UPD_PAKPassNum_U8;                 // Current pak pass number
249     uint8_t UPD_ACQQp_U8;
250     int8_t  UPD_DeltaQPForSadZone0_I8;
251     int8_t  UPD_DeltaQPForSadZone1_I8;
252     int8_t  UPD_DeltaQPForSadZone2_I8;
253     int8_t  UPD_DeltaQPForSadZone3_I8;
254     int8_t  UPD_DeltaQPForMvZero_I8;
255     int8_t  UPD_DeltaQPForMvZone0_I8;
256     int8_t  UPD_DeltaQPForMvZone1_I8;
257     int8_t  UPD_DeltaQPForMvZone2_I8;
258     uint8_t UPD_Temporal_Level_U8;
259     uint8_t UPD_SegMapGenerating_U8;           // Default 0: HuC does not update segmentation state; 1: HuC updates all 8 segmentation states in second level batch buffer
260     uint8_t RSVD8[95];                         // mbz
261 };
262 
263 }
264 
265 #endif  // !__MEDIA_VP9_PACKET_DEFS_H__
266