decode_corrupted.cc 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (c) 2018 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 <tuple>
  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/util.h"
  15. #include "test/i420_video_source.h"
  16. #include "vpx_mem/vpx_mem.h"
  17. namespace {
  18. class DecodeCorruptedFrameTest
  19. : public ::libvpx_test::EncoderTest,
  20. public ::testing::TestWithParam<
  21. std::tuple<const libvpx_test::CodecFactory *> > {
  22. public:
  23. DecodeCorruptedFrameTest() : EncoderTest(GET_PARAM(0)) {}
  24. protected:
  25. virtual ~DecodeCorruptedFrameTest() {}
  26. virtual void SetUp() {
  27. InitializeConfig();
  28. SetMode(::libvpx_test::kRealTime);
  29. cfg_.g_lag_in_frames = 0;
  30. cfg_.rc_end_usage = VPX_CBR;
  31. cfg_.rc_buf_sz = 1000;
  32. cfg_.rc_buf_initial_sz = 500;
  33. cfg_.rc_buf_optimal_sz = 600;
  34. // Set small key frame distance such that we insert more key frames.
  35. cfg_.kf_max_dist = 3;
  36. dec_cfg_.threads = 1;
  37. }
  38. virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
  39. ::libvpx_test::Encoder *encoder) {
  40. if (video->frame() == 0) encoder->Control(VP8E_SET_CPUUSED, 7);
  41. }
  42. virtual void MismatchHook(const vpx_image_t * /*img1*/,
  43. const vpx_image_t * /*img2*/) {}
  44. virtual const vpx_codec_cx_pkt_t *MutateEncoderOutputHook(
  45. const vpx_codec_cx_pkt_t *pkt) {
  46. // Don't edit frame packet on key frame.
  47. if (pkt->data.frame.flags & VPX_FRAME_IS_KEY) return pkt;
  48. if (pkt->kind != VPX_CODEC_CX_FRAME_PKT) return pkt;
  49. memcpy(&modified_pkt_, pkt, sizeof(*pkt));
  50. // Halve the size so it's corrupted to decoder.
  51. modified_pkt_.data.frame.sz = modified_pkt_.data.frame.sz / 2;
  52. return &modified_pkt_;
  53. }
  54. virtual bool HandleDecodeResult(const vpx_codec_err_t res_dec,
  55. const libvpx_test::VideoSource & /*video*/,
  56. libvpx_test::Decoder *decoder) {
  57. EXPECT_NE(res_dec, VPX_CODEC_MEM_ERROR) << decoder->DecodeError();
  58. return VPX_CODEC_MEM_ERROR != res_dec;
  59. }
  60. vpx_codec_cx_pkt_t modified_pkt_;
  61. };
  62. TEST_P(DecodeCorruptedFrameTest, DecodeCorruptedFrame) {
  63. cfg_.rc_target_bitrate = 200;
  64. cfg_.g_error_resilient = 0;
  65. ::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
  66. 30, 1, 0, 300);
  67. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  68. }
  69. #if CONFIG_VP9
  70. INSTANTIATE_TEST_CASE_P(
  71. VP9, DecodeCorruptedFrameTest,
  72. ::testing::Values(
  73. static_cast<const libvpx_test::CodecFactory *>(&libvpx_test::kVP9)));
  74. #endif // CONFIG_VP9
  75. #if CONFIG_VP8
  76. INSTANTIATE_TEST_CASE_P(
  77. VP8, DecodeCorruptedFrameTest,
  78. ::testing::Values(
  79. static_cast<const libvpx_test::CodecFactory *>(&libvpx_test::kVP8)));
  80. #endif // CONFIG_VP8
  81. } // namespace