ethread_test.cc 3.96 KB
Newer Older
1
/*
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3
 *
4 5 6 7 8 9 10 11
 * 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.
*/

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 {
Adrian Grange's avatar
Adrian Grange committed
22
class AVxEncoderThreadTest
Yaowu Xu's avatar
Yaowu Xu committed
23 24
    : public ::libaom_test::EncoderTest,
      public ::libaom_test::CodecTestWith2Params<libaom_test::TestMode, int> {
25
 protected:
Adrian Grange's avatar
Adrian Grange committed
26
  AVxEncoderThreadTest()
clang-format's avatar
clang-format committed
27 28
      : EncoderTest(GET_PARAM(0)), encoder_initialized_(false), tiles_(2),
        encoding_mode_(GET_PARAM(1)), set_cpu_used_(GET_PARAM(2)) {
Adrian Grange's avatar
Adrian Grange committed
29
    init_flags_ = AOM_CODEC_USE_PSNR;
30 31 32

    md5_.clear();
  }
33
  virtual ~AVxEncoderThreadTest() {}
34 35 36 37 38

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

Yaowu Xu's avatar
Yaowu Xu committed
39
    if (encoding_mode_ != ::libaom_test::kRealTime) {
40
      cfg_.g_lag_in_frames = 3;
Adrian Grange's avatar
Adrian Grange committed
41
      cfg_.rc_end_usage = AOM_VBR;
42 43 44 45
      cfg_.rc_2pass_vbr_minsection_pct = 5;
      cfg_.rc_2pass_vbr_minsection_pct = 2000;
    } else {
      cfg_.g_lag_in_frames = 0;
Adrian Grange's avatar
Adrian Grange committed
46
      cfg_.rc_end_usage = AOM_CBR;
47 48 49 50 51 52
      cfg_.g_error_resilient = 1;
    }
    cfg_.rc_max_quantizer = 56;
    cfg_.rc_min_quantizer = 0;
  }

53 54 55 56
  virtual void BeginPassHook(unsigned int /*pass*/) {
    encoder_initialized_ = false;
  }

57
  virtual void PreEncodeFrameHook(::libaom_test::VideoSource * /*video*/,
Yaowu Xu's avatar
Yaowu Xu committed
58
                                  ::libaom_test::Encoder *encoder) {
59
    if (!encoder_initialized_) {
60
      // Encode 4 column tiles.
Adrian Grange's avatar
Adrian Grange committed
61
      encoder->Control(AV1E_SET_TILE_COLUMNS, tiles_);
Adrian Grange's avatar
Adrian Grange committed
62
      encoder->Control(AOME_SET_CPUUSED, set_cpu_used_);
Yaowu Xu's avatar
Yaowu Xu committed
63
      if (encoding_mode_ != ::libaom_test::kRealTime) {
Adrian Grange's avatar
Adrian Grange committed
64 65 66 67
        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);
68
      } else {
Adrian Grange's avatar
Adrian Grange committed
69
        encoder->Control(AOME_SET_ENABLEAUTOALTREF, 0);
Adrian Grange's avatar
Adrian Grange committed
70
        encoder->Control(AV1E_SET_AQ_MODE, 3);
71
      }
72
      encoder_initialized_ = true;
73 74 75
    }
  }

76 77 78 79 80 81
  virtual void DecompressedFrameHook(const aom_image_t &img,
                                     aom_codec_pts_t /*pts*/) {
    ::libaom_test::MD5 md5_res;
    md5_res.Add(&img);
    md5_.push_back(md5_res.Get());
  }
82

83 84 85 86 87
  virtual bool HandleDecodeResult(const aom_codec_err_t res,
                                  libaom_test::Decoder * /*decoder*/) {
    if (res != AOM_CODEC_OK) {
      EXPECT_EQ(AOM_CODEC_OK, res);
      return false;
88
    }
89
    return true;
90 91
  }

92
  bool encoder_initialized_;
93
  int tiles_;
Yaowu Xu's avatar
Yaowu Xu committed
94
  ::libaom_test::TestMode encoding_mode_;
95 96 97 98
  int set_cpu_used_;
  std::vector<std::string> md5_;
};

Adrian Grange's avatar
Adrian Grange committed
99
TEST_P(AVxEncoderThreadTest, EncoderResultTest) {
100 101
  std::vector<std::string> single_thr_md5, multi_thr_md5;

Yaowu Xu's avatar
Yaowu Xu committed
102
  ::libaom_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 15, 20);
103 104 105 106 107

  cfg_.rc_target_bitrate = 1000;

  // Encode using single thread.
  cfg_.g_threads = 1;
Adrian Grange's avatar
Adrian Grange committed
108
  init_flags_ = AOM_CODEC_USE_PSNR;
109 110 111 112 113 114 115 116 117 118 119 120 121 122
  ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  single_thr_md5 = md5_;
  md5_.clear();

  // Encode using multiple threads.
  cfg_.g_threads = 4;
  ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  multi_thr_md5 = md5_;
  md5_.clear();

  // Compare to check if two vectors are equal.
  ASSERT_EQ(single_thr_md5, multi_thr_md5);
}

Adrian Grange's avatar
Adrian Grange committed
123
AV1_INSTANTIATE_TEST_CASE(AVxEncoderThreadTest,
clang-format's avatar
clang-format committed
124 125 126
                          ::testing::Values(::libaom_test::kTwoPassGood,
                                            ::libaom_test::kOnePassGood),
                          ::testing::Range(1, 3));
127
}  // namespace