vp9[loongarch]: Optimize fdct4x4/8x8_lsx
[platform/upstream/libvpx.git] / test / decode_corrupted.cc
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
11 #include <tuple>
12
13 #include "third_party/googletest/src/include/gtest/gtest.h"
14
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"
20
21 namespace {
22
23 class DecodeCorruptedFrameTest
24     : public ::libvpx_test::EncoderTest,
25       public ::testing::TestWithParam<
26           std::tuple<const libvpx_test::CodecFactory *> > {
27  public:
28   DecodeCorruptedFrameTest() : EncoderTest(GET_PARAM(0)) {}
29
30  protected:
31   virtual ~DecodeCorruptedFrameTest() {}
32
33   virtual void SetUp() {
34     InitializeConfig();
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;
41
42     // Set small key frame distance such that we insert more key frames.
43     cfg_.kf_max_dist = 3;
44     dec_cfg_.threads = 1;
45   }
46
47   virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
48                                   ::libvpx_test::Encoder *encoder) {
49     if (video->frame() == 0) encoder->Control(VP8E_SET_CPUUSED, 7);
50   }
51
52   virtual void MismatchHook(const vpx_image_t * /*img1*/,
53                             const vpx_image_t * /*img2*/) {}
54
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;
60
61     memcpy(&modified_pkt_, pkt, sizeof(*pkt));
62
63     // Halve the size so it's corrupted to decoder.
64     modified_pkt_.data.frame.sz = modified_pkt_.data.frame.sz / 2;
65
66     return &modified_pkt_;
67   }
68
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;
74   }
75
76   vpx_codec_cx_pkt_t modified_pkt_;
77 };
78
79 TEST_P(DecodeCorruptedFrameTest, DecodeCorruptedFrame) {
80   cfg_.rc_target_bitrate = 200;
81   cfg_.g_error_resilient = 0;
82
83   ::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
84                                        30, 1, 0, 300);
85
86   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
87 }
88
89 #if CONFIG_VP9
90 INSTANTIATE_TEST_SUITE_P(
91     VP9, DecodeCorruptedFrameTest,
92     ::testing::Values(
93         static_cast<const libvpx_test::CodecFactory *>(&libvpx_test::kVP9)));
94 #endif  // CONFIG_VP9
95
96 #if CONFIG_VP8
97 INSTANTIATE_TEST_SUITE_P(
98     VP8, DecodeCorruptedFrameTest,
99     ::testing::Values(
100         static_cast<const libvpx_test::CodecFactory *>(&libvpx_test::kVP8)));
101 #endif  // CONFIG_VP8
102
103 }  // namespace