user_priv_test.cc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. #include <cstdio>
  11. #include <cstdlib>
  12. #include <string>
  13. #include "third_party/googletest/src/include/gtest/gtest.h"
  14. #include "./vpx_config.h"
  15. #include "test/acm_random.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. #include "vpx/vp8.h"
  26. namespace {
  27. using libvpx_test::ACMRandom;
  28. using std::string;
  29. #if CONFIG_WEBM_IO
  30. void CheckUserPrivateData(void *user_priv, int *target) {
  31. // actual pointer value should be the same as expected.
  32. EXPECT_EQ(reinterpret_cast<void *>(target), user_priv)
  33. << "user_priv pointer value does not match.";
  34. }
  35. // Decodes |filename|. Passes in user_priv data when calling DecodeFrame and
  36. // compares the user_priv from return img with the original user_priv to see if
  37. // they match. Both the pointer values and the values inside the addresses
  38. // should match.
  39. string DecodeFile(const string &filename) {
  40. ACMRandom rnd(ACMRandom::DeterministicSeed());
  41. libvpx_test::WebMVideoSource video(filename);
  42. video.Init();
  43. vpx_codec_dec_cfg_t cfg = vpx_codec_dec_cfg_t();
  44. libvpx_test::VP9Decoder decoder(cfg, 0);
  45. libvpx_test::MD5 md5;
  46. int frame_num = 0;
  47. for (video.Begin(); !::testing::Test::HasFailure() && video.cxdata();
  48. video.Next()) {
  49. void *user_priv = reinterpret_cast<void *>(&frame_num);
  50. const vpx_codec_err_t res =
  51. decoder.DecodeFrame(video.cxdata(), video.frame_size(),
  52. (frame_num == 0) ? NULL : user_priv);
  53. if (res != VPX_CODEC_OK) {
  54. EXPECT_EQ(VPX_CODEC_OK, res) << decoder.DecodeError();
  55. break;
  56. }
  57. libvpx_test::DxDataIterator dec_iter = decoder.GetDxData();
  58. const vpx_image_t *img = NULL;
  59. // Get decompressed data.
  60. while ((img = dec_iter.Next())) {
  61. if (frame_num == 0) {
  62. CheckUserPrivateData(img->user_priv, NULL);
  63. } else {
  64. CheckUserPrivateData(img->user_priv, &frame_num);
  65. // Also test ctrl_get_reference api.
  66. struct vp9_ref_frame ref = vp9_ref_frame();
  67. // Randomly fetch a reference frame.
  68. ref.idx = rnd.Rand8() % 3;
  69. decoder.Control(VP9_GET_REFERENCE, &ref);
  70. CheckUserPrivateData(ref.img.user_priv, NULL);
  71. }
  72. md5.Add(img);
  73. }
  74. frame_num++;
  75. }
  76. return string(md5.Get());
  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. #endif // CONFIG_WEBM_IO
  85. } // namespace