vp9_cx_iface.c 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833
  1. /*
  2. * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include "./vpx_config.h"
  13. #include "vpx/vpx_encoder.h"
  14. #include "vpx_ports/vpx_once.h"
  15. #include "vpx_ports/system_state.h"
  16. #include "vpx_util/vpx_timestamp.h"
  17. #include "vpx/internal/vpx_codec_internal.h"
  18. #include "./vpx_version.h"
  19. #include "vp9/encoder/vp9_encoder.h"
  20. #include "vpx/vp8cx.h"
  21. #include "vp9/encoder/vp9_firstpass.h"
  22. #include "vp9/vp9_iface_common.h"
  23. struct vp9_extracfg {
  24. int cpu_used; // available cpu percentage in 1/16
  25. unsigned int enable_auto_alt_ref;
  26. unsigned int noise_sensitivity;
  27. unsigned int sharpness;
  28. unsigned int static_thresh;
  29. unsigned int tile_columns;
  30. unsigned int tile_rows;
  31. unsigned int enable_tpl_model;
  32. unsigned int arnr_max_frames;
  33. unsigned int arnr_strength;
  34. unsigned int min_gf_interval;
  35. unsigned int max_gf_interval;
  36. vp8e_tuning tuning;
  37. unsigned int cq_level; // constrained quality level
  38. unsigned int rc_max_intra_bitrate_pct;
  39. unsigned int rc_max_inter_bitrate_pct;
  40. unsigned int gf_cbr_boost_pct;
  41. unsigned int lossless;
  42. unsigned int target_level;
  43. unsigned int frame_parallel_decoding_mode;
  44. AQ_MODE aq_mode;
  45. int alt_ref_aq;
  46. unsigned int frame_periodic_boost;
  47. vpx_bit_depth_t bit_depth;
  48. vp9e_tune_content content;
  49. vpx_color_space_t color_space;
  50. vpx_color_range_t color_range;
  51. int render_width;
  52. int render_height;
  53. unsigned int row_mt;
  54. unsigned int motion_vector_unit_test;
  55. };
  56. static struct vp9_extracfg default_extra_cfg = {
  57. 0, // cpu_used
  58. 1, // enable_auto_alt_ref
  59. 0, // noise_sensitivity
  60. 0, // sharpness
  61. 0, // static_thresh
  62. 6, // tile_columns
  63. 0, // tile_rows
  64. 1, // enable_tpl_model
  65. 7, // arnr_max_frames
  66. 5, // arnr_strength
  67. 0, // min_gf_interval; 0 -> default decision
  68. 0, // max_gf_interval; 0 -> default decision
  69. VP8_TUNE_PSNR, // tuning
  70. 10, // cq_level
  71. 0, // rc_max_intra_bitrate_pct
  72. 0, // rc_max_inter_bitrate_pct
  73. 0, // gf_cbr_boost_pct
  74. 0, // lossless
  75. 255, // target_level
  76. 1, // frame_parallel_decoding_mode
  77. NO_AQ, // aq_mode
  78. 0, // alt_ref_aq
  79. 0, // frame_periodic_delta_q
  80. VPX_BITS_8, // Bit depth
  81. VP9E_CONTENT_DEFAULT, // content
  82. VPX_CS_UNKNOWN, // color space
  83. 0, // color range
  84. 0, // render width
  85. 0, // render height
  86. 0, // row_mt
  87. 0, // motion_vector_unit_test
  88. };
  89. struct vpx_codec_alg_priv {
  90. vpx_codec_priv_t base;
  91. vpx_codec_enc_cfg_t cfg;
  92. struct vp9_extracfg extra_cfg;
  93. vpx_rational64_t timestamp_ratio;
  94. vpx_codec_pts_t pts_offset;
  95. unsigned char pts_offset_initialized;
  96. VP9EncoderConfig oxcf;
  97. VP9_COMP *cpi;
  98. unsigned char *cx_data;
  99. size_t cx_data_sz;
  100. unsigned char *pending_cx_data;
  101. size_t pending_cx_data_sz;
  102. int pending_frame_count;
  103. size_t pending_frame_sizes[8];
  104. size_t pending_frame_magnitude;
  105. vpx_image_t preview_img;
  106. vpx_enc_frame_flags_t next_frame_flags;
  107. vp8_postproc_cfg_t preview_ppcfg;
  108. vpx_codec_pkt_list_decl(256) pkt_list;
  109. unsigned int fixed_kf_cntr;
  110. vpx_codec_priv_output_cx_pkt_cb_pair_t output_cx_pkt_cb;
  111. // BufferPool that holds all reference frames.
  112. BufferPool *buffer_pool;
  113. };
  114. static vpx_codec_err_t update_error_state(
  115. vpx_codec_alg_priv_t *ctx, const struct vpx_internal_error_info *error) {
  116. const vpx_codec_err_t res = error->error_code;
  117. if (res != VPX_CODEC_OK)
  118. ctx->base.err_detail = error->has_detail ? error->detail : NULL;
  119. return res;
  120. }
  121. #undef ERROR
  122. #define ERROR(str) \
  123. do { \
  124. ctx->base.err_detail = str; \
  125. return VPX_CODEC_INVALID_PARAM; \
  126. } while (0)
  127. #define RANGE_CHECK(p, memb, lo, hi) \
  128. do { \
  129. if (!(((p)->memb == (lo) || (p)->memb > (lo)) && (p)->memb <= (hi))) \
  130. ERROR(#memb " out of range [" #lo ".." #hi "]"); \
  131. } while (0)
  132. #define RANGE_CHECK_HI(p, memb, hi) \
  133. do { \
  134. if (!((p)->memb <= (hi))) ERROR(#memb " out of range [.." #hi "]"); \
  135. } while (0)
  136. #define RANGE_CHECK_LO(p, memb, lo) \
  137. do { \
  138. if (!((p)->memb >= (lo))) ERROR(#memb " out of range [" #lo "..]"); \
  139. } while (0)
  140. #define RANGE_CHECK_BOOL(p, memb) \
  141. do { \
  142. if (!!((p)->memb) != (p)->memb) ERROR(#memb " expected boolean"); \
  143. } while (0)
  144. #if defined(_MSC_VER)
  145. #define COMPILE_TIME_ASSERT(boolexp) \
  146. do { \
  147. char compile_time_assert[(boolexp) ? 1 : -1]; \
  148. (void)compile_time_assert; \
  149. } while (0)
  150. #else // !_MSC_VER
  151. #define COMPILE_TIME_ASSERT(boolexp) \
  152. do { \
  153. struct { \
  154. unsigned int compile_time_assert : (boolexp) ? 1 : -1; \
  155. } compile_time_assert; \
  156. (void)compile_time_assert; \
  157. } while (0)
  158. #endif // _MSC_VER
  159. static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx,
  160. const vpx_codec_enc_cfg_t *cfg,
  161. const struct vp9_extracfg *extra_cfg) {
  162. RANGE_CHECK(cfg, g_w, 1, 65535); // 16 bits available
  163. RANGE_CHECK(cfg, g_h, 1, 65535); // 16 bits available
  164. RANGE_CHECK(cfg, g_timebase.den, 1, 1000000000);
  165. RANGE_CHECK(cfg, g_timebase.num, 1, 1000000000);
  166. RANGE_CHECK_HI(cfg, g_profile, 3);
  167. RANGE_CHECK_HI(cfg, rc_max_quantizer, 63);
  168. RANGE_CHECK_HI(cfg, rc_min_quantizer, cfg->rc_max_quantizer);
  169. RANGE_CHECK_BOOL(extra_cfg, lossless);
  170. RANGE_CHECK_BOOL(extra_cfg, frame_parallel_decoding_mode);
  171. RANGE_CHECK(extra_cfg, aq_mode, 0, AQ_MODE_COUNT - 2);
  172. RANGE_CHECK(extra_cfg, alt_ref_aq, 0, 1);
  173. RANGE_CHECK(extra_cfg, frame_periodic_boost, 0, 1);
  174. RANGE_CHECK_HI(cfg, g_threads, 64);
  175. RANGE_CHECK_HI(cfg, g_lag_in_frames, MAX_LAG_BUFFERS);
  176. RANGE_CHECK(cfg, rc_end_usage, VPX_VBR, VPX_Q);
  177. RANGE_CHECK_HI(cfg, rc_undershoot_pct, 100);
  178. RANGE_CHECK_HI(cfg, rc_overshoot_pct, 100);
  179. RANGE_CHECK_HI(cfg, rc_2pass_vbr_bias_pct, 100);
  180. RANGE_CHECK(cfg, rc_2pass_vbr_corpus_complexity, 0, 10000);
  181. RANGE_CHECK(cfg, kf_mode, VPX_KF_DISABLED, VPX_KF_AUTO);
  182. RANGE_CHECK_BOOL(cfg, rc_resize_allowed);
  183. RANGE_CHECK_HI(cfg, rc_dropframe_thresh, 100);
  184. RANGE_CHECK_HI(cfg, rc_resize_up_thresh, 100);
  185. RANGE_CHECK_HI(cfg, rc_resize_down_thresh, 100);
  186. #if CONFIG_REALTIME_ONLY
  187. RANGE_CHECK(cfg, g_pass, VPX_RC_ONE_PASS, VPX_RC_ONE_PASS);
  188. #else
  189. RANGE_CHECK(cfg, g_pass, VPX_RC_ONE_PASS, VPX_RC_LAST_PASS);
  190. #endif
  191. RANGE_CHECK(extra_cfg, min_gf_interval, 0, (MAX_LAG_BUFFERS - 1));
  192. RANGE_CHECK(extra_cfg, max_gf_interval, 0, (MAX_LAG_BUFFERS - 1));
  193. if (extra_cfg->max_gf_interval > 0) {
  194. RANGE_CHECK(extra_cfg, max_gf_interval, 2, (MAX_LAG_BUFFERS - 1));
  195. }
  196. if (extra_cfg->min_gf_interval > 0 && extra_cfg->max_gf_interval > 0) {
  197. RANGE_CHECK(extra_cfg, max_gf_interval, extra_cfg->min_gf_interval,
  198. (MAX_LAG_BUFFERS - 1));
  199. }
  200. // For formation of valid ARF groups lag_in _frames should be 0 or greater
  201. // than the max_gf_interval + 2
  202. if (cfg->g_lag_in_frames > 0 && extra_cfg->max_gf_interval > 0 &&
  203. cfg->g_lag_in_frames < extra_cfg->max_gf_interval + 2) {
  204. ERROR("Set lag in frames to 0 (low delay) or >= (max-gf-interval + 2)");
  205. }
  206. if (cfg->rc_resize_allowed == 1) {
  207. RANGE_CHECK(cfg, rc_scaled_width, 0, cfg->g_w);
  208. RANGE_CHECK(cfg, rc_scaled_height, 0, cfg->g_h);
  209. }
  210. RANGE_CHECK(cfg, ss_number_layers, 1, VPX_SS_MAX_LAYERS);
  211. RANGE_CHECK(cfg, ts_number_layers, 1, VPX_TS_MAX_LAYERS);
  212. {
  213. unsigned int level = extra_cfg->target_level;
  214. if (level != LEVEL_1 && level != LEVEL_1_1 && level != LEVEL_2 &&
  215. level != LEVEL_2_1 && level != LEVEL_3 && level != LEVEL_3_1 &&
  216. level != LEVEL_4 && level != LEVEL_4_1 && level != LEVEL_5 &&
  217. level != LEVEL_5_1 && level != LEVEL_5_2 && level != LEVEL_6 &&
  218. level != LEVEL_6_1 && level != LEVEL_6_2 && level != LEVEL_UNKNOWN &&
  219. level != LEVEL_AUTO && level != LEVEL_MAX)
  220. ERROR("target_level is invalid");
  221. }
  222. if (cfg->ss_number_layers * cfg->ts_number_layers > VPX_MAX_LAYERS)
  223. ERROR("ss_number_layers * ts_number_layers is out of range");
  224. if (cfg->ts_number_layers > 1) {
  225. unsigned int sl, tl;
  226. for (sl = 1; sl < cfg->ss_number_layers; ++sl) {
  227. for (tl = 1; tl < cfg->ts_number_layers; ++tl) {
  228. const int layer = LAYER_IDS_TO_IDX(sl, tl, cfg->ts_number_layers);
  229. if (cfg->layer_target_bitrate[layer] <
  230. cfg->layer_target_bitrate[layer - 1])
  231. ERROR("ts_target_bitrate entries are not increasing");
  232. }
  233. }
  234. RANGE_CHECK(cfg, ts_rate_decimator[cfg->ts_number_layers - 1], 1, 1);
  235. for (tl = cfg->ts_number_layers - 2; tl > 0; --tl)
  236. if (cfg->ts_rate_decimator[tl - 1] != 2 * cfg->ts_rate_decimator[tl])
  237. ERROR("ts_rate_decimator factors are not powers of 2");
  238. }
  239. // VP9 does not support a lower bound on the keyframe interval in
  240. // automatic keyframe placement mode.
  241. if (cfg->kf_mode != VPX_KF_DISABLED && cfg->kf_min_dist != cfg->kf_max_dist &&
  242. cfg->kf_min_dist > 0)
  243. ERROR(
  244. "kf_min_dist not supported in auto mode, use 0 "
  245. "or kf_max_dist instead.");
  246. RANGE_CHECK(extra_cfg, row_mt, 0, 1);
  247. RANGE_CHECK(extra_cfg, motion_vector_unit_test, 0, 2);
  248. RANGE_CHECK(extra_cfg, enable_auto_alt_ref, 0, MAX_ARF_LAYERS);
  249. RANGE_CHECK(extra_cfg, cpu_used, -9, 9);
  250. RANGE_CHECK_HI(extra_cfg, noise_sensitivity, 6);
  251. RANGE_CHECK(extra_cfg, tile_columns, 0, 6);
  252. RANGE_CHECK(extra_cfg, tile_rows, 0, 2);
  253. RANGE_CHECK_HI(extra_cfg, sharpness, 7);
  254. RANGE_CHECK(extra_cfg, arnr_max_frames, 0, 15);
  255. RANGE_CHECK_HI(extra_cfg, arnr_strength, 6);
  256. RANGE_CHECK(extra_cfg, cq_level, 0, 63);
  257. RANGE_CHECK(cfg, g_bit_depth, VPX_BITS_8, VPX_BITS_12);
  258. RANGE_CHECK(cfg, g_input_bit_depth, 8, 12);
  259. RANGE_CHECK(extra_cfg, content, VP9E_CONTENT_DEFAULT,
  260. VP9E_CONTENT_INVALID - 1);
  261. #if !CONFIG_REALTIME_ONLY
  262. if (cfg->g_pass == VPX_RC_LAST_PASS) {
  263. const size_t packet_sz = sizeof(FIRSTPASS_STATS);
  264. const int n_packets = (int)(cfg->rc_twopass_stats_in.sz / packet_sz);
  265. const FIRSTPASS_STATS *stats;
  266. if (cfg->rc_twopass_stats_in.buf == NULL)
  267. ERROR("rc_twopass_stats_in.buf not set.");
  268. if (cfg->rc_twopass_stats_in.sz % packet_sz)
  269. ERROR("rc_twopass_stats_in.sz indicates truncated packet.");
  270. if (cfg->ss_number_layers > 1 || cfg->ts_number_layers > 1) {
  271. int i;
  272. unsigned int n_packets_per_layer[VPX_SS_MAX_LAYERS] = { 0 };
  273. stats = cfg->rc_twopass_stats_in.buf;
  274. for (i = 0; i < n_packets; ++i) {
  275. const int layer_id = (int)stats[i].spatial_layer_id;
  276. if (layer_id >= 0 && layer_id < (int)cfg->ss_number_layers) {
  277. ++n_packets_per_layer[layer_id];
  278. }
  279. }
  280. for (i = 0; i < (int)cfg->ss_number_layers; ++i) {
  281. unsigned int layer_id;
  282. if (n_packets_per_layer[i] < 2) {
  283. ERROR(
  284. "rc_twopass_stats_in requires at least two packets for each "
  285. "layer.");
  286. }
  287. stats = (const FIRSTPASS_STATS *)cfg->rc_twopass_stats_in.buf +
  288. n_packets - cfg->ss_number_layers + i;
  289. layer_id = (int)stats->spatial_layer_id;
  290. if (layer_id >= cfg->ss_number_layers ||
  291. (unsigned int)(stats->count + 0.5) !=
  292. n_packets_per_layer[layer_id] - 1)
  293. ERROR("rc_twopass_stats_in missing EOS stats packet");
  294. }
  295. } else {
  296. if (cfg->rc_twopass_stats_in.sz < 2 * packet_sz)
  297. ERROR("rc_twopass_stats_in requires at least two packets.");
  298. stats =
  299. (const FIRSTPASS_STATS *)cfg->rc_twopass_stats_in.buf + n_packets - 1;
  300. if ((int)(stats->count + 0.5) != n_packets - 1)
  301. ERROR("rc_twopass_stats_in missing EOS stats packet");
  302. }
  303. }
  304. #endif // !CONFIG_REALTIME_ONLY
  305. #if !CONFIG_VP9_HIGHBITDEPTH
  306. if (cfg->g_profile > (unsigned int)PROFILE_1) {
  307. ERROR("Profile > 1 not supported in this build configuration");
  308. }
  309. #endif
  310. if (cfg->g_profile <= (unsigned int)PROFILE_1 &&
  311. cfg->g_bit_depth > VPX_BITS_8) {
  312. ERROR("Codec high bit-depth not supported in profile < 2");
  313. }
  314. if (cfg->g_profile <= (unsigned int)PROFILE_1 && cfg->g_input_bit_depth > 8) {
  315. ERROR("Source high bit-depth not supported in profile < 2");
  316. }
  317. if (cfg->g_profile > (unsigned int)PROFILE_1 &&
  318. cfg->g_bit_depth == VPX_BITS_8) {
  319. ERROR("Codec bit-depth 8 not supported in profile > 1");
  320. }
  321. RANGE_CHECK(extra_cfg, color_space, VPX_CS_UNKNOWN, VPX_CS_SRGB);
  322. RANGE_CHECK(extra_cfg, color_range, VPX_CR_STUDIO_RANGE, VPX_CR_FULL_RANGE);
  323. return VPX_CODEC_OK;
  324. }
  325. static vpx_codec_err_t validate_img(vpx_codec_alg_priv_t *ctx,
  326. const vpx_image_t *img) {
  327. switch (img->fmt) {
  328. case VPX_IMG_FMT_YV12:
  329. case VPX_IMG_FMT_I420:
  330. case VPX_IMG_FMT_I42016: break;
  331. case VPX_IMG_FMT_I422:
  332. case VPX_IMG_FMT_I444:
  333. case VPX_IMG_FMT_I440:
  334. if (ctx->cfg.g_profile != (unsigned int)PROFILE_1) {
  335. ERROR(
  336. "Invalid image format. I422, I444, I440 images are "
  337. "not supported in profile.");
  338. }
  339. break;
  340. case VPX_IMG_FMT_I42216:
  341. case VPX_IMG_FMT_I44416:
  342. case VPX_IMG_FMT_I44016:
  343. if (ctx->cfg.g_profile != (unsigned int)PROFILE_1 &&
  344. ctx->cfg.g_profile != (unsigned int)PROFILE_3) {
  345. ERROR(
  346. "Invalid image format. 16-bit I422, I444, I440 images are "
  347. "not supported in profile.");
  348. }
  349. break;
  350. default:
  351. ERROR(
  352. "Invalid image format. Only YV12, I420, I422, I444 images are "
  353. "supported.");
  354. break;
  355. }
  356. if (img->d_w != ctx->cfg.g_w || img->d_h != ctx->cfg.g_h)
  357. ERROR("Image size must match encoder init configuration size");
  358. return VPX_CODEC_OK;
  359. }
  360. static int get_image_bps(const vpx_image_t *img) {
  361. switch (img->fmt) {
  362. case VPX_IMG_FMT_YV12:
  363. case VPX_IMG_FMT_I420: return 12;
  364. case VPX_IMG_FMT_I422: return 16;
  365. case VPX_IMG_FMT_I444: return 24;
  366. case VPX_IMG_FMT_I440: return 16;
  367. case VPX_IMG_FMT_I42016: return 24;
  368. case VPX_IMG_FMT_I42216: return 32;
  369. case VPX_IMG_FMT_I44416: return 48;
  370. case VPX_IMG_FMT_I44016: return 32;
  371. default: assert(0 && "Invalid image format"); break;
  372. }
  373. return 0;
  374. }
  375. // Modify the encoder config for the target level.
  376. static void config_target_level(VP9EncoderConfig *oxcf) {
  377. double max_average_bitrate; // in bits per second
  378. int max_over_shoot_pct;
  379. const int target_level_index = get_level_index(oxcf->target_level);
  380. vpx_clear_system_state();
  381. assert(target_level_index >= 0);
  382. assert(target_level_index < VP9_LEVELS);
  383. // Maximum target bit-rate is level_limit * 80%.
  384. max_average_bitrate =
  385. vp9_level_defs[target_level_index].average_bitrate * 800.0;
  386. if ((double)oxcf->target_bandwidth > max_average_bitrate)
  387. oxcf->target_bandwidth = (int64_t)(max_average_bitrate);
  388. if (oxcf->ss_number_layers == 1 && oxcf->pass != 0)
  389. oxcf->ss_target_bitrate[0] = (int)oxcf->target_bandwidth;
  390. // Adjust max over-shoot percentage.
  391. max_over_shoot_pct =
  392. (int)((max_average_bitrate * 1.10 - (double)oxcf->target_bandwidth) *
  393. 100 / (double)(oxcf->target_bandwidth));
  394. if (oxcf->over_shoot_pct > max_over_shoot_pct)
  395. oxcf->over_shoot_pct = max_over_shoot_pct;
  396. // Adjust worst allowed quantizer.
  397. oxcf->worst_allowed_q = vp9_quantizer_to_qindex(63);
  398. // Adjust minimum art-ref distance.
  399. // min_gf_interval should be no less than min_altref_distance + 1,
  400. // as the encoder may produce bitstream with alt-ref distance being
  401. // min_gf_interval - 1.
  402. if (oxcf->min_gf_interval <=
  403. (int)vp9_level_defs[target_level_index].min_altref_distance) {
  404. oxcf->min_gf_interval =
  405. (int)vp9_level_defs[target_level_index].min_altref_distance + 1;
  406. // If oxcf->max_gf_interval == 0, it will be assigned with a default value
  407. // in vp9_rc_set_gf_interval_range().
  408. if (oxcf->max_gf_interval != 0) {
  409. oxcf->max_gf_interval =
  410. VPXMAX(oxcf->max_gf_interval, oxcf->min_gf_interval);
  411. }
  412. }
  413. // Adjust maximum column tiles.
  414. if (vp9_level_defs[target_level_index].max_col_tiles <
  415. (1 << oxcf->tile_columns)) {
  416. while (oxcf->tile_columns > 0 &&
  417. vp9_level_defs[target_level_index].max_col_tiles <
  418. (1 << oxcf->tile_columns))
  419. --oxcf->tile_columns;
  420. }
  421. }
  422. static vpx_codec_err_t set_encoder_config(
  423. VP9EncoderConfig *oxcf, const vpx_codec_enc_cfg_t *cfg,
  424. const struct vp9_extracfg *extra_cfg) {
  425. const int is_vbr = cfg->rc_end_usage == VPX_VBR;
  426. int sl, tl;
  427. oxcf->profile = cfg->g_profile;
  428. oxcf->max_threads = (int)cfg->g_threads;
  429. oxcf->width = cfg->g_w;
  430. oxcf->height = cfg->g_h;
  431. oxcf->bit_depth = cfg->g_bit_depth;
  432. oxcf->input_bit_depth = cfg->g_input_bit_depth;
  433. // guess a frame rate if out of whack, use 30
  434. oxcf->init_framerate = (double)cfg->g_timebase.den / cfg->g_timebase.num;
  435. if (oxcf->init_framerate > 180) oxcf->init_framerate = 30;
  436. oxcf->mode = GOOD;
  437. switch (cfg->g_pass) {
  438. case VPX_RC_ONE_PASS: oxcf->pass = 0; break;
  439. case VPX_RC_FIRST_PASS: oxcf->pass = 1; break;
  440. case VPX_RC_LAST_PASS: oxcf->pass = 2; break;
  441. }
  442. oxcf->lag_in_frames =
  443. cfg->g_pass == VPX_RC_FIRST_PASS ? 0 : cfg->g_lag_in_frames;
  444. oxcf->rc_mode = cfg->rc_end_usage;
  445. // Convert target bandwidth from Kbit/s to Bit/s
  446. oxcf->target_bandwidth = 1000 * cfg->rc_target_bitrate;
  447. oxcf->rc_max_intra_bitrate_pct = extra_cfg->rc_max_intra_bitrate_pct;
  448. oxcf->rc_max_inter_bitrate_pct = extra_cfg->rc_max_inter_bitrate_pct;
  449. oxcf->gf_cbr_boost_pct = extra_cfg->gf_cbr_boost_pct;
  450. oxcf->best_allowed_q =
  451. extra_cfg->lossless ? 0 : vp9_quantizer_to_qindex(cfg->rc_min_quantizer);
  452. oxcf->worst_allowed_q =
  453. extra_cfg->lossless ? 0 : vp9_quantizer_to_qindex(cfg->rc_max_quantizer);
  454. oxcf->cq_level = vp9_quantizer_to_qindex(extra_cfg->cq_level);
  455. oxcf->fixed_q = -1;
  456. oxcf->under_shoot_pct = cfg->rc_undershoot_pct;
  457. oxcf->over_shoot_pct = cfg->rc_overshoot_pct;
  458. oxcf->scaled_frame_width = cfg->rc_scaled_width;
  459. oxcf->scaled_frame_height = cfg->rc_scaled_height;
  460. if (cfg->rc_resize_allowed == 1) {
  461. oxcf->resize_mode =
  462. (oxcf->scaled_frame_width == 0 || oxcf->scaled_frame_height == 0)
  463. ? RESIZE_DYNAMIC
  464. : RESIZE_FIXED;
  465. } else {
  466. oxcf->resize_mode = RESIZE_NONE;
  467. }
  468. oxcf->maximum_buffer_size_ms = is_vbr ? 240000 : cfg->rc_buf_sz;
  469. oxcf->starting_buffer_level_ms = is_vbr ? 60000 : cfg->rc_buf_initial_sz;
  470. oxcf->optimal_buffer_level_ms = is_vbr ? 60000 : cfg->rc_buf_optimal_sz;
  471. oxcf->drop_frames_water_mark = cfg->rc_dropframe_thresh;
  472. oxcf->two_pass_vbrbias = cfg->rc_2pass_vbr_bias_pct;
  473. oxcf->two_pass_vbrmin_section = cfg->rc_2pass_vbr_minsection_pct;
  474. oxcf->two_pass_vbrmax_section = cfg->rc_2pass_vbr_maxsection_pct;
  475. oxcf->vbr_corpus_complexity = cfg->rc_2pass_vbr_corpus_complexity;
  476. oxcf->auto_key =
  477. cfg->kf_mode == VPX_KF_AUTO && cfg->kf_min_dist != cfg->kf_max_dist;
  478. oxcf->key_freq = cfg->kf_max_dist;
  479. oxcf->speed = abs(extra_cfg->cpu_used);
  480. oxcf->encode_breakout = extra_cfg->static_thresh;
  481. oxcf->enable_auto_arf = extra_cfg->enable_auto_alt_ref;
  482. oxcf->noise_sensitivity = extra_cfg->noise_sensitivity;
  483. oxcf->sharpness = extra_cfg->sharpness;
  484. oxcf->two_pass_stats_in = cfg->rc_twopass_stats_in;
  485. #if CONFIG_FP_MB_STATS
  486. oxcf->firstpass_mb_stats_in = cfg->rc_firstpass_mb_stats_in;
  487. #endif
  488. oxcf->color_space = extra_cfg->color_space;
  489. oxcf->color_range = extra_cfg->color_range;
  490. oxcf->render_width = extra_cfg->render_width;
  491. oxcf->render_height = extra_cfg->render_height;
  492. oxcf->arnr_max_frames = extra_cfg->arnr_max_frames;
  493. oxcf->arnr_strength = extra_cfg->arnr_strength;
  494. oxcf->min_gf_interval = extra_cfg->min_gf_interval;
  495. oxcf->max_gf_interval = extra_cfg->max_gf_interval;
  496. oxcf->tuning = extra_cfg->tuning;
  497. oxcf->content = extra_cfg->content;
  498. oxcf->tile_columns = extra_cfg->tile_columns;
  499. oxcf->enable_tpl_model = extra_cfg->enable_tpl_model;
  500. // TODO(yunqing): The dependencies between row tiles cause error in multi-
  501. // threaded encoding. For now, tile_rows is forced to be 0 in this case.
  502. // The further fix can be done by adding synchronizations after a tile row
  503. // is encoded. But this will hurt multi-threaded encoder performance. So,
  504. // it is recommended to use tile-rows=0 while encoding with threads > 1.
  505. if (oxcf->max_threads > 1 && oxcf->tile_columns > 0)
  506. oxcf->tile_rows = 0;
  507. else
  508. oxcf->tile_rows = extra_cfg->tile_rows;
  509. oxcf->error_resilient_mode = cfg->g_error_resilient;
  510. oxcf->frame_parallel_decoding_mode = extra_cfg->frame_parallel_decoding_mode;
  511. oxcf->aq_mode = extra_cfg->aq_mode;
  512. oxcf->alt_ref_aq = extra_cfg->alt_ref_aq;
  513. oxcf->frame_periodic_boost = extra_cfg->frame_periodic_boost;
  514. oxcf->ss_number_layers = cfg->ss_number_layers;
  515. oxcf->ts_number_layers = cfg->ts_number_layers;
  516. oxcf->temporal_layering_mode =
  517. (enum vp9e_temporal_layering_mode)cfg->temporal_layering_mode;
  518. oxcf->target_level = extra_cfg->target_level;
  519. oxcf->row_mt = extra_cfg->row_mt;
  520. oxcf->motion_vector_unit_test = extra_cfg->motion_vector_unit_test;
  521. for (sl = 0; sl < oxcf->ss_number_layers; ++sl) {
  522. for (tl = 0; tl < oxcf->ts_number_layers; ++tl) {
  523. oxcf->layer_target_bitrate[sl * oxcf->ts_number_layers + tl] =
  524. 1000 * cfg->layer_target_bitrate[sl * oxcf->ts_number_layers + tl];
  525. }
  526. }
  527. if (oxcf->ss_number_layers == 1 && oxcf->pass != 0) {
  528. oxcf->ss_target_bitrate[0] = (int)oxcf->target_bandwidth;
  529. }
  530. if (oxcf->ts_number_layers > 1) {
  531. for (tl = 0; tl < VPX_TS_MAX_LAYERS; ++tl) {
  532. oxcf->ts_rate_decimator[tl] =
  533. cfg->ts_rate_decimator[tl] ? cfg->ts_rate_decimator[tl] : 1;
  534. }
  535. } else if (oxcf->ts_number_layers == 1) {
  536. oxcf->ts_rate_decimator[0] = 1;
  537. }
  538. if (get_level_index(oxcf->target_level) >= 0) config_target_level(oxcf);
  539. /*
  540. printf("Current VP9 Settings: \n");
  541. printf("target_bandwidth: %d\n", oxcf->target_bandwidth);
  542. printf("target_level: %d\n", oxcf->target_level);
  543. printf("noise_sensitivity: %d\n", oxcf->noise_sensitivity);
  544. printf("sharpness: %d\n", oxcf->sharpness);
  545. printf("cpu_used: %d\n", oxcf->cpu_used);
  546. printf("Mode: %d\n", oxcf->mode);
  547. printf("auto_key: %d\n", oxcf->auto_key);
  548. printf("key_freq: %d\n", oxcf->key_freq);
  549. printf("end_usage: %d\n", oxcf->end_usage);
  550. printf("under_shoot_pct: %d\n", oxcf->under_shoot_pct);
  551. printf("over_shoot_pct: %d\n", oxcf->over_shoot_pct);
  552. printf("starting_buffer_level: %d\n", oxcf->starting_buffer_level);
  553. printf("optimal_buffer_level: %d\n", oxcf->optimal_buffer_level);
  554. printf("maximum_buffer_size: %d\n", oxcf->maximum_buffer_size);
  555. printf("fixed_q: %d\n", oxcf->fixed_q);
  556. printf("worst_allowed_q: %d\n", oxcf->worst_allowed_q);
  557. printf("best_allowed_q: %d\n", oxcf->best_allowed_q);
  558. printf("allow_spatial_resampling: %d\n", oxcf->allow_spatial_resampling);
  559. printf("scaled_frame_width: %d\n", oxcf->scaled_frame_width);
  560. printf("scaled_frame_height: %d\n", oxcf->scaled_frame_height);
  561. printf("two_pass_vbrbias: %d\n", oxcf->two_pass_vbrbias);
  562. printf("two_pass_vbrmin_section: %d\n", oxcf->two_pass_vbrmin_section);
  563. printf("two_pass_vbrmax_section: %d\n", oxcf->two_pass_vbrmax_section);
  564. printf("vbr_corpus_complexity: %d\n", oxcf->vbr_corpus_complexity);
  565. printf("lag_in_frames: %d\n", oxcf->lag_in_frames);
  566. printf("enable_auto_arf: %d\n", oxcf->enable_auto_arf);
  567. printf("Version: %d\n", oxcf->Version);
  568. printf("encode_breakout: %d\n", oxcf->encode_breakout);
  569. printf("error resilient: %d\n", oxcf->error_resilient_mode);
  570. printf("frame parallel detokenization: %d\n",
  571. oxcf->frame_parallel_decoding_mode);
  572. */
  573. return VPX_CODEC_OK;
  574. }
  575. static vpx_codec_err_t encoder_set_config(vpx_codec_alg_priv_t *ctx,
  576. const vpx_codec_enc_cfg_t *cfg) {
  577. vpx_codec_err_t res;
  578. int force_key = 0;
  579. if (cfg->g_w != ctx->cfg.g_w || cfg->g_h != ctx->cfg.g_h) {
  580. if (cfg->g_lag_in_frames > 1 || cfg->g_pass != VPX_RC_ONE_PASS)
  581. ERROR("Cannot change width or height after initialization");
  582. if (!valid_ref_frame_size(ctx->cfg.g_w, ctx->cfg.g_h, cfg->g_w, cfg->g_h) ||
  583. (ctx->cpi->initial_width && (int)cfg->g_w > ctx->cpi->initial_width) ||
  584. (ctx->cpi->initial_height && (int)cfg->g_h > ctx->cpi->initial_height))
  585. force_key = 1;
  586. }
  587. // Prevent increasing lag_in_frames. This check is stricter than it needs
  588. // to be -- the limit is not increasing past the first lag_in_frames
  589. // value, but we don't track the initial config, only the last successful
  590. // config.
  591. if (cfg->g_lag_in_frames > ctx->cfg.g_lag_in_frames)
  592. ERROR("Cannot increase lag_in_frames");
  593. res = validate_config(ctx, cfg, &ctx->extra_cfg);
  594. if (res == VPX_CODEC_OK) {
  595. ctx->cfg = *cfg;
  596. set_encoder_config(&ctx->oxcf, &ctx->cfg, &ctx->extra_cfg);
  597. // On profile change, request a key frame
  598. force_key |= ctx->cpi->common.profile != ctx->oxcf.profile;
  599. vp9_change_config(ctx->cpi, &ctx->oxcf);
  600. }
  601. if (force_key) ctx->next_frame_flags |= VPX_EFLAG_FORCE_KF;
  602. return res;
  603. }
  604. static vpx_codec_err_t ctrl_get_quantizer(vpx_codec_alg_priv_t *ctx,
  605. va_list args) {
  606. int *const arg = va_arg(args, int *);
  607. if (arg == NULL) return VPX_CODEC_INVALID_PARAM;
  608. *arg = vp9_get_quantizer(ctx->cpi);
  609. return VPX_CODEC_OK;
  610. }
  611. static vpx_codec_err_t ctrl_get_quantizer64(vpx_codec_alg_priv_t *ctx,
  612. va_list args) {
  613. int *const arg = va_arg(args, int *);
  614. if (arg == NULL) return VPX_CODEC_INVALID_PARAM;
  615. *arg = vp9_qindex_to_quantizer(vp9_get_quantizer(ctx->cpi));
  616. return VPX_CODEC_OK;
  617. }
  618. static vpx_codec_err_t update_extra_cfg(vpx_codec_alg_priv_t *ctx,
  619. const struct vp9_extracfg *extra_cfg) {
  620. const vpx_codec_err_t res = validate_config(ctx, &ctx->cfg, extra_cfg);
  621. if (res == VPX_CODEC_OK) {
  622. ctx->extra_cfg = *extra_cfg;
  623. set_encoder_config(&ctx->oxcf, &ctx->cfg, &ctx->extra_cfg);
  624. vp9_change_config(ctx->cpi, &ctx->oxcf);
  625. }
  626. return res;
  627. }
  628. static vpx_codec_err_t ctrl_set_cpuused(vpx_codec_alg_priv_t *ctx,
  629. va_list args) {
  630. struct vp9_extracfg extra_cfg = ctx->extra_cfg;
  631. // Use fastest speed setting (speed 9 or -9) if it's set beyond the range.
  632. extra_cfg.cpu_used = CAST(VP8E_SET_CPUUSED, args);
  633. extra_cfg.cpu_used = VPXMIN(9, extra_cfg.cpu_used);
  634. extra_cfg.cpu_used = VPXMAX(-9, extra_cfg.cpu_used);
  635. return update_extra_cfg(ctx, &extra_cfg);
  636. }
  637. static vpx_codec_err_t ctrl_set_enable_auto_alt_ref(vpx_codec_alg_priv_t *ctx,
  638. va_list args) {
  639. struct vp9_extracfg extra_cfg = ctx->extra_cfg;
  640. extra_cfg.enable_auto_alt_ref = CAST(VP8E_SET_ENABLEAUTOALTREF, args);
  641. return update_extra_cfg(ctx, &extra_cfg);
  642. }
  643. static vpx_codec_err_t ctrl_set_noise_sensitivity(vpx_codec_alg_priv_t *ctx,
  644. va_list args) {
  645. struct vp9_extracfg extra_cfg = ctx->extra_cfg;
  646. extra_cfg.noise_sensitivity = CAST(VP9E_SET_NOISE_SENSITIVITY, args);
  647. return update_extra_cfg(ctx, &extra_cfg);
  648. }
  649. static vpx_codec_err_t ctrl_set_sharpness(vpx_codec_alg_priv_t *ctx,
  650. va_list args) {
  651. struct vp9_extracfg extra_cfg = ctx->extra_cfg;
  652. extra_cfg.sharpness = CAST(VP8E_SET_SHARPNESS, args);
  653. return update_extra_cfg(ctx, &extra_cfg);
  654. }
  655. static vpx_codec_err_t ctrl_set_static_thresh(vpx_codec_alg_priv_t *ctx,
  656. va_list args) {
  657. struct vp9_extracfg extra_cfg = ctx->extra_cfg;
  658. extra_cfg.static_thresh = CAST(VP8E_SET_STATIC_THRESHOLD, args);
  659. return update_extra_cfg(ctx, &extra_cfg);
  660. }
  661. static vpx_codec_err_t ctrl_set_tile_columns(vpx_codec_alg_priv_t *ctx,
  662. va_list args) {
  663. struct vp9_extracfg extra_cfg = ctx->extra_cfg;
  664. extra_cfg.tile_columns = CAST(VP9E_SET_TILE_COLUMNS, args);
  665. return update_extra_cfg(ctx, &extra_cfg);
  666. }
  667. static vpx_codec_err_t ctrl_set_tile_rows(vpx_codec_alg_priv_t *ctx,
  668. va_list args) {
  669. struct vp9_extracfg extra_cfg = ctx->extra_cfg;
  670. extra_cfg.tile_rows = CAST(VP9E_SET_TILE_ROWS, args);
  671. return update_extra_cfg(ctx, &extra_cfg);
  672. }
  673. static vpx_codec_err_t ctrl_set_tpl_model(vpx_codec_alg_priv_t *ctx,
  674. va_list args) {
  675. struct vp9_extracfg extra_cfg = ctx->extra_cfg;
  676. extra_cfg.enable_tpl_model = CAST(VP9E_SET_TPL, args);
  677. return update_extra_cfg(ctx, &extra_cfg);
  678. }
  679. static vpx_codec_err_t ctrl_set_arnr_max_frames(vpx_codec_alg_priv_t *ctx,
  680. va_list args) {
  681. struct vp9_extracfg extra_cfg = ctx->extra_cfg;
  682. extra_cfg.arnr_max_frames = CAST(VP8E_SET_ARNR_MAXFRAMES, args);
  683. return update_extra_cfg(ctx, &extra_cfg);
  684. }
  685. static vpx_codec_err_t ctrl_set_arnr_strength(vpx_codec_alg_priv_t *ctx,
  686. va_list args) {
  687. struct vp9_extracfg extra_cfg = ctx->extra_cfg;
  688. extra_cfg.arnr_strength = CAST(VP8E_SET_ARNR_STRENGTH, args);
  689. return update_extra_cfg(ctx, &extra_cfg);
  690. }
  691. static vpx_codec_err_t ctrl_set_arnr_type(vpx_codec_alg_priv_t *ctx,
  692. va_list args) {
  693. (void)ctx;
  694. (void)args;
  695. return VPX_CODEC_OK;
  696. }
  697. static vpx_codec_err_t ctrl_set_tuning(vpx_codec_alg_priv_t *ctx,
  698. va_list args) {
  699. struct vp9_extracfg extra_cfg = ctx->extra_cfg;
  700. extra_cfg.tuning = CAST(VP8E_SET_TUNING, args);
  701. return update_extra_cfg(ctx, &extra_cfg);
  702. }
  703. static vpx_codec_err_t ctrl_set_cq_level(vpx_codec_alg_priv_t *ctx,
  704. va_list args) {
  705. struct vp9_extracfg extra_cfg = ctx->extra_cfg;
  706. extra_cfg.cq_level = CAST(VP8E_SET_CQ_LEVEL, args);
  707. return update_extra_cfg(ctx, &extra_cfg);
  708. }
  709. static vpx_codec_err_t ctrl_set_rc_max_intra_bitrate_pct(
  710. vpx_codec_alg_priv_t *ctx, va_list args) {
  711. struct vp9_extracfg extra_cfg = ctx->extra_cfg;
  712. extra_cfg.rc_max_intra_bitrate_pct =
  713. CAST(VP8E_SET_MAX_INTRA_BITRATE_PCT, args);
  714. return update_extra_cfg(ctx, &extra_cfg);
  715. }
  716. static vpx_codec_err_t ctrl_set_rc_max_inter_bitrate_pct(
  717. vpx_codec_alg_priv_t *ctx, va_list args) {
  718. struct vp9_extracfg extra_cfg = ctx->extra_cfg;
  719. extra_cfg.rc_max_inter_bitrate_pct =
  720. CAST(VP9E_SET_MAX_INTER_BITRATE_PCT, args);
  721. return update_extra_cfg(ctx, &extra_cfg);
  722. }
  723. static vpx_codec_err_t ctrl_set_rc_gf_cbr_boost_pct(vpx_codec_alg_priv_t *ctx,
  724. va_list args) {
  725. struct vp9_extracfg extra_cfg = ctx->extra_cfg;
  726. extra_cfg.gf_cbr_boost_pct = CAST(VP9E_SET_GF_CBR_BOOST_PCT, args);
  727. return update_extra_cfg(ctx, &extra_cfg);
  728. }
  729. static vpx_codec_err_t ctrl_set_lossless(vpx_codec_alg_priv_t *ctx,
  730. va_list args) {
  731. struct vp9_extracfg extra_cfg = ctx->extra_cfg;
  732. extra_cfg.lossless = CAST(VP9E_SET_LOSSLESS, args);
  733. return update_extra_cfg(ctx, &extra_cfg);
  734. }
  735. static vpx_codec_err_t ctrl_set_frame_parallel_decoding_mode(
  736. vpx_codec_alg_priv_t *ctx, va_list args) {
  737. struct vp9_extracfg extra_cfg = ctx->extra_cfg;
  738. extra_cfg.frame_parallel_decoding_mode =
  739. CAST(VP9E_SET_FRAME_PARALLEL_DECODING, args);
  740. return update_extra_cfg(ctx, &extra_cfg);
  741. }
  742. static vpx_codec_err_t ctrl_set_aq_mode(vpx_codec_alg_priv_t *ctx,
  743. va_list args) {
  744. struct vp9_extracfg extra_cfg = ctx->extra_cfg;
  745. extra_cfg.aq_mode = CAST(VP9E_SET_AQ_MODE, args);
  746. return update_extra_cfg(ctx, &extra_cfg);
  747. }
  748. static vpx_codec_err_t ctrl_set_alt_ref_aq(vpx_codec_alg_priv_t *ctx,
  749. va_list args) {
  750. struct vp9_extracfg extra_cfg = ctx->extra_cfg;
  751. extra_cfg.alt_ref_aq = CAST(VP9E_SET_ALT_REF_AQ, args);
  752. return update_extra_cfg(ctx, &extra_cfg);
  753. }
  754. static vpx_codec_err_t ctrl_set_min_gf_interval(vpx_codec_alg_priv_t *ctx,
  755. va_list args) {
  756. struct vp9_extracfg extra_cfg = ctx->extra_cfg;
  757. extra_cfg.min_gf_interval = CAST(VP9E_SET_MIN_GF_INTERVAL, args);
  758. return update_extra_cfg(ctx, &extra_cfg);
  759. }
  760. static vpx_codec_err_t ctrl_set_max_gf_interval(vpx_codec_alg_priv_t *ctx,
  761. va_list args) {
  762. struct vp9_extracfg extra_cfg = ctx->extra_cfg;
  763. extra_cfg.max_gf_interval = CAST(VP9E_SET_MAX_GF_INTERVAL, args);
  764. return update_extra_cfg(ctx, &extra_cfg);
  765. }
  766. static vpx_codec_err_t ctrl_set_frame_periodic_boost(vpx_codec_alg_priv_t *ctx,
  767. va_list args) {
  768. struct vp9_extracfg extra_cfg = ctx->extra_cfg;
  769. extra_cfg.frame_periodic_boost = CAST(VP9E_SET_FRAME_PERIODIC_BOOST, args);
  770. return update_extra_cfg(ctx, &extra_cfg);
  771. }
  772. static vpx_codec_err_t ctrl_set_target_level(vpx_codec_alg_priv_t *ctx,
  773. va_list args) {
  774. struct vp9_extracfg extra_cfg = ctx->extra_cfg;
  775. extra_cfg.target_level = CAST(VP9E_SET_TARGET_LEVEL, args);
  776. return update_extra_cfg(ctx, &extra_cfg);
  777. }
  778. static vpx_codec_err_t ctrl_set_row_mt(vpx_codec_alg_priv_t *ctx,
  779. va_list args) {
  780. struct vp9_extracfg extra_cfg = ctx->extra_cfg;
  781. extra_cfg.row_mt = CAST(VP9E_SET_ROW_MT, args);
  782. return update_extra_cfg(ctx, &extra_cfg);
  783. }
  784. static vpx_codec_err_t ctrl_enable_motion_vector_unit_test(
  785. vpx_codec_alg_priv_t *ctx, va_list args) {
  786. struct vp9_extracfg extra_cfg = ctx->extra_cfg;
  787. extra_cfg.motion_vector_unit_test =
  788. CAST(VP9E_ENABLE_MOTION_VECTOR_UNIT_TEST, args);
  789. return update_extra_cfg(ctx, &extra_cfg);
  790. }
  791. static vpx_codec_err_t ctrl_get_level(vpx_codec_alg_priv_t *ctx, va_list args) {
  792. int *const arg = va_arg(args, int *);
  793. if (arg == NULL) return VPX_CODEC_INVALID_PARAM;
  794. *arg = (int)vp9_get_level(&ctx->cpi->level_info.level_spec);
  795. return VPX_CODEC_OK;
  796. }
  797. static vpx_codec_err_t encoder_init(vpx_codec_ctx_t *ctx,
  798. vpx_codec_priv_enc_mr_cfg_t *data) {
  799. vpx_codec_err_t res = VPX_CODEC_OK;
  800. (void)data;
  801. if (ctx->priv == NULL) {
  802. vpx_codec_alg_priv_t *const priv = vpx_calloc(1, sizeof(*priv));
  803. if (priv == NULL) return VPX_CODEC_MEM_ERROR;
  804. ctx->priv = (vpx_codec_priv_t *)priv;
  805. ctx->priv->init_flags = ctx->init_flags;
  806. ctx->priv->enc.total_encoders = 1;
  807. priv->buffer_pool = (BufferPool *)vpx_calloc(1, sizeof(BufferPool));
  808. if (priv->buffer_pool == NULL) return VPX_CODEC_MEM_ERROR;
  809. if (ctx->config.enc) {
  810. // Update the reference to the config structure to an internal copy.
  811. priv->cfg = *ctx->config.enc;
  812. ctx->config.enc = &priv->cfg;
  813. }
  814. priv->extra_cfg = default_extra_cfg;
  815. once(vp9_initialize_enc);
  816. res = validate_config(priv, &priv->cfg, &priv->extra_cfg);
  817. if (res == VPX_CODEC_OK) {
  818. priv->pts_offset_initialized = 0;
  819. priv->timestamp_ratio.den = priv->cfg.g_timebase.den;
  820. priv->timestamp_ratio.num = (int64_t)priv->cfg.g_timebase.num;
  821. priv->timestamp_ratio.num *= TICKS_PER_SEC;
  822. reduce_ratio(&priv->timestamp_ratio);
  823. set_encoder_config(&priv->oxcf, &priv->cfg, &priv->extra_cfg);
  824. #if CONFIG_VP9_HIGHBITDEPTH
  825. priv->oxcf.use_highbitdepth =
  826. (ctx->init_flags & VPX_CODEC_USE_HIGHBITDEPTH) ? 1 : 0;
  827. #endif
  828. priv->cpi = vp9_create_compressor(&priv->oxcf, priv->buffer_pool);
  829. if (priv->cpi == NULL)
  830. res = VPX_CODEC_MEM_ERROR;
  831. else
  832. priv->cpi->output_pkt_list = &priv->pkt_list.head;
  833. }
  834. }
  835. return res;
  836. }
  837. static vpx_codec_err_t encoder_destroy(vpx_codec_alg_priv_t *ctx) {
  838. free(ctx->cx_data);
  839. vp9_remove_compressor(ctx->cpi);
  840. vpx_free(ctx->buffer_pool);
  841. vpx_free(ctx);
  842. return VPX_CODEC_OK;
  843. }
  844. static void pick_quickcompress_mode(vpx_codec_alg_priv_t *ctx,
  845. unsigned long duration,
  846. unsigned long deadline) {
  847. MODE new_mode = BEST;
  848. #if CONFIG_REALTIME_ONLY
  849. (void)duration;
  850. deadline = VPX_DL_REALTIME;
  851. #else
  852. switch (ctx->cfg.g_pass) {
  853. case VPX_RC_ONE_PASS:
  854. if (deadline > 0) {
  855. // Convert duration parameter from stream timebase to microseconds.
  856. uint64_t duration_us;
  857. COMPILE_TIME_ASSERT(TICKS_PER_SEC > 1000000 &&
  858. (TICKS_PER_SEC % 1000000) == 0);
  859. duration_us = duration * (uint64_t)ctx->timestamp_ratio.num /
  860. (ctx->timestamp_ratio.den * (TICKS_PER_SEC / 1000000));
  861. // If the deadline is more that the duration this frame is to be shown,
  862. // use good quality mode. Otherwise use realtime mode.
  863. new_mode = (deadline > duration_us) ? GOOD : REALTIME;
  864. } else {
  865. new_mode = BEST;
  866. }
  867. break;
  868. case VPX_RC_FIRST_PASS: break;
  869. case VPX_RC_LAST_PASS: new_mode = deadline > 0 ? GOOD : BEST; break;
  870. }
  871. #endif // CONFIG_REALTIME_ONLY
  872. if (deadline == VPX_DL_REALTIME) {
  873. ctx->oxcf.pass = 0;
  874. new_mode = REALTIME;
  875. }
  876. if (ctx->oxcf.mode != new_mode) {
  877. ctx->oxcf.mode = new_mode;
  878. vp9_change_config(ctx->cpi, &ctx->oxcf);
  879. }
  880. }
  881. // Turn on to test if supplemental superframe data breaks decoding
  882. // #define TEST_SUPPLEMENTAL_SUPERFRAME_DATA
  883. static int write_superframe_index(vpx_codec_alg_priv_t *ctx) {
  884. uint8_t marker = 0xc0;
  885. unsigned int mask;
  886. int mag, index_sz;
  887. assert(ctx->pending_frame_count);
  888. assert(ctx->pending_frame_count <= 8);
  889. // Add the number of frames to the marker byte
  890. marker |= ctx->pending_frame_count - 1;
  891. // Choose the magnitude
  892. for (mag = 0, mask = 0xff; mag < 4; mag++) {
  893. if (ctx->pending_frame_magnitude < mask) break;
  894. mask <<= 8;
  895. mask |= 0xff;
  896. }
  897. marker |= mag << 3;
  898. // Write the index
  899. index_sz = 2 + (mag + 1) * ctx->pending_frame_count;
  900. if (ctx->pending_cx_data_sz + index_sz < ctx->cx_data_sz) {
  901. uint8_t *x = ctx->pending_cx_data + ctx->pending_cx_data_sz;
  902. int i, j;
  903. #ifdef TEST_SUPPLEMENTAL_SUPERFRAME_DATA
  904. uint8_t marker_test = 0xc0;
  905. int mag_test = 2; // 1 - 4
  906. int frames_test = 4; // 1 - 8
  907. int index_sz_test = 2 + mag_test * frames_test;
  908. marker_test |= frames_test - 1;
  909. marker_test |= (mag_test - 1) << 3;
  910. *x++ = marker_test;
  911. for (i = 0; i < mag_test * frames_test; ++i)
  912. *x++ = 0; // fill up with arbitrary data
  913. *x++ = marker_test;
  914. ctx->pending_cx_data_sz += index_sz_test;
  915. printf("Added supplemental superframe data\n");
  916. #endif
  917. *x++ = marker;
  918. for (i = 0; i < ctx->pending_frame_count; i++) {
  919. unsigned int this_sz = (unsigned int)ctx->pending_frame_sizes[i];
  920. for (j = 0; j <= mag; j++) {
  921. *x++ = this_sz & 0xff;
  922. this_sz >>= 8;
  923. }
  924. }
  925. *x++ = marker;
  926. ctx->pending_cx_data_sz += index_sz;
  927. #ifdef TEST_SUPPLEMENTAL_SUPERFRAME_DATA
  928. index_sz += index_sz_test;
  929. #endif
  930. }
  931. return index_sz;
  932. }
  933. static int64_t timebase_units_to_ticks(const vpx_rational64_t *timestamp_ratio,
  934. int64_t n) {
  935. return n * timestamp_ratio->num / timestamp_ratio->den;
  936. }
  937. static int64_t ticks_to_timebase_units(const vpx_rational64_t *timestamp_ratio,
  938. int64_t n) {
  939. int64_t round = timestamp_ratio->num / 2;
  940. if (round > 0) --round;
  941. return (n * timestamp_ratio->den + round) / timestamp_ratio->num;
  942. }
  943. static vpx_codec_frame_flags_t get_frame_pkt_flags(const VP9_COMP *cpi,
  944. unsigned int lib_flags) {
  945. vpx_codec_frame_flags_t flags = lib_flags << 16;
  946. if (lib_flags & FRAMEFLAGS_KEY ||
  947. (cpi->use_svc && cpi->svc
  948. .layer_context[cpi->svc.spatial_layer_id *
  949. cpi->svc.number_temporal_layers +
  950. cpi->svc.temporal_layer_id]
  951. .is_key_frame))
  952. flags |= VPX_FRAME_IS_KEY;
  953. if (cpi->droppable) flags |= VPX_FRAME_IS_DROPPABLE;
  954. return flags;
  955. }
  956. const size_t kMinCompressedSize = 8192;
  957. static vpx_codec_err_t encoder_encode(vpx_codec_alg_priv_t *ctx,
  958. const vpx_image_t *img,
  959. vpx_codec_pts_t pts_val,
  960. unsigned long duration,
  961. vpx_enc_frame_flags_t enc_flags,
  962. unsigned long deadline) {
  963. volatile vpx_codec_err_t res = VPX_CODEC_OK;
  964. volatile vpx_enc_frame_flags_t flags = enc_flags;
  965. volatile vpx_codec_pts_t pts = pts_val;
  966. VP9_COMP *const cpi = ctx->cpi;
  967. const vpx_rational64_t *const timestamp_ratio = &ctx->timestamp_ratio;
  968. size_t data_sz;
  969. if (cpi == NULL) return VPX_CODEC_INVALID_PARAM;
  970. if (cpi->oxcf.pass == 2 && cpi->level_constraint.level_index >= 0 &&
  971. !cpi->level_constraint.rc_config_updated) {
  972. const VP9EncoderConfig *const oxcf = &cpi->oxcf;
  973. TWO_PASS *const twopass = &cpi->twopass;
  974. FIRSTPASS_STATS *stats = &twopass->total_stats;
  975. twopass->bits_left =
  976. (int64_t)(stats->duration * oxcf->target_bandwidth / 10000000.0);
  977. cpi->level_constraint.rc_config_updated = 1;
  978. }
  979. if (img != NULL) {
  980. res = validate_img(ctx, img);
  981. if (res == VPX_CODEC_OK) {
  982. // There's no codec control for multiple alt-refs so check the encoder
  983. // instance for its status to determine the compressed data size.
  984. data_sz = ctx->cfg.g_w * ctx->cfg.g_h * get_image_bps(img) / 8 *
  985. (cpi->multi_layer_arf ? 8 : 2);
  986. if (data_sz < kMinCompressedSize) data_sz = kMinCompressedSize;
  987. if (ctx->cx_data == NULL || ctx->cx_data_sz < data_sz) {
  988. ctx->cx_data_sz = data_sz;
  989. free(ctx->cx_data);
  990. ctx->cx_data = (unsigned char *)malloc(ctx->cx_data_sz);
  991. if (ctx->cx_data == NULL) {
  992. return VPX_CODEC_MEM_ERROR;
  993. }
  994. }
  995. }
  996. }
  997. if (!ctx->pts_offset_initialized) {
  998. ctx->pts_offset = pts;
  999. ctx->pts_offset_initialized = 1;
  1000. }
  1001. pts -= ctx->pts_offset;
  1002. pick_quickcompress_mode(ctx, duration, deadline);
  1003. vpx_codec_pkt_list_init(&ctx->pkt_list);
  1004. // Handle Flags
  1005. if (((flags & VP8_EFLAG_NO_UPD_GF) && (flags & VP8_EFLAG_FORCE_GF)) ||
  1006. ((flags & VP8_EFLAG_NO_UPD_ARF) && (flags & VP8_EFLAG_FORCE_ARF))) {
  1007. ctx->base.err_detail = "Conflicting flags.";
  1008. return VPX_CODEC_INVALID_PARAM;
  1009. }
  1010. if (setjmp(cpi->common.error.jmp)) {
  1011. cpi->common.error.setjmp = 0;
  1012. res = update_error_state(ctx, &cpi->common.error);
  1013. vpx_clear_system_state();
  1014. return res;
  1015. }
  1016. cpi->common.error.setjmp = 1;
  1017. if (res == VPX_CODEC_OK) vp9_apply_encoding_flags(cpi, flags);
  1018. // Handle fixed keyframe intervals
  1019. if (ctx->cfg.kf_mode == VPX_KF_AUTO &&
  1020. ctx->cfg.kf_min_dist == ctx->cfg.kf_max_dist) {
  1021. if (++ctx->fixed_kf_cntr > ctx->cfg.kf_min_dist) {
  1022. flags |= VPX_EFLAG_FORCE_KF;
  1023. ctx->fixed_kf_cntr = 1;
  1024. }
  1025. }
  1026. if (res == VPX_CODEC_OK) {
  1027. unsigned int lib_flags = 0;
  1028. YV12_BUFFER_CONFIG sd;
  1029. int64_t dst_time_stamp = timebase_units_to_ticks(timestamp_ratio, pts);
  1030. int64_t dst_end_time_stamp =
  1031. timebase_units_to_ticks(timestamp_ratio, pts + duration);
  1032. size_t size, cx_data_sz;
  1033. unsigned char *cx_data;
  1034. cpi->svc.timebase_fac = timebase_units_to_ticks(timestamp_ratio, 1);
  1035. cpi->svc.time_stamp_superframe = dst_time_stamp;
  1036. // Set up internal flags
  1037. if (ctx->base.init_flags & VPX_CODEC_USE_PSNR) cpi->b_calculate_psnr = 1;
  1038. if (img != NULL) {
  1039. res = image2yuvconfig(img, &sd);
  1040. // Store the original flags in to the frame buffer. Will extract the
  1041. // key frame flag when we actually encode this frame.
  1042. if (vp9_receive_raw_frame(cpi, flags | ctx->next_frame_flags, &sd,
  1043. dst_time_stamp, dst_end_time_stamp)) {
  1044. res = update_error_state(ctx, &cpi->common.error);
  1045. }
  1046. ctx->next_frame_flags = 0;
  1047. }
  1048. cx_data = ctx->cx_data;
  1049. cx_data_sz = ctx->cx_data_sz;
  1050. /* Any pending invisible frames? */
  1051. if (ctx->pending_cx_data) {
  1052. memmove(cx_data, ctx->pending_cx_data, ctx->pending_cx_data_sz);
  1053. ctx->pending_cx_data = cx_data;
  1054. cx_data += ctx->pending_cx_data_sz;
  1055. cx_data_sz -= ctx->pending_cx_data_sz;
  1056. /* TODO: this is a minimal check, the underlying codec doesn't respect
  1057. * the buffer size anyway.
  1058. */
  1059. if (cx_data_sz < ctx->cx_data_sz / 2) {
  1060. vpx_internal_error(&cpi->common.error, VPX_CODEC_ERROR,
  1061. "Compressed data buffer too small");
  1062. return VPX_CODEC_ERROR;
  1063. }
  1064. }
  1065. while (cx_data_sz >= ctx->cx_data_sz / 2 &&
  1066. -1 != vp9_get_compressed_data(cpi, &lib_flags, &size, cx_data,
  1067. &dst_time_stamp, &dst_end_time_stamp,
  1068. !img)) {
  1069. if (size || (cpi->use_svc && cpi->svc.skip_enhancement_layer)) {
  1070. vpx_codec_cx_pkt_t pkt;
  1071. // Pack invisible frames with the next visible frame
  1072. if (!cpi->common.show_frame ||
  1073. (cpi->use_svc &&
  1074. cpi->svc.spatial_layer_id < cpi->svc.number_spatial_layers - 1)) {
  1075. if (ctx->pending_cx_data == 0) ctx->pending_cx_data = cx_data;
  1076. ctx->pending_cx_data_sz += size;
  1077. if (size) ctx->pending_frame_sizes[ctx->pending_frame_count++] = size;
  1078. ctx->pending_frame_magnitude |= size;
  1079. cx_data += size;
  1080. cx_data_sz -= size;
  1081. pkt.data.frame.width[cpi->svc.spatial_layer_id] = cpi->common.width;
  1082. pkt.data.frame.height[cpi->svc.spatial_layer_id] = cpi->common.height;
  1083. pkt.data.frame.spatial_layer_encoded[cpi->svc.spatial_layer_id] =
  1084. 1 - cpi->svc.drop_spatial_layer[cpi->svc.spatial_layer_id];
  1085. if (ctx->output_cx_pkt_cb.output_cx_pkt) {
  1086. pkt.kind = VPX_CODEC_CX_FRAME_PKT;
  1087. pkt.data.frame.pts =
  1088. ticks_to_timebase_units(timestamp_ratio, dst_time_stamp) +
  1089. ctx->pts_offset;
  1090. pkt.data.frame.duration = (unsigned long)ticks_to_timebase_units(
  1091. timestamp_ratio, dst_end_time_stamp - dst_time_stamp);
  1092. pkt.data.frame.flags = get_frame_pkt_flags(cpi, lib_flags);
  1093. pkt.data.frame.buf = ctx->pending_cx_data;
  1094. pkt.data.frame.sz = size;
  1095. ctx->pending_cx_data = NULL;
  1096. ctx->pending_cx_data_sz = 0;
  1097. ctx->pending_frame_count = 0;
  1098. ctx->pending_frame_magnitude = 0;
  1099. ctx->output_cx_pkt_cb.output_cx_pkt(
  1100. &pkt, ctx->output_cx_pkt_cb.user_priv);
  1101. }
  1102. continue;
  1103. }
  1104. // Add the frame packet to the list of returned packets.
  1105. pkt.kind = VPX_CODEC_CX_FRAME_PKT;
  1106. pkt.data.frame.pts =
  1107. ticks_to_timebase_units(timestamp_ratio, dst_time_stamp) +
  1108. ctx->pts_offset;
  1109. pkt.data.frame.duration = (unsigned long)ticks_to_timebase_units(
  1110. timestamp_ratio, dst_end_time_stamp - dst_time_stamp);
  1111. pkt.data.frame.flags = get_frame_pkt_flags(cpi, lib_flags);
  1112. pkt.data.frame.width[cpi->svc.spatial_layer_id] = cpi->common.width;
  1113. pkt.data.frame.height[cpi->svc.spatial_layer_id] = cpi->common.height;
  1114. pkt.data.frame.spatial_layer_encoded[cpi->svc.spatial_layer_id] =
  1115. 1 - cpi->svc.drop_spatial_layer[cpi->svc.spatial_layer_id];
  1116. if (ctx->pending_cx_data) {
  1117. if (size) ctx->pending_frame_sizes[ctx->pending_frame_count++] = size;
  1118. ctx->pending_frame_magnitude |= size;
  1119. ctx->pending_cx_data_sz += size;
  1120. // write the superframe only for the case when
  1121. if (!ctx->output_cx_pkt_cb.output_cx_pkt)
  1122. size += write_superframe_index(ctx);
  1123. pkt.data.frame.buf = ctx->pending_cx_data;
  1124. pkt.data.frame.sz = ctx->pending_cx_data_sz;
  1125. ctx->pending_cx_data = NULL;
  1126. ctx->pending_cx_data_sz = 0;
  1127. ctx->pending_frame_count = 0;
  1128. ctx->pending_frame_magnitude = 0;
  1129. } else {
  1130. pkt.data.frame.buf = cx_data;
  1131. pkt.data.frame.sz = size;
  1132. }
  1133. pkt.data.frame.partition_id = -1;
  1134. if (ctx->output_cx_pkt_cb.output_cx_pkt)
  1135. ctx->output_cx_pkt_cb.output_cx_pkt(&pkt,
  1136. ctx->output_cx_pkt_cb.user_priv);
  1137. else
  1138. vpx_codec_pkt_list_add(&ctx->pkt_list.head, &pkt);
  1139. cx_data += size;
  1140. cx_data_sz -= size;
  1141. if (is_one_pass_cbr_svc(cpi) &&
  1142. (cpi->svc.spatial_layer_id == cpi->svc.number_spatial_layers - 1)) {
  1143. // Encoded all spatial layers; exit loop.
  1144. break;
  1145. }
  1146. }
  1147. }
  1148. }
  1149. cpi->common.error.setjmp = 0;
  1150. return res;
  1151. }
  1152. static const vpx_codec_cx_pkt_t *encoder_get_cxdata(vpx_codec_alg_priv_t *ctx,
  1153. vpx_codec_iter_t *iter) {
  1154. return vpx_codec_pkt_list_get(&ctx->pkt_list.head, iter);
  1155. }
  1156. static vpx_codec_err_t ctrl_set_reference(vpx_codec_alg_priv_t *ctx,
  1157. va_list args) {
  1158. vpx_ref_frame_t *const frame = va_arg(args, vpx_ref_frame_t *);
  1159. if (frame != NULL) {
  1160. YV12_BUFFER_CONFIG sd;
  1161. image2yuvconfig(&frame->img, &sd);
  1162. vp9_set_reference_enc(ctx->cpi, ref_frame_to_vp9_reframe(frame->frame_type),
  1163. &sd);
  1164. return VPX_CODEC_OK;
  1165. }
  1166. return VPX_CODEC_INVALID_PARAM;
  1167. }
  1168. static vpx_codec_err_t ctrl_copy_reference(vpx_codec_alg_priv_t *ctx,
  1169. va_list args) {
  1170. vpx_ref_frame_t *const frame = va_arg(args, vpx_ref_frame_t *);
  1171. if (frame != NULL) {
  1172. YV12_BUFFER_CONFIG sd;
  1173. image2yuvconfig(&frame->img, &sd);
  1174. vp9_copy_reference_enc(ctx->cpi,
  1175. ref_frame_to_vp9_reframe(frame->frame_type), &sd);
  1176. return VPX_CODEC_OK;
  1177. }
  1178. return VPX_CODEC_INVALID_PARAM;
  1179. }
  1180. static vpx_codec_err_t ctrl_get_reference(vpx_codec_alg_priv_t *ctx,
  1181. va_list args) {
  1182. vp9_ref_frame_t *const frame = va_arg(args, vp9_ref_frame_t *);
  1183. if (frame != NULL) {
  1184. const int fb_idx = ctx->cpi->common.cur_show_frame_fb_idx;
  1185. YV12_BUFFER_CONFIG *fb = get_buf_frame(&ctx->cpi->common, fb_idx);
  1186. if (fb == NULL) return VPX_CODEC_ERROR;
  1187. yuvconfig2image(&frame->img, fb, NULL);
  1188. return VPX_CODEC_OK;
  1189. }
  1190. return VPX_CODEC_INVALID_PARAM;
  1191. }
  1192. static vpx_codec_err_t ctrl_set_previewpp(vpx_codec_alg_priv_t *ctx,
  1193. va_list args) {
  1194. #if CONFIG_VP9_POSTPROC
  1195. vp8_postproc_cfg_t *config = va_arg(args, vp8_postproc_cfg_t *);
  1196. if (config != NULL) {
  1197. ctx->preview_ppcfg = *config;
  1198. return VPX_CODEC_OK;
  1199. }
  1200. return VPX_CODEC_INVALID_PARAM;
  1201. #else
  1202. (void)ctx;
  1203. (void)args;
  1204. return VPX_CODEC_INCAPABLE;
  1205. #endif
  1206. }
  1207. static vpx_image_t *encoder_get_preview(vpx_codec_alg_priv_t *ctx) {
  1208. YV12_BUFFER_CONFIG sd;
  1209. vp9_ppflags_t flags;
  1210. vp9_zero(flags);
  1211. if (ctx->preview_ppcfg.post_proc_flag) {
  1212. flags.post_proc_flag = ctx->preview_ppcfg.post_proc_flag;
  1213. flags.deblocking_level = ctx->preview_ppcfg.deblocking_level;
  1214. flags.noise_level = ctx->preview_ppcfg.noise_level;
  1215. }
  1216. if (vp9_get_preview_raw_frame(ctx->cpi, &sd, &flags) == 0) {
  1217. yuvconfig2image(&ctx->preview_img, &sd, NULL);
  1218. return &ctx->preview_img;
  1219. }
  1220. return NULL;
  1221. }
  1222. static vpx_codec_err_t ctrl_set_roi_map(vpx_codec_alg_priv_t *ctx,
  1223. va_list args) {
  1224. vpx_roi_map_t *data = va_arg(args, vpx_roi_map_t *);
  1225. if (data) {
  1226. vpx_roi_map_t *roi = (vpx_roi_map_t *)data;
  1227. if (!vp9_set_roi_map(ctx->cpi, roi->roi_map, roi->rows, roi->cols,
  1228. roi->delta_q, roi->delta_lf, roi->skip,
  1229. roi->ref_frame)) {
  1230. return VPX_CODEC_OK;
  1231. }
  1232. return VPX_CODEC_INVALID_PARAM;
  1233. }
  1234. return VPX_CODEC_INVALID_PARAM;
  1235. }
  1236. static vpx_codec_err_t ctrl_set_active_map(vpx_codec_alg_priv_t *ctx,
  1237. va_list args) {
  1238. vpx_active_map_t *const map = va_arg(args, vpx_active_map_t *);
  1239. if (map) {
  1240. if (!vp9_set_active_map(ctx->cpi, map->active_map, (int)map->rows,
  1241. (int)map->cols))
  1242. return VPX_CODEC_OK;
  1243. return VPX_CODEC_INVALID_PARAM;
  1244. }
  1245. return VPX_CODEC_INVALID_PARAM;
  1246. }
  1247. static vpx_codec_err_t ctrl_get_active_map(vpx_codec_alg_priv_t *ctx,
  1248. va_list args) {
  1249. vpx_active_map_t *const map = va_arg(args, vpx_active_map_t *);
  1250. if (map) {
  1251. if (!vp9_get_active_map(ctx->cpi, map->active_map, (int)map->rows,
  1252. (int)map->cols))
  1253. return VPX_CODEC_OK;
  1254. return VPX_CODEC_INVALID_PARAM;
  1255. }
  1256. return VPX_CODEC_INVALID_PARAM;
  1257. }
  1258. static vpx_codec_err_t ctrl_set_scale_mode(vpx_codec_alg_priv_t *ctx,
  1259. va_list args) {
  1260. vpx_scaling_mode_t *const mode = va_arg(args, vpx_scaling_mode_t *);
  1261. if (mode) {
  1262. const int res =
  1263. vp9_set_internal_size(ctx->cpi, (VPX_SCALING)mode->h_scaling_mode,
  1264. (VPX_SCALING)mode->v_scaling_mode);
  1265. return (res == 0) ? VPX_CODEC_OK : VPX_CODEC_INVALID_PARAM;
  1266. }
  1267. return VPX_CODEC_INVALID_PARAM;
  1268. }
  1269. static vpx_codec_err_t ctrl_set_svc(vpx_codec_alg_priv_t *ctx, va_list args) {
  1270. int data = va_arg(args, int);
  1271. const vpx_codec_enc_cfg_t *cfg = &ctx->cfg;
  1272. // Both one-pass and two-pass RC are supported now.
  1273. // User setting this has to make sure of the following.
  1274. // In two-pass setting: either (but not both)
  1275. // cfg->ss_number_layers > 1, or cfg->ts_number_layers > 1
  1276. // In one-pass setting:
  1277. // either or both cfg->ss_number_layers > 1, or cfg->ts_number_layers > 1
  1278. vp9_set_svc(ctx->cpi, data);
  1279. if (data == 1 &&
  1280. (cfg->g_pass == VPX_RC_FIRST_PASS || cfg->g_pass == VPX_RC_LAST_PASS) &&
  1281. cfg->ss_number_layers > 1 && cfg->ts_number_layers > 1) {
  1282. return VPX_CODEC_INVALID_PARAM;
  1283. }
  1284. vp9_set_row_mt(ctx->cpi);
  1285. return VPX_CODEC_OK;
  1286. }
  1287. static vpx_codec_err_t ctrl_set_svc_layer_id(vpx_codec_alg_priv_t *ctx,
  1288. va_list args) {
  1289. vpx_svc_layer_id_t *const data = va_arg(args, vpx_svc_layer_id_t *);
  1290. VP9_COMP *const cpi = (VP9_COMP *)ctx->cpi;
  1291. SVC *const svc = &cpi->svc;
  1292. int sl;
  1293. svc->spatial_layer_to_encode = data->spatial_layer_id;
  1294. svc->first_spatial_layer_to_encode = data->spatial_layer_id;
  1295. // TODO(jianj): Deprecated to be removed.
  1296. svc->temporal_layer_id = data->temporal_layer_id;
  1297. // Allow for setting temporal layer per spatial layer for superframe.
  1298. for (sl = 0; sl < cpi->svc.number_spatial_layers; ++sl) {
  1299. svc->temporal_layer_id_per_spatial[sl] =
  1300. data->temporal_layer_id_per_spatial[sl];
  1301. }
  1302. // Checks on valid layer_id input.
  1303. if (svc->temporal_layer_id < 0 ||
  1304. svc->temporal_layer_id >= (int)ctx->cfg.ts_number_layers) {
  1305. return VPX_CODEC_INVALID_PARAM;
  1306. }
  1307. return VPX_CODEC_OK;
  1308. }
  1309. static vpx_codec_err_t ctrl_get_svc_layer_id(vpx_codec_alg_priv_t *ctx,
  1310. va_list args) {
  1311. vpx_svc_layer_id_t *data = va_arg(args, vpx_svc_layer_id_t *);
  1312. VP9_COMP *const cpi = (VP9_COMP *)ctx->cpi;
  1313. SVC *const svc = &cpi->svc;
  1314. data->spatial_layer_id = svc->spatial_layer_id;
  1315. data->temporal_layer_id = svc->temporal_layer_id;
  1316. return VPX_CODEC_OK;
  1317. }
  1318. static vpx_codec_err_t ctrl_set_svc_parameters(vpx_codec_alg_priv_t *ctx,
  1319. va_list args) {
  1320. VP9_COMP *const cpi = ctx->cpi;
  1321. vpx_svc_extra_cfg_t *const params = va_arg(args, vpx_svc_extra_cfg_t *);
  1322. int sl, tl;
  1323. // Number of temporal layers and number of spatial layers have to be set
  1324. // properly before calling this control function.
  1325. for (sl = 0; sl < cpi->svc.number_spatial_layers; ++sl) {
  1326. for (tl = 0; tl < cpi->svc.number_temporal_layers; ++tl) {
  1327. const int layer =
  1328. LAYER_IDS_TO_IDX(sl, tl, cpi->svc.number_temporal_layers);
  1329. LAYER_CONTEXT *lc = &cpi->svc.layer_context[layer];
  1330. lc->max_q = params->max_quantizers[layer];
  1331. lc->min_q = params->min_quantizers[layer];
  1332. lc->scaling_factor_num = params->scaling_factor_num[sl];
  1333. lc->scaling_factor_den = params->scaling_factor_den[sl];
  1334. lc->speed = params->speed_per_layer[sl];
  1335. }
  1336. }
  1337. return VPX_CODEC_OK;
  1338. }
  1339. static vpx_codec_err_t ctrl_get_svc_ref_frame_config(vpx_codec_alg_priv_t *ctx,
  1340. va_list args) {
  1341. VP9_COMP *const cpi = ctx->cpi;
  1342. vpx_svc_ref_frame_config_t *data = va_arg(args, vpx_svc_ref_frame_config_t *);
  1343. int sl;
  1344. for (sl = 0; sl <= cpi->svc.spatial_layer_id; sl++) {
  1345. data->update_buffer_slot[sl] = cpi->svc.update_buffer_slot[sl];
  1346. data->reference_last[sl] = cpi->svc.reference_last[sl];
  1347. data->reference_golden[sl] = cpi->svc.reference_golden[sl];
  1348. data->reference_alt_ref[sl] = cpi->svc.reference_altref[sl];
  1349. data->lst_fb_idx[sl] = cpi->svc.lst_fb_idx[sl];
  1350. data->gld_fb_idx[sl] = cpi->svc.gld_fb_idx[sl];
  1351. data->alt_fb_idx[sl] = cpi->svc.alt_fb_idx[sl];
  1352. // TODO(jianj): Remove these 3, deprecated.
  1353. data->update_last[sl] = cpi->svc.update_last[sl];
  1354. data->update_golden[sl] = cpi->svc.update_golden[sl];
  1355. data->update_alt_ref[sl] = cpi->svc.update_altref[sl];
  1356. }
  1357. return VPX_CODEC_OK;
  1358. }
  1359. static vpx_codec_err_t ctrl_set_svc_ref_frame_config(vpx_codec_alg_priv_t *ctx,
  1360. va_list args) {
  1361. VP9_COMP *const cpi = ctx->cpi;
  1362. vpx_svc_ref_frame_config_t *data = va_arg(args, vpx_svc_ref_frame_config_t *);
  1363. int sl;
  1364. cpi->svc.use_set_ref_frame_config = 1;
  1365. for (sl = 0; sl < cpi->svc.number_spatial_layers; ++sl) {
  1366. cpi->svc.update_buffer_slot[sl] = data->update_buffer_slot[sl];
  1367. cpi->svc.reference_last[sl] = data->reference_last[sl];
  1368. cpi->svc.reference_golden[sl] = data->reference_golden[sl];
  1369. cpi->svc.reference_altref[sl] = data->reference_alt_ref[sl];
  1370. cpi->svc.lst_fb_idx[sl] = data->lst_fb_idx[sl];
  1371. cpi->svc.gld_fb_idx[sl] = data->gld_fb_idx[sl];
  1372. cpi->svc.alt_fb_idx[sl] = data->alt_fb_idx[sl];
  1373. cpi->svc.duration[sl] = data->duration[sl];
  1374. }
  1375. return VPX_CODEC_OK;
  1376. }
  1377. static vpx_codec_err_t ctrl_set_svc_inter_layer_pred(vpx_codec_alg_priv_t *ctx,
  1378. va_list args) {
  1379. const int data = va_arg(args, int);
  1380. VP9_COMP *const cpi = ctx->cpi;
  1381. cpi->svc.disable_inter_layer_pred = data;
  1382. return VPX_CODEC_OK;
  1383. }
  1384. static vpx_codec_err_t ctrl_set_svc_frame_drop_layer(vpx_codec_alg_priv_t *ctx,
  1385. va_list args) {
  1386. VP9_COMP *const cpi = ctx->cpi;
  1387. vpx_svc_frame_drop_t *data = va_arg(args, vpx_svc_frame_drop_t *);
  1388. int sl;
  1389. cpi->svc.framedrop_mode = data->framedrop_mode;
  1390. for (sl = 0; sl < cpi->svc.number_spatial_layers; ++sl)
  1391. cpi->svc.framedrop_thresh[sl] = data->framedrop_thresh[sl];
  1392. // Don't allow max_consec_drop values below 1.
  1393. cpi->svc.max_consec_drop = VPXMAX(1, data->max_consec_drop);
  1394. return VPX_CODEC_OK;
  1395. }
  1396. static vpx_codec_err_t ctrl_set_svc_gf_temporal_ref(vpx_codec_alg_priv_t *ctx,
  1397. va_list args) {
  1398. VP9_COMP *const cpi = ctx->cpi;
  1399. const unsigned int data = va_arg(args, unsigned int);
  1400. cpi->svc.use_gf_temporal_ref = data;
  1401. return VPX_CODEC_OK;
  1402. }
  1403. static vpx_codec_err_t ctrl_set_svc_spatial_layer_sync(
  1404. vpx_codec_alg_priv_t *ctx, va_list args) {
  1405. VP9_COMP *const cpi = ctx->cpi;
  1406. vpx_svc_spatial_layer_sync_t *data =
  1407. va_arg(args, vpx_svc_spatial_layer_sync_t *);
  1408. int sl;
  1409. for (sl = 0; sl < cpi->svc.number_spatial_layers; ++sl)
  1410. cpi->svc.spatial_layer_sync[sl] = data->spatial_layer_sync[sl];
  1411. cpi->svc.set_intra_only_frame = data->base_layer_intra_only;
  1412. return VPX_CODEC_OK;
  1413. }
  1414. static vpx_codec_err_t ctrl_register_cx_callback(vpx_codec_alg_priv_t *ctx,
  1415. va_list args) {
  1416. vpx_codec_priv_output_cx_pkt_cb_pair_t *cbp =
  1417. (vpx_codec_priv_output_cx_pkt_cb_pair_t *)va_arg(args, void *);
  1418. ctx->output_cx_pkt_cb.output_cx_pkt = cbp->output_cx_pkt;
  1419. ctx->output_cx_pkt_cb.user_priv = cbp->user_priv;
  1420. return VPX_CODEC_OK;
  1421. }
  1422. static vpx_codec_err_t ctrl_set_tune_content(vpx_codec_alg_priv_t *ctx,
  1423. va_list args) {
  1424. struct vp9_extracfg extra_cfg = ctx->extra_cfg;
  1425. extra_cfg.content = CAST(VP9E_SET_TUNE_CONTENT, args);
  1426. return update_extra_cfg(ctx, &extra_cfg);
  1427. }
  1428. static vpx_codec_err_t ctrl_set_color_space(vpx_codec_alg_priv_t *ctx,
  1429. va_list args) {
  1430. struct vp9_extracfg extra_cfg = ctx->extra_cfg;
  1431. extra_cfg.color_space = CAST(VP9E_SET_COLOR_SPACE, args);
  1432. return update_extra_cfg(ctx, &extra_cfg);
  1433. }
  1434. static vpx_codec_err_t ctrl_set_color_range(vpx_codec_alg_priv_t *ctx,
  1435. va_list args) {
  1436. struct vp9_extracfg extra_cfg = ctx->extra_cfg;
  1437. extra_cfg.color_range = CAST(VP9E_SET_COLOR_RANGE, args);
  1438. return update_extra_cfg(ctx, &extra_cfg);
  1439. }
  1440. static vpx_codec_err_t ctrl_set_render_size(vpx_codec_alg_priv_t *ctx,
  1441. va_list args) {
  1442. struct vp9_extracfg extra_cfg = ctx->extra_cfg;
  1443. int *const render_size = va_arg(args, int *);
  1444. extra_cfg.render_width = render_size[0];
  1445. extra_cfg.render_height = render_size[1];
  1446. return update_extra_cfg(ctx, &extra_cfg);
  1447. }
  1448. static vpx_codec_err_t ctrl_set_postencode_drop(vpx_codec_alg_priv_t *ctx,
  1449. va_list args) {
  1450. VP9_COMP *const cpi = ctx->cpi;
  1451. const unsigned int data = va_arg(args, unsigned int);
  1452. cpi->rc.ext_use_post_encode_drop = data;
  1453. return VPX_CODEC_OK;
  1454. }
  1455. static vpx_codec_ctrl_fn_map_t encoder_ctrl_maps[] = {
  1456. { VP8_COPY_REFERENCE, ctrl_copy_reference },
  1457. // Setters
  1458. { VP8_SET_REFERENCE, ctrl_set_reference },
  1459. { VP8_SET_POSTPROC, ctrl_set_previewpp },
  1460. { VP9E_SET_ROI_MAP, ctrl_set_roi_map },
  1461. { VP8E_SET_ACTIVEMAP, ctrl_set_active_map },
  1462. { VP8E_SET_SCALEMODE, ctrl_set_scale_mode },
  1463. { VP8E_SET_CPUUSED, ctrl_set_cpuused },
  1464. { VP8E_SET_ENABLEAUTOALTREF, ctrl_set_enable_auto_alt_ref },
  1465. { VP8E_SET_SHARPNESS, ctrl_set_sharpness },
  1466. { VP8E_SET_STATIC_THRESHOLD, ctrl_set_static_thresh },
  1467. { VP9E_SET_TILE_COLUMNS, ctrl_set_tile_columns },
  1468. { VP9E_SET_TILE_ROWS, ctrl_set_tile_rows },
  1469. { VP9E_SET_TPL, ctrl_set_tpl_model },
  1470. { VP8E_SET_ARNR_MAXFRAMES, ctrl_set_arnr_max_frames },
  1471. { VP8E_SET_ARNR_STRENGTH, ctrl_set_arnr_strength },
  1472. { VP8E_SET_ARNR_TYPE, ctrl_set_arnr_type },
  1473. { VP8E_SET_TUNING, ctrl_set_tuning },
  1474. { VP8E_SET_CQ_LEVEL, ctrl_set_cq_level },
  1475. { VP8E_SET_MAX_INTRA_BITRATE_PCT, ctrl_set_rc_max_intra_bitrate_pct },
  1476. { VP9E_SET_MAX_INTER_BITRATE_PCT, ctrl_set_rc_max_inter_bitrate_pct },
  1477. { VP9E_SET_GF_CBR_BOOST_PCT, ctrl_set_rc_gf_cbr_boost_pct },
  1478. { VP9E_SET_LOSSLESS, ctrl_set_lossless },
  1479. { VP9E_SET_FRAME_PARALLEL_DECODING, ctrl_set_frame_parallel_decoding_mode },
  1480. { VP9E_SET_AQ_MODE, ctrl_set_aq_mode },
  1481. { VP9E_SET_ALT_REF_AQ, ctrl_set_alt_ref_aq },
  1482. { VP9E_SET_FRAME_PERIODIC_BOOST, ctrl_set_frame_periodic_boost },
  1483. { VP9E_SET_SVC, ctrl_set_svc },
  1484. { VP9E_SET_SVC_PARAMETERS, ctrl_set_svc_parameters },
  1485. { VP9E_REGISTER_CX_CALLBACK, ctrl_register_cx_callback },
  1486. { VP9E_SET_SVC_LAYER_ID, ctrl_set_svc_layer_id },
  1487. { VP9E_SET_TUNE_CONTENT, ctrl_set_tune_content },
  1488. { VP9E_SET_COLOR_SPACE, ctrl_set_color_space },
  1489. { VP9E_SET_COLOR_RANGE, ctrl_set_color_range },
  1490. { VP9E_SET_NOISE_SENSITIVITY, ctrl_set_noise_sensitivity },
  1491. { VP9E_SET_MIN_GF_INTERVAL, ctrl_set_min_gf_interval },
  1492. { VP9E_SET_MAX_GF_INTERVAL, ctrl_set_max_gf_interval },
  1493. { VP9E_SET_SVC_REF_FRAME_CONFIG, ctrl_set_svc_ref_frame_config },
  1494. { VP9E_SET_RENDER_SIZE, ctrl_set_render_size },
  1495. { VP9E_SET_TARGET_LEVEL, ctrl_set_target_level },
  1496. { VP9E_SET_ROW_MT, ctrl_set_row_mt },
  1497. { VP9E_SET_POSTENCODE_DROP, ctrl_set_postencode_drop },
  1498. { VP9E_ENABLE_MOTION_VECTOR_UNIT_TEST, ctrl_enable_motion_vector_unit_test },
  1499. { VP9E_SET_SVC_INTER_LAYER_PRED, ctrl_set_svc_inter_layer_pred },
  1500. { VP9E_SET_SVC_FRAME_DROP_LAYER, ctrl_set_svc_frame_drop_layer },
  1501. { VP9E_SET_SVC_GF_TEMPORAL_REF, ctrl_set_svc_gf_temporal_ref },
  1502. { VP9E_SET_SVC_SPATIAL_LAYER_SYNC, ctrl_set_svc_spatial_layer_sync },
  1503. // Getters
  1504. { VP8E_GET_LAST_QUANTIZER, ctrl_get_quantizer },
  1505. { VP8E_GET_LAST_QUANTIZER_64, ctrl_get_quantizer64 },
  1506. { VP9_GET_REFERENCE, ctrl_get_reference },
  1507. { VP9E_GET_SVC_LAYER_ID, ctrl_get_svc_layer_id },
  1508. { VP9E_GET_ACTIVEMAP, ctrl_get_active_map },
  1509. { VP9E_GET_LEVEL, ctrl_get_level },
  1510. { VP9E_GET_SVC_REF_FRAME_CONFIG, ctrl_get_svc_ref_frame_config },
  1511. { -1, NULL },
  1512. };
  1513. static vpx_codec_enc_cfg_map_t encoder_usage_cfg_map[] = {
  1514. { 0,
  1515. {
  1516. // NOLINT
  1517. 0, // g_usage (unused)
  1518. 8, // g_threads
  1519. 0, // g_profile
  1520. 320, // g_width
  1521. 240, // g_height
  1522. VPX_BITS_8, // g_bit_depth
  1523. 8, // g_input_bit_depth
  1524. { 1, 30 }, // g_timebase
  1525. 0, // g_error_resilient
  1526. VPX_RC_ONE_PASS, // g_pass
  1527. 25, // g_lag_in_frames
  1528. 0, // rc_dropframe_thresh
  1529. 0, // rc_resize_allowed
  1530. 0, // rc_scaled_width
  1531. 0, // rc_scaled_height
  1532. 60, // rc_resize_down_thresold
  1533. 30, // rc_resize_up_thresold
  1534. VPX_VBR, // rc_end_usage
  1535. { NULL, 0 }, // rc_twopass_stats_in
  1536. { NULL, 0 }, // rc_firstpass_mb_stats_in
  1537. 256, // rc_target_bandwidth
  1538. 0, // rc_min_quantizer
  1539. 63, // rc_max_quantizer
  1540. 25, // rc_undershoot_pct
  1541. 25, // rc_overshoot_pct
  1542. 6000, // rc_max_buffer_size
  1543. 4000, // rc_buffer_initial_size
  1544. 5000, // rc_buffer_optimal_size
  1545. 50, // rc_two_pass_vbrbias
  1546. 0, // rc_two_pass_vbrmin_section
  1547. 2000, // rc_two_pass_vbrmax_section
  1548. 0, // rc_2pass_vbr_corpus_complexity (non 0 for corpus vbr)
  1549. // keyframing settings (kf)
  1550. VPX_KF_AUTO, // g_kfmode
  1551. 0, // kf_min_dist
  1552. 128, // kf_max_dist
  1553. VPX_SS_DEFAULT_LAYERS, // ss_number_layers
  1554. { 0 },
  1555. { 0 }, // ss_target_bitrate
  1556. 1, // ts_number_layers
  1557. { 0 }, // ts_target_bitrate
  1558. { 0 }, // ts_rate_decimator
  1559. 0, // ts_periodicity
  1560. { 0 }, // ts_layer_id
  1561. { 0 }, // layer_taget_bitrate
  1562. 0 // temporal_layering_mode
  1563. } },
  1564. };
  1565. #ifndef VERSION_STRING
  1566. #define VERSION_STRING
  1567. #endif
  1568. CODEC_INTERFACE(vpx_codec_vp9_cx) = {
  1569. "WebM Project VP9 Encoder" VERSION_STRING,
  1570. VPX_CODEC_INTERNAL_ABI_VERSION,
  1571. #if CONFIG_VP9_HIGHBITDEPTH
  1572. VPX_CODEC_CAP_HIGHBITDEPTH |
  1573. #endif
  1574. VPX_CODEC_CAP_ENCODER | VPX_CODEC_CAP_PSNR, // vpx_codec_caps_t
  1575. encoder_init, // vpx_codec_init_fn_t
  1576. encoder_destroy, // vpx_codec_destroy_fn_t
  1577. encoder_ctrl_maps, // vpx_codec_ctrl_fn_map_t
  1578. {
  1579. // NOLINT
  1580. NULL, // vpx_codec_peek_si_fn_t
  1581. NULL, // vpx_codec_get_si_fn_t
  1582. NULL, // vpx_codec_decode_fn_t
  1583. NULL, // vpx_codec_frame_get_fn_t
  1584. NULL // vpx_codec_set_fb_fn_t
  1585. },
  1586. {
  1587. // NOLINT
  1588. 1, // 1 cfg map
  1589. encoder_usage_cfg_map, // vpx_codec_enc_cfg_map_t
  1590. encoder_encode, // vpx_codec_encode_fn_t
  1591. encoder_get_cxdata, // vpx_codec_get_cx_data_fn_t
  1592. encoder_set_config, // vpx_codec_enc_config_set_fn_t
  1593. NULL, // vpx_codec_get_global_headers_fn_t
  1594. encoder_get_preview, // vpx_codec_get_preview_frame_fn_t
  1595. NULL // vpx_codec_enc_mr_get_mem_loc_fn_t
  1596. }
  1597. };