From patchwork Mon Jul 27 16:32:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 21330 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:80ca:0:0:0:0:0 with SMTP id c10csp4278476ybm; Mon, 27 Jul 2020 09:35:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8zfa5kPYIUYXuiFlEpz+kW+bOgUNo5AqFNtPlUNfAKCcbhTC52KxkeBqj8JuAcuTfB0hL X-Received: by 2002:a05:6000:1141:: with SMTP id d1mr22932528wrx.229.1595867704397; Mon, 27 Jul 2020 09:35:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595867704; cv=none; d=google.com; s=arc-20160816; b=Cz6NTKWe6761UUy86aBsyiouRbYmezfCU2AecBueyvmFqNrFBg08CEziIyhSRn3RhT iE5Pvmgc+mitk+M2Yr8PgPjvMbEqyItX7ZUcGLdR2xr9J+nWwRFe2EZeq3127smWQFtx Ox/IWEFMIEeXr2XPJG/DWYtsKcUQRNW72pwGDkMhxPuL5xq182aGZi+Iq6/bDd+acmjU gEBYlHfC40zdiWp5z70jSX7GAnDHCbxSEomYxSn+1aL1kzkBl3461+b8rAHZfPuvuv7U aLxyNqyCf1ymyNZebyLn9m+swmF/AW4b+zBgNra4T8je2+Rbp5KozF/fIiA1H+sTV3Vr Ej9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=16Z5Eydx7wWDpxIOFSLv9kL+YhiSAXdv8pebvXB+bFs=; b=vUAoPRmSIo6OASodkEaLWSLMWZ8lDmjihVuaiCW+8p3bAgICvsnIO0duoMnfjeR4fg 4KUn3VVWf4wDHRZNw6A6UXH71HrBzceIlo7RcPILzhJnJ+q65Pg41HLyT24rRYZNAr6K 7JjjduyKlYEKvawH74VAGIgnroWE8MadxB8trt0KpTVWt58wf+aGwDw5QSnb6lN5hkBF rWTX938gGRTB0JEKVPocCp4jPKc6EMIvHLDUPiAQefsVacWbmEFMWESlXot3xGirIYis M5AU/uKgga0aJbVScFN9krHwJwxy47JH/uFWmxeue6olcNsarmfSLaQZ6DxI4+VwQ2Jl UBZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@jkqxz-net.20150623.gappssmtp.com header.s=20150623 header.b=tfdVv5bJ; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 135si89233wmb.151.2020.07.27.09.35.04; Mon, 27 Jul 2020 09:35:04 -0700 (PDT) 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=@jkqxz-net.20150623.gappssmtp.com header.s=20150623 header.b=tfdVv5bJ; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 668CE68B930; Mon, 27 Jul 2020 19:33:05 +0300 (EEST) 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 3477B68B8FD for ; Mon, 27 Jul 2020 19:32:52 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id f18so15414507wml.3 for ; Mon, 27 Jul 2020 09:32:52 -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=XoB4QgSwCSAsg7+MsbgcxbxzrrA71UXNqI+b5edn9Rs=; b=tfdVv5bJ3m1xkeIQroNnkQSbWv29wxB/EtV/XlEpMgoP9hVWFXnGtr9z3py0/TyMsc uK/4v5C4mjN8ERs3e5W5Bx1WS9oVcVu+eYob8KfyK+Wg4OWnaHO6nSNmJlqnygb/HVAq W6PnMrEBnyakkynlbOOOvjCffFWHZ4V7MiK2ZQaG1pYS+J5BAMo4PtaS3n3J2Q0Jupvr Pv5qjO+Ir4P+8YNMHLJcOwzN7DSufCYPo/Jahw74km1YKvaxFsDjgBzxfMo/LREqFeU0 YDCyFTX59zzudRDujzrjRdofcqi7sdKq0ksgZkv4JCAcy+RLTTIyAS3HCgGAGq2BcM/5 om2g== 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=XoB4QgSwCSAsg7+MsbgcxbxzrrA71UXNqI+b5edn9Rs=; b=GlOcohpY2P0NZadC7LqxOgQUtzPStUpEXwpwfNKfHzuAfmzmPvF+7pvc0OICggt6lB tMAnQ+YKvtmyuOY1+RUC4f0coDlqpxpa42YvMquQi6dWyo6wFWcRBQHWCoy6I5tcgV7l aOD8EYFIyZavL8M+OMVzL38Ca/gTpr/qKxr8uGww8+eEcUgg7wx5tYhPVIlidhPHBN5p 234of+dxQIaRkReOUsoftA4D5hZyJ5boiHWrXTtiXCNP7jyOxTzlqoWXsqVbmsf4S7z7 WcDMAEIQejcUGSXiai2/dWUz5BbReuXOztFhZL8JP5q6LmGQrENvp6xY8/B1c3XM4ao5 Bjfw== X-Gm-Message-State: AOAM531SF8jDcrZqShWHmuC0CmTfuYIOHrKLPyfudP/PlmHrzyoiV7Ny eGLY0fxhCWtLlRXruNlNFfNxMPofgX8= X-Received: by 2002:a7b:c941:: with SMTP id i1mr100264wml.73.1595867571213; Mon, 27 Jul 2020 09:32:51 -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 w16sm14706791wrg.95.2020.07.27.09.32.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2020 09:32:50 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 Jul 2020 17:32:23 +0100 Message-Id: <20200727163237.23371-9-sw@jkqxz.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727163237.23371-1-sw@jkqxz.net> References: <20200727163237.23371-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 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" X-TUID: iS64+myQQIzv Content-Length: 3818 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 a8af4105cf..cf41abe96c 100644 --- a/libavcodec/h264_redundant_pps_bsf.c +++ b/libavcodec/h264_redundant_pps_bsf.c @@ -41,8 +41,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; @@ -89,7 +100,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) { @@ -145,7 +156,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; }