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

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

Issue 232133009: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years, 8 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
11
12 #include "./vpx_config.h" 11 #include "./vpx_config.h"
13 #include "vpx_mem/vpx_mem.h" 12 #include "vpx_mem/vpx_mem.h"
14 13
15 #include "vp9/common/vp9_blockd.h" 14 #include "vp9/common/vp9_blockd.h"
16 #include "vp9/common/vp9_entropymode.h" 15 #include "vp9/common/vp9_entropymode.h"
17 #include "vp9/common/vp9_entropymv.h" 16 #include "vp9/common/vp9_entropymv.h"
18 #include "vp9/common/vp9_onyxc_int.h" 17 #include "vp9/common/vp9_onyxc_int.h"
19 #include "vp9/common/vp9_systemdependent.h" 18 #include "vp9/common/vp9_systemdependent.h"
20 19
21 void vp9_update_mode_info_border(VP9_COMMON *cm, MODE_INFO *mi) { 20 static void clear_mi_border(const VP9_COMMON *cm, MODE_INFO *mi) {
22 const int stride = cm->mode_info_stride;
23 int i; 21 int i;
24 22
25 // Clear down top border row 23 // Top border row
26 vpx_memset(mi, 0, sizeof(MODE_INFO) * stride); 24 vpx_memset(mi, 0, sizeof(*mi) * cm->mi_stride);
27 25
28 // Clear left border column 26 // Left border column
29 for (i = 1; i < cm->mi_rows + 1; i++) 27 for (i = 1; i < cm->mi_rows + 1; ++i)
30 vpx_memset(&mi[i * stride], 0, sizeof(MODE_INFO)); 28 vpx_memset(&mi[i * cm->mi_stride], 0, sizeof(*mi));
29 }
30
31 static void set_mb_mi(VP9_COMMON *cm, int aligned_width, int aligned_height) {
32 cm->mi_cols = aligned_width >> MI_SIZE_LOG2;
33 cm->mi_rows = aligned_height >> MI_SIZE_LOG2;
34 cm->mi_stride = cm->mi_cols + MI_BLOCK_SIZE;
35
36 cm->mb_cols = (cm->mi_cols + 1) >> 1;
37 cm->mb_rows = (cm->mi_rows + 1) >> 1;
38 cm->MBs = cm->mb_rows * cm->mb_cols;
39 }
40
41 static void setup_mi(VP9_COMMON *cm) {
42 cm->mi = cm->mip + cm->mi_stride + 1;
43 cm->prev_mi = cm->prev_mip + cm->mi_stride + 1;
44 cm->mi_grid_visible = cm->mi_grid_base + cm->mi_stride + 1;
45 cm->prev_mi_grid_visible = cm->prev_mi_grid_base + cm->mi_stride + 1;
46
47 vpx_memset(cm->mip, 0, cm->mi_stride * (cm->mi_rows + 1) * sizeof(*cm->mip));
48
49 vpx_memset(cm->mi_grid_base, 0, cm->mi_stride * (cm->mi_rows + 1) *
50 sizeof(*cm->mi_grid_base));
51
52 clear_mi_border(cm, cm->prev_mip);
53 }
54
55 static int alloc_mi(VP9_COMMON *cm, int mi_size) {
56 cm->mip = (MODE_INFO *)vpx_calloc(mi_size, sizeof(*cm->mip));
57 if (cm->mip == NULL)
58 return 1;
59
60 cm->prev_mip = (MODE_INFO *)vpx_calloc(mi_size, sizeof(*cm->prev_mip));
61 if (cm->prev_mip == NULL)
62 return 1;
63
64 cm->mi_grid_base =
65 (MODE_INFO **)vpx_calloc(mi_size, sizeof(*cm->mi_grid_base));
66 if (cm->mi_grid_base == NULL)
67 return 1;
68
69 cm->prev_mi_grid_base =
70 (MODE_INFO **)vpx_calloc(mi_size, sizeof(*cm->prev_mi_grid_base));
71 if (cm->prev_mi_grid_base == NULL)
72 return 1;
73
74 return 0;
75 }
76
77 static void free_mi(VP9_COMMON *cm) {
78 vpx_free(cm->mip);
79 vpx_free(cm->prev_mip);
80 vpx_free(cm->mi_grid_base);
81 vpx_free(cm->prev_mi_grid_base);
82
83 cm->mip = NULL;
84 cm->prev_mip = NULL;
85 cm->mi_grid_base = NULL;
86 cm->prev_mi_grid_base = NULL;
31 } 87 }
32 88
33 void vp9_free_frame_buffers(VP9_COMMON *cm) { 89 void vp9_free_frame_buffers(VP9_COMMON *cm) {
34 int i; 90 int i;
35 91
36 for (i = 0; i < FRAME_BUFFERS; i++) { 92 for (i = 0; i < FRAME_BUFFERS; ++i) {
37 vp9_free_frame_buffer(&cm->frame_bufs[i].buf); 93 vp9_free_frame_buffer(&cm->frame_bufs[i].buf);
38 94
39 if (cm->frame_bufs[i].ref_count > 0 && 95 if (cm->frame_bufs[i].ref_count > 0 &&
40 cm->frame_bufs[i].raw_frame_buffer.data != NULL) { 96 cm->frame_bufs[i].raw_frame_buffer.data != NULL) {
41 cm->release_fb_cb(cm->cb_priv, &cm->frame_bufs[i].raw_frame_buffer); 97 cm->release_fb_cb(cm->cb_priv, &cm->frame_bufs[i].raw_frame_buffer);
42 cm->frame_bufs[i].ref_count = 0; 98 cm->frame_bufs[i].ref_count = 0;
43 } 99 }
44 } 100 }
45 101
46 vp9_free_frame_buffer(&cm->post_proc_buffer); 102 vp9_free_frame_buffer(&cm->post_proc_buffer);
47 103
48 vpx_free(cm->mip); 104 free_mi(cm);
49 vpx_free(cm->prev_mip); 105
50 vpx_free(cm->last_frame_seg_map); 106 vpx_free(cm->last_frame_seg_map);
51 vpx_free(cm->mi_grid_base); 107 cm->last_frame_seg_map = NULL;
52 vpx_free(cm->prev_mi_grid_base);
53 108
54 cm->mip = NULL; 109 vpx_free(cm->above_context);
55 cm->prev_mip = NULL; 110 cm->above_context = NULL;
56 cm->last_frame_seg_map = NULL;
57 cm->mi_grid_base = NULL;
58 cm->prev_mi_grid_base = NULL;
59 }
60 111
61 static void set_mb_mi(VP9_COMMON *cm, int aligned_width, int aligned_height) { 112 vpx_free(cm->above_seg_context);
62 cm->mi_cols = aligned_width >> MI_SIZE_LOG2; 113 cm->above_seg_context = NULL;
63 cm->mi_rows = aligned_height >> MI_SIZE_LOG2;
64 cm->mode_info_stride = cm->mi_cols + MI_BLOCK_SIZE;
65
66 cm->mb_cols = (cm->mi_cols + 1) >> 1;
67 cm->mb_rows = (cm->mi_rows + 1) >> 1;
68 cm->MBs = cm->mb_rows * cm->mb_cols;
69 }
70
71 static void setup_mi(VP9_COMMON *cm) {
72 cm->mi = cm->mip + cm->mode_info_stride + 1;
73 cm->prev_mi = cm->prev_mip + cm->mode_info_stride + 1;
74 cm->mi_grid_visible = cm->mi_grid_base + cm->mode_info_stride + 1;
75 cm->prev_mi_grid_visible = cm->prev_mi_grid_base + cm->mode_info_stride + 1;
76
77 vpx_memset(cm->mip, 0,
78 cm->mode_info_stride * (cm->mi_rows + 1) * sizeof(MODE_INFO));
79
80 vpx_memset(cm->mi_grid_base, 0,
81 cm->mode_info_stride * (cm->mi_rows + 1) *
82 sizeof(*cm->mi_grid_base));
83
84 vp9_update_mode_info_border(cm, cm->prev_mip);
85 } 114 }
86 115
87 int vp9_resize_frame_buffers(VP9_COMMON *cm, int width, int height) { 116 int vp9_resize_frame_buffers(VP9_COMMON *cm, int width, int height) {
88 const int aligned_width = ALIGN_POWER_OF_TWO(width, MI_SIZE_LOG2); 117 const int aligned_width = ALIGN_POWER_OF_TWO(width, MI_SIZE_LOG2);
89 const int aligned_height = ALIGN_POWER_OF_TWO(height, MI_SIZE_LOG2); 118 const int aligned_height = ALIGN_POWER_OF_TWO(height, MI_SIZE_LOG2);
90 const int ss_x = cm->subsampling_x; 119 const int ss_x = cm->subsampling_x;
91 const int ss_y = cm->subsampling_y; 120 const int ss_y = cm->subsampling_y;
92 int mi_size;
93 121
94 if (vp9_realloc_frame_buffer(&cm->post_proc_buffer, width, height, ss_x, ss_y, 122 if (vp9_realloc_frame_buffer(&cm->post_proc_buffer, width, height, ss_x, ss_y,
95 VP9_DEC_BORDER_IN_PIXELS, NULL, NULL, NULL) < 0) 123 VP9_DEC_BORDER_IN_PIXELS, NULL, NULL, NULL) < 0)
96 goto fail; 124 goto fail;
97 125
98 set_mb_mi(cm, aligned_width, aligned_height); 126 set_mb_mi(cm, aligned_width, aligned_height);
99 127
100 // Allocation 128 free_mi(cm);
101 mi_size = cm->mode_info_stride * (cm->mi_rows + MI_BLOCK_SIZE); 129 if (alloc_mi(cm, cm->mi_stride * (cm->mi_rows + MI_BLOCK_SIZE)))
102
103 vpx_free(cm->mip);
104 cm->mip = vpx_calloc(mi_size, sizeof(MODE_INFO));
105 if (!cm->mip)
106 goto fail;
107
108 vpx_free(cm->prev_mip);
109 cm->prev_mip = vpx_calloc(mi_size, sizeof(MODE_INFO));
110 if (!cm->prev_mip)
111 goto fail;
112
113 vpx_free(cm->mi_grid_base);
114 cm->mi_grid_base = vpx_calloc(mi_size, sizeof(*cm->mi_grid_base));
115 if (!cm->mi_grid_base)
116 goto fail;
117
118 vpx_free(cm->prev_mi_grid_base);
119 cm->prev_mi_grid_base = vpx_calloc(mi_size, sizeof(*cm->prev_mi_grid_base));
120 if (!cm->prev_mi_grid_base)
121 goto fail; 130 goto fail;
122 131
123 setup_mi(cm); 132 setup_mi(cm);
124 133
125 // Create the segmentation map structure and set to 0. 134 // Create the segmentation map structure and set to 0.
126 vpx_free(cm->last_frame_seg_map); 135 vpx_free(cm->last_frame_seg_map);
127 cm->last_frame_seg_map = vpx_calloc(cm->mi_rows * cm->mi_cols, 1); 136 cm->last_frame_seg_map = (uint8_t *)vpx_calloc(cm->mi_rows * cm->mi_cols, 1);
128 if (!cm->last_frame_seg_map) 137 if (!cm->last_frame_seg_map)
129 goto fail; 138 goto fail;
130 139
140 vpx_free(cm->above_context);
141 cm->above_context =
142 (ENTROPY_CONTEXT *)vpx_calloc(2 * mi_cols_aligned_to_sb(cm->mi_cols) *
143 MAX_MB_PLANE,
144 sizeof(*cm->above_context));
145 if (!cm->above_context)
146 goto fail;
147
148 vpx_free(cm->above_seg_context);
149 cm->above_seg_context =
150 (PARTITION_CONTEXT *)vpx_calloc(mi_cols_aligned_to_sb(cm->mi_cols),
151 sizeof(*cm->above_seg_context));
152 if (!cm->above_seg_context)
153 goto fail;
154
131 return 0; 155 return 0;
132 156
133 fail: 157 fail:
134 vp9_free_frame_buffers(cm); 158 vp9_free_frame_buffers(cm);
135 return 1; 159 return 1;
136 } 160 }
137 161
138 int vp9_alloc_frame_buffers(VP9_COMMON *cm, int width, int height) { 162 int vp9_alloc_frame_buffers(VP9_COMMON *cm, int width, int height) {
139 int i;
140
141 const int aligned_width = ALIGN_POWER_OF_TWO(width, MI_SIZE_LOG2); 163 const int aligned_width = ALIGN_POWER_OF_TWO(width, MI_SIZE_LOG2);
142 const int aligned_height = ALIGN_POWER_OF_TWO(height, MI_SIZE_LOG2); 164 const int aligned_height = ALIGN_POWER_OF_TWO(height, MI_SIZE_LOG2);
143 const int ss_x = cm->subsampling_x; 165 const int ss_x = cm->subsampling_x;
144 const int ss_y = cm->subsampling_y; 166 const int ss_y = cm->subsampling_y;
145 int mi_size; 167 int i;
146 168
147 vp9_free_frame_buffers(cm); 169 vp9_free_frame_buffers(cm);
148 170
149 for (i = 0; i < FRAME_BUFFERS; i++) { 171 for (i = 0; i < FRAME_BUFFERS; i++) {
150 cm->frame_bufs[i].ref_count = 0; 172 cm->frame_bufs[i].ref_count = 0;
151 if (vp9_alloc_frame_buffer(&cm->frame_bufs[i].buf, width, height, 173 if (vp9_alloc_frame_buffer(&cm->frame_bufs[i].buf, width, height,
152 ss_x, ss_y, VP9_ENC_BORDER_IN_PIXELS) < 0) 174 ss_x, ss_y, VP9_ENC_BORDER_IN_PIXELS) < 0)
153 goto fail; 175 goto fail;
154 } 176 }
155 177
156 cm->new_fb_idx = FRAME_BUFFERS - 1; 178 cm->new_fb_idx = FRAME_BUFFERS - 1;
157 cm->frame_bufs[cm->new_fb_idx].ref_count = 1; 179 cm->frame_bufs[cm->new_fb_idx].ref_count = 1;
158 180
159 for (i = 0; i < REF_FRAMES; i++) { 181 for (i = 0; i < REF_FRAMES; i++) {
160 cm->ref_frame_map[i] = i; 182 cm->ref_frame_map[i] = i;
161 cm->frame_bufs[i].ref_count = 1; 183 cm->frame_bufs[i].ref_count = 1;
162 } 184 }
163 185
164 if (vp9_alloc_frame_buffer(&cm->post_proc_buffer, width, height, ss_x, ss_y, 186 if (vp9_alloc_frame_buffer(&cm->post_proc_buffer, width, height, ss_x, ss_y,
165 VP9_ENC_BORDER_IN_PIXELS) < 0) 187 VP9_ENC_BORDER_IN_PIXELS) < 0)
166 goto fail; 188 goto fail;
167 189
168 set_mb_mi(cm, aligned_width, aligned_height); 190 set_mb_mi(cm, aligned_width, aligned_height);
169 191
170 // Allocation 192 if (alloc_mi(cm, cm->mi_stride * (cm->mi_rows + MI_BLOCK_SIZE)))
171 mi_size = cm->mode_info_stride * (cm->mi_rows + MI_BLOCK_SIZE);
172
173 cm->mip = vpx_calloc(mi_size, sizeof(MODE_INFO));
174 if (!cm->mip)
175 goto fail;
176
177 cm->prev_mip = vpx_calloc(mi_size, sizeof(MODE_INFO));
178 if (!cm->prev_mip)
179 goto fail;
180
181 cm->mi_grid_base = vpx_calloc(mi_size, sizeof(*cm->mi_grid_base));
182 if (!cm->mi_grid_base)
183 goto fail;
184
185 cm->prev_mi_grid_base = vpx_calloc(mi_size, sizeof(*cm->prev_mi_grid_base));
186 if (!cm->prev_mi_grid_base)
187 goto fail; 193 goto fail;
188 194
189 setup_mi(cm); 195 setup_mi(cm);
190 196
191 // Create the segmentation map structure and set to 0. 197 // Create the segmentation map structure and set to 0.
192 cm->last_frame_seg_map = vpx_calloc(cm->mi_rows * cm->mi_cols, 1); 198 cm->last_frame_seg_map = (uint8_t *)vpx_calloc(cm->mi_rows * cm->mi_cols, 1);
193 if (!cm->last_frame_seg_map) 199 if (!cm->last_frame_seg_map)
194 goto fail; 200 goto fail;
195 201
202 cm->above_context =
203 (ENTROPY_CONTEXT *)vpx_calloc(2 * mi_cols_aligned_to_sb(cm->mi_cols) *
204 MAX_MB_PLANE,
205 sizeof(*cm->above_context));
206 if (!cm->above_context)
207 goto fail;
208
209 cm->above_seg_context =
210 (PARTITION_CONTEXT *)vpx_calloc(mi_cols_aligned_to_sb(cm->mi_cols),
211 sizeof(*cm->above_seg_context));
212 if (!cm->above_seg_context)
213 goto fail;
214
196 return 0; 215 return 0;
197 216
198 fail: 217 fail:
199 vp9_free_frame_buffers(cm); 218 vp9_free_frame_buffers(cm);
200 return 1; 219 return 1;
201 } 220 }
202 221
203 void vp9_remove_common(VP9_COMMON *cm) { 222 void vp9_remove_common(VP9_COMMON *cm) {
204 vp9_free_frame_buffers(cm); 223 vp9_free_frame_buffers(cm);
205 vp9_free_internal_frame_buffers(&cm->int_frame_buffers); 224 vp9_free_internal_frame_buffers(&cm->int_frame_buffers);
206 } 225 }
207 226
208 void vp9_initialize_common() {
209 vp9_init_neighbors();
210 }
211
212 void vp9_update_frame_size(VP9_COMMON *cm) { 227 void vp9_update_frame_size(VP9_COMMON *cm) {
213 const int aligned_width = ALIGN_POWER_OF_TWO(cm->width, MI_SIZE_LOG2); 228 const int aligned_width = ALIGN_POWER_OF_TWO(cm->width, MI_SIZE_LOG2);
214 const int aligned_height = ALIGN_POWER_OF_TWO(cm->height, MI_SIZE_LOG2); 229 const int aligned_height = ALIGN_POWER_OF_TWO(cm->height, MI_SIZE_LOG2);
215 230
216 set_mb_mi(cm, aligned_width, aligned_height); 231 set_mb_mi(cm, aligned_width, aligned_height);
217 setup_mi(cm); 232 setup_mi(cm);
218 233
219 // Initialize the previous frame segment map to 0. 234 // Initialize the previous frame segment map to 0.
220 if (cm->last_frame_seg_map) 235 if (cm->last_frame_seg_map)
221 vpx_memset(cm->last_frame_seg_map, 0, cm->mi_rows * cm->mi_cols); 236 vpx_memset(cm->last_frame_seg_map, 0, cm->mi_rows * cm->mi_cols);
222 } 237 }
238
239 void vp9_swap_mi_and_prev_mi(VP9_COMMON *cm) {
240 // Current mip will be the prev_mip for the next frame.
241 MODE_INFO *temp = cm->prev_mip;
242 MODE_INFO **temp2 = cm->prev_mi_grid_base;
243 cm->prev_mip = cm->mip;
244 cm->mip = temp;
245 cm->prev_mi_grid_base = cm->mi_grid_base;
246 cm->mi_grid_base = temp2;
247
248 // Update the upper left visible macroblock ptrs.
249 cm->mi = cm->mip + cm->mi_stride + 1;
250 cm->prev_mi = cm->prev_mip + cm->mi_stride + 1;
251 cm->mi_grid_visible = cm->mi_grid_base + cm->mi_stride + 1;
252 cm->prev_mi_grid_visible = cm->prev_mi_grid_base + cm->mi_stride + 1;
253 }
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