From patchwork Tue Mar 5 20:46:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 12208 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 08347447ADC for ; Tue, 5 Mar 2019 22:46:22 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id ECC4A689D10; Tue, 5 Mar 2019 22:46:21 +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 4A903689C14 for ; Tue, 5 Mar 2019 22:46:16 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 355F2E1553; Tue, 5 Mar 2019 21:46:16 +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 KTG5bJaqFq67; Tue, 5 Mar 2019 21:46:15 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 40EA6E1503; Tue, 5 Mar 2019 21:46:15 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Tue, 5 Mar 2019 21:46:04 +0100 Message-Id: <20190305204606.20281-3-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 3/5] avfilter/af_astats: factorize sample loops 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 | 108 +++++++++++++++++------------------------------- 1 file changed, 37 insertions(+), 71 deletions(-) diff --git a/libavfilter/af_astats.c b/libavfilter/af_astats.c index ddda84cfbb..f45558909a 100644 --- a/libavfilter/af_astats.c +++ b/libavfilter/af_astats.c @@ -406,12 +406,33 @@ 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) \ + for (int c = 0; c < channels; c++) { \ + ChannelStats *p = &s->chstats[c]; \ + const type *src = (const type *)data[c]; \ + for (int i = 0; i < samples; i++, src++) \ + update_stat(s, p, double_sample, normalized_sample, int_sample); \ + } + +#define UPDATE_STATS_I(type, double_sample, normalized_sample, int_sample) \ + { \ + const type *src = (const type *)data[0]; \ + for (int i = 0; i < samples; i++) { \ + for (int c = 0; c < channels; c++, src++) \ + update_stat(s, &s->chstats[c], double_sample, normalized_sample, int_sample); \ + } \ + } + +#define UPDATE_STATS(planar, type, sample, normalizer_suffix, int_sample) \ + UPDATE_STATS_##planar(type, sample, sample normalizer_suffix, int_sample); + static int filter_frame(AVFilterLink *inlink, AVFrame *buf) { AudioStatsContext *s = inlink->dst->priv; AVDictionary **metadata = &buf->metadata; const int channels = s->nb_channels; - int i, c; + const int samples = buf->nb_samples; + const uint8_t * const * const data = (const uint8_t * const *)buf->extended_data; if (s->reset_count > 0) { if (s->nb_frames >= s->reset_count) { @@ -423,89 +444,34 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf) switch (inlink->format) { case AV_SAMPLE_FMT_DBLP: - for (c = 0; c < channels; c++) { - ChannelStats *p = &s->chstats[c]; - const double *src = (const double *)buf->extended_data[c]; - - for (i = 0; i < buf->nb_samples; i++, src++) - update_stat(s, p, *src, *src, llrint(*src * (UINT64_C(1) << 63))); - } + UPDATE_STATS(P, double, *src, , llrint(*src * (UINT64_C(1) << 63))); break; - case AV_SAMPLE_FMT_DBL: { - const double *src = (const double *)buf->extended_data[0]; - - for (i = 0; i < buf->nb_samples; i++) { - for (c = 0; c < channels; c++, src++) - update_stat(s, &s->chstats[c], *src, *src, llrint(*src * (UINT64_C(1) << 63))); - }} + case AV_SAMPLE_FMT_DBL: + UPDATE_STATS(I, double, *src, , llrint(*src * (UINT64_C(1) << 63))); break; case AV_SAMPLE_FMT_FLTP: - for (c = 0; c < channels; c++) { - ChannelStats *p = &s->chstats[c]; - const float *src = (const float *)buf->extended_data[c]; - - for (i = 0; i < buf->nb_samples; i++, src++) - update_stat(s, p, *src, *src, llrint(*src * (UINT64_C(1) << 31))); - } + UPDATE_STATS(P, float, *src, , llrint(*src * (UINT64_C(1) << 31))); break; - case AV_SAMPLE_FMT_FLT: { - const float *src = (const float *)buf->extended_data[0]; - - for (i = 0; i < buf->nb_samples; i++) { - for (c = 0; c < channels; c++, src++) - update_stat(s, &s->chstats[c], *src, *src, llrint(*src * (UINT64_C(1) << 31))); - }} + case AV_SAMPLE_FMT_FLT: + UPDATE_STATS(I, float, *src, , llrint(*src * (UINT64_C(1) << 31))); break; case AV_SAMPLE_FMT_S64P: - for (c = 0; c < channels; c++) { - ChannelStats *p = &s->chstats[c]; - const int64_t *src = (const int64_t *)buf->extended_data[c]; - - for (i = 0; i < buf->nb_samples; i++, src++) - update_stat(s, p, *src, *src / (double)INT64_MAX, *src); - } + UPDATE_STATS(P, int64_t, *src, / (double)INT64_MAX, *src); break; - case AV_SAMPLE_FMT_S64: { - const int64_t *src = (const int64_t *)buf->extended_data[0]; - - for (i = 0; i < buf->nb_samples; i++) { - for (c = 0; c < channels; c++, src++) - update_stat(s, &s->chstats[c], *src, *src / (double)INT64_MAX, *src); - }} + case AV_SAMPLE_FMT_S64: + UPDATE_STATS(I, int64_t, *src, / (double)INT64_MAX, *src); break; case AV_SAMPLE_FMT_S32P: - for (c = 0; c < channels; c++) { - ChannelStats *p = &s->chstats[c]; - const int32_t *src = (const int32_t *)buf->extended_data[c]; - - for (i = 0; i < buf->nb_samples; i++, src++) - update_stat(s, p, *src, *src / (double)INT32_MAX, *src); - } + UPDATE_STATS(P, int32_t, *src, / (double)INT32_MAX, *src); break; - case AV_SAMPLE_FMT_S32: { - const int32_t *src = (const int32_t *)buf->extended_data[0]; - - for (i = 0; i < buf->nb_samples; i++) { - for (c = 0; c < channels; c++, src++) - update_stat(s, &s->chstats[c], *src, *src / (double)INT32_MAX, *src); - }} + case AV_SAMPLE_FMT_S32: + UPDATE_STATS(I, int32_t, *src, / (double)INT32_MAX, *src); break; case AV_SAMPLE_FMT_S16P: - for (c = 0; c < channels; c++) { - ChannelStats *p = &s->chstats[c]; - const int16_t *src = (const int16_t *)buf->extended_data[c]; - - for (i = 0; i < buf->nb_samples; i++, src++) - update_stat(s, p, *src, *src / (double)INT16_MAX, *src); - } + UPDATE_STATS(P, int16_t, *src, / (double)INT16_MAX, *src); break; - case AV_SAMPLE_FMT_S16: { - const int16_t *src = (const int16_t *)buf->extended_data[0]; - - for (i = 0; i < buf->nb_samples; i++) { - for (c = 0; c < channels; c++, src++) - update_stat(s, &s->chstats[c], *src, *src / (double)INT16_MAX, *src); - }} + case AV_SAMPLE_FMT_S16: + UPDATE_STATS(I, int16_t, *src, / (double)INT16_MAX, *src); break; }