ethread_test.cc 6.24 KB
Newer Older
1
/*
Yaowu Xu's avatar
Yaowu Xu committed
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3
 *
Yaowu Xu's avatar
Yaowu Xu committed
4
5
6
7
8
9
10
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/
11
12
13
14
15
16
17

#include <string>
#include <vector>
#include "third_party/googletest/src/include/gtest/gtest.h"
#include "test/codec_factory.h"
#include "test/encode_test_driver.h"
#include "test/md5_helper.h"
18
19
#include "test/util.h"
#include "test/y4m_video_source.h"
20
21

namespace {
Yaowu Xu's avatar
Yaowu Xu committed
22
class AVxEncoderThreadTest
23
24
    : public ::libaom_test::EncoderTest,
      public ::libaom_test::CodecTestWith2Params<libaom_test::TestMode, int> {
25
 protected:
Yaowu Xu's avatar
Yaowu Xu committed
26
  AVxEncoderThreadTest()
clang-format's avatar
clang-format committed
27
28
      : EncoderTest(GET_PARAM(0)), encoder_initialized_(false),
        encoding_mode_(GET_PARAM(1)), set_cpu_used_(GET_PARAM(2)) {
Yaowu Xu's avatar
Yaowu Xu committed
29
30
    init_flags_ = AOM_CODEC_USE_PSNR;
    aom_codec_dec_cfg_t cfg = aom_codec_dec_cfg_t();
31
32
33
    cfg.w = 1280;
    cfg.h = 720;
    decoder_ = codec_->CreateDecoder(cfg, 0);
Yaowu Xu's avatar
Yaowu Xu committed
34
35
36
37
#if CONFIG_AV1 && CONFIG_EXT_TILE
    if (decoder_->IsAV1()) {
      decoder_->Control(AV1_SET_DECODE_TILE_ROW, -1);
      decoder_->Control(AV1_SET_DECODE_TILE_COL, -1);
38
39
    }
#endif
40

41
42
43
    size_enc_.clear();
    md5_dec_.clear();
    md5_enc_.clear();
44
  }
Yaowu Xu's avatar
Yaowu Xu committed
45
  virtual ~AVxEncoderThreadTest() { delete decoder_; }
46
47
48
49
50

  virtual void SetUp() {
    InitializeConfig();
    SetMode(encoding_mode_);

51
    if (encoding_mode_ != ::libaom_test::kRealTime) {
52
      cfg_.g_lag_in_frames = 3;
Yaowu Xu's avatar
Yaowu Xu committed
53
      cfg_.rc_end_usage = AOM_VBR;
54
      cfg_.rc_2pass_vbr_minsection_pct = 5;
hui su's avatar
hui su committed
55
      cfg_.rc_2pass_vbr_maxsection_pct = 2000;
56
57
    } else {
      cfg_.g_lag_in_frames = 0;
Yaowu Xu's avatar
Yaowu Xu committed
58
      cfg_.rc_end_usage = AOM_CBR;
59
60
61
62
63
64
      cfg_.g_error_resilient = 1;
    }
    cfg_.rc_max_quantizer = 56;
    cfg_.rc_min_quantizer = 0;
  }

65
66
67
68
  virtual void BeginPassHook(unsigned int /*pass*/) {
    encoder_initialized_ = false;
  }

69
70
  virtual void PreEncodeFrameHook(::libaom_test::VideoSource * /*video*/,
                                  ::libaom_test::Encoder *encoder) {
71
    if (!encoder_initialized_) {
Yaowu Xu's avatar
Yaowu Xu committed
72
73
74
#if CONFIG_AV1 && CONFIG_EXT_TILE
      encoder->Control(AV1E_SET_TILE_COLUMNS, 1);
      if (codec_ == &libaom_test::kAV1) {
Geza Lore's avatar
Geza Lore committed
75
76
        // TODO(geza): Start using multiple tile rows when the multi-threaded
        // encoder can handle them
Yaowu Xu's avatar
Yaowu Xu committed
77
        encoder->Control(AV1E_SET_TILE_ROWS, 32);
Geza Lore's avatar
Geza Lore committed
78
      } else {
Yaowu Xu's avatar
Yaowu Xu committed
79
        encoder->Control(AV1E_SET_TILE_ROWS, 0);
Geza Lore's avatar
Geza Lore committed
80
      }
81
82
#else
      // Encode 4 tile columns.
Yaowu Xu's avatar
Yaowu Xu committed
83
84
85
86
      encoder->Control(AV1E_SET_TILE_COLUMNS, 2);
      encoder->Control(AV1E_SET_TILE_ROWS, 0);
#endif  // CONFIG_AV1 && CONFIG_EXT_TILE
      encoder->Control(AOME_SET_CPUUSED, set_cpu_used_);
87
      if (encoding_mode_ != ::libaom_test::kRealTime) {
Yaowu Xu's avatar
Yaowu Xu committed
88
89
90
91
        encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1);
        encoder->Control(AOME_SET_ARNR_MAXFRAMES, 7);
        encoder->Control(AOME_SET_ARNR_STRENGTH, 5);
        encoder->Control(AOME_SET_ARNR_TYPE, 3);
92
        encoder->Control(AV1E_SET_FRAME_PARALLEL_DECODING, 0);
93
      } else {
Yaowu Xu's avatar
Yaowu Xu committed
94
95
        encoder->Control(AOME_SET_ENABLEAUTOALTREF, 0);
        encoder->Control(AV1E_SET_AQ_MODE, 3);
96
      }
97
      encoder_initialized_ = true;
98
99
100
    }
  }

