From patchwork Sat Nov 24 01:55:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 11136 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 38D3044DA38 for ; Sat, 24 Nov 2018 03:57:23 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BA65068A38A; Sat, 24 Nov 2018 03:57:23 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CF8FF68A326 for ; Sat, 24 Nov 2018 03:57:17 +0200 (EET) Received: by mail-wr1-f68.google.com with SMTP id v13so10343329wrw.5 for ; Fri, 23 Nov 2018 17:57:21 -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=BYclQ+tbn8x2nJ9nhkB1pvcioThjYT4b3EQqmbI4xqk=; b=J9tJ1VldQKF6mnzoGtjwzH3YIBfAS7ZZugQGVBLknPI0FO3JweAPmRjX8V5ENZ3EFL kVmfHtur2xW63nishAvW8FVf4YmknxypsowzjhiIBrJ6sYd3z1j40aL5X1txUWVXNFa8 XrZhvIn/k84wqFWZxGNGopHZ4tCKj0/1wOnKXwcSBVl38nGg0qhRHWGcILrmWl2DRYTF EviA9lii17QYKwYAI1Bj8VHQCsUnMfe44SmkHPdyiFtzcKv+BAnakrIcC0czTEsJaIK2 uU/8njNBYw5+PYZsxVyV+RlyluOGPVzcELuWZ/NXhTHjgswc0p3/0VNZivJ4Dtv4EJio fQ7Q== 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=BYclQ+tbn8x2nJ9nhkB1pvcioThjYT4b3EQqmbI4xqk=; b=KX9Iu9RQxjhrQdIToOdoeXxsl9oEKOQONY1dfjPA3OZozWYsQ5MCBGknRAeOfCdf+x wQYlL7OuhQ8MZneVg285lQuu5UAiPK7yWSpSIOtZ+A/icN/Xd1GHxr44QiWWex4tpDrQ 3tCYmrAZV9FedoZODkuyJyqoznEYa7DZaWTBJjB11GmyldO+pfR4unxRo+q2mfN1gVYL eex6wM3M6KuEn0Z0SkbQgH28XIqryc9k2NNBs0Fnsk/kiqqfX2sYnQjk1wQ97NSYBJg8 NQGua8c5GG6lPbGSWzVUs9QaPwwZrw4BkWMZI8u7PTxEOrV5OmJ65fR4tfcCe+Hu/km0 rq9Q== X-Gm-Message-State: AA+aEWYQg2KL0/+k32x3fo71it+DzRC6TqZGBuuPpOaKlZMVh6MJbKJ5 A3zXzGT5n82xcFQaEsvWMNSBBbMa X-Google-Smtp-Source: AFSGD/VQyYweL1qqe5Jf6wD1e2OL97W1Cz2cqGGqU2yeKQAb74r+lMmXF6bMebP00sWKYzY6toDvlQ== X-Received: by 2002:adf:b649:: with SMTP id i9mr16588430wre.70.1543024640936; Fri, 23 Nov 2018 17:57:20 -0800 (PST) Received: from localhost.localdomain (ipbcc08c44.dynamic.kabel-deutschland.de. [188.192.140.68]) by smtp.googlemail.com with ESMTPSA id d8sm398284wrw.70.2018.11.23.17.57.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Nov 2018 17:57:20 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 24 Nov 2018 02:55:38 +0100 Message-Id: <20181124015539.7164-6-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..2270f9df7d 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)) < 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; }