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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 return 0; | 136 return 0; |
137 } | 137 } |
138 | 138 |
139 int vp9_realloc_frame_buffer(YV12_BUFFER_CONFIG *ybf, | 139 int vp9_realloc_frame_buffer(YV12_BUFFER_CONFIG *ybf, |
140 int width, int height, | 140 int width, int height, |
141 int ss_x, int ss_y, | 141 int ss_x, int ss_y, |
142 #if CONFIG_VP9_HIGHBITDEPTH | 142 #if CONFIG_VP9_HIGHBITDEPTH |
143 int use_highbitdepth, | 143 int use_highbitdepth, |
144 #endif | 144 #endif |
145 int border, | 145 int border, |
| 146 int byte_alignment, |
146 vpx_codec_frame_buffer_t *fb, | 147 vpx_codec_frame_buffer_t *fb, |
147 vpx_get_frame_buffer_cb_fn_t cb, | 148 vpx_get_frame_buffer_cb_fn_t cb, |
148 void *cb_priv) { | 149 void *cb_priv) { |
149 if (ybf) { | 150 if (ybf) { |
| 151 const int vp9_byte_align = (byte_alignment == 0) ? 1 : byte_alignment; |
150 const int aligned_width = (width + 7) & ~7; | 152 const int aligned_width = (width + 7) & ~7; |
151 const int aligned_height = (height + 7) & ~7; | 153 const int aligned_height = (height + 7) & ~7; |
152 const int y_stride = ((aligned_width + 2 * border) + 31) & ~31; | 154 const int y_stride = ((aligned_width + 2 * border) + 31) & ~31; |
153 const uint64_t yplane_size = (aligned_height + 2 * border) * | 155 const uint64_t yplane_size = (aligned_height + 2 * border) * |
154 (uint64_t)y_stride; | 156 (uint64_t)y_stride + byte_alignment; |
155 const int uv_width = aligned_width >> ss_x; | 157 const int uv_width = aligned_width >> ss_x; |
156 const int uv_height = aligned_height >> ss_y; | 158 const int uv_height = aligned_height >> ss_y; |
157 const int uv_stride = y_stride >> ss_x; | 159 const int uv_stride = y_stride >> ss_x; |
158 const int uv_border_w = border >> ss_x; | 160 const int uv_border_w = border >> ss_x; |
159 const int uv_border_h = border >> ss_y; | 161 const int uv_border_h = border >> ss_y; |
160 const uint64_t uvplane_size = (uv_height + 2 * uv_border_h) * | 162 const uint64_t uvplane_size = (uv_height + 2 * uv_border_h) * |
161 (uint64_t)uv_stride; | 163 (uint64_t)uv_stride + byte_alignment; |
| 164 |
162 #if CONFIG_ALPHA | 165 #if CONFIG_ALPHA |
163 const int alpha_width = aligned_width; | 166 const int alpha_width = aligned_width; |
164 const int alpha_height = aligned_height; | 167 const int alpha_height = aligned_height; |
165 const int alpha_stride = y_stride; | 168 const int alpha_stride = y_stride; |
166 const int alpha_border_w = border; | 169 const int alpha_border_w = border; |
167 const int alpha_border_h = border; | 170 const int alpha_border_h = border; |
168 const uint64_t alpha_plane_size = (alpha_height + 2 * alpha_border_h) * | 171 const uint64_t alpha_plane_size = (alpha_height + 2 * alpha_border_h) * |
169 (uint64_t)alpha_stride; | 172 (uint64_t)alpha_stride + byte_alignment; |
170 #if CONFIG_VP9_HIGHBITDEPTH | 173 #if CONFIG_VP9_HIGHBITDEPTH |
171 const uint64_t frame_size = (1 + use_highbitdepth) * | 174 const uint64_t frame_size = (1 + use_highbitdepth) * |
172 (yplane_size + 2 * uvplane_size + alpha_plane_size); | 175 (yplane_size + 2 * uvplane_size + alpha_plane_size); |
173 #else | 176 #else |
174 const uint64_t frame_size = yplane_size + 2 * uvplane_size + | 177 const uint64_t frame_size = yplane_size + 2 * uvplane_size + |
175 alpha_plane_size; | 178 alpha_plane_size; |
176 #endif // CONFIG_VP9_HIGHBITDEPTH | 179 #endif // CONFIG_VP9_HIGHBITDEPTH |
177 #else | 180 #else |
178 #if CONFIG_VP9_HIGHBITDEPTH | 181 #if CONFIG_VP9_HIGHBITDEPTH |
179 const uint64_t frame_size = | 182 const uint64_t frame_size = |
180 (1 + use_highbitdepth) * (yplane_size + 2 * uvplane_size); | 183 (1 + use_highbitdepth) * (yplane_size + 2 * uvplane_size); |
181 #else | 184 #else |
182 const uint64_t frame_size = yplane_size + 2 * uvplane_size; | 185 const uint64_t frame_size = yplane_size + 2 * uvplane_size; |
183 #endif // CONFIG_VP9_HIGHBITDEPTH | 186 #endif // CONFIG_VP9_HIGHBITDEPTH |
184 #endif // CONFIG_ALPHA | 187 #endif // CONFIG_ALPHA |
| 188 |
| 189 uint8_t *buf = NULL; |
| 190 |
185 if (cb != NULL) { | 191 if (cb != NULL) { |
186 const int align_addr_extra_size = 31; | 192 const int align_addr_extra_size = 31; |
187 const uint64_t external_frame_size = frame_size + align_addr_extra_size; | 193 const uint64_t external_frame_size = frame_size + align_addr_extra_size; |
188 | 194 |
189 assert(fb != NULL); | 195 assert(fb != NULL); |
190 | 196 |
191 if (external_frame_size != (size_t)external_frame_size) | 197 if (external_frame_size != (size_t)external_frame_size) |
192 return -1; | 198 return -1; |
193 | 199 |
194 // Allocation to hold larger frame, or first allocation. | 200 // Allocation to hold larger frame, or first allocation. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 ybf->uv_crop_height = (height + ss_y) >> ss_y; | 243 ybf->uv_crop_height = (height + ss_y) >> ss_y; |
238 ybf->uv_width = uv_width; | 244 ybf->uv_width = uv_width; |
239 ybf->uv_height = uv_height; | 245 ybf->uv_height = uv_height; |
240 ybf->uv_stride = uv_stride; | 246 ybf->uv_stride = uv_stride; |
241 | 247 |
242 ybf->border = border; | 248 ybf->border = border; |
243 ybf->frame_size = (int)frame_size; | 249 ybf->frame_size = (int)frame_size; |
244 ybf->subsampling_x = ss_x; | 250 ybf->subsampling_x = ss_x; |
245 ybf->subsampling_y = ss_y; | 251 ybf->subsampling_y = ss_y; |
246 | 252 |
| 253 buf = ybf->buffer_alloc; |
247 #if CONFIG_VP9_HIGHBITDEPTH | 254 #if CONFIG_VP9_HIGHBITDEPTH |
248 if (use_highbitdepth) { | 255 if (use_highbitdepth) { |
249 // Store uint16 addresses when using 16bit framebuffers | 256 // Store uint16 addresses when using 16bit framebuffers |
250 uint8_t *p = CONVERT_TO_BYTEPTR(ybf->buffer_alloc); | 257 buf = CONVERT_TO_BYTEPTR(ybf->buffer_alloc); |
251 ybf->y_buffer = p + (border * y_stride) + border; | |
252 ybf->u_buffer = p + yplane_size + | |
253 (uv_border_h * uv_stride) + uv_border_w; | |
254 ybf->v_buffer = p + yplane_size + uvplane_size + | |
255 (uv_border_h * uv_stride) + uv_border_w; | |
256 ybf->flags = YV12_FLAG_HIGHBITDEPTH; | 258 ybf->flags = YV12_FLAG_HIGHBITDEPTH; |
257 } else { | 259 } else { |
258 ybf->y_buffer = ybf->buffer_alloc + (border * y_stride) + border; | |
259 ybf->u_buffer = ybf->buffer_alloc + yplane_size + | |
260 (uv_border_h * uv_stride) + uv_border_w; | |
261 ybf->v_buffer = ybf->buffer_alloc + yplane_size + uvplane_size + | |
262 (uv_border_h * uv_stride) + uv_border_w; | |
263 ybf->flags = 0; | 260 ybf->flags = 0; |
264 } | 261 } |
265 #else | |
266 ybf->y_buffer = ybf->buffer_alloc + (border * y_stride) + border; | |
267 ybf->u_buffer = ybf->buffer_alloc + yplane_size + | |
268 (uv_border_h * uv_stride) + uv_border_w; | |
269 ybf->v_buffer = ybf->buffer_alloc + yplane_size + uvplane_size + | |
270 (uv_border_h * uv_stride) + uv_border_w; | |
271 #endif // CONFIG_VP9_HIGHBITDEPTH | 262 #endif // CONFIG_VP9_HIGHBITDEPTH |
272 | 263 |
| 264 ybf->y_buffer = (uint8_t *)yv12_align_addr( |
| 265 buf + (border * y_stride) + border, vp9_byte_align); |
| 266 ybf->u_buffer = (uint8_t *)yv12_align_addr( |
| 267 buf + yplane_size + (uv_border_h * uv_stride) + uv_border_w, |
| 268 vp9_byte_align); |
| 269 ybf->v_buffer = (uint8_t *)yv12_align_addr( |
| 270 buf + yplane_size + uvplane_size + (uv_border_h * uv_stride) + |
| 271 uv_border_w, vp9_byte_align); |
| 272 |
273 #if CONFIG_ALPHA | 273 #if CONFIG_ALPHA |
274 ybf->alpha_width = alpha_width; | 274 ybf->alpha_width = alpha_width; |
275 ybf->alpha_height = alpha_height; | 275 ybf->alpha_height = alpha_height; |
276 ybf->alpha_stride = alpha_stride; | 276 ybf->alpha_stride = alpha_stride; |
277 ybf->alpha_buffer = ybf->buffer_alloc + yplane_size + 2 * uvplane_size + | 277 ybf->alpha_buffer = (uint8_t *)yv12_align_addr( |
278 (alpha_border_h * alpha_stride) + alpha_border_w; | 278 buf + yplane_size + 2 * uvplane_size + |
| 279 (alpha_border_h * alpha_stride) + alpha_border_w, vp9_byte_align); |
279 #endif | 280 #endif |
280 ybf->corrupted = 0; /* assume not corrupted by errors */ | 281 ybf->corrupted = 0; /* assume not corrupted by errors */ |
281 return 0; | 282 return 0; |
282 } | 283 } |
283 return -2; | 284 return -2; |
284 } | 285 } |
285 | 286 |
286 int vp9_alloc_frame_buffer(YV12_BUFFER_CONFIG *ybf, | 287 int vp9_alloc_frame_buffer(YV12_BUFFER_CONFIG *ybf, |
287 int width, int height, | 288 int width, int height, |
288 int ss_x, int ss_y, | 289 int ss_x, int ss_y, |
289 #if CONFIG_VP9_HIGHBITDEPTH | 290 #if CONFIG_VP9_HIGHBITDEPTH |
290 int use_highbitdepth, | 291 int use_highbitdepth, |
291 #endif | 292 #endif |
292 int border) { | 293 int border, |
| 294 int byte_alignment) { |
293 if (ybf) { | 295 if (ybf) { |
294 vp9_free_frame_buffer(ybf); | 296 vp9_free_frame_buffer(ybf); |
295 return vp9_realloc_frame_buffer(ybf, width, height, ss_x, ss_y, | 297 return vp9_realloc_frame_buffer(ybf, width, height, ss_x, ss_y, |
296 #if CONFIG_VP9_HIGHBITDEPTH | 298 #if CONFIG_VP9_HIGHBITDEPTH |
297 use_highbitdepth, | 299 use_highbitdepth, |
298 #endif | 300 #endif |
299 border, NULL, NULL, NULL); | 301 border, byte_alignment, NULL, NULL, NULL); |
300 } | 302 } |
301 return -2; | 303 return -2; |
302 } | 304 } |
303 #endif | 305 #endif |
OLD | NEW |