]> granicus.if.org Git - libvpx/commitdiff
Add unit test to test user_priv parameter.
authorhkuang <hkuang@google.com>
Mon, 23 Jun 2014 21:59:20 +0000 (14:59 -0700)
committerhkuang <hkuang@google.com>
Tue, 24 Jun 2014 18:20:43 +0000 (11:20 -0700)
Change-Id: I6ba6171e43e0a43331ee0a7b698590b143979c44

test/decode_test_driver.cc
test/decode_test_driver.h
test/test.mk
test/user_priv_test.cc [new file with mode: 0644]

index 778c9a3c4ff000348ebd1e140c68c5cc7c368192..655b09055931f29fad17c2c910c9ac294a9bddbe 100644 (file)
@@ -24,12 +24,17 @@ vpx_codec_err_t Decoder::PeekStream(const uint8_t *cxdata, size_t size,
 }
 
 vpx_codec_err_t Decoder::DecodeFrame(const uint8_t *cxdata, size_t size) {
+  return DecodeFrame(cxdata, size, NULL);
+}
+
+vpx_codec_err_t Decoder::DecodeFrame(const uint8_t *cxdata, size_t size,
+                                     void *user_priv) {
   vpx_codec_err_t res_dec;
   InitOnce();
   REGISTER_STATE_CHECK(
       res_dec = vpx_codec_decode(&decoder_,
                                  cxdata, static_cast<unsigned int>(size),
-                                 NULL, 0));
+                                 user_priv, 0));
   return res_dec;
 }
 
index ada2946c805c92479ab0da496dedaeac4a322c0e..dd3593e1e3809eaff0190e73bcb95b2d5ceaf2ce 100644 (file)
@@ -54,6 +54,9 @@ class Decoder {
 
   vpx_codec_err_t DecodeFrame(const uint8_t *cxdata, size_t size);
 
+  vpx_codec_err_t DecodeFrame(const uint8_t *cxdata, size_t size,
+                              void *user_priv);
+
   DxDataIterator GetDxData() {
     return DxDataIterator(&decoder_);
   }
index 7a3eaa9aac9f0ed64ab97b71dfda231d57b710ba..a8397235db111881ab342b220b5af91fba507363 100644 (file)
@@ -30,6 +30,7 @@ LIBVPX_TEST_SRCS-$(CONFIG_VP8_ENCODER) += cq_test.cc
 LIBVPX_TEST_SRCS-$(CONFIG_VP8_ENCODER) += keyframe_test.cc
 
 LIBVPX_TEST_SRCS-$(CONFIG_VP9_DECODER) += external_frame_buffer_test.cc
+LIBVPX_TEST_SRCS-$(CONFIG_VP9_DECODER) += user_priv_test.cc
 LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += active_map_test.cc
 LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += borders_test.cc
 LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += cpu_speed_test.cc
diff --git a/test/user_priv_test.cc b/test/user_priv_test.cc
new file mode 100644 (file)
index 0000000..38eef1c
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ *  Copyright (c) 2013 The WebM project authors. All Rights Reserved.
+ *
+ *  Use of this source code is governed by a BSD-style license
+ *  that can be found in the LICENSE file in the root of the source
+ *  tree. An additional intellectual property rights grant can be found
+ *  in the file PATENTS.  All contributing project authors may
+ *  be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include <cstdio>
+#include <cstdlib>
+#include <string>
+#include "third_party/googletest/src/include/gtest/gtest.h"
+#include "./vpx_config.h"
+#include "test/codec_factory.h"
+#include "test/decode_test_driver.h"
+#include "test/ivf_video_source.h"
+#include "test/md5_helper.h"
+#include "test/util.h"
+#if CONFIG_WEBM_IO
+#include "test/webm_video_source.h"
+#endif
+#include "vpx_mem/vpx_mem.h"
+
+namespace {
+
+using std::string;
+
+#if CONFIG_WEBM_IO
+// Decodes |filename|. Passes in user_priv data when calling DecodeFrame and
+// compares the user_priv from return img with the original user_priv to see if
+// they match. Both the pointer values and the values inside the addresses
+// should match.
+string DecodeFile(const string &filename) {
+  libvpx_test::WebMVideoSource video(filename);
+  video.Init();
+
+  vpx_codec_dec_cfg_t cfg = {0};
+  libvpx_test::VP9Decoder decoder(cfg, 0);
+
+  libvpx_test::MD5 md5;
+  int frame_num = 0;
+  for (video.Begin(); video.cxdata(); video.Next()) {
+    void *user_priv = reinterpret_cast<void *>(&frame_num);
+    const vpx_codec_err_t res =
+        decoder.DecodeFrame(video.cxdata(), video.frame_size(),
+                            (frame_num == 0) ? NULL : user_priv);
+    if (res != VPX_CODEC_OK) {
+      EXPECT_EQ(VPX_CODEC_OK, res) << decoder.DecodeError();
+      break;
+    }
+    libvpx_test::DxDataIterator dec_iter = decoder.GetDxData();
+    const vpx_image_t *img = NULL;
+
+    // Get decompressed data.
+    while ((img = dec_iter.Next())) {
+      if (frame_num == 0) {
+        // user_priv pointer value should be the same.
+        EXPECT_EQ(img->user_priv, reinterpret_cast<void *>(NULL)) <<
+            "user_priv pointer value does not match.";
+      } else {
+        // user_priv pointer value should be the same.
+        EXPECT_EQ(img->user_priv, reinterpret_cast<void *>(&frame_num)) <<
+            "user_priv pointer value does not match.";
+        // value in user_priv pointer should also be the same.
+        EXPECT_EQ(*reinterpret_cast<int *>(img->user_priv), frame_num) <<
+            "Value in user_priv does not match.";
+      }
+      md5.Add(img);
+    }
+
+    frame_num++;
+  }
+  return string(md5.Get());
+}
+
+TEST(UserPrivTest, VideoDecode) {
+  // no tiles or frame parallel; this exercises the decoding to test the
+  // user_priv.
+  EXPECT_STREQ("b35a1b707b28e82be025d960aba039bc",
+               DecodeFile("vp90-2-03-size-226x226.webm").c_str());
+}
+
+#endif  // CONFIG_WEBM_IO
+
+}  // namespace