From patchwork Tue Mar 5 20:46:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 12206 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 6F755447ADC for ; Tue, 5 Mar 2019 22:46:28 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5A7F568A2A7; Tue, 5 Mar 2019 22:46:28 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8044E689C85 for ; Tue, 5 Mar 2019 22:46:21 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 43AD9E13A3; Tue, 5 Mar 2019 21:46:21 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9ylnskXs-x_1; Tue, 5 Mar 2019 21:46:20 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id CD3BAE1445; Tue, 5 Mar 2019 21:46:19 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Tue, 5 Mar 2019 21:46:06 +0100 Message-Id: <20190305204606.20281-5-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190305204606.20281-1-cus@passwd.hu> References: <20190305204606.20281-1-cus@passwd.hu> Subject: [FFmpeg-devel] [PATCH 5/5] avfilter/af_astats: add support for optimized min/max/peak calculation 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: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Marton Balint --- libavfilter/af_astats.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/libavfilter/af_astats.c b/libavfilter/af_astats.c index 9915a7965e..92368793c2 100644 --- a/libavfilter/af_astats.c +++ b/libavfilter/af_astats.c @@ -49,6 +49,8 @@ #define MEASURE_ZERO_CROSSINGS_RATE (1 << 17) #define MEASURE_NUMBER_OF_SAMPLES (1 << 18) +#define MEASURE_MINMAXPEAK (MEASURE_MIN_LEVEL | MEASURE_MAX_LEVEL | MEASURE_PEAK_LEVEL) + typedef struct ChannelStats { double last; double last_non_zero; @@ -216,6 +218,14 @@ static void bit_depth(AudioStatsContext *s, uint64_t mask, uint64_t imask, AVRat depth->num++; } +static inline void update_minmax(AudioStatsContext *s, ChannelStats *p, double d) +{ + if (d < p->min) + p->min = d; + if (d > p->max) + p->max = d; +} + static inline void update_stat(AudioStatsContext *s, ChannelStats *p, double d, double nd, int64_t i) { if (d < p->min) { @@ -406,26 +416,32 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata) set_meta(metadata, 0, "Overall.Number_of_samples", "%f", nb_samples / s->nb_channels); } -#define UPDATE_STATS_P(type, double_sample, normalized_sample, int_sample) \ +#define UPDATE_STATS_P(type, update_func, channel_func) \ for (int c = 0; c < channels; c++) { \ ChannelStats *p = &s->chstats[c]; \ const type *src = (const type *)data[c]; \ const type * const srcend = src + samples; \ for (; src < srcend; src++) \ - update_stat(s, p, double_sample, normalized_sample, int_sample); \ + update_func; \ + channel_func; \ } -#define UPDATE_STATS_I(type, double_sample, normalized_sample, int_sample) \ +#define UPDATE_STATS_I(type, update_func, channel_func) \ for (int c = 0; c < channels; c++) { \ ChannelStats *p = &s->chstats[c]; \ const type *src = (const type *)data[0]; \ const type * const srcend = src + samples * channels; \ for (src += c; src < srcend; src += channels) \ - update_stat(s, p, double_sample, normalized_sample, int_sample); \ + update_func; \ + channel_func; \ } #define UPDATE_STATS(planar, type, sample, normalizer_suffix, int_sample) \ - UPDATE_STATS_##planar(type, sample, sample normalizer_suffix, int_sample); + if ((s->measure_overall | s->measure_perchannel) & ~MEASURE_MINMAXPEAK) { \ + UPDATE_STATS_##planar(type, update_stat(s, p, sample, sample normalizer_suffix, int_sample), ); \ + } else { \ + UPDATE_STATS_##planar(type, update_minmax(s, p, sample), p->nmin = p->min normalizer_suffix; p->nmax = p->max normalizer_suffix;); \ + } static int filter_frame(AVFilterLink *inlink, AVFrame *buf) {