superframe_test.cc 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (c) 2012 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 <tuple>
  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. const int kTestMode = 0;
  19. typedef std::tuple<libvpx_test::TestMode, int> SuperframeTestParam;
  20. class SuperframeTest
  21. : public ::libvpx_test::EncoderTest,
  22. public ::libvpx_test::CodecTestWithParam<SuperframeTestParam> {
  23. protected:
  24. SuperframeTest()
  25. : EncoderTest(GET_PARAM(0)), modified_buf_(NULL), last_sf_pts_(0) {}
  26. virtual ~SuperframeTest() {}
  27. virtual void SetUp() {
  28. InitializeConfig();
  29. const SuperframeTestParam input = GET_PARAM(1);
  30. const libvpx_test::TestMode mode = std::get<kTestMode>(input);
  31. SetMode(mode);
  32. sf_count_ = 0;
  33. sf_count_max_ = INT_MAX;
  34. }
  35. virtual void TearDown() { delete[] modified_buf_; }
  36. virtual void PreEncodeFrameHook(libvpx_test::VideoSource *video,
  37. libvpx_test::Encoder *encoder) {
  38. if (video->frame() == 0) {
  39. encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1);
  40. }
  41. }
  42. virtual const vpx_codec_cx_pkt_t *MutateEncoderOutputHook(
  43. const vpx_codec_cx_pkt_t *pkt) {
  44. if (pkt->kind != VPX_CODEC_CX_FRAME_PKT) return pkt;
  45. const uint8_t *buffer = reinterpret_cast<uint8_t *>(pkt->data.frame.buf);
  46. const uint8_t marker = buffer[pkt->data.frame.sz - 1];
  47. const int frames = (marker & 0x7) + 1;
  48. const int mag = ((marker >> 3) & 3) + 1;
  49. const unsigned int index_sz = 2 + mag * frames;
  50. if ((marker & 0xe0) == 0xc0 && pkt->data.frame.sz >= index_sz &&
  51. buffer[pkt->data.frame.sz - index_sz] == marker) {
  52. // frame is a superframe. strip off the index.
  53. if (modified_buf_) delete[] modified_buf_;
  54. modified_buf_ = new uint8_t[pkt->data.frame.sz - index_sz];
  55. memcpy(modified_buf_, pkt->data.frame.buf, pkt->data.frame.sz - index_sz);
  56. modified_pkt_ = *pkt;
  57. modified_pkt_.data.frame.buf = modified_buf_;
  58. modified_pkt_.data.frame.sz -= index_sz;
  59. sf_count_++;
  60. last_sf_pts_ = pkt->data.frame.pts;
  61. return &modified_pkt_;
  62. }
  63. // Make sure we do a few frames after the last SF
  64. abort_ |=
  65. sf_count_ > sf_count_max_ && pkt->data.frame.pts - last_sf_pts_ >= 5;
  66. return pkt;
  67. }
  68. int sf_count_;
  69. int sf_count_max_;
  70. vpx_codec_cx_pkt_t modified_pkt_;
  71. uint8_t *modified_buf_;
  72. vpx_codec_pts_t last_sf_pts_;
  73. };
  74. TEST_P(SuperframeTest, TestSuperframeIndexIsOptional) {
  75. sf_count_max_ = 0; // early exit on successful test.
  76. cfg_.g_lag_in_frames = 25;
  77. ::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
  78. 30, 1, 0, 40);
  79. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  80. EXPECT_EQ(sf_count_, 1);
  81. }
  82. VP9_INSTANTIATE_TEST_CASE(
  83. SuperframeTest,
  84. ::testing::Combine(::testing::Values(::libvpx_test::kTwoPassGood),
  85. ::testing::Values(0)));
  86. } // namespace