]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/af_astats.c
avfilter: Constify all AVFilters
[ffmpeg] / libavfilter / af_astats.c
index 92368793c276ee4083ebc110bd151697a2eadcec..51a01aba2f9f1341a309b430793f9de8ff3916be 100644 (file)
  */
 
 #include <float.h>
+#include <math.h>
 
 #include "libavutil/opt.h"
 #include "audio.h"
 #include "avfilter.h"
 #include "internal.h"
 
+#define HISTOGRAM_SIZE                  8192
+#define HISTOGRAM_MAX                   (HISTOGRAM_SIZE-1)
+
 #define MEASURE_ALL                     UINT_MAX
 #define MEASURE_NONE                           0
 
 #define MEASURE_ZERO_CROSSINGS          (1 << 16)
 #define MEASURE_ZERO_CROSSINGS_RATE     (1 << 17)
 #define MEASURE_NUMBER_OF_SAMPLES       (1 << 18)
+#define MEASURE_NUMBER_OF_NANS          (1 << 19)
+#define MEASURE_NUMBER_OF_INFS          (1 << 20)
+#define MEASURE_NUMBER_OF_DENORMALS     (1 << 21)
+#define MEASURE_NOISE_FLOOR             (1 << 22)
+#define MEASURE_NOISE_FLOOR_COUNT       (1 << 23)
 
 #define MEASURE_MINMAXPEAK              (MEASURE_MIN_LEVEL | MEASURE_MAX_LEVEL | MEASURE_PEAK_LEVEL)
 
@@ -66,8 +75,17 @@ typedef struct ChannelStats {
     double diff1_sum_x2;
     uint64_t mask, imask;
     uint64_t min_count, max_count;
+    uint64_t noise_floor_count;
     uint64_t zero_runs;
     uint64_t nb_samples;
+    uint64_t nb_nans;
+    uint64_t nb_infs;
+    uint64_t nb_denormals;
+    double *win_samples;
+    unsigned histogram[HISTOGRAM_SIZE];
+    int win_pos;
+    int max_index;
+    double noise_floor;
 } ChannelStats;
 
 typedef struct AudioStatsContext {
@@ -83,6 +101,8 @@ typedef struct AudioStatsContext {
     int maxbitdepth;
     int measure_perchannel;
     int measure_overall;
+    int is_float;
+    int is_double;
 } AudioStatsContext;
 
 #define OFFSET(x) offsetof(AudioStatsContext, x)
@@ -113,7 +133,12 @@ static const AVOption astats_options[] = {
       { "Dynamic_range"             , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_DYNAMIC_RANGE       }, 0, 0, FLAGS, "measure" },
       { "Zero_crossings"            , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_ZERO_CROSSINGS      }, 0, 0, FLAGS, "measure" },
       { "Zero_crossings_rate"       , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_ZERO_CROSSINGS_RATE }, 0, 0, FLAGS, "measure" },
+      { "Noise_floor"               , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_NOISE_FLOOR         }, 0, 0, FLAGS, "measure" },
+      { "Noise_floor_count"         , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_NOISE_FLOOR_COUNT   }, 0, 0, FLAGS, "measure" },
       { "Number_of_samples"         , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_NUMBER_OF_SAMPLES   }, 0, 0, FLAGS, "measure" },
+      { "Number_of_NaNs"            , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_NUMBER_OF_NANS      }, 0, 0, FLAGS, "measure" },
+      { "Number_of_Infs"            , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_NUMBER_OF_INFS      }, 0, 0, FLAGS, "measure" },
+      { "Number_of_denormals"       , "", 0, AV_OPT_TYPE_CONST, {.i64=MEASURE_NUMBER_OF_DENORMALS }, 0, 0, FLAGS, "measure" },
     { "measure_overall", "only measure_perchannel these overall statistics", OFFSET(measure_overall), AV_OPT_TYPE_FLAGS, {.i64=MEASURE_ALL}, 0, UINT_MAX, FLAGS, "measure" },
     { NULL }
 };
@@ -162,10 +187,10 @@ static void reset_stats(AudioStatsContext *s)
         ChannelStats *p = &s->chstats[c];
 
         p->min = p->nmin = p->min_sigma_x2 = DBL_MAX;
