OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 } | 49 } |
50 | 50 |
51 static int alloc_seg_map(VP9_COMMON *cm, int seg_map_size) { | 51 static int alloc_seg_map(VP9_COMMON *cm, int seg_map_size) { |
52 int i; | 52 int i; |
53 | 53 |
54 for (i = 0; i < NUM_PING_PONG_BUFFERS; ++i) { | 54 for (i = 0; i < NUM_PING_PONG_BUFFERS; ++i) { |
55 cm->seg_map_array[i] = (uint8_t *)vpx_calloc(seg_map_size, 1); | 55 cm->seg_map_array[i] = (uint8_t *)vpx_calloc(seg_map_size, 1); |
56 if (cm->seg_map_array[i] == NULL) | 56 if (cm->seg_map_array[i] == NULL) |
57 return 1; | 57 return 1; |
58 } | 58 } |
| 59 cm->seg_map_alloc_size = seg_map_size; |
59 | 60 |
60 // Init the index. | 61 // Init the index. |
61 cm->seg_map_idx = 0; | 62 cm->seg_map_idx = 0; |
62 cm->prev_seg_map_idx = 1; | 63 cm->prev_seg_map_idx = 1; |
63 | 64 |
64 cm->current_frame_seg_map = cm->seg_map_array[cm->seg_map_idx]; | 65 cm->current_frame_seg_map = cm->seg_map_array[cm->seg_map_idx]; |
65 if (!cm->frame_parallel_decode) | 66 if (!cm->frame_parallel_decode) |
66 cm->last_frame_seg_map = cm->seg_map_array[cm->prev_seg_map_idx]; | 67 cm->last_frame_seg_map = cm->seg_map_array[cm->prev_seg_map_idx]; |
67 | 68 |
68 return 0; | 69 return 0; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 void vp9_free_context_buffers(VP9_COMMON *cm) { | 111 void vp9_free_context_buffers(VP9_COMMON *cm) { |
111 cm->free_mi(cm); | 112 cm->free_mi(cm); |
112 free_seg_map(cm); | 113 free_seg_map(cm); |
113 vpx_free(cm->above_context); | 114 vpx_free(cm->above_context); |
114 cm->above_context = NULL; | 115 cm->above_context = NULL; |
115 vpx_free(cm->above_seg_context); | 116 vpx_free(cm->above_seg_context); |
116 cm->above_seg_context = NULL; | 117 cm->above_seg_context = NULL; |
117 } | 118 } |
118 | 119 |
119 int vp9_alloc_context_buffers(VP9_COMMON *cm, int width, int height) { | 120 int vp9_alloc_context_buffers(VP9_COMMON *cm, int width, int height) { |
120 vp9_free_context_buffers(cm); | 121 int new_mi_size; |
121 | 122 |
122 vp9_set_mb_mi(cm, width, height); | 123 vp9_set_mb_mi(cm, width, height); |
123 if (cm->alloc_mi(cm, cm->mi_stride * calc_mi_size(cm->mi_rows))) | 124 new_mi_size = cm->mi_stride * calc_mi_size(cm->mi_rows); |
124 goto fail; | 125 if (cm->mi_alloc_size < new_mi_size) { |
| 126 cm->free_mi(cm); |
| 127 if (cm->alloc_mi(cm, new_mi_size)) |
| 128 goto fail; |
| 129 } |
125 | 130 |
126 // Create the segmentation map structure and set to 0. | 131 if (cm->seg_map_alloc_size < cm->mi_rows * cm->mi_cols) { |
127 free_seg_map(cm); | 132 // Create the segmentation map structure and set to 0. |
128 if (alloc_seg_map(cm, cm->mi_rows * cm->mi_cols)) | 133 free_seg_map(cm); |
129 goto fail; | 134 if (alloc_seg_map(cm, cm->mi_rows * cm->mi_cols)) |
| 135 goto fail; |
| 136 } |
130 | 137 |
131 cm->above_context = (ENTROPY_CONTEXT *)vpx_calloc( | 138 if (cm->above_context_alloc_cols < cm->mi_cols) { |
132 2 * mi_cols_aligned_to_sb(cm->mi_cols) * MAX_MB_PLANE, | 139 vpx_free(cm->above_context); |
133 sizeof(*cm->above_context)); | 140 cm->above_context = (ENTROPY_CONTEXT *)vpx_calloc( |
134 if (!cm->above_context) goto fail; | 141 2 * mi_cols_aligned_to_sb(cm->mi_cols) * MAX_MB_PLANE, |
| 142 sizeof(*cm->above_context)); |
| 143 if (!cm->above_context) goto fail; |
135 | 144 |
136 cm->above_seg_context = (PARTITION_CONTEXT *)vpx_calloc( | 145 vpx_free(cm->above_seg_context); |
137 mi_cols_aligned_to_sb(cm->mi_cols), sizeof(*cm->above_seg_context)); | 146 cm->above_seg_context = (PARTITION_CONTEXT *)vpx_calloc( |
138 if (!cm->above_seg_context) goto fail; | 147 mi_cols_aligned_to_sb(cm->mi_cols), sizeof(*cm->above_seg_context)); |
| 148 if (!cm->above_seg_context) goto fail; |
| 149 cm->above_context_alloc_cols = cm->mi_cols; |
| 150 } |
139 | 151 |
140 return 0; | 152 return 0; |
141 | 153 |
142 fail: | 154 fail: |
143 vp9_free_context_buffers(cm); | 155 vp9_free_context_buffers(cm); |
144 return 1; | 156 return 1; |
145 } | 157 } |
146 | 158 |
147 void vp9_remove_common(VP9_COMMON *cm) { | 159 void vp9_remove_common(VP9_COMMON *cm) { |
148 vp9_free_context_buffers(cm); | 160 vp9_free_context_buffers(cm); |
(...skipping 12 matching lines...) Expand all Loading... |
161 | 173 |
162 void vp9_swap_current_and_last_seg_map(VP9_COMMON *cm) { | 174 void vp9_swap_current_and_last_seg_map(VP9_COMMON *cm) { |
163 // Swap indices. | 175 // Swap indices. |
164 const int tmp = cm->seg_map_idx; | 176 const int tmp = cm->seg_map_idx; |
165 cm->seg_map_idx = cm->prev_seg_map_idx; | 177 cm->seg_map_idx = cm->prev_seg_map_idx; |
166 cm->prev_seg_map_idx = tmp; | 178 cm->prev_seg_map_idx = tmp; |
167 | 179 |
168 cm->current_frame_seg_map = cm->seg_map_array[cm->seg_map_idx]; | 180 cm->current_frame_seg_map = cm->seg_map_array[cm->seg_map_idx]; |
169 cm->last_frame_seg_map = cm->seg_map_array[cm->prev_seg_map_idx]; | 181 cm->last_frame_seg_map = cm->seg_map_array[cm->prev_seg_map_idx]; |
170 } | 182 } |
OLD | NEW |