]> granicus.if.org Git - libvpx/blob - test/tile_independence_test.cc
Merge "Increase disable_filter_search_var_thresh threshold"
[libvpx] / test / tile_independence_test.cc
1 /*
2  *  Copyright (c) 2013 The WebM project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10
11 #include <cstdio>
12 #include <cstdlib>
13 #include <string>
14 #include "third_party/googletest/src/include/gtest/gtest.h"
15 #include "test/codec_factory.h"
16 #include "test/encode_test_driver.h"
17 #include "test/i420_video_source.h"
18 #include "test/util.h"
19 #include "test/md5_helper.h"
20 extern "C" {
21 #include "vpx_mem/vpx_mem.h"
22 }
23
24 namespace {
25 class TileIndependenceTest : public ::libvpx_test::EncoderTest,
26                              public ::libvpx_test::CodecTestWithParam<int> {
27  protected:
28   TileIndependenceTest()
29       : EncoderTest(GET_PARAM(0)),
30         md5_fw_order_(),
31         md5_inv_order_(),
32         n_tiles_(GET_PARAM(1)) {
33     init_flags_ = VPX_CODEC_USE_PSNR;
34     vpx_codec_dec_cfg_t cfg;
35     cfg.w = 704;
36     cfg.h = 144;
37     cfg.threads = 1;
38     fw_dec_ = codec_->CreateDecoder(cfg, 0);
39     inv_dec_ = codec_->CreateDecoder(cfg, 0);
40     inv_dec_->Control(VP9_INVERT_TILE_DECODE_ORDER, 1);
41   }
42
43   virtual ~TileIndependenceTest() {
44     delete fw_dec_;
45     delete inv_dec_;
46   }
47
48   virtual void SetUp() {
49     InitializeConfig();
50     SetMode(libvpx_test::kTwoPassGood);
51   }
52
53   virtual void PreEncodeFrameHook(libvpx_test::VideoSource *video,
54                                   libvpx_test::Encoder *encoder) {
55     if (video->frame() == 1) {
56       encoder->Control(VP9E_SET_TILE_COLUMNS, n_tiles_);
57     }
58   }
59
60   void UpdateMD5(::libvpx_test::Decoder *dec, const vpx_codec_cx_pkt_t *pkt,
61                  ::libvpx_test::MD5 *md5) {
62     const vpx_codec_err_t res = dec->DecodeFrame(
63         reinterpret_cast<uint8_t*>(pkt->data.frame.buf), pkt->data.frame.sz);
64     if (res != VPX_CODEC_OK) {
65       abort_ = true;
66       ASSERT_EQ(VPX_CODEC_OK, res);
67     }
68     const vpx_image_t *img = dec->GetDxData().Next();
69     md5->Add(img);
70   }
71
72   virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) {
73     UpdateMD5(fw_dec_, pkt, &md5_fw_order_);
74     UpdateMD5(inv_dec_, pkt, &md5_inv_order_);
75   }
76
77   ::libvpx_test::MD5 md5_fw_order_, md5_inv_order_;
78   ::libvpx_test::Decoder *fw_dec_, *inv_dec_;
79
80  private:
81   int n_tiles_;
82 };
83
84 // run an encode with 2 or 4 tiles, and do the decode both in normal and
85 // inverted tile ordering. Ensure that the MD5 of the output in both cases
86 // is identical. If so, tiles are considered independent and the test passes.
87 TEST_P(TileIndependenceTest, MD5Match) {
88   const vpx_rational timebase = { 33333333, 1000000000 };
89   cfg_.g_timebase = timebase;
90   cfg_.rc_target_bitrate = 500;
91   cfg_.g_lag_in_frames = 25;
92   cfg_.rc_end_usage = VPX_VBR;
93
94   libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 704, 144,
95                                      timebase.den, timebase.num, 0, 30);
96   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
97
98   const char *md5_fw_str = md5_fw_order_.Get();
99   const char *md5_inv_str = md5_inv_order_.Get();
100
101   // could use ASSERT_EQ(!memcmp(.., .., 16) here, but this gives nicer
102   // output if it fails. Not sure if it's helpful since it's really just
103   // a MD5...
104   ASSERT_STREQ(md5_fw_str, md5_inv_str);
105 }
106
107 VP9_INSTANTIATE_TEST_CASE(TileIndependenceTest, ::testing::Range(0, 2, 1));
108
109 }  // namespace