-        p->max = p->nmax = p->max_sigma_x2 = DBL_MIN;
+        p->max = p->nmax = p->max_sigma_x2 =-DBL_MAX;
         p->min_non_zero = DBL_MAX;
         p->min_diff = DBL_MAX;
-        p->max_diff = DBL_MIN;
+        p->max_diff = 0;
         p->sigma_x = 0;
         p->sigma_x2 = 0;
         p->avg_sigma_x2 = 0;
@@ -181,6 +206,15 @@ static void reset_stats(AudioStatsContext *s)
         p->max_count = 0;
         p->zero_runs = 0;
         p->nb_samples = 0;
+        p->nb_nans = 0;
+        p->nb_infs = 0;
+        p->nb_denormals = 0;
+        p->last = NAN;
+        p->noise_floor = NAN;
+        p->noise_floor_count = 0;
+        p->win_pos = 0;
+        memset(p->win_samples, 0, s->tc_samples * sizeof(*p->win_samples));
+        memset(p->histogram, 0, sizeof(p->histogram));
     }
 }
 
@@ -191,11 +225,26 @@ static int config_output(AVFilterLink *outlink)
     s->chstats = av_calloc(sizeof(*s->chstats), outlink->channels);
     if (!s->chstats)
         return AVERROR(ENOMEM);
+
+    s->tc_samples = 5 * s->time_constant * outlink->sample_rate + .5;
     s->nb_channels = outlink->channels;
+
+    for (int i = 0; i < s->nb_channels; i++) {
+        ChannelStats *p = &s->chstats[i];
+
+        p->win_samples = av_calloc(s->tc_samples, sizeof(*p->win_samples));
+        if (!p->win_samples)
+            return AVERROR(ENOMEM);
+    }
+
     s->mult = exp((-1 / s->time_constant / outlink->sample_rate));
-    s->tc_samples = 5 * s->time_constant * outlink->sample_rate + .5;
     s->nb_frames = 0;
     s->maxbitdepth = av_get_bytes_per_sample(outlink->format) * 8;
+    s->is_double = outlink->format == AV_SAMPLE_FMT_DBL  ||
+                   outlink->format == AV_SAMPLE_FMT_DBLP;
+
+    s->is_float = outlink->format == AV_SAMPLE_FMT_FLT  ||
+                  outlink->format == AV_SAMPLE_FMT_FLTP;
 
     reset_stats(s);
 
