av1_ext_tile_test.cc 6.41 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.
10
11
12
13
14
 */

#include <assert.h>
#include <string>
#include <vector>
15
#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "test/codec_factory.h"
#include "test/encode_test_driver.h"
#include "test/i420_video_source.h"
#include "test/md5_helper.h"
#include "test/util.h"

namespace {
// The number of frames to be encoded/decoded
const int kLimit = 8;
// Skip 1 frame to check the frame decoding independency.
const int kSkip = 5;
const int kTileSize = 1;
const int kTIleSizeInPixels = (kTileSize << 6);
// Fake width and height so that they can be multiples of the tile size.
const int kImgWidth = 704;
const int kImgHeight = 576;

33
34
// This test tests "tile_encoding_mode = TILE_VR" case. The TILE_NORMAL case is
// tested by the tile_independence test.
Yaowu Xu's avatar
Yaowu Xu committed
35
class AV1ExtTileTest
36
37
    : public ::libaom_test::CodecTestWith2Params<libaom_test::TestMode, int>,
      public ::libaom_test::EncoderTest {
38
 protected:
Yaowu Xu's avatar
Yaowu Xu committed
39
  AV1ExtTileTest()
clang-format's avatar
clang-format committed
40
      : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)),
41
        set_cpu_used_(GET_PARAM(2)) {
Yaowu Xu's avatar
Yaowu Xu committed
42
43
    init_flags_ = AOM_CODEC_USE_PSNR;
    aom_codec_dec_cfg_t cfg = aom_codec_dec_cfg_t();
44
45
46
47
    cfg.w = kImgWidth;
    cfg.h = kImgHeight;

    decoder_ = codec_->CreateDecoder(cfg, 0);
Yaowu Xu's avatar
Yaowu Xu committed
48
49
    decoder_->Control(AV1_SET_DECODE_TILE_ROW, -1);
    decoder_->Control(AV1_SET_DECODE_TILE_COL, -1);
50
51

    // Allocate buffer to store tile image.
Yaowu Xu's avatar
Yaowu Xu committed
52
    aom_img_alloc(&tile_img_, AOM_IMG_FMT_I420, kImgWidth, kImgHeight, 32);
53
54
55
56
57

    md5_.clear();
    tile_md5_.clear();
  }

Yaowu Xu's avatar
Yaowu Xu committed
58
59
  virtual ~AV1ExtTileTest() {
    aom_img_free(&tile_img_);
60
61
62
63
64
65
66
67
    delete decoder_;
  }

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

    cfg_.g_lag_in_frames = 0;
Yaowu Xu's avatar
Yaowu Xu committed
68
    cfg_.rc_end_usage = AOM_VBR;
69
70
71
72
73
74
    cfg_.g_error_resilient = 1;

    cfg_.rc_max_quantizer = 56;
    cfg_.rc_min_quantizer = 0;
  }

75
76
  virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video,
                                  ::libaom_test::Encoder *encoder) {
77
78
    if (video->frame() == 0) {
      // Encode setting
Yaowu Xu's avatar
Yaowu Xu committed
79
80
81
      encoder->Control(AOME_SET_CPUUSED, set_cpu_used_);
      encoder->Control(AOME_SET_ENABLEAUTOALTREF, 0);
      encoder->Control(AV1E_SET_FRAME_PARALLEL_DECODING, 1);
82
83

      // The tile size is 64x64.
Yaowu Xu's avatar
Yaowu Xu committed
84
85
      encoder->Control(AV1E_SET_TILE_COLUMNS, kTileSize);
      encoder->Control(AV1E_SET_TILE_ROWS, kTileSize);
86
      encoder->Control(AV1E_SET_TILE_ENCODING_MODE, 1);  // TILE_VR
87
88
#if CONFIG_EXT_PARTITION
      // Always use 64x64 max partition.
Yaowu Xu's avatar
Yaowu Xu committed
89
      encoder->Control(AV1E_SET_SUPERBLOCK_SIZE, AOM_SUPERBLOCK_SIZE_64X64);
90
91
92
93
#endif
    }

    if (video->frame() == 1) {
clang-format's avatar
clang-format committed
94
      frame_flags_ =
Yaowu Xu's avatar
Yaowu Xu committed
95
          AOM_EFLAG_NO_UPD_LAST | AOM_EFLAG_NO_UPD_GF | AOM_EFLAG_NO_UPD_ARF;
96
97
98
    }
  }

Yaowu Xu's avatar
Yaowu Xu committed
99
100
  virtual void DecompressedFrameHook(const aom_image_t &img,
                                     aom_codec_pts_t pts) {
101
102
    // Skip 1 already decoded frame to be consistent with the decoder in this
    // test.
Yaowu Xu's avatar
Yaowu Xu committed
103
    if (pts == (aom_codec_pts_t)kSkip) return;
104
105

    // Calculate MD5 as the reference.
106
    ::libaom_test::MD5 md5_res;
107
108
109
110
    md5_res.Add(&img);
    md5_.push_back(md5_res.Get());
  }

