tile_independence_test.cc 5.09 KB
Newer Older
1
/*
Yaowu Xu's avatar
Yaowu Xu committed
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Frank Galligan's avatar
Frank Galligan committed
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 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"
Yaowu Xu's avatar
Yaowu Xu committed
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)) {
Yaowu Xu's avatar
Yaowu Xu committed
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);
Yaowu Xu's avatar
Yaowu Xu committed
39 40 41 42 43 44 45 46
    inv_dec_->Control(AV1_INVERT_TILE_DECODE_ORDER, 1);

#if CONFIG_AV1 && CONFIG_EXT_TILE
    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) {
Yaowu Xu's avatar
Yaowu Xu committed
64 65
      encoder->Control(AV1E_SET_TILE_COLUMNS, n_tile_cols_);
      encoder->Control(AV1E_SET_TILE_ROWS, n_tile_rows_);
66 67 68
#if CONFIG_EXT_TILE
      encoder->Control(AV1E_SET_TILE_ENCODING_MODE, 0);  // TILE_NORMAL
#endif                                                   // CONFIG_EXT_TILE
69
#if CONFIG_LOOPFILTERING_ACROSS_TILES
70
      encoder->Control(AV1E_SET_TILE_LOOPFILTER, 0);
71
#endif  // CONFIG_LOOPFILTERING_ACROSS_TILES
72
      SetCpuUsed(encoder);
73 74 75
    }
  }

76
  virtual void SetCpuUsed(libaom_test::Encoder *encoder) {
77
    static const int kCpuUsed = 3;
Yaowu Xu's avatar
Yaowu Xu committed
78
    encoder->Control(AOME_SET_CPUUSED, kCpuUsed);
79 80
  }

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

Yaowu Xu's avatar
Yaowu Xu committed
93
  virtual void FramePktHook(const aom_codec_cx_pkt_t *pkt) {
94 95 96 97
    UpdateMD5(fw_dec_, pkt, &md5_fw_order_);
    UpdateMD5(inv_dec_, pkt, &md5_inv_order_);
  }

98
  void DoTest() {
Yaowu Xu's avatar
Yaowu Xu committed
99
    const aom_rational timebase = { 33333333, 1000000000 };
100 101 102
    cfg_.g_timebase = timebase;
    cfg_.rc_target_bitrate = 500;
    cfg_.g_lag_in_frames = 12;
Yaowu Xu's avatar
Yaowu Xu committed
103
    cfg_.rc_end_usage = AOM_VBR;
104

105
    libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 704, 576,
106 107 108 109 110 111 112 113
                                       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);
  }

114 115
  ::libaom_test::MD5 md5_fw_order_, md5_inv_order_;
  ::libaom_test::Decoder *fw_dec_, *inv_dec_;
116 117

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

// 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.
clang-format's avatar
clang-format committed
125
TEST_P(TileIndependenceTest, MD5Match) { DoTest(); }
126 127

class TileIndependenceTestLarge : public TileIndependenceTest {
128
  virtual void SetCpuUsed(libaom_test::Encoder *encoder) {
129
    static const int kCpuUsed = 0;
Yaowu Xu's avatar
Yaowu Xu committed
130
    encoder->Control(AOME_SET_CPUUSED, kCpuUsed);
131 132 133
  }
};

clang-format's avatar
clang-format committed
134
TEST_P(TileIndependenceTestLarge, MD5Match) { DoTest(); }
135

136
#if CONFIG_EXT_TILE
Yaowu Xu's avatar
Yaowu Xu committed
137 138 139 140 141
AV1_INSTANTIATE_TEST_CASE(TileIndependenceTest, ::testing::Values(1, 2, 32),
                          ::testing::Values(1, 2, 32));
AV1_INSTANTIATE_TEST_CASE(TileIndependenceTestLarge,
                          ::testing::Values(1, 2, 32),
                          ::testing::Values(1, 2, 32));
142
#else
Yaowu Xu's avatar
Yaowu Xu committed
143 144 145 146
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));
147
#endif  // CONFIG_EXT_TILE
148
}  // namespace