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
This commit is contained in:
mikhal@webrtc.org 2012-10-09 16:04:48 +00:00
parent 656477b930
commit e4c920fb3d
2 changed files with 9 additions and 6 deletions

View File

@ -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<uint8_t>::scoped_ptr_aligned new_buffer(
AlignedMalloc<uint8_t>(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;
}

View File

@ -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<uint8_t> buffer_;
Allocator<uint8_t>::scoped_ptr_aligned buffer_;
int allocated_size_;
int plane_size_;
int stride_;