From 6c393244b0dbd9d690bb03f90cd232b7b1994368 Mon Sep 17 00:00:00 2001 From: peah Date: Tue, 5 Apr 2016 00:00:44 -0700 Subject: [PATCH] Revert of Moved the ringbuffer to be built using C++ (patchset #2 id:20001 of https://codereview.webrtc.org/1851873003/ ) Reason for revert: This CL is dependent on the CL https://codereview.webrtc.org/1846903004/ which caused a google3 breakage due to dependencies in Google3. I will fix that, and reland this CL. Original issue's description: > Moved the ringbuffer to be built using C++ > > BUG=webrtc:5724 > > Committed: https://crrev.com/677e5774eaf287fa02f75fd5c8ad3f9ded9ed9c4 > Cr-Commit-Position: refs/heads/master@{#12230} TBR=ivoc@webrtc.org,henrik.lundin@webrtc.org,kwiberg@webrtc.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=webrtc:5724 Review URL: https://codereview.webrtc.org/1858873003 Cr-Commit-Position: refs/heads/master@{#12231} --- 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.cc => ring_buffer.c} | 27 ++++++++++--------- 6 files changed, 21 insertions(+), 16 deletions(-) rename webrtc/modules/audio_processing/utility/{ring_buffer.cc => ring_buffer.c} (89%) diff --git a/webrtc/modules/audio_processing/BUILD.gn b/webrtc/modules/audio_processing/BUILD.gn index 7960368343..bf7bdc5d1c 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.cc", + "utility/ring_buffer.c", "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 5af6e5d5dc..4fe635d2db 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/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 79af29d28d..1f4f99be63 100644 --- a/webrtc/modules/audio_processing/aec/aec_core_internal.h +++ b/webrtc/modules/audio_processing/aec/aec_core_internal.h @@ -15,7 +15,9 @@ #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 9779d6fcd3..537ab5d904 100644 --- a/webrtc/modules/audio_processing/aec/echo_cancellation_internal.h +++ b/webrtc/modules/audio_processing/aec/echo_cancellation_internal.h @@ -12,7 +12,9 @@ #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 1fa4a8569b..75da59f3e0 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.cc', + 'utility/ring_buffer.c', 'utility/ring_buffer.h', 'vad/common.h', 'vad/gmm.cc', diff --git a/webrtc/modules/audio_processing/utility/ring_buffer.cc b/webrtc/modules/audio_processing/utility/ring_buffer.c similarity index 89% rename from webrtc/modules/audio_processing/utility/ring_buffer.cc rename to webrtc/modules/audio_processing/utility/ring_buffer.c index e5c86cdb3b..c71bac1862 100644 --- a/webrtc/modules/audio_processing/utility/ring_buffer.cc +++ b/webrtc/modules/audio_processing/utility/ring_buffer.c @@ -42,6 +42,7 @@ 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); @@ -70,12 +71,12 @@ RingBuffer* WebRtc_CreateBuffer(size_t element_count, size_t element_size) { return NULL; } - self = static_cast(malloc(sizeof(RingBuffer))); + self = malloc(sizeof(RingBuffer)); if (!self) { return NULL; } - self->data = static_cast(malloc(element_count * element_size)); + self->data = malloc(element_count * element_size); if (!self->data) { free(self); self = NULL; @@ -99,7 +100,7 @@ void WebRtc_InitBuffer(RingBuffer* self) { } void WebRtc_FreeBuffer(void* handle) { - RingBuffer* self = static_cast(handle); + RingBuffer* self = (RingBuffer*)handle; if (!self) { return; } @@ -112,6 +113,7 @@ size_t WebRtc_ReadBuffer(RingBuffer* self, void** data_ptr, void* data, size_t element_count) { + if (self == NULL) { return 0; } @@ -135,8 +137,7 @@ 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(static_cast(data) + buf_ptr_bytes_1, buf_ptr_2, - buf_ptr_bytes_2); + memcpy(((char*) 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. @@ -148,7 +149,7 @@ size_t WebRtc_ReadBuffer(RingBuffer* self, } // Update read position - WebRtc_MoveReadPtr(self, static_cast(read_count)); + WebRtc_MoveReadPtr(self, (int) read_count); return read_count; } @@ -196,9 +197,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 = static_cast(WebRtc_available_write(self)); - const int readable_elements = static_cast(WebRtc_available_read(self)); - int read_pos = static_cast(self->read_pos); + 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; if (element_count > readable_elements) { element_count = readable_elements; @@ -208,18 +209,18 @@ int WebRtc_MoveReadPtr(RingBuffer* self, int element_count) { } read_pos += element_count; - if (read_pos > static_cast(self->element_count)) { + if (read_pos > (int) self->element_count) { // Buffer wrap around. Restart read position and wrap indicator. - read_pos -= static_cast(self->element_count); + read_pos -= (int) self->element_count; self->rw_wrap = SAME_WRAP; } if (read_pos < 0) { // Buffer wrap around. Restart read position and wrap indicator. - read_pos += static_cast(self->element_count); + read_pos += (int) self->element_count; self->rw_wrap = DIFF_WRAP; } - self->read_pos = static_cast(read_pos); + self->read_pos = (size_t) read_pos; return element_count; }