Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(412)

Unified Diff: webrtc/common_audio/audio_ring_buffer.cc

Issue 1252943007: Split MoveReadPosition into Forward and Backward versions. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/common_audio/audio_ring_buffer.h ('k') | webrtc/common_audio/audio_ring_buffer_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
}
}
« no previous file with comments | « webrtc/common_audio/audio_ring_buffer.h ('k') | webrtc/common_audio/audio_ring_buffer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698