OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
24 using libvpx_test::VP9CodecFactory; | 24 using libvpx_test::VP9CodecFactory; |
25 | 25 |
26 class SvcTest : public ::testing::Test { | 26 class SvcTest : public ::testing::Test { |
27 protected: | 27 protected: |
28 static const uint32_t kWidth = 352; | 28 static const uint32_t kWidth = 352; |
29 static const uint32_t kHeight = 288; | 29 static const uint32_t kHeight = 288; |
30 | 30 |
31 SvcTest() | 31 SvcTest() |
32 : codec_iface_(0), | 32 : codec_iface_(0), |
33 test_file_name_("hantro_collage_w352h288.yuv"), | 33 test_file_name_("hantro_collage_w352h288.yuv"), |
34 stats_file_name_("hantro_collage_w352h288.stat"), | |
35 codec_initialized_(false), | 34 codec_initialized_(false), |
36 decoder_(0) { | 35 decoder_(0) { |
37 memset(&svc_, 0, sizeof(svc_)); | 36 memset(&svc_, 0, sizeof(svc_)); |
38 memset(&codec_, 0, sizeof(codec_)); | 37 memset(&codec_, 0, sizeof(codec_)); |
39 memset(&codec_enc_, 0, sizeof(codec_enc_)); | 38 memset(&codec_enc_, 0, sizeof(codec_enc_)); |
40 } | 39 } |
41 | 40 |
42 virtual ~SvcTest() {} | 41 virtual ~SvcTest() {} |
43 | 42 |
44 virtual void SetUp() { | 43 virtual void SetUp() { |
(...skipping 22 matching lines...) Expand all Loading... |
67 vpx_svc_release(&svc_); | 66 vpx_svc_release(&svc_); |
68 delete(decoder_); | 67 delete(decoder_); |
69 if (codec_initialized_) vpx_codec_destroy(&codec_); | 68 if (codec_initialized_) vpx_codec_destroy(&codec_); |
70 } | 69 } |
71 | 70 |
72 SvcContext svc_; | 71 SvcContext svc_; |
73 vpx_codec_ctx_t codec_; | 72 vpx_codec_ctx_t codec_; |
74 struct vpx_codec_enc_cfg codec_enc_; | 73 struct vpx_codec_enc_cfg codec_enc_; |
75 vpx_codec_iface_t *codec_iface_; | 74 vpx_codec_iface_t *codec_iface_; |
76 std::string test_file_name_; | 75 std::string test_file_name_; |
77 std::string stats_file_name_; | |
78 bool codec_initialized_; | 76 bool codec_initialized_; |
79 Decoder *decoder_; | 77 Decoder *decoder_; |
80 }; | 78 }; |
81 | 79 |
82 TEST_F(SvcTest, SvcInit) { | 80 TEST_F(SvcTest, SvcInit) { |
83 // test missing parameters | 81 // test missing parameters |
84 vpx_codec_err_t res = vpx_svc_init(NULL, &codec_, codec_iface_, &codec_enc_); | 82 vpx_codec_err_t res = vpx_svc_init(NULL, &codec_, codec_iface_, &codec_enc_); |
85 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); | 83 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); |
86 res = vpx_svc_init(&svc_, NULL, codec_iface_, &codec_enc_); | 84 res = vpx_svc_init(&svc_, NULL, codec_iface_, &codec_enc_); |
87 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); | 85 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 EXPECT_EQ(VPX_CODEC_OK, res); | 355 EXPECT_EQ(VPX_CODEC_OK, res); |
358 EXPECT_EQ(kWidth * 4 / 16, layer_width); | 356 EXPECT_EQ(kWidth * 4 / 16, layer_width); |
359 EXPECT_EQ(kHeight * 4 / 16, layer_height); | 357 EXPECT_EQ(kHeight * 4 / 16, layer_height); |
360 | 358 |
361 res = vpx_svc_get_layer_resolution(&svc_, 1, &layer_width, &layer_height); | 359 res = vpx_svc_get_layer_resolution(&svc_, 1, &layer_width, &layer_height); |
362 EXPECT_EQ(VPX_CODEC_OK, res); | 360 EXPECT_EQ(VPX_CODEC_OK, res); |
363 EXPECT_EQ(kWidth * 8 / 16, layer_width); | 361 EXPECT_EQ(kWidth * 8 / 16, layer_width); |
364 EXPECT_EQ(kHeight * 8 / 16, layer_height); | 362 EXPECT_EQ(kHeight * 8 / 16, layer_height); |
365 } | 363 } |
366 | 364 |
367 TEST_F(SvcTest, FirstPassEncode) { | 365 TEST_F(SvcTest, TwoPassEncode) { |
| 366 // First pass encode |
| 367 std::string stats_buf; |
368 svc_.spatial_layers = 2; | 368 svc_.spatial_layers = 2; |
369 codec_enc_.g_pass = VPX_RC_FIRST_PASS; | 369 codec_enc_.g_pass = VPX_RC_FIRST_PASS; |
370 vpx_svc_set_scale_factors(&svc_, "4/16,16/16"); | 370 vpx_svc_set_scale_factors(&svc_, "4/16,16/16"); |
371 vpx_svc_set_quantizers(&svc_, "40,30", 0); | 371 vpx_svc_set_quantizers(&svc_, "40,30", 0); |
372 | 372 |
373 vpx_codec_err_t res = | 373 vpx_codec_err_t res = |
374 vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_); | 374 vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_); |
375 ASSERT_EQ(VPX_CODEC_OK, res); | 375 ASSERT_EQ(VPX_CODEC_OK, res); |
376 codec_initialized_ = true; | 376 codec_initialized_ = true; |
377 | 377 |
378 libvpx_test::I420VideoSource video(test_file_name_, kWidth, kHeight, | 378 libvpx_test::I420VideoSource video(test_file_name_, kWidth, kHeight, |
379 codec_enc_.g_timebase.den, | 379 codec_enc_.g_timebase.den, |
380 codec_enc_.g_timebase.num, 0, 30); | 380 codec_enc_.g_timebase.num, 0, 30); |
381 // FRAME 0 | 381 // FRAME 0 |
382 video.Begin(); | 382 video.Begin(); |
383 res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(), | 383 res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(), |
384 video.duration(), VPX_DL_GOOD_QUALITY); | 384 video.duration(), VPX_DL_GOOD_QUALITY); |
385 ASSERT_EQ(VPX_CODEC_OK, res); | 385 ASSERT_EQ(VPX_CODEC_OK, res); |
386 EXPECT_GT(vpx_svc_get_rc_stats_buffer_size(&svc_), 0U); | 386 size_t stats_size = vpx_svc_get_rc_stats_buffer_size(&svc_); |
| 387 EXPECT_GT(stats_size, 0U); |
| 388 const char *stats_data = vpx_svc_get_rc_stats_buffer(&svc_); |
| 389 ASSERT_TRUE(stats_data != NULL); |
| 390 stats_buf.append(stats_data, stats_size); |
387 | 391 |
388 // FRAME 1 | 392 // FRAME 1 |
389 video.Next(); | 393 video.Next(); |
390 res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(), | 394 res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(), |
391 video.duration(), VPX_DL_GOOD_QUALITY); | 395 video.duration(), VPX_DL_GOOD_QUALITY); |
392 ASSERT_EQ(VPX_CODEC_OK, res); | 396 stats_size = vpx_svc_get_rc_stats_buffer_size(&svc_); |
393 EXPECT_GT(vpx_svc_get_rc_stats_buffer_size(&svc_), 0U); | 397 EXPECT_GT(stats_size, 0U); |
| 398 stats_data = vpx_svc_get_rc_stats_buffer(&svc_); |
| 399 ASSERT_TRUE(stats_data != NULL); |
| 400 stats_buf.append(stats_data, stats_size); |
394 | 401 |
395 // Flush encoder and test EOS packet | 402 // Flush encoder and test EOS packet |
396 res = vpx_svc_encode(&svc_, &codec_, NULL, video.pts(), | 403 res = vpx_svc_encode(&svc_, &codec_, NULL, video.pts(), |
397 video.duration(), VPX_DL_GOOD_QUALITY); | 404 video.duration(), VPX_DL_GOOD_QUALITY); |
398 ASSERT_EQ(VPX_CODEC_OK, res); | 405 stats_size = vpx_svc_get_rc_stats_buffer_size(&svc_); |
399 EXPECT_GT(vpx_svc_get_rc_stats_buffer_size(&svc_), 0U); | 406 EXPECT_GT(stats_size, 0U); |
400 } | 407 stats_data = vpx_svc_get_rc_stats_buffer(&svc_); |
| 408 ASSERT_TRUE(stats_data != NULL); |
| 409 stats_buf.append(stats_data, stats_size); |
401 | 410 |
402 TEST_F(SvcTest, SecondPassEncode) { | 411 // Tear down encoder |
403 svc_.spatial_layers = 2; | 412 vpx_svc_release(&svc_); |
| 413 vpx_codec_destroy(&codec_); |
| 414 |
| 415 // Second pass encode |
404 codec_enc_.g_pass = VPX_RC_LAST_PASS; | 416 codec_enc_.g_pass = VPX_RC_LAST_PASS; |
| 417 codec_enc_.rc_twopass_stats_in.buf = &stats_buf[0]; |
| 418 codec_enc_.rc_twopass_stats_in.sz = stats_buf.size(); |
405 | 419 |
406 FILE *const stats_file = libvpx_test::OpenTestDataFile(stats_file_name_); | 420 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_); |
407 ASSERT_TRUE(stats_file != NULL) << "Stats file open failed. Filename: " | |
408 << stats_file; | |
409 | |
410 struct vpx_fixed_buf stats_buf; | |
411 fseek(stats_file, 0, SEEK_END); | |
412 stats_buf.sz = static_cast<size_t>(ftell(stats_file)); | |
413 fseek(stats_file, 0, SEEK_SET); | |
414 | |
415 stats_buf.buf = malloc(stats_buf.sz); | |
416 ASSERT_TRUE(stats_buf.buf != NULL); | |
417 const size_t bytes_read = fread(stats_buf.buf, 1, stats_buf.sz, stats_file); | |
418 ASSERT_EQ(bytes_read, stats_buf.sz); | |
419 fclose(stats_file); | |
420 codec_enc_.rc_twopass_stats_in = stats_buf; | |
421 | |
422 vpx_codec_err_t res = | |
423 vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_); | |
424 ASSERT_EQ(VPX_CODEC_OK, res); | 421 ASSERT_EQ(VPX_CODEC_OK, res); |
425 codec_initialized_ = true; | 422 codec_initialized_ = true; |
426 | 423 |
427 libvpx_test::I420VideoSource video(test_file_name_, kWidth, kHeight, | |
428 codec_enc_.g_timebase.den, | |
429 codec_enc_.g_timebase.num, 0, 30); | |
430 // FRAME 0 | 424 // FRAME 0 |
431 video.Begin(); | 425 video.Begin(); |
432 // This frame is a keyframe. | 426 // This frame is a keyframe. |
433 res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(), | 427 res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(), |
434 video.duration(), VPX_DL_GOOD_QUALITY); | 428 video.duration(), VPX_DL_GOOD_QUALITY); |
435 ASSERT_EQ(VPX_CODEC_OK, res); | 429 ASSERT_EQ(VPX_CODEC_OK, res); |
436 EXPECT_EQ(1, vpx_svc_is_keyframe(&svc_)); | 430 EXPECT_EQ(1, vpx_svc_is_keyframe(&svc_)); |
437 | 431 |
438 vpx_codec_err_t res_dec = decoder_->DecodeFrame( | 432 vpx_codec_err_t res_dec = decoder_->DecodeFrame( |
439 static_cast<const uint8_t *>(vpx_svc_get_buffer(&svc_)), | 433 static_cast<const uint8_t *>(vpx_svc_get_buffer(&svc_)), |
(...skipping 18 matching lines...) Expand all Loading... |
458 // This is a P-frame. | 452 // This is a P-frame. |
459 res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(), | 453 res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(), |
460 video.duration(), VPX_DL_GOOD_QUALITY); | 454 video.duration(), VPX_DL_GOOD_QUALITY); |
461 ASSERT_EQ(VPX_CODEC_OK, res); | 455 ASSERT_EQ(VPX_CODEC_OK, res); |
462 EXPECT_EQ(0, vpx_svc_is_keyframe(&svc_)); | 456 EXPECT_EQ(0, vpx_svc_is_keyframe(&svc_)); |
463 | 457 |
464 res_dec = decoder_->DecodeFrame( | 458 res_dec = decoder_->DecodeFrame( |
465 static_cast<const uint8_t *>(vpx_svc_get_buffer(&svc_)), | 459 static_cast<const uint8_t *>(vpx_svc_get_buffer(&svc_)), |
466 vpx_svc_get_frame_size(&svc_)); | 460 vpx_svc_get_frame_size(&svc_)); |
467 ASSERT_EQ(VPX_CODEC_OK, res_dec) << decoder_->DecodeError(); | 461 ASSERT_EQ(VPX_CODEC_OK, res_dec) << decoder_->DecodeError(); |
468 | |
469 free(stats_buf.buf); | |
470 } | 462 } |
471 | 463 |
472 } // namespace | 464 } // namespace |
OLD | NEW |