1 /*! 2 * \copy 3 * Copyright (c) 2013, Cisco Systems 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * * Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 13 * * Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the 16 * distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 * 31 */ 32 33 34 35 #ifndef WELS_VIDEO_CODEC_APPLICATION_DEFINITION_H__ 36 #define WELS_VIDEO_CODEC_APPLICATION_DEFINITION_H__ 37 /** 38 * @file codec_app_def.h 39 * @brief Data and /or structures introduced in Cisco OpenH264 application 40 */ 41 42 #include "codec_def.h" 43 /* Constants */ 44 #define MAX_TEMPORAL_LAYER_NUM 4 45 #define MAX_SPATIAL_LAYER_NUM 4 46 #define MAX_QUALITY_LAYER_NUM 4 47 48 #define MAX_LAYER_NUM_OF_FRAME 128 49 #define MAX_NAL_UNITS_IN_LAYER 128 ///< predetermined here, adjust it later if need 50 51 #define MAX_RTP_PAYLOAD_LEN 1000 52 #define AVERAGE_RTP_PAYLOAD_LEN 800 53 54 55 #define SAVED_NALUNIT_NUM_TMP ( (MAX_SPATIAL_LAYER_NUM*MAX_QUALITY_LAYER_NUM) + 1 + MAX_SPATIAL_LAYER_NUM ) ///< SPS/PPS + SEI/SSEI + PADDING_NAL 56 #define MAX_SLICES_NUM_TMP ( ( MAX_NAL_UNITS_IN_LAYER - SAVED_NALUNIT_NUM_TMP ) / 3 ) 57 58 59 #define AUTO_REF_PIC_COUNT -1 ///< encoder selects the number of reference frame automatically 60 #define UNSPECIFIED_BIT_RATE 0 ///< to do: add detail comment 61 62 /** 63 * @brief Struct of OpenH264 version 64 */ 65 /// 66 /// E.g. SDK version is 1.2.0.0, major version number is 1, minor version number is 2, and revision number is 0. 67 typedef struct _tagVersion { 68 unsigned int uMajor; ///< The major version number 69 unsigned int uMinor; ///< The minor version number 70 unsigned int uRevision; ///< The revision number 71 unsigned int uReserved; ///< The reserved number, it should be 0. 72 } OpenH264Version; 73 74 /** 75 * @brief Decoding status 76 */ 77 typedef enum { 78 /** 79 * Errors derived from bitstream parsing 80 */ 81 dsErrorFree = 0x00, ///< bit stream error-free 82 dsFramePending = 0x01, ///< need more throughput to generate a frame output, 83 dsRefLost = 0x02, ///< layer lost at reference frame with temporal id 0 84 dsBitstreamError = 0x04, ///< error bitstreams(maybe broken internal frame) the decoder cared 85 dsDepLayerLost = 0x08, ///< dependented layer is ever lost 86 dsNoParamSets = 0x10, ///< no parameter set NALs involved 87 dsDataErrorConcealed = 0x20, ///< current data error concealed specified 88 dsRefListNullPtrs = 0x40, ///<ref picure list contains null ptrs within uiRefCount range 89 90 /** 91 * Errors derived from logic level 92 */ 93 dsInvalidArgument = 0x1000, ///< invalid argument specified 94 dsInitialOptExpected = 0x2000, ///< initializing operation is expected 95 dsOutOfMemory = 0x4000, ///< out of memory due to new request 96 /** 97 * ANY OTHERS? 98 */ 99 dsDstBufNeedExpan = 0x8000 ///< actual picture size exceeds size of dst pBuffer feed in decoder, so need expand its size 100 101 } DECODING_STATE; 102 103 /** 104 * @brief Option types introduced in SVC encoder application 105 */ 106 typedef enum { 107 ENCODER_OPTION_DATAFORMAT = 0, 108 ENCODER_OPTION_IDR_INTERVAL, ///< IDR period,0/-1 means no Intra period (only the first frame); lager than 0 means the desired IDR period, must be multiple of (2^temporal_layer) 109 ENCODER_OPTION_SVC_ENCODE_PARAM_BASE, ///< structure of Base Param 110 ENCODER_OPTION_SVC_ENCODE_PARAM_EXT, ///< structure of Extension Param 111 ENCODER_OPTION_FRAME_RATE, ///< maximal input frame rate, current supported range: MAX_FRAME_RATE = 30,MIN_FRAME_RATE = 1 112 ENCODER_OPTION_BITRATE, 113 ENCODER_OPTION_MAX_BITRATE, 114 ENCODER_OPTION_INTER_SPATIAL_PRED, 115 ENCODER_OPTION_RC_MODE, 116 ENCODER_OPTION_RC_FRAME_SKIP, 117 ENCODER_PADDING_PADDING, ///< 0:disable padding;1:padding 118 119 ENCODER_OPTION_PROFILE, ///< assgin the profile for each layer 120 ENCODER_OPTION_LEVEL, ///< assgin the level for each layer 121 ENCODER_OPTION_NUMBER_REF, ///< the number of refererence frame 122 ENCODER_OPTION_DELIVERY_STATUS, ///< the delivery info which is a feedback from app level 123 124 ENCODER_LTR_RECOVERY_REQUEST, 125 ENCODER_LTR_MARKING_FEEDBACK, 126 ENCODER_LTR_MARKING_PERIOD, 127 ENCODER_OPTION_LTR, ///< 0:disable LTR;larger than 0 enable LTR; LTR number is fixed to be 2 in current encoder 128 ENCODER_OPTION_COMPLEXITY, 129 130 ENCODER_OPTION_ENABLE_SSEI, ///< enable SSEI: true--enable ssei; false--disable ssei 131 ENCODER_OPTION_ENABLE_PREFIX_NAL_ADDING, ///< enable prefix: true--enable prefix; false--disable prefix 132 ENCODER_OPTION_SPS_PPS_ID_STRATEGY, ///< different stategy in adjust ID in SPS/PPS: 0- constant ID, 1-additional ID, 6-mapping and additional 133 134 ENCODER_OPTION_CURRENT_PATH, 135 ENCODER_OPTION_DUMP_FILE, ///< dump layer reconstruct frame to a specified file 136 ENCODER_OPTION_TRACE_LEVEL, ///< trace info based on the trace level 137 ENCODER_OPTION_TRACE_CALLBACK, ///< a void (*)(void* context, int level, const char* message) function which receives log messages 138 ENCODER_OPTION_TRACE_CALLBACK_CONTEXT, ///< context info of trace callback 139 140 ENCODER_OPTION_GET_STATISTICS, ///< read only 141 ENCODER_OPTION_STATISTICS_LOG_INTERVAL, ///< log interval in millisecond 142 143 ENCODER_OPTION_IS_LOSSLESS_LINK, ///< advanced algorithmetic settings 144 145 ENCODER_OPTION_BITS_VARY_PERCENTAGE ///< bit vary percentage 146 } ENCODER_OPTION; 147 148 /** 149 * @brief Option types introduced in decoder application 150 */ 151 typedef enum { 152 DECODER_OPTION_END_OF_STREAM = 1, ///< end of stream flag 153 DECODER_OPTION_VCL_NAL, ///< feedback whether or not have VCL NAL in current AU for application layer 154 DECODER_OPTION_TEMPORAL_ID, ///< feedback temporal id for application layer 155 DECODER_OPTION_FRAME_NUM, ///< feedback current decoded frame number 156 DECODER_OPTION_IDR_PIC_ID, ///< feedback current frame belong to which IDR period 157 DECODER_OPTION_LTR_MARKING_FLAG, ///< feedback wether current frame mark a LTR 158 DECODER_OPTION_LTR_MARKED_FRAME_NUM, ///< feedback frame num marked by current Frame 159 DECODER_OPTION_ERROR_CON_IDC, ///< indicate decoder error concealment method 160 DECODER_OPTION_TRACE_LEVEL, 161 DECODER_OPTION_TRACE_CALLBACK, ///< a void (*)(void* context, int level, const char* message) function which receives log messages 162 DECODER_OPTION_TRACE_CALLBACK_CONTEXT,///< context info of trace callbac 163 164 DECODER_OPTION_GET_STATISTICS, ///< feedback decoder statistics 165 DECODER_OPTION_GET_SAR_INFO, ///< feedback decoder Sample Aspect Ratio info in Vui 166 DECODER_OPTION_PROFILE, ///< get current AU profile info, only is used in GetOption 167 DECODER_OPTION_LEVEL, ///< get current AU level info,only is used in GetOption 168 DECODER_OPTION_STATISTICS_LOG_INTERVAL,///< set log output interval 169 DECODER_OPTION_IS_REF_PIC, ///< feedback current frame is ref pic or not 170 DECODER_OPTION_NUM_OF_FRAMES_REMAINING_IN_BUFFER, ///< number of frames remaining in decoder buffer when pictures are required to re-ordered into display-order. 171 DECODER_OPTION_NUM_OF_THREADS, ///< number of decoding threads. The maximum thread count is equal or less than lesser of (cpu core counts and 16). 172 } DECODER_OPTION; 173 174 /** 175 * @brief Enumerate the type of error concealment methods 176 */ 177 typedef enum { 178 ERROR_CON_DISABLE = 0, 179 ERROR_CON_FRAME_COPY, 180 ERROR_CON_SLICE_COPY, 181 ERROR_CON_FRAME_COPY_CROSS_IDR, 182 ERROR_CON_SLICE_COPY_CROSS_IDR, 183 ERROR_CON_SLICE_COPY_CROSS_IDR_FREEZE_RES_CHANGE, 184 ERROR_CON_SLICE_MV_COPY_CROSS_IDR, 185 ERROR_CON_SLICE_MV_COPY_CROSS_IDR_FREEZE_RES_CHANGE 186 } ERROR_CON_IDC; 187 /** 188 * @brief Feedback that whether or not have VCL NAL in current AU 189 */ 190 typedef enum { 191 FEEDBACK_NON_VCL_NAL = 0, 192 FEEDBACK_VCL_NAL, 193 FEEDBACK_UNKNOWN_NAL 194 } FEEDBACK_VCL_NAL_IN_AU; 195 196 /** 197 * @brief Type of layer being encoded 198 */ 199 typedef enum { 200 NON_VIDEO_CODING_LAYER = 0, 201 VIDEO_CODING_LAYER = 1 202 } LAYER_TYPE; 203 204 /** 205 * @brief Spatial layer num 206 */ 207 typedef enum { 208 SPATIAL_LAYER_0 = 0, 209 SPATIAL_LAYER_1 = 1, 210 SPATIAL_LAYER_2 = 2, 211 SPATIAL_LAYER_3 = 3, 212 SPATIAL_LAYER_ALL = 4 213 } LAYER_NUM; 214 215 /** 216 * @brief Enumerate the type of video bitstream which is provided to decoder 217 */ 218 typedef enum { 219 VIDEO_BITSTREAM_AVC = 0, 220 VIDEO_BITSTREAM_SVC = 1, 221 VIDEO_BITSTREAM_DEFAULT = VIDEO_BITSTREAM_SVC 222 } VIDEO_BITSTREAM_TYPE; 223 224 /** 225 * @brief Enumerate the type of key frame request 226 */ 227 typedef enum { 228 NO_RECOVERY_REQUSET = 0, 229 LTR_RECOVERY_REQUEST = 1, 230 IDR_RECOVERY_REQUEST = 2, 231 NO_LTR_MARKING_FEEDBACK = 3, 232 LTR_MARKING_SUCCESS = 4, 233 LTR_MARKING_FAILED = 5 234 } KEY_FRAME_REQUEST_TYPE; 235 236 /** 237 * @brief Structure for LTR recover request 238 */ 239 typedef struct { 240 unsigned int uiFeedbackType; ///< IDR request or LTR recovery request 241 unsigned int uiIDRPicId; ///< distinguish request from different IDR 242 int iLastCorrectFrameNum; 243 int iCurrentFrameNum; ///< specify current decoder frame_num. 244 int iLayerId; //specify the layer for recovery request 245 } SLTRRecoverRequest; 246 247 /** 248 * @brief Structure for LTR marking feedback 249 */ 250 typedef struct { 251 unsigned int uiFeedbackType; ///< mark failed or successful 252 unsigned int uiIDRPicId; ///< distinguish request from different IDR 253 int iLTRFrameNum; ///< specify current decoder frame_num 254 int iLayerId; //specify the layer for LTR marking feedback 255 } SLTRMarkingFeedback; 256 257 /** 258 * @brief Structure for LTR configuration 259 */ 260 typedef struct { 261 bool bEnableLongTermReference; ///< 1: on, 0: off 262 int iLTRRefNum; ///< TODO: not supported to set it arbitrary yet 263 } SLTRConfig; 264 265 /** 266 * @brief Enumerate the type of rate control mode 267 */ 268 typedef enum { 269 RC_QUALITY_MODE = 0, ///< quality mode 270 RC_BITRATE_MODE = 1, ///< bitrate mode 271 RC_BUFFERBASED_MODE = 2, ///< no bitrate control,only using buffer status,adjust the video quality 272 RC_TIMESTAMP_MODE = 3, //rate control based timestamp 273 RC_BITRATE_MODE_POST_SKIP = 4, ///< this is in-building RC MODE, WILL BE DELETED after algorithm tuning! 274 RC_OFF_MODE = -1, ///< rate control off mode 275 } RC_MODES; 276 277 /** 278 * @brief Enumerate the type of profile id 279 */ 280 typedef enum { 281 PRO_UNKNOWN = 0, 282 PRO_BASELINE = 66, 283 PRO_MAIN = 77, 284 PRO_EXTENDED = 88, 285 PRO_HIGH = 100, 286 PRO_HIGH10 = 110, 287 PRO_HIGH422 = 122, 288 PRO_HIGH444 = 144, 289 PRO_CAVLC444 = 244, 290 291 PRO_SCALABLE_BASELINE = 83, 292 PRO_SCALABLE_HIGH = 86 293 } EProfileIdc; 294 295 /** 296 * @brief Enumerate the type of level id 297 */ 298 typedef enum { 299 LEVEL_UNKNOWN = 0, 300 LEVEL_1_0 = 10, 301 LEVEL_1_B = 9, 302 LEVEL_1_1 = 11, 303 LEVEL_1_2 = 12, 304 LEVEL_1_3 = 13, 305 LEVEL_2_0 = 20, 306 LEVEL_2_1 = 21, 307 LEVEL_2_2 = 22, 308 LEVEL_3_0 = 30, 309 LEVEL_3_1 = 31, 310 LEVEL_3_2 = 32, 311 LEVEL_4_0 = 40, 312 LEVEL_4_1 = 41, 313 LEVEL_4_2 = 42, 314 LEVEL_5_0 = 50, 315 LEVEL_5_1 = 51, 316 LEVEL_5_2 = 52 317 } ELevelIdc; 318 319 /** 320 * @brief Enumerate the type of wels log 321 */ 322 enum { 323 WELS_LOG_QUIET = 0x00, ///< quiet mode 324 WELS_LOG_ERROR = 1 << 0, ///< error log iLevel 325 WELS_LOG_WARNING = 1 << 1, ///< Warning log iLevel 326 WELS_LOG_INFO = 1 << 2, ///< information log iLevel 327 WELS_LOG_DEBUG = 1 << 3, ///< debug log, critical algo log 328 WELS_LOG_DETAIL = 1 << 4, ///< per packet/frame log 329 WELS_LOG_RESV = 1 << 5, ///< resversed log iLevel 330 WELS_LOG_LEVEL_COUNT = 6, 331 WELS_LOG_DEFAULT = WELS_LOG_WARNING ///< default log iLevel in Wels codec 332 }; 333 334 /** 335 * @brief Enumerate the type of slice mode 336 */ 337 typedef enum { 338 SM_SINGLE_SLICE = 0, ///< | SliceNum==1 339 SM_FIXEDSLCNUM_SLICE = 1, ///< | according to SliceNum | enabled dynamic slicing for multi-thread 340 SM_RASTER_SLICE = 2, ///< | according to SlicesAssign | need input of MB numbers each slice. In addition, if other constraint in SSliceArgument is presented, need to follow the constraints. Typically if MB num and slice size are both constrained, re-encoding may be involved. 341 SM_SIZELIMITED_SLICE = 3, ///< | according to SliceSize | slicing according to size, the slicing will be dynamic(have no idea about slice_nums until encoding current frame) 342 SM_RESERVED = 4 343 } SliceModeEnum; 344 345 /** 346 * @brief Structure for slice argument 347 */ 348 typedef struct { 349 SliceModeEnum uiSliceMode; ///< by default, uiSliceMode will be SM_SINGLE_SLICE 350 unsigned int 351 uiSliceNum; ///< only used when uiSliceMode=1, when uiSliceNum=0 means auto design it with cpu core number 352 unsigned int 353 uiSliceMbNum[MAX_SLICES_NUM_TMP]; ///< only used when uiSliceMode=2; when =0 means setting one MB row a slice 354 unsigned int uiSliceSizeConstraint; ///< now only used when uiSliceMode=4 355 } SSliceArgument; 356 357 /** 358 * @brief Enumerate the type of video format 359 */ 360 typedef enum { 361 VF_COMPONENT, 362 VF_PAL, 363 VF_NTSC, 364 VF_SECAM, 365 VF_MAC, 366 VF_UNDEF, 367 VF_NUM_ENUM 368 } EVideoFormatSPS; // EVideoFormat is already defined/used elsewhere! 369 370 /** 371 * @brief Enumerate the type of color primaries 372 */ 373 typedef enum { 374 CP_RESERVED0, 375 CP_BT709, 376 CP_UNDEF, 377 CP_RESERVED3, 378 CP_BT470M, 379 CP_BT470BG, 380 CP_SMPTE170M, 381 CP_SMPTE240M, 382 CP_FILM, 383 CP_BT2020, 384 CP_NUM_ENUM 385 } EColorPrimaries; 386 387 /** 388 * @brief Enumerate the type of transfer characteristics 389 */ 390 typedef enum { 391 TRC_RESERVED0, 392 TRC_BT709, 393 TRC_UNDEF, 394 TRC_RESERVED3, 395 TRC_BT470M, 396 TRC_BT470BG, 397 TRC_SMPTE170M, 398 TRC_SMPTE240M, 399 TRC_LINEAR, 400 TRC_LOG100, 401 TRC_LOG316, 402 TRC_IEC61966_2_4, 403 TRC_BT1361E, 404 TRC_IEC61966_2_1, 405 TRC_BT2020_10, 406 TRC_BT2020_12, 407 TRC_NUM_ENUM 408 } ETransferCharacteristics; 409 410 /** 411 * @brief Enumerate the type of color matrix 412 */ 413 typedef enum { 414 CM_GBR, 415 CM_BT709, 416 CM_UNDEF, 417 CM_RESERVED3, 418 CM_FCC, 419 CM_BT470BG, 420 CM_SMPTE170M, 421 CM_SMPTE240M, 422 CM_YCGCO, 423 CM_BT2020NC, 424 CM_BT2020C, 425 CM_NUM_ENUM 426 } EColorMatrix; 427 428 429 /** 430 * @brief Enumerate the type of sample aspect ratio 431 */ 432 typedef enum { 433 ASP_UNSPECIFIED = 0, 434 ASP_1x1 = 1, 435 ASP_12x11 = 2, 436 ASP_10x11 = 3, 437 ASP_16x11 = 4, 438 ASP_40x33 = 5, 439 ASP_24x11 = 6, 440 ASP_20x11 = 7, 441 ASP_32x11 = 8, 442 ASP_80x33 = 9, 443 ASP_18x11 = 10, 444 ASP_15x11 = 11, 445 ASP_64x33 = 12, 446 ASP_160x99 = 13, 447 448 ASP_EXT_SAR = 255 449 } ESampleAspectRatio; 450 451 452 /** 453 * @brief Structure for spatial layer configuration 454 */ 455 typedef struct { 456 int iVideoWidth; ///< width of picture in luminance samples of a layer 457 int iVideoHeight; ///< height of picture in luminance samples of a layer 458 float fFrameRate; ///< frame rate specified for a layer 459 int iSpatialBitrate; ///< target bitrate for a spatial layer, in unit of bps 460 int iMaxSpatialBitrate; ///< maximum bitrate for a spatial layer, in unit of bps 461 EProfileIdc uiProfileIdc; ///< value of profile IDC (PRO_UNKNOWN for auto-detection) 462 ELevelIdc uiLevelIdc; ///< value of profile IDC (0 for auto-detection) 463 int iDLayerQp; ///< value of level IDC (0 for auto-detection) 464 465 SSliceArgument sSliceArgument; 466 467 // Note: members bVideoSignalTypePresent through uiColorMatrix below are also defined in SWelsSPS in parameter_sets.h. 468 bool bVideoSignalTypePresent; // false => do not write any of the following information to the header 469 unsigned char 470 uiVideoFormat; // EVideoFormatSPS; 3 bits in header; 0-5 => component, kpal, ntsc, secam, mac, undef 471 bool bFullRange; // false => analog video data range [16, 235]; true => full data range [0,255] 472 bool bColorDescriptionPresent; // false => do not write any of the following three items to the header 473 unsigned char 474 uiColorPrimaries; // EColorPrimaries; 8 bits in header; 0 - 9 => ???, bt709, undef, ???, bt470m, bt470bg, 475 // smpte170m, smpte240m, film, bt2020 476 unsigned char 477 uiTransferCharacteristics; // ETransferCharacteristics; 8 bits in header; 0 - 15 => ???, bt709, undef, ???, bt470m, bt470bg, smpte170m, 478 // smpte240m, linear, log100, log316, iec61966-2-4, bt1361e, iec61966-2-1, bt2020-10, bt2020-12 479 unsigned char 480 uiColorMatrix; // EColorMatrix; 8 bits in header (corresponds to FFmpeg "colorspace"); 0 - 10 => GBR, bt709, 481 // undef, ???, fcc, bt470bg, smpte170m, smpte240m, YCgCo, bt2020nc, bt2020c 482 483 bool bAspectRatioPresent; ///< aspect ratio present in VUI 484 ESampleAspectRatio eAspectRatio; ///< aspect ratio idc 485 unsigned short sAspectRatioExtWidth; ///< use if aspect ratio idc == 255 486 unsigned short sAspectRatioExtHeight; ///< use if aspect ratio idc == 255 487 488 } SSpatialLayerConfig; 489 490 /** 491 * @brief Encoder usage type 492 */ 493 typedef enum { 494 CAMERA_VIDEO_REAL_TIME, ///< camera video for real-time communication 495 SCREEN_CONTENT_REAL_TIME, ///< screen content signal 496 CAMERA_VIDEO_NON_REAL_TIME, 497 SCREEN_CONTENT_NON_REAL_TIME, 498 INPUT_CONTENT_TYPE_ALL, 499 } EUsageType; 500 501 /** 502 * @brief Enumulate the complexity mode 503 */ 504 typedef enum { 505 LOW_COMPLEXITY = 0, ///< the lowest compleixty,the fastest speed, 506 MEDIUM_COMPLEXITY, ///< medium complexity, medium speed,medium quality 507 HIGH_COMPLEXITY ///< high complexity, lowest speed, high quality 508 } ECOMPLEXITY_MODE; 509 510 /** 511 * @brief Enumulate for the stategy of SPS/PPS strategy 512 */ 513 typedef enum { 514 CONSTANT_ID = 0, ///< constant id in SPS/PPS 515 INCREASING_ID = 0x01, ///< SPS/PPS id increases at each IDR 516 SPS_LISTING = 0x02, ///< using SPS in the existing list if possible 517 SPS_LISTING_AND_PPS_INCREASING = 0x03, 518 SPS_PPS_LISTING = 0x06, 519 } EParameterSetStrategy; 520 521 // TODO: Refine the parameters definition. 522 /** 523 * @brief SVC Encoding Parameters 524 */ 525 typedef struct TagEncParamBase { 526 EUsageType 527 iUsageType; ///< application type; please refer to the definition of EUsageType 528 529 int iPicWidth; ///< width of picture in luminance samples (the maximum of all layers if multiple spatial layers presents) 530 int iPicHeight; ///< height of picture in luminance samples((the maximum of all layers if multiple spatial layers presents) 531 int iTargetBitrate; ///< target bitrate desired, in unit of bps 532 RC_MODES iRCMode; ///< rate control mode 533 float fMaxFrameRate; ///< maximal input frame rate 534 535 } SEncParamBase, *PEncParamBase; 536 537 /** 538 * @brief SVC Encoding Parameters extention 539 */ 540 typedef struct TagEncParamExt { 541 EUsageType 542 iUsageType; ///< same as in TagEncParamBase 543 544 int iPicWidth; ///< same as in TagEncParamBase 545 int iPicHeight; ///< same as in TagEncParamBase 546 int iTargetBitrate; ///< same as in TagEncParamBase 547 RC_MODES iRCMode; ///< same as in TagEncParamBase 548 float fMaxFrameRate; ///< same as in TagEncParamBase 549 550 int iTemporalLayerNum; ///< temporal layer number, max temporal layer = 4 551 int iSpatialLayerNum; ///< spatial layer number,1<= iSpatialLayerNum <= MAX_SPATIAL_LAYER_NUM, MAX_SPATIAL_LAYER_NUM = 4 552 SSpatialLayerConfig sSpatialLayers[MAX_SPATIAL_LAYER_NUM]; 553 554 ECOMPLEXITY_MODE iComplexityMode; 555 unsigned int uiIntraPeriod; ///< period of Intra frame 556 int iNumRefFrame; ///< number of reference frame used 557 EParameterSetStrategy 558 eSpsPpsIdStrategy; ///< different stategy in adjust ID in SPS/PPS: 0- constant ID, 1-additional ID, 6-mapping and additional 559 bool bPrefixNalAddingCtrl; ///< false:not use Prefix NAL; true: use Prefix NAL 560 bool bEnableSSEI; ///< false:not use SSEI; true: use SSEI -- TODO: planning to remove the interface of SSEI 561 bool bSimulcastAVC; ///< (when encoding more than 1 spatial layer) false: use SVC syntax for higher layers; true: use Simulcast AVC 562 int iPaddingFlag; ///< 0:disable padding;1:padding 563 int iEntropyCodingModeFlag; ///< 0:CAVLC 1:CABAC. 564 565 /* rc control */ 566 bool bEnableFrameSkip; ///< False: don't skip frame even if VBV buffer overflow.True: allow skipping frames to keep the bitrate within limits 567 int iMaxBitrate; ///< the maximum bitrate, in unit of bps, set it to UNSPECIFIED_BIT_RATE if not needed 568 int iMaxQp; ///< the maximum QP encoder supports 569 int iMinQp; ///< the minmum QP encoder supports 570 unsigned int uiMaxNalSize; ///< the maximum NAL size. This value should be not 0 for dynamic slice mode 571 572 /*LTR settings*/ 573 bool bEnableLongTermReference; ///< 1: on, 0: off 574 int iLTRRefNum; ///< the number of LTR(long term reference),TODO: not supported to set it arbitrary yet 575 unsigned int iLtrMarkPeriod; ///< the LTR marked period that is used in feedback. 576 /* multi-thread settings*/ 577 unsigned short 578 iMultipleThreadIdc; ///< 1 # 0: auto(dynamic imp. internal encoder); 1: multiple threads imp. disabled; lager than 1: count number of threads; 579 bool bUseLoadBalancing; ///< only used when uiSliceMode=1 or 3, will change slicing of a picture during the run-time of multi-thread encoding, so the result of each run may be different 580 581 /* Deblocking loop filter */ 582 int iLoopFilterDisableIdc; ///< 0: on, 1: off, 2: on except for slice boundaries 583 int iLoopFilterAlphaC0Offset; ///< AlphaOffset: valid range [-6, 6], default 0 584 int iLoopFilterBetaOffset; ///< BetaOffset: valid range [-6, 6], default 0 585 /*pre-processing feature*/ 586 bool bEnableDenoise; ///< denoise control 587 bool bEnableBackgroundDetection; ///< background detection control //VAA_BACKGROUND_DETECTION //BGD cmd 588 bool bEnableAdaptiveQuant; ///< adaptive quantization control 589 bool bEnableFrameCroppingFlag; ///< enable frame cropping flag: TRUE always in application 590 bool bEnableSceneChangeDetect; 591 592 bool bIsLosslessLink; ///< LTR advanced setting 593 } SEncParamExt; 594 595 /** 596 * @brief Define a new struct to show the property of video bitstream. 597 */ 598 typedef struct { 599 unsigned int size; ///< size of the struct 600 VIDEO_BITSTREAM_TYPE eVideoBsType; ///< video stream type (AVC/SVC) 601 } SVideoProperty; 602 603 /** 604 * @brief SVC Decoding Parameters, reserved here and potential applicable in the future 605 */ 606 typedef struct TagSVCDecodingParam { 607 char* pFileNameRestructed; ///< file name of reconstructed frame used for PSNR calculation based debug 608 609 unsigned int uiCpuLoad; ///< CPU load 610 unsigned char uiTargetDqLayer; ///< setting target dq layer id 611 612 ERROR_CON_IDC eEcActiveIdc; ///< whether active error concealment feature in decoder 613 bool bParseOnly; ///< decoder for parse only, no reconstruction. When it is true, SPS/PPS size should not exceed SPS_PPS_BS_SIZE (128). Otherwise, it will return error info 614 615 SVideoProperty sVideoProperty; ///< video stream property 616 } SDecodingParam, *PDecodingParam; 617 618 /** 619 * @brief Bitstream inforamtion of a layer being encoded 620 */ 621 typedef struct { 622 unsigned char uiTemporalId; 623 unsigned char uiSpatialId; 624 unsigned char uiQualityId; 625 EVideoFrameType eFrameType; 626 unsigned char uiLayerType; 627 628 /** 629 * The sub sequence layers are ordered hierarchically based on their dependency on each other so that any picture in a layer shall not be 630 * predicted from any picture on any higher layer. 631 */ 632 int iSubSeqId; ///< refer to D.2.11 Sub-sequence information SEI message semantics 633 int iNalCount; ///< count number of NAL coded already 634 int* pNalLengthInByte; ///< length of NAL size in byte from 0 to iNalCount-1 635 unsigned char* pBsBuf; ///< buffer of bitstream contained 636 } SLayerBSInfo, *PLayerBSInfo; 637 638 /** 639 * @brief Frame bit stream info 640 */ 641 typedef struct { 642 int iLayerNum; 643 SLayerBSInfo sLayerInfo[MAX_LAYER_NUM_OF_FRAME]; 644 645 EVideoFrameType eFrameType; 646 int iFrameSizeInBytes; 647 long long uiTimeStamp; 648 } SFrameBSInfo, *PFrameBSInfo; 649 650 /** 651 * @brief Structure for source picture 652 */ 653 typedef struct Source_Picture_s { 654 int iColorFormat; ///< color space type 655 int iStride[4]; ///< stride for each plane pData 656 unsigned char* pData[4]; ///< plane pData 657 int iPicWidth; ///< luma picture width in x coordinate 658 int iPicHeight; ///< luma picture height in y coordinate 659 long long uiTimeStamp; ///< timestamp of the source picture, unit: millisecond 660 } SSourcePicture; 661 /** 662 * @brief Structure for bit rate info 663 */ 664 typedef struct TagBitrateInfo { 665 LAYER_NUM iLayer; 666 int iBitrate; ///< the maximum bitrate 667 } SBitrateInfo; 668 669 /** 670 * @brief Structure for dump layer info 671 */ 672 typedef struct TagDumpLayer { 673 int iLayer; 674 char* pFileName; 675 } SDumpLayer; 676 677 /** 678 * @brief Structure for profile info in layer 679 * 680 */ 681 typedef struct TagProfileInfo { 682 int iLayer; 683 EProfileIdc uiProfileIdc; ///< the profile info 684 } SProfileInfo; 685 686 /** 687 * @brief Structure for level info in layer 688 * 689 */ 690 typedef struct TagLevelInfo { 691 int iLayer; 692 ELevelIdc uiLevelIdc; ///< the level info 693 } SLevelInfo; 694 /** 695 * @brief Structure for dilivery status 696 * 697 */ 698 typedef struct TagDeliveryStatus { 699 bool bDeliveryFlag; ///< 0: the previous frame isn't delivered,1: the previous frame is delivered 700 int iDropFrameType; ///< the frame type that is dropped; reserved 701 int iDropFrameSize; ///< the frame size that is dropped; reserved 702 } SDeliveryStatus; 703 704 /** 705 * @brief The capability of decoder, for SDP negotiation 706 */ 707 typedef struct TagDecoderCapability { 708 int iProfileIdc; ///< profile_idc 709 int iProfileIop; ///< profile-iop 710 int iLevelIdc; ///< level_idc 711 int iMaxMbps; ///< max-mbps 712 int iMaxFs; ///< max-fs 713 int iMaxCpb; ///< max-cpb 714 int iMaxDpb; ///< max-dpb 715 int iMaxBr; ///< max-br 716 bool bRedPicCap; ///< redundant-pic-cap 717 } SDecoderCapability; 718 719 /** 720 * @brief Structure for parse only output 721 */ 722 typedef struct TagParserBsInfo { 723 int iNalNum; ///< total NAL number in current AU 724 int* pNalLenInByte; ///< each nal length 725 unsigned char* pDstBuff; ///< outputted dst buffer for parsed bitstream 726 int iSpsWidthInPixel; ///< required SPS width info 727 int iSpsHeightInPixel; ///< required SPS height info 728 unsigned long long uiInBsTimeStamp; ///< input BS timestamp 729 unsigned long long uiOutBsTimeStamp; ///< output BS timestamp 730 } SParserBsInfo, *PParserBsInfo; 731 732 /** 733 * @brief Structure for encoder statistics 734 */ 735 typedef struct TagVideoEncoderStatistics { 736 unsigned int uiWidth; ///< the width of encoded frame 737 unsigned int uiHeight; ///< the height of encoded frame 738 //following standard, will be 16x aligned, if there are multiple spatial, this is of the highest 739 float fAverageFrameSpeedInMs; ///< average_Encoding_Time 740 741 // rate control related 742 float fAverageFrameRate; ///< the average frame rate in, calculate since encoding starts, supposed that the input timestamp is in unit of ms 743 float fLatestFrameRate; ///< the frame rate in, in the last second, supposed that the input timestamp is in unit of ms (? useful for checking BR, but is it easy to calculate? 744 unsigned int uiBitRate; ///< sendrate in Bits per second, calculated within the set time-window 745 unsigned int uiAverageFrameQP; ///< the average QP of last encoded frame 746 747 unsigned int uiInputFrameCount; ///< number of frames 748 unsigned int uiSkippedFrameCount; ///< number of frames 749 750 unsigned int uiResolutionChangeTimes; ///< uiResolutionChangeTimes 751 unsigned int uiIDRReqNum; ///< number of IDR requests 752 unsigned int uiIDRSentNum; ///< number of actual IDRs sent 753 unsigned int uiLTRSentNum; ///< number of LTR sent/marked 754 755 long long iStatisticsTs; ///< Timestamp of updating the statistics 756 757 unsigned long iTotalEncodedBytes; 758 unsigned long iLastStatisticsBytes; 759 unsigned long iLastStatisticsFrameCount; 760 } SEncoderStatistics; 761 762 /** 763 * @brief Structure for decoder statistics 764 */ 765 typedef struct TagVideoDecoderStatistics { 766 unsigned int uiWidth; ///< the width of encode/decode frame 767 unsigned int uiHeight; ///< the height of encode/decode frame 768 float fAverageFrameSpeedInMs; ///< average_Decoding_Time 769 float fActualAverageFrameSpeedInMs; ///< actual average_Decoding_Time, including freezing pictures 770 unsigned int uiDecodedFrameCount; ///< number of frames 771 unsigned int uiResolutionChangeTimes; ///< uiResolutionChangeTimes 772 unsigned int uiIDRCorrectNum; ///< number of correct IDR received 773 //EC on related 774 unsigned int 775 uiAvgEcRatio; ///< when EC is on, the average ratio of total EC areas, can be an indicator of reconstruction quality 776 unsigned int 777 uiAvgEcPropRatio; ///< when EC is on, the rough average ratio of propogate EC areas, can be an indicator of reconstruction quality 778 unsigned int uiEcIDRNum; ///< number of actual unintegrity IDR or not received but eced 779 unsigned int uiEcFrameNum; ///< 780 unsigned int uiIDRLostNum; ///< number of whole lost IDR 781 unsigned int 782 uiFreezingIDRNum; ///< number of freezing IDR with error (partly received), under resolution change 783 unsigned int uiFreezingNonIDRNum; ///< number of freezing non-IDR with error 784 int iAvgLumaQp; ///< average luma QP. default: -1, no correct frame outputted 785 int iSpsReportErrorNum; ///< number of Sps Invalid report 786 int iSubSpsReportErrorNum; ///< number of SubSps Invalid report 787 int iPpsReportErrorNum; ///< number of Pps Invalid report 788 int iSpsNoExistNalNum; ///< number of Sps NoExist Nal 789 int iSubSpsNoExistNalNum; ///< number of SubSps NoExist Nal 790 int iPpsNoExistNalNum; ///< number of Pps NoExist Nal 791 792 unsigned int uiProfile; ///< Profile idc in syntax 793 unsigned int uiLevel; ///< level idc according to Annex A-1 794 795 int iCurrentActiveSpsId; ///< current active SPS id 796 int iCurrentActivePpsId; ///< current active PPS id 797 798 unsigned int iStatisticsLogInterval; ///< frame interval of statistics log 799 } SDecoderStatistics; // in building, coming soon 800 801 /** 802 * @brief Structure for sample aspect ratio (SAR) info in VUI 803 */ 804 typedef struct TagVuiSarInfo { 805 unsigned int uiSarWidth; ///< SAR width 806 unsigned int uiSarHeight; ///< SAR height 807 bool bOverscanAppropriateFlag; ///< SAR overscan flag 808 } SVuiSarInfo, *PVuiSarInfo; 809 810 #endif//WELS_VIDEO_CODEC_APPLICATION_DEFINITION_H__ 811