Index: webrtc/common_audio/audio_ring_buffer.cc |
diff --git a/webrtc/common_audio/audio_ring_buffer.cc b/webrtc/common_audio/audio_ring_buffer.cc |
index 0ec53a34b85730106860a947f73454e81ae62f2b..32f5c69fc7a531407ce495ea1b3083b77f70ec5b 100644 |
--- a/webrtc/common_audio/audio_ring_buffer.cc |
+++ b/webrtc/common_audio/audio_ring_buffer.cc |
@@ -11,6 +11,7 @@ |
#include "webrtc/common_audio/audio_ring_buffer.h" |
#include "webrtc/base/checks.h" |
+#include "webrtc/base/safe_conversions.h" |
#include "webrtc/common_audio/ring_buffer.h" |
// This is a simple multi-channel wrapper over the ring_buffer.h C interface. |
@@ -18,6 +19,7 @@ |
namespace webrtc { |
AudioRingBuffer::AudioRingBuffer(size_t channels, size_t max_frames) { |
+ buffers_.reserve(channels); |
for (size_t i = 0; i < channels; ++i) |
buffers_.push_back(WebRtc_CreateBuffer(max_frames, sizeof(float))); |
} |
@@ -31,7 +33,7 @@ void AudioRingBuffer::Write(const float* const* data, size_t channels, |
size_t frames) { |
DCHECK_EQ(buffers_.size(), channels); |
for (size_t i = 0; i < channels; ++i) { |
- size_t written = WebRtc_WriteBuffer(buffers_[i], data[i], frames); |
+ const size_t written = WebRtc_WriteBuffer(buffers_[i], data[i], frames); |
CHECK_EQ(written, frames); |
} |
} |
@@ -39,7 +41,8 @@ void AudioRingBuffer::Write(const float* const* data, size_t channels, |
void AudioRingBuffer::Read(float* const* data, size_t channels, size_t frames) { |
DCHECK_EQ(buffers_.size(), channels); |
for (size_t i = 0; i < channels; ++i) { |
- size_t read = WebRtc_ReadBuffer(buffers_[i], nullptr, data[i], frames); |
+ const size_t read = |
+ WebRtc_ReadBuffer(buffers_[i], nullptr, data[i], frames); |
CHECK_EQ(read, frames); |
} |
} |
@@ -54,9 +57,17 @@ size_t AudioRingBuffer::WriteFramesAvailable() const { |
return WebRtc_available_write(buffers_[0]); |
} |
-void AudioRingBuffer::MoveReadPosition(int frames) { |
+void AudioRingBuffer::MoveReadPositionForward(size_t frames) { |
for (auto buf : buffers_) { |
- int moved = WebRtc_MoveReadPtr(buf, frames); |
+ const size_t moved = WebRtc_MoveReadPtr(buf, frames); |
+ CHECK_EQ(moved, frames); |
+ } |
+} |
+ |
+void AudioRingBuffer::MoveReadPositionBackward(size_t frames) { |
+ for (auto buf : buffers_) { |
+ const size_t moved = rtc::checked_cast<size_t>( |
Andrew MacDonald
2015/07/24 19:06:39
We already check this value below, so a checked ca
|
+ -WebRtc_MoveReadPtr(buf, -static_cast<int>(frames))); |
CHECK_EQ(moved, frames); |
} |
} |