diff options
author | Yunqing Wang <yunqingwang@google.com> | 2014-12-12 14:34:30 -0800 |
---|---|---|
committer | Yunqing Wang <yunqingwang@google.com> | 2014-12-17 08:49:46 -0800 |
commit | 3666478195144bdf207d99877d2005af231a5651 (patch) | |
tree | 171e2734523e6ec2b4b6c97580e38c007227b184 /test | |
parent | aeeaa679876be7709e55152c979c562787253c49 (diff) | |
download | libvpx-3666478195144bdf207d99877d2005af231a5651.tar libvpx-3666478195144bdf207d99877d2005af231a5651.tar.gz libvpx-3666478195144bdf207d99877d2005af231a5651.tar.bz2 libvpx-3666478195144bdf207d99877d2005af231a5651.zip |
Improve the libvpx encoder test driver
The encoder initialization is called in EncodeFrame(). Therefore,
in the unit tests, the set control is done when video->frame() is 1.
This didn't cause problem since current tests mainly test lag_frame
> 0 case, or no encoding option that needs to allocate memory before
1st frame is used. If use lag_frame = 0 and encoding multiple tiles,
the unit tests crash. The issue is fixed by doing the initialization
before encoding frames.
Change-Id: I43102048f88448bcf27e9c60e0ec06c176b02e5c
Diffstat (limited to 'test')
-rw-r--r-- | test/encode_test_driver.cc | 31 | ||||
-rw-r--r-- | test/encode_test_driver.h | 2 |
2 files changed, 21 insertions, 12 deletions
diff --git a/test/encode_test_driver.cc b/test/encode_test_driver.cc index b49e8cba2..7a133643d 100644 --- a/test/encode_test_driver.cc +++ b/test/encode_test_driver.cc @@ -17,6 +17,21 @@ #include "third_party/googletest/src/include/gtest/gtest.h" namespace libvpx_test { +void Encoder::InitEncoder(VideoSource *video) { + vpx_codec_err_t res; + const vpx_image_t *img = video->img(); + + if (video->img() && !encoder_.priv) { + cfg_.g_w = img->d_w; + cfg_.g_h = img->d_h; + cfg_.g_timebase = video->timebase(); + cfg_.rc_twopass_stats_in = stats_->buf(); + res = vpx_codec_enc_init(&encoder_, CodecInterface(), &cfg_, + init_flags_); + ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError(); + } +} + void Encoder::EncodeFrame(VideoSource *video, const unsigned long frame_flags) { if (video->img()) EncodeFrameInternal(*video, frame_flags); @@ -39,17 +54,6 @@ void Encoder::EncodeFrameInternal(const VideoSource &video, vpx_codec_err_t res; const vpx_image_t *img = video.img(); - // Handle first frame initialization - if (!encoder_.priv) { - cfg_.g_w = img->d_w; - cfg_.g_h = img->d_h; - cfg_.g_timebase = video.timebase(); - cfg_.rc_twopass_stats_in = stats_->buf(); - res = vpx_codec_enc_init(&encoder_, CodecInterface(), &cfg_, - init_flags_); - ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError(); - } - // Handle frame resizing if (cfg_.g_w != img->d_w || cfg_.g_h != img->d_h) { cfg_.g_w = img->d_w; @@ -160,6 +164,9 @@ void EncoderTest::RunLoop(VideoSource *video) { &stats_); ASSERT_TRUE(encoder != NULL); + video->Begin(); + encoder->InitEncoder(video); + unsigned long dec_init_flags = 0; // NOLINT // Use fragment decoder if encoder outputs partitions. // NOTE: fragment decoder and partition encoder are only supported by VP8. @@ -167,7 +174,7 @@ void EncoderTest::RunLoop(VideoSource *video) { dec_init_flags |= VPX_CODEC_USE_INPUT_FRAGMENTS; Decoder* const decoder = codec_->CreateDecoder(dec_cfg, dec_init_flags, 0); bool again; - for (again = true, video->Begin(); again; video->Next()) { + for (again = true; again; video->Next()) { again = (video->img() != NULL); PreEncodeFrameHook(video); diff --git a/test/encode_test_driver.h b/test/encode_test_driver.h index 770ac7e92..765c7d164 100644 --- a/test/encode_test_driver.h +++ b/test/encode_test_driver.h @@ -104,6 +104,8 @@ class Encoder { return CxDataIterator(&encoder_); } + void InitEncoder(VideoSource *video); + const vpx_image_t *GetPreviewFrame() { return vpx_codec_get_preview_frame(&encoder_); } |