OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebM project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 #include "./vpx_config.h" | 10 #include "./vpx_config.h" |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 InitializeConfig(); | 191 InitializeConfig(); |
192 SetMode(GET_PARAM(1)); | 192 SetMode(GET_PARAM(1)); |
193 set_cpu_used_ = GET_PARAM(2); | 193 set_cpu_used_ = GET_PARAM(2); |
194 ResetModel(); | 194 ResetModel(); |
195 } | 195 } |
196 | 196 |
197 virtual void ResetModel() { | 197 virtual void ResetModel() { |
198 last_pts_ = 0; | 198 last_pts_ = 0; |
199 bits_in_buffer_model_ = cfg_.rc_target_bitrate * cfg_.rc_buf_initial_sz; | 199 bits_in_buffer_model_ = cfg_.rc_target_bitrate * cfg_.rc_buf_initial_sz; |
200 frame_number_ = 0; | 200 frame_number_ = 0; |
| 201 tot_frame_number_ = 0; |
201 first_drop_ = 0; | 202 first_drop_ = 0; |
202 num_drops_ = 0; | 203 num_drops_ = 0; |
203 bits_total_ = 0; | 204 // For testing up to 3 layers. |
204 duration_ = 0.0; | 205 for (int i = 0; i < 3; ++i) { |
| 206 bits_total_[i] = 0; |
| 207 } |
| 208 } |
| 209 |
| 210 // |
| 211 // Frame flags and layer id for temporal layers. |
| 212 // |
| 213 |
| 214 // For two layers, test pattern is: |
| 215 // 1 3 |
| 216 // 0 2 ..... |
| 217 // For three layers, test pattern is: |
| 218 // 1 3 5 7 |
| 219 // 2 6 |
| 220 // 0 4 .... |
| 221 // LAST is always update on base/layer 0, GOLDEN is updated on layer 1. |
| 222 // For this 3 layer example, the 2nd enhancement layer (layer 2) does not |
| 223 // update any reference frames. |
| 224 int SetFrameFlags(int frame_num, int num_temp_layers) { |
| 225 int frame_flags = 0; |
| 226 if (num_temp_layers == 2) { |
| 227 if (frame_num % 2 == 0) { |
| 228 // Layer 0: predict from L and ARF, update L. |
| 229 frame_flags = VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_UPD_GF | |
| 230 VP8_EFLAG_NO_UPD_ARF; |
| 231 } else { |
| 232 // Layer 1: predict from L, G and ARF, and update G. |
| 233 frame_flags = VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST | |
| 234 VP8_EFLAG_NO_UPD_ENTROPY; |
| 235 } |
| 236 } else if (num_temp_layers == 3) { |
| 237 if (frame_num % 4 == 0) { |
| 238 // Layer 0: predict from L and ARF; update L. |
| 239 frame_flags = VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF | |
| 240 VP8_EFLAG_NO_REF_GF; |
| 241 } else if ((frame_num - 2) % 4 == 0) { |
| 242 // Layer 1: predict from L, G, ARF; update G. |
| 243 frame_flags = VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST; |
| 244 } else if ((frame_num - 1) % 2 == 0) { |
| 245 // Layer 2: predict from L, G, ARF; update none. |
| 246 frame_flags = VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF | |
| 247 VP8_EFLAG_NO_UPD_LAST; |
| 248 } |
| 249 } |
| 250 return frame_flags; |
| 251 } |
| 252 |
| 253 int SetLayerId(int frame_num, int num_temp_layers) { |
| 254 int layer_id = 0; |
| 255 if (num_temp_layers == 2) { |
| 256 if (frame_num % 2 == 0) { |
| 257 layer_id = 0; |
| 258 } else { |
| 259 layer_id = 1; |
| 260 } |
| 261 } else if (num_temp_layers == 3) { |
| 262 if (frame_num % 4 == 0) { |
| 263 layer_id = 0; |
| 264 } else if ((frame_num - 2) % 4 == 0) { |
| 265 layer_id = 1; |
| 266 } else if ((frame_num - 1) % 2 == 0) { |
| 267 layer_id = 2; |
| 268 } |
| 269 } |
| 270 return layer_id; |
205 } | 271 } |
206 | 272 |
207 virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, | 273 virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, |
208 ::libvpx_test::Encoder *encoder) { | 274 ::libvpx_test::Encoder *encoder) { |
209 if (video->frame() == 1) { | 275 if (video->frame() == 1) { |
210 encoder->Control(VP8E_SET_CPUUSED, set_cpu_used_); | 276 encoder->Control(VP8E_SET_CPUUSED, set_cpu_used_); |
211 } | 277 } |
| 278 if (cfg_.ts_number_layers > 1) { |
| 279 if (video->frame() == 1) { |
| 280 encoder->Control(VP9E_SET_SVC, 1); |
| 281 } |
| 282 vpx_svc_layer_id_t layer_id = {0, 0}; |
| 283 layer_id.spatial_layer_id = 0; |
| 284 frame_flags_ = SetFrameFlags(video->frame(), cfg_.ts_number_layers); |
| 285 layer_id.temporal_layer_id = SetLayerId(video->frame(), |
| 286 cfg_.ts_number_layers); |
| 287 if (video->frame() > 0) { |
| 288 encoder->Control(VP9E_SET_SVC_LAYER_ID, &layer_id); |
| 289 } |
| 290 } |
212 const vpx_rational_t tb = video->timebase(); | 291 const vpx_rational_t tb = video->timebase(); |
213 timebase_ = static_cast<double>(tb.num) / tb.den; | 292 timebase_ = static_cast<double>(tb.num) / tb.den; |
214 duration_ = 0; | 293 duration_ = 0; |
215 } | 294 } |
216 | 295 |
| 296 |
217 virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) { | 297 virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) { |
218 // Time since last timestamp = duration. | 298 // Time since last timestamp = duration. |
219 vpx_codec_pts_t duration = pkt->data.frame.pts - last_pts_; | 299 vpx_codec_pts_t duration = pkt->data.frame.pts - last_pts_; |
220 | 300 |
| 301 if (duration > 1) { |
| 302 // If first drop not set and we have a drop set it to this time. |
| 303 if (!first_drop_) |
| 304 first_drop_ = last_pts_ + 1; |
| 305 // Update the number of frame drops. |
| 306 num_drops_ += static_cast<int>(duration - 1); |
| 307 // Update counter for total number of frames (#frames input to encoder). |
| 308 // Needed for setting the proper layer_id below. |
| 309 tot_frame_number_ += static_cast<int>(duration - 1); |
| 310 } |
| 311 |
| 312 int layer = SetLayerId(tot_frame_number_, cfg_.ts_number_layers); |
| 313 |
221 // Add to the buffer the bits we'd expect from a constant bitrate server. | 314 // Add to the buffer the bits we'd expect from a constant bitrate server. |
222 bits_in_buffer_model_ += static_cast<int64_t>( | 315 bits_in_buffer_model_ += static_cast<int64_t>( |
223 duration * timebase_ * cfg_.rc_target_bitrate * 1000); | 316 duration * timebase_ * cfg_.rc_target_bitrate * 1000); |
224 | 317 |
225 // Buffer should not go negative. | 318 // Buffer should not go negative. |
226 ASSERT_GE(bits_in_buffer_model_, 0) << "Buffer Underrun at frame " | 319 ASSERT_GE(bits_in_buffer_model_, 0) << "Buffer Underrun at frame " |
227 << pkt->data.frame.pts; | 320 << pkt->data.frame.pts; |
228 | 321 |
229 const size_t frame_size_in_bits = pkt->data.frame.sz * 8; | 322 const size_t frame_size_in_bits = pkt->data.frame.sz * 8; |
230 bits_total_ += frame_size_in_bits; | |
231 | 323 |
232 // If first drop not set and we have a drop set it to this time. | 324 // Update the total encoded bits. For temporal layers, update the cumulative |
233 if (!first_drop_ && duration > 1) | 325 // encoded bits per layer. |
234 first_drop_ = last_pts_ + 1; | 326 for (int i = layer; i < static_cast<int>(cfg_.ts_number_layers); ++i) { |
235 | 327 bits_total_[i] += frame_size_in_bits; |
236 // Update the number of frame drops. | |
237 if (duration > 1) { | |
238 num_drops_ += static_cast<int>(duration - 1); | |
239 } | 328 } |
240 | 329 |
241 // Update the most recent pts. | 330 // Update the most recent pts. |
242 last_pts_ = pkt->data.frame.pts; | 331 last_pts_ = pkt->data.frame.pts; |
243 ++frame_number_; | 332 ++frame_number_; |
| 333 ++tot_frame_number_; |
244 } | 334 } |
245 | 335 |
246 virtual void EndPassHook(void) { | 336 virtual void EndPassHook(void) { |
247 if (bits_total_) { | 337 for (int layer = 0; layer < static_cast<int>(cfg_.ts_number_layers); |
| 338 ++layer) { |
248 duration_ = (last_pts_ + 1) * timebase_; | 339 duration_ = (last_pts_ + 1) * timebase_; |
249 // Effective file datarate: | 340 if (bits_total_[layer]) { |
250 effective_datarate_ = ((bits_total_) / 1000.0) / duration_; | 341 // Effective file datarate: |
| 342 effective_datarate_[layer] = (bits_total_[layer] / 1000.0) / duration_; |
| 343 } |
251 } | 344 } |
252 } | 345 } |
253 | 346 |
254 vpx_codec_pts_t last_pts_; | 347 vpx_codec_pts_t last_pts_; |
255 double timebase_; | 348 double timebase_; |
256 int frame_number_; | 349 int frame_number_; // Counter for number of non-dropped/encoded frames. |
257 int64_t bits_total_; | 350 int tot_frame_number_; // Counter for total number of input frames. |
| 351 int64_t bits_total_[3]; |
258 double duration_; | 352 double duration_; |
259 double effective_datarate_; | 353 double effective_datarate_[3]; |
260 int set_cpu_used_; | 354 int set_cpu_used_; |
261 int64_t bits_in_buffer_model_; | 355 int64_t bits_in_buffer_model_; |
262 vpx_codec_pts_t first_drop_; | 356 vpx_codec_pts_t first_drop_; |
263 int num_drops_; | 357 int num_drops_; |
264 }; | 358 }; |
265 | 359 |
266 // Check basic rate targeting, | 360 // Check basic rate targeting, |
267 TEST_P(DatarateTestVP9, BasicRateTargeting) { | 361 TEST_P(DatarateTestVP9, BasicRateTargeting) { |
268 cfg_.rc_buf_initial_sz = 500; | 362 cfg_.rc_buf_initial_sz = 500; |
269 cfg_.rc_buf_optimal_sz = 500; | 363 cfg_.rc_buf_optimal_sz = 500; |
270 cfg_.rc_buf_sz = 1000; | 364 cfg_.rc_buf_sz = 1000; |
271 cfg_.rc_dropframe_thresh = 1; | 365 cfg_.rc_dropframe_thresh = 1; |
272 cfg_.rc_min_quantizer = 0; | 366 cfg_.rc_min_quantizer = 0; |
273 cfg_.rc_max_quantizer = 63; | 367 cfg_.rc_max_quantizer = 63; |
274 cfg_.rc_end_usage = VPX_CBR; | 368 cfg_.rc_end_usage = VPX_CBR; |
| 369 cfg_.g_lag_in_frames = 0; |
275 | 370 |
276 ::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, | 371 ::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, |
277 30, 1, 0, 140); | 372 30, 1, 0, 140); |
278 for (int i = 150; i < 800; i += 200) { | 373 for (int i = 150; i < 800; i += 200) { |
279 cfg_.rc_target_bitrate = i; | 374 cfg_.rc_target_bitrate = i; |
280 ResetModel(); | 375 ResetModel(); |
281 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); | 376 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
282 ASSERT_GE(static_cast<double>(cfg_.rc_target_bitrate), | 377 ASSERT_GE(effective_datarate_[0], cfg_.rc_target_bitrate * 0.85) |
283 effective_datarate_ * 0.85) | 378 << " The datarate for the file is lower than target by too much!"; |
284 << " The datarate for the file exceeds the target by too much!"; | 379 ASSERT_LE(effective_datarate_[0], cfg_.rc_target_bitrate * 1.15) |
285 ASSERT_LE(static_cast<double>(cfg_.rc_target_bitrate), | 380 << " The datarate for the file is greater than target by too much!"; |
286 effective_datarate_ * 1.15) | |
287 << " The datarate for the file missed the target!"; | |
288 } | 381 } |
289 } | 382 } |
290 | 383 |
291 #if CONFIG_NON420 | 384 #if CONFIG_NON420 |
292 // Check basic rate targeting, | 385 // Check basic rate targeting, |
293 TEST_P(DatarateTestVP9, BasicRateTargeting444) { | 386 TEST_P(DatarateTestVP9, BasicRateTargeting444) { |
294 ::libvpx_test::Y4mVideoSource video("rush_hour_444.y4m", 0, 140); | 387 ::libvpx_test::Y4mVideoSource video("rush_hour_444.y4m", 0, 140); |
295 | 388 |
296 cfg_.g_profile = 1; | 389 cfg_.g_profile = 1; |
297 cfg_.g_timebase = video.timebase(); | 390 cfg_.g_timebase = video.timebase(); |
298 | 391 |
299 cfg_.rc_buf_initial_sz = 500; | 392 cfg_.rc_buf_initial_sz = 500; |
300 cfg_.rc_buf_optimal_sz = 500; | 393 cfg_.rc_buf_optimal_sz = 500; |
301 cfg_.rc_buf_sz = 1000; | 394 cfg_.rc_buf_sz = 1000; |
302 cfg_.rc_dropframe_thresh = 1; | 395 cfg_.rc_dropframe_thresh = 1; |
303 cfg_.rc_min_quantizer = 0; | 396 cfg_.rc_min_quantizer = 0; |
304 cfg_.rc_max_quantizer = 63; | 397 cfg_.rc_max_quantizer = 63; |
305 cfg_.rc_end_usage = VPX_CBR; | 398 cfg_.rc_end_usage = VPX_CBR; |
306 | 399 |
307 for (int i = 250; i < 900; i += 200) { | 400 for (int i = 250; i < 900; i += 200) { |
308 cfg_.rc_target_bitrate = i; | 401 cfg_.rc_target_bitrate = i; |
309 ResetModel(); | 402 ResetModel(); |
310 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); | 403 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
311 ASSERT_GE(static_cast<double>(cfg_.rc_target_bitrate), | 404 ASSERT_GE(static_cast<double>(cfg_.rc_target_bitrate), |
312 effective_datarate_ * 0.85) | 405 effective_datarate_[0] * 0.85) |
313 << " The datarate for the file exceeds the target by too much!"; | 406 << " The datarate for the file exceeds the target by too much!"; |
314 ASSERT_LE(static_cast<double>(cfg_.rc_target_bitrate), | 407 ASSERT_LE(static_cast<double>(cfg_.rc_target_bitrate), |
315 effective_datarate_ * 1.15) | 408 effective_datarate_[0] * 1.15) |
316 << " The datarate for the file missed the target!" | 409 << " The datarate for the file missed the target!" |
317 << cfg_.rc_target_bitrate << " "<< effective_datarate_; | 410 << cfg_.rc_target_bitrate << " "<< effective_datarate_; |
318 } | 411 } |
319 } | 412 } |
320 #endif | 413 #endif |
321 | 414 |
322 // Check that (1) the first dropped frame gets earlier and earlier | 415 // Check that (1) the first dropped frame gets earlier and earlier |
323 // as the drop frame threshold is increased, and (2) that the total number of | 416 // as the drop frame threshold is increased, and (2) that the total number of |
324 // frame drops does not decrease as we increase frame drop threshold. | 417 // frame drops does not decrease as we increase frame drop threshold. |
325 // Use a lower qp-max to force some frame drops. | 418 // Use a lower qp-max to force some frame drops. |
326 TEST_P(DatarateTestVP9, ChangingDropFrameThresh) { | 419 TEST_P(DatarateTestVP9, ChangingDropFrameThresh) { |
327 cfg_.rc_buf_initial_sz = 500; | 420 cfg_.rc_buf_initial_sz = 500; |
328 cfg_.rc_buf_optimal_sz = 500; | 421 cfg_.rc_buf_optimal_sz = 500; |
329 cfg_.rc_buf_sz = 1000; | 422 cfg_.rc_buf_sz = 1000; |
330 cfg_.rc_undershoot_pct = 20; | 423 cfg_.rc_undershoot_pct = 20; |
331 cfg_.rc_undershoot_pct = 20; | 424 cfg_.rc_undershoot_pct = 20; |
332 cfg_.rc_dropframe_thresh = 10; | 425 cfg_.rc_dropframe_thresh = 10; |
333 cfg_.rc_min_quantizer = 0; | 426 cfg_.rc_min_quantizer = 0; |
334 cfg_.rc_max_quantizer = 50; | 427 cfg_.rc_max_quantizer = 50; |
335 cfg_.rc_end_usage = VPX_CBR; | 428 cfg_.rc_end_usage = VPX_CBR; |
336 cfg_.rc_target_bitrate = 200; | 429 cfg_.rc_target_bitrate = 200; |
| 430 cfg_.g_lag_in_frames = 0; |
337 | 431 |
338 ::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, | 432 ::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, |
339 30, 1, 0, 140); | 433 30, 1, 0, 140); |
340 | 434 |
341 const int kDropFrameThreshTestStep = 30; | 435 const int kDropFrameThreshTestStep = 30; |
342 vpx_codec_pts_t last_drop = 140; | 436 vpx_codec_pts_t last_drop = 140; |
343 int last_num_drops = 0; | 437 int last_num_drops = 0; |
344 for (int i = 10; i < 100; i += kDropFrameThreshTestStep) { | 438 for (int i = 10; i < 100; i += kDropFrameThreshTestStep) { |
345 cfg_.rc_dropframe_thresh = i; | 439 cfg_.rc_dropframe_thresh = i; |
346 ResetModel(); | 440 ResetModel(); |
347 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); | 441 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
348 ASSERT_GE(effective_datarate_, cfg_.rc_target_bitrate * 0.85) | 442 ASSERT_GE(effective_datarate_[0], cfg_.rc_target_bitrate * 0.85) |
349 << " The datarate for the file is lower than target by too much!"; | 443 << " The datarate for the file is lower than target by too much!"; |
350 ASSERT_LE(effective_datarate_, cfg_.rc_target_bitrate * 1.15) | 444 ASSERT_LE(effective_datarate_[0], cfg_.rc_target_bitrate * 1.15) |
351 << " The datarate for the file is greater than target by too much!"; | 445 << " The datarate for the file is greater than target by too much!"; |
352 ASSERT_LE(first_drop_, last_drop) | 446 ASSERT_LE(first_drop_, last_drop) |
353 << " The first dropped frame for drop_thresh " << i | 447 << " The first dropped frame for drop_thresh " << i |
354 << " > first dropped frame for drop_thresh " | 448 << " > first dropped frame for drop_thresh " |
355 << i - kDropFrameThreshTestStep; | 449 << i - kDropFrameThreshTestStep; |
356 ASSERT_GE(num_drops_, last_num_drops) | 450 ASSERT_GE(num_drops_, last_num_drops) |
357 << " The number of dropped frames for drop_thresh " << i | 451 << " The number of dropped frames for drop_thresh " << i |
358 << " < number of dropped frames for drop_thresh " | 452 << " < number of dropped frames for drop_thresh " |
359 << i - kDropFrameThreshTestStep; | 453 << i - kDropFrameThreshTestStep; |
360 last_drop = first_drop_; | 454 last_drop = first_drop_; |
361 last_num_drops = num_drops_; | 455 last_num_drops = num_drops_; |
362 } | 456 } |
363 } | 457 } |
364 | 458 |
| 459 // Check basic rate targeting for 2 temporal layers. |
| 460 TEST_P(DatarateTestVP9, BasicRateTargeting2TemporalLayers) { |
| 461 cfg_.rc_buf_initial_sz = 500; |
| 462 cfg_.rc_buf_optimal_sz = 500; |
| 463 cfg_.rc_buf_sz = 1000; |
| 464 cfg_.rc_dropframe_thresh = 1; |
| 465 cfg_.rc_min_quantizer = 0; |
| 466 cfg_.rc_max_quantizer = 63; |
| 467 cfg_.rc_end_usage = VPX_CBR; |
| 468 cfg_.g_lag_in_frames = 0; |
| 469 |
| 470 // 2 Temporal layers, no spatial layers: Framerate decimation (2, 1). |
| 471 cfg_.ss_number_layers = 1; |
| 472 cfg_.ts_number_layers = 2; |
| 473 cfg_.ts_rate_decimator[0] = 2; |
| 474 cfg_.ts_rate_decimator[1] = 1; |
| 475 |
| 476 ::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, |
| 477 30, 1, 0, 200); |
| 478 for (int i = 200; i <= 800; i += 200) { |
| 479 cfg_.rc_target_bitrate = i; |
| 480 ResetModel(); |
| 481 // 60-40 bitrate allocation for 2 temporal layers. |
| 482 cfg_.ts_target_bitrate[0] = 60 * cfg_.rc_target_bitrate / 100; |
| 483 cfg_.ts_target_bitrate[1] = cfg_.rc_target_bitrate; |
| 484 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 485 for (int j = 0; j < static_cast<int>(cfg_.ts_number_layers); ++j) { |
| 486 ASSERT_GE(effective_datarate_[j], cfg_.ts_target_bitrate[j] * 0.85) |
| 487 << " The datarate for the file is lower than target by too much, " |
| 488 "for layer: " << j; |
| 489 ASSERT_LE(effective_datarate_[j], cfg_.ts_target_bitrate[j] * 1.15) |
| 490 << " The datarate for the file is greater than target by too much, " |
| 491 "for layer: " << j; |
| 492 } |
| 493 } |
| 494 } |
| 495 |
| 496 // Check basic rate targeting for 3 temporal layers. |
| 497 TEST_P(DatarateTestVP9, BasicRateTargeting3TemporalLayers) { |
| 498 cfg_.rc_buf_initial_sz = 500; |
| 499 cfg_.rc_buf_optimal_sz = 500; |
| 500 cfg_.rc_buf_sz = 1000; |
| 501 cfg_.rc_dropframe_thresh = 1; |
| 502 cfg_.rc_min_quantizer = 0; |
| 503 cfg_.rc_max_quantizer = 63; |
| 504 cfg_.rc_end_usage = VPX_CBR; |
| 505 cfg_.g_lag_in_frames = 0; |
| 506 |
| 507 // 3 Temporal layers, no spatial layers: Framerate decimation (4, 2, 1). |
| 508 cfg_.ss_number_layers = 1; |
| 509 cfg_.ts_number_layers = 3; |
| 510 cfg_.ts_rate_decimator[0] = 4; |
| 511 cfg_.ts_rate_decimator[1] = 2; |
| 512 cfg_.ts_rate_decimator[2] = 1; |
| 513 |
| 514 ::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, |
| 515 30, 1, 0, 200); |
| 516 for (int i = 200; i <= 800; i += 200) { |
| 517 cfg_.rc_target_bitrate = i; |
| 518 ResetModel(); |
| 519 // 40-20-40 bitrate allocation for 3 temporal layers. |
| 520 cfg_.ts_target_bitrate[0] = 40 * cfg_.rc_target_bitrate / 100; |
| 521 cfg_.ts_target_bitrate[1] = 60 * cfg_.rc_target_bitrate / 100; |
| 522 cfg_.ts_target_bitrate[2] = cfg_.rc_target_bitrate; |
| 523 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 524 for (int j = 0; j < static_cast<int>(cfg_.ts_number_layers); ++j) { |
| 525 ASSERT_GE(effective_datarate_[j], cfg_.ts_target_bitrate[j] * 0.85) |
| 526 << " The datarate for the file is lower than target by too much, " |
| 527 "for layer: " << j; |
| 528 ASSERT_LE(effective_datarate_[j], cfg_.ts_target_bitrate[j] * 1.15) |
| 529 << " The datarate for the file is greater than target by too much, " |
| 530 "for layer: " << j; |
| 531 } |
| 532 } |
| 533 } |
| 534 |
| 535 // Check basic rate targeting for 3 temporal layers, with frame dropping. |
| 536 // Only for one (low) bitrate with lower max_quantizer, and somewhat higher |
| 537 // frame drop threshold, to force frame dropping. |
| 538 TEST_P(DatarateTestVP9, BasicRateTargeting3TemporalLayersFrameDropping) { |
| 539 cfg_.rc_buf_initial_sz = 500; |
| 540 cfg_.rc_buf_optimal_sz = 500; |
| 541 cfg_.rc_buf_sz = 1000; |
| 542 // Set frame drop threshold and rc_max_quantizer to force some frame drops. |
| 543 cfg_.rc_dropframe_thresh = 20; |
| 544 cfg_.rc_max_quantizer = 45; |
| 545 cfg_.rc_min_quantizer = 0; |
| 546 cfg_.rc_end_usage = VPX_CBR; |
| 547 cfg_.g_lag_in_frames = 0; |
| 548 |
| 549 // 3 Temporal layers, no spatial layers: Framerate decimation (4, 2, 1). |
| 550 cfg_.ss_number_layers = 1; |
| 551 cfg_.ts_number_layers = 3; |
| 552 cfg_.ts_rate_decimator[0] = 4; |
| 553 cfg_.ts_rate_decimator[1] = 2; |
| 554 cfg_.ts_rate_decimator[2] = 1; |
| 555 |
| 556 ::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, |
| 557 30, 1, 0, 200); |
| 558 cfg_.rc_target_bitrate = 200; |
| 559 ResetModel(); |
| 560 // 40-20-40 bitrate allocation for 3 temporal layers. |
| 561 cfg_.ts_target_bitrate[0] = 40 * cfg_.rc_target_bitrate / 100; |
| 562 cfg_.ts_target_bitrate[1] = 60 * cfg_.rc_target_bitrate / 100; |
| 563 cfg_.ts_target_bitrate[2] = cfg_.rc_target_bitrate; |
| 564 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 565 for (int j = 0; j < static_cast<int>(cfg_.ts_number_layers); ++j) { |
| 566 ASSERT_GE(effective_datarate_[j], cfg_.ts_target_bitrate[j] * 0.85) |
| 567 << " The datarate for the file is lower than target by too much, " |
| 568 "for layer: " << j; |
| 569 ASSERT_LE(effective_datarate_[j], cfg_.ts_target_bitrate[j] * 1.15) |
| 570 << " The datarate for the file is greater than target by too much, " |
| 571 "for layer: " << j; |
| 572 // Expect some frame drops in this test: for this 200 frames test, |
| 573 // expect at least 10% and not more than 50% drops. |
| 574 ASSERT_GE(num_drops_, 20); |
| 575 ASSERT_LE(num_drops_, 100); |
| 576 } |
| 577 } |
| 578 |
365 VP8_INSTANTIATE_TEST_CASE(DatarateTest, ALL_TEST_MODES); | 579 VP8_INSTANTIATE_TEST_CASE(DatarateTest, ALL_TEST_MODES); |
366 VP9_INSTANTIATE_TEST_CASE(DatarateTestVP9, | 580 VP9_INSTANTIATE_TEST_CASE(DatarateTestVP9, |
367 ::testing::Values(::libvpx_test::kOnePassGood), | 581 ::testing::Values(::libvpx_test::kOnePassGood), |
368 ::testing::Range(1, 5)); | 582 ::testing::Range(2, 5)); |
369 } // namespace | 583 } // namespace |
OLD | NEW |