From patchwork Fri Aug 16 03:05:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 14545 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 223B8448BFD for ; Fri, 16 Aug 2019 06:19:16 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0C76E68AD4D; Fri, 16 Aug 2019 06:19:16 +0300 (EEST) 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 1E0B268AD23 for ; Fri, 16 Aug 2019 06:19:10 +0300 (EEST) Received: by mail-wr1-f68.google.com with SMTP id j16so161250wrr.8 for ; Thu, 15 Aug 2019 20:19:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qC6IJtJsI7GbAMCJrJGe99y3EeNqx8lRZSvlo3GGV34=; b=VNr6+OxE0jeIZhi3mwORtcvO0GO2EfxvrKL7/Vb+uxU38VkTghju3d7GzUwgteHBG6 2kMrUgj61GpiDnpRZxJPF+KJAHFfiYUeopKHdpj5lZQhE/0ENrevZeOWMTU1RXfCb3T4 hO0qGia6rvPWAG9t08oC/jPtA7Ulcvf912CZQI8xB48RJfhVI49ej/QoxEaj76ih68Sb 0vMXedYlscKpnvLXWZAjrzW1+LmHnOQnZsJh1yf5ErplUQCLnIVvj0TYP4DyvKKTWMVC cR0OxnzDQQGtlWOw9hV4fYKnZN8YziJmRd3HObs4CiyWDe0g//9bU5hQQ0l+wsY72a9T kWJg== 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=qC6IJtJsI7GbAMCJrJGe99y3EeNqx8lRZSvlo3GGV34=; b=gtsrMNC6+eaVISikBsUbFqAo3xrU2HDl530Dj5aytX3FXcwd8xa4bImnn9JUCkrfV/ zseMuzdIgX10Gb2nh+yY01oGCGICNEVmjE4kcU7zeJKYqDHKJH8DKHwo8WTqF1fi3mdF h6JYi+8eImB2y2u7RZRLtGHr1XtPqXrdXGd92KE31atz1L5a+Bfp3SZ6csUapeSEJ4BW MxY1dZ1HOxsuF2hhXeWei+cXlfiarZ1q0rXyci3v3XCcgyDrkl4LHjJHn/WrkP7ujO5R tAJLfUoyYRfOJNxFE1MioC4iyr6OVQYRusPlsvjko9zq+ka0zwzvsk3jgE/+BdM3htlj TKAg== X-Gm-Message-State: APjAAAXI0A/AXcJ+gt8pKvlER1+E60DFWLBOa/fnjKy6g9jNaQNDiBgT PxtTSkt74jtDBR9apMHqblPziYj6 X-Google-Smtp-Source: APXvYqx5foB6PLUwOZ7CzMcEEV+bdn4jouVFI6OULj4C7CaTETqBPg1aVeU286vkb0hVcnDGdOJJaQ== X-Received: by 2002:adf:eac3:: with SMTP id o3mr7295734wrn.264.1565925230233; Thu, 15 Aug 2019 20:13:50 -0700 (PDT) Received: from localhost.localdomain (ipbcc08b69.dynamic.kabel-deutschland.de. [188.192.139.105]) by smtp.gmail.com with ESMTPSA id x20sm8501603wrg.10.2019.08.15.20.13.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Aug 2019 20:13:49 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 16 Aug 2019 05:05:27 +0200 Message-Id: <20190816030531.4775-7-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190816030531.4775-1-andreas.rheinhardt@gmail.com> References: <20190816030531.4775-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 07/11] avcodec/h264_parser: Try to avoid (un)referencing 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" When a slice is encountered, the H.264 parser up until now always unreferenced and reset the currently active SPS and PPS; immediately afterwards, the currently active parameter sets are set which includes referencing them. Given that it is not uncommon for the active parameter sets to change only seldomly, most of the time the new active parameter sets will be the old ones. Therefore this commit checks for this and only unreferences an active parameter set if it changed. Signed-off-by: Andreas Rheinhardt --- libavcodec/h264_parser.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c index 5f7aea0c76..188ba41c0b 100644 --- a/libavcodec/h264_parser.c +++ b/libavcodec/h264_parser.c @@ -363,25 +363,33 @@ static inline int parse_nal_units(AVCodecParserContext *s, goto fail; } + if (p->ps.pps != (const PPS*)p->ps.pps_list[pps_id]->data) { av_buffer_unref(&p->ps.pps_ref); - av_buffer_unref(&p->ps.sps_ref); - p->ps.pps = NULL; - p->ps.sps = NULL; p->ps.pps_ref = av_buffer_ref(p->ps.pps_list[pps_id]); - if (!p->ps.pps_ref) - goto fail; + if (!p->ps.pps_ref) { + p->ps.pps = NULL; + goto unref_sps; + } p->ps.pps = (const PPS*)p->ps.pps_ref->data; + } if (!p->ps.sps_list[p->ps.pps->sps_id]) { av_log(avctx, AV_LOG_ERROR, "non-existing SPS %u referenced\n", p->ps.pps->sps_id); + unref_sps: + av_buffer_unref(&p->ps.sps_ref); + p->ps.sps = NULL; goto fail; } - + if (p->ps.sps != (const SPS*)p->ps.sps_list[p->ps.pps->sps_id]->data) { + av_buffer_unref(&p->ps.sps_ref); p->ps.sps_ref = av_buffer_ref(p->ps.sps_list[p->ps.pps->sps_id]); - if (!p->ps.sps_ref) + if (!p->ps.sps_ref) { + p->ps.sps = NULL; goto fail; + } p->ps.sps = (const SPS*)p->ps.sps_ref->data; + } sps = p->ps.sps;