1ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang/*
2ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang *  Copyright (c) 2012 The WebM project authors. All Rights Reserved.
3ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang *
4ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang *  Use of this source code is governed by a BSD-style license
5ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang *  that can be found in the LICENSE file in the root of the source
6ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang *  tree. An additional intellectual property rights grant can be found
7ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang *  in the file PATENTS.  All contributing project authors may
8ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang *  be found in the AUTHORS file in the root of the source tree.
9ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang */
10ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang#include <climits>
11ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang#include <vector>
12ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang#include "third_party/googletest/src/include/gtest/gtest.h"
13ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang#include "test/codec_factory.h"
14ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang#include "test/encode_test_driver.h"
15ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang#include "test/i420_video_source.h"
16ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang#include "test/util.h"
17ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang
18ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuangnamespace {
19ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang
207bc9febe8749e98a3812a0dc4380ceae75c29450Johannclass BordersTest
217bc9febe8749e98a3812a0dc4380ceae75c29450Johann    : public ::libvpx_test::EncoderTest,
227bc9febe8749e98a3812a0dc4380ceae75c29450Johann      public ::libvpx_test::CodecTestWithParam<libvpx_test::TestMode> {
23ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang protected:
24ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang  BordersTest() : EncoderTest(GET_PARAM(0)) {}
25a72801d7d92ababb50eecf27a36bd222d031d2feVignesh Venkatasubramanian  virtual ~BordersTest() {}
26ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang
27ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang  virtual void SetUp() {
28ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang    InitializeConfig();
29ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang    SetMode(GET_PARAM(1));
30ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang  }
31ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang
32ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang  virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
33ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang                                  ::libvpx_test::Encoder *encoder) {
343df0563f1b24dac6c0bd122fc922a48211269061hkuang    if (video->frame() == 1) {
353df0563f1b24dac6c0bd122fc922a48211269061hkuang      encoder->Control(VP8E_SET_CPUUSED, 1);
36ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang      encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1);
37ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang      encoder->Control(VP8E_SET_ARNR_MAXFRAMES, 7);
38ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang      encoder->Control(VP8E_SET_ARNR_STRENGTH, 5);
39ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang      encoder->Control(VP8E_SET_ARNR_TYPE, 3);
40ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang    }
41ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang  }
42ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang
43ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang  virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) {
44ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang    if (pkt->data.frame.flags & VPX_FRAME_IS_KEY) {
45ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang    }
46ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang  }
47ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang};
48ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang
49ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuangTEST_P(BordersTest, TestEncodeHighBitrate) {
50ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang  // Validate that this non multiple of 64 wide clip encodes and decodes
51ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang  // without a mismatch when passing in a very low max q.  This pushes
52ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang  // the encoder to producing lots of big partitions which will likely
53ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang  // extend into the border and test the border condition.
54ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang  cfg_.g_lag_in_frames = 25;
55ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang  cfg_.rc_2pass_vbr_minsection_pct = 5;
5668e1c830ade592be74773e249bf94e2bbfb50de7Johann  cfg_.rc_2pass_vbr_maxsection_pct = 2000;
57ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang  cfg_.rc_target_bitrate = 2000;
58ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang  cfg_.rc_max_quantizer = 10;
59ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang
60ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang  ::libvpx_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
61ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang                                       40);
62ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang
63ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang  ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
64ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang}
65ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuangTEST_P(BordersTest, TestLowBitrate) {
66ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang  // Validate that this clip encodes and decodes without a mismatch
67ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang  // when passing in a very high min q.  This pushes the encoder to producing
68ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang  // lots of small partitions which might will test the other condition.
69ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang
70ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang  cfg_.g_lag_in_frames = 25;
71ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang  cfg_.rc_2pass_vbr_minsection_pct = 5;
72b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian  cfg_.rc_2pass_vbr_maxsection_pct = 2000;
73ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang  cfg_.rc_target_bitrate = 200;
74ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang  cfg_.rc_min_quantizer = 40;
75ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang
76ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang  ::libvpx_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
77ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang                                       40);
78ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang
79ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang  ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
80ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang}
81ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang
827bc9febe8749e98a3812a0dc4380ceae75c29450JohannVP9_INSTANTIATE_TEST_CASE(BordersTest,
837bc9febe8749e98a3812a0dc4380ceae75c29450Johann                          ::testing::Values(::libvpx_test::kTwoPassGood));
84ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang}  // namespace
85