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
This commit is contained in:
Родитель
b8e027989f
Коммит
394b0a6a30
|
@ -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);
|
||||
|
|
|
@ -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_
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче