hkuang | 5e7242d | 2014-06-23 14:59:20 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | bde4ac8 | 2016-11-28 15:26:06 -0800 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
hkuang | 5e7242d | 2014-06-23 14:59:20 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | bde4ac8 | 2016-11-28 15:26:06 -0800 | [diff] [blame] | 4 | * 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. |
hkuang | 5e7242d | 2014-06-23 14:59:20 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <cstdio> |
| 13 | #include <cstdlib> |
| 14 | #include <string> |
| 15 | #include "third_party/googletest/src/include/gtest/gtest.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 16 | #include "./aom_config.h" |
hkuang | b336356 | 2014-06-24 14:22:09 -0700 | [diff] [blame] | 17 | #include "test/acm_random.h" |
hkuang | 5e7242d | 2014-06-23 14:59:20 -0700 | [diff] [blame] | 18 | #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 Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 26 | #include "aom_mem/aom_mem.h" |
| 27 | #include "aom/aom.h" |
hkuang | 5e7242d | 2014-06-23 14:59:20 -0700 | [diff] [blame] | 28 | |
| 29 | namespace { |
| 30 | |
| 31 | using std::string; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 32 | using libaom_test::ACMRandom; |
hkuang | 5e7242d | 2014-06-23 14:59:20 -0700 | [diff] [blame] | 33 | |
| 34 | #if CONFIG_WEBM_IO |
hkuang | b336356 | 2014-06-24 14:22:09 -0700 | [diff] [blame] | 35 | |
| 36 | void CheckUserPrivateData(void *user_priv, int *target) { |
| 37 | // actual pointer value should be the same as expected. |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 38 | EXPECT_EQ(reinterpret_cast<void *>(target), user_priv) |
| 39 | << "user_priv pointer value does not match."; |
hkuang | b336356 | 2014-06-24 14:22:09 -0700 | [diff] [blame] | 40 | } |
| 41 | |
hkuang | 5e7242d | 2014-06-23 14:59:20 -0700 | [diff] [blame] | 42 | // 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. |
| 46 | string DecodeFile(const string &filename) { |
hkuang | b336356 | 2014-06-24 14:22:09 -0700 | [diff] [blame] | 47 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 48 | libaom_test::WebMVideoSource video(filename); |
hkuang | 5e7242d | 2014-06-23 14:59:20 -0700 | [diff] [blame] | 49 | video.Init(); |
| 50 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 51 | aom_codec_dec_cfg_t cfg = aom_codec_dec_cfg_t(); |
| 52 | libaom_test::AV1Decoder decoder(cfg, 0); |
hkuang | 5e7242d | 2014-06-23 14:59:20 -0700 | [diff] [blame] | 53 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 54 | libaom_test::MD5 md5; |
hkuang | 5e7242d | 2014-06-23 14:59:20 -0700 | [diff] [blame] | 55 | int frame_num = 0; |
hkuang | b336356 | 2014-06-24 14:22:09 -0700 | [diff] [blame] | 56 | for (video.Begin(); !::testing::Test::HasFailure() && video.cxdata(); |
| 57 | video.Next()) { |
hkuang | 5e7242d | 2014-06-23 14:59:20 -0700 | [diff] [blame] | 58 | void *user_priv = reinterpret_cast<void *>(&frame_num); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 59 | const aom_codec_err_t res = |
hkuang | 5e7242d | 2014-06-23 14:59:20 -0700 | [diff] [blame] | 60 | decoder.DecodeFrame(video.cxdata(), video.frame_size(), |
| 61 | (frame_num == 0) ? NULL : user_priv); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 62 | if (res != AOM_CODEC_OK) { |
| 63 | EXPECT_EQ(AOM_CODEC_OK, res) << decoder.DecodeError(); |
hkuang | 5e7242d | 2014-06-23 14:59:20 -0700 | [diff] [blame] | 64 | break; |
| 65 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 66 | libaom_test::DxDataIterator dec_iter = decoder.GetDxData(); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 67 | const aom_image_t *img = NULL; |
hkuang | 5e7242d | 2014-06-23 14:59:20 -0700 | [diff] [blame] | 68 | |
| 69 | // Get decompressed data. |
| 70 | while ((img = dec_iter.Next())) { |
| 71 | if (frame_num == 0) { |
hkuang | b336356 | 2014-06-24 14:22:09 -0700 | [diff] [blame] | 72 | CheckUserPrivateData(img->user_priv, NULL); |
hkuang | 5e7242d | 2014-06-23 14:59:20 -0700 | [diff] [blame] | 73 | } else { |
hkuang | b336356 | 2014-06-24 14:22:09 -0700 | [diff] [blame] | 74 | CheckUserPrivateData(img->user_priv, &frame_num); |
| 75 | |
| 76 | // Also test ctrl_get_reference api. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 77 | struct av1_ref_frame ref; |
hkuang | b336356 | 2014-06-24 14:22:09 -0700 | [diff] [blame] | 78 | // Randomly fetch a reference frame. |
| 79 | ref.idx = rnd.Rand8() % 3; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 80 | decoder.Control(AV1_GET_REFERENCE, &ref); |
hkuang | b336356 | 2014-06-24 14:22:09 -0700 | [diff] [blame] | 81 | |
James Zern | 749e0c7 | 2014-06-27 17:31:01 -0700 | [diff] [blame] | 82 | CheckUserPrivateData(ref.img.user_priv, NULL); |
hkuang | 5e7242d | 2014-06-23 14:59:20 -0700 | [diff] [blame] | 83 | } |
| 84 | md5.Add(img); |
| 85 | } |
| 86 | |
| 87 | frame_num++; |
| 88 | } |
| 89 | return string(md5.Get()); |
| 90 | } |
| 91 | |
| 92 | TEST(UserPrivTest, VideoDecode) { |
| 93 | // no tiles or frame parallel; this exercises the decoding to test the |
| 94 | // user_priv. |
| 95 | EXPECT_STREQ("b35a1b707b28e82be025d960aba039bc", |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 96 | DecodeFile("av10-2-03-size-226x226.webm").c_str()); |
hkuang | 5e7242d | 2014-06-23 14:59:20 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | #endif // CONFIG_WEBM_IO |
| 100 | |
| 101 | } // namespace |