tile_independence_test.cc 5.92 KB
Newer Older
1
/*
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Frank Galligan's avatar
Frank Galligan committed
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 13 14

#include <cstdio>
#include <cstdlib>
#include <string>
15
#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
16 17 18 19 20
#include "test/codec_factory.h"
#include "test/encode_test_driver.h"
#include "test/i420_video_source.h"
#include "test/util.h"
#include "test/md5_helper.h"
21
#include "aom_mem/aom_mem.h"
22 23

namespace {
clang-format's avatar
clang-format committed
24
class TileIndependenceTest
25 26
    : public ::libaom_test::CodecTestWith2Params<int, int>,
      public ::libaom_test::EncoderTest {
27
 protected:
28
  TileIndependenceTest()
clang-format's avatar
clang-format committed
29 30
      : EncoderTest(GET_PARAM(0)), md5_fw_order_(), md5_inv_order_(),
        n_tile_cols_(GET_PARAM(1)), n_tile_rows_(GET_PARAM(2)) {
31 32
    init_flags_ = AOM_CODEC_USE_PSNR;
    aom_codec_dec_cfg_t cfg = aom_codec_dec_cfg_t();
33 34
    cfg.w = 704;
    cfg.h = 144;
35
    cfg.threads = 1;
36
    cfg.allow_lowbitdepth = 1;
37 38
    fw_dec_ = codec_->CreateDecoder(cfg, 0);
    inv_dec_ = codec_->CreateDecoder(cfg, 0);
39 40
    inv_dec_->Control(AV1_INVERT_TILE_DECODE_ORDER, 1);

41
#if CONFIG_AV1
42 43 44 45 46
    if (fw_dec_->IsAV1() && inv_dec_->IsAV1()) {
      fw_dec_->Control(AV1_SET_DECODE_TILE_ROW, -1);
      fw_dec_->Control(AV1_SET_DECODE_TILE_COL, -1);
      inv_dec_->Control(AV1_SET_DECODE_TILE_ROW, -1);
      inv_dec_->Control(AV1_SET_DECODE_TILE_COL, -1);
47 48
    }
#endif
49 50 51 52 53 54 55 56 57
  }

  virtual ~TileIndependenceTest() {
    delete fw_dec_;
    delete inv_dec_;
  }

  virtual void SetUp() {
    InitializeConfig();
58
    SetMode(libaom_test::kTwoPassGood);
59 60
  }

61 62
  virtual void PreEncodeFrameHook(libaom_test::VideoSource *video,
                                  libaom_test::Encoder *encoder) {
63
    if (video->frame() == 1) {
64 65
      encoder->Control(AV1E_SET_TILE_COLUMNS, n_tile_cols_);
      encoder->Control(AV1E_SET_TILE_ROWS, n_tile_rows_);
66
#if CONFIG_LOOPFILTERING_ACROSS_TILES
67 68 69 70
#if CONFIG_LOOPFILTERING_ACROSS_TILES_EXT
      encoder->Control(AV1E_SET_TILE_LOOPFILTER_V, 0);
      encoder->Control(AV1E_SET_TILE_LOOPFILTER_H, 0);
#else
71
      encoder->Control(AV1E_SET_TILE_LOOPFILTER, 0);
72
#endif  // CONFIG_LOOPFILTERING_ACROSS_TILES_EXT
73
#endif  // CONFIG_LOOPFILTERING_ACROSS_TILES
74
      SetCpuUsed(encoder);
75 76 77
    }
  }

78
  virtual void SetCpuUsed(libaom_test::Encoder *encoder) {
79
    static const int kCpuUsed = 3;
80
    encoder->Control(AOME_SET_CPUUSED, kCpuUsed);
81 82
  }

83
  void UpdateMD5(::libaom_test::Decoder *dec, const aom_codec_cx_pkt_t *pkt,
84
                 ::libaom_test::MD5 *md5) {
85
    const aom_codec_err_t res = dec->DecodeFrame(
clang-format's avatar
clang-format committed
86
        reinterpret_cast<uint8_t *>(pkt->data.frame.buf), pkt->data.frame.sz);
87
    if (res != AOM_CODEC_OK) {
88
      abort_ = true;
89
      ASSERT_EQ(AOM_CODEC_OK, res);
90
    }
91
    const aom_image_t *img = dec->GetDxData().Next();
92 93 94
    md5->Add(img);
  }

95
  virtual void FramePktHook(const aom_codec_cx_pkt_t *pkt) {
96 97 98 99
    UpdateMD5(fw_dec_, pkt, &md5_fw_order_);
    UpdateMD5(inv_dec_, pkt, &md5_inv_order_);
  }

100
  void DoTest() {
101
    const aom_rational timebase = { 33333333, 1000000000 };
102 103 104
    cfg_.g_timebase = timebase;
    cfg_.rc_target_bitrate = 500;
    cfg_.g_lag_in_frames = 12;
105
    cfg_.rc_end_usage = AOM_VBR;
106

107
    libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 704, 576,
108 109 110 111 112 113 114 115
                                       timebase.den, timebase.num, 0, 5);
    ASSERT_NO_FATAL_FAILURE(RunLoop(&video));

    const char *md5_fw_str = md5_fw_order_.Get();
    const char *md5_inv_str = md5_inv_order_.Get();
    ASSERT_STREQ(md5_fw_str, md5_inv_str);
  }

116 117
  ::libaom_test::MD5 md5_fw_order_, md5_inv_order_;
  ::libaom_test::Decoder *fw_dec_, *inv_dec_;
118 119

 private:
Geza Lore's avatar
Geza Lore committed
120 121
  int n_tile_cols_;
  int n_tile_rows_;
122 123 124 125 126
};

// run an encode with 2 or 4 tiles, and do the decode both in normal and
// inverted tile ordering. Ensure that the MD5 of the output in both cases
// is identical. If so, tiles are considered independent and the test passes.
127 128 129
TEST_P(TileIndependenceTest, MD5Match) {
#if CONFIG_EXT_TILE
  cfg_.large_scale_tile = 0;
130 131
  fw_dec_->Control(AV1_SET_TILE_MODE, 0);
  inv_dec_->Control(AV1_SET_TILE_MODE, 0);
132 133 134
#endif  // CONFIG_EXT_TILE
  DoTest();
}
135 136

class TileIndependenceTestLarge : public TileIndependenceTest {
137
  virtual void SetCpuUsed(libaom_test::Encoder *encoder) {
138
    static const int kCpuUsed = 0;
139
    encoder->Control(AOME_SET_CPUUSED, kCpuUsed);
140 141 142
  }
};

143
TEST_P(TileIndependenceTestLarge, MD5Match) {
144
#if CONFIG_EXT_TILE
145
  cfg_.large_scale_tile = 0;
146 147
  fw_dec_->Control(AV1_SET_TILE_MODE, 0);
  inv_dec_->Control(AV1_SET_TILE_MODE, 0);
148 149 150 151
#endif  // CONFIG_EXT_TILE
  DoTest();
}

152 153 154 155
AV1_INSTANTIATE_TEST_CASE(TileIndependenceTest, ::testing::Values(0, 1),
                          ::testing::Values(0, 1));
AV1_INSTANTIATE_TEST_CASE(TileIndependenceTestLarge, ::testing::Values(0, 1),
                          ::testing::Values(0, 1));
156 157 158 159

#if CONFIG_EXT_TILE
class TileIndependenceLSTest : public TileIndependenceTest {};

Yunqing Wang's avatar
Yunqing Wang committed
160
TEST_P(TileIndependenceLSTest, DISABLED_MD5Match) {
161
  cfg_.large_scale_tile = 1;
162 163
  fw_dec_->Control(AV1_SET_TILE_MODE, 1);
  inv_dec_->Control(AV1_SET_TILE_MODE, 1);
164 165 166 167 168
  DoTest();
}

class TileIndependenceLSTestLarge : public TileIndependenceTestLarge {};

Yunqing Wang's avatar
Yunqing Wang committed
169
TEST_P(TileIndependenceLSTestLarge, DISABLED_MD5Match) {
170
  cfg_.large_scale_tile = 1;
171 172
  fw_dec_->Control(AV1_SET_TILE_MODE, 1);
  inv_dec_->Control(AV1_SET_TILE_MODE, 1);
173 174 175 176 177 178 179 180
  DoTest();
}

AV1_INSTANTIATE_TEST_CASE(TileIndependenceLSTest, ::testing::Values(1, 2, 32),
                          ::testing::Values(1, 2, 32));
AV1_INSTANTIATE_TEST_CASE(TileIndependenceLSTestLarge,
                          ::testing::Values(1, 2, 32),
                          ::testing::Values(1, 2, 32));
181
#endif  // CONFIG_EXT_TILE
182
}  // namespace