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

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

Issue 375983002: 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_blockd.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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 vp9_free_frame_buffer(&cm->frame_bufs[i].buf); 102 vp9_free_frame_buffer(&cm->frame_bufs[i].buf);
103 103
104 if (cm->frame_bufs[i].ref_count > 0 && 104 if (cm->frame_bufs[i].ref_count > 0 &&
105 cm->frame_bufs[i].raw_frame_buffer.data != NULL) { 105 cm->frame_bufs[i].raw_frame_buffer.data != NULL) {
106 cm->release_fb_cb(cm->cb_priv, &cm->frame_bufs[i].raw_frame_buffer); 106 cm->release_fb_cb(cm->cb_priv, &cm->frame_bufs[i].raw_frame_buffer);
107 cm->frame_bufs[i].ref_count = 0; 107 cm->frame_bufs[i].ref_count = 0;
108 } 108 }
109 } 109 }
110 110
111 vp9_free_frame_buffer(&cm->post_proc_buffer); 111 vp9_free_frame_buffer(&cm->post_proc_buffer);
112 }
112 113
114 void vp9_free_context_buffers(VP9_COMMON *cm) {
113 free_mi(cm); 115 free_mi(cm);
114 116
115 vpx_free(cm->last_frame_seg_map); 117 vpx_free(cm->last_frame_seg_map);
116 cm->last_frame_seg_map = NULL; 118 cm->last_frame_seg_map = NULL;
117 119
118 vpx_free(cm->above_context); 120 vpx_free(cm->above_context);
119 cm->above_context = NULL; 121 cm->above_context = NULL;
120 122
121 vpx_free(cm->above_seg_context); 123 vpx_free(cm->above_seg_context);
122 cm->above_seg_context = NULL; 124 cm->above_seg_context = NULL;
123 } 125 }
124 126
125 int vp9_resize_frame_buffers(VP9_COMMON *cm, int width, int height) { 127 int vp9_resize_frame_buffers(VP9_COMMON *cm, int width, int height) {
126 const int aligned_width = ALIGN_POWER_OF_TWO(width, MI_SIZE_LOG2); 128 const int aligned_width = ALIGN_POWER_OF_TWO(width, MI_SIZE_LOG2);
127 const int aligned_height = ALIGN_POWER_OF_TWO(height, MI_SIZE_LOG2); 129 const int aligned_height = ALIGN_POWER_OF_TWO(height, MI_SIZE_LOG2);
130 #if CONFIG_INTERNAL_STATS || CONFIG_VP9_POSTPROC
128 const int ss_x = cm->subsampling_x; 131 const int ss_x = cm->subsampling_x;
129 const int ss_y = cm->subsampling_y; 132 const int ss_y = cm->subsampling_y;
130 133
134 // TODO(agrange): this should be conditionally allocated.
131 if (vp9_realloc_frame_buffer(&cm->post_proc_buffer, width, height, ss_x, ss_y, 135 if (vp9_realloc_frame_buffer(&cm->post_proc_buffer, width, height, ss_x, ss_y,
132 VP9_DEC_BORDER_IN_PIXELS, NULL, NULL, NULL) < 0) 136 VP9_DEC_BORDER_IN_PIXELS, NULL, NULL, NULL) < 0)
133 goto fail; 137 goto fail;
138 #endif
134 139
135 set_mb_mi(cm, aligned_width, aligned_height); 140 set_mb_mi(cm, aligned_width, aligned_height);
136 141
137 free_mi(cm); 142 free_mi(cm);
138 if (alloc_mi(cm, cm->mi_stride * (cm->mi_rows + MI_BLOCK_SIZE))) 143 if (alloc_mi(cm, cm->mi_stride * (cm->mi_rows + MI_BLOCK_SIZE)))
139 goto fail; 144 goto fail;
140 145
141 setup_mi(cm); 146 setup_mi(cm);
142 147
143 // Create the segmentation map structure and set to 0. 148 // Create the segmentation map structure and set to 0.
(...skipping 14 matching lines...) Expand all
158 cm->above_seg_context = 163 cm->above_seg_context =
159 (PARTITION_CONTEXT *)vpx_calloc(mi_cols_aligned_to_sb(cm->mi_cols), 164 (PARTITION_CONTEXT *)vpx_calloc(mi_cols_aligned_to_sb(cm->mi_cols),
160 sizeof(*cm->above_seg_context)); 165 sizeof(*cm->above_seg_context));
161 if (!cm->above_seg_context) 166 if (!cm->above_seg_context)
162 goto fail; 167 goto fail;
163 168
164 return 0; 169 return 0;
165 170
166 fail: 171 fail:
167 vp9_free_frame_buffers(cm); 172 vp9_free_frame_buffers(cm);
173 vp9_free_context_buffers(cm);
174 return 1;
175 }
176
177 static void init_frame_bufs(VP9_COMMON *cm) {
178 int i;
179
180 cm->new_fb_idx = FRAME_BUFFERS - 1;
181 cm->frame_bufs[cm->new_fb_idx].ref_count = 1;
182
183 for (i = 0; i < REF_FRAMES; ++i) {
184 cm->ref_frame_map[i] = i;
185 cm->frame_bufs[i].ref_count = 1;
186 }
187 }
188
189 int vp9_alloc_frame_buffers(VP9_COMMON *cm, int width, int height) {
190 int i;
191 const int ss_x = cm->subsampling_x;
192 const int ss_y = cm->subsampling_y;
193
194 vp9_free_frame_buffers(cm);
195
196 for (i = 0; i < FRAME_BUFFERS; ++i) {
197 cm->frame_bufs[i].ref_count = 0;
198 if (vp9_alloc_frame_buffer(&cm->frame_bufs[i].buf, width, height,
199 ss_x, ss_y, VP9_ENC_BORDER_IN_PIXELS) < 0)
200 goto fail;
201 }
202
203 init_frame_bufs(cm);
204
205 #if CONFIG_INTERNAL_STATS || CONFIG_VP9_POSTPROC
206 if (vp9_alloc_frame_buffer(&cm->post_proc_buffer, width, height, ss_x, ss_y,
207 VP9_ENC_BORDER_IN_PIXELS) < 0)
208 goto fail;
209 #endif
210
211 return 0;
212
213 fail:
214 vp9_free_frame_buffers(cm);
168 return 1; 215 return 1;
169 } 216 }
170 217
171 int vp9_alloc_frame_buffers(VP9_COMMON *cm, int width, int height) { 218 int vp9_alloc_context_buffers(VP9_COMMON *cm, int width, int height) {
172 const int aligned_width = ALIGN_POWER_OF_TWO(width, MI_SIZE_LOG2); 219 const int aligned_width = ALIGN_POWER_OF_TWO(width, MI_SIZE_LOG2);
173 const int aligned_height = ALIGN_POWER_OF_TWO(height, MI_SIZE_LOG2); 220 const int aligned_height = ALIGN_POWER_OF_TWO(height, MI_SIZE_LOG2);
174 const int ss_x = cm->subsampling_x;
175 const int ss_y = cm->subsampling_y;
176 int i;
177 221
178 vp9_free_frame_buffers(cm); 222 vp9_free_context_buffers(cm);
179
180 for (i = 0; i < FRAME_BUFFERS; i++) {
181 cm->frame_bufs[i].ref_count = 0;
182 if (vp9_alloc_frame_buffer(&cm->frame_bufs[i].buf, width, height,
183 ss_x, ss_y, VP9_ENC_BORDER_IN_PIXELS) < 0)
184 goto fail;
185 }
186
187 cm->new_fb_idx = FRAME_BUFFERS - 1;
188 cm->frame_bufs[cm->new_fb_idx].ref_count = 1;
189
190 for (i = 0; i < REF_FRAMES; i++) {
191 cm->ref_frame_map[i] = i;
192 cm->frame_bufs[i].ref_count = 1;
193 }
194
195 if (vp9_alloc_frame_buffer(&cm->post_proc_buffer, width, height, ss_x, ss_y,
196 VP9_ENC_BORDER_IN_PIXELS) < 0)
197 goto fail;
198 223
199 set_mb_mi(cm, aligned_width, aligned_height); 224 set_mb_mi(cm, aligned_width, aligned_height);
200 225
201 if (alloc_mi(cm, cm->mi_stride * (cm->mi_rows + MI_BLOCK_SIZE))) 226 if (alloc_mi(cm, cm->mi_stride * (cm->mi_rows + MI_BLOCK_SIZE)))
202 goto fail; 227 goto fail;
203 228
204 setup_mi(cm); 229 setup_mi(cm);
205 230
206 // Create the segmentation map structure and set to 0. 231 // Create the segmentation map structure and set to 0.
207 cm->last_frame_seg_map = (uint8_t *)vpx_calloc(cm->mi_rows * cm->mi_cols, 1); 232 cm->last_frame_seg_map = (uint8_t *)vpx_calloc(cm->mi_rows * cm->mi_cols, 1);
208 if (!cm->last_frame_seg_map) 233 if (!cm->last_frame_seg_map)
209 goto fail; 234 goto fail;
210 235
211 cm->above_context = 236 cm->above_context =
212 (ENTROPY_CONTEXT *)vpx_calloc(2 * mi_cols_aligned_to_sb(cm->mi_cols) * 237 (ENTROPY_CONTEXT *)vpx_calloc(2 * mi_cols_aligned_to_sb(cm->mi_cols) *
213 MAX_MB_PLANE, 238 MAX_MB_PLANE,
214 sizeof(*cm->above_context)); 239 sizeof(*cm->above_context));
215 if (!cm->above_context) 240 if (!cm->above_context)
216 goto fail; 241 goto fail;
217 242
218 cm->above_seg_context = 243 cm->above_seg_context =
219 (PARTITION_CONTEXT *)vpx_calloc(mi_cols_aligned_to_sb(cm->mi_cols), 244 (PARTITION_CONTEXT *)vpx_calloc(mi_cols_aligned_to_sb(cm->mi_cols),
220 sizeof(*cm->above_seg_context)); 245 sizeof(*cm->above_seg_context));
221 if (!cm->above_seg_context) 246 if (!cm->above_seg_context)
222 goto fail; 247 goto fail;
223 248
224 return 0; 249 return 0;
225 250
226 fail: 251 fail:
227 vp9_free_frame_buffers(cm); 252 vp9_free_context_buffers(cm);
228 return 1; 253 return 1;
229 } 254 }
230 255
231 void vp9_remove_common(VP9_COMMON *cm) { 256 void vp9_remove_common(VP9_COMMON *cm) {
232 vp9_free_frame_buffers(cm); 257 vp9_free_frame_buffers(cm);
258 vp9_free_context_buffers(cm);
233 vp9_free_internal_frame_buffers(&cm->int_frame_buffers); 259 vp9_free_internal_frame_buffers(&cm->int_frame_buffers);
234 } 260 }
235 261
236 void vp9_update_frame_size(VP9_COMMON *cm) { 262 void vp9_update_frame_size(VP9_COMMON *cm) {
237 const int aligned_width = ALIGN_POWER_OF_TWO(cm->width, MI_SIZE_LOG2); 263 const int aligned_width = ALIGN_POWER_OF_TWO(cm->width, MI_SIZE_LOG2);
238 const int aligned_height = ALIGN_POWER_OF_TWO(cm->height, MI_SIZE_LOG2); 264 const int aligned_height = ALIGN_POWER_OF_TWO(cm->height, MI_SIZE_LOG2);
239 265
240 set_mb_mi(cm, aligned_width, aligned_height); 266 set_mb_mi(cm, aligned_width, aligned_height);
241 setup_mi(cm); 267 setup_mi(cm);
242 268
(...skipping 13 matching lines...) Expand all
256 cm->prev_mip = cm->mip_array[cm->prev_mi_idx]; 282 cm->prev_mip = cm->mip_array[cm->prev_mi_idx];
257 cm->mi_grid_base = cm->mi_grid_base_array[cm->mi_idx]; 283 cm->mi_grid_base = cm->mi_grid_base_array[cm->mi_idx];
258 cm->prev_mi_grid_base = cm->mi_grid_base_array[cm->prev_mi_idx]; 284 cm->prev_mi_grid_base = cm->mi_grid_base_array[cm->prev_mi_idx];
259 285
260 // Update the upper left visible macroblock ptrs. 286 // Update the upper left visible macroblock ptrs.
261 cm->mi = cm->mip + cm->mi_stride + 1; 287 cm->mi = cm->mip + cm->mi_stride + 1;
262 cm->prev_mi = cm->prev_mip + cm->mi_stride + 1; 288 cm->prev_mi = cm->prev_mip + cm->mi_stride + 1;
263 cm->mi_grid_visible = cm->mi_grid_base + cm->mi_stride + 1; 289 cm->mi_grid_visible = cm->mi_grid_base + cm->mi_stride + 1;
264 cm->prev_mi_grid_visible = cm->prev_mi_grid_base + cm->mi_stride + 1; 290 cm->prev_mi_grid_visible = cm->prev_mi_grid_base + cm->mi_stride + 1;
265 } 291 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/common/vp9_alloccommon.h ('k') | source/libvpx/vp9/common/vp9_blockd.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698