From patchwork Tue Jul 2 01:33:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yigithan Yigit X-Patchwork-Id: 50272 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:cc64:0:b0:482:c625:d099 with SMTP id k4csp2187607vqv; Mon, 1 Jul 2024 21:02:55 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXtgzR6akY0QEhZp4Dfj3d4Z0r9lU1E/0DExBBs7+tyJRjX8JVK4VPnPnlcWabgPXowaOZKe325X4ehLbxwXLAE0CHrAJuGuGQOZg== X-Google-Smtp-Source: AGHT+IEtDB8KRW25gv0d9RrHDX+AdqnxCyNDEPRUJr657lXrYG0K4Dwz/r8bNI1IgqpHkpTjXVTh X-Received: by 2002:a2e:be13:0:b0:2ee:4ec2:8232 with SMTP id 38308e7fff4ca-2ee5e3c35e6mr49487791fa.25.1719892975518; Mon, 01 Jul 2024 21:02:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719892975; cv=none; d=google.com; s=arc-20160816; b=rqjCRisPWZq2eoGardnHcL5oer/4k5wg8IuUw9uXuucp54Rfs0uE540Irp6OAAc4D6 rG+zknbIkpu9FWODXQj/AvkWkUlnnIAQhS/oYr7hny1yIYmlns0jYx7pPn0dXSraRt8u Sr1xlCu6RIAV6XWkzZC5eXs1xfcBCYTyrg6fBCrBGLWJOSUgCPKzl5nNyGcE5iG+Wy1L zGHt2D1jWA2pPCe3wktgYVjU7HWJ15CYKbeNv1M5R/4H3v+/xWM9u9DffWY1TrwR4eGv gqesCfIjB6DzJxCPXQYRljDVvbwEOiNeS7jp1u/HI0F4D9VnZWNWxKVezt+TjGXVEFqa BX4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=AC3UXGGmRJiF8fH4oI8vkixWgmHRLJfRdWc0DfcJ93g=; fh=oYrUj4vT4ivb560z23e71q/pal11/Mm+yKMO8RKszaM=; b=yAG7rG3fR2E0nyLJjTotnGxdIZjbJObmYneZ8IjCTBHZ0tCHhILIPdQvgZgnX3a0Wx BRLkw8vqUHuZO1HWDq/oOl/jo8pfRiLtAd11nND02RfWsxVzgJHA1jSzZgQKGueauQ97 9ovDWq2wkFvycEd6K6P/mTvqOpsJ5MplXv6V089m0o7eqbTLcb9dIgThB2T790/jKxQ3 /V2dMCKqALdKC56oJyt7xuCc9GwAFqtVRgk9bCiv6Xvoin+LSLiaNKi0HXSb0e0sEqkC N3xVUrQ9W6QDP3l6+c3usWyPok3/a63QHm2a99bo72wDPXc4O92AXbfuSSvNwVvfGtRJ HnSw==; 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=Sg3M3bI+; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 38308e7fff4ca-2ee5153758bsi21988941fa.268.2024.07.01.21.02.55; Mon, 01 Jul 2024 21:02:55 -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=Sg3M3bI+; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3C26B68D888; Tue, 2 Jul 2024 04:34:11 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7645868D876 for ; Tue, 2 Jul 2024 04:34:02 +0300 (EEST) Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-42567ddf099so25765685e9.3 for ; Mon, 01 Jul 2024 18:34:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719884041; x=1720488841; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=P3ek+3Uy5fJmLpZFIAinBd+2jDzrxdAoQ6k6/5ZJLiA=; b=Sg3M3bI+PHZFZSTAIoGVdbjiWTptbxTs8iMqUBpqfTsocwSEWrXPb2v5kLa1SlOVJV L/Sbp7LOhB2nclfbE1HBbgyq/rc7j6xyDaoFXv1U1qMnpO+0nob2CQSpTqZoMCCIY5/+ UYoTTRxVcljUdT8ZD1iYGFeWc4W83dllj/vgi8YrMVRPNwDsE2w05roeBUSUq53yUlue /s5PEuVp7cylJUQf1Xkn/veVvJA37p93LR1PHnUonUoV59lkvlePOiJACiNSMVB4QcI9 dJWEegcVU3/6kLyvf9lC0fJrySizALKdG1LFHKO8WrooDcN7/yzGDU6IYub0JMXUZDqH DWDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719884041; x=1720488841; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=P3ek+3Uy5fJmLpZFIAinBd+2jDzrxdAoQ6k6/5ZJLiA=; b=cbiQKtJi0Wya8o175EMngvnEXA1rzrICNlfvHxaAsM9EsqyKAYISy8xxfr48Q1KJQy 6BzAM8lWXo3dWBtdpB+nGzF2jy9Q1PYBjU4XChaTHsVJyripe+wsFzFaEJyVFkytUC+u VW4mv/4uP/dQMlpy+j7mXnhQ1YfSu9HmnYvC0bvpTyKzjZ8R75if7k5eqhg1UhFItKAu 5MODvvTsfWkMwdIUCwN/uXGocjepzTO3UpD8VYGY3b9y3m2Lf4rgbuyfh07MlaIHKiNg EiCnJhdBKkrfh+bR7iuvIpT1K1IkRKSNrvyclkCHEpkQrZ07v9xg+LCNQC3y4qHDekHq VkYQ== X-Gm-Message-State: AOJu0YwlPGg1kz2KkzQOxd7Z56Hhuvn2TBwhSm9SPlBCjBUDkoJLZ1Xv JaNycFNdYvZFjoD1hW/0OdE0ZH/OtxFr+B3DaOaDYUMJasizL986vaCIsw== X-Received: by 2002:a05:600c:3089:b0:425:5ea5:a8f8 with SMTP id 5b1f17b1804b1-4257a00dce6mr48026675e9.13.1719884041631; Mon, 01 Jul 2024 18:34:01 -0700 (PDT) Received: from localhost.localdomain ([2a02:e0:8bea:ef00:81b5:4ba8:1843:4f00]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4256b068e93sm176273295e9.24.2024.07.01.18.34.00 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 01 Jul 2024 18:34:01 -0700 (PDT) From: Yigithan Yigit To: ffmpeg-devel@ffmpeg.org Date: Tue, 2 Jul 2024 04:33:52 +0300 Message-ID: <20240702013354.14942-4-yigithanyigitdevel@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240702013354.14942-1-yigithanyigitdevel@gmail.com> References: <20240702013354.14942-1-yigithanyigitdevel@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 3/5] avfilter/af_volumedetect.c: Added functions for int/float and planar/packed 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 Cc: thilo.borgmann@mail.de, yigithanyigitdevel@gmail.com Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Juo9ugulb5RQ --- libavfilter/af_volumedetect.c | 66 +++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/libavfilter/af_volumedetect.c b/libavfilter/af_volumedetect.c index edd2d56f7a..778f0cac6c 100644 --- a/libavfilter/af_volumedetect.c +++ b/libavfilter/af_volumedetect.c @@ -71,6 +71,64 @@ static void update_float_stats(VolDetectContext *vd, float *audio_data) vd->nb_samples++; } +static void process_float_planar_samples(VolDetectContext *vd, AVFrame *samples) +{ + int plane, i; + int nb_channels = samples->ch_layout.nb_channels; + int nb_samples = samples->nb_samples; + float *audio_data; + for (plane = 0; plane < nb_channels; plane++) { + audio_data = (float *)samples->extended_data[plane]; + for (i = 0; i < nb_samples; i++) { + update_float_stats(vd, &audio_data[i]); + } + } +} + +static void process_float_packed_samples(VolDetectContext *vd, AVFrame *samples) +{ + int i, j; + int nb_channels = samples->ch_layout.nb_channels; + int nb_samples = samples->nb_samples; + float *audio_data; + for (i = 0; i < nb_samples; i++) { + audio_data = (float *)samples->extended_data[0]; + for (j = 0; j < nb_channels; j++) { + update_float_stats(vd, &audio_data[i * nb_channels + j]); + } + } +} + +static void process_int_planar_samples(VolDetectContext *vd, AVFrame *samples) +{ + int plane, i; + int nb_channels = samples->ch_layout.nb_channels; + int nb_samples = samples->nb_samples; + int16_t *pcm; + for (plane = 0; plane < nb_channels; plane++) { + pcm = (int16_t *)samples->extended_data[plane]; + for (i = 0; i < nb_samples; i++) { + vd->histogram[pcm[i] + 0x8000]++; + vd->nb_samples++; + } + } +} + +static void process_int_packed_samples(VolDetectContext *vd, AVFrame *samples) +{ + int i, j; + int nb_channels = samples->ch_layout.nb_channels; + int nb_samples = samples->nb_samples; + int16_t *pcm; + for (i = 0; i < nb_samples; i++) { + pcm = (int16_t *)samples->extended_data[0]; + for (j = 0; j < nb_channels; j++) { + vd->histogram[pcm[i * nb_channels + j] + 0x8000]++; + vd->nb_samples++; + } + } +} + static int filter_frame(AVFilterLink *inlink, AVFrame *samples) { AVFilterContext *ctx = inlink->dst; @@ -157,12 +215,20 @@ static int config_output(AVFilterLink *outlink) * The extra element is there for symmetry. */ histogram_size = HISTOGRAM_SIZE + 1; + if (av_sample_fmt_is_planar(outlink->format)) + vd->process_samples = process_int_planar_samples; + else + vd->process_samples = process_int_packed_samples; } else { /* * The histogram is used to store the number of samples at each dB * instead of the number of samples at each PCM value. */ histogram_size = HISTOGRAM_SIZE_FLT + 1; + if (av_sample_fmt_is_planar(outlink->format)) + vd->process_samples = process_float_planar_samples; + else + vd->process_samples = process_float_packed_samples; } vd->histogram = av_calloc(histogram_size, sizeof(uint64_t)); if (!vd->histogram)