From patchwork Mon Nov 26 13:39:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 11170 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 641E84405CC for ; Mon, 26 Nov 2018 15:40:09 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DE32868A68A; Mon, 26 Nov 2018 15:40:09 +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 7D7FF68A688 for ; Mon, 26 Nov 2018 15:40:03 +0200 (EET) Received: by mail-wm1-f65.google.com with SMTP id y139so18209931wmc.5 for ; Mon, 26 Nov 2018 05:40:08 -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=a553aIKu6D4Qwirgy3MWr2ZWI+KyYmUjyulkRkDtet8=; b=dSIlG1LMpFt1Qrm4/KW222LaHb6hrlO5wNwWDOsOsY63me1ti87QVy7mv3OmM0m1oF YXI/CGekSEdOKUDJ2C+oPO8aYzuDi2D+a1BiubMJhVnTR5Y0orhFVLkU6pVPtydwgzGB ahDQKVEiPUfsn8TN/5UaG0mNTyIgKKRDG0LzmUwU2KpKz2TXYIkiB9WCPGQMB709dKzK YcaTyzncG8fumdaGJnSFF2QLstPr0V4i24bbe3Rdq2+O2GAkLhx3+dT7Gv5VttPcfTYk QXlNT2skLE1+oO0HouagG5YAwvcYAlV2jFR++I63AnqogWki7GmL+a8qYqEw+GghFZIa 09aQ== 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=a553aIKu6D4Qwirgy3MWr2ZWI+KyYmUjyulkRkDtet8=; b=Wg3G2Mqef+qUe38zypmUwANrhfI21sfCieKp9FkpStgSh9v1pGn0eAFUq9reLlKyCl Y07TIdRAwjZQId8ENcD0KTgQXiWW8UcI++oopeoiXrKRlusSOdZYe8kN4cJrjEL/fWws aJ+wZne7wy5AO7WWwD3h4vmMRbArvErLdeR2fLt74N7ShojNEPtfmD8qgamBdFHuAYek pW5/U7Wztl6siqoQph1bz+sh5hEjGYgw61gFL/wLItLAqy50DnHZ02IE1OMkdv99wEwz 0t1vgDjxYlaxbQETx8Zud9WFH1KcI4NibvIjrgb6y9/6NoaeyXtswWHyBlZWAFu/7Hcb 4qnA== X-Gm-Message-State: AGRZ1gLP7co7gYG/dhBOwMWGIrTvmER5COsn8msuUPX0tI+WBM34i2tx IVDbu9q1jSnS8HPwNgw2lG6wsy+J X-Google-Smtp-Source: AFSGD/W7sRROdhtRaYHpSSswwKaWI6rllUpUVYdHmhHSajpMgUzkOv13cgAeEQPQTu+OlbA6TMf60Q== X-Received: by 2002:a1c:f313:: with SMTP id q19-v6mr23343347wmq.87.1543239607552; Mon, 26 Nov 2018 05:40:07 -0800 (PST) Received: from localhost.localdomain (ipbcc08c44.dynamic.kabel-deutschland.de. [188.192.140.68]) by smtp.googlemail.com with ESMTPSA id 142sm1184169wmw.27.2018.11.26.05.40.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Nov 2018 05:40:07 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 26 Nov 2018 14:39:13 +0100 Message-Id: <20181126133913.2356-5-andreas.rheinhardt@googlemail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/5] 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 --- 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; }