From 677e5774eaf287fa02f75fd5c8ad3f9ded9ed9c4 Mon Sep 17 00:00:00 2001 From: peah Date: Mon, 4 Apr 2016 23:58:03 -0700 Subject: [PATCH] Moved the ringbuffer to be built using C++ BUG=webrtc:5724 Review URL: https://codereview.webrtc.org/1851873003 Cr-Commit-Position: refs/heads/master@{#12230} --- webrtc/modules/audio_processing/BUILD.gn | 2 +- .../modules/audio_processing/aec/aec_core.cc | 2 +- .../audio_processing/aec/aec_core_internal.h | 2 -- .../aec/echo_cancellation_internal.h | 2 -- .../audio_processing/audio_processing.gypi | 2 +- .../utility/{ring_buffer.c => ring_buffer.cc} | 27 +++++++++---------- 6 files changed, 16 insertions(+), 21 deletions(-) rename webrtc/modules/audio_processing/utility/{ring_buffer.c => ring_buffer.cc} (89%) diff --git a/webrtc/modules/audio_processing/BUILD.gn b/webrtc/modules/audio_processing/BUILD.gn index bf7bdc5d1c..7960368343 100644 --- a/webrtc/modules/audio_processing/BUILD.gn +++ b/webrtc/modules/audio_processing/BUILD.gn @@ -121,7 +121,7 @@ source_set("audio_processing") { "utility/delay_estimator_wrapper.h", "utility/lapped_transform.cc", "utility/lapped_transform.h", - "utility/ring_buffer.c", + "utility/ring_buffer.cc", "utility/ring_buffer.h", "vad/common.h", "vad/gmm.cc", diff --git a/webrtc/modules/audio_processing/aec/aec_core.cc b/webrtc/modules/audio_processing/aec/aec_core.cc index 4fe635d2db..5af6e5d5dc 100644 --- a/webrtc/modules/audio_processing/aec/aec_core.cc +++ b/webrtc/modules/audio_processing/aec/aec_core.cc @@ -33,8 +33,8 @@ extern "C" { #include "webrtc/modules/audio_processing/logging/aec_logging.h" extern "C" { #include "webrtc/modules/audio_processing/utility/delay_estimator_wrapper.h" -#include "webrtc/modules/audio_processing/utility/ring_buffer.h" } +#include "webrtc/modules/audio_processing/utility/ring_buffer.h" #include "webrtc/system_wrappers/include/cpu_features_wrapper.h" #include "webrtc/typedefs.h" diff --git a/webrtc/modules/audio_processing/aec/aec_core_internal.h b/webrtc/modules/audio_processing/aec/aec_core_internal.h index 1f4f99be63..79af29d28d 100644 --- a/webrtc/modules/audio_processing/aec/aec_core_internal.h +++ b/webrtc/modules/audio_processing/aec/aec_core_internal.h @@ -15,9 +15,7 @@ #include "webrtc/modules/audio_processing/aec/aec_common.h" #include "webrtc/modules/audio_processing/aec/aec_core.h" #include "webrtc/modules/audio_processing/utility/block_mean_calculator.h" -extern "C" { #include "webrtc/modules/audio_processing/utility/ring_buffer.h" -} #include "webrtc/typedefs.h" diff --git a/webrtc/modules/audio_processing/aec/echo_cancellation_internal.h b/webrtc/modules/audio_processing/aec/echo_cancellation_internal.h index 537ab5d904..9779d6fcd3 100644 --- a/webrtc/modules/audio_processing/aec/echo_cancellation_internal.h +++ b/webrtc/modules/audio_processing/aec/echo_cancellation_internal.h @@ -12,9 +12,7 @@ #define WEBRTC_MODULES_AUDIO_PROCESSING_AEC_ECHO_CANCELLATION_INTERNAL_H_ #include "webrtc/modules/audio_processing/aec/aec_core.h" -extern "C" { #include "webrtc/modules/audio_processing/utility/ring_buffer.h" -} namespace webrtc { diff --git a/webrtc/modules/audio_processing/audio_processing.gypi b/webrtc/modules/audio_processing/audio_processing.gypi index 75da59f3e0..1fa4a8569b 100644 --- a/webrtc/modules/audio_processing/audio_processing.gypi +++ b/webrtc/modules/audio_processing/audio_processing.gypi @@ -131,7 +131,7 @@ 'utility/delay_estimator_wrapper.h', 'utility/lapped_transform.cc', 'utility/lapped_transform.h', - 'utility/ring_buffer.c', + 'utility/ring_buffer.cc', 'utility/ring_buffer.h', 'vad/common.h', 'vad/gmm.cc', diff --git a/webrtc/modules/audio_processing/utility/ring_buffer.c b/webrtc/modules/audio_processing/utility/ring_buffer.cc similarity index 89% rename from webrtc/modules/audio_processing/utility/ring_buffer.c rename to webrtc/modules/audio_processing/utility/ring_buffer.cc index c71bac1862..e5c86cdb3b 100644 --- a/webrtc/modules/audio_processing/utility/ring_buffer.c +++ b/webrtc/modules/audio_processing/utility/ring_buffer.cc @@ -42,7 +42,6 @@ static size_t GetBufferReadRegions(RingBuffer* buf, size_t* data_ptr_bytes_1, void** data_ptr_2, size_t* data_ptr_bytes_2) { - const size_t readable_elements = WebRtc_available_read(buf); const size_t read_elements = (readable_elements < element_count ? readable_elements : element_count); @@ -71,12 +70,12 @@ RingBuffer* WebRtc_CreateBuffer(size_t element_count, size_t element_size) { return NULL; } - self = malloc(sizeof(RingBuffer)); + self = static_cast(malloc(sizeof(RingBuffer))); if (!self) { return NULL; } - self->data = malloc(element_count * element_size); + self->data = static_cast(malloc(element_count * element_size)); if (!self->data) { free(self); self = NULL; @@ -100,7 +99,7 @@ void WebRtc_InitBuffer(RingBuffer* self) { } void WebRtc_FreeBuffer(void* handle) { - RingBuffer* self = (RingBuffer*)handle; + RingBuffer* self = static_cast(handle); if (!self) { return; } @@ -113,7 +112,6 @@ size_t WebRtc_ReadBuffer(RingBuffer* self, void** data_ptr, void* data, size_t element_count) { - if (self == NULL) { return 0; } @@ -137,7 +135,8 @@ size_t WebRtc_ReadBuffer(RingBuffer* self, // We have a wrap around when reading the buffer. Copy the buffer data to // |data| and point to it. memcpy(data, buf_ptr_1, buf_ptr_bytes_1); - memcpy(((char*) data) + buf_ptr_bytes_1, buf_ptr_2, buf_ptr_bytes_2); + memcpy(static_cast(data) + buf_ptr_bytes_1, buf_ptr_2, + buf_ptr_bytes_2); buf_ptr_1 = data; } else if (!data_ptr) { // No wrap, but a memcpy was requested. @@ -149,7 +148,7 @@ size_t WebRtc_ReadBuffer(RingBuffer* self, } // Update read position - WebRtc_MoveReadPtr(self, (int) read_count); + WebRtc_MoveReadPtr(self, static_cast(read_count)); return read_count; } @@ -197,9 +196,9 @@ int WebRtc_MoveReadPtr(RingBuffer* self, int element_count) { { // We need to be able to take care of negative changes, hence use "int" // instead of "size_t". - const int free_elements = (int) WebRtc_available_write(self); - const int readable_elements = (int) WebRtc_available_read(self); - int read_pos = (int) self->read_pos; + const int free_elements = static_cast(WebRtc_available_write(self)); + const int readable_elements = static_cast(WebRtc_available_read(self)); + int read_pos = static_cast(self->read_pos); if (element_count > readable_elements) { element_count = readable_elements; @@ -209,18 +208,18 @@ int WebRtc_MoveReadPtr(RingBuffer* self, int element_count) { } read_pos += element_count; - if (read_pos > (int) self->element_count) { + if (read_pos > static_cast(self->element_count)) { // Buffer wrap around. Restart read position and wrap indicator. - read_pos -= (int) self->element_count; + read_pos -= static_cast(self->element_count); self->rw_wrap = SAME_WRAP; } if (read_pos < 0) { // Buffer wrap around. Restart read position and wrap indicator. - read_pos += (int) self->element_count; + read_pos += static_cast(self->element_count); self->rw_wrap = DIFF_WRAP; } - self->read_pos = (size_t) read_pos; + self->read_pos = static_cast(read_pos); return element_count; }