2 * Copyright (c) 2012 The WebM project authors. All Rights Reserved.
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
10 #include "test/encode_test_driver.h"
11 #include "test/video_source.h"
12 #include "third_party/googletest/src/include/gtest/gtest.h"
14 namespace libvpx_test {
16 void Encoder::EncodeFrame(VideoSource *video, unsigned long flags) {
18 EncodeFrameInternal(*video, flags);
22 // Handle twopass stats
23 CxDataIterator iter = GetCxData();
25 while (const vpx_codec_cx_pkt_t *pkt = iter.Next()) {
26 if (pkt->kind != VPX_CODEC_STATS_PKT)
33 void Encoder::EncodeFrameInternal(const VideoSource &video,
34 unsigned long flags) {
36 const vpx_image_t *img = video.img();
38 // Handle first frame initialization
42 cfg_.g_timebase = video.timebase();
43 cfg_.rc_twopass_stats_in = stats_->buf();
44 res = vpx_codec_enc_init(&encoder_, &vpx_codec_vp8_cx_algo, &cfg_, 0);
45 ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError();
48 // Handle frame resizing
49 if (cfg_.g_w != img->d_w || cfg_.g_h != img->d_h) {
52 res = vpx_codec_enc_config_set(&encoder_, &cfg_);
53 ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError();
57 res = vpx_codec_encode(&encoder_,
58 video.img(), video.pts(), video.duration(),
60 ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError();
63 void Encoder::Flush() {
64 const vpx_codec_err_t res = vpx_codec_encode(&encoder_, NULL, 0, 0, 0,
66 ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError();
69 void EncoderTest::SetMode(TestMode mode) {
72 deadline_ = VPX_DL_REALTIME;
77 deadline_ = VPX_DL_GOOD_QUALITY;
82 deadline_ = VPX_DL_BEST_QUALITY;
86 ASSERT_TRUE(false) << "Unexpected mode " << mode;
89 if (mode == kTwoPassGood || mode == kTwoPassBest)
95 void EncoderTest::RunLoop(VideoSource *video) {
96 for (unsigned int pass = 0; pass < passes_; pass++) {
98 cfg_.g_pass = VPX_RC_ONE_PASS;
100 cfg_.g_pass = VPX_RC_FIRST_PASS;
102 cfg_.g_pass = VPX_RC_LAST_PASS;
105 Encoder encoder(cfg_, deadline_, &stats_);
109 for (video->Begin(), again = true; again; video->Next()) {
110 again = video->img() != NULL;
112 PreEncodeFrameHook(video);
113 encoder.EncodeFrame(video, flags_);
115 CxDataIterator iter = encoder.GetCxData();
117 while (const vpx_codec_cx_pkt_t *pkt = iter.Next()) {
120 if (pkt->kind != VPX_CODEC_CX_FRAME_PKT)
137 } // namespace libvpx_test