From patchwork Fri May 29 16:31:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19968 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 D153D449D00 for ; Fri, 29 May 2020 19:32:13 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AEF3468ABD5; Fri, 29 May 2020 19:32:13 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C9F1E689BB1 for ; Fri, 29 May 2020 19:32:06 +0300 (EEST) Received: by mail-wm1-f68.google.com with SMTP id r15so4270419wmh.5 for ; Fri, 29 May 2020 09:32:06 -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:mime-version :content-transfer-encoding; bh=BqfC4WNnyCTlqMuqUjnopmIDIH4U08WguPDQUoWlonE=; b=k4Q+nYFz/J1GPd4d2xkC+kHtusroilGwBPK2niyiEj262yQH9wzwy7XDSOntX6AZ0g L6/nxoul6XDIVeiw1ezunlZvqidD/89p6m3zBmLqJE/d3FNNWx3TymsQHfSW+PdXtb97 KvVw0l/ty+vChwFgShnad/LAuopVcK4d7epSfak2fkcrVw/xOdVonpqPhxbEXnqzrRA3 VlaE/crmyvQQeTk5h78xEV0EaX6rl297r4agSr3UpFSwRykUlV+KZJnXyemPQySULsI2 QCsCIpyQt81TRKoTqqrnf2X6o7aAQmEgRV3JpEXJNMVERtFkfuAAHSAQ8A29nyH6PEUd no6A== 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:mime-version :content-transfer-encoding; bh=BqfC4WNnyCTlqMuqUjnopmIDIH4U08WguPDQUoWlonE=; b=FmWQD1/utg2viMymBQvKazK8KiZzcDJGBUwjlDbjdTyCOPCFYJNOCGjhndk/HPxcLV DoN7k+976Ue5WtUOcPtyNDbDCBL4BWvh7/0xW1ys8MJpvMRpsvadfvl7Jav3hOs10ljy Ds/PCA7ai8HH1N6kz4YXGcJLXp15Ie/iWHlLodAnEKuHwXErMMxURJUdC3XUFknj5m5R 8aLH5UJbAKBEPHle/Cu0rtMQmA3jnqNRWMm3tlb+y5YfHKovGevZxqHiQxaF2/yxj7/4 naL3M0CU6zgG30ZxyQA2EydUNpwxYcAIhWfdk9eV5wMyvAp/NFgyGu8xairw2zVIIstk iJmA== X-Gm-Message-State: AOAM531Qz8ViT61ln+4GB6TuMy9Q5/vMYbJh1cuYPsdDJFw/SdtWIS9R ztTPkS+qOntHAyr8LglUonSWR0Kc X-Google-Smtp-Source: ABdhPJx3YvbFMadj3B3L+RW9BlNMs/w9bmw0lAmueZl9r0yfaRRs6eCDkds0wh8sPwoBZf07pybavw== X-Received: by 2002:a7b:c0cc:: with SMTP id s12mr9587380wmh.111.1590769925879; Fri, 29 May 2020 09:32:05 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id s72sm7965694wme.35.2020.05.29.09.32.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2020 09:32:04 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 29 May 2020 18:31:57 +0200 Message-Id: <20200529163157.22588-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2] 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 PPS; immediately afterwards, the currently active PPS is set again which includes referencing it. Given that it is typical for the active parameter sets to change only seldomly, most of the time the new active PPS will be the old one. Therefore this commit checks for this and only unreferences the PPS if it changed. Signed-off-by: Andreas Rheinhardt --- New and much simplified version of [1]. This has been made possible by 5e316096fa9ba4493d9dbb48847ad8e0b0e188c3. [1]: https://ffmpeg.org/pipermail/ffmpeg-devel/2019-August/248374.html libavcodec/h264_parser.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c index d988484660..c6fd049f46 100644 --- a/libavcodec/h264_parser.c +++ b/libavcodec/h264_parser.c @@ -363,6 +363,7 @@ 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); p->ps.pps = NULL; p->ps.sps = NULL; @@ -371,6 +372,7 @@ static inline int parse_nal_units(AVCodecParserContext *s, goto fail; p->ps.pps = (const PPS*)p->ps.pps_ref->data; p->ps.sps = p->ps.pps->sps; + } sps = p->ps.sps; // heuristic to detect non marked keyframes