/* * Copyright (c) 2016, Alliance for Open Media. All rights reserved. * * This source code is subject to the terms of the BSD 2 Clause License and * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License * was not distributed with this source code in the LICENSE file, you can * obtain it at www.aomedia.org/license/software. If the Alliance for Open * Media Patent License 1.0 was not distributed with this source code in the * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/
// Determine the number of samples in the buffer. Use the file's framerate // to determine the number of frames in rc_buf_sz milliseconds, with an // adjustment (5/4) to account for alt-refs
hist->samples =
(int)((int64_t)cfg->rc_buf_sz * 5 / 4 * fps->num / fps->den / 1000);
// prevent division by zero if (hist->samples == 0) hist->samples = 1;
hist->frames = 0;
hist->total = 0;
hist->pts = calloc(hist->samples, sizeof(*hist->pts));
hist->sz = calloc(hist->samples, sizeof(*hist->sz)); if (hist->pts == NULL || hist->sz == NULL) goto fail; for (i = 0; i < RATE_BINS; i++) {
hist->bucket[i].low = INT_MAX;
hist->bucket[i].high = 0;
hist->bucket[i].count = 0;
}
return hist;
fail:
fprintf(stderr, "Warning: Unable to allocate buffers required for " "show_rate_histogram().\n" "Continuing without rate histogram feature...\n");
destroy_rate_histogram(hist); return NULL;
}
/* Sum the size over the past rc_buf_sz ms */ for (i = hist->frames; i > 0 && hist->frames - i < hist->samples; i--) { constint i_idx = (i - 1) % hist->samples;
then = hist->pts[i_idx]; if (now - then > cfg->rc_buf_sz) break;
sum_sz += hist->sz[i_idx];
}
staticint merge_hist_buckets(struct hist_bucket *bucket, int max_buckets, int *num_buckets) { int small_bucket = 0, merge_bucket = INT_MAX, big_bucket = 0; int buckets; int i;
/* Find the extrema for this list of buckets */
big_bucket = small_bucket = 0; for (i = 0; i < buckets; i++) { if (bucket[i].count < bucket[small_bucket].count) small_bucket = i; if (bucket[i].count > bucket[big_bucket].count) big_bucket = i;
}
/* If we have too many buckets, merge the smallest with an adjacent * bucket.
*/ while (buckets > max_buckets) { int last_bucket = buckets - 1;
/* merge the small bucket with an adjacent one. */ if (small_bucket == 0)
merge_bucket = 1; elseif (small_bucket == last_bucket)
merge_bucket = last_bucket - 1; elseif (bucket[small_bucket - 1].count < bucket[small_bucket + 1].count)
merge_bucket = small_bucket - 1; else
merge_bucket = small_bucket + 1;
/* Remove the merge_bucket from the list, and find the new small * and big buckets while we're at it
*/
big_bucket = small_bucket = 0; for (i = 0; i < buckets; i++) { if (i > merge_bucket) bucket[i] = bucket[i + 1];
if (bucket[i].count < bucket[small_bucket].count) small_bucket = i; if (bucket[i].count > bucket[big_bucket].count) big_bucket = i;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.