tile_independence_test.cc 4.86 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
15
16
17
18
19
20

#include <cstdio>
#include <cstdlib>
#include <string>
#include "third_party/googletest/src/include/gtest/gtest.h"
#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::EncoderTest,
      public ::libaom_test::CodecTestWith2Params<int, int> {
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
36
37
    cfg.threads = 1;
    fw_dec_ = codec_->CreateDecoder(cfg, 0);
    inv_dec_ = codec_->CreateDecoder(cfg, 0);
Yaowu Xu's avatar
Yaowu Xu committed
38
39
40
41
42
43
44
45
    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);
46
47
    }
#endif
48
49
50
51
52
53
54
55
56
  }

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

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

60
61
  virtual void PreEncodeFrameHook(libaom_test::VideoSource *video,
                                  libaom_test::Encoder *encoder) {
62
    if (video->frame() == 1) {
Yaowu Xu's avatar
Yaowu Xu committed
63
64
      encoder->Control(AV1E_SET_TILE_COLUMNS, n_tile_cols_);
      encoder->Control(AV1E_SET_TILE_ROWS, n_tile_rows_);
65
      SetCpuUsed(encoder);
66
67
68
    }
  }

69
  virtual void SetCpuUsed(libaom_test::Encoder *encoder) {
70
    static const int kCpuUsed = 3;
Yaowu Xu's avatar
Yaowu Xu committed
71
    encoder->Control(AOME_SET_CPUUSED, kCpuUsed);
72
73
  }

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

Yaowu Xu's avatar
Yaowu Xu committed
86
  virtual void FramePktHook(const aom_codec_cx_pkt_t *pkt) {
87
88
89
90
    UpdateMD5(fw_dec_, pkt, &md5_fw_order_);
    UpdateMD5(inv_dec_, pkt, &md5_inv_order_);
  }

91
  void DoTest() {
Yaowu Xu's avatar
Yaowu Xu committed
92
    const aom_rational timebase = { 33333333, 1000000000 };
93
94
95
    cfg_.g_timebase = timebase;
    cfg_.rc_target_bitrate = 500;
    cfg_.g_lag_in_frames = 12;
Yaowu Xu's avatar
Yaowu Xu committed
96
    cfg_.rc_end_usage = AOM_VBR;
97

98
    libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 704, 576,
99
100
101
102
103
104
105
106
                                       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);
  }

107
108
  ::libaom_test::MD5 md5_fw_order_, md5_inv_order_;
  ::libaom_test::Decoder *fw_dec_, *inv_dec_;
109
110

 private:
Geza Lore's avatar
Geza Lore committed
111
112
  int n_tile_cols_;
  int n_tile_rows_;
113
114
115
116
117
};

// 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
118
TEST_P(TileIndependenceTest, MD5Match) { DoTest(); }
119
120

class TileIndependenceTestLarge : public TileIndependenceTest {
121
  virtual void SetCpuUsed(libaom_test::Encoder *encoder) {
122
    static const int kCpuUsed = 0;
Yaowu Xu's avatar
Yaowu Xu committed
123
    encoder->Control(AOME_SET_CPUUSED, kCpuUsed);
124
125
126
  }
};

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

129
130
131
#if CONFIG_EC_ADAPT
// TODO(thdavies): EC_ADAPT does not support tiles
#else
132
#if CONFIG_EXT_TILE
Yaowu Xu's avatar
Yaowu Xu committed
133
134
135
136
137
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));
138
#else
Yaowu Xu's avatar
Yaowu Xu committed
139
140
141
142
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));
143
#endif  // CONFIG_EXT_TILE
144
#endif  // CONFIG_EC_ADAPT
145
}  // namespace