From patchwork Sun Nov 25 21:16:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 11158 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 8DB9444C6B6 for ; Sun, 25 Nov 2018 23:16:26 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 18AEE68A399; Sun, 25 Nov 2018 23:16:27 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1DE5A68A0A0 for ; Sun, 25 Nov 2018 23:16:20 +0200 (EET) Received: by mail-wm1-f66.google.com with SMTP id s11so16408912wmh.1 for ; Sun, 25 Nov 2018 13:16:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=X45fGURBs1jJ3mvfB6SvXH3bwv62fb9bkkhaYCvc2MQ=; b=WU7PBJ/qxO6fhLNNdUkloQG1Hbaf/5jvr6d8fy0OIFtNeEomxDKwZQRj6pvKlZ85lm 7oqSU3ed4snQ0jLEaGKOZAdCMROI5T5Urq/WDVd/RHU2H2PC/sZ8zIbjRRecokZR5yko lCM2E1ZElaTWWN177ifsjzE/4bR+FQGBjpPowIHUnIb6C05dtPaTnDjy0d9DQulewKg+ SmglV/Yx+sx0SWBv/O9Jfa8Tv2Qha6naBPU1nqLwgXbF5pz3B1BWlWY3dZtTogPX1s6C X9xYnAlbdo3cUiEdhLXtQTb2haQnMdu3pSXToWhcCFVdgswjwn+OZctZ7jmhk8IRjN3h 9//w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=X45fGURBs1jJ3mvfB6SvXH3bwv62fb9bkkhaYCvc2MQ=; b=ubgP0ymwEb9UDLorK76IaPIi+VfEe2mvZIyZ0PybWd2hOYRzxHojVaDXZfa1l5pfZQ h4hflb0aBeTuJrp8MwmGNcO6jaPqiGTU2KuaFYipTRmi2x9cYxWVoZdOg9P/MndOhxjh 8wS3lyzZ+onZgeMBvdH2aQQ4rLEFu4PX9efj8oUz2pi2YCKbfNYkFaRFnjiCpHm9fqcI /9h/eO0BnGFrj/cmQEBf1ptorGHIf0viYTMK701Uz8eEXPKveRHHQ3sTE79xAUVZMt5n xNJJp4Nmi6qEn+9VU2CMyRi/xFQHSFicBtzFj80bzSqZ8o7OTrSoLnRO23nEABZkn87B wwVg== X-Gm-Message-State: AA+aEWbEPn+k1YbIvaZu+QTNh6f58tD4fU5jVLfEKbUG9KUIXFxrxrAp c91mZ701XCfkcSbN98KV+eP3dEga X-Google-Smtp-Source: AFSGD/XBP9q4tr7WTWRRmlTDIFOYT1oGTsjs2cVt2bQ32oKA1ZmeFev9/VoRlHHh+pS5KLbRRN5fLA== X-Received: by 2002:a1c:48c1:: with SMTP id v184-v6mr10939916wma.26.1543180583911; Sun, 25 Nov 2018 13:16:23 -0800 (PST) Received: from localhost.localdomain (ipbcc08c44.dynamic.kabel-deutschland.de. [188.192.140.68]) by smtp.googlemail.com with ESMTPSA id y9sm23720757wrq.55.2018.11.25.13.16.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 25 Nov 2018 13:16:23 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 25 Nov 2018 22:16:01 +0100 Message-Id: <20181125211601.2092-1-andreas.rheinhardt@googlemail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181124015539.7164-6-andreas.rheinhardt@googlemail.com> References: <20181124015539.7164-6-andreas.rheinhardt@googlemail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 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 --- This version is compatible with the new make_unit_writable function. libavcodec/h264_redundant_pps_bsf.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libavcodec/h264_redundant_pps_bsf.c b/libavcodec/h264_redundant_pps_bsf.c index 0b7888c97e..c484357942 100644 --- a/libavcodec/h264_redundant_pps_bsf.c +++ b/libavcodec/h264_redundant_pps_bsf.c @@ -40,8 +40,17 @@ 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. + if ((err = ff_cbs_make_unit_writable(ctx->input, unit, NULL)) < 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 +98,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 +160,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; }