blob: 193bd45986853d204491dd09ff8959ad6298f36e [file] [log] [blame]
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -08001/*
Frank Galligan38536f62013-12-12 08:36:34 -08002 * 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.
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -08009 */
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"
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080020#include "vpx_mem/vpx_mem.h"
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080021
22namespace {
23class TileIndependenceTest : public ::libvpx_test::EncoderTest,
James Zernbae31172013-07-18 14:37:53 -070024 public ::libvpx_test::CodecTestWithParam<int> {
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080025 protected:
James Zernbae31172013-07-18 14:37:53 -070026 TileIndependenceTest()
27 : EncoderTest(GET_PARAM(0)),
28 md5_fw_order_(),
29 md5_inv_order_(),
30 n_tiles_(GET_PARAM(1)) {
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080031 init_flags_ = VPX_CODEC_USE_PSNR;
James Zernb4b191a2014-08-22 12:16:20 -070032 vpx_codec_dec_cfg_t cfg = vpx_codec_dec_cfg_t();
Ronald S. Bultjef496f602013-02-06 15:30:21 -080033 cfg.w = 704;
34 cfg.h = 144;
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080035 cfg.threads = 1;
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080036 fw_dec_ = codec_->CreateDecoder(cfg, 0);
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080037 inv_dec_ = codec_->CreateDecoder(cfg, 0);
John Koleszar672b75a2013-03-27 11:22:20 -070038 inv_dec_->Control(VP9_INVERT_TILE_DECODE_ORDER, 1);
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080039 }
40
41 virtual ~TileIndependenceTest() {
42 delete fw_dec_;
43 delete inv_dec_;
44 }
45
46 virtual void SetUp() {
47 InitializeConfig();
Ronald S. Bultjee189edf2013-03-01 12:43:10 -080048 SetMode(libvpx_test::kTwoPassGood);
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080049 }
50
51 virtual void PreEncodeFrameHook(libvpx_test::VideoSource *video,
52 libvpx_test::Encoder *encoder) {
53 if (video->frame() == 1) {
54 encoder->Control(VP9E_SET_TILE_COLUMNS, n_tiles_);
55 }
56 }
57
58 void UpdateMD5(::libvpx_test::Decoder *dec, const vpx_codec_cx_pkt_t *pkt,
59 ::libvpx_test::MD5 *md5) {
James Zernbae31172013-07-18 14:37:53 -070060 const vpx_codec_err_t res = dec->DecodeFrame(
61 reinterpret_cast<uint8_t*>(pkt->data.frame.buf), pkt->data.frame.sz);
James Zern2b1a0b62013-05-06 11:45:03 -070062 if (res != VPX_CODEC_OK) {
63 abort_ = true;
64 ASSERT_EQ(VPX_CODEC_OK, res);
65 }
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080066 const vpx_image_t *img = dec->GetDxData().Next();
67 md5->Add(img);
68 }
69
70 virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) {
71 UpdateMD5(fw_dec_, pkt, &md5_fw_order_);
72 UpdateMD5(inv_dec_, pkt, &md5_inv_order_);
73 }
74
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080075 ::libvpx_test::MD5 md5_fw_order_, md5_inv_order_;
76 ::libvpx_test::Decoder *fw_dec_, *inv_dec_;
James Zernbae31172013-07-18 14:37:53 -070077
78 private:
79 int n_tiles_;
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080080};
81
82// run an encode with 2 or 4 tiles, and do the decode both in normal and
83// inverted tile ordering. Ensure that the MD5 of the output in both cases
84// is identical. If so, tiles are considered independent and the test passes.
85TEST_P(TileIndependenceTest, MD5Match) {
86 const vpx_rational timebase = { 33333333, 1000000000 };
87 cfg_.g_timebase = timebase;
88 cfg_.rc_target_bitrate = 500;
89 cfg_.g_lag_in_frames = 25;
90 cfg_.rc_end_usage = VPX_VBR;
91
Ronald S. Bultjef496f602013-02-06 15:30:21 -080092 libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 704, 144,
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080093 timebase.den, timebase.num, 0, 30);
94 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
95
James Zernbae31172013-07-18 14:37:53 -070096 const char *md5_fw_str = md5_fw_order_.Get();
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080097 const char *md5_inv_str = md5_inv_order_.Get();
98
99 // could use ASSERT_EQ(!memcmp(.., .., 16) here, but this gives nicer
100 // output if it fails. Not sure if it's helpful since it's really just
101 // a MD5...
102 ASSERT_STREQ(md5_fw_str, md5_inv_str);
103}
104
James Zernbae31172013-07-18 14:37:53 -0700105VP9_INSTANTIATE_TEST_CASE(TileIndependenceTest, ::testing::Range(0, 2, 1));
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -0800106
Jingning Han41be09a2015-08-19 14:13:18 -0700107VP10_INSTANTIATE_TEST_CASE(TileIndependenceTest, ::testing::Range(0, 2, 1));
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -0800108} // namespace