From patchwork Fri Mar 26 12:58:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Rapp X-Patchwork-Id: 26618 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 6ABFD44AC58 for ; Fri, 26 Mar 2021 14:58:17 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 476C368AA89; Fri, 26 Mar 2021 14:58:17 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from server6.ceeqoo.com (server6.ceeqoo.com [178.77.101.243]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2C12668A711 for ; Fri, 26 Mar 2021 14:58:09 +0200 (EET) Received: from mailix (www.noaport.de [109.90.164.154]) by server6.ceeqoo.com (Postfix) with ESMTPA id 273E1B9FB1 for ; Fri, 26 Mar 2021 13:58:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=noa-archive.com; s=default; t=1616763488; bh=MSQy5bm8F/VLX8iMFd+1J8wx90SJkPuYBoLp8zeXHLo=; h=Received:From:To:Subject; b=xoLQQcIZhdITpp5KDaKfE9qNJSSTpNp4c8UeexFKK/1SyUlgPC0YxPNyddbYoYjYa WxcT8aBkVFXCQQwkGMlsMSQYxnVKGxVbqJsjoKCEzij/2jrzthSRkinXq7rwb3w3kP G6/PkhRDl75ymCS4J3bt2nHBv0lBpvTsL+mwSqps= Authentication-Results: server6.ceeqoo.com; spf=pass (sender IP is 109.90.164.154) smtp.mailfrom=t.rapp@noa-archive.com smtp.helo=mailix Received-SPF: pass (server6.ceeqoo.com: connection is authenticated) Received: from frogstar-a.kuhnle.local (frogstar-a.kuhnle.local [192.168.0.26]) by mailix with ESMTPA ; Fri, 26 Mar 2021 13:58:07 +0100 From: Tobias Rapp To: ffmpeg-devel@ffmpeg.org Date: Fri, 26 Mar 2021 13:58:07 +0100 Message-Id: <1616763487-10025-2-git-send-email-t.rapp@noa-archive.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1616763487-10025-1-git-send-email-t.rapp@noa-archive.com> References: <1616763487-10025-1-git-send-email-t.rapp@noa-archive.com> X-PPP-Message-ID: <161676348837.28839.7878867008240723118@server6.ceeqoo.com> X-PPP-Vhost: noa-archive.com Subject: [FFmpeg-devel] [PATCH 2/2] avfilter/af_astats: Remove fraction part of integer metadata entries 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Using integer format makes the metadata display similar to the log output. Fix missing "Overall" metadata key name prefix where necessary. Also replace whitespace in some metadata key names with underscore character for consistency. Signed-off-by: Tobias Rapp --- libavfilter/af_astats.c | 56 +++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/libavfilter/af_astats.c b/libavfilter/af_astats.c index c13df62..3b248b9 100644 --- a/libavfilter/af_astats.c +++ b/libavfilter/af_astats.c @@ -390,18 +390,24 @@ static inline void update_double_stat(AudioStatsContext *s, ChannelStats *p, dou p->nb_denormals += type == FP_SUBNORMAL; } -static void set_meta(AVDictionary **metadata, int chan, const char *key, - const char *fmt, double val) +static av_printf_format(4, 5) void set_meta(AVDictionary **metadata, int chan, + const char *key, const char *value, ...) { - uint8_t value[128]; - uint8_t key2[128]; - - snprintf(value, sizeof(value), fmt, val); - if (chan) - snprintf(key2, sizeof(key2), "lavfi.astats.%d.%s", chan, key); - else - snprintf(key2, sizeof(key2), "lavfi.astats.%s", key); - av_dict_set(metadata, key2, value, 0); + va_list argument_list; + + va_start(argument_list, value); + if (value) { + char keybuf[128]; + char valbuf[128]; + if (chan) { + snprintf(keybuf, sizeof(keybuf), "lavfi.astats.%d.%s", chan, key); + } else { + snprintf(keybuf, sizeof(keybuf), "lavfi.astats.%s", key); + } + vsnprintf(valbuf, sizeof(valbuf), value, argument_list); + av_dict_set(metadata, keybuf, valbuf, 0); + } + va_end(argument_list); } #define LINEAR_TO_DB(x) (log10(x) * 20) @@ -484,28 +490,28 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata) if (s->measure_perchannel & MEASURE_FLAT_FACTOR) set_meta(metadata, c + 1, "Flat_factor", "%f", LINEAR_TO_DB((p->min_runs + p->max_runs) / (p->min_count + p->max_count))); if (s->measure_perchannel & MEASURE_PEAK_COUNT) - set_meta(metadata, c + 1, "Peak_count", "%f", (float)(p->min_count + p->max_count)); + set_meta(metadata, c + 1, "Peak_count", "%"PRId64, p->min_count + p->max_count); if (s->measure_perchannel & MEASURE_NOISE_FLOOR) set_meta(metadata, c + 1, "Noise_floor", "%f", LINEAR_TO_DB(p->noise_floor)); if (s->measure_perchannel & MEASURE_NOISE_FLOOR_COUNT) - set_meta(metadata, c + 1, "Noise_floor_count", "%f", p->noise_floor_count); + set_meta(metadata, c + 1, "Noise_floor_count", "%"PRId64, p->noise_floor_count); if (s->measure_perchannel & MEASURE_BIT_DEPTH) { bit_depth(s, p->mask, p->imask, &depth); - set_meta(metadata, c + 1, "Bit_depth", "%f", depth.num); - set_meta(metadata, c + 1, "Bit_depth2", "%f", depth.den); + set_meta(metadata, c + 1, "Bit_depth", "%u", depth.num); + set_meta(metadata, c + 1, "Bit_depth2", "%u", depth.den); } if (s->measure_perchannel & MEASURE_DYNAMIC_RANGE) set_meta(metadata, c + 1, "Dynamic_range", "%f", LINEAR_TO_DB(2 * FFMAX(FFABS(p->min), FFABS(p->max))/ p->min_non_zero)); if (s->measure_perchannel & MEASURE_ZERO_CROSSINGS) - set_meta(metadata, c + 1, "Zero_crossings", "%f", p->zero_runs); + set_meta(metadata, c + 1, "Zero_crossings", "%"PRId64, p->zero_runs); if (s->measure_perchannel & MEASURE_ZERO_CROSSINGS_RATE) set_meta(metadata, c + 1, "Zero_crossings_rate", "%f", p->zero_runs/(double)p->nb_samples); if ((s->is_float || s->is_double) && s->measure_perchannel & MEASURE_NUMBER_OF_NANS) - set_meta(metadata, c + 1, "Number of NaNs", "%f", p->nb_nans); + set_meta(metadata, c + 1, "Number_of_NaNs", "%"PRId64, p->nb_nans); if ((s->is_float || s->is_double) && s->measure_perchannel & MEASURE_NUMBER_OF_INFS) - set_meta(metadata, c + 1, "Number of Infs", "%f", p->nb_infs); + set_meta(metadata, c + 1, "Number_of_Infs", "%"PRId64, p->nb_infs); if ((s->is_float || s->is_double) && s->measure_perchannel & MEASURE_NUMBER_OF_DENORMALS) - set_meta(metadata, c + 1, "Number of denormals", "%f", p->nb_denormals); + set_meta(metadata, c + 1, "Number_of_denormals", "%"PRId64, p->nb_denormals); } if (s->measure_overall & MEASURE_DC_OFFSET) @@ -540,17 +546,17 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata) set_meta(metadata, 0, "Overall.Noise_floor_count", "%f", noise_floor_count / (double)s->nb_channels); if (s->measure_overall & MEASURE_BIT_DEPTH) { bit_depth(s, mask, imask, &depth); - set_meta(metadata, 0, "Overall.Bit_depth", "%f", depth.num); - set_meta(metadata, 0, "Overall.Bit_depth2", "%f", depth.den); + set_meta(metadata, 0, "Overall.Bit_depth", "%u", depth.num); + set_meta(metadata, 0, "Overall.Bit_depth2", "%u", depth.den); } if (s->measure_overall & MEASURE_NUMBER_OF_SAMPLES) - set_meta(metadata, 0, "Overall.Number_of_samples", "%f", nb_samples / s->nb_channels); + set_meta(metadata, 0, "Overall.Number_of_samples", "%"PRId64, nb_samples / s->nb_channels); if ((s->is_float || s->is_double) && s->measure_overall & MEASURE_NUMBER_OF_NANS) - set_meta(metadata, 0, "Number of NaNs", "%f", nb_nans / (float)s->nb_channels); + set_meta(metadata, 0, "Overall.Number_of_NaNs", "%f", nb_nans / (float)s->nb_channels); if ((s->is_float || s->is_double) && s->measure_overall & MEASURE_NUMBER_OF_INFS) - set_meta(metadata, 0, "Number of Infs", "%f", nb_infs / (float)s->nb_channels); + set_meta(metadata, 0, "Overall.Number_of_Infs", "%f", nb_infs / (float)s->nb_channels); if ((s->is_float || s->is_double) && s->measure_overall & MEASURE_NUMBER_OF_DENORMALS) - set_meta(metadata, 0, "Number of denormals", "%f", nb_denormals / (float)s->nb_channels); + set_meta(metadata, 0, "Overall.Number_of_denormals", "%f", nb_denormals / (float)s->nb_channels); } #define UPDATE_STATS_P(type, update_func, update_float, channel_func) \