active_map_test.cc 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright (c) 2014 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 <climits>
  11. #include <vector>
  12. #include "third_party/googletest/src/include/gtest/gtest.h"
  13. #include "test/codec_factory.h"
  14. #include "test/encode_test_driver.h"
  15. #include "test/i420_video_source.h"
  16. #include "test/util.h"
  17. namespace {
  18. class ActiveMapTest
  19. : public ::libvpx_test::EncoderTest,
  20. public ::libvpx_test::CodecTestWith2Params<libvpx_test::TestMode, int> {
  21. protected:
  22. static const int kWidth = 208;
  23. static const int kHeight = 144;
  24. ActiveMapTest() : EncoderTest(GET_PARAM(0)) {}
  25. virtual ~ActiveMapTest() {}
  26. virtual void SetUp() {
  27. InitializeConfig();
  28. SetMode(GET_PARAM(1));
  29. cpu_used_ = GET_PARAM(2);
  30. }
  31. virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
  32. ::libvpx_test::Encoder *encoder) {
  33. if (video->frame() == 0) {
  34. encoder->Control(VP8E_SET_CPUUSED, cpu_used_);
  35. } else if (video->frame() == 3) {
  36. vpx_active_map_t map = vpx_active_map_t();
  37. /* clang-format off */
  38. uint8_t active_map[9 * 13] = {
  39. 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0,
  40. 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0,
  41. 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0,
  42. 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0,
  43. 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1,
  44. 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1,
  45. 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1,
  46. 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1,
  47. 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0,
  48. };
  49. /* clang-format on */
  50. map.cols = (kWidth + 15) / 16;
  51. map.rows = (kHeight + 15) / 16;
  52. ASSERT_EQ(map.cols, 13u);
  53. ASSERT_EQ(map.rows, 9u);
  54. map.active_map = active_map;
  55. encoder->Control(VP8E_SET_ACTIVEMAP, &map);
  56. } else if (video->frame() == 15) {
  57. vpx_active_map_t map = vpx_active_map_t();
  58. map.cols = (kWidth + 15) / 16;
  59. map.rows = (kHeight + 15) / 16;
  60. map.active_map = NULL;
  61. encoder->Control(VP8E_SET_ACTIVEMAP, &map);
  62. }
  63. }
  64. int cpu_used_;
  65. };
  66. TEST_P(ActiveMapTest, Test) {
  67. // Validate that this non multiple of 64 wide clip encodes
  68. cfg_.g_lag_in_frames = 0;
  69. cfg_.rc_target_bitrate = 400;
  70. cfg_.rc_resize_allowed = 0;
  71. cfg_.g_pass = VPX_RC_ONE_PASS;
  72. cfg_.rc_end_usage = VPX_CBR;
  73. cfg_.kf_max_dist = 90000;
  74. ::libvpx_test::I420VideoSource video("hantro_odd.yuv", kWidth, kHeight, 30, 1,
  75. 0, 20);
  76. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  77. }
  78. VP9_INSTANTIATE_TEST_CASE(ActiveMapTest,
  79. ::testing::Values(::libvpx_test::kRealTime),
  80. ::testing::Range(0, 9));
  81. } // namespace