From patchwork Sat Sep 14 00:45:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 51574 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:9fc3:0:b0:48e:c0f8:d0de with SMTP id k3csp183218vqy; Fri, 13 Sep 2024 21:24:11 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUh07qx+GppPs4XCOG9sXjWC3fgsO4Gi3ZCCbZpVuRV4oPjryO6tfp24SW2NDS1vqQRFMomJRWuHgv+TIK3K4Li@gmail.com X-Google-Smtp-Source: AGHT+IGvvOh8eZVU1EXUJkSPAW6hHGddoODba7aQhp5SSul1itzqcxpIMDl0yPEgpbGyKxnAfsVL X-Received: by 2002:a05:6512:3f17:b0:52e:ccf5:7c3e with SMTP id 2adb3069b0e04-53678fef719mr1286206e87.7.1726287850743; Fri, 13 Sep 2024 21:24:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726287850; cv=none; d=google.com; s=arc-20240605; b=jD0YpgbPvNcZ1v9Qga9wbiSnqo56cDmErWe6GIrI5ShRdyqsvTQ5jEa+I0FHtAdTVa pEZiNMUJMeFQFnqL1P+zs+xVNmPQyRNC2YaF9KYCbvDRHcdwqaJ8u+6q2fzRjyHbIEQL gHGfj83NFTcSTAoTux//A5wzakCqlT2yWWGKmTlrwmV+VqQOUVqhWBxBGRvKqfsZp98J bvk1lYG2fBaiEy1K9zwzt67hWVqZm7plzGt0EYzoe0dNYs6d2lySdVFQuH5Ah0LZL047 StTCVXgLFv0z9Ca6XUIgTaa7k9dZi87gfEoV29He0onBqcnevYNSKweWtszPNch6zIMr ALyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=HSPTDHFJVlEmpIA0BwtF4/jFcU763cVSNQXEItY0A78=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=gN8kl08UPTRCKjRtT03Iwf1kxHmqssgujxepTlZnhRqAcc7NMYgLYa3dMy1WnfCURm GuVYRmp7w1xhKrNh3uAcXRP+YalfDxq3ML/8zS/dEVEGPhDEEVDumLttBfnFdf2I9YSE w2UcPv1PVfzy1TTZllfS1aSpqAvsmEHrQn4rkoY6DnkUvRg9x/0iAo/ALch56RS12M/D F9Ie7FomZJcEejz5lE6r53ZVl5aTOdstSeTUUr+JzdBHGLHDTG4ggDTs8eGJUFzLxGdP 8ZOiYXplL8bNpQl3juNybw0Z1zzeMJnu0OPt8Q0zBOPkkvRzrTHvaDz0PRv1MENU8C/p gEIA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b="ek/8kAZ0"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com; dara=fail header.i=@gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 2adb3069b0e04-536870491absi231242e87.157.2024.09.13.21.24.10; Fri, 13 Sep 2024 21:24:10 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b="ek/8kAZ0"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com; dara=fail header.i=@gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9F99468DF71; Sat, 14 Sep 2024 03:45:56 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E704368DF30 for ; Sat, 14 Sep 2024 03:45:49 +0300 (EEST) Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-718e1ce7e84so2025587b3a.1 for ; Fri, 13 Sep 2024 17:45:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726274747; x=1726879547; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=KwsaTQnuRj7M6R9MF+T3a+9VlILCPbwaYF25HqKS3hQ=; b=ek/8kAZ0Wna5xrEz50d+EpgwXJps8HdbDOAVWbLSi+eVzIcBT0E8g+wLah9Efh5a79 AH0UknjOrCEWmTeyR1plOYMkCxz4W9nzjY+xLND4yJAkcJWnArZaXJLKfxjTiiiZ3pAT JTdZYllXuTjn6N/8wcONsO5GE4KBLFi5Zq6qf3qwgxw9Sqsrw1NK2Sq5eQ3ysdE+sQ+x zVNbLGfM75iOL5HBnawYCKCfeaFyedeuzcl/YGOO3cBA0xonCc8MXpEUo0224MR9vKDJ 5FsVeRc+usX6zAkPuQrcjVX++CWTbuEQ+i3oDAznmymXYwfFWttlIMGggB2GOF+aKgER pjsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726274747; x=1726879547; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=KwsaTQnuRj7M6R9MF+T3a+9VlILCPbwaYF25HqKS3hQ=; b=C5UWL3gNmq5U7bkPdOrfDaYJYQXmopmHOZJIV6m4QIYa0kPFuYYaNbEZAhaU+iQggq iyR2jbCd6ap0u4UkfaIll3brwk70JHnPK3m+MSojEU0/tnc7DZ3noQ7/ZEtAVFhvygHi uZ8QVoQrnDzCH2rgzHTco97iwXqx4KfaFPVKYgxYp/vI7rBEqLZpb+YKCN8tOQgG+1xB X6ETOk4/8HCQD3iovOQMnueD7WOjqIf7wAz5j9OM+05RKYaKT9itckFFIHYSz0lrEQve OnUur68Pt/lHund+9syZO6tz+1wpblXpUZjBFikL/REY3oRqpho6Bc5tuAYeFJrQxFgX M90g== X-Gm-Message-State: AOJu0Ywt3d0+LxTG2HDzcrxRap3rzrZSQlSlK06VlUdbZ4XMo27QWJpZ ZI3WpxUP+7NYb13BcOfFjQn0zYwcUJhHfSXiIFsRj/9ExJTC7INxjaN81A== X-Received: by 2002:aa7:88c6:0:b0:70d:3354:a190 with SMTP id d2e1a72fcca58-719261f8db2mr12037794b3a.27.1726274746923; Fri, 13 Sep 2024 17:45:46 -0700 (PDT) Received: from localhost.localdomain ([181.92.233.116]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71944ab5905sm165483b3a.78.2024.09.13.17.45.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 17:45:46 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 13 Sep 2024 21:45:33 -0300 Message-ID: <20240914004533.6382-1-jamrial@gmail.com> X-Mailer: git-send-email 2.46.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avcodec/bsf/dts2pts: use a RefStruct pool to allocate nodes X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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" X-TUID: tPrgGkjZRntj Signed-off-by: James Almer --- libavcodec/bsf/dts2pts.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/libavcodec/bsf/dts2pts.c b/libavcodec/bsf/dts2pts.c index ba4dc43f84..2be79c624b 100644 --- a/libavcodec/bsf/dts2pts.c +++ b/libavcodec/bsf/dts2pts.c @@ -34,6 +34,7 @@ #include "cbs_h264.h" #include "h264_parse.h" #include "h264_ps.h" +#include "refstruct.h" typedef struct DTS2PTSNode { int64_t dts; @@ -61,6 +62,7 @@ typedef struct DTS2PTSH264Context { typedef struct DTS2PTSContext { struct AVTreeNode *root; AVFifo *fifo; + FFRefStructPool *node_pool; // Codec specific function pointers and constants int (*init)(AVBSFContext *ctx); @@ -110,7 +112,7 @@ static int dec_poc(void *opaque, void *elem) static int free_node(void *opaque, void *elem) { DTS2PTSNode *node = elem; - av_free(node); + ff_refstruct_unref(&node); return 0; } @@ -124,7 +126,7 @@ static int alloc_and_insert_node(AVBSFContext *ctx, int64_t ts, int64_t duration DTS2PTSNode *poc_node, *ret; if (!node) return AVERROR(ENOMEM); - poc_node = av_malloc(sizeof(*poc_node)); + poc_node = ff_refstruct_pool_get(s->node_pool); if (!poc_node) { av_free(node); return AVERROR(ENOMEM); @@ -135,7 +137,7 @@ static int alloc_and_insert_node(AVBSFContext *ctx, int64_t ts, int64_t duration ret = av_tree_insert(&s->root, poc_node, cmp_insert, &node); if (ret && ret != poc_node) { *ret = *poc_node; - av_free(poc_node); + ff_refstruct_unref(&poc_node); av_free(node); } } @@ -394,6 +396,11 @@ static int dts2pts_init(AVBSFContext *ctx) if (!s->fifo) return AVERROR(ENOMEM); + s->node_pool = ff_refstruct_pool_alloc(sizeof(DTS2PTSNode), 0); + + if (!s->node_pool) + return AVERROR(ENOMEM); + ret = ff_cbs_init(&s->cbc, ctx->par_in->codec_id, ctx); if (ret < 0) return ret; @@ -459,7 +466,7 @@ static int dts2pts_filter(AVBSFContext *ctx, AVPacket *out) if (!poc_node || poc_node->dts != out->pts) continue; av_tree_insert(&s->root, poc_node, cmp_insert, &node); - av_free(poc_node); + ff_refstruct_unref(&poc_node); av_free(node); poc_node = av_tree_find(s->root, &dup, cmp_find, NULL); } @@ -521,6 +528,7 @@ static void dts2pts_close(AVBSFContext *ctx) dts2pts_flush(ctx); av_fifo_freep2(&s->fifo); + ff_refstruct_pool_uninit(&s->node_pool); ff_cbs_fragment_free(&s->au); ff_cbs_close(&s->cbc); }