diff options
author | John Koleszar <jkoleszar@google.com> | 2013-02-06 14:22:17 -0800 |
---|---|---|
committer | John Koleszar <jkoleszar@google.com> | 2013-02-08 12:20:30 -0800 |
commit | c03d45def9ff03fd1ee35070f59928f702e7b8e9 (patch) | |
tree | 0af950dd7413665deeedcbd3fa41205e430a153b /vpx_scale | |
parent | 88f99f4ec29d1df6cb99e47562734df7bd9a6892 (diff) | |
download | libvpx-c03d45def9ff03fd1ee35070f59928f702e7b8e9.tar.gz libvpx-c03d45def9ff03fd1ee35070f59928f702e7b8e9.tar.bz2 libvpx-c03d45def9ff03fd1ee35070f59928f702e7b8e9.zip |
Avoid allocating memory when resizing frames
As long as the new frame is smaller than the size that was originally
allocated, we don't need to free and reallocate the memory allocated.
Instead, do the allocation on the size of the first frame. We could
make this passed in from the application instead, if we wanted to
support external upscaling.
Change-Id: I204d17a130728bbd91155bb4bd863a99bb99b038
Diffstat (limited to 'vpx_scale')
-rw-r--r-- | vpx_scale/generic/yv12config.c | 38 | ||||
-rw-r--r-- | vpx_scale/generic/yv12extend.c | 5 | ||||
-rw-r--r-- | vpx_scale/yv12config.h | 3 |
3 files changed, 28 insertions, 18 deletions
diff --git a/vpx_scale/generic/yv12config.c b/vpx_scale/generic/yv12config.c index 4cb2a4190..267d55f40 100644 --- a/vpx_scale/generic/yv12config.c +++ b/vpx_scale/generic/yv12config.c @@ -35,13 +35,8 @@ vp8_yv12_de_alloc_frame_buffer(YV12_BUFFER_CONFIG *ybf) { return 0; } -/**************************************************************************** - * - ****************************************************************************/ -int -vp8_yv12_alloc_frame_buffer(YV12_BUFFER_CONFIG *ybf, int width, int height, int border) { - /*NOTE:*/ - +int vp8_yv12_realloc_frame_buffer(YV12_BUFFER_CONFIG *ybf, + int width, int height, int border) { if (ybf) { int y_stride = ((width + 2 * border) + 31) & ~31; int yplane_size = (height + 2 * border) * y_stride; @@ -51,8 +46,15 @@ vp8_yv12_alloc_frame_buffer(YV12_BUFFER_CONFIG *ybf, int width, int height, int * uv_stride == y_stride/2, so enforce this here. */ int uv_stride = y_stride >> 1; int uvplane_size = (uv_height + border) * uv_stride; + const int frame_size = yplane_size + 2 * uvplane_size; - vp8_yv12_de_alloc_frame_buffer(ybf); + if (!ybf->buffer_alloc) { + ybf->buffer_alloc = vpx_memalign(32, frame_size); + ybf->buffer_alloc_sz = frame_size; + } + + if (!ybf->buffer_alloc || ybf->buffer_alloc_sz < frame_size) + return -1; /** Only support allocating buffers that have a height and width that * are multiples of 16, and a border that's a multiple of 32. @@ -72,21 +74,23 @@ vp8_yv12_alloc_frame_buffer(YV12_BUFFER_CONFIG *ybf, int width, int height, int ybf->uv_stride = uv_stride; ybf->border = border; - ybf->frame_size = yplane_size + 2 * uvplane_size; - - ybf->buffer_alloc = (unsigned char *) vpx_memalign(32, ybf->frame_size); - - if (ybf->buffer_alloc == NULL) - return -1; + ybf->frame_size = frame_size; ybf->y_buffer = ybf->buffer_alloc + (border * y_stride) + border; ybf->u_buffer = ybf->buffer_alloc + yplane_size + (border / 2 * uv_stride) + border / 2; ybf->v_buffer = ybf->buffer_alloc + yplane_size + uvplane_size + (border / 2 * uv_stride) + border / 2; ybf->corrupted = 0; /* assume not currupted by errors */ - } else { - return -2; + return 0; } + return -2; +} - return 0; +int vp8_yv12_alloc_frame_buffer(YV12_BUFFER_CONFIG *ybf, + int width, int height, int border) { + if (ybf) { + vp8_yv12_de_alloc_frame_buffer(ybf); + return vp8_yv12_realloc_frame_buffer(ybf, width, height, border); + } + return -2; } diff --git a/vpx_scale/generic/yv12extend.c b/vpx_scale/generic/yv12extend.c index 5a427356b..d733bd49d 100644 --- a/vpx_scale/generic/yv12extend.c +++ b/vpx_scale/generic/yv12extend.c @@ -8,7 +8,7 @@ * be found in the AUTHORS file in the root of the source tree. */ - +#include <assert.h> #include "vpx_scale/yv12config.h" #include "vpx_mem/vpx_mem.h" #include "vpx_scale/vpx_scale.h" @@ -216,6 +216,9 @@ vp8_yv12_copy_frame_c(YV12_BUFFER_CONFIG *src_ybc, int row; unsigned char *source, *dest; + assert(src_ybc->y_width == dst_ybc->y_width); + assert(src_ybc->y_height == dst_ybc->y_height); + source = src_ybc->y_buffer; dest = dst_ybc->y_buffer; diff --git a/vpx_scale/yv12config.h b/vpx_scale/yv12config.h index 23be8f3dd..45e57f401 100644 --- a/vpx_scale/yv12config.h +++ b/vpx_scale/yv12config.h @@ -55,6 +55,7 @@ extern "C" { uint8_t *v_buffer; uint8_t *buffer_alloc; + int buffer_alloc_sz; int border; int frame_size; YUV_TYPE clrtype; @@ -65,6 +66,8 @@ extern "C" { int vp8_yv12_alloc_frame_buffer(YV12_BUFFER_CONFIG *ybf, int width, int height, int border); + int vp8_yv12_realloc_frame_buffer(YV12_BUFFER_CONFIG *ybf, + int width, int height, int border); int vp8_yv12_de_alloc_frame_buffer(YV12_BUFFER_CONFIG *ybf); #ifdef __cplusplus |