blob: 3052b27b1cf006ef25c8708d5e958fa2fcbb5d57 [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();
52 libaom_test::AV1Decoder decoder(cfg, 0);
hkuang5e7242d2014-06-23 14:59:20 -070053
Yaowu Xuc27fc142016-08-22 16:08:15 -070054 libaom_test::MD5 md5;
hkuang5e7242d2014-06-23 14:59:20 -070055 int frame_num = 0;
hkuangb3363562014-06-24 14:22:09 -070056 for (video.Begin(); !::testing::Test::HasFailure() && video.cxdata();
57 video.Next()) {
hkuang5e7242d2014-06-23 14:59:20 -070058 void *user_priv = reinterpret_cast<void *>(&frame_num);
Yaowu Xuf883b422016-08-30 14:01:10 -070059 const aom_codec_err_t res =
hkuang5e7242d2014-06-23 14:59:20 -070060 decoder.DecodeFrame(video.cxdata(), video.frame_size(),
61 (frame_num == 0) ? NULL : user_priv);
Yaowu Xuf883b422016-08-30 14:01:10 -070062 if (res != AOM_CODEC_OK) {
63 EXPECT_EQ(AOM_CODEC_OK, res) << decoder.DecodeError();
hkuang5e7242d2014-06-23 14:59:20 -070064 break;
65 }
Yaowu Xuc27fc142016-08-22 16:08:15 -070066 libaom_test::DxDataIterator dec_iter = decoder.GetDxData();
Yaowu Xuf883b422016-08-30 14:01:10 -070067 const aom_image_t *img = NULL;
hkuang5e7242d2014-06-23 14:59:20 -070068
69 // Get decompressed data.
70 while ((img = dec_iter.Next())) {
71 if (frame_num == 0) {
hkuangb3363562014-06-24 14:22:09 -070072 CheckUserPrivateData(img->user_priv, NULL);
hkuang5e7242d2014-06-23 14:59:20 -070073 } else {
hkuangb3363562014-06-24 14:22:09 -070074 CheckUserPrivateData(img->user_priv, &frame_num);
75
76 // Also test ctrl_get_reference api.
Yaowu Xuf883b422016-08-30 14:01:10 -070077 struct av1_ref_frame ref;
hkuangb3363562014-06-24 14:22:09 -070078 // Randomly fetch a reference frame.
79 ref.idx = rnd.Rand8() % 3;
Yaowu Xuf883b422016-08-30 14:01:10 -070080 decoder.Control(AV1_GET_REFERENCE, &ref);
hkuangb3363562014-06-24 14:22:09 -070081
James Zern749e0c72014-06-27 17:31:01 -070082 CheckUserPrivateData(ref.img.user_priv, NULL);
hkuang5e7242d2014-06-23 14:59:20 -070083 }
84 md5.Add(img);
85 }
86
87 frame_num++;
88 }
89 return string(md5.Get());
90}
91
92TEST(UserPrivTest, VideoDecode) {
93 // no tiles or frame parallel; this exercises the decoding to test the
94 // user_priv.
95 EXPECT_STREQ("b35a1b707b28e82be025d960aba039bc",
Yaowu Xuf883b422016-08-30 14:01:10 -070096 DecodeFile("av10-2-03-size-226x226.webm").c_str());
hkuang5e7242d2014-06-23 14:59:20 -070097}
98
99#endif // CONFIG_WEBM_IO
100
101} // namespace