From patchwork Wed Jan 23 23:01:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 11847 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 484BF44EBC8 for ; Thu, 24 Jan 2019 01:08:46 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7190A68AC95; Thu, 24 Jan 2019 01:08:34 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0588068AC94 for ; Thu, 24 Jan 2019 01:08:28 +0200 (EET) Received: by mail-wm1-f53.google.com with SMTP id y139so1135529wmc.5 for ; Wed, 23 Jan 2019 15:08:46 -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=2bC2+pmHnn+bloIU0kNa1+qmuA/DM1KcLy/KvwrxyB0=; b=LfPhzPENifCzNIdO98sBiwZmBuiHurRNeWKs53NlK3qJY6CLYPfsGNQ2nIpr/6tS3j QxR8olYFhdNVOXpn3hgZJ1JFVSke08ub5N6Ejcpk4LScNqpkIKVldxiiHWK6k0Ceedxy 72rpha0czJvBiHR1WHzTzUvAqEZdh7Tn/88b7gPvBov1ZWloxgWmTERTY7ViJAf6+hDb iiBegiddH77hsyubvj94uNQgwMl4FKMvL4+KcP/hjzkBNhbaI7juynK0r7r+XjuiqtyK Fzuq5vI6d3cC8qo4fjZu3LkHER7RiLOY1w/+D4KmmtLUnV7VPVtwL0xb71A9pWalEbpc AAJw== 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=2bC2+pmHnn+bloIU0kNa1+qmuA/DM1KcLy/KvwrxyB0=; b=UXaDmAZe8aCXu8FGE1ZBUHbScmbopS0Ntt1M7wFIXzv0UKXjJwfGl1bkx+tJEBQl3z 4w4S5zlkAByweyGHv9/cxkJAsJL3wqJiVJTtUwPNleWf2AcKlWegI9BMotkfRoJEG8JG 9o9TfTXWIASVMEUsFLWKio3LoFGWDHoLVyne8bcbrAHyIsupSI3IQD/EmA57HKR5g+QM N1ZPXbx6tYf1dbDYaTU3DDy4wpMmBQbvfVU3EK8h49AowrnxPiLrjjy27rUFomV0R9u3 Ut/MjgoIhnIsLi09yg9quxIkXu9SIaoFtaXro2N6skwkS+TzZIYwt2epMYa8jWrZG+Fs zu/w== X-Gm-Message-State: AJcUukeFpJemjmKpAPyAUxXsGDYkntiguyjk0I2hGWiOwxivX1c/gHrt hniIAieDzrmw3dTOEf+fySY7oKsBt1E= X-Google-Smtp-Source: ALg8bN4JsBB+pW1JYd5Ha3SprqeChrMTAlFiPuyirnu9m8IDJ2/0AWhjB9uhH7yl6b23y51OcM6ElA== X-Received: by 2002:a1c:2547:: with SMTP id l68mr51311wml.11.1548284487513; Wed, 23 Jan 2019 15:01:27 -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 a62sm48786478wmf.47.2019.01.23.15.01.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Jan 2019 15:01:26 -0800 (PST) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Wed, 23 Jan 2019 23:01:14 +0000 Message-Id: <20190123230114.1086-8-sw@jkqxz.net> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190123230114.1086-1-sw@jkqxz.net> References: <20190123230114.1086-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 7/7] 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 --- 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 0b7888c97e..193a3bac7e 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; @@ -89,7 +100,7 @@ static int h264_redundant_pps_filter(AVBSFContext *bsf, AVPacket *out) 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) { @@ -151,7 +162,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; }