From e4c920fb3db651d800d73fbdc2bef54831579211 Mon Sep 17 00:00:00 2001 From: "mikhal@webrtc.org" Date: Tue, 9 Oct 2012 16:04:48 +0000 Subject: [PATCH] Adding plane alignment. Review URL: https://webrtc-codereview.appspot.com/857008 git-svn-id: http://webrtc.googlecode.com/svn/trunk@2891 4adac7df-926f-26a2-2b94-8c16560cd09d --- src/common_video/plane.cc | 11 +++++++---- src/common_video/plane.h | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/common_video/plane.cc b/src/common_video/plane.cc index e47208f633..dc20c62703 100644 --- a/src/common_video/plane.cc +++ b/src/common_video/plane.cc @@ -15,6 +15,9 @@ namespace webrtc { +// Aligning pointer to 64 bytes for improved performance, e.g. use SIMD. +static const int kBufferAlignment = 64; + Plane::Plane() : buffer_(NULL), allocated_size_(0), @@ -37,12 +40,12 @@ int Plane::MaybeResize(int new_size) { return -1; if (new_size <= allocated_size_) return 0; - uint8_t* new_buffer = new uint8_t[new_size]; + Allocator::scoped_ptr_aligned new_buffer( + AlignedMalloc(new_size, kBufferAlignment)); if (buffer_.get()) { - memcpy(new_buffer, buffer_.get(), plane_size_); - buffer_.reset(); + memcpy(new_buffer.get(), buffer_.get(), plane_size_); } - buffer_.reset(new_buffer); + buffer_.reset(new_buffer.release()); allocated_size_ = new_size; return 0; } diff --git a/src/common_video/plane.h b/src/common_video/plane.h index 795f800a66..c6d08cefb3 100644 --- a/src/common_video/plane.h +++ b/src/common_video/plane.h @@ -11,7 +11,7 @@ #ifndef COMMON_VIDEO_PLANE_H #define COMMON_VIDEO_PLANE_H -#include "system_wrappers/interface/scoped_ptr.h" +#include "system_wrappers/interface/aligned_malloc.h" #include "typedefs.h" //NOLINT namespace webrtc { @@ -57,7 +57,7 @@ class Plane { // Return value: 0 on success ,-1 on error. int MaybeResize(int new_size); - scoped_array buffer_; + Allocator::scoped_ptr_aligned buffer_; int allocated_size_; int plane_size_; int stride_;