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

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: Now builds on all platforms 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
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..00646ebdace6336c6dd6cfa05f90046a04b6cde8
--- /dev/null
+++ b/media/base/audio_pull_fifo.cc
@@ -0,0 +1,53 @@
+// 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"
DaleCurtis 2012/09/10 08:28:26 Needs to be first include, move above <algorithm>
henrika (OOO until Aug 14) 2012/09/10 09:35:31 Done.
+
+#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);
+ DCHECK_LE(frames_to_consume, destination->frames());
+
+ int write_pos = 0;
+ int remaining_frames_to_provide = frames_to_consume;
+
+ // Try to fulfill the request using what's available in the FIFO.
+ ReadFromFifo(destination, &remaining_frames_to_provide, &write_pos);
+
+ // Get the remaining audio frames from the producer using the callback.
+ while (remaining_frames_to_provide > 0) {
+ // Fill up the FIFO by acquiring audio data from the producer.
+ read_cb_.Run(bus_.get());
+ fifo_->Push(bus_.get());
+
+ // Try to fulfill the request using what's available in the FIFO.
+ ReadFromFifo(destination, &remaining_frames_to_provide, &write_pos);
+ }
+}
+
+void AudioPullFifo::ReadFromFifo(AudioBus* destination,
+ int* frames_to_provide,
+ int* write_pos) {
+ int frames = std::min(fifo_->frames(), *frames_to_provide);
DaleCurtis 2012/09/10 08:28:26 DCHECK() frames_to_provide and write_pos.
henrika (OOO until Aug 14) 2012/09/10 09:35:31 Done.
+ fifo_->Consume(destination, *write_pos, frames);
+ *write_pos += frames;
+ *frames_to_provide -= frames;
+}
+
+} // namespace media

Powered by Google App Engine
This is Rietveld 408576698