codec_app_def.h 32 KB

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