1 /******************************************************************************* *\ 2 3 Copyright (C) 2019-2020 Intel Corporation. All rights reserved. 4 5 Redistribution and use in source and binary forms, with or without 6 modification, are permitted provided that the following conditions are met: 7 - Redistributions of source code must retain the above copyright notice, 8 this list of conditions and the following disclaimer. 9 - Redistributions in binary form must reproduce the above copyright notice, 10 this list of conditions and the following disclaimer in the documentation 11 and/or other materials provided with the distribution. 12 - Neither the name of Intel Corporation nor the names of its contributors 13 may be used to endorse or promote products derived from this software 14 without specific prior written permission. 15 16 THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS" AND ANY EXPRESS OR 17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 IN NO EVENT SHALL INTEL CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT, 20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 27 File Name: mfxenctools-int.h 28 29 *******************************************************************************/ 30 #ifndef __MFXENCTOOLS_INT_H__ 31 #define __MFXENCTOOLS_INT_H__ 32 33 #include "mfx_config.h" 34 #include "mfxvideo++.h" 35 #include "mfxbrc.h" 36 37 #ifdef __cplusplus 38 extern "C" 39 { 40 #endif /* __cplusplus */ 41 42 /* Extended Buffer Ids */ 43 enum { 44 MFX_EXTBUFF_ENCTOOLS_CONFIG = MFX_MAKEFOURCC('E', 'T', 'C', 'F'), 45 }; 46 47 MFX_PACK_BEGIN_USUAL_STRUCT() 48 typedef union { 49 struct { 50 mfxU8 Minor; 51 mfxU8 Major; 52 }; 53 mfxU16 Version; 54 } mfxStructVersion; 55 MFX_PACK_END() 56 57 #define MFX_STRUCT_VERSION(MAJOR, MINOR) (256*(MAJOR) + (MINOR)) 58 59 60 MFX_PACK_BEGIN_USUAL_STRUCT() 61 typedef struct 62 { 63 mfxExtBuffer Header; 64 mfxStructVersion Version; 65 mfxU16 AdaptiveI; 66 mfxU16 AdaptiveB; 67 mfxU16 AdaptiveRefP; 68 mfxU16 AdaptiveRefB; 69 mfxU16 SceneChange; 70 mfxU16 AdaptiveLTR; 71 mfxU16 AdaptivePyramidQuantP; 72 mfxU16 AdaptivePyramidQuantB; 73 mfxU16 AdaptiveQuantMatrices; 74 mfxU16 BRCBufferHints; 75 mfxU16 BRC; 76 mfxU16 reserved[20]; 77 } mfxExtEncToolsConfig; 78 MFX_PACK_END() 79 80 #define MFX_ENCTOOLS_CONFIG_VERSION MFX_STRUCT_VERSION(1, 0) 81 82 83 84 /* Extended Buffer Ids */ 85 enum { 86 MFX_EXTBUFF_ENCTOOLS = MFX_MAKEFOURCC('E', 'E', 'T', 'L'), 87 MFX_EXTBUFF_ENCTOOLS_DEVICE = MFX_MAKEFOURCC('E', 'T', 'E', 'D'), 88 MFX_EXTBUFF_ENCTOOLS_ALLOCATOR = MFX_MAKEFOURCC('E', 'T', 'E', 'A'), 89 MFX_EXTBUFF_ENCTOOLS_FRAME_TO_ANALYZE = MFX_MAKEFOURCC('E', 'F', 'T', 'A'), 90 MFX_EXTBUFF_ENCTOOLS_HINT_SCENE_CHANGE = MFX_MAKEFOURCC('E', 'H', 'S', 'C'), 91 MFX_EXTBUFF_ENCTOOLS_HINT_GOP = MFX_MAKEFOURCC('E', 'H', 'G', 'O'), 92 MFX_EXTBUFF_ENCTOOLS_HINT_AREF = MFX_MAKEFOURCC('E', 'H', 'A', 'R'), 93 MFX_EXTBUFF_ENCTOOLS_BRC_BUFFER_HINT = MFX_MAKEFOURCC('E', 'B', 'B', 'H'), 94 MFX_EXTBUFF_ENCTOOLS_BRC_FRAME_PARAM = MFX_MAKEFOURCC('E', 'B', 'F', 'P'), 95 MFX_EXTBUFF_ENCTOOLS_BRC_QUANT_CONTROL = MFX_MAKEFOURCC('E', 'B', 'Q', 'C'), 96 MFX_EXTBUFF_ENCTOOLS_BRC_HRD_POS = MFX_MAKEFOURCC('E', 'B', 'H', 'P'), 97 MFX_EXTBUFF_ENCTOOLS_BRC_ENCODE_RESULT = MFX_MAKEFOURCC('E', 'B', 'E', 'R'), 98 MFX_EXTBUFF_ENCTOOLS_BRC_STATUS = MFX_MAKEFOURCC('E', 'B', 'S', 'T'), 99 MFX_EXTBUFF_ENCTOOLS_HINT_MATRIX = MFX_MAKEFOURCC('E', 'H', 'Q', 'M') 100 }; 101 102 #define MFX_ENCTOOLS_CONFIG_VERSION MFX_STRUCT_VERSION(1, 0) 103 104 enum 105 { 106 MFX_BRC_NO_HRD = 0, 107 MFX_BRC_HRD_WEAK, /* IF HRD CALCULATION IS REQUIRED, BUT NOT WRITTEN TO THE STREAM */ 108 MFX_BRC_HRD_STRONG, 109 }; 110 111 MFX_PACK_BEGIN_STRUCT_W_PTR() 112 typedef struct 113 { 114 mfxStructVersion Version; 115 mfxU16 reserved[3]; 116 117 /* info about codec */ 118 struct /* coding info*/ 119 { 120 mfxU32 CodecId; 121 mfxU16 CodecProfile; 122 mfxU16 CodecLevel; 123 mfxU16 reserved2[64]; 124 }; 125 struct /* input frames info */ 126 { 127 /* info about input frames */ 128 mfxFrameInfo FrameInfo; 129 mfxU16 IOPattern; 130 mfxU16 MaxDelayInFrames; 131 mfxU16 reserved3[64]; 132 }; 133 struct 134 { 135 /* Gop limitations */ 136 mfxU16 MaxGopSize; 137 mfxU16 MaxGopRefDist; 138 mfxU16 MaxIDRDist; 139 mfxU16 BRefType; 140 mfxU16 reserved4[64]; 141 }; 142 mfxU16 ScenarioInfo; 143 144 struct /* Rate control info */ 145 { 146 mfxU16 RateControlMethod; /* CBR, VBR, CRF, CQP */ 147 mfxU32 TargetKbps; /* ignored for CRF, CQP */ 148 mfxU32 MaxKbps; /* ignored for CRF, CQP */ 149 mfxU16 QPLevel[3]; /* for CRF, CQP */ 150 151 mfxU16 HRDConformance; /* for CBR & VBR */ 152 mfxU32 BufferSizeInKB; /* if HRDConformance is ON */ 153 mfxU32 InitialDelayInKB; /* if HRDConformance is ON */ 154 155 mfxU32 ConvergencePeriod; /* if HRDConformance is OFF, 0 - the period is whole stream */ 156 mfxU32 Accuracy; /* if HRDConformance is OFF */ 157 158 mfxU32 WinBRCMaxAvgKbps; /* sliding window restriction */ 159 mfxU16 WinBRCSize; /* sliding window restriction */ 160 161 mfxU32 MaxFrameSizeInBytes[3]; /* MaxFrameSize limitation */ 162 163 mfxU16 MinQPLevel[3]; /* QP range limitations */ 164 mfxU16 MaxQPLevel[3]; /* QP range limitations */ 165 166 mfxU32 PanicMode; 167 mfxU16 reserved5[64]; 168 }; 169 mfxU16 NumExtParam; 170 mfxExtBuffer** ExtParam; 171 } mfxEncToolsCtrl; 172 MFX_PACK_END() 173 174 #define MFX_ENCTOOLS_CTRL_VERSION MFX_STRUCT_VERSION(1, 0) 175 176 MFX_PACK_BEGIN_STRUCT_W_PTR() 177 typedef struct { 178 mfxExtBuffer Header; 179 mfxStructVersion Version; 180 mfxU16 reserved[3]; 181 mfxHDL DeviceHdl; 182 mfxU32 HdlType; 183 mfxU32 reserved2[3]; 184 } mfxEncToolsCtrlExtDevice; 185 MFX_PACK_END() 186 187 #define MFX_ENCTOOLS_CTRL_EXTDEVICE_VERSION MFX_STRUCT_VERSION(1, 0) 188 189 MFX_PACK_BEGIN_STRUCT_W_PTR() 190 typedef struct { 191 mfxExtBuffer Header; 192 mfxStructVersion Version; 193 mfxU16 reserved[3]; 194 mfxFrameAllocator *pAllocator; 195 mfxU32 reserved2[4]; 196 } mfxEncToolsCtrlExtAllocator; 197 MFX_PACK_END() 198 199 #define MFX_ENCTOOLS_CTRL_EXTALLOCATOR_VERSION MFX_STRUCT_VERSION(1, 0) 200 201 MFX_PACK_BEGIN_STRUCT_W_PTR() 202 typedef struct { 203 mfxStructVersion Version; 204 mfxU16 reserved; 205 mfxU32 DisplayOrder; 206 mfxExtBuffer **ExtParam; 207 mfxU16 NumExtParam; 208 mfxU16 reserved2; 209 mfxU32 reserved3[3]; 210 } mfxEncToolsTaskParam; 211 MFX_PACK_END() 212 213 #define MFX_ENCTOOLS_TASKPARAM_VERSION MFX_STRUCT_VERSION(1, 0) 214 215 MFX_PACK_BEGIN_STRUCT_W_PTR() 216 typedef struct 217 { 218 mfxExtBuffer Header; 219 mfxStructVersion Version; 220 mfxU16 reserved[3]; 221 mfxFrameSurface1 *Surface; /* Input surface */ 222 mfxU32 reserved2[2]; 223 } mfxEncToolsFrameToAnalyze; 224 MFX_PACK_END() 225 226 #define MFX_ENCTOOLS_FRAMETOANALYZE_VERSION MFX_STRUCT_VERSION(1, 0) 227 228 MFX_PACK_BEGIN_USUAL_STRUCT() 229 typedef struct { 230 mfxExtBuffer Header; 231 mfxStructVersion Version; 232 mfxU16 reserved[3]; 233 mfxU16 SceneChangeFlag; 234 mfxU16 RepeatedFrameFlag; 235 mfxU32 TemporalComplexity; 236 mfxU32 reserved2[2]; 237 } mfxEncToolsHintPreEncodeSceneChange; 238 MFX_PACK_END() 239 240 #define MFX_ENCTOOLS_HINTPREENCODE_SCENECHANGE_VERSION MFX_STRUCT_VERSION(1, 0) 241 242 enum 243 { 244 MFX_QUANT_MATRIX_DEFAULT = 0, 245 MFX_QUANT_MATRIX_FLAT, 246 MFX_QUANT_MATRIX_HIGH_FREQUENCY_STRONG 247 }; 248 249 MFX_PACK_BEGIN_USUAL_STRUCT() 250 typedef struct { 251 mfxExtBuffer Header; 252 mfxStructVersion Version; 253 mfxU16 reserved[2]; 254 mfxU16 MatrixType; /* enum */ 255 } mfxEncToolsHintQuantMatrix; 256 MFX_PACK_END() 257 258 #define MFX_ENCTOOLS_HINT_QUANTMATRIX_VERSION MFX_STRUCT_VERSION(1, 0) 259 260 #define MFX_QP_UNDEFINED 0x1111 261 262 enum 263 { 264 MFX_QP_MODULATION_NOT_DEFINED = 0, 265 MFX_QP_MODULATION_LOW, 266 MFX_QP_MODULATION_MEDIUM, 267 MFX_QP_MODULATION_HIGH 268 }; 269 270 MFX_PACK_BEGIN_USUAL_STRUCT() 271 typedef struct { 272 mfxExtBuffer Header; 273 mfxStructVersion Version; 274 mfxU16 reserved[2]; 275 mfxU16 FrameType; 276 mfxI16 QPDelta; 277 mfxU16 QPModulation; /* enum */ 278 mfxU16 MiniGopSize; /* Adaptive GOP decision for the frame */ 279 mfxU16 reserved2[5]; 280 } mfxEncToolsHintPreEncodeGOP; 281 MFX_PACK_END() 282 283 #define MFX_ENCTOOLS_HINTPREENCODE_GOP_VERSION MFX_STRUCT_VERSION(1, 0) 284 285 enum 286 { 287 MFX_REF_FRAME_NORMAL = 0, 288 MFX_REF_FRAME_TYPE_LTR, 289 MFX_REF_FRAME_TYPE_KEY 290 }; 291 292 MFX_PACK_BEGIN_USUAL_STRUCT() 293 typedef struct { /* only for progressive. Need to think about interlace for future support */ 294 mfxExtBuffer Header; 295 mfxStructVersion Version; 296 mfxU16 reserved[2]; 297 mfxU16 CurrFrameType; /* enum */ 298 mfxU32 PreferredRefList[16]; 299 mfxU32 RejectedRefList[16]; 300 mfxU16 PreferredRefListSize; 301 mfxU16 RejectedRefListSize; 302 mfxU16 reserved2[7]; 303 } mfxEncToolsHintPreEncodeARefFrames; /* Output structure */ 304 MFX_PACK_END() 305 306 #define MFX_ENCTOOLS_HINTPREENCODE_AREFFRAMES_VERSION MFX_STRUCT_VERSION(1, 0) 307 308 MFX_PACK_BEGIN_USUAL_STRUCT() 309 typedef struct { 310 mfxExtBuffer Header; 311 mfxStructVersion Version; 312 mfxU16 reserved[3]; 313 mfxU32 OptimalFrameSizeInBytes; 314 /* mfxU32 OptimalBufferFullness; */ /* Target buffer fullness in bits, currently can be calculated from OptimalFrameSizeInBytes */ 315 mfxU32 reserved2[7]; 316 } mfxEncToolsBRCBufferHint; 317 MFX_PACK_END() 318 319 #define MFX_ENCTOOLS_BRCBUFFER_HINT_VERSION MFX_STRUCT_VERSION(1, 0) 320 321 MFX_PACK_BEGIN_USUAL_STRUCT() 322 typedef struct { 323 mfxExtBuffer Header; 324 mfxStructVersion Version; 325 mfxU16 reserved[3]; 326 mfxU16 FrameType; /* See FrameType enumerator */ 327 mfxU16 PyramidLayer; /* B-pyramid or P-pyramid layer frame belongs to */ 328 mfxU32 EncodeOrder; /* Frame number in a sequence of reordered frames starting from encoder Init() */ 329 mfxU32 reserved1[2]; 330 } mfxEncToolsBRCFrameParams; 331 MFX_PACK_END() 332 333 #define MFX_ENCTOOLS_BRCFRAMEPARAMS_VERSION MFX_STRUCT_VERSION(1, 0) 334 335 MFX_PACK_BEGIN_USUAL_STRUCT() 336 typedef struct { 337 mfxExtBuffer Header; 338 mfxStructVersion Version; 339 mfxU16 reserved[3]; 340 mfxU32 QpY; /* Frame-level Luma QP. Mandatory */ 341 mfxU32 MaxFrameSize; /* Max frame size in bytes (used for rePak). Optional */ 342 mfxU8 DeltaQP[8]; /* deltaQP[i] is added to QP value while ith-rePakOptional */ 343 mfxU16 NumDeltaQP; /* Max number of rePaks to provide MaxFrameSize (from 0 to 8) */ 344 mfxU16 reserved2[3]; 345 } mfxEncToolsBRCQuantControl; 346 MFX_PACK_END() 347 348 #define MFX_ENCTOOLS_BRCQUANTCONTROL_VERSION MFX_STRUCT_VERSION(1, 0) 349 350 MFX_PACK_BEGIN_USUAL_STRUCT() 351 typedef struct { 352 mfxExtBuffer Header; 353 mfxStructVersion Version; 354 mfxU16 reserved[3]; 355 mfxU32 InitialCpbRemovalDelay; 356 mfxU32 InitialCpbRemovalDelayOffset; 357 mfxU32 reserved2[2]; 358 } mfxEncToolsBRCHRDPos; 359 MFX_PACK_END() 360 361 #define MFX_ENCTOOLS_BRCHRDPOS_VERSION MFX_STRUCT_VERSION(1, 0) 362 363 MFX_PACK_BEGIN_USUAL_STRUCT() 364 typedef struct { 365 mfxExtBuffer Header; 366 mfxStructVersion Version; 367 mfxU16 reserved[3]; 368 mfxU16 NumRecodesDone; /* Number of recodings performed for this frame. Optional */ 369 mfxU16 QpY; /* Luma QP the frame was encoded with */ 370 mfxU32 CodedFrameSize; /* Size of frame in bytes after encoding */ 371 mfxU32 reserved2[2]; 372 } mfxEncToolsBRCEncodeResult; 373 MFX_PACK_END() 374 375 #define MFX_ENCTOOLS_BRCENCODERESULT_VERSION MFX_STRUCT_VERSION(1, 0) 376 377 MFX_PACK_BEGIN_USUAL_STRUCT() 378 typedef struct { 379 mfxExtBuffer Header; 380 mfxStructVersion Version; 381 mfxU16 reserved[3]; 382 mfxBRCFrameStatus FrameStatus; 383 } mfxEncToolsBRCStatus; 384 MFX_PACK_END() 385 386 #define MFX_ENCTOOLS_BRCSTATUS_VERSION MFX_STRUCT_VERSION(1, 0) 387 388 MFX_PACK_BEGIN_STRUCT_W_PTR() 389 typedef struct { 390 mfxExtBuffer Header; 391 mfxStructVersion Version; /* what about to return version of EncTools containing commit_id � return through GetVersion? */ 392 mfxU16 reserved[3]; /* to align with Version */ 393 mfxU32 reserved2[14]; 394 mfxHDL Context; 395 mfxStatus(MFX_CDECL *Init) (mfxHDL pthis, mfxExtEncToolsConfig* config, mfxEncToolsCtrl* ctrl); 396 mfxStatus(MFX_CDECL *GetSupportedConfig) (mfxHDL pthis, mfxExtEncToolsConfig* config, mfxEncToolsCtrl* ctrl); 397 mfxStatus(MFX_CDECL *GetActiveConfig) (mfxHDL pthis, mfxExtEncToolsConfig* pEncToolConfig); 398 mfxStatus(MFX_CDECL *GetDelayInFrames)(mfxHDL pthis, mfxExtEncToolsConfig* pEncToolConfig, mfxEncToolsCtrl* ctrl, mfxU32 *numFrames); 399 mfxStatus(MFX_CDECL *Reset) (mfxHDL pthis, mfxExtEncToolsConfig* pEncToolConfig, mfxEncToolsCtrl* ctrl); /* asynchronous reset */ 400 mfxStatus(MFX_CDECL *Close) (mfxHDL pthis); 401 mfxStatus(MFX_CDECL *Submit) (mfxHDL pthis, mfxEncToolsTaskParam* sparam); /* Encoder knows how many buffers should be provided by app/encode and it waits for all of them */ 402 mfxStatus(MFX_CDECL *Query) (mfxHDL pthis, mfxEncToolsTaskParam* param, mfxU32 timeout); 403 mfxStatus(MFX_CDECL *Discard) (mfxHDL pthis, mfxU32 DisplayOrder); 404 mfxHDL reserved3[8]; 405 } mfxEncTools; 406 MFX_PACK_END() 407 408 #define MFX_ENCTOOLS_VERSION MFX_STRUCT_VERSION(1, 0) 409 410 mfxEncTools* MFX_CDECL MFXVideoENCODE_CreateEncTools(); 411 void MFX_CDECL MFXVideoENCODE_DestroyEncTools(mfxEncTools *et); 412 413 414 415 #ifdef __cplusplus 416 } /* extern "C" */ 417 #endif /* __cplusplus */ 418 419 #endif 420 421