Commit 5802ebe6 authored by Debargha Mukherjee's avatar Debargha Mukherjee

Add code to output counts for an encode run

If --enable-entropy-stats is on, the aggregate counts for each
frame are written out to a file named counts.stt.

Change-Id: I0c73ab872183a9dbd6d767a8c6f0642c5c117253
parent be6cc07d
......@@ -518,19 +518,13 @@ void av1_loop_filter_dealloc(AV1LfSync *lf_sync) {
// Accumulate frame counts. FRAME_COUNTS consist solely of 'unsigned int'
// members, so we treat it as an array, and sum over the whole length.
void av1_accumulate_frame_counts(AV1_COMMON *cm, FRAME_COUNTS *counts) {
unsigned int *const acc = (unsigned int *)&cm->counts;
void av1_accumulate_frame_counts(FRAME_COUNTS *acc_counts,
FRAME_COUNTS *counts) {
unsigned int *const acc = (unsigned int *)acc_counts;
const unsigned int *const cnt = (unsigned int *)counts;
const unsigned int n_counts = sizeof(FRAME_COUNTS) / sizeof(unsigned int);
unsigned int i;
for (i = 0; i < n_counts; i++) acc[i] += cnt[i];
#if CONFIG_DELTA_Q
for (i = 0; i < DELTA_Q_CONTEXTS; i++) {
int j;
for (j = 0; j < 2; ++j) cm->counts.delta_q[i][j] += counts->delta_q[i][j];
}
#endif
}
......@@ -54,7 +54,7 @@ void av1_loop_filter_frame_mt(YV12_BUFFER_CONFIG *frame, struct AV1Common *cm,
int partial_frame, AVxWorker *workers,
int num_workers, AV1LfSync *lf_sync);
void av1_accumulate_frame_counts(struct AV1Common *cm,
void av1_accumulate_frame_counts(struct FRAME_COUNTS *acc_counts,
struct FRAME_COUNTS *counts);
#ifdef __cplusplus
......
......@@ -3591,7 +3591,7 @@ static const uint8_t *decode_tiles_mt(AV1Decoder *pbi, const uint8_t *data,
if (cm->refresh_frame_context == REFRESH_FRAME_CONTEXT_BACKWARD) {
for (i = 0; i < num_workers; ++i) {
TileWorkerData *const twd = (TileWorkerData *)pbi->tile_workers[i].data1;
av1_accumulate_frame_counts(cm, &twd->counts);
av1_accumulate_frame_counts(&cm->counts, &twd->counts);
}
}
......
......@@ -72,6 +72,10 @@
#include "aom_util/debug_util.h"
#endif // CONFIG_BITSTREAM_DEBUG
#if CONFIG_ENTROPY_STATS
FRAME_COUNTS aggregate_fc;
#endif // CONFIG_ENTROPY_STATS
#define AM_SEGMENT_ID_INACTIVE 7
#define AM_SEGMENT_ID_ACTIVE 0
......@@ -2186,6 +2190,9 @@ AV1_COMP *av1_create_compressor(AV1EncoderConfig *oxcf,
cpi->worst_consistency = 100.0;
}
#endif
#if CONFIG_ENTROPY_STATS
av1_zero(aggregate_fc);
#endif // CONFIG_ENTROPY_STATS
cpi->first_time_stamp_ever = INT64_MAX;
......@@ -2464,6 +2471,14 @@ void av1_remove_compressor(AV1_COMP *cpi) {
cm = &cpi->common;
if (cm->current_video_frame > 0) {
#if CONFIG_ENTROPY_STATS
if (cpi->oxcf.pass != 1) {
fprintf(stderr, "Writing counts.stt\n");
FILE *f = fopen("counts.stt", "wb");
fwrite(&aggregate_fc, sizeof(aggregate_fc), 1, f);
fclose(f);
}
#endif // CONFIG_ENTROPY_STATS
#if CONFIG_INTERNAL_STATS
aom_clear_system_state();
......@@ -4813,7 +4828,9 @@ static void encode_frame_to_data_rate(AV1_COMP *cpi, size_t *size,
for (t = 0; t < TX_SIZES; t++)
av1_full_to_model_counts(cpi->td.counts->coef[t],
cpi->td.rd_counts.coef_counts[t]);
#if CONFIG_ENTROPY_STATS
av1_accumulate_frame_counts(&aggregate_fc, &cm->counts);
#endif // CONFIG_ENTROPY_STATS
if (cm->refresh_frame_context == REFRESH_FRAME_CONTEXT_BACKWARD) {
#if CONFIG_ENTROPY
cm->partial_prob_update = 0;
......
......@@ -163,7 +163,7 @@ void av1_encode_tiles_mt(AV1_COMP *cpi) {
// Accumulate counters.
if (i < cpi->num_workers - 1) {
av1_accumulate_frame_counts(cm, thread_data->td->counts);
av1_accumulate_frame_counts(&cm->counts, thread_data->td->counts);
accumulate_rd_opt(&cpi->td, thread_data->td);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment