Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(571)

Side by Side Diff: source/libvpx/vp9/common/vp9_alloccommon.c

Issue 394353005: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « source/libvpx/vp9/common/vp9_alloccommon.h ('k') | source/libvpx/vp9/common/vp9_entropy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 10 matching lines...) Expand all
21 int i; 21 int i;
22 22
23 // Top border row 23 // Top border row
24 vpx_memset(mi, 0, sizeof(*mi) * cm->mi_stride); 24 vpx_memset(mi, 0, sizeof(*mi) * cm->mi_stride);
25 25
26 // Left border column 26 // Left border column
27 for (i = 1; i < cm->mi_rows + 1; ++i) 27 for (i = 1; i < cm->mi_rows + 1; ++i)
28 vpx_memset(&mi[i * cm->mi_stride], 0, sizeof(*mi)); 28 vpx_memset(&mi[i * cm->mi_stride], 0, sizeof(*mi));
29 } 29 }
30 30
31 static void set_mb_mi(VP9_COMMON *cm, int aligned_width, int aligned_height) { 31 void vp9_set_mb_mi(VP9_COMMON *cm, int width, int height) {
32 const int aligned_width = ALIGN_POWER_OF_TWO(width, MI_SIZE_LOG2);
33 const int aligned_height = ALIGN_POWER_OF_TWO(height, MI_SIZE_LOG2);
34
32 cm->mi_cols = aligned_width >> MI_SIZE_LOG2; 35 cm->mi_cols = aligned_width >> MI_SIZE_LOG2;
33 cm->mi_rows = aligned_height >> MI_SIZE_LOG2; 36 cm->mi_rows = aligned_height >> MI_SIZE_LOG2;
34 cm->mi_stride = cm->mi_cols + MI_BLOCK_SIZE; 37 cm->mi_stride = cm->mi_cols + MI_BLOCK_SIZE;
35 38
36 cm->mb_cols = (cm->mi_cols + 1) >> 1; 39 cm->mb_cols = (cm->mi_cols + 1) >> 1;
37 cm->mb_rows = (cm->mi_rows + 1) >> 1; 40 cm->mb_rows = (cm->mi_rows + 1) >> 1;
38 cm->MBs = cm->mb_rows * cm->mb_cols; 41 cm->MBs = cm->mb_rows * cm->mb_cols;
39 } 42 }
40 43
41 static void setup_mi(VP9_COMMON *cm) { 44 static void setup_mi(VP9_COMMON *cm) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 vpx_free(cm->mi_grid_base_array[i]); 91 vpx_free(cm->mi_grid_base_array[i]);
89 cm->mi_grid_base_array[i] = NULL; 92 cm->mi_grid_base_array[i] = NULL;
90 } 93 }
91 94
92 cm->mip = NULL; 95 cm->mip = NULL;
93 cm->prev_mip = NULL; 96 cm->prev_mip = NULL;
94 cm->mi_grid_base = NULL; 97 cm->mi_grid_base = NULL;
95 cm->prev_mi_grid_base = NULL; 98 cm->prev_mi_grid_base = NULL;
96 } 99 }
97 100
98 void vp9_free_frame_buffers(VP9_COMMON *cm) { 101 void vp9_free_ref_frame_buffers(VP9_COMMON *cm) {
99 int i; 102 int i;
100 103
101 for (i = 0; i < FRAME_BUFFERS; ++i) { 104 for (i = 0; i < FRAME_BUFFERS; ++i) {
102 vp9_free_frame_buffer(&cm->frame_bufs[i].buf); 105 vp9_free_frame_buffer(&cm->frame_bufs[i].buf);
103 106
104 if (cm->frame_bufs[i].ref_count > 0 && 107 if (cm->frame_bufs[i].ref_count > 0 &&
105 cm->frame_bufs[i].raw_frame_buffer.data != NULL) { 108 cm->frame_bufs[i].raw_frame_buffer.data != NULL) {
106 cm->release_fb_cb(cm->cb_priv, &cm->frame_bufs[i].raw_frame_buffer); 109 cm->release_fb_cb(cm->cb_priv, &cm->frame_bufs[i].raw_frame_buffer);
107 cm->frame_bufs[i].ref_count = 0; 110 cm->frame_bufs[i].ref_count = 0;
108 } 111 }
109 } 112 }
110 113
111 vp9_free_frame_buffer(&cm->post_proc_buffer); 114 vp9_free_frame_buffer(&cm->post_proc_buffer);
112 } 115 }
113 116
114 void vp9_free_context_buffers(VP9_COMMON *cm) { 117 void vp9_free_context_buffers(VP9_COMMON *cm) {
115 free_mi(cm); 118 free_mi(cm);
116 119
117 vpx_free(cm->last_frame_seg_map); 120 vpx_free(cm->last_frame_seg_map);
118 cm->last_frame_seg_map = NULL; 121 cm->last_frame_seg_map = NULL;
119 122
120 vpx_free(cm->above_context); 123 vpx_free(cm->above_context);
121 cm->above_context = NULL; 124 cm->above_context = NULL;
122 125
123 vpx_free(cm->above_seg_context); 126 vpx_free(cm->above_seg_context);
124 cm->above_seg_context = NULL; 127 cm->above_seg_context = NULL;
125 } 128 }
126 129
127 int vp9_resize_frame_buffers(VP9_COMMON *cm, int width, int height) { 130 int vp9_alloc_context_buffers(VP9_COMMON *cm, int width, int height) {
128 const int aligned_width = ALIGN_POWER_OF_TWO(width, MI_SIZE_LOG2); 131 vp9_free_context_buffers(cm);
129 const int aligned_height = ALIGN_POWER_OF_TWO(height, MI_SIZE_LOG2);
130 #if CONFIG_INTERNAL_STATS || CONFIG_VP9_POSTPROC
131 const int ss_x = cm->subsampling_x;
132 const int ss_y = cm->subsampling_y;
133 132
134 // TODO(agrange): this should be conditionally allocated. 133 vp9_set_mb_mi(cm, width, height);
135 if (vp9_realloc_frame_buffer(&cm->post_proc_buffer, width, height, ss_x, ss_y, 134 if (alloc_mi(cm, cm->mi_stride * (cm->mi_rows + MI_BLOCK_SIZE))) goto fail;
136 VP9_DEC_BORDER_IN_PIXELS, NULL, NULL, NULL) < 0)
137 goto fail;
138 #endif
139 135
140 set_mb_mi(cm, aligned_width, aligned_height); 136 cm->last_frame_seg_map = (uint8_t *)vpx_calloc(cm->mi_rows * cm->mi_cols, 1);
137 if (!cm->last_frame_seg_map) goto fail;
141 138
142 free_mi(cm); 139 cm->above_context = (ENTROPY_CONTEXT *)vpx_calloc(
143 if (alloc_mi(cm, cm->mi_stride * (cm->mi_rows + MI_BLOCK_SIZE))) 140 2 * mi_cols_aligned_to_sb(cm->mi_cols) * MAX_MB_PLANE,
144 goto fail; 141 sizeof(*cm->above_context));
142 if (!cm->above_context) goto fail;
145 143
146 setup_mi(cm); 144 cm->above_seg_context = (PARTITION_CONTEXT *)vpx_calloc(
147 145 mi_cols_aligned_to_sb(cm->mi_cols), sizeof(*cm->above_seg_context));
148 // Create the segmentation map structure and set to 0. 146 if (!cm->above_seg_context) goto fail;
149 vpx_free(cm->last_frame_seg_map);
150 cm->last_frame_seg_map = (uint8_t *)vpx_calloc(cm->mi_rows * cm->mi_cols, 1);
151 if (!cm->last_frame_seg_map)
152 goto fail;
153
154 vpx_free(cm->above_context);
155 cm->above_context =
156 (ENTROPY_CONTEXT *)vpx_calloc(2 * mi_cols_aligned_to_sb(cm->mi_cols) *
157 MAX_MB_PLANE,
158 sizeof(*cm->above_context));
159 if (!cm->above_context)
160 goto fail;
161
162 vpx_free(cm->above_seg_context);
163 cm->above_seg_context =
164 (PARTITION_CONTEXT *)vpx_calloc(mi_cols_aligned_to_sb(cm->mi_cols),
165 sizeof(*cm->above_seg_context));
166 if (!cm->above_seg_context)
167 goto fail;
168 147
169 return 0; 148 return 0;
170 149
171 fail: 150 fail:
172 vp9_free_frame_buffers(cm);
173 vp9_free_context_buffers(cm); 151 vp9_free_context_buffers(cm);
174 return 1; 152 return 1;
175 } 153 }
176 154
177 static void init_frame_bufs(VP9_COMMON *cm) { 155 static void init_frame_bufs(VP9_COMMON *cm) {
178 int i; 156 int i;
179 157
180 cm->new_fb_idx = FRAME_BUFFERS - 1; 158 cm->new_fb_idx = FRAME_BUFFERS - 1;
181 cm->frame_bufs[cm->new_fb_idx].ref_count = 1; 159 cm->frame_bufs[cm->new_fb_idx].ref_count = 1;
182 160
183 for (i = 0; i < REF_FRAMES; ++i) { 161 for (i = 0; i < REF_FRAMES; ++i) {
184 cm->ref_frame_map[i] = i; 162 cm->ref_frame_map[i] = i;
185 cm->frame_bufs[i].ref_count = 1; 163 cm->frame_bufs[i].ref_count = 1;
186 } 164 }
187 } 165 }
188 166
189 int vp9_alloc_frame_buffers(VP9_COMMON *cm, int width, int height) { 167 int vp9_alloc_ref_frame_buffers(VP9_COMMON *cm, int width, int height) {
190 int i; 168 int i;
191 const int ss_x = cm->subsampling_x; 169 const int ss_x = cm->subsampling_x;
192 const int ss_y = cm->subsampling_y; 170 const int ss_y = cm->subsampling_y;
193 171
194 vp9_free_frame_buffers(cm); 172 vp9_free_ref_frame_buffers(cm);
195 173
196 for (i = 0; i < FRAME_BUFFERS; ++i) { 174 for (i = 0; i < FRAME_BUFFERS; ++i) {
197 cm->frame_bufs[i].ref_count = 0; 175 cm->frame_bufs[i].ref_count = 0;
198 if (vp9_alloc_frame_buffer(&cm->frame_bufs[i].buf, width, height, 176 if (vp9_alloc_frame_buffer(&cm->frame_bufs[i].buf, width, height,
199 ss_x, ss_y, VP9_ENC_BORDER_IN_PIXELS) < 0) 177 ss_x, ss_y, VP9_ENC_BORDER_IN_PIXELS) < 0)
200 goto fail; 178 goto fail;
201 } 179 }
202 180
203 init_frame_bufs(cm); 181 init_frame_bufs(cm);
204 182
205 #if CONFIG_INTERNAL_STATS || CONFIG_VP9_POSTPROC 183 #if CONFIG_INTERNAL_STATS || CONFIG_VP9_POSTPROC
206 if (vp9_alloc_frame_buffer(&cm->post_proc_buffer, width, height, ss_x, ss_y, 184 if (vp9_alloc_frame_buffer(&cm->post_proc_buffer, width, height, ss_x, ss_y,
207 VP9_ENC_BORDER_IN_PIXELS) < 0) 185 VP9_ENC_BORDER_IN_PIXELS) < 0)
208 goto fail; 186 goto fail;
209 #endif 187 #endif
210 188
211 return 0; 189 return 0;
212 190
213 fail: 191 fail:
214 vp9_free_frame_buffers(cm); 192 vp9_free_ref_frame_buffers(cm);
215 return 1;
216 }
217
218 int vp9_alloc_context_buffers(VP9_COMMON *cm, int width, int height) {
219 const int aligned_width = ALIGN_POWER_OF_TWO(width, MI_SIZE_LOG2);
220 const int aligned_height = ALIGN_POWER_OF_TWO(height, MI_SIZE_LOG2);
221
222 vp9_free_context_buffers(cm);
223
224 set_mb_mi(cm, aligned_width, aligned_height);
225
226 if (alloc_mi(cm, cm->mi_stride * (cm->mi_rows + MI_BLOCK_SIZE)))
227 goto fail;
228
229 setup_mi(cm);
230
231 // Create the segmentation map structure and set to 0.
232 cm->last_frame_seg_map = (uint8_t *)vpx_calloc(cm->mi_rows * cm->mi_cols, 1);
233 if (!cm->last_frame_seg_map)
234 goto fail;
235
236 cm->above_context =
237 (ENTROPY_CONTEXT *)vpx_calloc(2 * mi_cols_aligned_to_sb(cm->mi_cols) *
238 MAX_MB_PLANE,
239 sizeof(*cm->above_context));
240 if (!cm->above_context)
241 goto fail;
242
243 cm->above_seg_context =
244 (PARTITION_CONTEXT *)vpx_calloc(mi_cols_aligned_to_sb(cm->mi_cols),
245 sizeof(*cm->above_seg_context));
246 if (!cm->above_seg_context)
247 goto fail;
248
249 return 0;
250
251 fail:
252 vp9_free_context_buffers(cm);
253 return 1; 193 return 1;
254 } 194 }
255 195
256 void vp9_remove_common(VP9_COMMON *cm) { 196 void vp9_remove_common(VP9_COMMON *cm) {
257 vp9_free_frame_buffers(cm); 197 vp9_free_ref_frame_buffers(cm);
258 vp9_free_context_buffers(cm); 198 vp9_free_context_buffers(cm);
259 vp9_free_internal_frame_buffers(&cm->int_frame_buffers); 199 vp9_free_internal_frame_buffers(&cm->int_frame_buffers);
260 } 200 }
261 201
262 void vp9_update_frame_size(VP9_COMMON *cm) { 202 void vp9_init_context_buffers(VP9_COMMON *cm) {
263 const int aligned_width = ALIGN_POWER_OF_TWO(cm->width, MI_SIZE_LOG2);
264 const int aligned_height = ALIGN_POWER_OF_TWO(cm->height, MI_SIZE_LOG2);
265
266 set_mb_mi(cm, aligned_width, aligned_height);
267 setup_mi(cm); 203 setup_mi(cm);
268
269 // Initialize the previous frame segment map to 0.
270 if (cm->last_frame_seg_map) 204 if (cm->last_frame_seg_map)
271 vpx_memset(cm->last_frame_seg_map, 0, cm->mi_rows * cm->mi_cols); 205 vpx_memset(cm->last_frame_seg_map, 0, cm->mi_rows * cm->mi_cols);
272 } 206 }
273 207
274 void vp9_swap_mi_and_prev_mi(VP9_COMMON *cm) { 208 void vp9_swap_mi_and_prev_mi(VP9_COMMON *cm) {
275 // Swap indices. 209 // Swap indices.
276 const int tmp = cm->mi_idx; 210 const int tmp = cm->mi_idx;
277 cm->mi_idx = cm->prev_mi_idx; 211 cm->mi_idx = cm->prev_mi_idx;
278 cm->prev_mi_idx = tmp; 212 cm->prev_mi_idx = tmp;
279 213
280 // Current mip will be the prev_mip for the next frame. 214 // Current mip will be the prev_mip for the next frame.
281 cm->mip = cm->mip_array[cm->mi_idx]; 215 cm->mip = cm->mip_array[cm->mi_idx];
282 cm->prev_mip = cm->mip_array[cm->prev_mi_idx]; 216 cm->prev_mip = cm->mip_array[cm->prev_mi_idx];
283 cm->mi_grid_base = cm->mi_grid_base_array[cm->mi_idx]; 217 cm->mi_grid_base = cm->mi_grid_base_array[cm->mi_idx];
284 cm->prev_mi_grid_base = cm->mi_grid_base_array[cm->prev_mi_idx]; 218 cm->prev_mi_grid_base = cm->mi_grid_base_array[cm->prev_mi_idx];
285 219
286 // Update the upper left visible macroblock ptrs. 220 // Update the upper left visible macroblock ptrs.
287 cm->mi = cm->mip + cm->mi_stride + 1; 221 cm->mi = cm->mip + cm->mi_stride + 1;
288 cm->prev_mi = cm->prev_mip + cm->mi_stride + 1; 222 cm->prev_mi = cm->prev_mip + cm->mi_stride + 1;
289 cm->mi_grid_visible = cm->mi_grid_base + cm->mi_stride + 1; 223 cm->mi_grid_visible = cm->mi_grid_base + cm->mi_stride + 1;
290 cm->prev_mi_grid_visible = cm->prev_mi_grid_base + cm->mi_stride + 1; 224 cm->prev_mi_grid_visible = cm->prev_mi_grid_base + cm->mi_stride + 1;
291 } 225 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/common/vp9_alloccommon.h ('k') | source/libvpx/vp9/common/vp9_entropy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698