]> granicus.if.org Git - libvpx/blob - test/user_priv_test.cc
Merge "decode_test_driver: check HasFailure() in RunLoop"
[libvpx] / test / user_priv_test.cc
1 /*
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"
15 #include "./vpx_config.h"
16 #include "test/codec_factory.h"
17 #include "test/decode_test_driver.h"
18 #include "test/ivf_video_source.h"
19 #include "test/md5_helper.h"
20 #include "test/util.h"
21 #if CONFIG_WEBM_IO
22 #include "test/webm_video_source.h"
23 #endif
24 #include "vpx_mem/vpx_mem.h"
25
26 namespace {
27
28 using std::string;
29
30 #if CONFIG_WEBM_IO
31 // Decodes |filename|. Passes in user_priv data when calling DecodeFrame and
32 // compares the user_priv from return img with the original user_priv to see if
33 // they match. Both the pointer values and the values inside the addresses
34 // should match.
35 string DecodeFile(const string &filename) {
36   libvpx_test::WebMVideoSource video(filename);
37   video.Init();
38
39   vpx_codec_dec_cfg_t cfg = {0};
40   libvpx_test::VP9Decoder decoder(cfg, 0);
41
42   libvpx_test::MD5 md5;
43   int frame_num = 0;
44   for (video.Begin(); video.cxdata(); video.Next()) {
45     void *user_priv = reinterpret_cast<void *>(&frame_num);
46     const vpx_codec_err_t res =
47         decoder.DecodeFrame(video.cxdata(), video.frame_size(),
48                             (frame_num == 0) ? NULL : user_priv);
49     if (res != VPX_CODEC_OK) {
50       EXPECT_EQ(VPX_CODEC_OK, res) << decoder.DecodeError();
51       break;
52     }
53     libvpx_test::DxDataIterator dec_iter = decoder.GetDxData();
54     const vpx_image_t *img = NULL;
55
56     // Get decompressed data.
57     while ((img = dec_iter.Next())) {
58       if (frame_num == 0) {
59         // user_priv pointer value should be the same.
60         EXPECT_EQ(img->user_priv, reinterpret_cast<void *>(NULL)) <<
61             "user_priv pointer value does not match.";
62       } else {
63         // user_priv pointer value should be the same.
64         EXPECT_EQ(img->user_priv, reinterpret_cast<void *>(&frame_num)) <<
65             "user_priv pointer value does not match.";
66         // value in user_priv pointer should also be the same.
67         EXPECT_EQ(*reinterpret_cast<int *>(img->user_priv), frame_num) <<
68             "Value in user_priv does not match.";
69       }
70       md5.Add(img);
71     }
72
73     frame_num++;
74   }
75   return string(md5.Get());
76 }
77
78 TEST(UserPrivTest, VideoDecode) {
79   // no tiles or frame parallel; this exercises the decoding to test the
80   // user_priv.
81   EXPECT_STREQ("b35a1b707b28e82be025d960aba039bc",
82                DecodeFile("vp90-2-03-size-226x226.webm").c_str());
83 }
84
85 #endif  // CONFIG_WEBM_IO
86
87 }  // namespace