Combining fb_idx_ref_cnt[] and yv12_fb[] arrays.

Adding new RefCntBuffer struct which contains reference counter and image
buffer.

Change-Id: I71c1f532faa13442c32c43fc03ec45b6f88fb844
This commit is contained in:
Dmitry Kovalev 2014-01-29 12:48:01 -08:00
parent 99d39e5b99
commit 6332063475
7 changed files with 55 additions and 47 deletions

View File

@ -34,7 +34,7 @@ void vp9_free_frame_buffers(VP9_COMMON *cm) {
int i;
for (i = 0; i < FRAME_BUFFERS; i++)
vp9_free_frame_buffer(&cm->yv12_fb[i]);
vp9_free_frame_buffer(&cm->frame_bufs[i].buf);
vp9_free_frame_buffer(&cm->post_proc_buffer);
@ -140,18 +140,18 @@ int vp9_alloc_frame_buffers(VP9_COMMON *cm, int width, int height) {
vp9_free_frame_buffers(cm);
for (i = 0; i < FRAME_BUFFERS; i++) {
cm->fb_idx_ref_cnt[i] = 0;
if (vp9_alloc_frame_buffer(&cm->yv12_fb[i], width, height, ss_x, ss_y,
VP9_ENC_BORDER_IN_PIXELS) < 0)
cm->frame_bufs[i].ref_count = 0;
if (vp9_alloc_frame_buffer(&cm->frame_bufs[i].buf, width, height,
ss_x, ss_y, VP9_ENC_BORDER_IN_PIXELS) < 0)
goto fail;
}
cm->new_fb_idx = FRAME_BUFFERS - 1;
cm->fb_idx_ref_cnt[cm->new_fb_idx] = 1;
cm->frame_bufs[cm->new_fb_idx].ref_count = 1;
for (i = 0; i < REF_FRAMES; i++) {
cm->ref_frame_map[i] = i;
cm->fb_idx_ref_cnt[i] = 1;
cm->frame_bufs[i].ref_count = 1;
}
if (vp9_alloc_frame_buffer(&cm->post_proc_buffer, width, height, ss_x, ss_y,

View File

@ -91,6 +91,12 @@ typedef enum {
REFERENCE_MODES = 3,
} REFERENCE_MODE;
typedef struct {
int ref_count;
YV12_BUFFER_CONFIG buf;
} RefCntBuffer;
typedef struct VP9Common {
struct vpx_internal_error_info error;
@ -117,8 +123,8 @@ typedef struct VP9Common {
YV12_BUFFER_CONFIG *frame_to_show;
YV12_BUFFER_CONFIG yv12_fb[FRAME_BUFFERS];
int fb_idx_ref_cnt[FRAME_BUFFERS]; /* reference counts */
RefCntBuffer frame_bufs[FRAME_BUFFERS];
int ref_frame_map[REF_FRAMES]; /* maps fb_idx to reference slot */
// TODO(jkoleszar): could expand active_ref_idx to 4, with 0 as intra, and
@ -220,29 +226,29 @@ typedef struct VP9Common {
} VP9_COMMON;
static YV12_BUFFER_CONFIG *get_frame_new_buffer(VP9_COMMON *cm) {
return &cm->yv12_fb[cm->new_fb_idx];
return &cm->frame_bufs[cm->new_fb_idx].buf;
}
static int get_free_fb(VP9_COMMON *cm) {
int i;
for (i = 0; i < FRAME_BUFFERS; i++)
if (cm->fb_idx_ref_cnt[i] == 0)
if (cm->frame_bufs[i].ref_count == 0)
break;
assert(i < FRAME_BUFFERS);
cm->fb_idx_ref_cnt[i] = 1;
cm->frame_bufs[i].ref_count = 1;
return i;
}
static void ref_cnt_fb(int *buf, int *idx, int new_idx) {
static void ref_cnt_fb(RefCntBuffer *bufs, int *idx, int new_idx) {
const int ref_index = *idx;
if (ref_index >= 0 && buf[ref_index] > 0)
buf[ref_index]--;
if (ref_index >= 0 && bufs[ref_index].ref_count > 0)
bufs[ref_index].ref_count--;
*idx = new_idx;
buf[new_idx]++;
bufs[new_idx].ref_count++;
}
static int mi_cols_aligned_to_sb(int n_mis) {

View File

@ -1117,7 +1117,7 @@ static size_t read_uncompressed_header(VP9D_COMP *pbi,
if (cm->show_existing_frame) {
// Show an existing frame directly.
int frame_to_show = cm->ref_frame_map[vp9_rb_read_literal(rb, 3)];
ref_cnt_fb(cm->fb_idx_ref_cnt, &cm->new_fb_idx, frame_to_show);
ref_cnt_fb(cm->frame_bufs, &cm->new_fb_idx, frame_to_show);
pbi->refresh_frame_flags = 0;
cm->lf.filter_level = 0;
cm->show_frame = 1;
@ -1177,7 +1177,7 @@ static size_t read_uncompressed_header(VP9D_COMP *pbi,
const int ref = vp9_rb_read_literal(rb, REF_FRAMES_LOG2);
const int idx = cm->ref_frame_map[ref];
cm->frame_refs[i].idx = idx;
cm->frame_refs[i].buf = &cm->yv12_fb[idx];
cm->frame_refs[i].buf = &cm->frame_bufs[idx].buf;
cm->ref_frame_sign_bias[LAST_FRAME + i] = vp9_rb_read_bit(rb);
}

View File

@ -183,7 +183,8 @@ void vp9_remove_decompressor(VP9D_PTR ptr) {
vpx_free(pbi);
}
static int equal_dimensions(YV12_BUFFER_CONFIG *a, YV12_BUFFER_CONFIG *b) {
static int equal_dimensions(const YV12_BUFFER_CONFIG *a,
const YV12_BUFFER_CONFIG *b) {
return a->y_height == b->y_height && a->y_width == b->y_width &&
a->uv_height == b->uv_height && a->uv_width == b->uv_width;
}
@ -200,7 +201,8 @@ vpx_codec_err_t vp9_copy_reference_dec(VP9D_PTR ptr,
* later commit that adds VP9-specific controls for this functionality.
*/
if (ref_frame_flag == VP9_LAST_FLAG) {
YV12_BUFFER_CONFIG *cfg = &cm->yv12_fb[cm->ref_frame_map[0]];
const YV12_BUFFER_CONFIG *const cfg =
&cm->frame_bufs[cm->ref_frame_map[0]].buf;
if (!equal_dimensions(cfg, sd))
vpx_internal_error(&cm->error, VPX_CODEC_ERROR,
"Incorrect buffer dimensions");
@ -246,13 +248,13 @@ vpx_codec_err_t vp9_set_reference_dec(VP9D_PTR ptr, VP9_REFFRAME ref_frame_flag,
// Find an empty frame buffer.
const int free_fb = get_free_fb(cm);
// Decrease fb_idx_ref_cnt since it will be increased again in
// Decrease ref_count since it will be increased again in
// ref_cnt_fb() below.
cm->fb_idx_ref_cnt[free_fb]--;
cm->frame_bufs[free_fb].ref_count--;
// Manage the reference counters and copy image.
ref_cnt_fb(cm->fb_idx_ref_cnt, ref_fb_ptr, free_fb);
ref_buf->buf = &cm->yv12_fb[*ref_fb_ptr];
ref_cnt_fb(cm->frame_bufs, ref_fb_ptr, free_fb);
ref_buf->buf = &cm->frame_bufs[*ref_fb_ptr].buf;
vp8_yv12_copy_frame(sd, ref_buf->buf);
}
@ -267,7 +269,7 @@ int vp9_get_reference_dec(VP9D_PTR ptr, int index, YV12_BUFFER_CONFIG **fb) {
if (index < 0 || index >= REF_FRAMES)
return -1;
*fb = &cm->yv12_fb[cm->ref_frame_map[index]];
*fb = &cm->frame_bufs[cm->ref_frame_map[index]].buf;
return 0;
}
@ -278,13 +280,13 @@ static void swap_frame_buffers(VP9D_COMP *pbi) {
for (mask = pbi->refresh_frame_flags; mask; mask >>= 1) {
if (mask & 1)
ref_cnt_fb(cm->fb_idx_ref_cnt, &cm->ref_frame_map[ref_index],
ref_cnt_fb(cm->frame_bufs, &cm->ref_frame_map[ref_index],
cm->new_fb_idx);
++ref_index;
}
cm->frame_to_show = get_frame_new_buffer(cm);
cm->fb_idx_ref_cnt[cm->new_fb_idx]--;
cm->frame_bufs[cm->new_fb_idx].ref_count--;
// Invalidate these references until the next frame starts.
for (ref_index = 0; ref_index < 3; ref_index++)
@ -340,8 +342,8 @@ int vp9_receive_compressed_data(VP9D_PTR ptr,
if (cm->frame_refs[0].idx != INT_MAX)
cm->frame_refs[0].buf->corrupted = 1;
if (cm->fb_idx_ref_cnt[cm->new_fb_idx] > 0)
cm->fb_idx_ref_cnt[cm->new_fb_idx]--;
if (cm->frame_bufs[cm->new_fb_idx].ref_count > 0)
cm->frame_bufs[cm->new_fb_idx].ref_count--;
return -1;
}
@ -353,8 +355,8 @@ int vp9_receive_compressed_data(VP9D_PTR ptr,
if (retcode < 0) {
cm->error.error_code = VPX_CODEC_ERROR;
cm->error.setjmp = 0;
if (cm->fb_idx_ref_cnt[cm->new_fb_idx] > 0)
cm->fb_idx_ref_cnt[cm->new_fb_idx]--;
if (cm->frame_bufs[cm->new_fb_idx].ref_count > 0)
cm->frame_bufs[cm->new_fb_idx].ref_count--;
return retcode;
}

View File

@ -2186,7 +2186,7 @@ int vp9_get_reference_enc(VP9_PTR ptr, int index, YV12_BUFFER_CONFIG **fb) {
if (index < 0 || index >= REF_FRAMES)
return -1;
*fb = &cm->yv12_fb[cm->ref_frame_map[index]];
*fb = &cm->frame_bufs[cm->ref_frame_map[index]].buf;
return 0;
}
@ -2478,9 +2478,9 @@ static void update_reference_frames(VP9_COMP * const cpi) {
// At this point the new frame has been encoded.
// If any buffer copy / swapping is signaled it should be done here.
if (cm->frame_type == KEY_FRAME) {
ref_cnt_fb(cm->fb_idx_ref_cnt,
ref_cnt_fb(cm->frame_bufs,
&cm->ref_frame_map[cpi->gld_fb_idx], cm->new_fb_idx);
ref_cnt_fb(cm->fb_idx_ref_cnt,
ref_cnt_fb(cm->frame_bufs,
&cm->ref_frame_map[cpi->alt_fb_idx], cm->new_fb_idx);
}
#if CONFIG_MULTIPLE_ARF
@ -2501,7 +2501,7 @@ static void update_reference_frames(VP9_COMP * const cpi) {
*/
int tmp;
ref_cnt_fb(cm->fb_idx_ref_cnt,
ref_cnt_fb(cm->frame_bufs,
&cm->ref_frame_map[cpi->alt_fb_idx], cm->new_fb_idx);
tmp = cpi->alt_fb_idx;
@ -2515,18 +2515,18 @@ static void update_reference_frames(VP9_COMP * const cpi) {
arf_idx = cpi->arf_buffer_idx[cpi->sequence_number + 1];
}
#endif
ref_cnt_fb(cm->fb_idx_ref_cnt,
ref_cnt_fb(cm->frame_bufs,
&cm->ref_frame_map[arf_idx], cm->new_fb_idx);
}
if (cpi->refresh_golden_frame) {
ref_cnt_fb(cm->fb_idx_ref_cnt,
ref_cnt_fb(cm->frame_bufs,
&cm->ref_frame_map[cpi->gld_fb_idx], cm->new_fb_idx);
}
}
if (cpi->refresh_last_frame) {
ref_cnt_fb(cm->fb_idx_ref_cnt,
ref_cnt_fb(cm->frame_bufs,
&cm->ref_frame_map[cpi->lst_fb_idx], cm->new_fb_idx);
}
}
@ -2564,20 +2564,20 @@ static void scale_references(VP9_COMP *cpi) {
for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
const int idx = cm->ref_frame_map[get_ref_frame_idx(cpi, ref_frame)];
YV12_BUFFER_CONFIG *ref = &cm->yv12_fb[idx];
YV12_BUFFER_CONFIG *const ref = &cm->frame_bufs[idx].buf;
if (ref->y_crop_width != cm->width ||
ref->y_crop_height != cm->height) {
const int new_fb = get_free_fb(cm);
vp9_realloc_frame_buffer(&cm->yv12_fb[new_fb],
vp9_realloc_frame_buffer(&cm->frame_bufs[new_fb].buf,
cm->width, cm->height,
cm->subsampling_x, cm->subsampling_y,
VP9_ENC_BORDER_IN_PIXELS);
scale_and_extend_frame(ref, &cm->yv12_fb[new_fb]);
scale_and_extend_frame(ref, &cm->frame_bufs[new_fb].buf);
cpi->scaled_ref_idx[ref_frame - 1] = new_fb;
} else {
cpi->scaled_ref_idx[ref_frame - 1] = idx;
cm->fb_idx_ref_cnt[idx]++;
cm->frame_bufs[idx].ref_count++;
}
}
}
@ -2587,7 +2587,7 @@ static void release_scaled_references(VP9_COMP *cpi) {
int i;
for (i = 0; i < 3; i++)
cm->fb_idx_ref_cnt[cpi->scaled_ref_idx[i]]--;
cm->frame_bufs[cpi->scaled_ref_idx[i]].ref_count--;
}
static void full_to_model_count(unsigned int *model_count,
@ -3544,7 +3544,7 @@ int vp9_get_compressed_data(VP9_PTR ptr, unsigned int *frame_flags,
/* find a free buffer for the new frame, releasing the reference previously
* held.
*/
cm->fb_idx_ref_cnt[cm->new_fb_idx]--;
cm->frame_bufs[cm->new_fb_idx].ref_count--;
cm->new_fb_idx = get_free_fb(cm);
#if CONFIG_MULTIPLE_ARF
@ -3568,8 +3568,7 @@ int vp9_get_compressed_data(VP9_PTR ptr, unsigned int *frame_flags,
for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
const int idx = cm->ref_frame_map[get_ref_frame_idx(cpi, ref_frame)];
YV12_BUFFER_CONFIG *const buf = &cm->yv12_fb[idx];
YV12_BUFFER_CONFIG *const buf = &cm->frame_bufs[idx].buf;
RefBuffer *const ref_buf = &cm->frame_refs[ref_frame - 1];
ref_buf->buf = buf;
ref_buf->idx = idx;

View File

@ -802,7 +802,8 @@ static int get_ref_frame_idx(const VP9_COMP *cpi,
static YV12_BUFFER_CONFIG *get_ref_frame_buffer(VP9_COMP *cpi,
MV_REFERENCE_FRAME ref_frame) {
VP9_COMMON *const cm = &cpi->common;
return &cm->yv12_fb[cm->ref_frame_map[get_ref_frame_idx(cpi, ref_frame)]];
return &cm->frame_bufs[cm->ref_frame_map[get_ref_frame_idx(cpi,
ref_frame)]].buf;
}
void vp9_encode_frame(VP9_COMP *cpi);

View File

@ -2320,7 +2320,7 @@ const YV12_BUFFER_CONFIG *vp9_get_scaled_ref_frame(const VP9_COMP *cpi,
const VP9_COMMON *const cm = &cpi->common;
const int ref_idx = cm->ref_frame_map[get_ref_frame_idx(cpi, ref_frame)];
const int scaled_idx = cpi->scaled_ref_idx[ref_frame - 1];
return (scaled_idx != ref_idx) ? &cm->yv12_fb[scaled_idx] : NULL;
return (scaled_idx != ref_idx) ? &cm->frame_bufs[scaled_idx].buf : NULL;
}
static INLINE int get_switchable_rate(const MACROBLOCK *x) {