From patchwork Thu Jan 5 11:11:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Bouron X-Patchwork-Id: 2060 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp5281162vsb; Thu, 5 Jan 2017 03:17:14 -0800 (PST) X-Received: by 10.28.148.6 with SMTP id w6mr62877127wmd.43.1483615033944; Thu, 05 Jan 2017 03:17:13 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id tu4si62907385wjb.44.2017.01.05.03.17.13; Thu, 05 Jan 2017 03:17:13 -0800 (PST) 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; 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 dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A9CF8689E1D; Thu, 5 Jan 2017 13:17:05 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C8787689E1D for ; Thu, 5 Jan 2017 13:16:59 +0200 (EET) Received: by mail-wm0-f68.google.com with SMTP id c85so57626267wmi.1 for ; Thu, 05 Jan 2017 03:17:05 -0800 (PST) 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; bh=tMpILqZR8JKuzkSsTDvnPgGZQ6LT5Yv3jhD7oQP/wVs=; b=SNuwx7191BpFhXdCf3t+7QD5rQwS1dMMzHC5GTEpCaW15D+rKFL4riJ1dhjIMJTd89 947c62oHVKw+7u3ZOuRiQAzZYXTdvsUVoA2vPRt8x5aIAwZ1vV+xzc9SVyuXMWX9AssM H6yR8APpI55CNkBuwXzQc4LHARbwDFUFQKxbl0D4h1tte6in8WRFD3PfJpV8hFpf7rfp 0R+Xco5ZJg1Jnhx2y62i8tWHH/gDDXyMlXPSmBWE7i6tfqBPHcNrpHSW5eG8MTs5VTMp XSh3EQrTLmRU3zBde9FHC9nxHt0lvdj45Lddr7twHziQUx/b4BoGv+qJ6wwhBKjgtBAD EXIw== 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; bh=tMpILqZR8JKuzkSsTDvnPgGZQ6LT5Yv3jhD7oQP/wVs=; b=n1DCbK9eFI2w6T/HpRafVqTyKWom/kbExKX5ztGk9kdROknlzBEh/jTBTaTyXno/ED 1JKjb2Kw0t7z/56KhMJaM3norcuwLJ2FcC3mlDRLOUZFIe9WaBy157Vz2AJjc+/eDeEn vZ4vrtjqcjRnGa6ELo2ED33h1ZOgbqL4LT94schZoCGAC+WqmRtJ6ZdreEwP+D7DyZNZ HML25P3UZSmfFtXzkPdRSzfbbNZaBfYh+GOzrDXCal0gdUkAvg/g6h9ix5rPnqltVU5V S8phgr9yCVCeT/3Lmu6LJT8jImBTYyTFVVucfuuUtoVJrNQHLqvIhelS1eKU6S0iaGVk ImXQ== X-Gm-Message-State: AIkVDXJpoHz5VZYVoKgD13yG9V5XjyqjWFrScZzDoxx+geiiEl5AOgf2oIlLq4SB0p0BQA== X-Received: by 10.28.163.5 with SMTP id m5mr62920303wme.98.1483614682928; Thu, 05 Jan 2017 03:11:22 -0800 (PST) Received: from boken.gopro.lcl (LPuteaux-656-1-74-135.w80-12.abo.wanadoo.fr. [80.12.80.135]) by smtp.gmail.com with ESMTPSA id j6sm103326617wjk.25.2017.01.05.03.11.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Jan 2017 03:11:22 -0800 (PST) From: Matthieu Bouron To: ffmpeg-devel@ffmpeg.org Date: Thu, 5 Jan 2017 12:11:36 +0100 Message-Id: <20170105111136.31854-6-matthieu.bouron@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170105111136.31854-1-matthieu.bouron@gmail.com> References: <1462895161-21148-1-git-send-email-matthieu.bouron@gmail.com> <20170105111136.31854-1-matthieu.bouron@gmail.com> Subject: [FFmpeg-devel] [PATCH 5/5] lavfi: use an audio frame pool for each link of the filtergraph 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: Matthieu Bouron MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- libavfilter/audio.c | 50 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/libavfilter/audio.c b/libavfilter/audio.c index a18be89293..5996f607b2 100644 --- a/libavfilter/audio.c +++ b/libavfilter/audio.c @@ -27,6 +27,9 @@ #include "avfilter.h" #include "internal.h" +#define BUFFER_ALIGN 0 + + AVFrame *ff_null_get_audio_buffer(AVFilterLink *link, int nb_samples) { return ff_get_audio_buffer(link->dst->outputs[0], nb_samples); @@ -34,29 +37,48 @@ AVFrame *ff_null_get_audio_buffer(AVFilterLink *link, int nb_samples) AVFrame *ff_default_get_audio_buffer(AVFilterLink *link, int nb_samples) { - AVFrame *frame = av_frame_alloc(); + AVFrame *frame = NULL; int channels = link->channels; - int ret; av_assert0(channels == av_get_channel_layout_nb_channels(link->channel_layout) || !av_get_channel_layout_nb_channels(link->channel_layout)); + if (!link->frame_pool) { + link->frame_pool = ff_frame_pool_audio_init(av_buffer_allocz, channels, + nb_samples, link->format, BUFFER_ALIGN); + if (!link->frame_pool) + return NULL; + } else { + int pool_channels = 0; + int pool_nb_samples = 0; + int pool_align = 0; + enum AVSampleFormat pool_format = AV_SAMPLE_FMT_NONE; + + if (ff_frame_pool_get_audio_config(link->frame_pool, + &pool_channels, &pool_nb_samples, + &pool_format, &pool_align) < 0) { + return NULL; + } + + if (pool_channels != channels || pool_nb_samples < nb_samples || + pool_format != link->format || pool_align != BUFFER_ALIGN) { + + ff_frame_pool_uninit((FFFramePool **)&link->frame_pool); + link->frame_pool = ff_frame_pool_audio_init(av_buffer_allocz, channels, + nb_samples, link->format, BUFFER_ALIGN); + if (!link->frame_pool) + return NULL; + } + } + + frame = ff_frame_pool_get(link->frame_pool); if (!frame) return NULL; - frame->nb_samples = nb_samples; - frame->format = link->format; - av_frame_set_channels(frame, link->channels); + frame->nb_samples = nb_samples; frame->channel_layout = link->channel_layout; - frame->sample_rate = link->sample_rate; - ret = av_frame_get_buffer(frame, 0); - if (ret < 0) { - av_frame_free(&frame); - return NULL; - } - - av_samples_set_silence(frame->extended_data, 0, nb_samples, channels, - link->format); + frame->sample_rate = link->sample_rate; + av_samples_set_silence(frame->extended_data, 0, nb_samples, channels, link->format); return frame; }