Yaowu Xu's avatar
Yaowu Xu committed
111
  virtual void FramePktHook(const aom_codec_cx_pkt_t *pkt) {
112
    // Skip decoding 1 frame.
Yaowu Xu's avatar
Yaowu Xu committed
113
    if (pkt->data.frame.pts == (aom_codec_pts_t)kSkip) return;
114

Yaowu Xu's avatar
Yaowu Xu committed
115
    bool IsLastFrame = (pkt->data.frame.pts == (aom_codec_pts_t)(kLimit - 1));
116
117
118
119
120
121

    // Decode the first (kLimit - 1) frames as whole frame, and decode the last
    // frame in single tiles.
    for (int r = 0; r < kImgHeight / kTIleSizeInPixels; ++r) {
      for (int c = 0; c < kImgWidth / kTIleSizeInPixels; ++c) {
        if (!IsLastFrame) {
Yaowu Xu's avatar
Yaowu Xu committed
122
123
          decoder_->Control(AV1_SET_DECODE_TILE_ROW, -1);
          decoder_->Control(AV1_SET_DECODE_TILE_COL, -1);
124
        } else {
Yaowu Xu's avatar
Yaowu Xu committed
125
126
          decoder_->Control(AV1_SET_DECODE_TILE_ROW, r);
          decoder_->Control(AV1_SET_DECODE_TILE_COL, c);
127
128
        }

Yaowu Xu's avatar
Yaowu Xu committed
129
        const aom_codec_err_t res = decoder_->DecodeFrame(
clang-format's avatar
clang-format committed
130
            reinterpret_cast<uint8_t *>(pkt->data.frame.buf),
131
            pkt->data.frame.sz);
Yaowu Xu's avatar
Yaowu Xu committed
132
        if (res != AOM_CODEC_OK) {
133
          abort_ = true;
Yaowu Xu's avatar
Yaowu Xu committed
134
          ASSERT_EQ(AOM_CODEC_OK, res);
135
        }
Yaowu Xu's avatar
Yaowu Xu committed
136
        const aom_image_t *img = decoder_->GetDxData().Next();
137
138
139

        if (!IsLastFrame) {
          if (img) {
140
            ::libaom_test::MD5 md5_res;
141
142
143
144
145
146
147
148
149
150
151
152
153
154
            md5_res.Add(img);
            tile_md5_.push_back(md5_res.Get());
          }
          break;
        }

        const int kMaxMBPlane = 3;
        for (int plane = 0; plane < kMaxMBPlane; ++plane) {
          const int shift = (plane == 0) ? 0 : 1;
          int tile_height = kTIleSizeInPixels >> shift;
          int tile_width = kTIleSizeInPixels >> shift;

          for (int tr = 0; tr < tile_height; ++tr) {
            memcpy(tile_img_.planes[plane] +
clang-format's avatar
clang-format committed
155
156
                       tile_img_.stride[plane] * (r * tile_height + tr) +
                       c * tile_width,
157
158
159
160
161
                   img->planes[plane] + img->stride[plane] * tr, tile_width);
          }
        }
      }

clang-format's avatar
clang-format committed
162
      if (!IsLastFrame) break;
163
164
    }

165
    if (IsLastFrame) {
166
      ::libaom_test::MD5 md5_res;
167
168
169
170
171
      md5_res.Add(&tile_img_);
      tile_md5_.push_back(md5_res.Get());
    }
  }

172
  ::libaom_test::TestMode encoding_mode_;
173
  int set_cpu_used_;
174
  ::libaom_test::Decoder *decoder_;
Yaowu Xu's avatar
Yaowu Xu committed
175
  aom_image_t tile_img_;
176
177
178
179
  std::vector<std::string> md5_;
  std::vector<std::string> tile_md5_;
};

Yaowu Xu's avatar
Yaowu Xu committed
180
TEST_P(AV1ExtTileTest, DecoderResultTest) {
181
  ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", kImgWidth,
clang-format's avatar
clang-format committed
182
                                       kImgHeight, 30, 1, 0, kLimit);
183
  cfg_.rc_target_bitrate = 500;
Yaowu Xu's avatar
Yaowu Xu committed
184
  cfg_.g_error_resilient = AOM_ERROR_RESILIENT_DEFAULT;
185
186
187
188
  cfg_.g_lag_in_frames = 0;
  cfg_.g_threads = 1;

  // Tile encoding
Yaowu Xu's avatar
Yaowu Xu committed
189
  init_flags_ = AOM_CODEC_USE_PSNR;
190
191
192
193
194
195
  ASSERT_NO_FATAL_FAILURE(RunLoop(&video));

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

Yaowu Xu's avatar
Yaowu Xu committed
196
AV1_INSTANTIATE_TEST_CASE(
197
    // Now only test 2-pass mode.
Yaowu Xu's avatar
Yaowu Xu committed
198
    AV1ExtTileTest, ::testing::Values(::libaom_test::kTwoPassGood),
199
200
    ::testing::Range(0, 4));
}  // namespace