svc_datarate_test.cc 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428
  1. /*
  2. * Copyright (c) 2012 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 "./vpx_config.h"
  11. #include "third_party/googletest/src/include/gtest/gtest.h"
  12. #include "test/codec_factory.h"
  13. #include "test/encode_test_driver.h"
  14. #include "test/i420_video_source.h"
  15. #include "test/svc_test.h"
  16. #include "test/util.h"
  17. #include "test/y4m_video_source.h"
  18. #include "vp9/common/vp9_onyxc_int.h"
  19. #include "vpx/vpx_codec.h"
  20. #include "vpx_ports/bitops.h"
  21. namespace svc_test {
  22. namespace {
  23. typedef enum {
  24. // Inter-layer prediction is on on all frames.
  25. INTER_LAYER_PRED_ON,
  26. // Inter-layer prediction is off on all frames.
  27. INTER_LAYER_PRED_OFF,
  28. // Inter-layer prediction is off on non-key frames and non-sync frames.
  29. INTER_LAYER_PRED_OFF_NONKEY,
  30. // Inter-layer prediction is on on all frames, but constrained such
  31. // that any layer S (> 0) can only predict from previous spatial
  32. // layer S-1, from the same superframe.
  33. INTER_LAYER_PRED_ON_CONSTRAINED
  34. } INTER_LAYER_PRED;
  35. class DatarateOnePassCbrSvc : public OnePassCbrSvc {
  36. public:
  37. explicit DatarateOnePassCbrSvc(const ::libvpx_test::CodecFactory *codec)
  38. : OnePassCbrSvc(codec) {
  39. inter_layer_pred_mode_ = 0;
  40. }
  41. protected:
  42. virtual ~DatarateOnePassCbrSvc() {}
  43. virtual void ResetModel() {
  44. last_pts_ = 0;
  45. duration_ = 0.0;
  46. mismatch_psnr_ = 0.0;
  47. mismatch_nframes_ = 0;
  48. denoiser_on_ = 0;
  49. tune_content_ = 0;
  50. base_speed_setting_ = 5;
  51. spatial_layer_id_ = 0;
  52. temporal_layer_id_ = 0;
  53. update_pattern_ = 0;
  54. memset(bits_in_buffer_model_, 0, sizeof(bits_in_buffer_model_));
  55. memset(bits_total_, 0, sizeof(bits_total_));
  56. memset(layer_target_avg_bandwidth_, 0, sizeof(layer_target_avg_bandwidth_));
  57. dynamic_drop_layer_ = false;
  58. change_bitrate_ = false;
  59. last_pts_ref_ = 0;
  60. middle_bitrate_ = 0;
  61. top_bitrate_ = 0;
  62. superframe_count_ = -1;
  63. key_frame_spacing_ = 9999;
  64. num_nonref_frames_ = 0;
  65. layer_framedrop_ = 0;
  66. force_key_ = 0;
  67. force_key_test_ = 0;
  68. insert_layer_sync_ = 0;
  69. layer_sync_on_base_ = 0;
  70. force_intra_only_frame_ = 0;
  71. superframe_has_intra_only_ = 0;
  72. use_post_encode_drop_ = 0;
  73. denoiser_off_on_ = false;
  74. denoiser_enable_layers_ = false;
  75. }
  76. virtual void BeginPassHook(unsigned int /*pass*/) {}
  77. // Example pattern for spatial layers and 2 temporal layers used in the
  78. // bypass/flexible mode. The pattern corresponds to the pattern
  79. // VP9E_TEMPORAL_LAYERING_MODE_0101 (temporal_layering_mode == 2) used in
  80. // non-flexible mode, except that we disable inter-layer prediction.
  81. void set_frame_flags_bypass_mode(
  82. int tl, int num_spatial_layers, int is_key_frame,
  83. vpx_svc_ref_frame_config_t *ref_frame_config) {
  84. for (int sl = 0; sl < num_spatial_layers; ++sl)
  85. ref_frame_config->update_buffer_slot[sl] = 0;
  86. for (int sl = 0; sl < num_spatial_layers; ++sl) {
  87. if (tl == 0) {
  88. ref_frame_config->lst_fb_idx[sl] = sl;
  89. if (sl) {
  90. if (is_key_frame) {
  91. ref_frame_config->lst_fb_idx[sl] = sl - 1;
  92. ref_frame_config->gld_fb_idx[sl] = sl;
  93. } else {
  94. ref_frame_config->gld_fb_idx[sl] = sl - 1;
  95. }
  96. } else {
  97. ref_frame_config->gld_fb_idx[sl] = 0;
  98. }
  99. ref_frame_config->alt_fb_idx[sl] = 0;
  100. } else if (tl == 1) {
  101. ref_frame_config->lst_fb_idx[sl] = sl;
  102. ref_frame_config->gld_fb_idx[sl] =
  103. VPXMIN(REF_FRAMES - 1, num_spatial_layers + sl - 1);
  104. ref_frame_config->alt_fb_idx[sl] =
  105. VPXMIN(REF_FRAMES - 1, num_spatial_layers + sl);
  106. }
  107. if (!tl) {
  108. if (!sl) {
  109. ref_frame_config->reference_last[sl] = 1;
  110. ref_frame_config->reference_golden[sl] = 0;
  111. ref_frame_config->reference_alt_ref[sl] = 0;
  112. ref_frame_config->update_buffer_slot[sl] |=
  113. 1 << ref_frame_config->lst_fb_idx[sl];
  114. } else {
  115. if (is_key_frame) {
  116. ref_frame_config->reference_last[sl] = 1;
  117. ref_frame_config->reference_golden[sl] = 0;
  118. ref_frame_config->reference_alt_ref[sl] = 0;
  119. ref_frame_config->update_buffer_slot[sl] |=
  120. 1 << ref_frame_config->gld_fb_idx[sl];
  121. } else {
  122. ref_frame_config->reference_last[sl] = 1;
  123. ref_frame_config->reference_golden[sl] = 0;
  124. ref_frame_config->reference_alt_ref[sl] = 0;
  125. ref_frame_config->update_buffer_slot[sl] |=
  126. 1 << ref_frame_config->lst_fb_idx[sl];
  127. }
  128. }
  129. } else if (tl == 1) {
  130. if (!sl) {
  131. ref_frame_config->reference_last[sl] = 1;
  132. ref_frame_config->reference_golden[sl] = 0;
  133. ref_frame_config->reference_alt_ref[sl] = 0;
  134. ref_frame_config->update_buffer_slot[sl] |=
  135. 1 << ref_frame_config->alt_fb_idx[sl];
  136. } else {
  137. ref_frame_config->reference_last[sl] = 1;
  138. ref_frame_config->reference_golden[sl] = 0;
  139. ref_frame_config->reference_alt_ref[sl] = 0;
  140. ref_frame_config->update_buffer_slot[sl] |=
  141. 1 << ref_frame_config->alt_fb_idx[sl];
  142. }
  143. }
  144. }
  145. }
  146. void CheckLayerRateTargeting(int num_spatial_layers, int num_temporal_layers,
  147. double thresh_overshoot,
  148. double thresh_undershoot) const {
  149. for (int sl = 0; sl < num_spatial_layers; ++sl)
  150. for (int tl = 0; tl < num_temporal_layers; ++tl) {
  151. const int layer = sl * num_temporal_layers + tl;
  152. ASSERT_GE(cfg_.layer_target_bitrate[layer],
  153. file_datarate_[layer] * thresh_overshoot)
  154. << " The datarate for the file exceeds the target by too much!";
  155. ASSERT_LE(cfg_.layer_target_bitrate[layer],
  156. file_datarate_[layer] * thresh_undershoot)
  157. << " The datarate for the file is lower than the target by too "
  158. "much!";
  159. }
  160. }
  161. virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
  162. ::libvpx_test::Encoder *encoder) {
  163. PreEncodeFrameHookSetup(video, encoder);
  164. if (video->frame() == 0) {
  165. if (force_intra_only_frame_) {
  166. // Decoder sets the color_space for Intra-only frames
  167. // to BT_601 (see line 1810 in vp9_decodeframe.c).
  168. // So set it here in these tess to avoid encoder-decoder
  169. // mismatch check on color space setting.
  170. encoder->Control(VP9E_SET_COLOR_SPACE, VPX_CS_BT_601);
  171. }
  172. encoder->Control(VP9E_SET_NOISE_SENSITIVITY, denoiser_on_);
  173. encoder->Control(VP9E_SET_TUNE_CONTENT, tune_content_);
  174. encoder->Control(VP9E_SET_SVC_INTER_LAYER_PRED, inter_layer_pred_mode_);
  175. if (layer_framedrop_) {
  176. vpx_svc_frame_drop_t svc_drop_frame;
  177. svc_drop_frame.framedrop_mode = LAYER_DROP;
  178. for (int i = 0; i < number_spatial_layers_; i++)
  179. svc_drop_frame.framedrop_thresh[i] = 30;
  180. svc_drop_frame.max_consec_drop = 30;
  181. encoder->Control(VP9E_SET_SVC_FRAME_DROP_LAYER, &svc_drop_frame);
  182. }
  183. if (use_post_encode_drop_) {
  184. encoder->Control(VP9E_SET_POSTENCODE_DROP, use_post_encode_drop_);
  185. }
  186. }
  187. if (denoiser_off_on_) {
  188. encoder->Control(VP9E_SET_AQ_MODE, 3);
  189. // Set inter_layer_pred to INTER_LAYER_PRED_OFF_NONKEY (K-SVC).
  190. encoder->Control(VP9E_SET_SVC_INTER_LAYER_PRED, 2);
  191. if (!denoiser_enable_layers_) {
  192. if (video->frame() == 0)
  193. encoder->Control(VP9E_SET_NOISE_SENSITIVITY, 0);
  194. else if (video->frame() == 100)
  195. encoder->Control(VP9E_SET_NOISE_SENSITIVITY, 1);
  196. } else {
  197. // Cumulative bitrates for top spatial layers, for
  198. // 3 temporal layers.
  199. if (video->frame() == 0) {
  200. encoder->Control(VP9E_SET_NOISE_SENSITIVITY, 0);
  201. // Change layer bitrates to set top spatial layer to 0.
  202. // This is for 3 spatial 3 temporal layers.
  203. // This will trigger skip encoding/dropping of top spatial layer.
  204. cfg_.rc_target_bitrate -= cfg_.layer_target_bitrate[8];
  205. for (int i = 0; i < 3; i++)
  206. bitrate_sl3_[i] = cfg_.layer_target_bitrate[i + 6];
  207. cfg_.layer_target_bitrate[6] = 0;
  208. cfg_.layer_target_bitrate[7] = 0;
  209. cfg_.layer_target_bitrate[8] = 0;
  210. encoder->Config(&cfg_);
  211. } else if (video->frame() == 100) {
  212. // Change layer bitrates to non-zero on top spatial layer.
  213. // This will trigger skip encoding of top spatial layer
  214. // on key frame (period = 100).
  215. for (int i = 0; i < 3; i++)
  216. cfg_.layer_target_bitrate[i + 6] = bitrate_sl3_[i];
  217. cfg_.rc_target_bitrate += cfg_.layer_target_bitrate[8];
  218. encoder->Config(&cfg_);
  219. } else if (video->frame() == 120) {
  220. // Enable denoiser and top spatial layer after key frame (period is
  221. // 100).
  222. encoder->Control(VP9E_SET_NOISE_SENSITIVITY, 1);
  223. }
  224. }
  225. }
  226. if (update_pattern_ && video->frame() >= 100) {
  227. vpx_svc_layer_id_t layer_id;
  228. if (video->frame() == 100) {
  229. cfg_.temporal_layering_mode = VP9E_TEMPORAL_LAYERING_MODE_BYPASS;
  230. encoder->Config(&cfg_);
  231. }
  232. // Set layer id since the pattern changed.
  233. layer_id.spatial_layer_id = 0;
  234. layer_id.temporal_layer_id = (video->frame() % 2 != 0);
  235. temporal_layer_id_ = layer_id.temporal_layer_id;
  236. for (int i = 0; i < number_spatial_layers_; i++)
  237. layer_id.temporal_layer_id_per_spatial[i] = temporal_layer_id_;
  238. encoder->Control(VP9E_SET_SVC_LAYER_ID, &layer_id);
  239. set_frame_flags_bypass_mode(layer_id.temporal_layer_id,
  240. number_spatial_layers_, 0, &ref_frame_config);
  241. encoder->Control(VP9E_SET_SVC_REF_FRAME_CONFIG, &ref_frame_config);
  242. }
  243. if (change_bitrate_ && video->frame() == 200) {
  244. duration_ = (last_pts_ + 1) * timebase_;
  245. for (int sl = 0; sl < number_spatial_layers_; ++sl) {
  246. for (int tl = 0; tl < number_temporal_layers_; ++tl) {
  247. const int layer = sl * number_temporal_layers_ + tl;
  248. const double file_size_in_kb = bits_total_[layer] / 1000.;
  249. file_datarate_[layer] = file_size_in_kb / duration_;
  250. }
  251. }
  252. CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_,
  253. 0.78, 1.15);
  254. memset(file_datarate_, 0, sizeof(file_datarate_));
  255. memset(bits_total_, 0, sizeof(bits_total_));
  256. int64_t bits_in_buffer_model_tmp[VPX_MAX_LAYERS];
  257. last_pts_ref_ = last_pts_;
  258. // Set new target bitarate.
  259. cfg_.rc_target_bitrate = cfg_.rc_target_bitrate >> 1;
  260. // Buffer level should not reset on dynamic bitrate change.
  261. memcpy(bits_in_buffer_model_tmp, bits_in_buffer_model_,
  262. sizeof(bits_in_buffer_model_));
  263. AssignLayerBitrates();
  264. memcpy(bits_in_buffer_model_, bits_in_buffer_model_tmp,
  265. sizeof(bits_in_buffer_model_));
  266. // Change config to update encoder with new bitrate configuration.
  267. encoder->Config(&cfg_);
  268. }
  269. if (dynamic_drop_layer_) {
  270. // TODO(jian): Disable AQ Mode for this test for now.
  271. encoder->Control(VP9E_SET_AQ_MODE, 0);
  272. if (video->frame() == 0) {
  273. // Change layer bitrates to set top layers to 0. This will trigger skip
  274. // encoding/dropping of top two spatial layers.
  275. cfg_.rc_target_bitrate -=
  276. (cfg_.layer_target_bitrate[1] + cfg_.layer_target_bitrate[2]);
  277. middle_bitrate_ = cfg_.layer_target_bitrate[1];
  278. top_bitrate_ = cfg_.layer_target_bitrate[2];
  279. cfg_.layer_target_bitrate[1] = 0;
  280. cfg_.layer_target_bitrate[2] = 0;
  281. encoder->Config(&cfg_);
  282. } else if (video->frame() == 50) {
  283. // Change layer bitrates to non-zero on two top spatial layers.
  284. // This will trigger skip encoding of top two spatial layers.
  285. cfg_.layer_target_bitrate[1] = middle_bitrate_;
  286. cfg_.layer_target_bitrate[2] = top_bitrate_;
  287. cfg_.rc_target_bitrate +=
  288. cfg_.layer_target_bitrate[2] + cfg_.layer_target_bitrate[1];
  289. encoder->Config(&cfg_);
  290. } else if (video->frame() == 100) {
  291. // Change layer bitrates to set top layers to 0. This will trigger skip
  292. // encoding/dropping of top two spatial layers.
  293. cfg_.rc_target_bitrate -=
  294. (cfg_.layer_target_bitrate[1] + cfg_.layer_target_bitrate[2]);
  295. middle_bitrate_ = cfg_.layer_target_bitrate[1];
  296. top_bitrate_ = cfg_.layer_target_bitrate[2];
  297. cfg_.layer_target_bitrate[1] = 0;
  298. cfg_.layer_target_bitrate[2] = 0;
  299. encoder->Config(&cfg_);
  300. } else if (video->frame() == 150) {
  301. // Change layer bitrate on second layer to non-zero to start
  302. // encoding it again.
  303. cfg_.layer_target_bitrate[1] = middle_bitrate_;
  304. cfg_.rc_target_bitrate += cfg_.layer_target_bitrate[1];
  305. encoder->Config(&cfg_);
  306. } else if (video->frame() == 200) {
  307. // Change layer bitrate on top layer to non-zero to start
  308. // encoding it again.
  309. cfg_.layer_target_bitrate[2] = top_bitrate_;
  310. cfg_.rc_target_bitrate += cfg_.layer_target_bitrate[2];
  311. encoder->Config(&cfg_);
  312. }
  313. }
  314. if (force_key_test_ && force_key_) frame_flags_ = VPX_EFLAG_FORCE_KF;
  315. if (insert_layer_sync_) {
  316. vpx_svc_spatial_layer_sync_t svc_layer_sync;
  317. svc_layer_sync.base_layer_intra_only = 0;
  318. for (int i = 0; i < number_spatial_layers_; i++)
  319. svc_layer_sync.spatial_layer_sync[i] = 0;
  320. if (force_intra_only_frame_) {
  321. superframe_has_intra_only_ = 0;
  322. if (video->frame() == 0) {
  323. svc_layer_sync.base_layer_intra_only = 1;
  324. svc_layer_sync.spatial_layer_sync[0] = 1;
  325. encoder->Control(VP9E_SET_SVC_SPATIAL_LAYER_SYNC, &svc_layer_sync);
  326. superframe_has_intra_only_ = 1;
  327. } else if (video->frame() == 100) {
  328. svc_layer_sync.base_layer_intra_only = 1;
  329. svc_layer_sync.spatial_layer_sync[0] = 1;
  330. encoder->Control(VP9E_SET_SVC_SPATIAL_LAYER_SYNC, &svc_layer_sync);
  331. superframe_has_intra_only_ = 1;
  332. }
  333. } else {
  334. layer_sync_on_base_ = 0;
  335. if (video->frame() == 150) {
  336. svc_layer_sync.spatial_layer_sync[1] = 1;
  337. encoder->Control(VP9E_SET_SVC_SPATIAL_LAYER_SYNC, &svc_layer_sync);
  338. } else if (video->frame() == 240) {
  339. svc_layer_sync.spatial_layer_sync[2] = 1;
  340. encoder->Control(VP9E_SET_SVC_SPATIAL_LAYER_SYNC, &svc_layer_sync);
  341. } else if (video->frame() == 320) {
  342. svc_layer_sync.spatial_layer_sync[0] = 1;
  343. layer_sync_on_base_ = 1;
  344. encoder->Control(VP9E_SET_SVC_SPATIAL_LAYER_SYNC, &svc_layer_sync);
  345. }
  346. }
  347. }
  348. const vpx_rational_t tb = video->timebase();
  349. timebase_ = static_cast<double>(tb.num) / tb.den;
  350. duration_ = 0;
  351. }
  352. vpx_codec_err_t parse_superframe_index(const uint8_t *data, size_t data_sz,
  353. uint32_t sizes[8], int *count) {
  354. uint8_t marker;
  355. marker = *(data + data_sz - 1);
  356. *count = 0;
  357. if ((marker & 0xe0) == 0xc0) {
  358. const uint32_t frames = (marker & 0x7) + 1;
  359. const uint32_t mag = ((marker >> 3) & 0x3) + 1;
  360. const size_t index_sz = 2 + mag * frames;
  361. // This chunk is marked as having a superframe index but doesn't have
  362. // enough data for it, thus it's an invalid superframe index.
  363. if (data_sz < index_sz) return VPX_CODEC_CORRUPT_FRAME;
  364. {
  365. const uint8_t marker2 = *(data + data_sz - index_sz);
  366. // This chunk is marked as having a superframe index but doesn't have
  367. // the matching marker byte at the front of the index therefore it's an
  368. // invalid chunk.
  369. if (marker != marker2) return VPX_CODEC_CORRUPT_FRAME;
  370. }
  371. {
  372. uint32_t i, j;
  373. const uint8_t *x = &data[data_sz - index_sz + 1];
  374. for (i = 0; i < frames; ++i) {
  375. uint32_t this_sz = 0;
  376. for (j = 0; j < mag; ++j) this_sz |= (*x++) << (j * 8);
  377. sizes[i] = this_sz;
  378. }
  379. *count = frames;
  380. }
  381. }
  382. return VPX_CODEC_OK;
  383. }
  384. virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) {
  385. uint32_t sizes[8] = { 0 };
  386. uint32_t sizes_parsed[8] = { 0 };
  387. int count = 0;
  388. int num_layers_encoded = 0;
  389. last_pts_ = pkt->data.frame.pts;
  390. const bool key_frame =
  391. (pkt->data.frame.flags & VPX_FRAME_IS_KEY) ? true : false;
  392. if (key_frame) {
  393. // For test that inserts layer sync frames: requesting a layer_sync on
  394. // the base layer must force key frame. So if any key frame occurs after
  395. // first superframe it must due to layer sync on base spatial layer.
  396. if (superframe_count_ > 0 && insert_layer_sync_ &&
  397. !force_intra_only_frame_) {
  398. ASSERT_EQ(layer_sync_on_base_, 1);
  399. }
  400. temporal_layer_id_ = 0;
  401. superframe_count_ = 0;
  402. }
  403. parse_superframe_index(static_cast<const uint8_t *>(pkt->data.frame.buf),
  404. pkt->data.frame.sz, sizes_parsed, &count);
  405. // Count may be less than number of spatial layers because of frame drops.
  406. for (int sl = 0; sl < number_spatial_layers_; ++sl) {
  407. if (pkt->data.frame.spatial_layer_encoded[sl]) {
  408. sizes[sl] = sizes_parsed[num_layers_encoded];
  409. num_layers_encoded++;
  410. }
  411. }
  412. // For superframe with Intra-only count will be +1 larger
  413. // because of no-show frame.
  414. if (force_intra_only_frame_ && superframe_has_intra_only_)
  415. ASSERT_EQ(count, num_layers_encoded + 1);
  416. else
  417. ASSERT_EQ(count, num_layers_encoded);
  418. // In the constrained frame drop mode, if a given spatial is dropped all
  419. // upper layers must be dropped too.
  420. if (!layer_framedrop_) {
  421. int num_layers_dropped = 0;
  422. for (int sl = 0; sl < number_spatial_layers_; ++sl) {
  423. if (!pkt->data.frame.spatial_layer_encoded[sl]) {
  424. // Check that all upper layers are dropped.
  425. num_layers_dropped++;
  426. for (int sl2 = sl + 1; sl2 < number_spatial_layers_; ++sl2)
  427. ASSERT_EQ(pkt->data.frame.spatial_layer_encoded[sl2], 0);
  428. }
  429. }
  430. if (num_layers_dropped == number_spatial_layers_ - 1)
  431. force_key_ = 1;
  432. else
  433. force_key_ = 0;
  434. }
  435. // Keep track of number of non-reference frames, needed for mismatch check.
  436. // Non-reference frames are top spatial and temporal layer frames,
  437. // for TL > 0.
  438. if (temporal_layer_id_ == number_temporal_layers_ - 1 &&
  439. temporal_layer_id_ > 0 &&
  440. pkt->data.frame.spatial_layer_encoded[number_spatial_layers_ - 1])
  441. num_nonref_frames_++;
  442. for (int sl = 0; sl < number_spatial_layers_; ++sl) {
  443. sizes[sl] = sizes[sl] << 3;
  444. // Update the total encoded bits per layer.
  445. // For temporal layers, update the cumulative encoded bits per layer.
  446. for (int tl = temporal_layer_id_; tl < number_temporal_layers_; ++tl) {
  447. const int layer = sl * number_temporal_layers_ + tl;
  448. bits_total_[layer] += static_cast<int64_t>(sizes[sl]);
  449. // Update the per-layer buffer level with the encoded frame size.
  450. bits_in_buffer_model_[layer] -= static_cast<int64_t>(sizes[sl]);
  451. // There should be no buffer underrun, except on the base
  452. // temporal layer, since there may be key frames there.
  453. // Fo short key frame spacing, buffer can underrun on individual frames.
  454. if (!key_frame && tl > 0 && key_frame_spacing_ < 100) {
  455. ASSERT_GE(bits_in_buffer_model_[layer], 0)
  456. << "Buffer Underrun at frame " << pkt->data.frame.pts;
  457. }
  458. }
  459. ASSERT_EQ(pkt->data.frame.width[sl],
  460. top_sl_width_ * svc_params_.scaling_factor_num[sl] /
  461. svc_params_.scaling_factor_den[sl]);
  462. ASSERT_EQ(pkt->data.frame.height[sl],
  463. top_sl_height_ * svc_params_.scaling_factor_num[sl] /
  464. svc_params_.scaling_factor_den[sl]);
  465. }
  466. }
  467. virtual void EndPassHook(void) {
  468. if (change_bitrate_) last_pts_ = last_pts_ - last_pts_ref_;
  469. duration_ = (last_pts_ + 1) * timebase_;
  470. for (int sl = 0; sl < number_spatial_layers_; ++sl) {
  471. for (int tl = 0; tl < number_temporal_layers_; ++tl) {
  472. const int layer = sl * number_temporal_layers_ + tl;
  473. const double file_size_in_kb = bits_total_[layer] / 1000.;
  474. file_datarate_[layer] = file_size_in_kb / duration_;
  475. }
  476. }
  477. }
  478. virtual void MismatchHook(const vpx_image_t *img1, const vpx_image_t *img2) {
  479. double mismatch_psnr = compute_psnr(img1, img2);
  480. mismatch_psnr_ += mismatch_psnr;
  481. ++mismatch_nframes_;
  482. }
  483. unsigned int GetMismatchFrames() { return mismatch_nframes_; }
  484. unsigned int GetNonRefFrames() { return num_nonref_frames_; }
  485. vpx_codec_pts_t last_pts_;
  486. double timebase_;
  487. int64_t bits_total_[VPX_MAX_LAYERS];
  488. double duration_;
  489. double file_datarate_[VPX_MAX_LAYERS];
  490. size_t bits_in_last_frame_;
  491. double mismatch_psnr_;
  492. int denoiser_on_;
  493. int tune_content_;
  494. int spatial_layer_id_;
  495. bool dynamic_drop_layer_;
  496. unsigned int top_sl_width_;
  497. unsigned int top_sl_height_;
  498. vpx_svc_ref_frame_config_t ref_frame_config;
  499. int update_pattern_;
  500. bool change_bitrate_;
  501. vpx_codec_pts_t last_pts_ref_;
  502. int middle_bitrate_;
  503. int top_bitrate_;
  504. int key_frame_spacing_;
  505. int layer_framedrop_;
  506. int force_key_;
  507. int force_key_test_;
  508. int inter_layer_pred_mode_;
  509. int insert_layer_sync_;
  510. int layer_sync_on_base_;
  511. int force_intra_only_frame_;
  512. int superframe_has_intra_only_;
  513. int use_post_encode_drop_;
  514. int bitrate_sl3_[3];
  515. // Denoiser switched on the fly.
  516. bool denoiser_off_on_;
  517. // Top layer enabled on the fly.
  518. bool denoiser_enable_layers_;
  519. private:
  520. virtual void SetConfig(const int num_temporal_layer) {
  521. cfg_.rc_end_usage = VPX_CBR;
  522. cfg_.g_lag_in_frames = 0;
  523. cfg_.g_error_resilient = 1;
  524. if (num_temporal_layer == 3) {
  525. cfg_.ts_rate_decimator[0] = 4;
  526. cfg_.ts_rate_decimator[1] = 2;
  527. cfg_.ts_rate_decimator[2] = 1;
  528. cfg_.temporal_layering_mode = 3;
  529. } else if (num_temporal_layer == 2) {
  530. cfg_.ts_rate_decimator[0] = 2;
  531. cfg_.ts_rate_decimator[1] = 1;
  532. cfg_.temporal_layering_mode = 2;
  533. } else if (num_temporal_layer == 1) {
  534. cfg_.ts_rate_decimator[0] = 1;
  535. cfg_.temporal_layering_mode = 0;
  536. }
  537. }
  538. unsigned int num_nonref_frames_;
  539. unsigned int mismatch_nframes_;
  540. };
  541. // Params: speed setting.
  542. class DatarateOnePassCbrSvcSingleBR
  543. : public DatarateOnePassCbrSvc,
  544. public ::libvpx_test::CodecTestWithParam<int> {
  545. public:
  546. DatarateOnePassCbrSvcSingleBR() : DatarateOnePassCbrSvc(GET_PARAM(0)) {
  547. memset(&svc_params_, 0, sizeof(svc_params_));
  548. }
  549. virtual ~DatarateOnePassCbrSvcSingleBR() {}
  550. protected:
  551. virtual void SetUp() {
  552. InitializeConfig();
  553. SetMode(::libvpx_test::kRealTime);
  554. speed_setting_ = GET_PARAM(1);
  555. ResetModel();
  556. }
  557. };
  558. // Check basic rate targeting for 1 pass CBR SVC: 2 spatial layers and 1
  559. // temporal layer, with screen content mode on and same speed setting for all
  560. // layers.
  561. TEST_P(DatarateOnePassCbrSvcSingleBR, OnePassCbrSvc2SL1TLScreenContent1) {
  562. SetSvcConfig(2, 1);
  563. cfg_.rc_buf_initial_sz = 500;
  564. cfg_.rc_buf_optimal_sz = 500;
  565. cfg_.rc_buf_sz = 1000;
  566. cfg_.rc_min_quantizer = 0;
  567. cfg_.rc_max_quantizer = 63;
  568. cfg_.g_threads = 1;
  569. cfg_.rc_dropframe_thresh = 10;
  570. cfg_.kf_max_dist = 9999;
  571. ::libvpx_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60);
  572. top_sl_width_ = 1280;
  573. top_sl_height_ = 720;
  574. cfg_.rc_target_bitrate = 500;
  575. ResetModel();
  576. tune_content_ = 1;
  577. AssignLayerBitrates();
  578. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  579. CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.78,
  580. 1.15);
  581. #if CONFIG_VP9_DECODER
  582. // The non-reference frames are expected to be mismatched frames as the
  583. // encoder will avoid loopfilter on these frames.
  584. EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames());
  585. #endif
  586. }
  587. // Check basic rate targeting for 1 pass CBR SVC: 3 spatial layers and
  588. // 3 temporal layers, with force key frame after frame drop
  589. TEST_P(DatarateOnePassCbrSvcSingleBR, OnePassCbrSvc3SL3TLForceKey) {
  590. SetSvcConfig(3, 3);
  591. cfg_.rc_buf_initial_sz = 500;
  592. cfg_.rc_buf_optimal_sz = 500;
  593. cfg_.rc_buf_sz = 1000;
  594. cfg_.rc_min_quantizer = 0;
  595. cfg_.rc_max_quantizer = 63;
  596. cfg_.g_threads = 1;
  597. cfg_.rc_dropframe_thresh = 30;
  598. cfg_.kf_max_dist = 9999;
  599. ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
  600. 0, 400);
  601. top_sl_width_ = 640;
  602. top_sl_height_ = 480;
  603. cfg_.rc_target_bitrate = 100;
  604. ResetModel();
  605. AssignLayerBitrates();
  606. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  607. CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.78,
  608. 1.25);
  609. #if CONFIG_VP9_DECODER
  610. // The non-reference frames are expected to be mismatched frames as the
  611. // encoder will avoid loopfilter on these frames.
  612. EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames());
  613. #endif
  614. }
  615. // Check basic rate targeting for 1 pass CBR SVC: 3 spatial layers and
  616. // 2 temporal layers, with a change on the fly from the fixed SVC pattern to one
  617. // generate via SVC_SET_REF_FRAME_CONFIG. The new pattern also disables
  618. // inter-layer prediction.
  619. TEST_P(DatarateOnePassCbrSvcSingleBR, OnePassCbrSvc3SL2TLDynamicPatternChange) {
  620. SetSvcConfig(3, 2);
  621. cfg_.rc_buf_initial_sz = 500;
  622. cfg_.rc_buf_optimal_sz = 500;
  623. cfg_.rc_buf_sz = 1000;
  624. cfg_.rc_min_quantizer = 0;
  625. cfg_.rc_max_quantizer = 63;
  626. cfg_.g_threads = 1;
  627. cfg_.rc_dropframe_thresh = 30;
  628. cfg_.kf_max_dist = 9999;
  629. // Change SVC pattern on the fly.
  630. update_pattern_ = 1;
  631. ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
  632. 0, 400);
  633. top_sl_width_ = 640;
  634. top_sl_height_ = 480;
  635. cfg_.rc_target_bitrate = 800;
  636. ResetModel();
  637. AssignLayerBitrates();
  638. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  639. CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.78,
  640. 1.15);
  641. #if CONFIG_VP9_DECODER
  642. // The non-reference frames are expected to be mismatched frames as the
  643. // encoder will avoid loopfilter on these frames.
  644. EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames());
  645. #endif
  646. }
  647. // Check basic rate targeting for 1 pass CBR SVC with 3 spatial and 3 temporal
  648. // layers, for inter_layer_pred=OffKey (K-SVC) and on the fly switching
  649. // of denoiser from off to on (on at frame = 100). Key frame period is set to
  650. // 1000 so denoise is enabled on non-key.
  651. TEST_P(DatarateOnePassCbrSvcSingleBR,
  652. OnePassCbrSvc3SL3TL_DenoiserOffOnFixedLayers) {
  653. SetSvcConfig(3, 3);
  654. cfg_.rc_buf_initial_sz = 500;
  655. cfg_.rc_buf_optimal_sz = 500;
  656. cfg_.rc_buf_sz = 1000;
  657. cfg_.rc_min_quantizer = 0;
  658. cfg_.rc_max_quantizer = 63;
  659. cfg_.g_threads = 1;
  660. cfg_.rc_dropframe_thresh = 30;
  661. cfg_.kf_max_dist = 1000;
  662. ::libvpx_test::I420VideoSource video("desktop_office1.1280_720-020.yuv", 1280,
  663. 720, 30, 1, 0, 300);
  664. top_sl_width_ = 1280;
  665. top_sl_height_ = 720;
  666. cfg_.rc_target_bitrate = 1000;
  667. ResetModel();
  668. denoiser_off_on_ = true;
  669. denoiser_enable_layers_ = false;
  670. AssignLayerBitrates();
  671. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  672. // Don't check rate targeting on two top spatial layer since they will be
  673. // skipped for part of the sequence.
  674. CheckLayerRateTargeting(number_spatial_layers_ - 2, number_temporal_layers_,
  675. 0.78, 1.15);
  676. #if CONFIG_VP9_DECODER
  677. // The non-reference frames are expected to be mismatched frames as the
  678. // encoder will avoid loopfilter on these frames.
  679. EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames());
  680. #endif
  681. }
  682. // Check basic rate targeting for 1 pass CBR SVC with 3 spatial and 3 temporal
  683. // layers, for inter_layer_pred=OffKey (K-SVC) and on the fly switching
  684. // of denoiser from off to on, for dynamic layers. Start at 2 spatial layers
  685. // and enable 3rd spatial layer at frame = 100. Use periodic key frame with
  686. // period 100 so enabling of spatial layer occurs at key frame. Enable denoiser
  687. // at frame > 100, after the key frame sync.
  688. TEST_P(DatarateOnePassCbrSvcSingleBR,
  689. OnePassCbrSvc3SL3TL_DenoiserOffOnEnableLayers) {
  690. SetSvcConfig(3, 3);
  691. cfg_.rc_buf_initial_sz = 500;
  692. cfg_.rc_buf_optimal_sz = 500;
  693. cfg_.rc_buf_sz = 1000;
  694. cfg_.rc_min_quantizer = 0;
  695. cfg_.rc_max_quantizer = 63;
  696. cfg_.g_threads = 1;
  697. cfg_.rc_dropframe_thresh = 0;
  698. cfg_.kf_max_dist = 100;
  699. ::libvpx_test::I420VideoSource video("desktop_office1.1280_720-020.yuv", 1280,
  700. 720, 30, 1, 0, 300);
  701. top_sl_width_ = 1280;
  702. top_sl_height_ = 720;
  703. cfg_.rc_target_bitrate = 1000;
  704. ResetModel();
  705. denoiser_off_on_ = true;
  706. denoiser_enable_layers_ = true;
  707. AssignLayerBitrates();
  708. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  709. // Don't check rate targeting on two top spatial layer since they will be
  710. // skipped for part of the sequence.
  711. CheckLayerRateTargeting(number_spatial_layers_ - 2, number_temporal_layers_,
  712. 0.78, 1.15);
  713. #if CONFIG_VP9_DECODER
  714. // The non-reference frames are expected to be mismatched frames as the
  715. // encoder will avoid loopfilter on these frames.
  716. EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames());
  717. #endif
  718. }
  719. // Check basic rate targeting for 1 pass CBR SVC with 3 spatial layers and on
  720. // the fly switching to 1 and then 2 and back to 3 spatial layers. This switch
  721. // is done by setting spatial layer bitrates to 0, and then back to non-zero,
  722. // during the sequence.
  723. TEST_P(DatarateOnePassCbrSvcSingleBR, OnePassCbrSvc3SL_DisableEnableLayers) {
  724. SetSvcConfig(3, 1);
  725. cfg_.rc_buf_initial_sz = 500;
  726. cfg_.rc_buf_optimal_sz = 500;
  727. cfg_.rc_buf_sz = 1000;
  728. cfg_.rc_min_quantizer = 0;
  729. cfg_.rc_max_quantizer = 63;
  730. cfg_.g_threads = 1;
  731. cfg_.temporal_layering_mode = 0;
  732. cfg_.rc_dropframe_thresh = 30;
  733. cfg_.kf_max_dist = 9999;
  734. ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
  735. 0, 400);
  736. top_sl_width_ = 640;
  737. top_sl_height_ = 480;
  738. cfg_.rc_target_bitrate = 800;
  739. ResetModel();
  740. dynamic_drop_layer_ = true;
  741. AssignLayerBitrates();
  742. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  743. // Don't check rate targeting on two top spatial layer since they will be
  744. // skipped for part of the sequence.
  745. CheckLayerRateTargeting(number_spatial_layers_ - 2, number_temporal_layers_,
  746. 0.78, 1.15);
  747. #if CONFIG_VP9_DECODER
  748. // The non-reference frames are expected to be mismatched frames as the
  749. // encoder will avoid loopfilter on these frames.
  750. EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames());
  751. #endif
  752. }
  753. // Run SVC encoder for 1 temporal layer, 2 spatial layers, with spatial
  754. // downscale 5x5.
  755. TEST_P(DatarateOnePassCbrSvcSingleBR, OnePassCbrSvc2SL1TL5x5MultipleRuns) {
  756. cfg_.rc_buf_initial_sz = 500;
  757. cfg_.rc_buf_optimal_sz = 500;
  758. cfg_.rc_buf_sz = 1000;
  759. cfg_.rc_min_quantizer = 0;
  760. cfg_.rc_max_quantizer = 63;
  761. cfg_.rc_end_usage = VPX_CBR;
  762. cfg_.g_lag_in_frames = 0;
  763. cfg_.ss_number_layers = 2;
  764. cfg_.ts_number_layers = 1;
  765. cfg_.ts_rate_decimator[0] = 1;
  766. cfg_.g_error_resilient = 1;
  767. cfg_.g_threads = 3;
  768. cfg_.temporal_layering_mode = 0;
  769. svc_params_.scaling_factor_num[0] = 256;
  770. svc_params_.scaling_factor_den[0] = 1280;
  771. svc_params_.scaling_factor_num[1] = 1280;
  772. svc_params_.scaling_factor_den[1] = 1280;
  773. cfg_.rc_dropframe_thresh = 10;
  774. cfg_.kf_max_dist = 999999;
  775. cfg_.kf_min_dist = 0;
  776. cfg_.ss_target_bitrate[0] = 300;
  777. cfg_.ss_target_bitrate[1] = 1400;
  778. cfg_.layer_target_bitrate[0] = 300;
  779. cfg_.layer_target_bitrate[1] = 1400;
  780. cfg_.rc_target_bitrate = 1700;
  781. number_spatial_layers_ = cfg_.ss_number_layers;
  782. number_temporal_layers_ = cfg_.ts_number_layers;
  783. ResetModel();
  784. layer_target_avg_bandwidth_[0] = cfg_.layer_target_bitrate[0] * 1000 / 30;
  785. bits_in_buffer_model_[0] =
  786. cfg_.layer_target_bitrate[0] * cfg_.rc_buf_initial_sz;
  787. layer_target_avg_bandwidth_[1] = cfg_.layer_target_bitrate[1] * 1000 / 30;
  788. bits_in_buffer_model_[1] =
  789. cfg_.layer_target_bitrate[1] * cfg_.rc_buf_initial_sz;
  790. ::libvpx_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60);
  791. top_sl_width_ = 1280;
  792. top_sl_height_ = 720;
  793. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  794. CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.78,
  795. 1.15);
  796. #if CONFIG_VP9_DECODER
  797. // The non-reference frames are expected to be mismatched frames as the
  798. // encoder will avoid loopfilter on these frames.
  799. EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames());
  800. #endif
  801. }
  802. // Params: speed setting and index for bitrate array.
  803. class DatarateOnePassCbrSvcMultiBR
  804. : public DatarateOnePassCbrSvc,
  805. public ::libvpx_test::CodecTestWith2Params<int, int> {
  806. public:
  807. DatarateOnePassCbrSvcMultiBR() : DatarateOnePassCbrSvc(GET_PARAM(0)) {
  808. memset(&svc_params_, 0, sizeof(svc_params_));
  809. }
  810. virtual ~DatarateOnePassCbrSvcMultiBR() {}
  811. protected:
  812. virtual void SetUp() {
  813. InitializeConfig();
  814. SetMode(::libvpx_test::kRealTime);
  815. speed_setting_ = GET_PARAM(1);
  816. ResetModel();
  817. }
  818. };
  819. // Check basic rate targeting for 1 pass CBR SVC: 2 spatial layers and
  820. // 3 temporal layers. Run CIF clip with 1 thread.
  821. TEST_P(DatarateOnePassCbrSvcMultiBR, OnePassCbrSvc2SL3TL) {
  822. SetSvcConfig(2, 3);
  823. cfg_.rc_buf_initial_sz = 500;
  824. cfg_.rc_buf_optimal_sz = 500;
  825. cfg_.rc_buf_sz = 1000;
  826. cfg_.rc_min_quantizer = 0;
  827. cfg_.rc_max_quantizer = 63;
  828. cfg_.g_threads = 1;
  829. cfg_.rc_dropframe_thresh = 30;
  830. cfg_.kf_max_dist = 9999;
  831. ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
  832. 0, 400);
  833. top_sl_width_ = 640;
  834. top_sl_height_ = 480;
  835. const int bitrates[3] = { 200, 400, 600 };
  836. // TODO(marpan): Check that effective_datarate for each layer hits the
  837. // layer target_bitrate.
  838. cfg_.rc_target_bitrate = bitrates[GET_PARAM(2)];
  839. ResetModel();
  840. AssignLayerBitrates();
  841. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  842. CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.75,
  843. 1.2);
  844. #if CONFIG_VP9_DECODER
  845. // The non-reference frames are expected to be mismatched frames as the
  846. // encoder will avoid loopfilter on these frames.
  847. EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames());
  848. #endif
  849. }
  850. // Params: speed setting, layer framedrop control and index for bitrate array.
  851. class DatarateOnePassCbrSvcFrameDropMultiBR
  852. : public DatarateOnePassCbrSvc,
  853. public ::libvpx_test::CodecTestWith3Params<int, int, int> {
  854. public:
  855. DatarateOnePassCbrSvcFrameDropMultiBR()
  856. : DatarateOnePassCbrSvc(GET_PARAM(0)) {
  857. memset(&svc_params_, 0, sizeof(svc_params_));
  858. }
  859. virtual ~DatarateOnePassCbrSvcFrameDropMultiBR() {}
  860. protected:
  861. virtual void SetUp() {
  862. InitializeConfig();
  863. SetMode(::libvpx_test::kRealTime);
  864. speed_setting_ = GET_PARAM(1);
  865. ResetModel();
  866. }
  867. };
  868. // Check basic rate targeting for 1 pass CBR SVC: 2 spatial layers and
  869. // 3 temporal layers. Run HD clip with 4 threads.
  870. TEST_P(DatarateOnePassCbrSvcFrameDropMultiBR, OnePassCbrSvc2SL3TL4Threads) {
  871. SetSvcConfig(2, 3);
  872. cfg_.rc_buf_initial_sz = 500;
  873. cfg_.rc_buf_optimal_sz = 500;
  874. cfg_.rc_buf_sz = 1000;
  875. cfg_.rc_min_quantizer = 0;
  876. cfg_.rc_max_quantizer = 63;
  877. cfg_.g_threads = 4;
  878. cfg_.rc_dropframe_thresh = 30;
  879. cfg_.kf_max_dist = 9999;
  880. ::libvpx_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60);
  881. top_sl_width_ = 1280;
  882. top_sl_height_ = 720;
  883. layer_framedrop_ = 0;
  884. const int bitrates[3] = { 200, 400, 600 };
  885. cfg_.rc_target_bitrate = bitrates[GET_PARAM(3)];
  886. ResetModel();
  887. layer_framedrop_ = GET_PARAM(2);
  888. AssignLayerBitrates();
  889. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  890. CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.64,
  891. 1.45);
  892. #if CONFIG_VP9_DECODER
  893. // The non-reference frames are expected to be mismatched frames as the
  894. // encoder will avoid loopfilter on these frames.
  895. EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames());
  896. #endif
  897. }
  898. // Check basic rate targeting for 1 pass CBR SVC: 3 spatial layers and
  899. // 3 temporal layers. Run HD clip with 4 threads.
  900. TEST_P(DatarateOnePassCbrSvcFrameDropMultiBR, OnePassCbrSvc3SL3TL4Threads) {
  901. SetSvcConfig(3, 3);
  902. cfg_.rc_buf_initial_sz = 500;
  903. cfg_.rc_buf_optimal_sz = 500;
  904. cfg_.rc_buf_sz = 1000;
  905. cfg_.rc_min_quantizer = 0;
  906. cfg_.rc_max_quantizer = 63;
  907. cfg_.g_threads = 4;
  908. cfg_.rc_dropframe_thresh = 30;
  909. cfg_.kf_max_dist = 9999;
  910. ::libvpx_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60);
  911. top_sl_width_ = 1280;
  912. top_sl_height_ = 720;
  913. layer_framedrop_ = 0;
  914. const int bitrates[3] = { 200, 400, 600 };
  915. cfg_.rc_target_bitrate = bitrates[GET_PARAM(3)];
  916. ResetModel();
  917. layer_framedrop_ = GET_PARAM(2);
  918. AssignLayerBitrates();
  919. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  920. CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.58,
  921. 1.2);
  922. #if CONFIG_VP9_DECODER
  923. // The non-reference frames are expected to be mismatched frames as the
  924. // encoder will avoid loopfilter on these frames.
  925. EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames());
  926. #endif
  927. }
  928. // Params: speed setting, inter-layer prediction mode.
  929. class DatarateOnePassCbrSvcInterLayerPredSingleBR
  930. : public DatarateOnePassCbrSvc,
  931. public ::libvpx_test::CodecTestWith2Params<int, int> {
  932. public:
  933. DatarateOnePassCbrSvcInterLayerPredSingleBR()
  934. : DatarateOnePassCbrSvc(GET_PARAM(0)) {
  935. memset(&svc_params_, 0, sizeof(svc_params_));
  936. }
  937. virtual ~DatarateOnePassCbrSvcInterLayerPredSingleBR() {}
  938. protected:
  939. virtual void SetUp() {
  940. InitializeConfig();
  941. SetMode(::libvpx_test::kRealTime);
  942. speed_setting_ = GET_PARAM(1);
  943. inter_layer_pred_mode_ = GET_PARAM(2);
  944. ResetModel();
  945. }
  946. };
  947. // Check basic rate targeting with different inter-layer prediction modes for 1
  948. // pass CBR SVC: 3 spatial layers and 3 temporal layers. Run CIF clip with 1
  949. // thread.
  950. TEST_P(DatarateOnePassCbrSvcInterLayerPredSingleBR, OnePassCbrSvc3SL3TL) {
  951. // Disable test for inter-layer pred off for now since simulcast_mode fails.
  952. if (inter_layer_pred_mode_ == INTER_LAYER_PRED_OFF) return;
  953. SetSvcConfig(3, 3);
  954. cfg_.rc_buf_initial_sz = 500;
  955. cfg_.rc_buf_optimal_sz = 500;
  956. cfg_.rc_buf_sz = 1000;
  957. cfg_.rc_min_quantizer = 0;
  958. cfg_.rc_max_quantizer = 63;
  959. cfg_.g_threads = 1;
  960. cfg_.temporal_layering_mode = 3;
  961. cfg_.rc_dropframe_thresh = 30;
  962. cfg_.kf_max_dist = 9999;
  963. ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
  964. 0, 400);
  965. top_sl_width_ = 640;
  966. top_sl_height_ = 480;
  967. cfg_.rc_target_bitrate = 800;
  968. ResetModel();
  969. AssignLayerBitrates();
  970. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  971. CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.78,
  972. 1.15);
  973. #if CONFIG_VP9_DECODER
  974. // The non-reference frames are expected to be mismatched frames as the
  975. // encoder will avoid loopfilter on these frames.
  976. EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames());
  977. #endif
  978. }
  979. // Check rate targeting with different inter-layer prediction modes for 1 pass
  980. // CBR SVC: 3 spatial layers and 3 temporal layers, changing the target bitrate
  981. // at the middle of encoding.
  982. TEST_P(DatarateOnePassCbrSvcSingleBR, OnePassCbrSvc3SL3TLDynamicBitrateChange) {
  983. SetSvcConfig(3, 3);
  984. cfg_.rc_buf_initial_sz = 500;
  985. cfg_.rc_buf_optimal_sz = 500;
  986. cfg_.rc_buf_sz = 1000;
  987. cfg_.rc_min_quantizer = 0;
  988. cfg_.rc_max_quantizer = 63;
  989. cfg_.g_threads = 1;
  990. cfg_.rc_dropframe_thresh = 30;
  991. cfg_.kf_max_dist = 9999;
  992. ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
  993. 0, 400);
  994. top_sl_width_ = 640;
  995. top_sl_height_ = 480;
  996. cfg_.rc_target_bitrate = 800;
  997. ResetModel();
  998. change_bitrate_ = true;
  999. AssignLayerBitrates();
  1000. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  1001. CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.78,
  1002. 1.15);
  1003. #if CONFIG_VP9_DECODER
  1004. // The non-reference frames are expected to be mismatched frames as the
  1005. // encoder will avoid loopfilter on these frames.
  1006. EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames());
  1007. #endif
  1008. }
  1009. #if CONFIG_VP9_TEMPORAL_DENOISING
  1010. // Params: speed setting, noise sensitivity, index for bitrate array and inter
  1011. // layer pred mode.
  1012. class DatarateOnePassCbrSvcDenoiser
  1013. : public DatarateOnePassCbrSvc,
  1014. public ::libvpx_test::CodecTestWith4Params<int, int, int, int> {
  1015. public:
  1016. DatarateOnePassCbrSvcDenoiser() : DatarateOnePassCbrSvc(GET_PARAM(0)) {
  1017. memset(&svc_params_, 0, sizeof(svc_params_));
  1018. }
  1019. virtual ~DatarateOnePassCbrSvcDenoiser() {}
  1020. protected:
  1021. virtual void SetUp() {
  1022. InitializeConfig();
  1023. SetMode(::libvpx_test::kRealTime);
  1024. speed_setting_ = GET_PARAM(1);
  1025. inter_layer_pred_mode_ = GET_PARAM(3);
  1026. ResetModel();
  1027. }
  1028. };
  1029. // Check basic rate targeting for 1 pass CBR SVC with denoising.
  1030. // 2 spatial layers and 3 temporal layer. Run HD clip with 2 threads.
  1031. TEST_P(DatarateOnePassCbrSvcDenoiser, OnePassCbrSvc2SL3TLDenoiserOn) {
  1032. SetSvcConfig(2, 3);
  1033. cfg_.rc_buf_initial_sz = 500;
  1034. cfg_.rc_buf_optimal_sz = 500;
  1035. cfg_.rc_buf_sz = 1000;
  1036. cfg_.rc_min_quantizer = 0;
  1037. cfg_.rc_max_quantizer = 63;
  1038. cfg_.g_threads = 2;
  1039. cfg_.rc_dropframe_thresh = 30;
  1040. cfg_.kf_max_dist = 9999;
  1041. number_spatial_layers_ = cfg_.ss_number_layers;
  1042. number_temporal_layers_ = cfg_.ts_number_layers;
  1043. ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
  1044. 0, 400);
  1045. top_sl_width_ = 640;
  1046. top_sl_height_ = 480;
  1047. const int bitrates[3] = { 600, 800, 1000 };
  1048. // TODO(marpan): Check that effective_datarate for each layer hits the
  1049. // layer target_bitrate.
  1050. // For SVC, noise_sen = 1 means denoising only the top spatial layer
  1051. // noise_sen = 2 means denoising the two top spatial layers.
  1052. cfg_.rc_target_bitrate = bitrates[GET_PARAM(3)];
  1053. ResetModel();
  1054. denoiser_on_ = GET_PARAM(2);
  1055. AssignLayerBitrates();
  1056. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  1057. CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.78,
  1058. 1.15);
  1059. #if CONFIG_VP9_DECODER
  1060. // The non-reference frames are expected to be mismatched frames as the
  1061. // encoder will avoid loopfilter on these frames.
  1062. EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames());
  1063. #endif
  1064. }
  1065. #endif
  1066. // Params: speed setting, key frame dist.
  1067. class DatarateOnePassCbrSvcSmallKF
  1068. : public DatarateOnePassCbrSvc,
  1069. public ::libvpx_test::CodecTestWith2Params<int, int> {
  1070. public:
  1071. DatarateOnePassCbrSvcSmallKF() : DatarateOnePassCbrSvc(GET_PARAM(0)) {
  1072. memset(&svc_params_, 0, sizeof(svc_params_));
  1073. }
  1074. virtual ~DatarateOnePassCbrSvcSmallKF() {}
  1075. protected:
  1076. virtual void SetUp() {
  1077. InitializeConfig();
  1078. SetMode(::libvpx_test::kRealTime);
  1079. speed_setting_ = GET_PARAM(1);
  1080. ResetModel();
  1081. }
  1082. };
  1083. // Check basic rate targeting for 1 pass CBR SVC: 3 spatial layers and 3
  1084. // temporal layers. Run CIF clip with 1 thread, and few short key frame periods.
  1085. TEST_P(DatarateOnePassCbrSvcSmallKF, OnePassCbrSvc3SL3TLSmallKf) {
  1086. SetSvcConfig(3, 3);
  1087. cfg_.rc_buf_initial_sz = 500;
  1088. cfg_.rc_buf_optimal_sz = 500;
  1089. cfg_.rc_buf_sz = 1000;
  1090. cfg_.rc_min_quantizer = 0;
  1091. cfg_.rc_max_quantizer = 63;
  1092. cfg_.g_threads = 1;
  1093. cfg_.rc_dropframe_thresh = 10;
  1094. cfg_.rc_target_bitrate = 800;
  1095. ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
  1096. 0, 400);
  1097. top_sl_width_ = 640;
  1098. top_sl_height_ = 480;
  1099. // For this 3 temporal layer case, pattern repeats every 4 frames, so choose
  1100. // 4 key neighboring key frame periods (so key frame will land on 0-2-1-2).
  1101. const int kf_dist = GET_PARAM(2);
  1102. cfg_.kf_max_dist = kf_dist;
  1103. key_frame_spacing_ = kf_dist;
  1104. ResetModel();
  1105. AssignLayerBitrates();
  1106. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  1107. // TODO(jianj): webm:1554
  1108. CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.70,
  1109. 1.15);
  1110. #if CONFIG_VP9_DECODER
  1111. // The non-reference frames are expected to be mismatched frames as the
  1112. // encoder will avoid loopfilter on these frames.
  1113. EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames());
  1114. #endif
  1115. }
  1116. // Check basic rate targeting for 1 pass CBR SVC: 2 spatial layers and 3
  1117. // temporal layers. Run CIF clip with 1 thread, and few short key frame periods.
  1118. TEST_P(DatarateOnePassCbrSvcSmallKF, OnePassCbrSvc2SL3TLSmallKf) {
  1119. SetSvcConfig(2, 3);
  1120. cfg_.rc_buf_initial_sz = 500;
  1121. cfg_.rc_buf_optimal_sz = 500;
  1122. cfg_.rc_buf_sz = 1000;
  1123. cfg_.rc_min_quantizer = 0;
  1124. cfg_.rc_max_quantizer = 63;
  1125. cfg_.g_threads = 1;
  1126. cfg_.rc_dropframe_thresh = 10;
  1127. cfg_.rc_target_bitrate = 400;
  1128. ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
  1129. 0, 400);
  1130. top_sl_width_ = 640;
  1131. top_sl_height_ = 480;
  1132. // For this 3 temporal layer case, pattern repeats every 4 frames, so choose
  1133. // 4 key neighboring key frame periods (so key frame will land on 0-2-1-2).
  1134. const int kf_dist = GET_PARAM(2) + 32;
  1135. cfg_.kf_max_dist = kf_dist;
  1136. key_frame_spacing_ = kf_dist;
  1137. ResetModel();
  1138. AssignLayerBitrates();
  1139. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  1140. CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.78,
  1141. 1.15);
  1142. #if CONFIG_VP9_DECODER
  1143. // The non-reference frames are expected to be mismatched frames as the
  1144. // encoder will avoid loopfilter on these frames.
  1145. EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames());
  1146. #endif
  1147. }
  1148. // Check basic rate targeting for 1 pass CBR SVC: 3 spatial layers and 3
  1149. // temporal layers. Run VGA clip with 1 thread, and place layer sync frames:
  1150. // one at middle layer first, then another one for top layer, and another
  1151. // insert for base spatial layer (which forces key frame).
  1152. TEST_P(DatarateOnePassCbrSvcSingleBR, OnePassCbrSvc3SL3TLSyncFrames) {
  1153. SetSvcConfig(3, 3);
  1154. cfg_.rc_buf_initial_sz = 500;
  1155. cfg_.rc_buf_optimal_sz = 500;
  1156. cfg_.rc_buf_sz = 1000;
  1157. cfg_.rc_min_quantizer = 0;
  1158. cfg_.rc_max_quantizer = 63;
  1159. cfg_.g_threads = 1;
  1160. cfg_.kf_max_dist = 9999;
  1161. cfg_.rc_dropframe_thresh = 10;
  1162. cfg_.rc_target_bitrate = 400;
  1163. ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
  1164. 0, 400);
  1165. top_sl_width_ = 640;
  1166. top_sl_height_ = 480;
  1167. ResetModel();
  1168. insert_layer_sync_ = 1;
  1169. AssignLayerBitrates();
  1170. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  1171. CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.78,
  1172. 1.15);
  1173. #if CONFIG_VP9_DECODER
  1174. // The non-reference frames are expected to be mismatched frames as the
  1175. // encoder will avoid loopfilter on these frames.
  1176. EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames());
  1177. #endif
  1178. }
  1179. // Run SVC encoder for 3 spatial layers, 1 temporal layer, with
  1180. // intra-only frame as sync frame on base spatial layer.
  1181. // Intra_only is inserted at start and in middle of sequence.
  1182. TEST_P(DatarateOnePassCbrSvcSingleBR, OnePassCbrSvc3SL1TLSyncWithIntraOnly) {
  1183. SetSvcConfig(3, 1);
  1184. cfg_.rc_buf_initial_sz = 500;
  1185. cfg_.rc_buf_optimal_sz = 500;
  1186. cfg_.rc_buf_sz = 1000;
  1187. cfg_.rc_min_quantizer = 0;
  1188. cfg_.rc_max_quantizer = 63;
  1189. cfg_.g_threads = 4;
  1190. cfg_.rc_dropframe_thresh = 30;
  1191. cfg_.kf_max_dist = 9999;
  1192. cfg_.rc_target_bitrate = 400;
  1193. ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
  1194. 0, 400);
  1195. top_sl_width_ = 640;
  1196. top_sl_height_ = 480;
  1197. ResetModel();
  1198. insert_layer_sync_ = 1;
  1199. // Use intra_only frame for sync on base layer.
  1200. force_intra_only_frame_ = 1;
  1201. AssignLayerBitrates();
  1202. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  1203. CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.73,
  1204. 1.2);
  1205. #if CONFIG_VP9_DECODER
  1206. // The non-reference frames are expected to be mismatched frames as the
  1207. // encoder will avoid loopfilter on these frames.
  1208. EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames());
  1209. #endif
  1210. }
  1211. // Run SVC encoder for 2 quality layers (same resolution different,
  1212. // bitrates), 1 temporal layer, with screen content mode.
  1213. TEST_P(DatarateOnePassCbrSvcSingleBR, OnePassCbrSvc2QL1TLScreen) {
  1214. cfg_.rc_buf_initial_sz = 500;
  1215. cfg_.rc_buf_optimal_sz = 500;
  1216. cfg_.rc_buf_sz = 1000;
  1217. cfg_.rc_min_quantizer = 0;
  1218. cfg_.rc_max_quantizer = 56;
  1219. cfg_.rc_end_usage = VPX_CBR;
  1220. cfg_.g_lag_in_frames = 0;
  1221. cfg_.ss_number_layers = 2;
  1222. cfg_.ts_number_layers = 1;
  1223. cfg_.ts_rate_decimator[0] = 1;
  1224. cfg_.temporal_layering_mode = 0;
  1225. cfg_.g_error_resilient = 1;
  1226. cfg_.g_threads = 2;
  1227. svc_params_.scaling_factor_num[0] = 1;
  1228. svc_params_.scaling_factor_den[0] = 1;
  1229. svc_params_.scaling_factor_num[1] = 1;
  1230. svc_params_.scaling_factor_den[1] = 1;
  1231. cfg_.rc_dropframe_thresh = 30;
  1232. cfg_.kf_max_dist = 9999;
  1233. number_spatial_layers_ = cfg_.ss_number_layers;
  1234. number_temporal_layers_ = cfg_.ts_number_layers;
  1235. ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
  1236. 0, 400);
  1237. top_sl_width_ = 640;
  1238. top_sl_height_ = 480;
  1239. ResetModel();
  1240. tune_content_ = 1;
  1241. // Set the layer bitrates, for 2 spatial layers, 1 temporal.
  1242. cfg_.rc_target_bitrate = 400;
  1243. cfg_.ss_target_bitrate[0] = 100;
  1244. cfg_.ss_target_bitrate[1] = 300;
  1245. cfg_.layer_target_bitrate[0] = 100;
  1246. cfg_.layer_target_bitrate[1] = 300;
  1247. for (int sl = 0; sl < 2; ++sl) {
  1248. float layer_framerate = 30.0;
  1249. layer_target_avg_bandwidth_[sl] = static_cast<int>(
  1250. cfg_.layer_target_bitrate[sl] * 1000.0 / layer_framerate);
  1251. bits_in_buffer_model_[sl] =
  1252. cfg_.layer_target_bitrate[sl] * cfg_.rc_buf_initial_sz;
  1253. }
  1254. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  1255. CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.73,
  1256. 1.25);
  1257. #if CONFIG_VP9_DECODER
  1258. // The non-reference frames are expected to be mismatched frames as the
  1259. // encoder will avoid loopfilter on these frames.
  1260. EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames());
  1261. #endif
  1262. }
  1263. // Params: speed setting.
  1264. class DatarateOnePassCbrSvcPostencodeDrop
  1265. : public DatarateOnePassCbrSvc,
  1266. public ::libvpx_test::CodecTestWithParam<int> {
  1267. public:
  1268. DatarateOnePassCbrSvcPostencodeDrop() : DatarateOnePassCbrSvc(GET_PARAM(0)) {
  1269. memset(&svc_params_, 0, sizeof(svc_params_));
  1270. }
  1271. virtual ~DatarateOnePassCbrSvcPostencodeDrop() {}
  1272. protected:
  1273. virtual void SetUp() {
  1274. InitializeConfig();
  1275. SetMode(::libvpx_test::kRealTime);
  1276. speed_setting_ = GET_PARAM(1);
  1277. ResetModel();
  1278. }
  1279. };
  1280. // Run SVC encoder for 2 quality layers (same resolution different,
  1281. // bitrates), 1 temporal layer, with screen content mode.
  1282. TEST_P(DatarateOnePassCbrSvcPostencodeDrop, OnePassCbrSvc2QL1TLScreen) {
  1283. cfg_.rc_buf_initial_sz = 200;
  1284. cfg_.rc_buf_optimal_sz = 200;
  1285. cfg_.rc_buf_sz = 400;
  1286. cfg_.rc_min_quantizer = 0;
  1287. cfg_.rc_max_quantizer = 52;
  1288. cfg_.rc_end_usage = VPX_CBR;
  1289. cfg_.g_lag_in_frames = 0;
  1290. cfg_.ss_number_layers = 2;
  1291. cfg_.ts_number_layers = 1;
  1292. cfg_.ts_rate_decimator[0] = 1;
  1293. cfg_.temporal_layering_mode = 0;
  1294. cfg_.g_error_resilient = 1;
  1295. cfg_.g_threads = 2;
  1296. svc_params_.scaling_factor_num[0] = 1;
  1297. svc_params_.scaling_factor_den[0] = 1;
  1298. svc_params_.scaling_factor_num[1] = 1;
  1299. svc_params_.scaling_factor_den[1] = 1;
  1300. cfg_.rc_dropframe_thresh = 30;
  1301. cfg_.kf_max_dist = 9999;
  1302. number_spatial_layers_ = cfg_.ss_number_layers;
  1303. number_temporal_layers_ = cfg_.ts_number_layers;
  1304. ::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
  1305. 30, 1, 0, 300);
  1306. top_sl_width_ = 352;
  1307. top_sl_height_ = 288;
  1308. ResetModel();
  1309. base_speed_setting_ = speed_setting_;
  1310. tune_content_ = 1;
  1311. use_post_encode_drop_ = 1;
  1312. // Set the layer bitrates, for 2 spatial layers, 1 temporal.
  1313. cfg_.rc_target_bitrate = 400;
  1314. cfg_.ss_target_bitrate[0] = 100;
  1315. cfg_.ss_target_bitrate[1] = 300;
  1316. cfg_.layer_target_bitrate[0] = 100;
  1317. cfg_.layer_target_bitrate[1] = 300;
  1318. for (int sl = 0; sl < 2; ++sl) {
  1319. float layer_framerate = 30.0;
  1320. layer_target_avg_bandwidth_[sl] = static_cast<int>(
  1321. cfg_.layer_target_bitrate[sl] * 1000.0 / layer_framerate);
  1322. bits_in_buffer_model_[sl] =
  1323. cfg_.layer_target_bitrate[sl] * cfg_.rc_buf_initial_sz;
  1324. }
  1325. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  1326. CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.73,
  1327. 1.25);
  1328. #if CONFIG_VP9_DECODER
  1329. // The non-reference frames are expected to be mismatched frames as the
  1330. // encoder will avoid loopfilter on these frames.
  1331. EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames());
  1332. #endif
  1333. }
  1334. VP9_INSTANTIATE_TEST_CASE(DatarateOnePassCbrSvcSingleBR,
  1335. ::testing::Range(5, 10));
  1336. VP9_INSTANTIATE_TEST_CASE(DatarateOnePassCbrSvcPostencodeDrop,
  1337. ::testing::Range(5, 6));
  1338. VP9_INSTANTIATE_TEST_CASE(DatarateOnePassCbrSvcInterLayerPredSingleBR,
  1339. ::testing::Range(5, 10), ::testing::Range(0, 3));
  1340. VP9_INSTANTIATE_TEST_CASE(DatarateOnePassCbrSvcMultiBR, ::testing::Range(5, 10),
  1341. ::testing::Range(0, 3));
  1342. VP9_INSTANTIATE_TEST_CASE(DatarateOnePassCbrSvcFrameDropMultiBR,
  1343. ::testing::Range(5, 10), ::testing::Range(0, 2),
  1344. ::testing::Range(0, 3));
  1345. #if CONFIG_VP9_TEMPORAL_DENOISING
  1346. VP9_INSTANTIATE_TEST_CASE(DatarateOnePassCbrSvcDenoiser,
  1347. ::testing::Range(5, 10), ::testing::Range(1, 3),
  1348. ::testing::Range(0, 3), ::testing::Range(0, 4));
  1349. #endif
  1350. VP9_INSTANTIATE_TEST_CASE(DatarateOnePassCbrSvcSmallKF, ::testing::Range(5, 10),
  1351. ::testing::Range(32, 36));
  1352. } // namespace
  1353. } // namespace svc_test