@@ -228,6 +277,9 @@ static inline void update_minmax(AudioStatsContext *s, ChannelStats *p, double d
 
 static inline void update_stat(AudioStatsContext *s, ChannelStats *p, double d, double nd, int64_t i)
 {
+    double drop;
+    int index;
+
     if (d < p->min) {
         p->min = d;
         p->nmin = nd;
@@ -265,14 +317,54 @@ static inline void update_stat(AudioStatsContext *s, ChannelStats *p, double d,
     p->sigma_x += nd;
     p->sigma_x2 += nd * nd;
     p->avg_sigma_x2 = p->avg_sigma_x2 * s->mult + (1.0 - s->mult) * nd * nd;
-    p->min_diff = FFMIN(p->min_diff, fabs(d - p->last));
-    p->max_diff = FFMAX(p->max_diff, fabs(d - p->last));
-    p->diff1_sum += fabs(d - p->last);
-    p->diff1_sum_x2 += (d - p->last) * (d - p->last);
+    if (!isnan(p->last)) {
+        p->min_diff = FFMIN(p->min_diff, fabs(d - p->last));
+        p->max_diff = FFMAX(p->max_diff, fabs(d - p->last));
+        p->diff1_sum += fabs(d - p->last);
+        p->diff1_sum_x2 += (d - p->last) * (d - p->last);
+    }
     p->last = d;
     p->mask |= i;
     p->imask &= i;
 
+    drop = p->win_samples[p->win_pos];
+    p->win_samples[p->win_pos] = nd;
+    index = av_clip(lrint(av_clipd(FFABS(nd), 0.0, 1.0) * HISTOGRAM_MAX), 0, HISTOGRAM_MAX);
+    p->max_index = FFMAX(p->max_index, index);
+    p->histogram[index]++;
+    if (!isnan(p->noise_floor))
+        p->histogram[av_clip(lrint(av_clipd(FFABS(drop), 0.0, 1.0) * HISTOGRAM_MAX), 0, HISTOGRAM_MAX)]--;
+    p->win_pos++;
+
+    while (p->histogram[p->max_index] == 0)
+        p->max_index--;
+    if (p->win_pos >= s->tc_samples || !isnan(p->noise_floor)) {
+        double noise_floor = 1.;
+
+        for (int i = p->max_index; i >= 0; i--) {
+            if (p->histogram[i]) {
+                noise_floor = i / (double)HISTOGRAM_MAX;
+                break;
+            }
+        }
+
+        if (isnan(p->noise_floor)) {
+            p->noise_floor = noise_floor;
+            p->noise_floor_count = 1;
+        } else {
+            if (noise_floor < p->noise_floor) {
+                p->noise_floor = noise_floor;
+                p->noise_floor_count = 1;
+            } else if (noise_floor == p->noise_floor) {
+                p->noise_floor_count++;
+            }
+        }
+    }
+
+    if (p->win_pos >= s->tc_samples) {
+        p->win_pos = 0;
+    }
+
     if (p->nb_samples >= s->tc_samples) {
         p->max_sigma_x2 = FFMAX(p->max_sigma_x2, p->avg_sigma_x2);
         p->min_sigma_x2 = FFMIN(p->min_sigma_x2, p->avg_sigma_x2);
@@ -280,6 +372,24 @@ static inline void update_stat(AudioStatsContext *s, ChannelStats *p, double d,
     p->nb_samples++;
 }
 
+static inline void update_float_stat(AudioStatsContext *s, ChannelStats *p, float d)
+{
+    int type = fpclassify(d);
+
+    p->nb_nans      += type == FP_NAN;
+    p->nb_infs      += type == FP_INFINITE;
+    p->nb_denormals += type == FP_SUBNORMAL;
+}
+
+static inline void update_double_stat(AudioStatsContext *s, ChannelStats *p, double d)
+{
+    int type = fpclassify(d);
+
+    p->nb_nans      += type == FP_NAN;
+    p->nb_infs      += type == FP_INFINITE;
+    p->nb_denormals += type == FP_SUBNORMAL;
+}
+
 static void set_meta(AVDictionary **metadata, int chan, const char *key,
                      const char *fmt, double val)
 {
@@ -298,17 +408,19 @@ static void set_meta(AVDictionary **metadata, int chan, const char *key,
 
 static void set_metadata(AudioStatsContext *s, AVDictionary **metadata)
 {
-    uint64_t mask = 0, imask = 0xFFFFFFFFFFFFFFFF, min_count = 0, max_count = 0, nb_samples = 0;
+    uint64_t mask = 0, imask = 0xFFFFFFFFFFFFFFFF, min_count = 0, max_count = 0, nb_samples = 0, noise_floor_count = 0;
+    uint64_t nb_nans = 0, nb_infs = 0, nb_denormals = 0;
     double min_runs = 0, max_runs = 0,
-           min = DBL_MAX, max = DBL_MIN, min_diff = DBL_MAX, max_diff = 0,
-           nmin = DBL_MAX, nmax = DBL_MIN,
+           min = DBL_MAX, max =-DBL_MAX, min_diff = DBL_MAX, max_diff = 0,
+           nmin = DBL_MAX, nmax =-DBL_MAX,
            max_sigma_x = 0,
            diff1_sum = 0,
            diff1_sum_x2 = 0,
            sigma_x = 0,
            sigma_x2 = 0,
+           noise_floor = 0,
            min_sigma_x2 = DBL_MAX,
-           max_sigma_x2 = DBL_MIN;
+           max_sigma_x2 =-DBL_MAX;
     AVRational depth;
     int c;
 
@@ -330,6 +442,8 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata)
         max_sigma_x2 = FFMAX(max_sigma_x2, p->max_sigma_x2);
         sigma_x += p->sigma_x;
         sigma_x2 += p->sigma_x2;
+        noise_floor = FFMAX(noise_floor, p->noise_floor);
+        noise_floor_count += p->noise_floor_count;
         min_count += p->min_count;
         max_count += p->max_count;
         min_runs += p->min_runs;
@@ -337,6 +451,9 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata)
         mask |= p->mask;
         imask &= p->imask;
         nb_samples += p->nb_samples;
+        nb_nans += p->nb_nans;
+        nb_infs += p->nb_infs;
+        nb_denormals += p->nb_denormals;
         if (fabs(p->sigma_x) > fabs(max_sigma_x))
             max_sigma_x = p->sigma_x;
 
@@ -368,6 +485,10 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata)
             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));
+        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);
         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);
@@ -379,6 +500,12 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata)
             set_meta(metadata, c + 1, "Zero_crossings", "%f", 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);
