From patchwork Sun Feb 6 14:58:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Zhili X-Patchwork-Id: 34148 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2c4e:0:0:0:0 with SMTP id x14csp5059395iov; Sun, 6 Feb 2022 06:58:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJyTzYgMXTJOyWUIc0QVTPNEqEhEwiC+tmMQMkSZ41EmosJvgTnMKTBIHJD09dYAPcP8YPNb X-Received: by 2002:a17:906:7948:: with SMTP id l8mr6402899ejo.636.1644159537195; Sun, 06 Feb 2022 06:58:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644159537; cv=none; d=google.com; s=arc-20160816; b=XZOdP1BYVCbqWpfnBXhJ2Nkg+o05Hk5mb9QiSsVEaiHmZugGDYWIDxmquoB0cwiFUy hC2UgW9x4j2wiYZP8zzMtBTA50HpGjGWh9sEtI6yptuGb5NCglErmSCR2WksJIXSO9yW eNn9F9tZn9p1CrzJ6UKiEcu+Z+68QbhqbXXYsfPKvydVdkaepJuXUTiB6wisA1Oufzaf seGjECDvMDsZf+N8pcaUQGFY1IfaDB3x5EVHhvxf5iuCnGGxLWmThJ6znhwNob9VR+Bx lkg2SF+kJlumN6WsEucQVuIFwc6k2PisV7Op3/kCiO4Y8QcGElpvv5381PDxQl7dRs3L Qlnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:date:to:from:message-id :dkim-signature:delivered-to; bh=rSn0/2NV+8yQydN2UuqIlALB0SLQGauNumLxuRh7Qq4=; b=dqvxPGQ6OnZ9YQAFFqA0l7MLK3M40Y3k67VILMTqZT4/MMPdzfhzSPl2id7Sf+23rc /1uurl/5qejdL73fDuO+5vUfo1fDjQVstR5qGuzNz4JnqhJkIfd1cDuiwJgj1sTrChbf D9s3sH8hGqpO3WCRUREOvzuiQJ8dyAvOkxMGaR1T6uOVFWUTSGd87LyglXA2WjSLXHwK 9w3va6AFvZjsZOuxypdYaLw/1kjINlXsrYgoo16PLELiPLZo8+iQj2r1K4xGlkULsPe7 jqjtyZgTFEW3tkL1vtUSuxFtm7Rbb3JtaEUy0BGgT7wVV+FHbcTxxR2xgEVBX6uFwRwM 3jzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@foxmail.com header.s=s201512 header.b="OT9/iceV"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id cs18si5565966ejc.353.2022.02.06.06.58.56; Sun, 06 Feb 2022 06:58:57 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@foxmail.com header.s=s201512 header.b="OT9/iceV"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 22BF068B15C; Sun, 6 Feb 2022 16:58:51 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from out162-62-57-87.mail.qq.com (out162-62-57-87.mail.qq.com [162.62.57.87]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6745A68B0D1 for ; Sun, 6 Feb 2022 16:58:43 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1644159520; bh=QQWcG3sPbG5NJKqoXKAtgg9CjoypzBF02Li1a5JtQX0=; h=From:To:Cc:Subject:Date; b=OT9/iceVI9H71VIGwA8ToNh+eA1EzyhzfVazDPHHi/nSQMsTLR0MEjkWksb6UuMvv XK4XwTq75i/yot6h1WpaFYl7j4qv/HU7mqV5b3JeO+ssyFMX+PhU9JtVG8i34XDFDV ESdNEk22xIDvZfECFPs/1HKlqFi+YDNcgGWkWFHw= Received: from ZHILIZHAO-MB2.tencent.com ([119.123.134.169]) by newxmesmtplogicsvrszc11.qq.com (NewEsmtp) with SMTP id EA69541B; Sun, 06 Feb 2022 22:58:38 +0800 X-QQ-mid: xmsmtpt1644159518tbh30bcos Message-ID: X-QQ-XMAILINFO: MxtMpmMtaOnyISE4LYQW4MRt5988HoEpqzXoAnTJ85vK7o75JBG8FdJP7ks/Ox sI/T3vcPlUfZ9XJN0UpMKFimIPY9SWKpCOIw3pZ8TLSO0Zrx0GRTRbpiOQPyUcXUsUPyynTEe2El p8ysmL3Wy3mNSnbniK5QVzGqwi0AyGuUXUiPKh750tAebDXWi2rA/suQ9z3cUZCnkNJocFUPjqm3 M++OmxsS4Gt5rATgvRM7Gr7Rc0/d/zaGp/5Cf4Jw7xYOWhBX1cY/Q9cZzSB7eNbAq2aNqCnxJcSo 5kJqJfkad+Pvcxabo7m0iAKmzfchBgPAfHkbC+2DF/DAQn412GgZRac8SBq3JfPdp2AXlMc9K9E/ I9Mp9tsakheeLgLb9TeDKxyqOpsrhxqDUsutF8k/g0YTEGOYf6srfW56jSVut/grGH41z/VPthyt kNVpLZRlctYg/bK0mmCFZ9WqgwcyD3OvSvIHnXJEN0ak5tt268S5IWB8wcfMcx4qFDPVxKn2uvXF G+5v4aoovqJjlX4mi79hXOc3kcAwM2CHmGKrEaGaxq2u93hIEWG3H265/hF1YoOyV02Tnw4VIZkc TU4qtJmZLQI6X3fNWY3STTYvXe+QRvPrzlE8uGWtoLZbognq1xprH4khWCNbUhaQuNeTF77gpEFn NAOjj5+r63UDITNgG2pXZgmYx5ueyB0G6ZHH5ZEJMhU42sU7VMKRNpoXhyVLzDfOZ9FXhvOoGM9z /dzA2ChEhhbI4lUmymzj2El6QFgnexMTngodklcgZAgRun2jNPn//r7QcUrbOGHNFt7p3NbvHX1o IGKk4wJPRQqUbR+CiAf8eeG8U/RCjFMd7Jb4+GOGwMqPyPZ3R6g4XJN1TYMIzPtZQ= From: Zhao Zhili To: ffmpeg-devel@ffmpeg.org Date: Sun, 6 Feb 2022 22:58:36 +0800 X-OQ-MSGID: <20220206145836.65033-1-quinkblack@foxmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avcodec/h264dec: add option to ignore in band parameter set X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Zhao Zhili Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: BJAPRFKYVGf2 It works in three mode: 0: don't ignore in-band ps 1: ignore in-band ps -1: if corrupted data is detected, then ignore in-band ps afterwards h264dec working hard to do error resilience, it doesn't drop a whole packet when error is detected in a nalu. Then there is a higher chance for fake sps/pps be found and used. This happened in a mp4 file. h264dec failed to recovery after broken data due to the fake pps, while other H.264 decoders have no such problem. --- libavcodec/h264dec.c | 17 ++++++++++++++++- libavcodec/h264dec.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c index a47caa95e8..1ee2b68459 100644 --- a/libavcodec/h264dec.c +++ b/libavcodec/h264dec.c @@ -681,6 +681,10 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size) break; case H264_NAL_SPS: { GetBitContext tmp_gb = nal->gb; + if (h->ps.sps && h->ignore_in_band_ps == 1) { + av_log(h, AV_LOG_WARNING, "ignore in-band sps\n"); + break; + } if (avctx->hwaccel && avctx->hwaccel->decode_params) { ret = avctx->hwaccel->decode_params(avctx, nal->type, @@ -700,6 +704,10 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size) break; } case H264_NAL_PPS: + if (h->ps.pps && h->ignore_in_band_ps == 1) { + av_log(h, AV_LOG_WARNING, "ignore in-band pps\n"); + break; + } if (avctx->hwaccel && avctx->hwaccel->decode_params) { ret = avctx->hwaccel->decode_params(avctx, nal->type, @@ -726,6 +734,8 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size) } if (err < 0) { + if (h->ignore_in_band_ps == -1) + h->ignore_in_band_ps = 1; av_log(h->avctx, AV_LOG_ERROR, "decode_slice_header error\n"); } } @@ -1011,8 +1021,12 @@ static int h264_decode_frame(AVCodecContext *avctx, void *data, } buf_index = decode_nal_units(h, buf, buf_size); - if (buf_index < 0) + if (buf_index < 0) { + /* If there is corrupted data, then don't trust the in-band ps. */ + if (h->ignore_in_band_ps == -1) + h->ignore_in_band_ps = 1; return AVERROR_INVALIDDATA; + } if (!h->cur_pic_ptr && h->nal_unit_type == H264_NAL_END_SEQUENCE) { av_assert0(buf_index <= buf_size); @@ -1055,6 +1069,7 @@ static const AVOption h264_options[] = { { "nal_length_size", "nal_length_size", OFFSET(nal_length_size), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 4, VDX }, { "enable_er", "Enable error resilience on damaged frames (unsafe)", OFFSET(enable_er), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VD }, { "x264_build", "Assume this x264 version if no x264 version found in any SEI", OFFSET(x264_build), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VD }, + { "ignore_in_band_ps", "ignore in-band parameter set", OFFSET(ignore_in_band_ps), AV_OPT_TYPE_INT, {.i64 = 0}, -1, 1, VD }, { NULL }, }; diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h index 8168c8e97b..760540bc9d 100644 --- a/libavcodec/h264dec.h +++ b/libavcodec/h264dec.h @@ -448,6 +448,7 @@ typedef struct H264Context { int bit_depth_luma; ///< luma bit depth from sps to detect changes int chroma_format_idc; ///< chroma format from sps to detect changes + int ignore_in_band_ps; H264ParamSets ps; uint16_t *slice_table_base;