From patchwork Sun May 3 22:05:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 19463 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 05E2144B916 for ; Mon, 4 May 2020 01:06:10 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E284768C17B; Mon, 4 May 2020 01:06:09 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 775BB68C0DC for ; Mon, 4 May 2020 01:05:59 +0300 (EEST) Received: by mail-wr1-f65.google.com with SMTP id g13so18643193wrb.8 for ; Sun, 03 May 2020 15:05:59 -0700 (PDT) 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=Lz6JGR3L7Ce+PC0wCfGEcQg4tTAkGce4d0aPlG84GFw=; b=jQVSsCjpHLXxt+BIaDzEDSHQNbEFnFSz5AW7EJL1eLcsKeMJKA1YEajLiQv8LjX/I1 MOcttBnIQzgx64f6T2WsKG02BOk8DGbP7XUzsnxBFgFsyMf6/92Sx0kmJ4YGOeNudeqF eTbAEuf1TAtFpWbG0g7MF6UU8RdoMXjmCXq59expiTJyFwSMNzx4lcb8dmDQ+Wc/mZeV d/M5zRYUGO5xI4urHmBBTQ7n5q3zLt937nGT2d6fsVdbfjPywL/73GM23WHktlfsHfO4 ooB33dsPJYiq40fTX0E/ILcaHw4EXnV5FS5IolndveP1o16NnbQr320SqbKYYqYd2Xiv DCbg== 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=Lz6JGR3L7Ce+PC0wCfGEcQg4tTAkGce4d0aPlG84GFw=; b=a6Qyx2wgXSsdi3NnQTDHPF3xWp/PH1mZtA5Eg+R2RmoFQ8BLXEzw50HrwIdJ15jQX9 nsJ8CYGCazCTp/yT8Y6HFDM/UwxaTaH7N1OIT4S/E4nl/kv4w6wofmzTnGPBLMqElLqr k/yXg4rMDN5ZtDXfAv6yGTJukVbCZc9U8mVdaDANT1h4r81B8rDru50pRBrJfYinV7mU YyHk6Gyk13YRykEbLFt+f13UNz8ry1+LuQLL6itHaS3MsD3RQKLFZUk/4OY3fOCnaILW Oi4PjVwo7pP57j+JOM+6k4i8snnhyAFyjDXbC//yS40LiFhRIx4/pPNMmqLF9gyGRGSQ Hawg== X-Gm-Message-State: AGi0PuavlTDjRL1dx3v3QKA1oIYpaaVl3pLthZDQ6O4DW4AnOJye7mvZ uC+zggWAyacsaxDVukl9KMqSstpA2bg= X-Google-Smtp-Source: APiQypLz/YYrXwxT9qoMmiQnRHd2yFGC7Thb7oT/B0xO295Cm4dps9WknvCanBKFaD4Qfo8/bAFmqQ== X-Received: by 2002:adf:df82:: with SMTP id z2mr17093724wrl.58.1588543558668; Sun, 03 May 2020 15:05:58 -0700 (PDT) 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 a24sm10307285wmb.24.2020.05.03.15.05.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 May 2020 15:05:58 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Sun, 3 May 2020 23:05:34 +0100 Message-Id: <20200503220548.23543-8-sw@jkqxz.net> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200503220548.23543-1-sw@jkqxz.net> References: <20200503220548.23543-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 08/22] 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. Fixes #7807. 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; }