+        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);
+        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);
     }
 
     if (s->measure_overall & MEASURE_DC_OFFSET)
@@ -407,6 +534,10 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata)
         set_meta(metadata, 0, "Overall.Flat_factor", "%f", LINEAR_TO_DB((min_runs + max_runs) / (min_count + max_count)));
     if (s->measure_overall & MEASURE_PEAK_COUNT)
         set_meta(metadata, 0, "Overall.Peak_count", "%f", (float)(min_count + max_count) / (double)s->nb_channels);
+    if (s->measure_overall & MEASURE_NOISE_FLOOR)
+        set_meta(metadata, 0, "Overall.Noise_floor", "%f", LINEAR_TO_DB(noise_floor));
+    if (s->measure_overall & MEASURE_NOISE_FLOOR_COUNT)
+        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);
@@ -414,50 +545,55 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata)
     }
     if (s->measure_overall & MEASURE_NUMBER_OF_SAMPLES)
         set_meta(metadata, 0, "Overall.Number_of_samples", "%f", 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);
+    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);
+    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);
 }
 
-#define UPDATE_STATS_P(type, update_func, channel_func)                         \
-    for (int c = 0; c < channels; c++) {                                        \
+#define UPDATE_STATS_P(type, update_func, update_float, channel_func)           \
+    for (int c = start; c < end; c++) {                                         \
         ChannelStats *p = &s->chstats[c];                                       \
         const type *src = (const type *)data[c];                                \
         const type * const srcend = src + samples;                              \
-        for (; src < srcend; src++)                                             \
+        for (; src < srcend; src++) {                                           \
             update_func;                                                        \
+            update_float;                                                       \
+        }                                                                       \
         channel_func;                                                           \
     }
 
-#define UPDATE_STATS_I(type, update_func, channel_func)                         \
-    for (int c = 0; c < channels; c++) {                                        \
+#define UPDATE_STATS_I(type, update_func, update_float, channel_func)           \
+    for (int c = start; c < end; 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)                           \
+        for (src += c; src < srcend; src += channels) {                         \
             update_func;                                                        \
+            update_float;                                                       \
+        }                                                                       \
         channel_func;                                                           \
     }
 
 #define UPDATE_STATS(planar, type, 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), );    \
+        UPDATE_STATS_##planar(type, update_stat(s, p, sample, sample normalizer_suffix, int_sample), s->is_float ? update_float_stat(s, p, sample) : s->is_double ? update_double_stat(s, p, sample) : (void)NULL, ); \
     } else {                                                                                           \
-        UPDATE_STATS_##planar(type, update_minmax(s, p, sample), p->nmin = p->min normalizer_suffix; p->nmax = p->max normalizer_suffix;); \
+        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)
+static int filter_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
 {
-    AudioStatsContext *s = inlink->dst->priv;
-    AVDictionary **metadata = &buf->metadata;
+    AudioStatsContext *s = ctx->priv;
+    AVFilterLink *inlink = ctx->inputs[0];
+    AVFrame *buf = arg;
+    const uint8_t * const * const data = (const uint8_t * const *)buf->extended_data;
     const int channels = s->nb_channels;
     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) {
-            reset_stats(s);
-            s->nb_frames = 0;
-        }
-        s->nb_frames++;
-    }
+    const int start = (buf->channels * jobnr) / nb_jobs;
+    const int end = (buf->channels * (jobnr+1)) / nb_jobs;
 
     switch (inlink->format) {
     case AV_SAMPLE_FMT_DBLP:
@@ -492,6 +628,25 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
         break;
     }
 
