diff --git a/webrtc/common_audio/resampler/sinc_resampler.h b/webrtc/common_audio/resampler/sinc_resampler.h index 60abd6128f..7e6237adc0 100644 --- a/webrtc/common_audio/resampler/sinc_resampler.h +++ b/webrtc/common_audio/resampler/sinc_resampler.h @@ -146,12 +146,12 @@ class SincResampler { // Contains kKernelOffsetCount kernels back-to-back, each of size kKernelSize. // The kernel offsets are sub-sample shifts of a windowed sinc shifted from // 0.0 to 1.0 sample. - scoped_ptr_malloc kernel_storage_; - scoped_ptr_malloc kernel_pre_sinc_storage_; - scoped_ptr_malloc kernel_window_storage_; + scoped_ptr kernel_storage_; + scoped_ptr kernel_pre_sinc_storage_; + scoped_ptr kernel_window_storage_; // Data from the source is copied into this buffer for each processing pass. - scoped_ptr_malloc input_buffer_; + scoped_ptr input_buffer_; // Stores the runtime selection of which Convolve function to use. // TODO(ajm): Move to using a global static which must only be initialized diff --git a/webrtc/common_video/plane.cc b/webrtc/common_video/plane.cc index 68d32cd459..3776de1323 100644 --- a/webrtc/common_video/plane.cc +++ b/webrtc/common_video/plane.cc @@ -20,8 +20,7 @@ namespace webrtc { static const int kBufferAlignment = 64; Plane::Plane() - : buffer_(NULL), - allocated_size_(0), + : allocated_size_(0), plane_size_(0), stride_(0) {} @@ -42,8 +41,8 @@ int Plane::MaybeResize(int new_size) { return -1; if (new_size <= allocated_size_) return 0; - Allocator::scoped_ptr_aligned new_buffer( - AlignedMalloc(new_size, kBufferAlignment)); + scoped_ptr new_buffer(static_cast( + AlignedMalloc(new_size, kBufferAlignment))); if (buffer_.get()) { memcpy(new_buffer.get(), buffer_.get(), plane_size_); } diff --git a/webrtc/common_video/plane.h b/webrtc/common_video/plane.h index 1b74f37ec0..4031e03b4c 100644 --- a/webrtc/common_video/plane.h +++ b/webrtc/common_video/plane.h @@ -12,6 +12,7 @@ #define COMMON_VIDEO_PLANE_H #include "webrtc/system_wrappers/interface/aligned_malloc.h" +#include "webrtc/system_wrappers/interface/scoped_ptr.h" #include "webrtc/typedefs.h" namespace webrtc { @@ -63,7 +64,7 @@ class Plane { // Return value: 0 on success ,-1 on error. int MaybeResize(int new_size); - Allocator::scoped_ptr_aligned buffer_; + scoped_ptr buffer_; int allocated_size_; int plane_size_; int stride_; diff --git a/webrtc/modules/audio_processing/utility/ring_buffer_unittest.cc b/webrtc/modules/audio_processing/utility/ring_buffer_unittest.cc index 2b7634dd07..bd68f9489b 100644 --- a/webrtc/modules/audio_processing/utility/ring_buffer_unittest.cc +++ b/webrtc/modules/audio_processing/utility/ring_buffer_unittest.cc @@ -22,7 +22,12 @@ extern "C" { namespace webrtc { -typedef scoped_ptr_malloc scoped_ring_buffer; +struct FreeBufferDeleter { + inline void operator()(void* ptr) const { + WebRtc_FreeBuffer(ptr); + } +}; +typedef scoped_ptr scoped_ring_buffer; static void AssertElementEq(int expected, int actual) { ASSERT_EQ(expected, actual); diff --git a/webrtc/system_wrappers/interface/aligned_malloc.h b/webrtc/system_wrappers/interface/aligned_malloc.h index 6409999e8f..5d343cde7c 100644 --- a/webrtc/system_wrappers/interface/aligned_malloc.h +++ b/webrtc/system_wrappers/interface/aligned_malloc.h @@ -19,8 +19,6 @@ #include -#include "webrtc/system_wrappers/interface/scoped_ptr.h" - namespace webrtc { // Returns a pointer to the first boundry of |alignment| bytes following the @@ -48,10 +46,12 @@ T* AlignedMalloc(size_t size, size_t alignment) { return reinterpret_cast(AlignedMalloc(size, alignment)); } -// Scoped pointer to AlignedMalloc-memory. -template -struct Allocator { - typedef scoped_ptr_malloc scoped_ptr_aligned; +// Deleter for use with scoped_ptr. E.g., use as +// scoped_ptr foo; +struct AlignedFreeDeleter { + inline void operator()(void* ptr) const { + AlignedFree(ptr); + } }; } // namespace webrtc diff --git a/webrtc/system_wrappers/interface/scoped_ptr.h b/webrtc/system_wrappers/interface/scoped_ptr.h index aeac77ac95..fb203638f9 100644 --- a/webrtc/system_wrappers/interface/scoped_ptr.h +++ b/webrtc/system_wrappers/interface/scoped_ptr.h @@ -96,7 +96,7 @@ #define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_SCOPED_PTR_H_ // This is an implementation designed to match the anticipated future TR2 -// implementation of the scoped_ptr class and scoped_ptr_malloc (deprecated). +// implementation of the scoped_ptr class. #include #include @@ -639,77 +639,6 @@ void swap(scoped_array& a, scoped_array& b) { a.swap(b); } -// DEPRECATED: Use scoped_ptr instead. -// TODO(ajm): Remove scoped_ptr_malloc. -// -// scoped_ptr_malloc<> is similar to scoped_ptr<>, but it accepts a -// second template argument, the function used to free the object. - -template class scoped_ptr_malloc { - private: - - T* ptr; - - scoped_ptr_malloc(scoped_ptr_malloc const &); - scoped_ptr_malloc & operator=(scoped_ptr_malloc const &); - - public: - - typedef T element_type; - - explicit scoped_ptr_malloc(T* p = 0): ptr(p) {} - - ~scoped_ptr_malloc() { - FF(static_cast(ptr)); - } - - void reset(T* p = 0) { - if (ptr != p) { - FF(static_cast(ptr)); - ptr = p; - } - } - - T& operator*() const { - assert(ptr != 0); - return *ptr; - } - - T* operator->() const { - assert(ptr != 0); - return ptr; - } - - T* get() const { - return ptr; - } - - void swap(scoped_ptr_malloc & b) { - T* tmp = b.ptr; - b.ptr = ptr; - ptr = tmp; - } - - T* release() { - T* tmp = ptr; - ptr = 0; - return tmp; - } - - T** accept() { - if (ptr) { - FF(static_cast(ptr)); - ptr = 0; - } - return &ptr; - } -}; - -template inline -void swap(scoped_ptr_malloc& a, scoped_ptr_malloc& b) { - a.swap(b); -} - } // namespace webrtc #endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_SCOPED_PTR_H_ diff --git a/webrtc/system_wrappers/source/aligned_malloc_unittest.cc b/webrtc/system_wrappers/source/aligned_malloc_unittest.cc index 10e08aae7b..0acbf97590 100644 --- a/webrtc/system_wrappers/source/aligned_malloc_unittest.cc +++ b/webrtc/system_wrappers/source/aligned_malloc_unittest.cc @@ -16,14 +16,16 @@ #include #endif +#include "testing/gtest/include/gtest/gtest.h" +#include "webrtc/system_wrappers/interface/scoped_ptr.h" #include "webrtc/typedefs.h" -#include "testing/gtest/include/gtest/gtest.h" +namespace webrtc { // Returns true if |size| and |alignment| are valid combinations. bool CorrectUsage(size_t size, size_t alignment) { - webrtc::Allocator::scoped_ptr_aligned scoped( - webrtc::AlignedMalloc(size, alignment)); + scoped_ptr scoped( + static_cast(AlignedMalloc(size, alignment))); if (scoped.get() == NULL) { return false; } @@ -34,16 +36,15 @@ bool CorrectUsage(size_t size, size_t alignment) { TEST(AlignedMalloc, GetRightAlign) { const size_t size = 100; const size_t alignment = 32; - const size_t left_missalignment = 8; - webrtc::Allocator::scoped_ptr_aligned scoped( - webrtc::AlignedMalloc(size, alignment)); + const size_t left_misalignment = 1; + scoped_ptr scoped( + static_cast(AlignedMalloc(size, alignment))); EXPECT_TRUE(scoped.get() != NULL); const uintptr_t aligned_address = reinterpret_cast (scoped.get()); - const uintptr_t missaligned_address = aligned_address - left_missalignment; - const char* missaligned_ptr = reinterpret_cast( - missaligned_address); - const char* realigned_ptr = webrtc::GetRightAlign( - missaligned_ptr, alignment); + const uintptr_t misaligned_address = aligned_address - left_misalignment; + const char* misaligned_ptr = reinterpret_cast( + misaligned_address); + const char* realigned_ptr = GetRightAlign(misaligned_ptr, alignment); EXPECT_EQ(scoped.get(), realigned_ptr); } @@ -76,3 +77,6 @@ TEST(AlignedMalloc, AlignTo128Bytes) { size_t alignment = 128; EXPECT_TRUE(CorrectUsage(size, alignment)); } + +} // namespace webrtc +