Unified · Split
| @@ -42,8 +42,6 @@ · 41 unmodified lines | ||
| 42 | 42 | #include "formats.h" |
| 43 | 43 | #include "internal.h" |
| 44 | 44 | |
| 45 | −#define MAX_CHANNELS 63 | |
| 46 | − | |
| 47 | 45 | #define ABS_THRES -70 ///< silence gate: we discard anything below this absolute (LUFS) threshold |
| 48 | 46 | #define ABS_UP_THRES 10 ///< upper loud limit to consider (ABS_THRES being the minimum) |
| 49 | 47 | #define HIST_GRAIN 100 ///< defines histogram precision |
| @@ -63,10 +61,10 @@ struct hist_entry { · 13 unmodified lines | ||
| 63 | 61 | }; |
| 64 | 62 | |
| 65 | 63 | struct integrator { |
| 66 | − double *cache[MAX_CHANNELS]; ///< window of filtered samples (N ms) | |
| 64 | + double **cache; ///< window of filtered samples (N ms) | |
| 67 | 65 | int cache_pos; ///< focus on the last added bin in the cache array |
| 68 | 66 | int cache_size; |
| 69 | − double sum[MAX_CHANNELS]; ///< sum of the last N ms filtered samples (cache content) | |
| 67 | + double *sum; ///< sum of the last N ms filtered samples (cache content) | |
| 70 | 68 | int filled; ///< 1 if the cache is completely filled, 0 otherwise |
| 71 | 69 | double rel_threshold; ///< relative threshold |
| 72 | 70 | double sum_kept_powers; ///< sum of the powers (weighted sums) above absolute threshold |
| @@ -111,9 +109,9 @@ typedef struct EBUR128Context { · 38 unmodified lines | ||
| 111 | 109 | |
| 112 | 110 | /* Filter caches. |
| 113 | 111 | * The mult by 3 in the following is for X[i], X[i-1] and X[i-2] */ |
| 114 | − double x[MAX_CHANNELS * 3]; ///< 3 input samples cache for each channel | |
| 115 | − double y[MAX_CHANNELS * 3]; ///< 3 pre-filter samples cache for each channel | |
| 116 | − double z[MAX_CHANNELS * 3]; ///< 3 RLB-filter samples cache for each channel | |
| 112 | + double *x; ///< 3 input samples cache for each channel | |
| 113 | + double *y; ///< 3 pre-filter samples cache for each channel | |
| 114 | + double *z; ///< 3 RLB-filter samples cache for each channel | |
| 117 | 115 | double pre_b[3]; ///< pre-filter numerator coefficients |
| 118 | 116 | double pre_a[3]; ///< pre-filter denominator coefficients |
| 119 | 117 | double rlb_b[3]; ///< rlb-filter numerator coefficients |
| @@ -430,13 +428,24 @@ static int config_audio_output(AVFilterLink *outlink) · 310 unmodified lines | ||
| 430 | 428 | AV_CH_SURROUND_DIRECT_LEFT |AV_CH_SURROUND_DIRECT_RIGHT) |
| 431 | 429 | |
| 432 | 430 | ebur128->nb_channels = nb_channels; |
| 431 | + ebur128->x = av_calloc(nb_channels, 3 * sizeof(*ebur128->x)); | |
| 432 | + ebur128->y = av_calloc(nb_channels, 3 * sizeof(*ebur128->y)); | |
| 433 | + ebur128->z = av_calloc(nb_channels, 3 * sizeof(*ebur128->z)); | |
| 433 | 434 | ebur128->ch_weighting = av_calloc(nb_channels, sizeof(*ebur128->ch_weighting)); |
| 434 | − if (!ebur128->ch_weighting) | |
| 435 | + if (!ebur128->ch_weighting || !ebur128->x || !ebur128->y || !ebur128->z) | |
| 435 | 436 | return AVERROR(ENOMEM); |
| 436 | 437 | |
| 437 | 438 | #define I400_BINS(x) ((x) * 4 / 10) |
| 438 | 439 | #define I3000_BINS(x) ((x) * 3) |
| 439 | 440 | |
| 441 | + ebur128->i400.sum = av_calloc(nb_channels, sizeof(*ebur128->i400.sum)); | |
| 442 | + ebur128->i3000.sum = av_calloc(nb_channels, sizeof(*ebur128->i3000.sum)); | |
| 443 | + ebur128->i400.cache = av_calloc(nb_channels, sizeof(*ebur128->i400.cache)); | |
| 444 | + ebur128->i3000.cache = av_calloc(nb_channels, sizeof(*ebur128->i3000.cache)); | |
| 445 | + if (!ebur128->i400.sum || !ebur128->i3000.sum || | |
| 446 | + !ebur128->i400.cache || !ebur128->i3000.cache) | |
| 447 | + return AVERROR(ENOMEM); | |
| 448 | + | |
| 440 | 449 | for (i = 0; i < nb_channels; i++) { |
| 441 | 450 | /* channel weighting */ |
| 442 | 451 | const uint64_t chl = av_channel_layout_extract_channel(outlink->channel_layout, i); |
| @@ -993,16 +1002,25 @@ static av_cold void uninit(AVFilterContext *ctx) · 550 unmodified lines | ||
| 993 | 1002 | av_log(ctx, AV_LOG_INFO, "\n"); |
| 994 | 1003 | |
| 995 | 1004 | av_freep(&ebur128->y_line_ref); |
| 1005 | + av_freep(&ebur128->x); | |
| 1006 | + av_freep(&ebur128->y); | |
| 1007 | + av_freep(&ebur128->z); | |
| 996 | 1008 | av_freep(&ebur128->ch_weighting); |
| 997 | 1009 | av_freep(&ebur128->true_peaks); |
| 998 | 1010 | av_freep(&ebur128->sample_peaks); |
| 999 | 1011 | av_freep(&ebur128->true_peaks_per_frame); |
| 1012 | + av_freep(&ebur128->i400.sum); | |
| 1013 | + av_freep(&ebur128->i3000.sum); | |
| 1000 | 1014 | av_freep(&ebur128->i400.histogram); |
| 1001 | 1015 | av_freep(&ebur128->i3000.histogram); |
| 1002 | 1016 | for (i = 0; i < ebur128->nb_channels; i++) { |
| 1003 | − av_freep(&ebur128->i400.cache[i]); | |
| 1004 | − av_freep(&ebur128->i3000.cache[i]); | |
| 1017 | + if (ebur128->i400.cache) | |
| 1018 | + av_freep(&ebur128->i400.cache[i]); | |
| 1019 | + if (ebur128->i3000.cache) | |
| 1020 | + av_freep(&ebur128->i3000.cache[i]); | |
| 1005 | 1021 | } |
| 1022 | + av_freep(&ebur128->i400.cache); | |
| 1023 | + av_freep(&ebur128->i3000.cache); | |
| 1006 | 1024 | av_frame_free(&ebur128->outpicref); |
| 1007 | 1025 | #if CONFIG_SWRESAMPLE |
| 1008 | 1026 | av_freep(&ebur128->swr_buf); |