+    return 0;
+}
+
+static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
+{
+    AVFilterContext *ctx = inlink->dst;
+    AudioStatsContext *s = ctx->priv;
+    AVDictionary **metadata = &buf->metadata;
+
+    if (s->reset_count > 0) {
+        if (s->nb_frames >= s->reset_count) {
+            reset_stats(s);
+            s->nb_frames = 0;
+        }
+        s->nb_frames++;
+    }
+
+    ctx->internal->execute(ctx, filter_channel, buf, NULL, FFMIN(inlink->channels, ff_filter_get_nb_threads(ctx)));
+
     if (s->metadata)
         set_metadata(s, metadata);
 
@@ -501,17 +656,19 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
 static void print_stats(AVFilterContext *ctx)
 {
     AudioStatsContext *s = ctx->priv;
-    uint64_t mask = 0, imask = 0xFFFFFFFFFFFFFFFF, min_count = 0, max_count = 0, nb_samples = 0;
+    uint64_t mask = 0, imask = 0xFFFFFFFFFFFFFFFF, min_count = 0, max_count = 0, nb_samples = 0, noise_floor_count = 0;
+    uint64_t nb_nans = 0, nb_infs = 0, nb_denormals = 0;
     double min_runs = 0, max_runs = 0,
-           min = DBL_MAX, max = DBL_MIN, min_diff = DBL_MAX, max_diff = 0,
-           nmin = DBL_MAX, nmax = DBL_MIN,
+           min = DBL_MAX, max =-DBL_MAX, min_diff = DBL_MAX, max_diff = 0,
+           nmin = DBL_MAX, nmax =-DBL_MAX,
            max_sigma_x = 0,
            diff1_sum_x2 = 0,
            diff1_sum = 0,
            sigma_x = 0,
            sigma_x2 = 0,
+           noise_floor = 0,
            min_sigma_x2 = DBL_MAX,
-           max_sigma_x2 = DBL_MIN;
+           max_sigma_x2 =-DBL_MAX;
     AVRational depth;
     int c;
 
@@ -533,13 +690,18 @@ static void print_stats(AVFilterContext *ctx)
         max_sigma_x2 = FFMAX(max_sigma_x2, p->max_sigma_x2);
         sigma_x += p->sigma_x;
         sigma_x2 += p->sigma_x2;
+        noise_floor = FFMAX(noise_floor, p->noise_floor);
         min_count += p->min_count;
         max_count += p->max_count;
+        noise_floor_count += p->noise_floor_count;
         min_runs += p->min_runs;
         max_runs += p->max_runs;
         mask |= p->mask;
         imask &= p->imask;
         nb_samples += p->nb_samples;
+        nb_nans += p->nb_nans;
+        nb_infs += p->nb_infs;
+        nb_denormals += p->nb_denormals;
         if (fabs(p->sigma_x) > fabs(max_sigma_x))
             max_sigma_x = p->sigma_x;
 
@@ -573,6 +735,10 @@ static void print_stats(AVFilterContext *ctx)
             av_log(ctx, AV_LOG_INFO, "Flat factor: %f\n", LINEAR_TO_DB((p->min_runs + p->max_runs) / (p->min_count + p->max_count)));
         if (s->measure_perchannel & MEASURE_PEAK_COUNT)
             av_log(ctx, AV_LOG_INFO, "Peak count: %"PRId64"\n", p->min_count + p->max_count);
+        if (s->measure_perchannel & MEASURE_NOISE_FLOOR)
+            av_log(ctx, AV_LOG_INFO, "Noise floor dB: %f\n", LINEAR_TO_DB(p->noise_floor));
+        if (s->measure_perchannel & MEASURE_NOISE_FLOOR_COUNT)
+            av_log(ctx, AV_LOG_INFO, "Noise floor count: %"PRId64"\n", p->noise_floor_count);
         if (s->measure_perchannel & MEASURE_BIT_DEPTH) {
             bit_depth(s, p->mask, p->imask, &depth);
             av_log(ctx, AV_LOG_INFO, "Bit depth: %u/%u\n", depth.num, depth.den);
@@ -583,6 +749,12 @@ static void print_stats(AVFilterContext *ctx)
             av_log(ctx, AV_LOG_INFO, "Zero crossings: %"PRId64"\n", p->zero_runs);
         if (s->measure_perchannel & MEASURE_ZERO_CROSSINGS_RATE)
             av_log(ctx, AV_LOG_INFO, "Zero crossings rate: %f\n", p->zero_runs/(double)p->nb_samples);
+        if ((s->is_float || s->is_double) && s->measure_perchannel & MEASURE_NUMBER_OF_NANS)
+            av_log(ctx, AV_LOG_INFO, "Number of NaNs: %"PRId64"\n", p->nb_nans);
+        if ((s->is_float || s->is_double) && s->measure_perchannel & MEASURE_NUMBER_OF_INFS)
+            av_log(ctx, AV_LOG_INFO, "Number of Infs: %"PRId64"\n", p->nb_infs);
+        if ((s->is_float || s->is_double) && s->measure_perchannel & MEASURE_NUMBER_OF_DENORMALS)
+            av_log(ctx, AV_LOG_INFO, "Number of denormals: %"PRId64"\n", p->nb_denormals);
     }
 
     av_log(ctx, AV_LOG_INFO, "Overall\n");
@@ -613,12 +785,22 @@ static void print_stats(AVFilterContext *ctx)
         av_log(ctx, AV_LOG_INFO, "Flat factor: %f\n", LINEAR_TO_DB((min_runs + max_runs) / (min_count + max_count)));
     if (s->measure_overall & MEASURE_PEAK_COUNT)
         av_log(ctx, AV_LOG_INFO, "Peak count: %f\n", (min_count + max_count) / (double)s->nb_channels);
+    if (s->measure_overall & MEASURE_NOISE_FLOOR)
+        av_log(ctx, AV_LOG_INFO, "Noise floor dB: %f\n", LINEAR_TO_DB(noise_floor));
+    if (s->measure_overall & MEASURE_NOISE_FLOOR_COUNT)
+        av_log(ctx, AV_LOG_INFO, "Noise floor count: %f\n", noise_floor_count / (double)s->nb_channels);
     if (s->measure_overall & MEASURE_BIT_DEPTH) {
         bit_depth(s, mask, imask, &depth);
         av_log(ctx, AV_LOG_INFO, "Bit depth: %u/%u\n", depth.num, depth.den);
     }
     if (s->measure_overall & MEASURE_NUMBER_OF_SAMPLES)
         av_log(ctx, AV_LOG_INFO, "Number of samples: %"PRId64"\n", nb_samples / s->nb_channels);
+    if ((s->is_float || s->is_double) && s->measure_overall & MEASURE_NUMBER_OF_NANS)
+        av_log(ctx, AV_LOG_INFO, "Number of NaNs: %f\n", nb_nans / (float)s->nb_channels);
+    if ((s->is_float || s->is_double) && s->measure_overall & MEASURE_NUMBER_OF_INFS)
+        av_log(ctx, AV_LOG_INFO, "Number of Infs: %f\n", nb_infs / (float)s->nb_channels);
+    if ((s->is_float || s->is_double) && s->measure_overall & MEASURE_NUMBER_OF_DENORMALS)
+        av_log(ctx, AV_LOG_INFO, "Number of denormals: %f\n", nb_denormals / (float)s->nb_channels);
 }
 
 static av_cold void uninit(AVFilterContext *ctx)
@@ -627,6 +809,13 @@ static av_cold void uninit(AVFilterContext *ctx)
 
     if (s->nb_channels)
         print_stats(ctx);
+    if (s->chstats) {
+        for (int i = 0; i < s->nb_channels; i++) {
+            ChannelStats *p = &s->chstats[i];
+
+            av_freep(&p->win_samples);
+        }
+    }
     av_freep(&s->chstats);
 }
 
@@ -648,7 +837,7 @@ static const AVFilterPad astats_outputs[] = {
     { NULL }
 };
 
-AVFilter ff_af_astats = {
+const AVFilter ff_af_astats = {
     .name          = "astats",
     .description   = NULL_IF_CONFIG_SMALL("Show time domain statistics about audio frames."),
     .query_formats = query_formats,
@@ -657,4 +846,5 @@ AVFilter ff_af_astats = {
     .uninit        = uninit,
     .inputs        = astats_inputs,
     .outputs       = astats_outputs,
+    .flags         = AVFILTER_FLAG_SLICE_THREADS,
 };