superframe_test.cc 3.3 KB

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