2 * Copyright (c) 2014 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.
13 #include "third_party/googletest/src/include/gtest/gtest.h"
14 #include "test/codec_factory.h"
15 #include "test/encode_test_driver.h"
16 #include "test/md5_helper.h"
17 #include "test/util.h"
18 #include "test/y4m_video_source.h"
21 class VP9EncoderThreadTest
22 : public ::libvpx_test::EncoderTest,
23 public ::libvpx_test::CodecTestWith2Params<libvpx_test::TestMode, int> {
25 VP9EncoderThreadTest()
26 : EncoderTest(GET_PARAM(0)),
28 encoding_mode_(GET_PARAM(1)),
29 set_cpu_used_(GET_PARAM(2)) {
30 init_flags_ = VPX_CODEC_USE_PSNR;
31 vpx_codec_dec_cfg_t cfg = vpx_codec_dec_cfg_t();
34 decoder_ = codec_->CreateDecoder(cfg, 0);
38 virtual ~VP9EncoderThreadTest() {
42 virtual void SetUp() {
44 SetMode(encoding_mode_);
46 if (encoding_mode_ != ::libvpx_test::kRealTime) {
47 cfg_.g_lag_in_frames = 3;
48 cfg_.rc_end_usage = VPX_VBR;
49 cfg_.rc_2pass_vbr_minsection_pct = 5;
50 cfg_.rc_2pass_vbr_minsection_pct = 2000;
52 cfg_.g_lag_in_frames = 0;
53 cfg_.rc_end_usage = VPX_CBR;
54 cfg_.g_error_resilient = 1;
56 cfg_.rc_max_quantizer = 56;
57 cfg_.rc_min_quantizer = 0;
60 virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
61 ::libvpx_test::Encoder *encoder) {
62 if (video->frame() == 0) {
63 // Encode 4 column tiles.
64 encoder->Control(VP9E_SET_TILE_COLUMNS, tiles_);
65 encoder->Control(VP8E_SET_CPUUSED, set_cpu_used_);
66 if (encoding_mode_ != ::libvpx_test::kRealTime) {
67 encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1);
68 encoder->Control(VP8E_SET_ARNR_MAXFRAMES, 7);
69 encoder->Control(VP8E_SET_ARNR_STRENGTH, 5);
70 encoder->Control(VP8E_SET_ARNR_TYPE, 3);
72 encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 0);
77 virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) {
78 const vpx_codec_err_t res = decoder_->DecodeFrame(
79 reinterpret_cast<uint8_t*>(pkt->data.frame.buf), pkt->data.frame.sz);
80 if (res != VPX_CODEC_OK) {
82 ASSERT_EQ(VPX_CODEC_OK, res);
84 const vpx_image_t *img = decoder_->GetDxData().Next();
87 ::libvpx_test::MD5 md5_res;
89 md5_.push_back(md5_res.Get());
94 ::libvpx_test::TestMode encoding_mode_;
96 ::libvpx_test::Decoder *decoder_;
97 std::vector<std::string> md5_;
100 TEST_P(VP9EncoderThreadTest, EncoderResultTest) {
101 std::vector<std::string> single_thr_md5, multi_thr_md5;
103 ::libvpx_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 15, 20);
105 cfg_.rc_target_bitrate = 1000;
107 // Encode using single thread.
109 init_flags_ = VPX_CODEC_USE_PSNR;
110 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
111 single_thr_md5 = md5_;
114 // Encode using multiple threads.
116 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
117 multi_thr_md5 = md5_;
120 // Compare to check if two vectors are equal.
121 ASSERT_EQ(single_thr_md5, multi_thr_md5);
124 VP9_INSTANTIATE_TEST_CASE(
125 VP9EncoderThreadTest,
126 ::testing::Values(::libvpx_test::kTwoPassGood, ::libvpx_test::kOnePassGood,
127 ::libvpx_test::kRealTime),
128 ::testing::Range(1, 9));