encoder_parms_get_to_decoder.cc 5.34 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
#include "third_party/googletest/src/include/gtest/gtest.h"

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"
Yaowu Xu's avatar
Yaowu Xu committed
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;
};

Yaowu Xu's avatar
Yaowu Xu committed
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;
Yaowu Xu's avatar
Yaowu Xu committed
42
43
  aom_color_range_t color_range;
  aom_color_space_t cs;
44
  int render_size[2];
45
46
47
  // TODO(JBB): quantizers / bitrate
};

Yaowu Xu's avatar
Yaowu Xu committed
48
49
50
51
const EncodeParameters kAV1EncodeParameterSet[] = {
  { 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 } },
  { 0, 0, 1, 0, 0, AOM_CR_FULL_RANGE, AOM_CS_BT_2020, { 0, 0 } },
52
#if !CONFIG_EC_ADAPT
Yaowu Xu's avatar
Yaowu Xu committed
53
  { 0, 2, 0, 0, 1, AOM_CR_STUDIO_RANGE, AOM_CS_UNKNOWN, { 640, 480 } },
54
#endif
55
  // TODO(JBB): Test profiles (requires more work).
56
57
};

Yaowu Xu's avatar
Yaowu Xu committed
58
class AvxEncoderParmsGetToDecoder
59
60
    : public ::libaom_test::EncoderTest,
      public ::libaom_test::CodecTestWith2Params<EncodeParameters,
61
62
                                                 EncodePerfTestVideo> {
 protected:
Yaowu Xu's avatar
Yaowu Xu committed
63
  AvxEncoderParmsGetToDecoder()
64
      : EncoderTest(GET_PARAM(0)), encode_parms(GET_PARAM(1)) {}
65

Yaowu Xu's avatar
Yaowu Xu committed
66
  virtual ~AvxEncoderParmsGetToDecoder() {}
67
68
69

  virtual void SetUp() {
    InitializeConfig();
70
    SetMode(::libaom_test::kTwoPassGood);
71
72
73
74
75
76
77
    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;
  }

78
79
  virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video,
                                  ::libaom_test::Encoder *encoder) {
80
    if (video->frame() == 1) {
Yaowu Xu's avatar
Yaowu Xu committed
81
82
83
84
      encoder->Control(AV1E_SET_COLOR_SPACE, encode_parms.cs);
      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,
85
                       encode_parms.frame_parallel);
Yaowu Xu's avatar
Yaowu Xu committed
86
87
88
89
90
91
92
      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);
      encoder->Control(AOME_SET_ARNR_TYPE, 3);
93
      if (encode_parms.render_size[0] > 0 && encode_parms.render_size[1] > 0)
Yaowu Xu's avatar
Yaowu Xu committed
94
        encoder->Control(AV1E_SET_RENDER_SIZE, encode_parms.render_size);
95
96
97
    }
  }

Yaowu Xu's avatar
Yaowu Xu committed
98
  virtual bool HandleDecodeResult(const aom_codec_err_t res_dec,
99
                                  libaom_test::Decoder *decoder) {
Yaowu Xu's avatar
Yaowu Xu committed
100
101
102
    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
103
104
    FrameWorkerData *const worker_data =
        reinterpret_cast<FrameWorkerData *>(priv->frame_workers[0].data1);
Yaowu Xu's avatar
Yaowu Xu committed
105
    AV1_COMMON *const common = &worker_data->pbi->common;
106
107

    if (encode_parms.lossless) {
108
109
110
111
112
      EXPECT_EQ(0, common->base_qindex);
      EXPECT_EQ(0, common->y_dc_delta_q);
      EXPECT_EQ(0, common->uv_dc_delta_q);
      EXPECT_EQ(0, common->uv_ac_delta_q);
      EXPECT_EQ(ONLY_4X4, common->tx_mode);
113
    }
114
    EXPECT_EQ(encode_parms.error_resilient, common->error_resilient_mode);
115
    if (encode_parms.error_resilient) {
116
      EXPECT_EQ(0, common->use_prev_frame_mvs);
117
    }
118
    EXPECT_EQ(encode_parms.color_range, common->color_range);
119
    EXPECT_EQ(encode_parms.cs, common->color_space);
120
121
122
123
    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);
    }
124
125
    EXPECT_EQ(encode_parms.tile_cols, common->log2_tile_cols);
    EXPECT_EQ(encode_parms.tile_rows, common->log2_tile_rows);
126

Yaowu Xu's avatar
Yaowu Xu committed
127
128
    EXPECT_EQ(AOM_CODEC_OK, res_dec) << decoder->DecodeError();
    return AOM_CODEC_OK == res_dec;
129
130
131
132
133
134
135
136
  }

  EncodePerfTestVideo test_video_;

 private:
  EncodeParameters encode_parms;
};

Yaowu Xu's avatar
Yaowu Xu committed
137
138
TEST_P(AvxEncoderParmsGetToDecoder, BitstreamParms) {
  init_flags_ = AOM_CODEC_USE_PSNR;
139

140
141
  libaom_test::VideoSource *const video =
      new libaom_test::Y4mVideoSource(test_video_.name, 0, test_video_.frames);
142
  ASSERT_TRUE(video != NULL);
143
144

  ASSERT_NO_FATAL_FAILURE(RunLoop(video));
145
  delete video;
146
147
}

Yaowu Xu's avatar
Yaowu Xu committed
148
149
150
AV1_INSTANTIATE_TEST_CASE(AvxEncoderParmsGetToDecoder,
                          ::testing::ValuesIn(kAV1EncodeParameterSet),
                          ::testing::ValuesIn(kAV1EncodePerfTestVectors));
151
}  // namespace