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

12
#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
13

14 15
#include "test/codec_factory.h"
#include "test/encode_test_driver.h"
16
#include "test/util.h"
17
#include "test/y4m_video_source.h"
18
#include "av1/av1_dx_iface.c"
19 20 21 22 23 24 25 26 27 28 29 30 31

namespace {

const int kCpuUsed = 2;

struct EncodePerfTestVideo {
  const char *name;
  uint32_t width;
  uint32_t height;
  uint32_t bitrate;
  int frames;
};

32
const EncodePerfTestVideo kAV1EncodePerfTestVectors[] = {
clang-format's avatar
clang-format committed
33
  { "niklas_1280_720_30.y4m", 1280, 720, 600, 10 },
34 35 36 37 38 39 40 41
};

struct EncodeParameters {
  int32_t tile_rows;
  int32_t tile_cols;
  int32_t lossless;
  int32_t error_resilient;
  int32_t frame_parallel;
42
  aom_color_range_t color_range;
Andrey Norkin's avatar
Andrey Norkin committed
43 44 45 46 47
#if CONFIG_CICP
  aom_color_primaries_t cp;
  aom_transfer_characteristics_t tc;
  aom_matrix_coefficients_t mc;
#else
48
  aom_color_space_t cs;
Andrey Norkin's avatar
Andrey Norkin committed
49
#endif
50
#if CONFIG_COLORSPACE_HEADERS
Andrey Norkin's avatar
Andrey Norkin committed
51
#if !CONFIG_CICP
52
  aom_transfer_function_t tf;
Andrey Norkin's avatar
Andrey Norkin committed
53
#endif
54 55
  aom_chroma_sample_position_t csp;
#endif
56
  int render_size[2];
57 58 59
  // TODO(JBB): quantizers / bitrate
};

60
const EncodeParameters kAV1EncodeParameterSet[] = {
Andrey Norkin's avatar
Andrey Norkin committed
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
#if CONFIG_CICP && CONFIG_COLORSPACE_HEADERS
  { 0,
    0,
    1,
    0,
    0,
    AOM_CR_FULL_RANGE,
    AOM_CICP_CP_BT_2020,
    AOM_CICP_TC_BT_2020_10_BIT,
    AOM_CICP_MC_BT_2020_NCL,
    AOM_CSP_COLOCATED,
    { 0, 0 } },
  { 0,
    0,
    0,
    1,
    0,
    AOM_CR_STUDIO_RANGE,
    AOM_CICP_CP_BT_601,
    AOM_CICP_TC_BT_601,
    AOM_CICP_MC_BT_601,
    AOM_CSP_VERTICAL,
    { 0, 0 } },
  { 0,
    0,
    0,
    0,
    0,
    AOM_CR_STUDIO_RANGE,
    AOM_CICP_CP_BT_2020,
    AOM_CICP_TC_SMPTE_2084,
    AOM_CICP_MC_BT_2020_NCL,
    AOM_CSP_COLOCATED,
    { 0, 0 } },
  { 0,
    0,
    0,
    1,
    0,
    AOM_CR_STUDIO_RANGE,
    AOM_CICP_CP_BT_709,
    AOM_CICP_TC_BT_709,
    AOM_CICP_MC_BT_709,
    AOM_CSP_VERTICAL,
    { 0, 0 } },
#else
107
#if CONFIG_COLORSPACE_HEADERS
Andrey Norkin's avatar
Andrey Norkin committed
108 109 110 111 112 113 114 115 116 117
  { 0,
    0,
    1,
    0,
    0,
    AOM_CR_FULL_RANGE,
    AOM_CS_BT_2020_NCL,
    AOM_TF_BT_709,
    AOM_CSP_COLOCATED,
    { 0, 0 } },
118
#else
Andrey Norkin's avatar
Andrey Norkin committed
119 120 121
  { 0, 0, 1, 0, 0, AOM_CR_FULL_RANGE, AOM_CS_BT_2020{ 0, 0 } },
  { 0, 0, 0, 1, 0, AOM_CR_STUDIO_RANGE, AOM_CS_BT_601, { 0, 0 } },
  { 0, 0, 0, 0, 0, AOM_CR_FULL_RANGE, AOM_CS_BT_709, { 0, 0 } },
122
  { 0, 2, 0, 0, 1, AOM_CR_STUDIO_RANGE, AOM_CS_UNKNOWN, { 640, 480 } },
Andrey Norkin's avatar
Andrey Norkin committed
123 124
#endif
#endif
125
  // TODO(JBB): Test profiles (requires more work).
126 127
};

128
class AvxEncoderParmsGetToDecoder
129 130 131 132
    : public ::libaom_test::CodecTestWith2Params<EncodeParameters,
                                                 EncodePerfTestVideo>,
      public ::libaom_test::EncoderTest,
{
133
 protected:
134
  AvxEncoderParmsGetToDecoder()
135
      : EncoderTest(GET_PARAM(0)), encode_parms(GET_PARAM(1)) {}
136

137
  virtual ~AvxEncoderParmsGetToDecoder() {}
138 139 140

  virtual void SetUp() {
    InitializeConfig();
141
    SetMode(::libaom_test::kTwoPassGood);
142 143 144 145 146 147 148
    cfg_.g_lag_in_frames = 25;
    cfg_.g_error_resilient = encode_parms.error_resilient;
    dec_cfg_.threads = 4;
    test_video_ = GET_PARAM(2);
    cfg_.rc_target_bitrate = test_video_.bitrate;
  }

149 150
  virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video,
                                  ::libaom_test::Encoder *encoder) {
151
    if (video->frame() == 1) {
Andrey Norkin's avatar
Andrey Norkin committed
152 153 154 155 156
#if CONFIG_CICP
      encoder->Control(AV1E_SET_COLOR_PRIMARIES, encode_parms.cp);
      encoder->Control(AV1E_SET_TRANSFER_CHARACTERISTICS, encode_parms.tc);
      encoder->Control(AV1E_SET_MATRIX_COEFFICIENTS, encode_parms.mc);
#else
157
      encoder->Control(AV1E_SET_COLOR_SPACE, encode_parms.cs);
Andrey Norkin's avatar
Andrey Norkin committed
158
#endif
159
#if CONFIG_COLORSPACE_HEADERS
Andrey Norkin's avatar
Andrey Norkin committed
160
#if !CONFIG_CICP
161
      encoder->Control(AV1E_SET_TRANSFER_FUNCTION, encode_parms.tf);
Andrey Norkin's avatar
Andrey Norkin committed
162
#endif
163 164
      encoder->Control(AV1E_SET_CHROMA_SAMPLE_POSITION, encode_parms.csp);
#endif
165 166 167
      encoder->Control(AV1E_SET_COLOR_RANGE, encode_parms.color_range);
      encoder->Control(AV1E_SET_LOSSLESS, encode_parms.lossless);
      encoder->Control(AV1E_SET_FRAME_PARALLEL_DECODING,
168
                       encode_parms.frame_parallel);
169 170 171 172 173 174
      encoder->Control(AV1E_SET_TILE_ROWS, encode_parms.tile_rows);
      encoder->Control(AV1E_SET_TILE_COLUMNS, encode_parms.tile_cols);
      encoder->Control(AOME_SET_CPUUSED, kCpuUsed);
      encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1);
      encoder->Control(AOME_SET_ARNR_MAXFRAMES, 7);
      encoder->Control(AOME_SET_ARNR_STRENGTH, 5);
175
      if (encode_parms.render_size[0] > 0 && encode_parms.render_size[1] > 0)
176
        encoder->Control(AV1E_SET_RENDER_SIZE, encode_parms.render_size);
177 178 179
    }
  }

