From 394b0a6a30d4a7d6b97bdd22d7ff7153b2c7d459 Mon Sep 17 00:00:00 2001 From: John Koleszar Date: Mon, 14 Jan 2013 15:52:20 -0800 Subject: [PATCH] Update encoder to use fb_idx_ref_cnt Do reference counting the same way on the encoder as the decoder does, rather than maintaining the 'flags' member of YV12_BUFFER_CONFIG. Change-Id: I91dc210ffca081acaf9d5c09a06e7461b3c3139c --- vp9/common/vp9_alloccommon.c | 1 - vp9/common/vp9_onyxc_int.h | 20 ++++++++++++++++++ vp9/decoder/vp9_onyxd_if.c | 23 --------------------- vp9/encoder/vp9_onyx_if.c | 39 ++++++++++-------------------------- 4 files changed, 31 insertions(+), 52 deletions(-) diff --git a/vp9/common/vp9_alloccommon.c b/vp9/common/vp9_alloccommon.c index 777228298..e32240157 100644 --- a/vp9/common/vp9_alloccommon.c +++ b/vp9/common/vp9_alloccommon.c @@ -80,7 +80,6 @@ int vp9_alloc_frame_buffers(VP9_COMMON *oci, int width, int height) { for (i = 0; i < NUM_YV12_BUFFERS; i++) { oci->fb_idx_ref_cnt[i] = 0; - oci->yv12_fb[i].flags = 0; if (vp8_yv12_alloc_frame_buffer(&oci->yv12_fb[i], width, height, VP9BORDERINPIXELS) < 0) { vp9_de_alloc_frame_buffers(oci); diff --git a/vp9/common/vp9_onyxc_int.h b/vp9/common/vp9_onyxc_int.h index bfe697626..8fbfafdc2 100644 --- a/vp9/common/vp9_onyxc_int.h +++ b/vp9/common/vp9_onyxc_int.h @@ -271,4 +271,24 @@ typedef struct VP9Common { } VP9_COMMON; +static int get_free_fb(VP9_COMMON *cm) { + int i; + for (i = 0; i < NUM_YV12_BUFFERS; i++) + if (cm->fb_idx_ref_cnt[i] == 0) + break; + + assert(i < NUM_YV12_BUFFERS); + cm->fb_idx_ref_cnt[i] = 1; + return i; +} + +static void ref_cnt_fb(int *buf, int *idx, int new_idx) { + if (buf[*idx] > 0) + buf[*idx]--; + + *idx = new_idx; + + buf[new_idx]++; +} + #endif // VP9_COMMON_VP9_ONYXC_INT_H_ diff --git a/vp9/decoder/vp9_onyxd_if.c b/vp9/decoder/vp9_onyxd_if.c index 6ae7b75d6..0c38cfdaf 100644 --- a/vp9/decoder/vp9_onyxd_if.c +++ b/vp9/decoder/vp9_onyxd_if.c @@ -30,9 +30,6 @@ #include "vp9/decoder/vp9_detokenize.h" #include "./vpx_scale_rtcd.h" -static int get_free_fb(VP9_COMMON *cm); -static void ref_cnt_fb(int *buf, int *idx, int new_idx); - #define WRITE_RECON_BUFFER 0 #if WRITE_RECON_BUFFER == 1 static void recon_write_yuv_frame(char *name, YV12_BUFFER_CONFIG *s) { @@ -234,26 +231,6 @@ vpx_codec_err_t vp9_set_reference_dec(VP9D_PTR ptr, VP9_REFFRAME ref_frame_flag, } -static int get_free_fb(VP9_COMMON *cm) { - int i; - for (i = 0; i < NUM_YV12_BUFFERS; i++) - if (cm->fb_idx_ref_cnt[i] == 0) - break; - - assert(i < NUM_YV12_BUFFERS); - cm->fb_idx_ref_cnt[i] = 1; - return i; -} - -static void ref_cnt_fb(int *buf, int *idx, int new_idx) { - if (buf[*idx] > 0) - buf[*idx]--; - - *idx = new_idx; - - buf[new_idx]++; -} - /* If any buffer copy / swapping is signalled it should be done here. */ static int swap_frame_buffers(VP9_COMMON *cm) { int err = 0; diff --git a/vp9/encoder/vp9_onyx_if.c b/vp9/encoder/vp9_onyx_if.c index c133bf23d..ee6c46f00 100644 --- a/vp9/encoder/vp9_onyx_if.c +++ b/vp9/encoder/vp9_onyx_if.c @@ -2564,36 +2564,24 @@ static int recode_loop_test(VP9_COMP *cpi, } static void update_reference_frames(VP9_COMMON *cm) { - YV12_BUFFER_CONFIG *yv12_fb = cm->yv12_fb; - // 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) { - yv12_fb[cm->new_fb_idx].flags |= VP9_GOLD_FLAG | VP9_ALT_FLAG; - - yv12_fb[cm->gld_fb_idx].flags &= ~VP9_GOLD_FLAG; - yv12_fb[cm->alt_fb_idx].flags &= ~VP9_ALT_FLAG; - - cm->alt_fb_idx = cm->gld_fb_idx = cm->new_fb_idx; + ref_cnt_fb(cm->fb_idx_ref_cnt, &cm->gld_fb_idx, cm->new_fb_idx); + ref_cnt_fb(cm->fb_idx_ref_cnt, &cm->alt_fb_idx, cm->new_fb_idx); } else { /* For non key frames */ if (cm->refresh_alt_ref_frame) { - cm->yv12_fb[cm->new_fb_idx].flags |= VP9_ALT_FLAG; - cm->yv12_fb[cm->alt_fb_idx].flags &= ~VP9_ALT_FLAG; - cm->alt_fb_idx = cm->new_fb_idx; + ref_cnt_fb(cm->fb_idx_ref_cnt, &cm->alt_fb_idx, cm->new_fb_idx); } if (cm->refresh_golden_frame) { - cm->yv12_fb[cm->new_fb_idx].flags |= VP9_GOLD_FLAG; - cm->yv12_fb[cm->gld_fb_idx].flags &= ~VP9_GOLD_FLAG; - cm->gld_fb_idx = cm->new_fb_idx; + ref_cnt_fb(cm->fb_idx_ref_cnt, &cm->gld_fb_idx, cm->new_fb_idx); } } if (cm->refresh_last_frame) { - cm->yv12_fb[cm->new_fb_idx].flags |= VP9_LAST_FLAG; - cm->yv12_fb[cm->lst_fb_idx].flags &= ~VP9_LAST_FLAG; - cm->lst_fb_idx = cm->new_fb_idx; + ref_cnt_fb(cm->fb_idx_ref_cnt, &cm->lst_fb_idx, cm->new_fb_idx); } } @@ -3914,18 +3902,13 @@ int vp9_get_compressed_data(VP9_PTR ptr, unsigned int *frame_flags, } #endif - /* find a free buffer for the new frame */ - { - int i = 0; - for (; i < NUM_YV12_BUFFERS; i++) { - if (!cm->yv12_fb[i].flags) { - cm->new_fb_idx = i; - break; - } - } - assert(i < NUM_YV12_BUFFERS); - } + /* find a free buffer for the new frame, releasing the reference previously + * held. + */ + cm->fb_idx_ref_cnt[cm->new_fb_idx]--; + cm->new_fb_idx = get_free_fb(cm); + if (cpi->pass == 1) { Pass1Encode(cpi, size, dest, frame_flags); } else if (cpi->pass == 2) {