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}
This commit is contained in:
@ -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",
|
||||
|
||||
@ -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"
|
||||
|
||||
|
||||
@ -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"
|
||||
|
||||
|
||||
@ -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 {
|
||||
|
||||
|
||||
@ -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',
|
||||
|
||||
@ -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<RingBuffer*>(malloc(sizeof(RingBuffer)));
|
||||
if (!self) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
self->data = malloc(element_count * element_size);
|
||||
self->data = static_cast<char*>(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<RingBuffer*>(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<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.
|
||||
@ -149,7 +148,7 @@ size_t WebRtc_ReadBuffer(RingBuffer* self,
|
||||
}
|
||||
|
||||
// Update read position
|
||||
WebRtc_MoveReadPtr(self, (int) read_count);
|
||||
WebRtc_MoveReadPtr(self, static_cast<int>(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<int>(WebRtc_available_write(self));
|
||||
const int readable_elements = static_cast<int>(WebRtc_available_read(self));
|
||||
int read_pos = static_cast<int>(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<int>(self->element_count)) {
|
||||
// Buffer wrap around. Restart read position and wrap indicator.
|
||||
read_pos -= (int) self->element_count;
|
||||
read_pos -= static_cast<int>(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<int>(self->element_count);
|
||||
self->rw_wrap = DIFF_WRAP;
|
||||
}
|
||||
|
||||
self->read_pos = (size_t) read_pos;
|
||||
self->read_pos = static_cast<size_t>(read_pos);
|
||||
|
||||
return element_count;
|
||||
}
|
||||
Reference in New Issue
Block a user