180
  virtual bool HandleDecodeResult(const aom_codec_err_t res_dec,
181
                                  libaom_test::Decoder *decoder) {
182 183 184
    aom_codec_ctx_t *const av1_decoder = decoder->GetDecoder();
    aom_codec_alg_priv_t *const priv =
        reinterpret_cast<aom_codec_alg_priv_t *>(av1_decoder->priv);
James Zern's avatar
James Zern committed
185 186
    FrameWorkerData *const worker_data =
        reinterpret_cast<FrameWorkerData *>(priv->frame_workers[0].data1);
187
    AV1_COMMON *const common = &worker_data->pbi->common;
188 189

    if (encode_parms.lossless) {
190 191
      EXPECT_EQ(0, common->base_qindex);
      EXPECT_EQ(0, common->y_dc_delta_q);
192 193 194 195
      EXPECT_EQ(0, common->u_dc_delta_q);
      EXPECT_EQ(0, common->u_ac_delta_q);
      EXPECT_EQ(0, common->v_dc_delta_q);
      EXPECT_EQ(0, common->v_ac_delta_q);
196
      EXPECT_EQ(ONLY_4X4, common->tx_mode);
197
    }
198
    EXPECT_EQ(encode_parms.error_resilient, common->error_resilient_mode);
199
    if (encode_parms.error_resilient) {
200
      EXPECT_EQ(0, common->use_prev_frame_mvs);
201
    }
202
    EXPECT_EQ(encode_parms.color_range, common->color_range);
Andrey Norkin's avatar
Andrey Norkin committed
203 204 205 206 207
#if CONFIG_CICP
    EXPECT_EQ(encode_parms.cp, common->color_primaries);
    EXPECT_EQ(encode_parms.tc, common->transfer_characteristics);
    EXPECT_EQ(encode_parms.mc, common->matrix_coefficients);
#else
208
    EXPECT_EQ(encode_parms.cs, common->color_space);
Andrey Norkin's avatar
Andrey Norkin committed
209
#endif
210
#if CONFIG_COLORSPACE_HEADERS
Andrey Norkin's avatar
Andrey Norkin committed
211
#if !CONFIG_CICP
212
    EXPECT_EQ(encode_parms.tf, common->transfer_function);
Andrey Norkin's avatar
Andrey Norkin committed
213
#endif
214 215
    EXPECT_EQ(encode_parms.csp, common->chroma_sample_position);
#endif
216 217 218 219
    if (encode_parms.render_size[0] > 0 && encode_parms.render_size[1] > 0) {
      EXPECT_EQ(encode_parms.render_size[0], common->render_width);
      EXPECT_EQ(encode_parms.render_size[1], common->render_height);
    }
220 221
    EXPECT_EQ(encode_parms.tile_cols, common->log2_tile_cols);
    EXPECT_EQ(encode_parms.tile_rows, common->log2_tile_rows);
222

223 224
    EXPECT_EQ(AOM_CODEC_OK, res_dec) << decoder->DecodeError();
    return AOM_CODEC_OK == res_dec;
225 226 227 228 229 230 231 232
  }

  EncodePerfTestVideo test_video_;

 private:
  EncodeParameters encode_parms;
};

233 234
TEST_P(AvxEncoderParmsGetToDecoder, BitstreamParms) {
  init_flags_ = AOM_CODEC_USE_PSNR;
235

236 237 238
  testing::internal::scoped_ptr<libaom_test::VideoSource> video(
      new libaom_test::Y4mVideoSource(test_video_.name, 0, test_video_.frames));
  ASSERT_TRUE(video.get() != NULL);
239

240
  ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
241 242
}

243 244 245
AV1_INSTANTIATE_TEST_CASE(AvxEncoderParmsGetToDecoder,
                          ::testing::ValuesIn(kAV1EncodeParameterSet),
                          ::testing::ValuesIn(kAV1EncodePerfTestVectors));
246
}  // namespace