summaryrefslogtreecommitdiff
path: root/rate_hist.c
diff options
context:
space:
mode:
authorclang-format <noreply@google.com>2016-07-18 19:44:59 -0700
committerJames Zern <jzern@google.com>2016-07-19 14:34:19 -0700
commit033dab9ca0adb78a0ce417d5956a6caf440c7ca7 (patch)
treebe50ddb1a5235d4d3b6e5921a69f0cffd2579365 /rate_hist.c
parent6e336f6e5f623929018c2db84472f1b2f5d67a85 (diff)
downloadlibvpx-033dab9ca0adb78a0ce417d5956a6caf440c7ca7.tar.gz
top-level: apply clang-format
Change-Id: Ibd5395bf8956a80f7c0df4d539c7a42c927a1fc7
Diffstat (limited to 'rate_hist.c')
-rw-r--r--rate_hist.c61
1 files changed, 23 insertions, 38 deletions
diff --git a/rate_hist.c b/rate_hist.c
index a77222b16..872a10bae 100644
--- a/rate_hist.c
+++ b/rate_hist.c
@@ -45,8 +45,7 @@ struct rate_hist *init_rate_histogram(const vpx_codec_enc_cfg_t *cfg,
hist->samples = cfg->rc_buf_sz * 5 / 4 * fps->num / fps->den / 1000;
// prevent division by zero
- if (hist->samples == 0)
- hist->samples = 1;
+ if (hist->samples == 0) hist->samples = 1;
hist->frames = 0;
hist->total = 0;
@@ -78,18 +77,16 @@ void update_rate_histogram(struct rate_hist *hist,
int64_t avg_bitrate = 0;
int64_t sum_sz = 0;
const int64_t now = pkt->data.frame.pts * 1000 *
- (uint64_t)cfg->g_timebase.num /
- (uint64_t)cfg->g_timebase.den;
+ (uint64_t)cfg->g_timebase.num /
+ (uint64_t)cfg->g_timebase.den;
int idx = hist->frames++ % hist->samples;
hist->pts[idx] = now;
hist->sz[idx] = (int)pkt->data.frame.sz;
- if (now < cfg->rc_buf_initial_sz)
- return;
+ if (now < cfg->rc_buf_initial_sz) return;
- if (!cfg->rc_target_bitrate)
- return;
+ if (!cfg->rc_target_bitrate) return;
then = now;
@@ -98,20 +95,16 @@ void update_rate_histogram(struct rate_hist *hist,
const int i_idx = (i - 1) % hist->samples;
then = hist->pts[i_idx];
- if (now - then > cfg->rc_buf_sz)
- break;
+ if (now - then > cfg->rc_buf_sz) break;
sum_sz += hist->sz[i_idx];
}
- if (now == then)
- return;
+ if (now == then) return;
avg_bitrate = sum_sz * 8 * 1000 / (now - then);
idx = (int)(avg_bitrate * (RATE_BINS / 2) / (cfg->rc_target_bitrate * 1000));
- if (idx < 0)
- idx = 0;
- if (idx > RATE_BINS - 1)
- idx = RATE_BINS - 1;
+ if (idx < 0) idx = 0;
+ if (idx > RATE_BINS - 1) idx = RATE_BINS - 1;
if (hist->bucket[idx].low > avg_bitrate)
hist->bucket[idx].low = (int)avg_bitrate;
if (hist->bucket[idx].high < avg_bitrate)
@@ -120,8 +113,8 @@ void update_rate_histogram(struct rate_hist *hist,
hist->total++;
}
-static int merge_hist_buckets(struct hist_bucket *bucket,
- int max_buckets, int *num_buckets) {
+static int 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 = *num_buckets;
int i;
@@ -129,10 +122,8 @@ static int merge_hist_buckets(struct hist_bucket *bucket,
/* 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 (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
@@ -174,13 +165,10 @@ static int merge_hist_buckets(struct hist_bucket *bucket,
*/
big_bucket = small_bucket = 0;
for (i = 0; i < buckets; i++) {
- if (i > merge_bucket)
- bucket[i] = bucket[i + 1];
+ 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;
+ if (bucket[i].count < bucket[small_bucket].count) small_bucket = i;
+ if (bucket[i].count > bucket[big_bucket].count) big_bucket = i;
}
}
@@ -188,8 +176,8 @@ static int merge_hist_buckets(struct hist_bucket *bucket,
return bucket[big_bucket].count;
}
-static void show_histogram(const struct hist_bucket *bucket,
- int buckets, int total, int scale) {
+static void show_histogram(const struct hist_bucket *bucket, int buckets,
+ int total, int scale) {
const char *pat1, *pat2;
int i;
@@ -232,8 +220,7 @@ static void show_histogram(const struct hist_bucket *bucket,
pct = (float)(100.0 * bucket[i].count / total);
len = HIST_BAR_MAX * bucket[i].count / scale;
- if (len < 1)
- len = 1;
+ if (len < 1) len = 1;
assert(len <= HIST_BAR_MAX);
if (bucket[i].low == bucket[i].high)
@@ -241,8 +228,7 @@ static void show_histogram(const struct hist_bucket *bucket,
else
fprintf(stderr, pat2, bucket[i].low, bucket[i].high);
- for (j = 0; j < HIST_BAR_MAX; j++)
- fprintf(stderr, j < len ? "=" : " ");
+ for (j = 0; j < HIST_BAR_MAX; j++) fprintf(stderr, j < len ? "=" : " ");
fprintf(stderr, "\t%5d (%6.2f%%)\n", bucket[i].count, pct);
}
}
@@ -268,14 +254,13 @@ void show_q_histogram(const int counts[64], int max_buckets) {
show_histogram(bucket, buckets, total, scale);
}
-void show_rate_histogram(struct rate_hist *hist,
- const vpx_codec_enc_cfg_t *cfg, int max_buckets) {
+void show_rate_histogram(struct rate_hist *hist, const vpx_codec_enc_cfg_t *cfg,
+ int max_buckets) {
int i, scale;
int buckets = 0;
for (i = 0; i < RATE_BINS; i++) {
- if (hist->bucket[i].low == INT_MAX)
- continue;
+ if (hist->bucket[i].low == INT_MAX) continue;
hist->bucket[buckets++] = hist->bucket[i];
}