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

Side by Side Diff: source/libvpx/vpx_scale/generic/yv12config.c

Issue 111463005: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 7 years 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/vpx_ports/x86_cpuid.c ('k') | source/libvpx/vpx_scale/generic/yv12extend.c » ('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 #include "./vpx_config.h" 11 #include "./vpx_config.h"
12 #include "vpx_scale/yv12config.h" 12 #include "vpx_scale/yv12config.h"
13 #include "vpx_mem/vpx_mem.h" 13 #include "vpx_mem/vpx_mem.h"
14 14
15 /**************************************************************************** 15 /****************************************************************************
16 * Exports 16 * Exports
17 ****************************************************************************/ 17 ****************************************************************************/
18 18
19 /**************************************************************************** 19 /****************************************************************************
20 * 20 *
21 ****************************************************************************/ 21 ****************************************************************************/
22
23 #define yv12_align_addr(addr, align) \
24 (void*)(((size_t)(addr) + ((align) - 1)) & (size_t)-(align))
25
22 int 26 int
23 vp8_yv12_de_alloc_frame_buffer(YV12_BUFFER_CONFIG *ybf) { 27 vp8_yv12_de_alloc_frame_buffer(YV12_BUFFER_CONFIG *ybf) {
24 if (ybf) { 28 if (ybf) {
25 vpx_free(ybf->buffer_alloc); 29 // If libvpx is using external frame buffers then buffer_alloc_sz must
30 // not be set.
31 if (ybf->buffer_alloc_sz > 0) {
32 vpx_free(ybf->buffer_alloc);
33 }
26 34
27 /* buffer_alloc isn't accessed by most functions. Rather y_buffer, 35 /* buffer_alloc isn't accessed by most functions. Rather y_buffer,
28 u_buffer and v_buffer point to buffer_alloc and are used. Clear out 36 u_buffer and v_buffer point to buffer_alloc and are used. Clear out
29 all of this so that a freed pointer isn't inadvertently used */ 37 all of this so that a freed pointer isn't inadvertently used */
30 vpx_memset(ybf, 0, sizeof(YV12_BUFFER_CONFIG)); 38 vpx_memset(ybf, 0, sizeof(YV12_BUFFER_CONFIG));
31 } else { 39 } else {
32 return -1; 40 return -1;
33 } 41 }
34 42
35 return 0; 43 return 0;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 return vp8_yv12_realloc_frame_buffer(ybf, width, height, border); 109 return vp8_yv12_realloc_frame_buffer(ybf, width, height, border);
102 } 110 }
103 return -2; 111 return -2;
104 } 112 }
105 113
106 #if CONFIG_VP9 114 #if CONFIG_VP9
107 // TODO(jkoleszar): Maybe replace this with struct vpx_image 115 // TODO(jkoleszar): Maybe replace this with struct vpx_image
108 116
109 int vp9_free_frame_buffer(YV12_BUFFER_CONFIG *ybf) { 117 int vp9_free_frame_buffer(YV12_BUFFER_CONFIG *ybf) {
110 if (ybf) { 118 if (ybf) {
111 vpx_free(ybf->buffer_alloc); 119 if (ybf->buffer_alloc_sz > 0) {
120 vpx_free(ybf->buffer_alloc);
121 }
112 122
113 /* buffer_alloc isn't accessed by most functions. Rather y_buffer, 123 /* buffer_alloc isn't accessed by most functions. Rather y_buffer,
114 u_buffer and v_buffer point to buffer_alloc and are used. Clear out 124 u_buffer and v_buffer point to buffer_alloc and are used. Clear out
115 all of this so that a freed pointer isn't inadvertently used */ 125 all of this so that a freed pointer isn't inadvertently used */
116 vpx_memset(ybf, 0, sizeof(YV12_BUFFER_CONFIG)); 126 vpx_memset(ybf, 0, sizeof(YV12_BUFFER_CONFIG));
117 } else { 127 } else {
118 return -1; 128 return -1;
119 } 129 }
120 130
121 return 0; 131 return 0;
122 } 132 }
123 133
124 int vp9_realloc_frame_buffer(YV12_BUFFER_CONFIG *ybf, 134 int vp9_realloc_frame_buffer(YV12_BUFFER_CONFIG *ybf,
125 int width, int height, 135 int width, int height,
126 int ss_x, int ss_y, int border) { 136 int ss_x, int ss_y, int border,
137 vpx_codec_frame_buffer_t *ext_fb,
138 vpx_realloc_frame_buffer_cb_fn_t cb,
139 void *user_priv) {
127 if (ybf) { 140 if (ybf) {
128 const int aligned_width = (width + 7) & ~7; 141 const int aligned_width = (width + 7) & ~7;
129 const int aligned_height = (height + 7) & ~7; 142 const int aligned_height = (height + 7) & ~7;
130 const int y_stride = ((aligned_width + 2 * border) + 31) & ~31; 143 const int y_stride = ((aligned_width + 2 * border) + 31) & ~31;
131 const int yplane_size = (aligned_height + 2 * border) * y_stride; 144 const int yplane_size = (aligned_height + 2 * border) * y_stride;
132 const int uv_width = aligned_width >> ss_x; 145 const int uv_width = aligned_width >> ss_x;
133 const int uv_height = aligned_height >> ss_y; 146 const int uv_height = aligned_height >> ss_y;
134 const int uv_stride = y_stride >> ss_x; 147 const int uv_stride = y_stride >> ss_x;
135 const int uv_border_w = border >> ss_x; 148 const int uv_border_w = border >> ss_x;
136 const int uv_border_h = border >> ss_y; 149 const int uv_border_h = border >> ss_y;
137 const int uvplane_size = (uv_height + 2 * uv_border_h) * uv_stride; 150 const int uvplane_size = (uv_height + 2 * uv_border_h) * uv_stride;
138 #if CONFIG_ALPHA 151 #if CONFIG_ALPHA
139 const int alpha_width = aligned_width; 152 const int alpha_width = aligned_width;
140 const int alpha_height = aligned_height; 153 const int alpha_height = aligned_height;
141 const int alpha_stride = y_stride; 154 const int alpha_stride = y_stride;
142 const int alpha_border_w = border; 155 const int alpha_border_w = border;
143 const int alpha_border_h = border; 156 const int alpha_border_h = border;
144 const int alpha_plane_size = (alpha_height + 2 * alpha_border_h) * 157 const int alpha_plane_size = (alpha_height + 2 * alpha_border_h) *
145 alpha_stride; 158 alpha_stride;
146 const int frame_size = yplane_size + 2 * uvplane_size + 159 const int frame_size = yplane_size + 2 * uvplane_size +
147 alpha_plane_size; 160 alpha_plane_size;
148 #else 161 #else
149 const int frame_size = yplane_size + 2 * uvplane_size; 162 const int frame_size = yplane_size + 2 * uvplane_size;
150 #endif 163 #endif
151 if (!ybf->buffer_alloc) { 164
152 ybf->buffer_alloc = vpx_memalign(32, frame_size); 165 if (ext_fb != NULL) {
153 ybf->buffer_alloc_sz = frame_size; 166 const int align_addr_extra_size = 31;
167 const int external_frame_size = frame_size + align_addr_extra_size;
168 if (external_frame_size > ext_fb->size) {
169 // Allocation to hold larger frame, or first allocation.
170 if (cb(user_priv, external_frame_size, ext_fb) < 0) {
171 return -1;
172 }
173
174 if (ext_fb->data == NULL || ext_fb->size < external_frame_size) {
175 return -1;
176 }
177
178 ybf->buffer_alloc = yv12_align_addr(ext_fb->data, 32);
179 }
180 } else {
181 if (frame_size > ybf->buffer_alloc_sz) {
182 // Allocation to hold larger frame, or first allocation.
183 if (ybf->buffer_alloc)
184 vpx_free(ybf->buffer_alloc);
185 ybf->buffer_alloc = vpx_memalign(32, frame_size);
186 ybf->buffer_alloc_sz = frame_size;
187 }
188
189 if (ybf->buffer_alloc_sz < frame_size)
190 return -1;
154 } 191 }
155 192
156 if (!ybf->buffer_alloc || ybf->buffer_alloc_sz < frame_size) 193 if (!ybf->buffer_alloc)
157 return -1; 194 return -1;
158 195
159 /* Only support allocating buffers that have a border that's a multiple 196 /* Only support allocating buffers that have a border that's a multiple
160 * of 32. The border restriction is required to get 16-byte alignment of 197 * of 32. The border restriction is required to get 16-byte alignment of
161 * the start of the chroma rows without introducing an arbitrary gap 198 * the start of the chroma rows without introducing an arbitrary gap
162 * between planes, which would break the semantics of things like 199 * between planes, which would break the semantics of things like
163 * vpx_img_set_rect(). */ 200 * vpx_img_set_rect(). */
164 if (border & 0x1f) 201 if (border & 0x1f)
165 return -3; 202 return -3;
166 203
(...skipping 29 matching lines...) Expand all
196 return 0; 233 return 0;
197 } 234 }
198 return -2; 235 return -2;
199 } 236 }
200 237
201 int vp9_alloc_frame_buffer(YV12_BUFFER_CONFIG *ybf, 238 int vp9_alloc_frame_buffer(YV12_BUFFER_CONFIG *ybf,
202 int width, int height, 239 int width, int height,
203 int ss_x, int ss_y, int border) { 240 int ss_x, int ss_y, int border) {
204 if (ybf) { 241 if (ybf) {
205 vp9_free_frame_buffer(ybf); 242 vp9_free_frame_buffer(ybf);
206 return vp9_realloc_frame_buffer(ybf, width, height, ss_x, ss_y, border); 243 return vp9_realloc_frame_buffer(ybf, width, height, ss_x, ss_y, border,
244 NULL, NULL, NULL);
207 } 245 }
208 return -2; 246 return -2;
209 } 247 }
210 #endif 248 #endif
OLDNEW
« no previous file with comments | « source/libvpx/vpx_ports/x86_cpuid.c ('k') | source/libvpx/vpx_scale/generic/yv12extend.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698