ref: 8c82bda0b816b59c3caad5e0d814d3e519f6b39b
parent: bc7c99e7eca8d30d005e7d5db8b0aada2459fb15
author: Jerome Jiang <[email protected]>
date: Mon Jul 16 13:47:44 EDT 2018
vp9: release frame buffer on key frame. Add tests with corrupted frames and periodic key frames. BUG=webm:1545 Change-Id: Ic0684bdafd01507036f56465387b9d2187b1458e
--- /dev/null
+++ b/test/decode_corrupted.cc
@@ -1,0 +1,101 @@
+/*
+ * Copyright (c) 2018 The WebM project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "third_party/googletest/src/include/gtest/gtest.h"
+
+#include "test/codec_factory.h"
+#include "test/encode_test_driver.h"
+#include "test/util.h"
+#include "test/i420_video_source.h"
+#include "vpx_mem/vpx_mem.h"
+
+namespace {
+
+class DecodeCorruptedFrameTest
+ : public ::libvpx_test::EncoderTest,
+ public ::testing::TestWithParam<
+ ::testing::tuple<const libvpx_test::CodecFactory *> > {
+ public:
+ DecodeCorruptedFrameTest() : EncoderTest(GET_PARAM(0)) {}
+
+ protected:
+ virtual ~DecodeCorruptedFrameTest() {}
+
+ virtual void SetUp() {
+ InitializeConfig();
+ SetMode(::libvpx_test::kRealTime);
+ cfg_.g_lag_in_frames = 0;
+ cfg_.rc_end_usage = VPX_CBR;
+ cfg_.rc_buf_sz = 1000;
+ cfg_.rc_buf_initial_sz = 500;
+ cfg_.rc_buf_optimal_sz = 600;
+
+ // Set small key frame distance such that we insert more key frames.
+ cfg_.kf_max_dist = 3;
+ dec_cfg_.threads = 1;
+ }
+
+ virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
+ ::libvpx_test::Encoder *encoder) {
+ if (video->frame() == 0) encoder->Control(VP8E_SET_CPUUSED, 7);
+ }
+
+ virtual void MismatchHook(const vpx_image_t * /*img1*/,
+ const vpx_image_t * /*img2*/) {}
+
+ virtual const vpx_codec_cx_pkt_t *MutateEncoderOutputHook(
+ const vpx_codec_cx_pkt_t *pkt) {
+ // Don't edit frame packet on key frame.
+ if (pkt->data.frame.flags & VPX_FRAME_IS_KEY) return pkt;
+ if (pkt->kind != VPX_CODEC_CX_FRAME_PKT) return pkt;
+
+ memcpy(&modified_pkt_, pkt, sizeof(*pkt));
+
+ // Halve the size so it's corrupted to decoder.
+ modified_pkt_.data.frame.sz = modified_pkt_.data.frame.sz / 2;
+
+ return &modified_pkt_;
+ }
+
+ virtual bool HandleDecodeResult(const vpx_codec_err_t res_dec,
+ const libvpx_test::VideoSource & /*video*/,
+ libvpx_test::Decoder *decoder) {
+ EXPECT_NE(res_dec, VPX_CODEC_MEM_ERROR) << decoder->DecodeError();
+ return VPX_CODEC_MEM_ERROR != res_dec;
+ }
+
+ vpx_codec_cx_pkt_t modified_pkt_;
+};
+
+TEST_P(DecodeCorruptedFrameTest, DecodeCorruptedFrame) {
+ cfg_.rc_target_bitrate = 200;
+ cfg_.g_error_resilient = 0;
+
+ ::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
+ 30, 1, 0, 300);
+
+ ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
+}
+
+#if CONFIG_VP9
+INSTANTIATE_TEST_CASE_P(
+ VP9, DecodeCorruptedFrameTest,
+ ::testing::Values(
+ static_cast<const libvpx_test::CodecFactory *>(&libvpx_test::kVP9)));
+#endif // CONFIG_VP9
+
+#if CONFIG_VP8
+INSTANTIATE_TEST_CASE_P(
+ VP8, DecodeCorruptedFrameTest,
+ ::testing::Values(
+ static_cast<const libvpx_test::CodecFactory *>(&libvpx_test::kVP8)));
+#endif // CONFIG_VP8
+
+} // namespace
--- a/test/test.mk
+++ b/test/test.mk
@@ -53,6 +53,7 @@
LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += frame_size_tests.cc
LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += vp9_lossless_test.cc
LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += vp9_end_to_end_test.cc
+LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += decode_corrupted.cc
LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += vp9_ethread_test.cc
LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += vp9_motion_vector_test.cc
LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += level_test.cc
--- a/vp9/decoder/vp9_decodeframe.c
+++ b/vp9/decoder/vp9_decodeframe.c
@@ -1730,6 +1730,21 @@
}
}
+static INLINE void flush_all_fb_on_key(VP9_COMMON *cm) {
+ if (cm->frame_type == KEY_FRAME && cm->current_video_frame > 0) {
+ RefCntBuffer *const frame_bufs = cm->buffer_pool->frame_bufs;
+ BufferPool *const pool = cm->buffer_pool;
+ int i;
+ for (i = 0; i < FRAME_BUFFERS; ++i) {
+ frame_bufs[i].ref_count = 0;
+ if (!frame_bufs[i].released) {
+ pool->release_fb_cb(pool->cb_priv, &frame_bufs[i].raw_frame_buffer);
+ frame_bufs[i].released = 1;
+ }
+ }
+ }
+}
+
static size_t read_uncompressed_header(VP9Decoder *pbi,
struct vpx_read_bit_buffer *rb) {
VP9_COMMON *const cm = &pbi->common;
@@ -1794,6 +1809,7 @@
setup_frame_size(cm, rb);
if (pbi->need_resync) {
memset(&cm->ref_frame_map, -1, sizeof(cm->ref_frame_map));
+ flush_all_fb_on_key(cm);
pbi->need_resync = 0;
}
} else {