fix scalling bug by buffer auto-reallocation
Change-Id: Ib748eb287520c794631697204da6ebe19523ce95
This commit is contained in:
parent
e6b72d0119
commit
38144ed8b2
@ -79,6 +79,57 @@ static void setup_mi(VP9_COMMON *cm) {
|
|||||||
vp9_update_mode_info_border(cm, cm->prev_mip);
|
vp9_update_mode_info_border(cm, cm->prev_mip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int vp9_resize_frame_buffers(VP9_COMMON *cm, int width, int height) {
|
||||||
|
const int aligned_width = ALIGN_POWER_OF_TWO(width, MI_SIZE_LOG2);
|
||||||
|
const int aligned_height = ALIGN_POWER_OF_TWO(height, MI_SIZE_LOG2);
|
||||||
|
const int ss_x = cm->subsampling_x;
|
||||||
|
const int ss_y = cm->subsampling_y;
|
||||||
|
int mi_size;
|
||||||
|
|
||||||
|
if (vp9_realloc_frame_buffer(&cm->post_proc_buffer, width, height, ss_x, ss_y,
|
||||||
|
VP9BORDERINPIXELS) < 0)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
set_mb_mi(cm, aligned_width, aligned_height);
|
||||||
|
|
||||||
|
// Allocation
|
||||||
|
mi_size = cm->mode_info_stride * (cm->mi_rows + MI_BLOCK_SIZE);
|
||||||
|
|
||||||
|
vpx_free(cm->mip);
|
||||||
|
cm->mip = vpx_calloc(mi_size, sizeof(MODE_INFO));
|
||||||
|
if (!cm->mip)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
vpx_free(cm->prev_mip);
|
||||||
|
cm->prev_mip = vpx_calloc(mi_size, sizeof(MODE_INFO));
|
||||||
|
if (!cm->prev_mip)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
vpx_free(cm->mi_grid_base);
|
||||||
|
cm->mi_grid_base = vpx_calloc(mi_size, sizeof(*cm->mi_grid_base));
|
||||||
|
if (!cm->mi_grid_base)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
vpx_free(cm->prev_mi_grid_base);
|
||||||
|
cm->prev_mi_grid_base = vpx_calloc(mi_size, sizeof(*cm->prev_mi_grid_base));
|
||||||
|
if (!cm->prev_mi_grid_base)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
setup_mi(cm);
|
||||||
|
|
||||||
|
// Create the segmentation map structure and set to 0.
|
||||||
|
vpx_free(cm->last_frame_seg_map);
|
||||||
|
cm->last_frame_seg_map = vpx_calloc(cm->mi_rows * cm->mi_cols, 1);
|
||||||
|
if (!cm->last_frame_seg_map)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
vp9_free_frame_buffers(cm);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int vp9_alloc_frame_buffers(VP9_COMMON *cm, int width, int height) {
|
int vp9_alloc_frame_buffers(VP9_COMMON *cm, int width, int height) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ void vp9_update_mode_info_border(VP9_COMMON *cm, MODE_INFO *mi);
|
|||||||
void vp9_create_common(VP9_COMMON *cm);
|
void vp9_create_common(VP9_COMMON *cm);
|
||||||
void vp9_remove_common(VP9_COMMON *cm);
|
void vp9_remove_common(VP9_COMMON *cm);
|
||||||
|
|
||||||
|
int vp9_resize_frame_buffers(VP9_COMMON *cm, int width, int height);
|
||||||
int vp9_alloc_frame_buffers(VP9_COMMON *cm, int width, int height);
|
int vp9_alloc_frame_buffers(VP9_COMMON *cm, int width, int height);
|
||||||
void vp9_free_frame_buffers(VP9_COMMON *cm);
|
void vp9_free_frame_buffers(VP9_COMMON *cm);
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ void vp9_copy_and_extend_frame(const YV12_BUFFER_CONFIG *src,
|
|||||||
const int et_y = 16;
|
const int et_y = 16;
|
||||||
const int el_y = 16;
|
const int el_y = 16;
|
||||||
// Motion estimation may use src block variance with the block size up
|
// Motion estimation may use src block variance with the block size up
|
||||||
// to 64x64, so the right and bottom need to be extended to 64 mulitple
|
// to 64x64, so the right and bottom need to be extended to 64 multiple
|
||||||
// or up to 16, whichever is greater.
|
// or up to 16, whichever is greater.
|
||||||
const int eb_y = MAX(ALIGN_POWER_OF_TWO(src->y_width, 6) - src->y_width,
|
const int eb_y = MAX(ALIGN_POWER_OF_TWO(src->y_width, 6) - src->y_width,
|
||||||
16);
|
16);
|
||||||
|
@ -704,20 +704,19 @@ static void apply_frame_size(VP9D_COMP *pbi, int width, int height) {
|
|||||||
VP9_COMMON *cm = &pbi->common;
|
VP9_COMMON *cm = &pbi->common;
|
||||||
|
|
||||||
if (cm->width != width || cm->height != height) {
|
if (cm->width != width || cm->height != height) {
|
||||||
if (!pbi->initial_width || !pbi->initial_height) {
|
// Change in frame size.
|
||||||
if (vp9_alloc_frame_buffers(cm, width, height))
|
if (cm->width == 0 || cm->height == 0) {
|
||||||
|
// Assign new frame buffer on first call.
|
||||||
|
cm->new_fb_idx = NUM_YV12_BUFFERS - 1;
|
||||||
|
cm->fb_idx_ref_cnt[cm->new_fb_idx] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(agrange) Don't test width/height, check overall size.
|
||||||
|
if (width > cm->width || height > cm->height) {
|
||||||
|
// Rescale frame buffers only if they're not big enough already.
|
||||||
|
if (vp9_resize_frame_buffers(cm, width, height))
|
||||||
vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
|
vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
|
||||||
"Failed to allocate frame buffers");
|
"Failed to allocate frame buffers");
|
||||||
pbi->initial_width = width;
|
|
||||||
pbi->initial_height = height;
|
|
||||||
} else {
|
|
||||||
if (width > pbi->initial_width)
|
|
||||||
vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
|
|
||||||
"Frame width too large");
|
|
||||||
|
|
||||||
if (height > pbi->initial_height)
|
|
||||||
vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
|
|
||||||
"Frame height too large");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cm->width = width;
|
cm->width = width;
|
||||||
|
@ -148,7 +148,10 @@ int vp9_realloc_frame_buffer(YV12_BUFFER_CONFIG *ybf,
|
|||||||
#else
|
#else
|
||||||
const int frame_size = yplane_size + 2 * uvplane_size;
|
const int frame_size = yplane_size + 2 * uvplane_size;
|
||||||
#endif
|
#endif
|
||||||
if (!ybf->buffer_alloc) {
|
if (frame_size > ybf->buffer_alloc_sz) {
|
||||||
|
// Allocation to hold larger frame, or first allocation.
|
||||||
|
if (ybf->buffer_alloc)
|
||||||
|
vpx_free(ybf->buffer_alloc);
|
||||||
ybf->buffer_alloc = vpx_memalign(32, frame_size);
|
ybf->buffer_alloc = vpx_memalign(32, frame_size);
|
||||||
ybf->buffer_alloc_sz = frame_size;
|
ybf->buffer_alloc_sz = frame_size;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user