blob: 54d4ee6a03257705436f9bcdd696ebd47581d9b0 [file] [log] [blame]
hkuang5e7242d2014-06-23 14:59:20 -07001/*
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"
Yaowu Xuf883b422016-08-30 14:01:10 -070015#include "./aom_config.h"
hkuangb3363562014-06-24 14:22:09 -070016#include "test/acm_random.h"
hkuang5e7242d2014-06-23 14:59:20 -070017#include "test/codec_factory.h"
18#include "test/decode_test_driver.h"
19#include "test/ivf_video_source.h"
20#include "test/md5_helper.h"
21#include "test/util.h"
22#if CONFIG_WEBM_IO
23#include "test/webm_video_source.h"
24#endif
Yaowu Xuf883b422016-08-30 14:01:10 -070025#include "aom_mem/aom_mem.h"
26#include "aom/aom.h"
hkuang5e7242d2014-06-23 14:59:20 -070027
28namespace {
29
30using std::string;
Yaowu Xuc27fc142016-08-22 16:08:15 -070031using libaom_test::ACMRandom;
hkuang5e7242d2014-06-23 14:59:20 -070032
33#if CONFIG_WEBM_IO
hkuangb3363562014-06-24 14:22:09 -070034
35void CheckUserPrivateData(void *user_priv, int *target) {
36 // actual pointer value should be the same as expected.
clang-format3a826f12016-08-11 17:46:05 -070037 EXPECT_EQ(reinterpret_cast<void *>(target), user_priv)
38 << "user_priv pointer value does not match.";
hkuangb3363562014-06-24 14:22:09 -070039}
40
hkuang5e7242d2014-06-23 14:59:20 -070041// Decodes |filename|. Passes in user_priv data when calling DecodeFrame and
42// compares the user_priv from return img with the original user_priv to see if
43// they match. Both the pointer values and the values inside the addresses
44// should match.
45string DecodeFile(const string &filename) {
hkuangb3363562014-06-24 14:22:09 -070046 ACMRandom rnd(ACMRandom::DeterministicSeed());
Yaowu Xuc27fc142016-08-22 16:08:15 -070047 libaom_test::WebMVideoSource video(filename);
hkuang5e7242d2014-06-23 14:59:20 -070048 video.Init();
49
Yaowu Xuf883b422016-08-30 14:01:10 -070050 aom_codec_dec_cfg_t cfg = aom_codec_dec_cfg_t();
51 libaom_test::AV1Decoder decoder(cfg, 0);
hkuang5e7242d2014-06-23 14:59:20 -070052
Yaowu Xuc27fc142016-08-22 16:08:15 -070053 libaom_test::MD5 md5;
hkuang5e7242d2014-06-23 14:59:20 -070054 int frame_num = 0;
hkuangb3363562014-06-24 14:22:09 -070055 for (video.Begin(); !::testing::Test::HasFailure() && video.cxdata();
56 video.Next()) {
hkuang5e7242d2014-06-23 14:59:20 -070057 void *user_priv = reinterpret_cast<void *>(&frame_num);
Yaowu Xuf883b422016-08-30 14:01:10 -070058 const aom_codec_err_t res =
hkuang5e7242d2014-06-23 14:59:20 -070059 decoder.DecodeFrame(video.cxdata(), video.frame_size(),
60 (frame_num == 0) ? NULL : user_priv);
Yaowu Xuf883b422016-08-30 14:01:10 -070061 if (res != AOM_CODEC_OK) {
62 EXPECT_EQ(AOM_CODEC_OK, res) << decoder.DecodeError();
hkuang5e7242d2014-06-23 14:59:20 -070063 break;
64 }
Yaowu Xuc27fc142016-08-22 16:08:15 -070065 libaom_test::DxDataIterator dec_iter = decoder.GetDxData();
Yaowu Xuf883b422016-08-30 14:01:10 -070066 const aom_image_t *img = NULL;
hkuang5e7242d2014-06-23 14:59:20 -070067
68 // Get decompressed data.
69 while ((img = dec_iter.Next())) {
70 if (frame_num == 0) {
hkuangb3363562014-06-24 14:22:09 -070071 CheckUserPrivateData(img->user_priv, NULL);
hkuang5e7242d2014-06-23 14:59:20 -070072 } else {
hkuangb3363562014-06-24 14:22:09 -070073 CheckUserPrivateData(img->user_priv, &frame_num);
74
75 // Also test ctrl_get_reference api.
Yaowu Xuf883b422016-08-30 14:01:10 -070076 struct av1_ref_frame ref;
hkuangb3363562014-06-24 14:22:09 -070077 // Randomly fetch a reference frame.
78 ref.idx = rnd.Rand8() % 3;
Yaowu Xuf883b422016-08-30 14:01:10 -070079 decoder.Control(AV1_GET_REFERENCE, &ref);
hkuangb3363562014-06-24 14:22:09 -070080
James Zern749e0c72014-06-27 17:31:01 -070081 CheckUserPrivateData(ref.img.user_priv, NULL);
hkuang5e7242d2014-06-23 14:59:20 -070082 }
83 md5.Add(img);
84 }
85
86 frame_num++;
87 }
88 return string(md5.Get());
89}
90
91TEST(UserPrivTest, VideoDecode) {
92 // no tiles or frame parallel; this exercises the decoding to test the
93 // user_priv.
94 EXPECT_STREQ("b35a1b707b28e82be025d960aba039bc",
Yaowu Xuf883b422016-08-30 14:01:10 -070095 DecodeFile("av10-2-03-size-226x226.webm").c_str());
hkuang5e7242d2014-06-23 14:59:20 -070096}
97
98#endif // CONFIG_WEBM_IO
99
100} // namespace