Use char as ring-buffer data type.
- Avoids a bunch of char* casts. - Use enum type rather than char. TEST=audioproc_unittest on Linux (float and fixed), build on Windows Review URL: http://webrtc-codereview.appspot.com/336010 git-svn-id: http://webrtc.googlecode.com/svn/trunk@1303 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
e2642494e4
commit
6d6a43d6e3
@ -28,17 +28,20 @@ typedef struct {
|
|||||||
bufdata_t *data;
|
bufdata_t *data;
|
||||||
} tmp_buf_t;
|
} tmp_buf_t;
|
||||||
|
|
||||||
|
enum Wrap {
|
||||||
|
SAME_WRAP,
|
||||||
|
DIFF_WRAP
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
size_t read_pos;
|
size_t read_pos;
|
||||||
size_t write_pos;
|
size_t write_pos;
|
||||||
size_t element_count;
|
size_t element_count;
|
||||||
size_t element_size;
|
size_t element_size;
|
||||||
char rw_wrap;
|
enum Wrap rw_wrap;
|
||||||
void* data;
|
char* data;
|
||||||
} buf_t;
|
} buf_t;
|
||||||
|
|
||||||
enum { SAME_WRAP, DIFF_WRAP };
|
|
||||||
|
|
||||||
// Get address of region(s) from which we can read data.
|
// Get address of region(s) from which we can read data.
|
||||||
// If the region is contiguous, |data_ptr_bytes_2| will be zero.
|
// If the region is contiguous, |data_ptr_bytes_2| will be zero.
|
||||||
// If non-contiguous, |data_ptr_bytes_2| will be the size in bytes of the second
|
// If non-contiguous, |data_ptr_bytes_2| will be the size in bytes of the second
|
||||||
@ -59,12 +62,12 @@ static size_t GetBufferReadRegions(buf_t* buf,
|
|||||||
// Check to see if read is not contiguous.
|
// Check to see if read is not contiguous.
|
||||||
if (read_elements > margin) {
|
if (read_elements > margin) {
|
||||||
// Write data in two blocks that wrap the buffer.
|
// Write data in two blocks that wrap the buffer.
|
||||||
*data_ptr_1 = ((char*) buf->data) + (buf->read_pos * buf->element_size);
|
*data_ptr_1 = buf->data + buf->read_pos * buf->element_size;
|
||||||
*data_ptr_bytes_1 = margin * buf->element_size;
|
*data_ptr_bytes_1 = margin * buf->element_size;
|
||||||
*data_ptr_2 = buf->data;
|
*data_ptr_2 = buf->data;
|
||||||
*data_ptr_bytes_2 = (read_elements - margin) * buf->element_size;
|
*data_ptr_bytes_2 = (read_elements - margin) * buf->element_size;
|
||||||
} else {
|
} else {
|
||||||
*data_ptr_1 = ((char*) buf->data) + (buf->read_pos * buf->element_size);
|
*data_ptr_1 = buf->data + buf->read_pos * buf->element_size;
|
||||||
*data_ptr_bytes_1 = read_elements * buf->element_size;
|
*data_ptr_bytes_1 = read_elements * buf->element_size;
|
||||||
*data_ptr_2 = NULL;
|
*data_ptr_2 = NULL;
|
||||||
*data_ptr_bytes_2 = 0;
|
*data_ptr_bytes_2 = 0;
|
||||||
@ -396,13 +399,13 @@ size_t WebRtc_WriteBuffer(void* handle,
|
|||||||
|
|
||||||
if (write_elements > margin) {
|
if (write_elements > margin) {
|
||||||
// Buffer wrap around when writing.
|
// Buffer wrap around when writing.
|
||||||
memcpy(((char*) self->data) + (self->write_pos * self->element_size),
|
memcpy(self->data + self->write_pos * self->element_size,
|
||||||
data, margin * self->element_size);
|
data, margin * self->element_size);
|
||||||
self->write_pos = 0;
|
self->write_pos = 0;
|
||||||
n -= margin;
|
n -= margin;
|
||||||
self->rw_wrap = DIFF_WRAP;
|
self->rw_wrap = DIFF_WRAP;
|
||||||
}
|
}
|
||||||
memcpy(((char*) self->data) + (self->write_pos * self->element_size),
|
memcpy(self->data + self->write_pos * self->element_size,
|
||||||
((const char*) data) + ((write_elements - n) * self->element_size),
|
((const char*) data) + ((write_elements - n) * self->element_size),
|
||||||
n * self->element_size);
|
n * self->element_size);
|
||||||
self->write_pos += n;
|
self->write_pos += n;
|
||||||
|
Loading…
Reference in New Issue
Block a user