rk_venc_cmd.h 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578
  1. /*
  2. * Copyright 2015 Rockchip Electronics Co. LTD
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef __RK_VENC_CMD_H__
  17. #define __RK_VENC_CMD_H__
  18. #include "mpp_frame.h"
  19. #include "rk_venc_rc.h"
  20. /*
  21. * Configure of encoder is very complicated. So we divide configures into
  22. * four parts:
  23. *
  24. * 1. Rate control parameter
  25. * This is quality and bitrate request from user.
  26. *
  27. * 2. Data source MppFrame parameter
  28. * This is data source buffer information.
  29. * Now it is PreP config
  30. * PreP : Encoder Preprocess configuration
  31. *
  32. * 3. Video codec infomation
  33. * This is user custormized stream information.
  34. * including:
  35. * H.264 / H.265 / vp8 / mjpeg
  36. *
  37. * 4. Misc parameter
  38. * including:
  39. * Split : Slice split configuration
  40. * GopRef: Reference gop configuration
  41. * ROI : Region Of Interest
  42. * OSD : On Screen Display
  43. * MD : Motion Detection
  44. *
  45. * The module transcation flow is as follows:
  46. *
  47. * + +
  48. * User | Mpi/Mpp | EncImpl
  49. * | | Hal
  50. * | |
  51. * +----------+ | +---------+ | +-----------+
  52. * | | | | +-----RcCfg-----> |
  53. * | RcCfg +---------> | | | EncImpl |
  54. * | | | | | +-Frame-----> |
  55. * +----------+ | | | | | +--+-----^--+
  56. * | | | | | | |
  57. * | | | | | | |
  58. * +----------+ | | | | | syntax |
  59. * | | | | | | | | |
  60. * | MppFrame +---------> MppEnc +---+ | | result
  61. * | | | | | | | | |
  62. * +----------+ | | | | | | |
  63. * | | | | | +--v-----+--+
  64. * | | | +-Frame-----> |
  65. * +----------+ | | | | | |
  66. * | | | | +---CodecCfg----> Hal |
  67. * | CodecCfg +---------> | | | |
  68. * | | | | <-----Extra-----> |
  69. * +----------+ | +---------+ | +-----------+
  70. * | |
  71. * | |
  72. * + +
  73. *
  74. * The function call flow is shown below:
  75. *
  76. * mpi mpp_enc controller hal
  77. * + + + +
  78. * | | | |
  79. * | | | |
  80. * +----------init------------> | |
  81. * | | | |
  82. * | | | |
  83. * | PrepCfg | | |
  84. * +---------control----------> PrepCfg | |
  85. * | +-----control-----> |
  86. * | | | PrepCfg |
  87. * | +--------------------------control-------->
  88. * | | | allocate
  89. * | | | buffer
  90. * | | | |
  91. * | RcCfg | | |
  92. * +---------control----------> RcCfg | |
  93. * | +-----control-----> |
  94. * | | rc_init |
  95. * | | | |
  96. * | | | |
  97. * | CodecCfg | | |
  98. * +---------control----------> | CodecCfg |
  99. * | +--------------------------control-------->
  100. * | | | generate
  101. * | | | sps/pps
  102. * | | | Get extra info |
  103. * | +--------------------------control-------->
  104. * | Get extra info | | |
  105. * +---------control----------> | |
  106. * | | | |
  107. * | | | |
  108. * | ROICfg | | |
  109. * +---------control----------> | ROICfg |
  110. * | +--------------------------control-------->
  111. * | | | |
  112. * | OSDCfg | | |
  113. * +---------control----------> | OSDCfg |
  114. * | +--------------------------control-------->
  115. * | | | |
  116. * | MDCfg | | |
  117. * +---------control----------> | MDCfg |
  118. * | +--------------------------control-------->
  119. * | | | |
  120. * | Set extra info | | |
  121. * +---------control----------> | Set extra info |
  122. * | +--------------------------control-------->
  123. * | | | |
  124. * | task | | |
  125. * +----------encode----------> task | |
  126. * | +-----encode------> |
  127. * | | encode |
  128. * | | | syntax |
  129. * | +--------------------------gen_reg-------->
  130. * | | | |
  131. * | | | |
  132. * | +---------------------------start--------->
  133. * | | | |
  134. * | | | |
  135. * | +---------------------------wait---------->
  136. * | | | |
  137. * | | callback | |
  138. * | +-----------------> |
  139. * +--OSD-MD--encode----------> | |
  140. * | . | | |
  141. * | . | | |
  142. * | . | | |
  143. * +--OSD-MD--encode----------> | |
  144. * | | | |
  145. * +----------deinit----------> | |
  146. * + + + +
  147. */
  148. /*
  149. * encoder query interface is only for debug usage
  150. */
  151. #define MPP_ENC_QUERY_STATUS (0x00000001)
  152. #define MPP_ENC_QUERY_WAIT (0x00000002)
  153. #define MPP_ENC_QUERY_FPS (0x00000004)
  154. #define MPP_ENC_QUERY_BPS (0x00000008)
  155. #define MPP_ENC_QUERY_ENC_IN_FRM (0x00000010)
  156. #define MPP_ENC_QUERY_ENC_WORK (0x00000020)
  157. #define MPP_ENC_QUERY_ENC_OUT_PKT (0x00000040)
  158. #define MPP_ENC_QUERY_ALL (MPP_ENC_QUERY_STATUS | \
  159. MPP_ENC_QUERY_WAIT | \
  160. MPP_ENC_QUERY_FPS | \
  161. MPP_ENC_QUERY_BPS | \
  162. MPP_ENC_QUERY_ENC_IN_FRM | \
  163. MPP_ENC_QUERY_ENC_WORK | \
  164. MPP_ENC_QUERY_ENC_OUT_PKT)
  165. typedef struct MppEncQueryCfg_t {
  166. /*
  167. * 32 bit query flag for query data check
  168. * Each bit represent a query data switch.
  169. * bit 0 - for querying encoder runtime status
  170. * bit 1 - for querying encoder runtime waiting status
  171. * bit 2 - for querying encoder realtime encode fps
  172. * bit 3 - for querying encoder realtime output bps
  173. * bit 4 - for querying encoder input frame count
  174. * bit 5 - for querying encoder start hardware times
  175. * bit 6 - for querying encoder output packet count
  176. */
  177. RK_U32 query_flag;
  178. /* 64 bit query data output */
  179. RK_U32 rt_status;
  180. RK_U32 rt_wait;
  181. RK_U32 rt_fps;
  182. RK_U32 rt_bps;
  183. RK_U32 enc_in_frm_cnt;
  184. RK_U32 enc_hw_run_cnt;
  185. RK_U32 enc_out_pkt_cnt;
  186. } MppEncQueryCfg;
  187. /*
  188. * base working mode parameter
  189. */
  190. typedef enum MppEncBaseCfgChange_e {
  191. MPP_ENC_BASE_CFG_CHANGE_LOW_DELAY = (1 << 0),
  192. MPP_ENC_BASE_CFG_CHANGE_ALL = (0xFFFFFFFF),
  193. } MppEncBaseCfgChange;
  194. typedef struct MppEncBaseCfg_t {
  195. RK_U32 change;
  196. RK_S32 low_delay;
  197. } MppEncBaseCfg;
  198. /*
  199. * Rate control parameter
  200. */
  201. typedef enum MppEncRcCfgChange_e {
  202. MPP_ENC_RC_CFG_CHANGE_RC_MODE = (1 << 0),
  203. MPP_ENC_RC_CFG_CHANGE_QUALITY = (1 << 1),
  204. MPP_ENC_RC_CFG_CHANGE_BPS = (1 << 2), /* change on bps target / max / min */
  205. MPP_ENC_RC_CFG_CHANGE_FPS_IN = (1 << 5), /* change on fps in flex / numerator / denominator */
  206. MPP_ENC_RC_CFG_CHANGE_FPS_OUT = (1 << 6), /* change on fps out flex / numerator / denominator */
  207. MPP_ENC_RC_CFG_CHANGE_GOP = (1 << 7),
  208. MPP_ENC_RC_CFG_CHANGE_SKIP_CNT = (1 << 8),
  209. MPP_ENC_RC_CFG_CHANGE_MAX_REENC = (1 << 9),
  210. MPP_ENC_RC_CFG_CHANGE_DROP_FRM = (1 << 10),
  211. MPP_ENC_RC_CFG_CHANGE_MAX_I_PROP = (1 << 11),
  212. MPP_ENC_RC_CFG_CHANGE_MIN_I_PROP = (1 << 12),
  213. MPP_ENC_RC_CFG_CHANGE_INIT_IP_RATIO = (1 << 13),
  214. MPP_ENC_RC_CFG_CHANGE_PRIORITY = (1 << 14),
  215. MPP_ENC_RC_CFG_CHANGE_SUPER_FRM = (1 << 15),
  216. /* qp related change flag */
  217. MPP_ENC_RC_CFG_CHANGE_QP_INIT = (1 << 16),
  218. MPP_ENC_RC_CFG_CHANGE_QP_RANGE = (1 << 17),
  219. MPP_ENC_RC_CFG_CHANGE_QP_RANGE_I = (1 << 18),
  220. MPP_ENC_RC_CFG_CHANGE_QP_MAX_STEP = (1 << 19),
  221. MPP_ENC_RC_CFG_CHANGE_QP_IP = (1 << 20),
  222. MPP_ENC_RC_CFG_CHANGE_QP_VI = (1 << 21),
  223. MPP_ENC_RC_CFG_CHANGE_QP_ROW = (1 << 22),
  224. MPP_ENC_RC_CFG_CHANGE_QP_ROW_I = (1 << 23),
  225. MPP_ENC_RC_CFG_CHANGE_DEBREATH = (1 << 24),
  226. MPP_ENC_RC_CFG_CHANGE_HIER_QP = (1 << 25),
  227. MPP_ENC_RC_CFG_CHANGE_ST_TIME = (1 << 26),
  228. MPP_ENC_RC_CFG_CHANGE_REFRESH = (1 << 27),
  229. MPP_ENC_RC_CFG_CHANGE_GOP_REF_CFG = (1 << 28),
  230. MPP_ENC_RC_CFG_CHANGE_FQP = (1 << 29),
  231. MPP_ENC_RC_CFG_CHANGE_ALL = (0xFFFFFFFF),
  232. } MppEncRcCfgChange;
  233. typedef enum MppEncRcQuality_e {
  234. MPP_ENC_RC_QUALITY_WORST,
  235. MPP_ENC_RC_QUALITY_WORSE,
  236. MPP_ENC_RC_QUALITY_MEDIUM,
  237. MPP_ENC_RC_QUALITY_BETTER,
  238. MPP_ENC_RC_QUALITY_BEST,
  239. MPP_ENC_RC_QUALITY_CQP,
  240. MPP_ENC_RC_QUALITY_AQ_ONLY,
  241. MPP_ENC_RC_QUALITY_BUTT
  242. } MppEncRcQuality;
  243. typedef struct MppEncRcCfg_t {
  244. RK_U32 change;
  245. /*
  246. * rc_mode - rate control mode
  247. *
  248. * mpp provide two rate control mode:
  249. *
  250. * Constant Bit Rate (CBR) mode
  251. * - paramter 'bps*' define target bps
  252. * - paramter quality and qp will not take effect
  253. *
  254. * Variable Bit Rate (VBR) mode
  255. * - paramter 'quality' define 5 quality levels
  256. * - paramter 'bps*' is used as reference but not strict condition
  257. * - special Constant QP (CQP) mode is under VBR mode
  258. * CQP mode will work with qp in CodecCfg. But only use for test
  259. *
  260. * default: CBR
  261. */
  262. MppEncRcMode rc_mode;
  263. /*
  264. * quality - quality parameter, only takes effect in VBR mode
  265. *
  266. * Mpp does not give the direct parameter in different protocol.
  267. *
  268. * Mpp provide total 5 quality level:
  269. * Worst - worse - Medium - better - best
  270. *
  271. * extra CQP level means special constant-qp (CQP) mode
  272. *
  273. * default value: Medium
  274. */
  275. MppEncRcQuality quality;
  276. /*
  277. * bit rate parameters
  278. * mpp gives three bit rate control parameter for control
  279. * bps_target - target bit rate, unit: bit per second
  280. * bps_max - maximun bit rate, unit: bit per second
  281. * bps_min - minimun bit rate, unit: bit per second
  282. * if user need constant bit rate set parameters to the similar value
  283. * if user need variable bit rate set parameters as they need
  284. */
  285. RK_S32 bps_target;
  286. RK_S32 bps_max;
  287. RK_S32 bps_min;
  288. /*
  289. * frame rate parameters have great effect on rate control
  290. *
  291. * fps_in_flex
  292. * 0 - fix input frame rate
  293. * 1 - variable input frame rate
  294. *
  295. * fps_in_num
  296. * input frame rate numerator, if 0 then default 30
  297. *
  298. * fps_in_denom
  299. * input frame rate denominator, if 0 then default 1
  300. *
  301. * fps_out_flex
  302. * 0 - fix output frame rate
  303. * 1 - variable output frame rate
  304. *
  305. * fps_out_num
  306. * output frame rate numerator, if 0 then default 30
  307. *
  308. * fps_out_denom
  309. * output frame rate denominator, if 0 then default 1
  310. */
  311. RK_S32 fps_in_flex;
  312. RK_S32 fps_in_num;
  313. RK_S32 fps_in_denom;
  314. RK_S32 fps_out_flex;
  315. RK_S32 fps_out_num;
  316. RK_S32 fps_out_denom;
  317. /*
  318. * Whether to encoder IDR when fps_out is changed.
  319. * 0 -- default value, SPS, PPS headers and IDR will be added.
  320. * 1 -- only SPS, PPS headers is added.
  321. */
  322. RK_S32 fps_chg_no_idr;
  323. /*
  324. * gop - group of picture, gap between Intra frame
  325. * 0 for only 1 I frame the rest are all P frames
  326. * 1 for all I frame
  327. * 2 for I P I P I P
  328. * 3 for I P P I P P
  329. * etc...
  330. */
  331. RK_S32 gop;
  332. void *ref_cfg;
  333. /*
  334. * skip_cnt - max continuous frame skip count
  335. * 0 - frame skip is not allow
  336. */
  337. RK_S32 skip_cnt;
  338. /*
  339. * max_reenc_times - max reencode time for one frame
  340. * 0 - reencode is not allowed
  341. * 1~3 max reencode time is limited to 3
  342. */
  343. RK_U32 max_reenc_times;
  344. /*
  345. * stats_time - the time of bitrate statistics
  346. */
  347. RK_S32 stats_time;
  348. /*
  349. * drop frame parameters
  350. * used on bitrate is far over the max bitrate
  351. *
  352. * drop_mode
  353. *
  354. * MPP_ENC_RC_DROP_FRM_DISABLED
  355. * - do not drop frame when bitrate overflow.
  356. * MPP_ENC_RC_DROP_FRM_NORMAL
  357. * - do not encode the dropped frame when bitrate overflow.
  358. * MPP_ENC_RC_DROP_FRM_PSKIP
  359. * - encode a all skip frame when bitrate overflow.
  360. *
  361. * drop_threshold
  362. *
  363. * The percentage threshold over max_bitrate for trigger frame drop.
  364. *
  365. * drop_gap
  366. * The max continuous frame drop number
  367. */
  368. MppEncRcDropFrmMode drop_mode;
  369. RK_U32 drop_threshold;
  370. RK_U32 drop_gap;
  371. MppEncRcSuperFrameMode super_mode;
  372. RK_U32 super_i_thd;
  373. RK_U32 super_p_thd;
  374. MppEncRcPriority rc_priority;
  375. RK_U32 debreath_en;
  376. RK_U32 debre_strength;
  377. RK_S32 max_i_prop;
  378. RK_S32 min_i_prop;
  379. RK_S32 init_ip_ratio;
  380. /* general qp control */
  381. RK_S32 qp_init;
  382. RK_S32 qp_max;
  383. RK_S32 qp_max_i;
  384. RK_S32 qp_min;
  385. RK_S32 qp_min_i;
  386. RK_S32 qp_max_step; /* delta qp between each two P frame */
  387. RK_S32 qp_delta_ip; /* delta qp between I and P */
  388. RK_S32 qp_delta_vi; /* delta qp between vi and P */
  389. RK_S32 fqp_min_i;
  390. RK_S32 fqp_min_p;
  391. RK_S32 fqp_max_i;
  392. RK_S32 fqp_max_p;
  393. RK_S32 mt_st_swth_frm_qp;
  394. RK_S32 hier_qp_en;
  395. RK_S32 hier_qp_delta[4];
  396. RK_S32 hier_frame_num[4];
  397. RK_U32 refresh_en;
  398. MppEncRcRefreshMode refresh_mode;
  399. RK_U32 refresh_num;
  400. RK_S32 refresh_length;
  401. } MppEncRcCfg;
  402. typedef enum MppEncHwCfgChange_e {
  403. /* qp related hardware config flag */
  404. MPP_ENC_HW_CFG_CHANGE_QP_ROW = (1 << 0),
  405. MPP_ENC_HW_CFG_CHANGE_QP_ROW_I = (1 << 1),
  406. MPP_ENC_HW_CFG_CHANGE_AQ_THRD_I = (1 << 2),
  407. MPP_ENC_HW_CFG_CHANGE_AQ_THRD_P = (1 << 3),
  408. MPP_ENC_HW_CFG_CHANGE_AQ_STEP_I = (1 << 4),
  409. MPP_ENC_HW_CFG_CHANGE_AQ_STEP_P = (1 << 5),
  410. MPP_ENC_HW_CFG_CHANGE_MB_RC = (1 << 6),
  411. MPP_ENC_HW_CFG_CHANGE_CU_MODE_BIAS = (1 << 8),
  412. MPP_ENC_HW_CFG_CHANGE_CU_SKIP_BIAS = (1 << 9),
  413. MPP_ENC_HW_CFG_CHANGE_QBIAS_I = (1 << 10),
  414. MPP_ENC_HW_CFG_CHANGE_QBIAS_P = (1 << 11),
  415. MPP_ENC_HW_CFG_CHANGE_QBIAS_EN = (1 << 12),
  416. MPP_ENC_HW_CFG_CHANGE_AQ_RNGE_ARR = (1 << 13),
  417. MPP_ENC_HW_CFG_CHANGE_QBIAS_ARR = (1 << 14),
  418. MPP_ENC_HW_CFG_CHANGE_FLT_STR_I = (1 << 15),
  419. MPP_ENC_HW_CFG_CHANGE_FLT_STR_P = (1 << 16),
  420. MPP_ENC_HW_CFG_CHANGE_ALL = (0xFFFFFFFF),
  421. } MppEncHwCfgChange;
  422. /*
  423. * Hardware related rate control config
  424. *
  425. * This config will open some detail feature to external user to control
  426. * hardware behavior directly.
  427. */
  428. typedef struct MppEncHwCfg_t {
  429. RK_U32 change;
  430. /* vepu541/vepu540 */
  431. RK_S32 qp_delta_row; /* delta qp between two row in P frame */
  432. RK_S32 qp_delta_row_i; /* delta qp between two row in I frame */
  433. RK_S32 qbias_i;
  434. RK_S32 qbias_p;
  435. RK_S32 qbias_en;
  436. RK_S32 flt_str_i;
  437. RK_S32 flt_str_p;
  438. RK_U32 aq_thrd_i[16];
  439. RK_U32 aq_thrd_p[16];
  440. RK_S32 aq_step_i[16];
  441. RK_S32 aq_step_p[16];
  442. /* vepu1/2 */
  443. RK_S32 mb_rc_disable;
  444. /* vepu580 */
  445. RK_S32 extra_buf;
  446. /*
  447. * block mode decision bias config
  448. * 0 - intra32x32
  449. * 1 - intra16x16
  450. * 2 - intra8x8
  451. * 3 - intra4x4
  452. * 4 - inter64x64
  453. * 5 - inter32x32
  454. * 6 - inter16x16
  455. * 7 - inter8x8
  456. * value range 0 ~ 15, default : 8
  457. * If the value is smaller then encoder will be more likely to encode corresponding block mode.
  458. */
  459. RK_S32 mode_bias[8];
  460. /*
  461. * skip mode bias config
  462. * skip_bias_en - enable flag for skip bias config
  463. * skip_sad - sad threshold for skip / non-skip
  464. * skip_bias - tendency for skip, value range 0 ~ 15, default : 8
  465. * If the value is smaller then encoder will be more likely to encode skip block.
  466. */
  467. RK_S32 skip_bias_en;
  468. RK_S32 skip_sad;
  469. RK_S32 skip_bias;
  470. /* vepu500
  471. * 0-2: I frame thd; 3-6: I frame bias
  472. * 7-9: P frame thd; 10-13: I block bias of P frame
  473. * 14-17: P block bias of P frame
  474. */
  475. RK_S32 qbias_arr[18];
  476. /* vepu500
  477. * 0: aq16_range; 1: aq32_range; 2: aq8_range
  478. * 3: aq16_diff0; 4: aq16_diff1
  479. * 0 ~ 4 for I frame, 5 ~ 9 for P frame
  480. */
  481. RK_S32 aq_rnge_arr[10];
  482. } MppEncHwCfg;
  483. /*
  484. * Mpp preprocess parameter
  485. */
  486. typedef enum MppEncPrepCfgChange_e {
  487. MPP_ENC_PREP_CFG_CHANGE_INPUT = (1 << 0), /* change on input config */
  488. MPP_ENC_PREP_CFG_CHANGE_FORMAT = (1 << 2), /* change on format */
  489. /* transform parameter */
  490. MPP_ENC_PREP_CFG_CHANGE_ROTATION = (1 << 4), /* change on rotation */
  491. MPP_ENC_PREP_CFG_CHANGE_MIRRORING = (1 << 5), /* change on mirroring */
  492. MPP_ENC_PREP_CFG_CHANGE_FLIP = (1 << 6), /* change on flip */
  493. /* enhancement parameter */
  494. MPP_ENC_PREP_CFG_CHANGE_DENOISE = (1 << 8), /* change on denoise */
  495. MPP_ENC_PREP_CFG_CHANGE_SHARPEN = (1 << 9), /* change on denoise */
  496. /* color related parameter */
  497. MPP_ENC_PREP_CFG_CHANGE_COLOR_RANGE = (1 << 16), /* change on color range */
  498. MPP_ENC_PREP_CFG_CHANGE_COLOR_SPACE = (1 << 17), /* change on color range */
  499. MPP_ENC_PREP_CFG_CHANGE_COLOR_PRIME = (1 << 18), /* change on color primaries */
  500. MPP_ENC_PREP_CFG_CHANGE_COLOR_TRC = (1 << 19), /* change on color transfer */
  501. MPP_ENC_PREP_CFG_CHANGE_ALL = (0xFFFFFFFF),
  502. } MppEncPrepCfgChange;
  503. /*
  504. * Preprocess sharpen parameter
  505. *
  506. * 5x5 sharpen core
  507. *
  508. * enable_y - enable luma sharpen
  509. * enable_uv - enable chroma sharpen
  510. */
  511. typedef struct {
  512. RK_U32 enable_y;
  513. RK_U32 enable_uv;
  514. RK_S32 coef[5];
  515. RK_S32 div;
  516. RK_S32 threshold;
  517. } MppEncPrepSharpenCfg;
  518. /*
  519. * input frame rotation parameter
  520. * 0 - disable rotation
  521. * 1 - 90 degree
  522. * 2 - 180 degree
  523. * 3 - 270 degree
  524. */
  525. typedef enum MppEncRotationCfg_e {
  526. MPP_ENC_ROT_0,
  527. MPP_ENC_ROT_90,
  528. MPP_ENC_ROT_180,
  529. MPP_ENC_ROT_270,
  530. MPP_ENC_ROT_BUTT
  531. } MppEncRotationCfg;
  532. typedef struct MppEncPrepCfg_t {
  533. RK_U32 change;
  534. /*
  535. * Mpp encoder input data dimension config
  536. *
  537. * width / height / hor_stride / ver_stride / format
  538. * These information will be used for buffer allocation and rc config init
  539. * The output format is always YUV420. So if input is RGB then color
  540. * conversion will be done internally
  541. */
  542. RK_S32 width;
  543. RK_S32 height;
  544. RK_S32 hor_stride;
  545. RK_S32 ver_stride;
  546. RK_S32 max_width;
  547. RK_S32 max_height;
  548. /*
  549. * Mpp encoder input/output color config
  550. */
  551. MppFrameFormat format;
  552. MppFrameColorSpace color;
  553. MppFrameColorPrimaries colorprim;
  554. MppFrameColorTransferCharacteristic colortrc;
  555. MppFrameColorRange range;
  556. MppFrameChromaFormat format_out;
  557. MppFrameChromaDownSampleMode chroma_ds_mode;
  558. MppFrameColorRange range_out;
  559. RK_S32 fix_chroma_en;
  560. RK_S32 fix_chroma_u;
  561. RK_S32 fix_chroma_v;
  562. /* suffix ext means the user set config externally */
  563. MppEncRotationCfg rotation;
  564. MppEncRotationCfg rotation_ext;
  565. /*
  566. * input frame mirroring parameter
  567. * 0 - disable mirroring
  568. * 1 - horizontal mirroring
  569. */
  570. RK_S32 mirroring;
  571. RK_S32 mirroring_ext;
  572. /*
  573. * input frame flip parameter
  574. * 0 - disable flip
  575. * 1 - flip, vertical mirror transformation
  576. */
  577. RK_S32 flip;
  578. /*
  579. * TODO:
  580. */
  581. RK_S32 denoise;
  582. MppEncPrepSharpenCfg sharpen;
  583. } MppEncPrepCfg;
  584. /*
  585. * Mpp Motion Detection parameter
  586. *
  587. * Mpp can output Motion Detection infomation for each frame.
  588. * If user euqueue a encode task with KEY_MOTION_INFO by following function
  589. * then encoder will output Motion Detection information to the buffer.
  590. *
  591. * mpp_task_meta_set_buffer(task, KEY_MOTION_INFO, buffer);
  592. *
  593. * Motion Detection information will be organized in this way:
  594. * 1. Each 16x16 block will have a 32 bit block information which contains
  595. * 15 bit SAD(Sum of Abstract Difference value
  596. * 9 bit signed horizontal motion vector
  597. * 8 bit signed vertical motion vector
  598. * 2. The sequence of MD information in the buffer is corresponding to the
  599. * block position in the frame, left-to right, top-to-bottom.
  600. * 3. If the width of the frame is not a multiple of 256 pixels (16 macro
  601. * blocks), DMA would extend the frame to a multiple of 256 pixels and
  602. * the extended blocks' MD information are 32'h0000_0000.
  603. * 4. Buffer must be ion buffer and 1024 byte aligned.
  604. */
  605. typedef struct MppEncMDBlkInfo_t {
  606. RK_U32 sad : 15; /* bit 0~14 - SAD */
  607. RK_S32 mvx : 9; /* bit 15~23 - signed horizontal mv */
  608. RK_S32 mvy : 8; /* bit 24~31 - signed vertical mv */
  609. } MppEncMDBlkInfo;
  610. typedef enum MppEncHeaderMode_e {
  611. /* default mode: attach vps/sps/pps only on first frame */
  612. MPP_ENC_HEADER_MODE_DEFAULT,
  613. /* IDR mode: attach vps/sps/pps on each IDR frame */
  614. MPP_ENC_HEADER_MODE_EACH_IDR,
  615. MPP_ENC_HEADER_MODE_BUTT,
  616. } MppEncHeaderMode;
  617. typedef enum MppEncSeiMode_e {
  618. MPP_ENC_SEI_MODE_DISABLE, /* default mode, SEI writing is disabled */
  619. MPP_ENC_SEI_MODE_ONE_SEQ, /* one sequence has only one SEI */
  620. MPP_ENC_SEI_MODE_ONE_FRAME /* one frame may have one SEI, if SEI info has changed */
  621. } MppEncSeiMode;
  622. /*
  623. * Mpp codec parameter
  624. * parameter is defined from here
  625. */
  626. /*
  627. * H.264 configurable parameter
  628. */
  629. typedef enum MppEncH264CfgChange_e {
  630. /* change on stream type */
  631. MPP_ENC_H264_CFG_STREAM_TYPE = (1 << 0),
  632. /* change on svc / profile / level */
  633. MPP_ENC_H264_CFG_CHANGE_PROFILE = (1 << 1),
  634. /* change on entropy_coding_mode / cabac_init_idc */
  635. MPP_ENC_H264_CFG_CHANGE_ENTROPY = (1 << 2),
  636. /* change on transform8x8_mode */
  637. MPP_ENC_H264_CFG_CHANGE_TRANS_8x8 = (1 << 4),
  638. /* change on constrained_intra_pred_mode */
  639. MPP_ENC_H264_CFG_CHANGE_CONST_INTRA = (1 << 5),
  640. /* change on chroma_cb_qp_offset/ chroma_cr_qp_offset */
  641. MPP_ENC_H264_CFG_CHANGE_CHROMA_QP = (1 << 6),
  642. /* change on deblock_disable / deblock_offset_alpha / deblock_offset_beta */
  643. MPP_ENC_H264_CFG_CHANGE_DEBLOCKING = (1 << 7),
  644. /* change on use_longterm */
  645. MPP_ENC_H264_CFG_CHANGE_LONG_TERM = (1 << 8),
  646. /* change on scaling_list_mode */
  647. MPP_ENC_H264_CFG_CHANGE_SCALING_LIST = (1 << 9),
  648. /* change on poc type */
  649. MPP_ENC_H264_CFG_CHANGE_POC_TYPE = (1 << 10),
  650. /* change on log2 max poc lsb minus 4 */
  651. MPP_ENC_H264_CFG_CHANGE_MAX_POC_LSB = (1 << 11),
  652. /* change on log2 max frame number minus 4 */
  653. MPP_ENC_H264_CFG_CHANGE_MAX_FRM_NUM = (1 << 12),
  654. /* change on gaps_in_frame_num_value_allowed_flag */
  655. MPP_ENC_H264_CFG_CHANGE_GAPS_IN_FRM_NUM = (1 << 13),
  656. /* change on max_qp / min_qp */
  657. MPP_ENC_H264_CFG_CHANGE_QP_LIMIT = (1 << 16),
  658. /* change on max_qp_i / min_qp_i */
  659. MPP_ENC_H264_CFG_CHANGE_QP_LIMIT_I = (1 << 17),
  660. /* change on max_qp_step */
  661. MPP_ENC_H264_CFG_CHANGE_MAX_QP_STEP = (1 << 18),
  662. /* change on qp_delta_ip */
  663. MPP_ENC_H264_CFG_CHANGE_QP_DELTA = (1 << 19),
  664. /* change on intra_refresh_mode / intra_refresh_arg */
  665. MPP_ENC_H264_CFG_CHANGE_INTRA_REFRESH = (1 << 20),
  666. /* change on max long-term reference frame count */
  667. MPP_ENC_H264_CFG_CHANGE_MAX_LTR = (1 << 21),
  668. /* change on max temporal id */
  669. MPP_ENC_H264_CFG_CHANGE_MAX_TID = (1 << 22),
  670. /* change on adding prefix nal */
  671. MPP_ENC_H264_CFG_CHANGE_ADD_PREFIX = (1 << 23),
  672. /* change on base layer priority id */
  673. MPP_ENC_H264_CFG_CHANGE_BASE_LAYER_PID = (1 << 24),
  674. /* change on vui */
  675. MPP_ENC_H264_CFG_CHANGE_VUI = (1 << 28),
  676. /* change on constraint */
  677. MPP_ENC_H264_CFG_CHANGE_CONSTRAINT_SET = (1 << 29),
  678. MPP_ENC_H264_CFG_CHANGE_ALL = (0xFFFFFFFF),
  679. } MppEncH264CfgChange;
  680. /* default H.264 hardware config */
  681. typedef struct MppEncH264HwCfg_t {
  682. /*
  683. * VEPU 1/2 : 2
  684. * others : 0
  685. */
  686. RK_U32 hw_poc_type;
  687. /*
  688. * VEPU 1/2 : fixed to 12
  689. * others : changeable, default 12
  690. */
  691. RK_U32 hw_log2_max_frame_num_minus4;
  692. /* default 0, only RKVENC2 support split out */
  693. RK_U32 hw_split_out;
  694. } MppEncH264HwCfg;
  695. typedef struct MppEncH264Cfg_t {
  696. RK_U32 change;
  697. /*
  698. * H.264 stream format
  699. * 0 - H.264 Annex B: NAL unit starts with '00 00 00 01'
  700. * 1 - Plain NAL units without startcode
  701. */
  702. RK_S32 stream_type;
  703. /*
  704. * H.264 codec syntax config
  705. *
  706. * do NOT setup the three option below unless you are familiar with encoder detail
  707. * poc_type - picture order count type 0 ~ 2
  708. * log2_max_poc_lsb - used in sps with poc_type 0,
  709. * log2_max_frame_num - used in sps
  710. */
  711. RK_U32 poc_type;
  712. RK_U32 log2_max_poc_lsb;
  713. RK_U32 log2_max_frame_num; /* actually log2_max_frame_num_minus4 */
  714. RK_U32 gaps_not_allowed;
  715. MppEncH264HwCfg hw_cfg;
  716. /*
  717. * H.264 profile_idc parameter
  718. * 66 - Baseline profile
  719. * 77 - Main profile
  720. * 100 - High profile
  721. */
  722. RK_S32 profile;
  723. /*
  724. * H.264 level_idc parameter
  725. * 10 / 11 / 12 / 13 - qcif@15fps / cif@7.5fps / cif@15fps / cif@30fps
  726. * 20 / 21 / 22 - cif@30fps / half-D1@@25fps / D1@12.5fps
  727. * 30 / 31 / 32 - D1@25fps / 720p@30fps / 720p@60fps
  728. * 40 / 41 / 42 - 1080p@30fps / 1080p@30fps / 1080p@60fps
  729. * 50 / 51 / 52 - 4K@30fps
  730. */
  731. RK_S32 level;
  732. /*
  733. * H.264 entropy coding method
  734. * 0 - CAVLC
  735. * 1 - CABAC
  736. * When CABAC is select cabac_init_idc can be range 0~2
  737. */
  738. RK_S32 entropy_coding_mode;
  739. RK_S32 entropy_coding_mode_ex;
  740. RK_S32 cabac_init_idc;
  741. RK_S32 cabac_init_idc_ex;
  742. /*
  743. * 8x8 intra prediction and 8x8 transform enable flag
  744. * This flag can only be enable under High profile
  745. * 0 : disable (BP/MP)
  746. * 1 : enable (HP)
  747. */
  748. RK_S32 transform8x8_mode;
  749. RK_S32 transform8x8_mode_ex;
  750. /*
  751. * 0 : disable
  752. * 1 : enable
  753. */
  754. RK_S32 constrained_intra_pred_mode;
  755. /*
  756. * 0 : flat scaling list
  757. * 1 : default scaling list for all cases
  758. * 2 : customized scaling list (not supported)
  759. */
  760. RK_S32 scaling_list_mode;
  761. /*
  762. * chroma qp offset (-12 - 12)
  763. */
  764. RK_S32 chroma_cb_qp_offset;
  765. RK_S32 chroma_cr_qp_offset;
  766. /*
  767. * H.264 deblock filter mode flag
  768. * 0 : enable
  769. * 1 : disable
  770. * 2 : disable deblocking filter at slice boundaries
  771. *
  772. * deblock filter offset alpha (-6 - 6)
  773. * deblock filter offset beta (-6 - 6)
  774. */
  775. RK_S32 deblock_disable;
  776. RK_S32 deblock_offset_alpha;
  777. RK_S32 deblock_offset_beta;
  778. /*
  779. * H.264 long term reference picture enable flag
  780. * 0 - disable
  781. * 1 - enable
  782. */
  783. RK_S32 use_longterm;
  784. /*
  785. * quality config
  786. * qp_max - 8 ~ 51
  787. * qp_max_i - 10 ~ 40
  788. * qp_min - 8 ~ 48
  789. * qp_min_i - 10 ~ 40
  790. * qp_max_step - max delta qp step between two frames
  791. */
  792. RK_S32 qp_init;
  793. RK_S16 qp_max;
  794. RK_S16 qp_max_i;
  795. RK_S16 qp_min;
  796. RK_S16 qp_min_i;
  797. RK_S16 qp_max_step;
  798. RK_S16 qp_delta_ip;
  799. /*
  800. * intra fresh config
  801. *
  802. * intra_refresh_mode
  803. * 0 - no intra refresh
  804. * 1 - intra refresh by MB row
  805. * 2 - intra refresh by MB column
  806. * 3 - intra refresh by MB gap
  807. *
  808. * intra_refresh_arg
  809. * mode 0 - no effect
  810. * mode 1 - refresh MB row number
  811. * mode 2 - refresh MB colmn number
  812. * mode 3 - refresh MB gap count
  813. */
  814. RK_S32 intra_refresh_mode;
  815. RK_S32 intra_refresh_arg;
  816. /* extra mode config */
  817. RK_S32 max_ltr_frames;
  818. RK_S32 max_tid;
  819. RK_S32 prefix_mode;
  820. RK_S32 base_layer_pid;
  821. /*
  822. * Mpp encoder constraint_set parameter
  823. * Mpp encoder constraint_set controls constraint_setx_flag in AVC.
  824. * Mpp encoder constraint_set uses type RK_U32 to store force_flag and constraint_force as followed.
  825. * | 00 | force_flag | 00 | constraint_force |
  826. * As for force_flag and constraint_force, only low 6 bits are valid,
  827. * corresponding to constraint_setx_flag from 5 to 0.
  828. * If force_flag bit is enabled, constraint_setx_flag will be set correspondingly.
  829. * Otherwise, constraint_setx_flag will use default value.
  830. */
  831. RK_U32 constraint_set;
  832. } MppEncH264Cfg;
  833. #define H265E_MAX_ROI_NUMBER 64
  834. typedef struct H265eRect_t {
  835. RK_S32 left;
  836. RK_S32 right;
  837. RK_S32 top;
  838. RK_S32 bottom;
  839. } H265eRect;
  840. typedef struct H265eRoi_Region_t {
  841. RK_U8 level;
  842. H265eRect rect;
  843. } H265eRoiRegion;
  844. /*
  845. * roi region only can be setting when rc_enable = 1
  846. */
  847. typedef struct MppEncH265RoiCfg_t {
  848. /*
  849. * the value is defined by H265eCtuMethod
  850. */
  851. RK_U8 method;
  852. /*
  853. * the number of roi,the value must less than H265E_MAX_ROI_NUMBER
  854. */
  855. RK_S32 num;
  856. /* delat qp using in roi region*/
  857. RK_U32 delta_qp;
  858. /* roi region */
  859. H265eRoiRegion region[H265E_MAX_ROI_NUMBER];
  860. } MppEncH265RoiCfg;
  861. typedef struct H265eCtuQp_t {
  862. /* the qp value using in ctu region */
  863. RK_U32 qp;
  864. /*
  865. * define the ctu region
  866. * method = H265E_METHOD_CUT_SIZE, the value of rect is in ctu size
  867. * method = H264E_METHOD_COORDINATE,the value of rect is in coordinates
  868. */
  869. H265eRect rect;
  870. } H265eCtu;
  871. typedef struct H265eCtuRegion_t {
  872. /*
  873. * the value is defined by H265eCtuMethod
  874. */
  875. RK_U8 method;
  876. /*
  877. * the number of ctu,the value must less than H265E_MAX_ROI_NUMBER
  878. */
  879. RK_S32 num;
  880. /* ctu region */
  881. H265eCtu ctu[H265E_MAX_ROI_NUMBER];
  882. } MppEncH265CtuCfg;
  883. /*
  884. * define the method when set CTU/ROI parameters
  885. * this value is using by method in H265eCtuRegion or H265eRoi struct
  886. */
  887. typedef enum {
  888. H265E_METHOD_CTU_SIZE,
  889. H264E_METHOD_COORDINATE,
  890. } H265eCtuMethod;
  891. /*
  892. * H.265 configurable parameter
  893. */
  894. typedef struct MppEncH265VuiCfg_t {
  895. RK_U32 change;
  896. RK_S32 vui_present;
  897. RK_S32 vui_aspect_ratio;
  898. RK_S32 vui_sar_size;
  899. RK_S32 full_range;
  900. RK_S32 time_scale;
  901. } MppEncH265VuiCfg;
  902. typedef enum MppEncH265CfgChange_e {
  903. /* change on stream type */
  904. MPP_ENC_H265_CFG_PROFILE_LEVEL_TILER_CHANGE = (1 << 0),
  905. MPP_ENC_H265_CFG_INTRA_QP_CHANGE = (1 << 1),
  906. MPP_ENC_H265_CFG_FRAME_RATE_CHANGE = (1 << 2),
  907. MPP_ENC_H265_CFG_BITRATE_CHANGE = (1 << 3),
  908. MPP_ENC_H265_CFG_GOP_SIZE = (1 << 4),
  909. MPP_ENC_H265_CFG_RC_QP_CHANGE = (1 << 5),
  910. MPP_ENC_H265_CFG_INTRA_REFRESH_CHANGE = (1 << 6),
  911. MPP_ENC_H265_CFG_INDEPEND_SLICE_CHANGE = (1 << 7),
  912. MPP_ENC_H265_CFG_DEPEND_SLICE_CHANGE = (1 << 8),
  913. MPP_ENC_H265_CFG_CTU_CHANGE = (1 << 9),
  914. MPP_ENC_H265_CFG_ROI_CHANGE = (1 << 10),
  915. MPP_ENC_H265_CFG_CU_CHANGE = (1 << 11),
  916. MPP_ENC_H265_CFG_DBLK_CHANGE = (1 << 12),
  917. MPP_ENC_H265_CFG_SAO_CHANGE = (1 << 13),
  918. MPP_ENC_H265_CFG_TRANS_CHANGE = (1 << 14),
  919. MPP_ENC_H265_CFG_SLICE_CHANGE = (1 << 15),
  920. MPP_ENC_H265_CFG_ENTROPY_CHANGE = (1 << 16),
  921. MPP_ENC_H265_CFG_MERGE_CHANGE = (1 << 17),
  922. MPP_ENC_H265_CFG_CHANGE_VUI = (1 << 18),
  923. MPP_ENC_H265_CFG_RC_I_QP_CHANGE = (1 << 19),
  924. MPP_ENC_H265_CFG_RC_MAX_QP_STEP_CHANGE = (1 << 21),
  925. MPP_ENC_H265_CFG_RC_IP_DELTA_QP_CHANGE = (1 << 20),
  926. MPP_ENC_H265_CFG_TILE_CHANGE = (1 << 22),
  927. MPP_ENC_H265_CFG_SLICE_LPFACS_CHANGE = (1 << 23),
  928. MPP_ENC_H265_CFG_TILE_LPFACS_CHANGE = (1 << 24),
  929. MPP_ENC_H265_CFG_CHANGE_CONST_INTRA = (1 << 25),
  930. MPP_ENC_H265_CFG_CHANGE_LCU_SIZE = (1 << 26),
  931. MPP_ENC_H265_CFG_CHANGE_MAX_TID = (1 << 27),
  932. MPP_ENC_H265_CFG_CHANGE_MAX_LTR = (1 << 28),
  933. MPP_ENC_H265_CFG_CHANGE_BASE_LAYER_PID = (1 << 29),
  934. MPP_ENC_H265_CFG_CHANGE_ALL = (0xFFFFFFFF),
  935. } MppEncH265CfgChange;
  936. typedef struct MppEncH265SliceCfg_t {
  937. /* default value: 0, means no slice split*/
  938. RK_U32 split_enable;
  939. /* 0: by bits number; 1: by lcu line number*/
  940. RK_U32 split_mode;
  941. /*
  942. * when splitmode is 0, this value presents bits number,
  943. * when splitmode is 1, this value presents lcu line number
  944. */
  945. RK_U32 slice_size;
  946. RK_U32 slice_out;
  947. } MppEncH265SliceCfg;
  948. typedef struct MppEncH265CuCfg_t {
  949. RK_U32 cu32x32_en; /*default: 1 */
  950. RK_U32 cu16x16_en; /*default: 1 */
  951. RK_U32 cu8x8_en; /*default: 1 */
  952. RK_U32 cu4x4_en; /*default: 1 */
  953. // intra pred
  954. RK_U32 constrained_intra_pred_flag; /*default: 0 */
  955. RK_U32 strong_intra_smoothing_enabled_flag; /*INTRA_SMOOTH*/
  956. RK_U32 pcm_enabled_flag; /*default: 0, enable ipcm*/
  957. RK_U32 pcm_loop_filter_disabled_flag;
  958. } MppEncH265CuCfg;
  959. typedef struct MppEncH265RefCfg_t {
  960. RK_U32 num_lt_ref_pic; /*default: 0*/
  961. } MppEncH265RefCfg;
  962. typedef struct MppEncH265DblkCfg_t {
  963. RK_U32 slice_deblocking_filter_disabled_flag; /* default value: 0. {0,1} */
  964. RK_S32 slice_beta_offset_div2; /* default value: 0. [-6,+6] */
  965. RK_S32 slice_tc_offset_div2; /* default value: 0. [-6,+6] */
  966. } MppEncH265DblkCfg_t;
  967. typedef struct MppEncH265SaoCfg_t {
  968. RK_U32 slice_sao_luma_disable;
  969. RK_U32 slice_sao_chroma_disable;
  970. RK_U32 sao_bit_ratio;
  971. } MppEncH265SaoCfg;
  972. typedef struct MppEncH265TransCfg_t {
  973. RK_U32 transquant_bypass_enabled_flag;
  974. RK_U32 transform_skip_enabled_flag;
  975. RK_U32 defalut_ScalingList_enable; /* default: 0 */
  976. RK_S32 cb_qp_offset;
  977. RK_S32 cr_qp_offset;
  978. RK_S32 diff_cu_qp_delta_depth;
  979. } MppEncH265TransCfg;
  980. typedef struct MppEncH265MergeCfg_t {
  981. RK_U32 max_mrg_cnd;
  982. RK_U32 merge_up_flag;
  983. RK_U32 merge_left_flag;
  984. } MppEncH265MergesCfg;
  985. typedef struct MppEncH265EntropyCfg_t {
  986. RK_U32 cabac_init_flag; /* default: 0 */
  987. } MppEncH265EntropyCfg;
  988. typedef struct MppEncH265Cfg_t {
  989. RK_U32 change;
  990. /* H.265 codec syntax config */
  991. RK_S32 profile;
  992. RK_S32 level;
  993. RK_S32 tier;
  994. /* constraint intra prediction flag */
  995. RK_S32 const_intra_pred;
  996. RK_S32 ctu_size;
  997. RK_S32 max_cu_size;
  998. RK_S32 tmvp_enable;
  999. RK_S32 amp_enable;
  1000. RK_S32 wpp_enable;
  1001. RK_S32 merge_range;
  1002. RK_S32 sao_enable;
  1003. RK_U32 num_ref;
  1004. /* quality config */
  1005. RK_S32 max_qp;
  1006. RK_S32 min_qp;
  1007. RK_S32 max_i_qp;
  1008. RK_S32 min_i_qp;
  1009. RK_S32 ip_qp_delta;
  1010. RK_S32 max_delta_qp;
  1011. RK_S32 intra_qp;
  1012. RK_S32 gop_delta_qp;
  1013. RK_S32 qp_init;
  1014. RK_S32 qp_max_step;
  1015. RK_S32 raw_dealt_qp;
  1016. RK_U8 qpmax_map[8];
  1017. RK_U8 qpmin_map[8];
  1018. RK_S32 qpmap_mode;
  1019. /* intra fresh config */
  1020. RK_S32 intra_refresh_mode;
  1021. RK_S32 intra_refresh_arg;
  1022. /* extra mode config */
  1023. RK_S32 max_ltr_frames;
  1024. RK_S32 max_tid;
  1025. RK_S32 base_layer_pid;
  1026. /* slice mode config */
  1027. RK_S32 independ_slice_mode;
  1028. RK_S32 independ_slice_arg;
  1029. RK_S32 depend_slice_mode;
  1030. RK_S32 depend_slice_arg;
  1031. MppEncH265CuCfg cu_cfg;
  1032. MppEncH265SliceCfg slice_cfg;
  1033. MppEncH265EntropyCfg entropy_cfg;
  1034. MppEncH265TransCfg trans_cfg;
  1035. MppEncH265SaoCfg sao_cfg;
  1036. MppEncH265DblkCfg_t dblk_cfg;
  1037. MppEncH265RefCfg ref_cfg;
  1038. MppEncH265MergesCfg merge_cfg;
  1039. RK_S32 auto_tile;
  1040. RK_U32 lpf_acs_sli_en;
  1041. RK_U32 lpf_acs_tile_disable;
  1042. /* extra info */
  1043. MppEncH265VuiCfg vui;
  1044. MppEncH265CtuCfg ctu;
  1045. MppEncH265RoiCfg roi;
  1046. } MppEncH265Cfg;
  1047. /*
  1048. * motion jpeg configurable parameter
  1049. */
  1050. typedef enum MppEncJpegCfgChange_e {
  1051. /* change on quant parameter */
  1052. MPP_ENC_JPEG_CFG_CHANGE_QP = (1 << 0),
  1053. MPP_ENC_JPEG_CFG_CHANGE_QTABLE = (1 << 1),
  1054. MPP_ENC_JPEG_CFG_CHANGE_QFACTOR = (1 << 2),
  1055. MPP_ENC_JPEG_CFG_CHANGE_ALL = (0xFFFFFFFF),
  1056. } MppEncJpegCfgChange;
  1057. typedef struct MppEncJpegCfg_t {
  1058. RK_U32 change;
  1059. RK_S32 quant;
  1060. /*
  1061. * quality factor config
  1062. *
  1063. * q_factor - 1 ~ 99
  1064. * qf_max - 1 ~ 99
  1065. * qf_min - 1 ~ 99
  1066. * qtable_y: qtable for luma
  1067. * qtable_u: qtable for chroma
  1068. * qtable_v: default equal qtable_u
  1069. */
  1070. RK_S32 q_factor;
  1071. RK_S32 qf_max;
  1072. RK_S32 qf_min;
  1073. RK_U8 *qtable_y;
  1074. RK_U8 *qtable_u;
  1075. RK_U8 *qtable_v;
  1076. } MppEncJpegCfg;
  1077. /*
  1078. * vp8 configurable parameter
  1079. */
  1080. typedef enum MppEncVP8CfgChange_e {
  1081. MPP_ENC_VP8_CFG_CHANGE_QP = (1 << 0),
  1082. MPP_ENC_VP8_CFG_CHANGE_DIS_IVF = (1 << 1),
  1083. MPP_ENC_VP8_CFG_CHANGE_ALL = (0xFFFFFFFF),
  1084. } MppEncVP8CfgChange;
  1085. typedef struct MppEncVp8Cfg_t {
  1086. RK_U32 change;
  1087. RK_S32 quant;
  1088. RK_S32 qp_init;
  1089. RK_S32 qp_max;
  1090. RK_S32 qp_max_i;
  1091. RK_S32 qp_min;
  1092. RK_S32 qp_min_i;
  1093. RK_S32 qp_max_step;
  1094. RK_S32 disable_ivf;
  1095. } MppEncVp8Cfg;
  1096. /**
  1097. * @ingroup rk_mpi
  1098. * @brief MPP encoder codec configuration parameters
  1099. * @details The encoder codec configuration parameters are different for each
  1100. * compression codings. For example, H.264 encoder can configure
  1101. * profile, level, qp, etc. while jpeg encoder can configure qp
  1102. * only. The detailed parameters can refer the corresponding data
  1103. * structure such as MppEncH264Cfg and MppEncJpegCfg. This data
  1104. * structure is associated with MPP_ENC_SET_CODEC_CFG command.
  1105. */
  1106. typedef struct MppEncCodecCfg_t {
  1107. MppCodingType coding;
  1108. union {
  1109. RK_U32 change;
  1110. MppEncH264Cfg h264;
  1111. MppEncH265Cfg h265;
  1112. MppEncJpegCfg jpeg;
  1113. MppEncVp8Cfg vp8;
  1114. };
  1115. } MppEncCodecCfg;
  1116. typedef enum MppEncSliceSplit_e {
  1117. /* change on quant parameter */
  1118. MPP_ENC_SPLIT_CFG_CHANGE_MODE = (1 << 0),
  1119. MPP_ENC_SPLIT_CFG_CHANGE_ARG = (1 << 1),
  1120. MPP_ENC_SPLIT_CFG_CHANGE_OUTPUT = (1 << 2),
  1121. MPP_ENC_SPLIT_CFG_CHANGE_ALL = (0xFFFFFFFF),
  1122. } MppEncSliceSplitChange;
  1123. typedef enum MppEncSplitMode_e {
  1124. MPP_ENC_SPLIT_NONE,
  1125. MPP_ENC_SPLIT_BY_BYTE,
  1126. MPP_ENC_SPLIT_BY_CTU,
  1127. } MppEncSplitMode;
  1128. typedef enum MppEncSplitOutMode_e {
  1129. MPP_ENC_SPLIT_OUT_LOWDELAY = (1 << 0),
  1130. MPP_ENC_SPLIT_OUT_SEGMENT = (1 << 1),
  1131. } MppEncSplitOutMode;
  1132. typedef struct MppEncSliceSplit_t {
  1133. RK_U32 change;
  1134. /*
  1135. * slice split mode
  1136. *
  1137. * MPP_ENC_SPLIT_NONE - No slice is split
  1138. * MPP_ENC_SPLIT_BY_BYTE - Slice is split by byte number
  1139. * MPP_ENC_SPLIT_BY_CTU - Slice is split by macroblock / ctu number
  1140. */
  1141. RK_U32 split_mode;
  1142. /*
  1143. * slice split size parameter
  1144. *
  1145. * When split by byte number this value is the max byte number for each
  1146. * slice.
  1147. * When split by macroblock / ctu number this value is the MB/CTU number
  1148. * for each slice.
  1149. */
  1150. RK_U32 split_arg;
  1151. /*
  1152. * slice split output mode
  1153. *
  1154. * MPP_ENC_SPLIT_OUT_LOWDELAY
  1155. * - When enabled encoder will lowdelay output each slice in a single packet
  1156. * MPP_ENC_SPLIT_OUT_SEGMENT
  1157. * - When enabled encoder will packet with segment info for each slice
  1158. */
  1159. RK_U32 split_out;
  1160. } MppEncSliceSplit;
  1161. /**
  1162. * @brief Mpp ROI parameter
  1163. * Region configure define a rectangle as ROI
  1164. * @note x, y, w, h are calculated in pixels, which had better be 16-pixel aligned.
  1165. * These parameters MUST retain in memory when encoder is running.
  1166. * Both absolute qp and relative qp are supported in vepu541.
  1167. * Only absolute qp is supported in rv1108
  1168. */
  1169. typedef struct MppEncROIRegion_t {
  1170. RK_U16 x; /**< horizontal position of top left corner */
  1171. RK_U16 y; /**< vertical position of top left corner */
  1172. RK_U16 w; /**< width of ROI rectangle */
  1173. RK_U16 h; /**< height of ROI rectangle */
  1174. RK_U16 intra; /**< flag of forced intra macroblock */
  1175. RK_S16 quality; /**< absolute / relative qp of macroblock */
  1176. RK_U16 qp_area_idx; /**< qp min max area select*/
  1177. RK_U8 area_map_en; /**< enable area map */
  1178. RK_U8 abs_qp_en; /**< absolute qp enable flag*/
  1179. } MppEncROIRegion;
  1180. /**
  1181. * @brief MPP encoder's ROI configuration
  1182. */
  1183. typedef struct MppEncROICfg_t {
  1184. RK_U32 number; /**< ROI rectangle number */
  1185. MppEncROIRegion *regions; /**< ROI parameters */
  1186. } MppEncROICfg;
  1187. typedef struct MppEncROICfg0_t {
  1188. RK_U32 change; /**< change flag */
  1189. RK_U32 number; /**< ROI rectangle number */
  1190. MppEncROIRegion regions[8]; /**< ROI parameters */
  1191. } MppEncROICfgLegacy;
  1192. /**
  1193. * @brief Mpp ROI parameter for vepu54x / vepu58x
  1194. * @note These encoders have more complex roi configure structure.
  1195. * User need to generate roi structure data for different soc.
  1196. * And send buffers to encoder through metadata.
  1197. */
  1198. typedef struct MppEncROICfg2_t {
  1199. MppBuffer base_cfg_buf;
  1200. MppBuffer qp_cfg_buf;
  1201. MppBuffer amv_cfg_buf;
  1202. MppBuffer mv_cfg_buf;
  1203. RK_U32 roi_qp_en : 1;
  1204. RK_U32 roi_amv_en : 1;
  1205. RK_U32 roi_mv_en : 1;
  1206. RK_U32 reserve_bits : 29;
  1207. RK_U32 reserve[3];
  1208. } MppEncROICfg2;
  1209. /*
  1210. * Mpp OSD parameter
  1211. *
  1212. * Mpp OSD support total 8 regions
  1213. * Mpp OSD support 256-color palette two mode palette:
  1214. * 1. Configurable OSD palette
  1215. * When palette is set.
  1216. * 2. fixed OSD palette
  1217. * When palette is NULL.
  1218. *
  1219. * if MppEncOSDPlt.buf != NULL , palette includes maximun 256 levels,
  1220. * every level composed of 32 bits defined below:
  1221. * Y : 8 bits
  1222. * U : 8 bits
  1223. * V : 8 bits
  1224. * alpha : 8 bits
  1225. */
  1226. #define MPP_ENC_OSD_PLT_WHITE ((255<<24)|(128<<16)|(128<<8)|235)
  1227. #define MPP_ENC_OSD_PLT_YELLOW ((255<<24)|(146<<16)|( 16<<8)|210)
  1228. #define MPP_ENC_OSD_PLT_CYAN ((255<<24)|( 16<<16)|(166<<8)|170)
  1229. #define MPP_ENC_OSD_PLT_GREEN ((255<<24)|( 34<<16)|( 54<<8)|145)
  1230. #define MPP_ENC_OSD_PLT_TRANS (( 0<<24)|(222<<16)|(202<<8)|106)
  1231. #define MPP_ENC_OSD_PLT_RED ((255<<24)|(240<<16)|( 90<<8)| 81)
  1232. #define MPP_ENC_OSD_PLT_BLUE ((255<<24)|(110<<16)|(240<<8)| 41)
  1233. #define MPP_ENC_OSD_PLT_BLACK ((255<<24)|(128<<16)|(128<<8)| 16)
  1234. typedef enum MppEncOSDPltType_e {
  1235. MPP_ENC_OSD_PLT_TYPE_DEFAULT,
  1236. MPP_ENC_OSD_PLT_TYPE_USERDEF,
  1237. MPP_ENC_OSD_PLT_TYPE_BUTT,
  1238. } MppEncOSDPltType;
  1239. /* OSD palette value define */
  1240. typedef union MppEncOSDPltVal_u {
  1241. struct {
  1242. RK_U32 v : 8;
  1243. RK_U32 u : 8;
  1244. RK_U32 y : 8;
  1245. RK_U32 alpha : 8;
  1246. };
  1247. RK_U32 val;
  1248. } MppEncOSDPltVal;
  1249. typedef struct MppEncOSDPlt_t {
  1250. MppEncOSDPltVal data[256];
  1251. } MppEncOSDPlt;
  1252. typedef enum MppEncOSDPltCfgChange_e {
  1253. MPP_ENC_OSD_PLT_CFG_CHANGE_MODE = (1 << 0), /* change osd plt type */
  1254. MPP_ENC_OSD_PLT_CFG_CHANGE_PLT_VAL = (1 << 1), /* change osd plt table value */
  1255. MPP_ENC_OSD_PLT_CFG_CHANGE_ALL = (0xFFFFFFFF),
  1256. } MppEncOSDPltCfgChange;
  1257. typedef struct MppEncOSDPltCfg_t {
  1258. RK_U32 change;
  1259. MppEncOSDPltType type;
  1260. MppEncOSDPlt *plt;
  1261. } MppEncOSDPltCfg;
  1262. /* position info is unit in 16 pixels(one MB), and
  1263. * x-directon range in pixels = (rd_pos_x - lt_pos_x + 1) * 16;
  1264. * y-directon range in pixels = (rd_pos_y - lt_pos_y + 1) * 16;
  1265. */
  1266. typedef struct MppEncOSDRegion_t {
  1267. RK_U32 enable;
  1268. RK_U32 inverse;
  1269. RK_U32 start_mb_x;
  1270. RK_U32 start_mb_y;
  1271. RK_U32 num_mb_x;
  1272. RK_U32 num_mb_y;
  1273. RK_U32 buf_offset;
  1274. } MppEncOSDRegion;
  1275. /* if num_region > 0 && region==NULL
  1276. * use old osd data
  1277. */
  1278. typedef struct MppEncOSDData_t {
  1279. MppBuffer buf;
  1280. RK_U32 num_region;
  1281. MppEncOSDRegion region[8];
  1282. } MppEncOSDData;
  1283. typedef struct MppEncOSDRegion2_t {
  1284. RK_U32 enable;
  1285. RK_U32 inverse;
  1286. RK_U32 start_mb_x;
  1287. RK_U32 start_mb_y;
  1288. RK_U32 num_mb_x;
  1289. RK_U32 num_mb_y;
  1290. RK_U32 buf_offset;
  1291. MppBuffer buf;
  1292. } MppEncOSDRegion2;
  1293. typedef struct MppEncOSDData2_t {
  1294. RK_U32 num_region;
  1295. MppEncOSDRegion2 region[8];
  1296. } MppEncOSDData2;
  1297. /* kmpp osd configure */
  1298. typedef struct MppOsdBuf_t {
  1299. RK_S32 fd;
  1300. void *buf;
  1301. } MppOsdBuf;
  1302. typedef struct EncOSDInvCfg_t {
  1303. RK_U32 yg_inv_en;
  1304. RK_U32 uvrb_inv_en;
  1305. RK_U32 alpha_inv_en;
  1306. RK_U32 inv_sel;
  1307. RK_U32 uv_sw_inv_en;
  1308. RK_U32 inv_size;
  1309. RK_U32 inv_stride;
  1310. MppOsdBuf inv_buf;
  1311. } EncOSDInvCfg;
  1312. typedef struct EncOSDAlphaCfg_t {
  1313. RK_U32 alpha_swap;
  1314. RK_U32 bg_alpha;
  1315. RK_U32 fg_alpha;
  1316. RK_U32 fg_alpha_sel;
  1317. } EncOSDAlphaCfg;
  1318. typedef struct EncOSDQpCfg_t {
  1319. RK_U32 qp_adj_en;
  1320. RK_U32 qp_adj_sel;
  1321. RK_S32 qp;
  1322. RK_U32 qp_max;
  1323. RK_U32 qp_min;
  1324. RK_U32 qp_prj;
  1325. } EncOSDQpCfg;
  1326. typedef struct MppEncOSDRegion3_t {
  1327. RK_U32 enable;
  1328. RK_U32 range_trns_en;
  1329. RK_U32 range_trns_sel;
  1330. RK_U32 fmt;
  1331. RK_U32 rbuv_swap;
  1332. RK_U32 lt_x;
  1333. RK_U32 lt_y;
  1334. RK_U32 rb_x;
  1335. RK_U32 rb_y;
  1336. RK_U32 stride;
  1337. RK_U32 ch_ds_mode;
  1338. RK_U32 osd_endn;
  1339. EncOSDInvCfg inv_cfg;
  1340. EncOSDAlphaCfg alpha_cfg;
  1341. EncOSDQpCfg qp_cfg;
  1342. MppOsdBuf osd_buf;
  1343. RK_U8 lut[8]; //vuy vuy alpha
  1344. } MppEncOSDRegion3;
  1345. typedef struct MppEncOSDData3_t {
  1346. RK_U32 change;
  1347. RK_U32 num_region;
  1348. MppEncOSDRegion3 region[8];
  1349. } MppEncOSDData3;
  1350. /* kmpp osd configure end */
  1351. typedef struct MppEncUserData_t {
  1352. RK_U32 len;
  1353. void *pdata;
  1354. } MppEncUserData;
  1355. typedef struct MppEncUserDataFull_t {
  1356. RK_U32 len;
  1357. RK_U8 *uuid;
  1358. void *pdata;
  1359. } MppEncUserDataFull;
  1360. typedef struct MppEncUserDataSet_t {
  1361. RK_U32 count;
  1362. MppEncUserDataFull *datas;
  1363. } MppEncUserDataSet;
  1364. typedef enum MppEncSceneMode_e {
  1365. MPP_ENC_SCENE_MODE_DEFAULT,
  1366. MPP_ENC_SCENE_MODE_IPC,
  1367. MPP_ENC_SCENE_MODE_IPC_PTZ,
  1368. MPP_ENC_SCENE_MODE_BUTT,
  1369. } MppEncSceneMode;
  1370. typedef enum MppEncFineTuneCfgChange_e {
  1371. /* change on scene mode */
  1372. MPP_ENC_TUNE_CFG_CHANGE_SCENE_MODE = (1 << 0),
  1373. MPP_ENC_TUNE_CFG_CHANGE_DEBLUR_EN = (1 << 1),
  1374. MPP_ENC_TUNE_CFG_CHANGE_DEBLUR_STR = (1 << 2),
  1375. MPP_ENC_TUNE_CFG_CHANGE_ANTI_FLICKER_STR = (1 << 3),
  1376. MPP_ENC_TUNE_CFG_CHANGE_LAMBDA_IDX_I = (1 << 5),
  1377. MPP_ENC_TUNE_CFG_CHANGE_LAMBDA_IDX_P = (1 << 6),
  1378. MPP_ENC_TUNE_CFG_CHANGE_ATR_STR_I = (1 << 7),
  1379. MPP_ENC_TUNE_CFG_CHANGE_ATR_STR_P = (1 << 8),
  1380. MPP_ENC_TUNE_CFG_CHANGE_ATL_STR = (1 << 9),
  1381. MPP_ENC_TUNE_CFG_CHANGE_SAO_STR_I = (1 << 10),
  1382. MPP_ENC_TUNE_CFG_CHANGE_SAO_STR_P = (1 << 11),
  1383. MPP_ENC_TUNE_CFG_CHANGE_RC_CONTAINER = (1 << 13),
  1384. MPP_ENC_TUNE_CFG_CHANGE_VMAF_OPT = (1 << 14),
  1385. MPP_ENC_TUNE_CFG_CHANGE_MOTION_STATIC_SWITCH_ENABLE = (1 << 15),
  1386. MPP_ENC_TUNE_CFG_CHANGE_ATF_STR = (1 << 16),
  1387. MPP_ENC_TUNE_CFG_CHANGE_LGT_CHG_LVL = (1 << 17),
  1388. MPP_ENC_TUNE_CFG_CHANGE_STATIC_FRM_NUM = (1 << 18),
  1389. MPP_ENC_TUNE_CFG_CHANGE_MADP16_TH = (1 << 19),
  1390. MPP_ENC_TUNE_CFG_CHANGE_SKIP16_WGT = (1 << 20),
  1391. MPP_ENC_TUNE_CFG_CHANGE_SKIP32_WGT = (1 << 21),
  1392. MPP_ENC_TUNE_CFG_CHANGE_SPEED = (1 << 22),
  1393. MPP_ENC_TUNE_CFG_CHANGE_ALL = (0xFFFFFFFF),
  1394. } MppEncFineTuneCfgChange;
  1395. typedef struct MppEncFineTuneCfg_t {
  1396. RK_U32 change;
  1397. MppEncSceneMode scene_mode;
  1398. RK_S32 deblur_en; /* qpmap_en */
  1399. RK_S32 deblur_str; /* deblur strength */
  1400. RK_S32 anti_flicker_str;
  1401. RK_S32 lambda_idx_i;
  1402. RK_S32 lambda_idx_p;
  1403. RK_S32 atr_str_i; /* line_en */
  1404. RK_S32 atr_str_p; /* line_en */
  1405. RK_S32 atl_str; /* anti_stripe */
  1406. RK_S32 sao_str_i; /* anti blur */
  1407. RK_S32 sao_str_p; /* anti blur */
  1408. RK_S32 rc_container;
  1409. RK_S32 vmaf_opt;
  1410. RK_S32 motion_static_switch_enable;
  1411. RK_S32 atf_str;
  1412. /* vepu500 only */
  1413. RK_S32 lgt_chg_lvl; /* light change level, [0, 3] */
  1414. RK_S32 static_frm_num; /* static frame number, [0, 7] */
  1415. RK_S32 madp16_th; /* madp threshold for static block detection, [0, 63] */
  1416. RK_S32 skip16_wgt; /* weight for skip16, 0 or [3, 8] */
  1417. RK_S32 skip32_wgt; /* weight for skip32, 0 or [3, 8] */
  1418. RK_S32 qpmap_en;
  1419. RK_S32 speed; /*enc speed [0..3], 0:full mode; 1:fast; 2:faster; 3:fastest */
  1420. RK_S32 reserved[4];
  1421. } MppEncFineTuneCfg;
  1422. #endif /*__RK_VENC_CMD_H__*/