Merge "remove mmx variance functions"
[aom.git] / test / user_priv_test.cc
blob8512d88cf43d3de988d9854f35dc318585893054
1 /*
2 * Copyright (c) 2013 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 <cstdio>
12 #include <cstdlib>
13 #include <string>
14 #include "third_party/googletest/src/include/gtest/gtest.h"
15 #include "./vpx_config.h"
16 #include "test/acm_random.h"
17 #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
25 #include "vpx_mem/vpx_mem.h"
26 #include "vpx/vp8.h"
28 namespace {
30 using std::string;
31 using libvpx_test::ACMRandom;
33 #if CONFIG_WEBM_IO
35 void CheckUserPrivateData(void *user_priv, int *target) {
36 // actual pointer value should be the same as expected.
37 EXPECT_EQ(reinterpret_cast<void *>(target), user_priv) <<
38 "user_priv pointer value does not match.";
41 // 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.
45 string DecodeFile(const string &filename) {
46 ACMRandom rnd(ACMRandom::DeterministicSeed());
47 libvpx_test::WebMVideoSource video(filename);
48 video.Init();
50 vpx_codec_dec_cfg_t cfg = vpx_codec_dec_cfg_t();
51 libvpx_test::VP9Decoder decoder(cfg, 0);
53 libvpx_test::MD5 md5;
54 int frame_num = 0;
55 for (video.Begin(); !::testing::Test::HasFailure() && video.cxdata();
56 video.Next()) {
57 void *user_priv = reinterpret_cast<void *>(&frame_num);
58 const vpx_codec_err_t res =
59 decoder.DecodeFrame(video.cxdata(), video.frame_size(),
60 (frame_num == 0) ? NULL : user_priv);
61 if (res != VPX_CODEC_OK) {
62 EXPECT_EQ(VPX_CODEC_OK, res) << decoder.DecodeError();
63 break;
65 libvpx_test::DxDataIterator dec_iter = decoder.GetDxData();
66 const vpx_image_t *img = NULL;
68 // Get decompressed data.
69 while ((img = dec_iter.Next())) {
70 if (frame_num == 0) {
71 CheckUserPrivateData(img->user_priv, NULL);
72 } else {
73 CheckUserPrivateData(img->user_priv, &frame_num);
75 // Also test ctrl_get_reference api.
76 struct vp9_ref_frame ref;
77 // Randomly fetch a reference frame.
78 ref.idx = rnd.Rand8() % 3;
79 decoder.Control(VP9_GET_REFERENCE, &ref);
81 CheckUserPrivateData(ref.img.user_priv, NULL);
83 md5.Add(img);
86 frame_num++;
88 return string(md5.Get());
91 TEST(UserPrivTest, VideoDecode) {
92 // no tiles or frame parallel; this exercises the decoding to test the
93 // user_priv.
94 EXPECT_STREQ("b35a1b707b28e82be025d960aba039bc",
95 DecodeFile("vp90-2-03-size-226x226.webm").c_str());
98 #endif // CONFIG_WEBM_IO
100 } // namespace