Merge "remove mmx variance functions"
[aom.git] / test / vp9_skip_loopfilter_test.cc
blobb0cc7ba41c71d80386dccfc00441dd3b107e5e79
1 /*
2 * Copyright (c) 2015 The WebM project authors. All Rights Reserved.
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 */
11 #include <string>
13 #include "test/codec_factory.h"
14 #include "test/decode_test_driver.h"
15 #include "test/md5_helper.h"
16 #include "test/util.h"
17 #include "test/webm_video_source.h"
19 namespace {
21 const char kVp9TestFile[] = "vp90-2-08-tile_1x8_frame_parallel.webm";
22 const char kVp9Md5File[] = "vp90-2-08-tile_1x8_frame_parallel.webm.md5";
24 // Class for testing shutting off the loop filter.
25 class SkipLoopFilterTest {
26 public:
27 SkipLoopFilterTest()
28 : video_(NULL),
29 decoder_(NULL),
30 md5_file_(NULL) {}
32 ~SkipLoopFilterTest() {
33 if (md5_file_ != NULL)
34 fclose(md5_file_);
35 delete decoder_;
36 delete video_;
39 // If |threads| > 0 then set the decoder with that number of threads.
40 void Init(int num_threads) {
41 expected_md5_[0] = '\0';
42 junk_[0] = '\0';
43 video_ = new libvpx_test::WebMVideoSource(kVp9TestFile);
44 ASSERT_TRUE(video_ != NULL);
45 video_->Init();
46 video_->Begin();
48 vpx_codec_dec_cfg_t cfg = vpx_codec_dec_cfg_t();
49 if (num_threads > 0)
50 cfg.threads = num_threads;
51 decoder_ = new libvpx_test::VP9Decoder(cfg, 0);
52 ASSERT_TRUE(decoder_ != NULL);
54 OpenMd5File(kVp9Md5File);
57 // Set the VP9 skipLoopFilter control value.
58 void SetSkipLoopFilter(int value, vpx_codec_err_t expected_value) {
59 decoder_->Control(VP9_SET_SKIP_LOOP_FILTER, value, expected_value);
62 vpx_codec_err_t DecodeOneFrame() {
63 const vpx_codec_err_t res =
64 decoder_->DecodeFrame(video_->cxdata(), video_->frame_size());
65 if (res == VPX_CODEC_OK) {
66 ReadMd5();
67 video_->Next();
69 return res;
72 vpx_codec_err_t DecodeRemainingFrames() {
73 for (; video_->cxdata() != NULL; video_->Next()) {
74 const vpx_codec_err_t res =
75 decoder_->DecodeFrame(video_->cxdata(), video_->frame_size());
76 if (res != VPX_CODEC_OK)
77 return res;
78 ReadMd5();
80 return VPX_CODEC_OK;
83 // Checks if MD5 matches or doesn't.
84 void CheckMd5(bool matches) {
85 libvpx_test::DxDataIterator dec_iter = decoder_->GetDxData();
86 const vpx_image_t *img = dec_iter.Next();
87 CheckMd5Vpx(*img, matches);
90 private:
91 // TODO(fgalligan): Move the MD5 testing code into another class.
92 void OpenMd5File(const std::string &md5_file_name) {
93 md5_file_ = libvpx_test::OpenTestDataFile(md5_file_name);
94 ASSERT_TRUE(md5_file_ != NULL) << "MD5 file open failed. Filename: "
95 << md5_file_name;
98 // Reads the next line of the MD5 file.
99 void ReadMd5() {
100 ASSERT_TRUE(md5_file_ != NULL);
101 const int res = fscanf(md5_file_, "%s %s", expected_md5_, junk_);
102 ASSERT_NE(EOF, res) << "Read md5 data failed";
103 expected_md5_[32] = '\0';
106 // Checks if the last read MD5 matches |img| or doesn't.
107 void CheckMd5Vpx(const vpx_image_t &img, bool matches) {
108 ::libvpx_test::MD5 md5_res;
109 md5_res.Add(&img);
110 const char *const actual_md5 = md5_res.Get();
112 // Check MD5.
113 if (matches)
114 ASSERT_STREQ(expected_md5_, actual_md5) << "MD5 checksums don't match";
115 else
116 ASSERT_STRNE(expected_md5_, actual_md5) << "MD5 checksums match";
119 libvpx_test::WebMVideoSource *video_;
120 libvpx_test::VP9Decoder *decoder_;
121 FILE *md5_file_;
122 char expected_md5_[33];
123 char junk_[128];
126 TEST(SkipLoopFilterTest, ShutOffLoopFilter) {
127 const int non_zero_value = 1;
128 const int num_threads = 0;
129 SkipLoopFilterTest skip_loop_filter;
130 skip_loop_filter.Init(num_threads);
131 skip_loop_filter.SetSkipLoopFilter(non_zero_value, VPX_CODEC_OK);
132 ASSERT_EQ(VPX_CODEC_OK, skip_loop_filter.DecodeRemainingFrames());
133 skip_loop_filter.CheckMd5(false);
136 TEST(SkipLoopFilterTest, ShutOffLoopFilterSingleThread) {
137 const int non_zero_value = 1;
138 const int num_threads = 1;
139 SkipLoopFilterTest skip_loop_filter;
140 skip_loop_filter.Init(num_threads);
141 skip_loop_filter.SetSkipLoopFilter(non_zero_value, VPX_CODEC_OK);
142 ASSERT_EQ(VPX_CODEC_OK, skip_loop_filter.DecodeRemainingFrames());
143 skip_loop_filter.CheckMd5(false);
146 TEST(SkipLoopFilterTest, ShutOffLoopFilter8Threads) {
147 const int non_zero_value = 1;
148 const int num_threads = 8;
149 SkipLoopFilterTest skip_loop_filter;
150 skip_loop_filter.Init(num_threads);
151 skip_loop_filter.SetSkipLoopFilter(non_zero_value, VPX_CODEC_OK);
152 ASSERT_EQ(VPX_CODEC_OK, skip_loop_filter.DecodeRemainingFrames());
153 skip_loop_filter.CheckMd5(false);
156 TEST(SkipLoopFilterTest, WithLoopFilter) {
157 const int non_zero_value = 1;
158 const int num_threads = 0;
159 SkipLoopFilterTest skip_loop_filter;
160 skip_loop_filter.Init(num_threads);
161 skip_loop_filter.SetSkipLoopFilter(non_zero_value, VPX_CODEC_OK);
162 skip_loop_filter.SetSkipLoopFilter(0, VPX_CODEC_OK);
163 ASSERT_EQ(VPX_CODEC_OK, skip_loop_filter.DecodeRemainingFrames());
164 skip_loop_filter.CheckMd5(true);
167 TEST(SkipLoopFilterTest, ToggleLoopFilter) {
168 const int num_threads = 0;
169 SkipLoopFilterTest skip_loop_filter;
170 skip_loop_filter.Init(num_threads);
172 for (int i = 0; i < 10; ++i) {
173 skip_loop_filter.SetSkipLoopFilter(i % 2, VPX_CODEC_OK);
174 ASSERT_EQ(VPX_CODEC_OK, skip_loop_filter.DecodeOneFrame());
176 ASSERT_EQ(VPX_CODEC_OK, skip_loop_filter.DecodeRemainingFrames());
177 skip_loop_filter.CheckMd5(false);
180 } // namespace