From patchwork Mon May 20 23:02:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 13212 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 E9C13447422 for ; Tue, 21 May 2019 02:11:00 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D1B7068A559; Tue, 21 May 2019 02:11:00 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9A83968031D for ; Tue, 21 May 2019 02:10:59 +0300 (EEST) Received: by mail-wr1-f65.google.com with SMTP id g12so16091060wro.8 for ; Mon, 20 May 2019 16:10:59 -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=RkmWR6urKRUAO6ZifyKvG7Kj3o34SfNgnOW8tMNc1l4=; b=Xiq21MA8NhbfPL3/bMH01TQNsxBFDZoNI0J/gmENElr3E/ziaC99TIKc9bFbBSWtnB jwJJbeRh+Tbe0whbZkudCpZytcR80BqW0g+I9llsvSw4Lf8T/cS3ivsTsUl0JB/YZ+Gw kQAkVA06gMY9EGLMq3JonKwZ9ba4so2t+ldNhF1iu75EOZ7hEKEOnMTIAw8+ovlhvDKE 4EEH2MULUaK8sEWmfjQzPWCO7FkRQiAnE8sE77P6eH8uT5JwDKgNZXzZdw2mcHcFcjcq 1ITDGcb3hRyJNdsuOcgLCf15DM4/eHy7sDI92VrjvUrsdmqBLO6SJ67Vw1F27gvUjS7M 0CoQ== 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=RkmWR6urKRUAO6ZifyKvG7Kj3o34SfNgnOW8tMNc1l4=; b=OM35o5Jm5Ij5hcJOiVmJ470zF8Lg2m9NBKUpN7N64RkV4bOkkbCfTJ2jzHEPqnt7C2 LMT/GZ5pBLBk/vIUGc/aip81cACixxl/FOJaTa/vtB+Pzo3cwAlF77dR99eN8Oh6o9wp dx2xtMrj0746exEO79Xp+Oewkn3xp2U0Nyruh+qWegVdIPx3sV4WUYOxLT470VrAr4rZ L2BSxFLgFeAg0nDHQbw167pCDC/Pn7Ep9KSRCSRD2FasCIZc8m/k6IuroRx0OFQRA8nU Rtu3wDZksqvZs4bYNasZ9fealrymxIucf41ce/By0Vqv6qc132BdGeLeLTEMhiUBzuBa 3l6A== X-Gm-Message-State: APjAAAW2PVnMAK0T9fVDRd9RVQORG6RKsrDEPB6KYKq4hzy4LtaZyukP p5Ikazsi9PdWPLD1mMe5amcgktlH2sA= X-Google-Smtp-Source: APXvYqwyTJl+fDrV2kdXYy6HBK9UilXl8ZaTKgiH/FmFSs2bD2bIB/vq+GKcxEJQjRFZQdcXEsvvOw== X-Received: by 2002:adf:9e89:: with SMTP id a9mr33636829wrf.78.1558393356129; Mon, 20 May 2019 16:02:36 -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 z14sm13858538wrq.22.2019.05.20.16.02.35 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 May 2019 16:02:35 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 May 2019 00:02:21 +0100 Message-Id: <20190520230224.19221-8-sw@jkqxz.net> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190520230224.19221-1-sw@jkqxz.net> References: <20190520230224.19221-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 08/11] 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 db8717d69a..b98c344058 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; }