blob: da289c9901df269319cc66f82aefd11f1983d7d3 [file] [log] [blame]
hkuang5e7242d2014-06-23 14:59:20 -07001/*
Yaowu Xubde4ac82016-11-28 15:26:06 -08002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
hkuang5e7242d2014-06-23 14:59:20 -07003 *
Yaowu Xubde4ac82016-11-28 15:26:06 -08004 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
hkuang5e7242d2014-06-23 14:59:20 -070010 */
11
12#include <cstdio>
13#include <cstdlib>
14#include <string>
Tom Finegan7a07ece2017-02-07 17:14:05 -080015#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070016#include "./aom_config.h"
hkuangb3363562014-06-24 14:22:09 -070017#include "test/acm_random.h"
hkuang5e7242d2014-06-23 14:59:20 -070018#include "test/codec_factory.h"
19#include "test/decode_test_driver.h"
20#include "test/ivf_video_source.h"
21#include "test/md5_helper.h"
22#include "test/util.h"
23#if CONFIG_WEBM_IO
24#include "test/webm_video_source.h"
25#endif
Yaowu Xuf883b422016-08-30 14:01:10 -070026#include "aom_mem/aom_mem.h"
27#include "aom/aom.h"
hkuang5e7242d2014-06-23 14:59:20 -070028
29namespace {
30
31using std::string;
Yaowu Xuc27fc142016-08-22 16:08:15 -070032using libaom_test::ACMRandom;
hkuang5e7242d2014-06-23 14:59:20 -070033
34#if CONFIG_WEBM_IO
hkuangb3363562014-06-24 14:22:09 -070035
36void CheckUserPrivateData(void *user_priv, int *target) {
37 // actual pointer value should be the same as expected.
clang-format3a826f12016-08-11 17:46:05 -070038 EXPECT_EQ(reinterpret_cast<void *>(target), user_priv)
39 << "user_priv pointer value does not match.";
hkuangb3363562014-06-24 14:22:09 -070040}
41
hkuang5e7242d2014-06-23 14:59:20 -070042// Decodes |filename|. Passes in user_priv data when calling DecodeFrame and
43// compares the user_priv from return img with the original user_priv to see if
44// they match. Both the pointer values and the values inside the addresses
45// should match.
46string DecodeFile(const string &filename) {
hkuangb3363562014-06-24 14:22:09 -070047 ACMRandom rnd(ACMRandom::DeterministicSeed());
Yaowu Xuc27fc142016-08-22 16:08:15 -070048 libaom_test::WebMVideoSource video(filename);
hkuang5e7242d2014-06-23 14:59:20 -070049 video.Init();
50
Yaowu Xuf883b422016-08-30 14:01:10 -070051 aom_codec_dec_cfg_t cfg = aom_codec_dec_cfg_t();
Sebastien Alaiwan8a65f9f2017-06-23 07:28:44 +020052 cfg.allow_lowbitdepth = 1;
Yaowu Xuf883b422016-08-30 14:01:10 -070053 libaom_test::AV1Decoder decoder(cfg, 0);
hkuang5e7242d2014-06-23 14:59:20 -070054
Yaowu Xuc27fc142016-08-22 16:08:15 -070055 libaom_test::MD5 md5;
hkuang5e7242d2014-06-23 14:59:20 -070056 int frame_num = 0;
hkuangb3363562014-06-24 14:22:09 -070057 for (video.Begin(); !::testing::Test::HasFailure() && video.cxdata();
58 video.Next()) {
hkuang5e7242d2014-06-23 14:59:20 -070059 void *user_priv = reinterpret_cast<void *>(&frame_num);
Yaowu Xuf883b422016-08-30 14:01:10 -070060 const aom_codec_err_t res =
hkuang5e7242d2014-06-23 14:59:20 -070061 decoder.DecodeFrame(video.cxdata(), video.frame_size(),
62 (frame_num == 0) ? NULL : user_priv);
Yaowu Xuf883b422016-08-30 14:01:10 -070063 if (res != AOM_CODEC_OK) {
64 EXPECT_EQ(AOM_CODEC_OK, res) << decoder.DecodeError();
hkuang5e7242d2014-06-23 14:59:20 -070065 break;
66 }
Yaowu Xuc27fc142016-08-22 16:08:15 -070067 libaom_test::DxDataIterator dec_iter = decoder.GetDxData();
Yaowu Xuf883b422016-08-30 14:01:10 -070068 const aom_image_t *img = NULL;
hkuang5e7242d2014-06-23 14:59:20 -070069
70 // Get decompressed data.
71 while ((img = dec_iter.Next())) {
72 if (frame_num == 0) {
hkuangb3363562014-06-24 14:22:09 -070073 CheckUserPrivateData(img->user_priv, NULL);
hkuang5e7242d2014-06-23 14:59:20 -070074 } else {
hkuangb3363562014-06-24 14:22:09 -070075 CheckUserPrivateData(img->user_priv, &frame_num);
76
77 // Also test ctrl_get_reference api.
Yaowu Xuf883b422016-08-30 14:01:10 -070078 struct av1_ref_frame ref;
hkuangb3363562014-06-24 14:22:09 -070079 // Randomly fetch a reference frame.
80 ref.idx = rnd.Rand8() % 3;
Yaowu Xuf883b422016-08-30 14:01:10 -070081 decoder.Control(AV1_GET_REFERENCE, &ref);
hkuangb3363562014-06-24 14:22:09 -070082
James Zern749e0c72014-06-27 17:31:01 -070083 CheckUserPrivateData(ref.img.user_priv, NULL);
hkuang5e7242d2014-06-23 14:59:20 -070084 }
85 md5.Add(img);
86 }
87
88 frame_num++;
89 }
90 return string(md5.Get());
91}
92
93TEST(UserPrivTest, VideoDecode) {
94 // no tiles or frame parallel; this exercises the decoding to test the
95 // user_priv.
96 EXPECT_STREQ("b35a1b707b28e82be025d960aba039bc",
Yaowu Xuf883b422016-08-30 14:01:10 -070097 DecodeFile("av10-2-03-size-226x226.webm").c_str());
hkuang5e7242d2014-06-23 14:59:20 -070098}
99
100#endif // CONFIG_WEBM_IO
101
102} // namespace