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"), |
34 codec_initialized_(false), | 35 codec_initialized_(false), |
35 decoder_(0) { | 36 decoder_(0) { |
36 memset(&svc_, 0, sizeof(svc_)); | 37 memset(&svc_, 0, sizeof(svc_)); |
37 memset(&codec_, 0, sizeof(codec_)); | 38 memset(&codec_, 0, sizeof(codec_)); |
38 memset(&codec_enc_, 0, sizeof(codec_enc_)); | 39 memset(&codec_enc_, 0, sizeof(codec_enc_)); |
39 } | 40 } |
40 | 41 |
41 virtual ~SvcTest() {} | 42 virtual ~SvcTest() {} |
42 | 43 |
43 virtual void SetUp() { | 44 virtual void SetUp() { |
(...skipping 22 matching lines...) Expand all Loading... |
66 vpx_svc_release(&svc_); | 67 vpx_svc_release(&svc_); |
67 delete(decoder_); | 68 delete(decoder_); |
68 if (codec_initialized_) vpx_codec_destroy(&codec_); | 69 if (codec_initialized_) vpx_codec_destroy(&codec_); |
69 } | 70 } |
70 | 71 |
71 SvcContext svc_; | 72 SvcContext svc_; |
72 vpx_codec_ctx_t codec_; | 73 vpx_codec_ctx_t codec_; |
73 struct vpx_codec_enc_cfg codec_enc_; | 74 struct vpx_codec_enc_cfg codec_enc_; |
74 vpx_codec_iface_t *codec_iface_; | 75 vpx_codec_iface_t *codec_iface_; |
75 std::string test_file_name_; | 76 std::string test_file_name_; |
| 77 std::string stats_file_name_; |
76 bool codec_initialized_; | 78 bool codec_initialized_; |
77 Decoder *decoder_; | 79 Decoder *decoder_; |
78 }; | 80 }; |
79 | 81 |
80 TEST_F(SvcTest, SvcInit) { | 82 TEST_F(SvcTest, SvcInit) { |
81 // test missing parameters | 83 // test missing parameters |
82 vpx_codec_err_t res = vpx_svc_init(NULL, &codec_, codec_iface_, &codec_enc_); | 84 vpx_codec_err_t res = vpx_svc_init(NULL, &codec_, codec_iface_, &codec_enc_); |
83 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); | 85 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); |
84 res = vpx_svc_init(&svc_, NULL, codec_iface_, &codec_enc_); | 86 res = vpx_svc_init(&svc_, NULL, codec_iface_, &codec_enc_); |
85 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); | 87 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 EXPECT_EQ(VPX_CODEC_OK, res); | 357 EXPECT_EQ(VPX_CODEC_OK, res); |
356 EXPECT_EQ(kWidth * 4 / 16, layer_width); | 358 EXPECT_EQ(kWidth * 4 / 16, layer_width); |
357 EXPECT_EQ(kHeight * 4 / 16, layer_height); | 359 EXPECT_EQ(kHeight * 4 / 16, layer_height); |
358 | 360 |
359 res = vpx_svc_get_layer_resolution(&svc_, 1, &layer_width, &layer_height); | 361 res = vpx_svc_get_layer_resolution(&svc_, 1, &layer_width, &layer_height); |
360 EXPECT_EQ(VPX_CODEC_OK, res); | 362 EXPECT_EQ(VPX_CODEC_OK, res); |
361 EXPECT_EQ(kWidth * 8 / 16, layer_width); | 363 EXPECT_EQ(kWidth * 8 / 16, layer_width); |
362 EXPECT_EQ(kHeight * 8 / 16, layer_height); | 364 EXPECT_EQ(kHeight * 8 / 16, layer_height); |
363 } | 365 } |
364 | 366 |
| 367 TEST_F(SvcTest, FirstPassEncode) { |
| 368 svc_.spatial_layers = 2; |
| 369 codec_enc_.g_pass = VPX_RC_FIRST_PASS; |
| 370 vpx_svc_set_scale_factors(&svc_, "4/16,16/16"); |
| 371 vpx_svc_set_quantizers(&svc_, "40,30", 0); |
| 372 |
| 373 vpx_codec_err_t res = |
| 374 vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_); |
| 375 ASSERT_EQ(VPX_CODEC_OK, res); |
| 376 codec_initialized_ = true; |
| 377 |
| 378 libvpx_test::I420VideoSource video(test_file_name_, kWidth, kHeight, |
| 379 codec_enc_.g_timebase.den, |
| 380 codec_enc_.g_timebase.num, 0, 30); |
| 381 // FRAME 0 |
| 382 video.Begin(); |
| 383 res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(), |
| 384 video.duration(), VPX_DL_GOOD_QUALITY); |
| 385 ASSERT_EQ(VPX_CODEC_OK, res); |
| 386 EXPECT_GT(vpx_svc_get_rc_stats_buffer_size(&svc_), 0U); |
| 387 |
| 388 // FRAME 1 |
| 389 video.Next(); |
| 390 res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(), |
| 391 video.duration(), VPX_DL_GOOD_QUALITY); |
| 392 ASSERT_EQ(VPX_CODEC_OK, res); |
| 393 EXPECT_GT(vpx_svc_get_rc_stats_buffer_size(&svc_), 0U); |
| 394 |
| 395 // Flush encoder and test EOS packet |
| 396 res = vpx_svc_encode(&svc_, &codec_, NULL, video.pts(), |
| 397 video.duration(), VPX_DL_GOOD_QUALITY); |
| 398 ASSERT_EQ(VPX_CODEC_OK, res); |
| 399 EXPECT_GT(vpx_svc_get_rc_stats_buffer_size(&svc_), 0U); |
| 400 } |
| 401 |
| 402 TEST_F(SvcTest, SecondPassEncode) { |
| 403 svc_.spatial_layers = 2; |
| 404 codec_enc_.g_pass = VPX_RC_LAST_PASS; |
| 405 |
| 406 FILE *const stats_file = libvpx_test::OpenTestDataFile(stats_file_name_); |
| 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); |
| 425 codec_initialized_ = true; |
| 426 |
| 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 |
| 431 video.Begin(); |
| 432 // This frame is a keyframe. |
| 433 res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(), |
| 434 video.duration(), VPX_DL_GOOD_QUALITY); |
| 435 ASSERT_EQ(VPX_CODEC_OK, res); |
| 436 EXPECT_EQ(1, vpx_svc_is_keyframe(&svc_)); |
| 437 |
| 438 vpx_codec_err_t res_dec = decoder_->DecodeFrame( |
| 439 static_cast<const uint8_t *>(vpx_svc_get_buffer(&svc_)), |
| 440 vpx_svc_get_frame_size(&svc_)); |
| 441 ASSERT_EQ(VPX_CODEC_OK, res_dec) << decoder_->DecodeError(); |
| 442 |
| 443 // FRAME 1 |
| 444 video.Next(); |
| 445 // This is a P-frame. |
| 446 res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(), |
| 447 video.duration(), VPX_DL_GOOD_QUALITY); |
| 448 ASSERT_EQ(VPX_CODEC_OK, res); |
| 449 EXPECT_EQ(0, vpx_svc_is_keyframe(&svc_)); |
| 450 |
| 451 res_dec = decoder_->DecodeFrame( |
| 452 static_cast<const uint8_t *>(vpx_svc_get_buffer(&svc_)), |
| 453 vpx_svc_get_frame_size(&svc_)); |
| 454 ASSERT_EQ(VPX_CODEC_OK, res_dec) << decoder_->DecodeError(); |
| 455 |
| 456 // FRAME 2 |
| 457 video.Next(); |
| 458 // This is a P-frame. |
| 459 res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(), |
| 460 video.duration(), VPX_DL_GOOD_QUALITY); |
| 461 ASSERT_EQ(VPX_CODEC_OK, res); |
| 462 EXPECT_EQ(0, vpx_svc_is_keyframe(&svc_)); |
| 463 |
| 464 res_dec = decoder_->DecodeFrame( |
| 465 static_cast<const uint8_t *>(vpx_svc_get_buffer(&svc_)), |
| 466 vpx_svc_get_frame_size(&svc_)); |
| 467 ASSERT_EQ(VPX_CODEC_OK, res_dec) << decoder_->DecodeError(); |
| 468 |
| 469 free(stats_buf.buf); |
| 470 } |
| 471 |
365 } // namespace | 472 } // namespace |
OLD | NEW |