From patchwork Sun Feb 23 23:41:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 17890 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 528E544A08D for ; Mon, 24 Feb 2020 01:49:29 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3D9BC68B52C; Mon, 24 Feb 2020 01:49:29 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4D45468B502 for ; Mon, 24 Feb 2020 01:49:23 +0200 (EET) Received: by mail-wm1-f65.google.com with SMTP id s10so7223823wmh.3 for ; Sun, 23 Feb 2020 15:49:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jkqxz-net.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=+iadSbpoe7rWMQHRauxkCwBQ6SYyQU9zNDNe/7/NSUU=; b=oA6bvOgj38QFGRH694vSyZksmugDTejuwzlgcaCL/PoQMjYjcbVAfy4WgNVFePVeDd KHnap/GCXJvN9uJrnv5c5jBiVyUzscCmlXbVcfjVYIMh+YI2htKuZ3KRiEEFh2IMj8Q0 FiKCDaZnp2u5+qmZg0Nb+D2ZUATx4DKOpTB6rGoDohjRVggUVr/Y4F7aF2PhpQSTpWsQ tllZM7Upk8gCZm9G/WPXktmz252rkNzZJ6WLxxZUpuScILDwhL/Z17pW9FnvCkUQUgHQ FN3BUmkJTIPp/kY4shVTk7TufKXjob2Wc/OW52d99o3rWFlf4KK860/ofXVj+Zqpt2VY KumA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+iadSbpoe7rWMQHRauxkCwBQ6SYyQU9zNDNe/7/NSUU=; b=BbrGr5j4TCJNfuYzHB+HGd4AlZMA4c01VZWKRUvITLL8d3AL05mejPnHW3c1xuqy/H Vg/ahBrFtB2jAjmhdlBSYpSrpOnLDd9QcoDjK6YgbxCCzfjy99iES7T4tGAffR52SY/z PLsm5eIVa/hi+vbxK539x+ezOd3QOVvFTUo/YWZyiTkLkns9mg/kA0pDw8DUi2kTnGUV b9h0AI2r3z6jign0I948Z+vV63g2YrxIMfjpFbIZUS300CIi1rbyhdj25zcSKc1MyIOm njkPXaawi9PmDO/O1Zyabr5ef94erPtkYK4WsOzYDOJjg8J0tPvqAn4AEeINBUS5TIA5 Wzqw== X-Gm-Message-State: APjAAAVQ36rZ6xDJsuaT6QAQ+0yod8M4wZqihN3FrwCGv3WF2POPB6T1 CSWcp9bXEhnjkvFHybJSOs08BPuZFPM= X-Google-Smtp-Source: APXvYqwyXsN833kpzxJhYTK9R5VDmuWQ/yPDspKd5BKq1CKp7i/J2V/WY7qDfk6wUsLBC+JI0GGb1A== X-Received: by 2002:a1c:6408:: with SMTP id y8mr18094238wmb.130.1582501300583; Sun, 23 Feb 2020 15:41:40 -0800 (PST) Received: from rywe.jkqxz.net (cpc91242-cmbg18-2-0-cust650.5-4.cable.virginm.net. [82.8.130.139]) by smtp.gmail.com with ESMTPSA id y131sm16358070wmc.13.2020.02.23.15.41.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Feb 2020 15:41:40 -0800 (PST) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Sun, 23 Feb 2020 23:41:11 +0000 Message-Id: <20200223234124.17689-8-sw@jkqxz.net> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200223234124.17689-1-sw@jkqxz.net> References: <20200223234124.17689-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 08/21] h264_redundant_pps: Make it reference-compatible X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Andreas Rheinhardt Since c6a63e11092c975b89d824f08682fe31948d3686, the parameter sets modified as content of PPS units were references shared with the CodedBitstreamH264Context, so modifying them alters the parsing process of future access units which meant that frames often got discarded because invalid values were parsed. This patch makes h264_redundant_pps compatible with the reality of reference-counted parameter sets. Signed-off-by: Andreas Rheinhardt Signed-off-by: Mark Thompson --- libavcodec/h264_redundant_pps_bsf.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/libavcodec/h264_redundant_pps_bsf.c b/libavcodec/h264_redundant_pps_bsf.c index 8405738c4b..4d5dd9a90f 100644 --- a/libavcodec/h264_redundant_pps_bsf.c +++ b/libavcodec/h264_redundant_pps_bsf.c @@ -40,8 +40,19 @@ typedef struct H264RedundantPPSContext { static int h264_redundant_pps_fixup_pps(H264RedundantPPSContext *ctx, - H264RawPPS *pps) + CodedBitstreamUnit *unit) { + H264RawPPS *pps; + int err; + + // The changes we are about to perform affect the parsing process, + // so we must make sure that the PPS is writable, otherwise the + // parsing of future slices will be incorrect and even raise errors. + err = ff_cbs_make_unit_writable(ctx->input, unit); + if (err < 0) + return err; + pps = unit->content; + // Record the current value of pic_init_qp in order to fix up // following slices, then overwrite with the global value. ctx->current_pic_init_qp = pps->pic_init_qp_minus26 + 26; @@ -88,7 +99,7 @@ static int h264_redundant_pps_filter(AVBSFContext *bsf, AVPacket *pkt) if (nal->type == H264_NAL_SPS) au_has_sps = 1; if (nal->type == H264_NAL_PPS) { - err = h264_redundant_pps_fixup_pps(ctx, nal->content); + err = h264_redundant_pps_fixup_pps(ctx, nal); if (err < 0) goto fail; if (!au_has_sps) { @@ -144,7 +155,7 @@ static int h264_redundant_pps_init(AVBSFContext *bsf) for (i = 0; i < au->nb_units; i++) { if (au->units[i].type == H264_NAL_PPS) { - err = h264_redundant_pps_fixup_pps(ctx, au->units[i].content); + err = h264_redundant_pps_fixup_pps(ctx, &au->units[i]); if (err < 0) goto fail; }