Showing the changes to libavfilter (1 of 1 file). Show all
Unified · Split
| @@ -76,7 +76,7 @@ typedef struct ChannelStats { · 75 unmodified lines | |||
| 76 | double diff1_sum; | 76 | double diff1_sum; |
| 77 | double diff1_sum_x2; | 77 | double diff1_sum_x2; |
| 78 | double abs_peak; | 78 | double abs_peak; |
| 79 | uint64_t mask, imask; | 79 | uint64_t mask[4]; |
| 80 | uint64_t min_count, max_count; | 80 | uint64_t min_count, max_count; |
| 81 | uint64_t abs_peak_count; | 81 | uint64_t abs_peak_count; |
| 82 | uint64_t noise_floor_count; | 82 | uint64_t noise_floor_count; |
| @@ -88,6 +88,7 @@ typedef struct ChannelStats { · 5 unmodified lines | |||
| 88 | double *win_samples; | 88 | double *win_samples; |
| 89 | double *sorted_samples; | 89 | double *sorted_samples; |
| 90 | uint64_t ehistogram[HISTOGRAM_SIZE]; | 90 | uint64_t ehistogram[HISTOGRAM_SIZE]; |
| 91 | int64_t lasti; | ||
| 91 | int sorted_front; | 92 | int sorted_front; |
| 92 | int sorted_back; | 93 | int sorted_back; |
| 93 | int win_pos; | 94 | int win_pos; |
| @@ -178,8 +179,10 @@ static void reset_stats(AudioStatsContext *s) · 84 unmodified lines | |||
| 178 | p->max_runs = 0; | 179 | p->max_runs = 0; |
| 179 | p->diff1_sum = 0; | 180 | p->diff1_sum = 0; |
| 180 | p->diff1_sum_x2 = 0; | 181 | p->diff1_sum_x2 = 0; |
| 181 | p->mask = 0; | 182 | p->mask[0] = 0; |
| 182 | p->imask = 0xFFFFFFFFFFFFFFFF; | 183 | p->mask[1] = 0; |
| 184 | p->mask[2] =~0; | ||
| 185 | p->mask[3] = 0; | ||
| 183 | p->min_count = 0; | 186 | p->min_count = 0; |
| 184 | p->max_count = 0; | 187 | p->max_count = 0; |
| 185 | p->abs_peak_count = 0; | 188 | p->abs_peak_count = 0; |
| @@ -239,20 +242,28 @@ static int config_output(AVFilterLink *outlink) · 53 unmodified lines | |||
| 239 | return 0; | 242 | return 0; |
| 240 | } | 243 | } |
| 241 | 244 | ||
| 242 | static void bit_depth(AudioStatsContext *s, uint64_t mask, uint64_t imask, AVRational *depth) | 245 | static void bit_depth(AudioStatsContext *s, const uint64_t *const mask, uint8_t *depth) |
| 243 | { | 246 | { |
| 244 | unsigned result = s->maxbitdepth; | 247 | unsigned result = s->maxbitdepth; |
| 248 | uint64_t amask = mask[1] & (~mask[2]); | ||
| 245 | 249 | ||
| 246 | mask = mask & (~imask); | 250 | depth[0] = 0; |
| 251 | for (int i = 0; i < result; i++) | ||
| 252 | depth[0] += !!(mask[0] & (1ULL << i)); | ||
| 247 | 253 | ||
| 248 | for (; result && !(mask & 1); --result, mask >>= 1); | 254 | depth[1] = 0; |
| 255 | for (int i = 0; i < result; i++) | ||
| 256 | depth[1] += !!(mask[1] & (1ULL << i)); | ||
| 249 | 257 | ||
| 250 | depth->den = result; | 258 | depth[2] = result; |
| 251 | depth->num = 0; | 259 | for (int i = 0; i < result && !(amask & 1); i++) { |
| 260 | depth[2]--; | ||
| 261 | amask >>= 1; | ||
| 262 | } | ||
| 252 | 263 | ||
| 253 | for (; result; --result, mask >>= 1) | 264 | depth[3] = 0; |
| 254 | if (mask & 1) | 265 | for (int i = 0; i < result; i++) |
| 255 | depth->num++; | 266 | depth[3] += !!(mask[3] & (1ULL << i)); |
| 256 | } | 267 | } |
| 257 | 268 | ||
| 258 | static double calc_entropy(AudioStatsContext *s, ChannelStats *p) | 269 | static double calc_entropy(AudioStatsContext *s, ChannelStats *p) |
| @@ -389,9 +400,13 @@ static inline void update_stat(AudioStatsContext *s, ChannelStats *p, double d, · 130 unmodified lines | |||
| 389 | p->diff1_sum += fabs(d - p->last); | 400 | p->diff1_sum += fabs(d - p->last); |
| 390 | p->diff1_sum_x2 += (d - p->last) * (d - p->last); | 401 | p->diff1_sum_x2 += (d - p->last) * (d - p->last); |
| 391 | } | 402 | } |
| 403 | p->mask[0] |= (i < 0) ? -i : i; | ||
| 404 | p->mask[1] |= i; | ||
| 405 | p->mask[2] &= i; | ||
| 406 | if (!isnan(p->last)) | ||
| 407 | p->mask[3] |= i ^ p->lasti; | ||
| 408 | p->lasti = i; | ||
| 392 | p->last = d; | 409 | p->last = d; |
| 393 | p->mask |= i; | ||
| 394 | p->imask &= i; | ||
| 395 | 410 | ||
| 396 | drop = p->win_samples[p->win_pos]; | 411 | drop = p->win_samples[p->win_pos]; |
| 397 | p->win_samples[p->win_pos] = nd; | 412 | p->win_samples[p->win_pos] = nd; |
| @@ -462,7 +477,7 @@ static void set_meta(AVDictionary **metadata, int chan, const char *key, · 64 unmodified lines | |||
| 462 | 477 | ||
| 463 | static void set_metadata(AudioStatsContext *s, AVDictionary **metadata) | 478 | static void set_metadata(AudioStatsContext *s, AVDictionary **metadata) |
| 464 | { | 479 | { |
| 465 | uint64_t mask = 0, imask = 0xFFFFFFFFFFFFFFFF, min_count = 0, max_count = 0, nb_samples = 0, noise_floor_count = 0; | 480 | uint64_t mask[4], min_count = 0, max_count = 0, nb_samples = 0, noise_floor_count = 0; |
| 466 | uint64_t nb_nans = 0, nb_infs = 0, nb_denormals = 0; | 481 | uint64_t nb_nans = 0, nb_infs = 0, nb_denormals = 0; |
| 467 | uint64_t abs_peak_count = 0; | 482 | uint64_t abs_peak_count = 0; |
| 468 | double min_runs = 0, max_runs = 0, | 483 | double min_runs = 0, max_runs = 0, |
| @@ -476,9 +491,14 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata) · 7 unmodified lines | |||
| 476 | entropy = 0, | 491 | entropy = 0, |
| 477 | min_sigma_x2 = DBL_MAX, | 492 | min_sigma_x2 = DBL_MAX, |
| 478 | max_sigma_x2 =-DBL_MAX; | 493 | max_sigma_x2 =-DBL_MAX; |
| 479 | AVRational depth; | 494 | uint8_t depth[4]; |
| 480 | int c; | 495 | int c; |
| 481 | 496 | ||
| 497 | mask[0] = 0; | ||
| 498 | mask[1] = 0; | ||
| 499 | mask[2] =~0; | ||
| 500 | mask[3] = 0; | ||
| 501 | |||
| 482 | for (c = 0; c < s->nb_channels; c++) { | 502 | for (c = 0; c < s->nb_channels; c++) { |
| 483 | ChannelStats *p = &s->chstats[c]; | 503 | ChannelStats *p = &s->chstats[c]; |
| 484 | 504 | ||
| @@ -505,8 +525,10 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata) · 20 unmodified lines | |||
| 505 | abs_peak_count += p->abs_peak_count; | 525 | abs_peak_count += p->abs_peak_count; |
| 506 | min_runs += p->min_runs; | 526 | min_runs += p->min_runs; |
| 507 | max_runs += p->max_runs; | 527 | max_runs += p->max_runs; |
| 508 | mask |= p->mask; | 528 | mask[0] |= p->mask[0]; |
| 509 | imask &= p->imask; | 529 | mask[1] |= p->mask[1]; |
| 530 | mask[2] &= p->mask[2]; | ||
| 531 | mask[3] |= p->mask[3]; | ||
| 510 | nb_samples += p->nb_samples; | 532 | nb_samples += p->nb_samples; |
| 511 | nb_nans += p->nb_nans; | 533 | nb_nans += p->nb_nans; |
| 512 | nb_infs += p->nb_infs; | 534 | nb_infs += p->nb_infs; |
| @@ -551,9 +573,11 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata) · 38 unmodified lines | |||
| 551 | if (s->measure_perchannel & MEASURE_ENTROPY) | 573 | if (s->measure_perchannel & MEASURE_ENTROPY) |
| 552 | set_meta(metadata, c + 1, "Entropy", "%f", p->entropy); | 574 | set_meta(metadata, c + 1, "Entropy", "%f", p->entropy); |
| 553 | if (s->measure_perchannel & MEASURE_BIT_DEPTH) { | 575 | if (s->measure_perchannel & MEASURE_BIT_DEPTH) { |
| 554 | bit_depth(s, p->mask, p->imask, &depth); | 576 | bit_depth(s, p->mask, depth); |
| 555 | set_meta(metadata, c + 1, "Bit_depth", "%f", depth.num); | 577 | set_meta(metadata, c + 1, "Bit_depth", "%f", depth[0]); |
| 556 | set_meta(metadata, c + 1, "Bit_depth2", "%f", depth.den); | 578 | set_meta(metadata, c + 1, "Bit_depth2", "%f", depth[1]); |
| 579 | set_meta(metadata, c + 1, "Bit_depth3", "%f", depth[2]); | ||
| 580 | set_meta(metadata, c + 1, "Bit_depth4", "%f", depth[3]); | ||
| 557 | } | 581 | } |
| 558 | if (s->measure_perchannel & MEASURE_DYNAMIC_RANGE) | 582 | if (s->measure_perchannel & MEASURE_DYNAMIC_RANGE) |
| 559 | set_meta(metadata, c + 1, "Dynamic_range", "%f", LINEAR_TO_DB(2 * FFMAX(FFABS(p->min), FFABS(p->max))/ p->min_non_zero)); | 583 | set_meta(metadata, c + 1, "Dynamic_range", "%f", LINEAR_TO_DB(2 * FFMAX(FFABS(p->min), FFABS(p->max))/ p->min_non_zero)); |
| @@ -604,9 +628,11 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata) · 44 unmodified lines | |||
| 604 | if (s->measure_overall & MEASURE_ENTROPY) | 628 | if (s->measure_overall & MEASURE_ENTROPY) |
| 605 | set_meta(metadata, 0, "Overall.Entropy", "%f", entropy / (double)s->nb_channels); | 629 | set_meta(metadata, 0, "Overall.Entropy", "%f", entropy / (double)s->nb_channels); |
| 606 | if (s->measure_overall & MEASURE_BIT_DEPTH) { | 630 | if (s->measure_overall & MEASURE_BIT_DEPTH) { |
| 607 | bit_depth(s, mask, imask, &depth); | 631 | bit_depth(s, mask, depth); |
| 608 | set_meta(metadata, 0, "Overall.Bit_depth", "%f", depth.num); | 632 | set_meta(metadata, 0, "Overall.Bit_depth", "%f", depth[0]); |
| 609 | set_meta(metadata, 0, "Overall.Bit_depth2", "%f", depth.den); | 633 | set_meta(metadata, 0, "Overall.Bit_depth2", "%f", depth[1]); |
| 634 | set_meta(metadata, 0, "Overall.Bit_depth3", "%f", depth[2]); | ||
| 635 | set_meta(metadata, 0, "Overall.Bit_depth4", "%f", depth[3]); | ||
| 610 | } | 636 | } |
| 611 | if (s->measure_overall & MEASURE_NUMBER_OF_SAMPLES) | 637 | if (s->measure_overall & MEASURE_NUMBER_OF_SAMPLES) |
| 612 | set_meta(metadata, 0, "Overall.Number_of_samples", "%f", nb_samples / s->nb_channels); | 638 | set_meta(metadata, 0, "Overall.Number_of_samples", "%f", nb_samples / s->nb_channels); |
| @@ -724,7 +750,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf) · 111 unmodified lines | |||
| 724 | static void print_stats(AVFilterContext *ctx) | 750 | static void print_stats(AVFilterContext *ctx) |
| 725 | { | 751 | { |
| 726 | AudioStatsContext *s = ctx->priv; | 752 | AudioStatsContext *s = ctx->priv; |
| 727 | uint64_t mask = 0, imask = 0xFFFFFFFFFFFFFFFF, min_count = 0, max_count = 0, nb_samples = 0, noise_floor_count = 0; | 753 | uint64_t mask[4], min_count = 0, max_count = 0, nb_samples = 0, noise_floor_count = 0; |
| 728 | uint64_t nb_nans = 0, nb_infs = 0, nb_denormals = 0, abs_peak_count = 0; | 754 | uint64_t nb_nans = 0, nb_infs = 0, nb_denormals = 0, abs_peak_count = 0; |
| 729 | double min_runs = 0, max_runs = 0, | 755 | double min_runs = 0, max_runs = 0, |
| 730 | min = DBL_MAX, max =-DBL_MAX, min_diff = DBL_MAX, max_diff = 0, | 756 | min = DBL_MAX, max =-DBL_MAX, min_diff = DBL_MAX, max_diff = 0, |
| @@ -737,9 +763,14 @@ static void print_stats(AVFilterContext *ctx) · 6 unmodified lines | |||
| 737 | entropy = 0, | 763 | entropy = 0, |
| 738 | min_sigma_x2 = DBL_MAX, | 764 | min_sigma_x2 = DBL_MAX, |
| 739 | max_sigma_x2 =-DBL_MAX; | 765 | max_sigma_x2 =-DBL_MAX; |
| 740 | AVRational depth; | 766 | uint8_t depth[4]; |
| 741 | int c; | 767 | int c; |
| 742 | 768 | ||
| 769 | mask[0] = 0; | ||
| 770 | mask[1] = 0; | ||
| 771 | mask[2] =~0; | ||
| 772 | mask[3] = 0; | ||
| 773 | |||
| 743 | for (c = 0; c < s->nb_channels; c++) { | 774 | for (c = 0; c < s->nb_channels; c++) { |
| 744 | ChannelStats *p = &s->chstats[c]; | 775 | ChannelStats *p = &s->chstats[c]; |
| 745 | 776 | ||
| @@ -769,8 +800,10 @@ static void print_stats(AVFilterContext *ctx) · 23 unmodified lines | |||
| 769 | noise_floor_count += p->noise_floor_count; | 800 | noise_floor_count += p->noise_floor_count; |
| 770 | min_runs += p->min_runs; | 801 | min_runs += p->min_runs; |
| 771 | max_runs += p->max_runs; | 802 | max_runs += p->max_runs; |
| 772 | mask |= p->mask; | 803 | mask[0] |= p->mask[0]; |
| 773 | imask &= p->imask; | 804 | mask[1] |= p->mask[1]; |
| 805 | mask[2] &= p->mask[2]; | ||
| 806 | mask[3] |= p->mask[3]; | ||
| 774 | nb_samples += p->nb_samples; | 807 | nb_samples += p->nb_samples; |
| 775 | nb_nans += p->nb_nans; | 808 | nb_nans += p->nb_nans; |
| 776 | nb_infs += p->nb_infs; | 809 | nb_infs += p->nb_infs; |
| @@ -818,8 +851,8 @@ static void print_stats(AVFilterContext *ctx) · 41 unmodified lines | |||
| 818 | if (s->measure_perchannel & MEASURE_ENTROPY) | 851 | if (s->measure_perchannel & MEASURE_ENTROPY) |
| 819 | av_log(ctx, AV_LOG_INFO, "Entropy: %f\n", p->entropy); | 852 | av_log(ctx, AV_LOG_INFO, "Entropy: %f\n", p->entropy); |
| 820 | if (s->measure_perchannel & MEASURE_BIT_DEPTH) { | 853 | if (s->measure_perchannel & MEASURE_BIT_DEPTH) { |
| 821 | bit_depth(s, p->mask, p->imask, &depth); | 854 | bit_depth(s, p->mask, depth); |
| 822 | av_log(ctx, AV_LOG_INFO, "Bit depth: %u/%u\n", depth.num, depth.den); | 855 | av_log(ctx, AV_LOG_INFO, "Bit depth: %u/%u/%u/%u\n", depth[0], depth[1], depth[2], depth[3]); |
| 823 | } | 856 | } |
| 824 | if (s->measure_perchannel & MEASURE_DYNAMIC_RANGE) | 857 | if (s->measure_perchannel & MEASURE_DYNAMIC_RANGE) |
| 825 | av_log(ctx, AV_LOG_INFO, "Dynamic range: %f\n", LINEAR_TO_DB(2 * FFMAX(FFABS(p->min), FFABS(p->max))/ p->min_non_zero)); | 858 | av_log(ctx, AV_LOG_INFO, "Dynamic range: %f\n", LINEAR_TO_DB(2 * FFMAX(FFABS(p->min), FFABS(p->max))/ p->min_non_zero)); |
| @@ -876,8 +909,8 @@ static void print_stats(AVFilterContext *ctx) · 50 unmodified lines | |||
| 876 | if (s->measure_overall & MEASURE_ENTROPY) | 909 | if (s->measure_overall & MEASURE_ENTROPY) |
| 877 | av_log(ctx, AV_LOG_INFO, "Entropy: %f\n", entropy / (double)s->nb_channels); | 910 | av_log(ctx, AV_LOG_INFO, "Entropy: %f\n", entropy / (double)s->nb_channels); |
| 878 | if (s->measure_overall & MEASURE_BIT_DEPTH) { | 911 | if (s->measure_overall & MEASURE_BIT_DEPTH) { |
| 879 | bit_depth(s, mask, imask, &depth); | 912 | bit_depth(s, mask, depth); |
| 880 | av_log(ctx, AV_LOG_INFO, "Bit depth: %u/%u\n", depth.num, depth.den); | 913 | av_log(ctx, AV_LOG_INFO, "Bit depth: %u/%u/%u/%u\n", depth[0], depth[1], depth[2], depth[3]); |
| 881 | } | 914 | } |
| 882 | if (s->measure_overall & MEASURE_NUMBER_OF_SAMPLES) | 915 | if (s->measure_overall & MEASURE_NUMBER_OF_SAMPLES) |
| 883 | av_log(ctx, AV_LOG_INFO, "Number of samples: %"PRId64"\n", nb_samples / s->nb_channels); | 916 | av_log(ctx, AV_LOG_INFO, "Number of samples: %"PRId64"\n", nb_samples / s->nb_channels); |