Index: source/libvpx/test/svc_test.cc |
=================================================================== |
--- source/libvpx/test/svc_test.cc (revision 278778) |
+++ source/libvpx/test/svc_test.cc (working copy) |
@@ -31,7 +31,6 @@ |
SvcTest() |
: codec_iface_(0), |
test_file_name_("hantro_collage_w352h288.yuv"), |
- stats_file_name_("hantro_collage_w352h288.stat"), |
codec_initialized_(false), |
decoder_(0) { |
memset(&svc_, 0, sizeof(svc_)); |
@@ -74,7 +73,6 @@ |
struct vpx_codec_enc_cfg codec_enc_; |
vpx_codec_iface_t *codec_iface_; |
std::string test_file_name_; |
- std::string stats_file_name_; |
bool codec_initialized_; |
Decoder *decoder_; |
}; |
@@ -364,7 +362,9 @@ |
EXPECT_EQ(kHeight * 8 / 16, layer_height); |
} |
-TEST_F(SvcTest, FirstPassEncode) { |
+TEST_F(SvcTest, TwoPassEncode) { |
+ // First pass encode |
+ std::string stats_buf; |
svc_.spatial_layers = 2; |
codec_enc_.g_pass = VPX_RC_FIRST_PASS; |
vpx_svc_set_scale_factors(&svc_, "4/16,16/16"); |
@@ -383,50 +383,44 @@ |
res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(), |
video.duration(), VPX_DL_GOOD_QUALITY); |
ASSERT_EQ(VPX_CODEC_OK, res); |
- EXPECT_GT(vpx_svc_get_rc_stats_buffer_size(&svc_), 0U); |
+ size_t stats_size = vpx_svc_get_rc_stats_buffer_size(&svc_); |
+ EXPECT_GT(stats_size, 0U); |
+ const char *stats_data = vpx_svc_get_rc_stats_buffer(&svc_); |
+ ASSERT_TRUE(stats_data != NULL); |
+ stats_buf.append(stats_data, stats_size); |
// FRAME 1 |
video.Next(); |
res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(), |
video.duration(), VPX_DL_GOOD_QUALITY); |
- ASSERT_EQ(VPX_CODEC_OK, res); |
- EXPECT_GT(vpx_svc_get_rc_stats_buffer_size(&svc_), 0U); |
+ stats_size = vpx_svc_get_rc_stats_buffer_size(&svc_); |
+ EXPECT_GT(stats_size, 0U); |
+ stats_data = vpx_svc_get_rc_stats_buffer(&svc_); |
+ ASSERT_TRUE(stats_data != NULL); |
+ stats_buf.append(stats_data, stats_size); |
// Flush encoder and test EOS packet |
res = vpx_svc_encode(&svc_, &codec_, NULL, video.pts(), |
video.duration(), VPX_DL_GOOD_QUALITY); |
- ASSERT_EQ(VPX_CODEC_OK, res); |
- EXPECT_GT(vpx_svc_get_rc_stats_buffer_size(&svc_), 0U); |
-} |
+ stats_size = vpx_svc_get_rc_stats_buffer_size(&svc_); |
+ EXPECT_GT(stats_size, 0U); |
+ stats_data = vpx_svc_get_rc_stats_buffer(&svc_); |
+ ASSERT_TRUE(stats_data != NULL); |
+ stats_buf.append(stats_data, stats_size); |
-TEST_F(SvcTest, SecondPassEncode) { |
- svc_.spatial_layers = 2; |
+ // Tear down encoder |
+ vpx_svc_release(&svc_); |
+ vpx_codec_destroy(&codec_); |
+ |
+ // Second pass encode |
codec_enc_.g_pass = VPX_RC_LAST_PASS; |
+ codec_enc_.rc_twopass_stats_in.buf = &stats_buf[0]; |
+ codec_enc_.rc_twopass_stats_in.sz = stats_buf.size(); |
- FILE *const stats_file = libvpx_test::OpenTestDataFile(stats_file_name_); |
- ASSERT_TRUE(stats_file != NULL) << "Stats file open failed. Filename: " |
- << stats_file; |
- |
- struct vpx_fixed_buf stats_buf; |
- fseek(stats_file, 0, SEEK_END); |
- stats_buf.sz = static_cast<size_t>(ftell(stats_file)); |
- fseek(stats_file, 0, SEEK_SET); |
- |
- stats_buf.buf = malloc(stats_buf.sz); |
- ASSERT_TRUE(stats_buf.buf != NULL); |
- const size_t bytes_read = fread(stats_buf.buf, 1, stats_buf.sz, stats_file); |
- ASSERT_EQ(bytes_read, stats_buf.sz); |
- fclose(stats_file); |
- codec_enc_.rc_twopass_stats_in = stats_buf; |
- |
- vpx_codec_err_t res = |
- vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_); |
+ res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_); |
ASSERT_EQ(VPX_CODEC_OK, res); |
codec_initialized_ = true; |
- libvpx_test::I420VideoSource video(test_file_name_, kWidth, kHeight, |
- codec_enc_.g_timebase.den, |
- codec_enc_.g_timebase.num, 0, 30); |
// FRAME 0 |
video.Begin(); |
// This frame is a keyframe. |
@@ -465,8 +459,6 @@ |
static_cast<const uint8_t *>(vpx_svc_get_buffer(&svc_)), |
vpx_svc_get_frame_size(&svc_)); |
ASSERT_EQ(VPX_CODEC_OK, res_dec) << decoder_->DecodeError(); |
- |
- free(stats_buf.buf); |
} |
} // namespace |