diff --git a/webrtc/common_audio/ring_buffer.c b/webrtc/common_audio/ring_buffer.c index 5fc653bd57..5a91205118 100644 --- a/webrtc/common_audio/ring_buffer.c +++ b/webrtc/common_audio/ring_buffer.c @@ -118,7 +118,6 @@ size_t WebRtc_ReadBuffer(RingBuffer* self, &buf_ptr_bytes_1, &buf_ptr_2, &buf_ptr_bytes_2); - if (buf_ptr_bytes_2 > 0) { // We have a wrap around when reading the buffer. Copy the buffer data to // |data| and point to it. @@ -131,7 +130,7 @@ size_t WebRtc_ReadBuffer(RingBuffer* self, } if (data_ptr) { // |buf_ptr_1| == |data| in the case of a wrap. - *data_ptr = buf_ptr_1; + *data_ptr = read_count == 0 ? NULL : buf_ptr_1; } // Update read position diff --git a/webrtc/common_audio/ring_buffer.h b/webrtc/common_audio/ring_buffer.h index baa1df4fe0..46759b6697 100644 --- a/webrtc/common_audio/ring_buffer.h +++ b/webrtc/common_audio/ring_buffer.h @@ -36,12 +36,13 @@ RingBuffer* WebRtc_CreateBuffer(size_t element_count, size_t element_size); void WebRtc_InitBuffer(RingBuffer* handle); void WebRtc_FreeBuffer(void* handle); -// Reads data from the buffer. The |data_ptr| will point to the address where -// it is located. If all |element_count| data are feasible to read without -// buffer wrap around |data_ptr| will point to the location in the buffer. -// Otherwise, the data will be copied to |data| (memory allocation done by the -// user) and |data_ptr| points to the address of |data|. |data_ptr| is only -// guaranteed to be valid until the next call to WebRtc_WriteBuffer(). +// Reads data from the buffer. Returns the number of elements that were read. +// The |data_ptr| will point to the address where the read data is located. +// If no data can be read, |data_ptr| is set to |NULL|. If all data can be read +// without buffer wrap around then |data_ptr| will point to the location in the +// buffer. Otherwise, the data will be copied to |data| (memory allocation done +// by the user) and |data_ptr| points to the address of |data|. |data_ptr| is +// only guaranteed to be valid until the next call to WebRtc_WriteBuffer(). // // To force a copying to |data|, pass a null |data_ptr|. // diff --git a/webrtc/modules/audio_processing/aec/aec_core.cc b/webrtc/modules/audio_processing/aec/aec_core.cc index 3155bad972..f64617e5db 100644 --- a/webrtc/modules/audio_processing/aec/aec_core.cc +++ b/webrtc/modules/audio_processing/aec/aec_core.cc @@ -206,15 +206,18 @@ void BlockBuffer::ExtractExtendedBlock(float extended_block[PART_LEN2]) { // Extract the previous block. WebRtc_MoveReadPtr(buffer_, -1); - WebRtc_ReadBuffer(buffer_, reinterpret_cast(&block_ptr), - &extended_block[0], 1); + size_t read_elements = WebRtc_ReadBuffer( + buffer_, reinterpret_cast(&block_ptr), &extended_block[0], 1); + RTC_CHECK_EQ(read_elements, 1); if (block_ptr != &extended_block[0]) { memcpy(&extended_block[0], block_ptr, PART_LEN * sizeof(float)); } // Extract the current block. - WebRtc_ReadBuffer(buffer_, reinterpret_cast(&block_ptr), - &extended_block[PART_LEN], 1); + read_elements = + WebRtc_ReadBuffer(buffer_, reinterpret_cast(&block_ptr), + &extended_block[PART_LEN], 1); + RTC_CHECK_EQ(read_elements, 1); if (block_ptr != &extended_block[PART_LEN]) { memcpy(&extended_block[PART_LEN], block_ptr, PART_LEN * sizeof(float)); }