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

Unified Diff: media/base/audio_pull_fifo.cc

Issue 10915123: Adds media::AudioPullFifo class to Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added TODOs from Dale Created 8 years, 3 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 | « media/base/audio_pull_fifo.h ('k') | media/base/audio_pull_fifo_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/audio_pull_fifo.cc
diff --git a/media/base/audio_pull_fifo.cc b/media/base/audio_pull_fifo.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b37a94ab96a4f3216414524178862cfcf286b5a3
--- /dev/null
+++ b/media/base/audio_pull_fifo.cc
@@ -0,0 +1,42 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <algorithm>
+
+#include "media/base/audio_pull_fifo.h"
+
+#include "base/logging.h"
+
+namespace media {
+
+AudioPullFifo::AudioPullFifo(int channels, int frames, const ReadCB& read_cb)
+ : read_cb_(read_cb) {
+ fifo_.reset(new AudioFifo(channels, frames));
+ bus_ = AudioBus::Create(channels, frames);
+}
+
+AudioPullFifo::~AudioPullFifo() {
+ read_cb_.Reset();
+}
+
+void AudioPullFifo::Consume(AudioBus* destination, int frames_to_consume) {
+ DCHECK(destination);
DaleCurtis 2012/09/07 16:24:01 Add a DCHECK_LE(frames_to_consume, destination->fr
henrika (OOO until Aug 14) 2012/09/10 07:23:04 Done.
+
+ int frames_to_write = frames_to_consume;
+ int frames_left = std::min(fifo_->frames(), frames_to_consume);
+ fifo_->Consume(destination, 0, frames_left);
+ frames_to_write -= frames_left;
+ int write_pos = frames_left;
+
+ while (frames_to_write > 0) {
+ read_cb_.Run(bus_.get());
DaleCurtis 2012/09/07 16:24:01 This is the part we can optimize later, as right n
+ fifo_->Push(bus_.get());
+ int to_consume = std::min(bus_->frames(), frames_to_write);
+ fifo_->Consume(destination, write_pos, to_consume);
+ write_pos += to_consume;
+ frames_to_write -= to_consume;
+ }
+}
+
+} // namespace media
« no previous file with comments | « media/base/audio_pull_fifo.h ('k') | media/base/audio_pull_fifo_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698