2 * Copyright (c) 2018 The WebM project authors. All Rights Reserved.
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.
13 #include "third_party/googletest/src/include/gtest/gtest.h"
15 #include "test/codec_factory.h"
16 #include "test/encode_test_driver.h"
17 #include "test/util.h"
18 #include "test/i420_video_source.h"
19 #include "vpx_mem/vpx_mem.h"
23 class DecodeCorruptedFrameTest
24 : public ::libvpx_test::EncoderTest,
25 public ::testing::TestWithParam<
26 std::tuple<const libvpx_test::CodecFactory *> > {
28 DecodeCorruptedFrameTest() : EncoderTest(GET_PARAM(0)) {}
31 virtual ~DecodeCorruptedFrameTest() {}
33 virtual void SetUp() {
35 SetMode(::libvpx_test::kRealTime);
36 cfg_.g_lag_in_frames = 0;
37 cfg_.rc_end_usage = VPX_CBR;
38 cfg_.rc_buf_sz = 1000;
39 cfg_.rc_buf_initial_sz = 500;
40 cfg_.rc_buf_optimal_sz = 600;
42 // Set small key frame distance such that we insert more key frames.
47 virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
48 ::libvpx_test::Encoder *encoder) {
49 if (video->frame() == 0) encoder->Control(VP8E_SET_CPUUSED, 7);
52 virtual void MismatchHook(const vpx_image_t * /*img1*/,
53 const vpx_image_t * /*img2*/) {}
55 virtual const vpx_codec_cx_pkt_t *MutateEncoderOutputHook(
56 const vpx_codec_cx_pkt_t *pkt) {
57 // Don't edit frame packet on key frame.
58 if (pkt->data.frame.flags & VPX_FRAME_IS_KEY) return pkt;
59 if (pkt->kind != VPX_CODEC_CX_FRAME_PKT) return pkt;
61 memcpy(&modified_pkt_, pkt, sizeof(*pkt));
63 // Halve the size so it's corrupted to decoder.
64 modified_pkt_.data.frame.sz = modified_pkt_.data.frame.sz / 2;
66 return &modified_pkt_;
69 virtual bool HandleDecodeResult(const vpx_codec_err_t res_dec,
70 const libvpx_test::VideoSource & /*video*/,
71 libvpx_test::Decoder *decoder) {
72 EXPECT_NE(res_dec, VPX_CODEC_MEM_ERROR) << decoder->DecodeError();
73 return VPX_CODEC_MEM_ERROR != res_dec;
76 vpx_codec_cx_pkt_t modified_pkt_;
79 TEST_P(DecodeCorruptedFrameTest, DecodeCorruptedFrame) {
80 cfg_.rc_target_bitrate = 200;
81 cfg_.g_error_resilient = 0;
83 ::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
86 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
90 INSTANTIATE_TEST_SUITE_P(
91 VP9, DecodeCorruptedFrameTest,
93 static_cast<const libvpx_test::CodecFactory *>(&libvpx_test::kVP9)));
97 INSTANTIATE_TEST_SUITE_P(
98 VP8, DecodeCorruptedFrameTest,
100 static_cast<const libvpx_test::CodecFactory *>(&libvpx_test::kVP8)));