Commit 9b0f7038 authored by Yaowu Xu's avatar Yaowu Xu
Browse files

Prevent redundant down converting operation

Adds a flag "buf_8bit_valid" to indicate if buf_8bit is synchronized
with HBD buffer, the flag is then used to avoid possible redundant
operation in down conversion the hbd buffer to buf_8bit.

Also this commit also moves the operation to prepare source frame for
coding outside of recode loop to avoid duplicate operations there.

Change-Id: I67a1eb408b75bb734bd8a16fe6ffbd58c93a230f
parent 7d30b4a6
......@@ -59,6 +59,7 @@ typedef struct yv12_buffer_config {
// If the frame is stored in a 16-bit buffer, this stores an 8-bit version
// for use in global motion detection. It is allocated on-demand.
uint8_t *y_buffer_8bit;
int buf_8bit_valid;
#endif
uint8_t *buffer_alloc;
......
......@@ -4147,6 +4147,9 @@ static void encode_without_recode_loop(AV1_COMP *cpi) {
if (cpi->unscaled_last_source != NULL)
cpi->last_source = av1_scale_if_required(cm, cpi->unscaled_last_source,
&cpi->scaled_last_source);
#if CONFIG_HIGHBITDEPTH && CONFIG_GLOBAL_MOTION
cpi->source->buf_8bit_valid = 0;
#endif
if (frame_is_intra_only(cm) == 0) {
av1_scale_references(cpi);
......@@ -4200,6 +4203,15 @@ static void encode_with_recode_loop(AV1_COMP *cpi, size_t *size,
set_size_independent_vars(cpi);
cpi->source =
av1_scale_if_required(cm, cpi->unscaled_source, &cpi->scaled_source);
if (cpi->unscaled_last_source != NULL)
cpi->last_source = av1_scale_if_required(cm, cpi->unscaled_last_source,
&cpi->scaled_last_source);
#if CONFIG_HIGHBITDEPTH && CONFIG_GLOBAL_MOTION
cpi->source->buf_8bit_valid = 0;
#endif
do {
aom_clear_system_state();
......@@ -4230,19 +4242,12 @@ static void encode_with_recode_loop(AV1_COMP *cpi, size_t *size,
&frame_over_shoot_limit);
}
cpi->source =
av1_scale_if_required(cm, cpi->unscaled_source, &cpi->scaled_source);
if (cpi->unscaled_last_source != NULL)
cpi->last_source = av1_scale_if_required(cm, cpi->unscaled_last_source,
&cpi->scaled_last_source);
if (frame_is_intra_only(cm) == 0) {
if (loop_count > 0) {
release_scaled_references(cpi);
}
av1_scale_references(cpi);
}
av1_set_quantizer(cm, q);
if (loop_count == 0) setup_frame(cpi);
......@@ -5893,7 +5898,9 @@ int av1_get_compressed_data(AV1_COMP *cpi, unsigned int *frame_flags,
if (cm->new_fb_idx == INVALID_IDX) return -1;
cm->cur_frame = &pool->frame_bufs[cm->new_fb_idx];
#if CONFIG_HIGHBITDEPTH && CONFIG_GLOBAL_MOTION
cm->cur_frame->buf.buf_8bit_valid = 0;
#endif
#if CONFIG_EXT_REFS
#if !CONFIG_ALTREF2
if (oxcf->pass == 2) {
......
......@@ -246,10 +246,15 @@ static unsigned char *downconvert_frame(YV12_BUFFER_CONFIG *frm,
uint16_t *orig_buf = CONVERT_TO_SHORTPTR(frm->y_buffer);
uint8_t *buf_8bit = frm->y_buffer_8bit;
assert(buf_8bit);
for (i = 0; i < frm->y_height; ++i)
for (j = 0; j < frm->y_width; ++j)
buf_8bit[i * frm->y_stride + j] =
orig_buf[i * frm->y_stride + j] >> (bit_depth - 8);
if (!frm->buf_8bit_valid) {
for (i = 0; i < frm->y_height; ++i) {
for (j = 0; j < frm->y_width; ++j) {
buf_8bit[i * frm->y_stride + j] =
orig_buf[i * frm->y_stride + j] >> (bit_depth - 8);
}
}
frm->buf_8bit_valid = 1;
}
return buf_8bit;
}
#endif
......
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