Index: source/libvpx/vp9/common/vp9_alloccommon.c |
diff --git a/source/libvpx/vp9/common/vp9_alloccommon.c b/source/libvpx/vp9/common/vp9_alloccommon.c |
index 7db210c3ae018df2b1cf25804d13f17e60627e9f..222b88eff5d09a310f7d638ac6e14ea71fd72bab 100644 |
--- a/source/libvpx/vp9/common/vp9_alloccommon.c |
+++ b/source/libvpx/vp9/common/vp9_alloccommon.c |
@@ -56,6 +56,7 @@ static int alloc_seg_map(VP9_COMMON *cm, int seg_map_size) { |
if (cm->seg_map_array[i] == NULL) |
return 1; |
} |
+ cm->seg_map_alloc_size = seg_map_size; |
// Init the index. |
cm->seg_map_idx = 0; |
@@ -117,25 +118,36 @@ void vp9_free_context_buffers(VP9_COMMON *cm) { |
} |
int vp9_alloc_context_buffers(VP9_COMMON *cm, int width, int height) { |
- vp9_free_context_buffers(cm); |
+ int new_mi_size; |
vp9_set_mb_mi(cm, width, height); |
- if (cm->alloc_mi(cm, cm->mi_stride * calc_mi_size(cm->mi_rows))) |
- goto fail; |
- |
- // Create the segmentation map structure and set to 0. |
- free_seg_map(cm); |
- if (alloc_seg_map(cm, cm->mi_rows * cm->mi_cols)) |
- goto fail; |
+ new_mi_size = cm->mi_stride * calc_mi_size(cm->mi_rows); |
+ if (cm->mi_alloc_size < new_mi_size) { |
+ cm->free_mi(cm); |
+ if (cm->alloc_mi(cm, new_mi_size)) |
+ goto fail; |
+ } |
- cm->above_context = (ENTROPY_CONTEXT *)vpx_calloc( |
- 2 * mi_cols_aligned_to_sb(cm->mi_cols) * MAX_MB_PLANE, |
- sizeof(*cm->above_context)); |
- if (!cm->above_context) goto fail; |
+ if (cm->seg_map_alloc_size < cm->mi_rows * cm->mi_cols) { |
+ // Create the segmentation map structure and set to 0. |
+ free_seg_map(cm); |
+ if (alloc_seg_map(cm, cm->mi_rows * cm->mi_cols)) |
+ goto fail; |
+ } |
- cm->above_seg_context = (PARTITION_CONTEXT *)vpx_calloc( |
- mi_cols_aligned_to_sb(cm->mi_cols), sizeof(*cm->above_seg_context)); |
- if (!cm->above_seg_context) goto fail; |
+ if (cm->above_context_alloc_cols < cm->mi_cols) { |
+ vpx_free(cm->above_context); |
+ cm->above_context = (ENTROPY_CONTEXT *)vpx_calloc( |
+ 2 * mi_cols_aligned_to_sb(cm->mi_cols) * MAX_MB_PLANE, |
+ sizeof(*cm->above_context)); |
+ if (!cm->above_context) goto fail; |
+ |
+ vpx_free(cm->above_seg_context); |
+ cm->above_seg_context = (PARTITION_CONTEXT *)vpx_calloc( |
+ mi_cols_aligned_to_sb(cm->mi_cols), sizeof(*cm->above_seg_context)); |
+ if (!cm->above_seg_context) goto fail; |
+ cm->above_context_alloc_cols = cm->mi_cols; |
+ } |
return 0; |