Yaowu Xu's avatar
Yaowu Xu committed
101
  virtual void FramePktHook(const aom_codec_cx_pkt_t *pkt) {
102
103
    size_enc_.push_back(pkt->data.frame.sz);

104
    ::libaom_test::MD5 md5_enc;
clang-format's avatar
clang-format committed
105
    md5_enc.Add(reinterpret_cast<uint8_t *>(pkt->data.frame.buf),
106
107
108
                pkt->data.frame.sz);
    md5_enc_.push_back(md5_enc.Get());

Yaowu Xu's avatar
Yaowu Xu committed
109
    const aom_codec_err_t res = decoder_->DecodeFrame(
clang-format's avatar
clang-format committed
110
        reinterpret_cast<uint8_t *>(pkt->data.frame.buf), pkt->data.frame.sz);
Yaowu Xu's avatar
Yaowu Xu committed
111
    if (res != AOM_CODEC_OK) {
112
      abort_ = true;
Yaowu Xu's avatar
Yaowu Xu committed
113
      ASSERT_EQ(AOM_CODEC_OK, res);
114
    }
Yaowu Xu's avatar
Yaowu Xu committed
115
    const aom_image_t *img = decoder_->GetDxData().Next();
116
117

    if (img) {
118
      ::libaom_test::MD5 md5_res;
119
      md5_res.Add(img);
120
      md5_dec_.push_back(md5_res.Get());
121
122
123
    }
  }

124
  void DoTest() {
125
    ::libaom_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 15, 18);
126
127
128
129
    cfg_.rc_target_bitrate = 1000;

    // Encode using single thread.
    cfg_.g_threads = 1;
Yaowu Xu's avatar
Yaowu Xu committed
130
    init_flags_ = AOM_CODEC_USE_PSNR;
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
    ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
    std::vector<size_t> single_thr_size_enc;
    std::vector<std::string> single_thr_md5_enc;
    std::vector<std::string> single_thr_md5_dec;
    single_thr_size_enc = size_enc_;
    single_thr_md5_enc = md5_enc_;
    single_thr_md5_dec = md5_dec_;
    size_enc_.clear();
    md5_enc_.clear();
    md5_dec_.clear();

    // Encode using multiple threads.
    cfg_.g_threads = 4;
    ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
    std::vector<size_t> multi_thr_size_enc;
    std::vector<std::string> multi_thr_md5_enc;
    std::vector<std::string> multi_thr_md5_dec;
    multi_thr_size_enc = size_enc_;
    multi_thr_md5_enc = md5_enc_;
    multi_thr_md5_dec = md5_dec_;
    size_enc_.clear();
    md5_enc_.clear();
    md5_dec_.clear();

    // Check that the vectors are equal.
    ASSERT_EQ(single_thr_size_enc, multi_thr_size_enc);
    ASSERT_EQ(single_thr_md5_enc, multi_thr_md5_enc);
    ASSERT_EQ(single_thr_md5_dec, multi_thr_md5_dec);
  }

161
  bool encoder_initialized_;
162
  ::libaom_test::TestMode encoding_mode_;
163
  int set_cpu_used_;
164
  ::libaom_test::Decoder *decoder_;
165
166
167
  std::vector<size_t> size_enc_;
  std::vector<std::string> md5_enc_;
  std::vector<std::string> md5_dec_;
168
169
};

Yaowu Xu's avatar
Yaowu Xu committed
170
TEST_P(AVxEncoderThreadTest, EncoderResultTest) { DoTest(); }
171

Yaowu Xu's avatar
Yaowu Xu committed
172
class AVxEncoderThreadTestLarge : public AVxEncoderThreadTest {};
173

Yaowu Xu's avatar
Yaowu Xu committed
174
TEST_P(AVxEncoderThreadTestLarge, EncoderResultTest) { DoTest(); }
175

176
177
178
179
#if CONFIG_EC_ADAPT
// TODO(thdavies): EC_ADAPT does not support tiles

#else
Yaowu Xu's avatar
Yaowu Xu committed
180
181
182
183
AV1_INSTANTIATE_TEST_CASE(AVxEncoderThreadTest,
                          ::testing::Values(::libaom_test::kTwoPassGood,
                                            ::libaom_test::kOnePassGood),
                          ::testing::Range(3, 9));
184

Yaowu Xu's avatar
Yaowu Xu committed
185
186
187
AV1_INSTANTIATE_TEST_CASE(AVxEncoderThreadTestLarge,
                          ::testing::Values(::libaom_test::kTwoPassGood,
                                            ::libaom_test::kOnePassGood),
188
                          ::testing::Range(0, 3));
189
#endif
190
}  // namespace