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

Unified Diff: media/base/audio_pull_fifo.h

Issue 10915123: Adds media::AudioPullFifo class to Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: AudioFIFO changes based on comments from Andrew 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.h
diff --git a/media/base/audio_pull_fifo.h b/media/base/audio_pull_fifo.h
new file mode 100644
index 0000000000000000000000000000000000000000..b1d6d215a50201ae9ad5498e584018afadd783c7
--- /dev/null
+++ b/media/base/audio_pull_fifo.h
@@ -0,0 +1,58 @@
+// 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.
+
+#ifndef MEDIA_BASE_AUDIO_PULL_FIFO_H_
+#define MEDIA_BASE_AUDIO_PULL_FIFO_H_
+
+#include "base/callback.h"
+#include "media/base/audio_fifo.h"
+#include "media/base/media_export.h"
+
+namespace media {
+
+// A FIFO (First In First Out) buffer to handle mismatches in buffer sizes
+// between a provider and consumer. The consumer will pull data from this FIFO.
scherkus (not reviewing) 2012/09/07 14:19:03 s/provider/producer/
henrika (OOO until Aug 14) 2012/09/10 07:23:04 OK. Can be discussed I guess but it sounds better.
+// If data is already available in the FIFO, it is provided to the consumer.
+// If insufficient data is available to satisfy the request, the FIFO will ask
+// the provider for more data to fulfill a request.
+class MEDIA_EXPORT AudioPullFifo {
+ public:
+ // Callback type for providing more data into the FIFO. Expects AudioBus
+ // to be completely filled with data upon return; zero padded if not enough
+ // frames are available to satisfy the request.
+ typedef base::Callback<void(AudioBus* audio_bus)> ReadCB;
+
+ // Constructs an AudioPullFifo with the specified |read_cb|, which is used to
+ // read audio data of size |read_frames| to the FIFO if data is not already
+ // available. The internal FIFO can contain |channel| number of channels,
+ // where each channel is of length |frames| audio frames.
+ AudioPullFifo(int channels, int frames,
+ const ReadCB& read_cb, int read_frames);
+ virtual ~AudioPullFifo();
+
+ // Consumes |frames_to_consume| audio frames from the FIFO and copies
+ // them to |destination|.
+ // If the FIFO does not have enough data, we ask the provider to give us more
+ // data to fulfill the request using the ReadCB implementation.
+ void Consume(AudioBus* destination, int frames_to_consume);
+
+ private:
+ // Fill the FIFO buffer with at least |frames| number of audio frames.
+ void FillBuffer(int frames);
+
+ // Source of data to the FIFO.
+ ReadCB read_cb_;
+
+ // The actual FIFO.
+ scoped_ptr<AudioFifo> audio_fifo_;
+
+ // Temporary audio bus to hold the data from the provider.
+ scoped_ptr<AudioBus> audio_bus_;
+
+ DISALLOW_COPY_AND_ASSIGN(AudioPullFifo);
+};
+
+} // namespace media
+
+#endif // MEDIA_BASE_AUDIO_PULL_FIFO_H_

Powered by Google App Engine
This is Rietveld 408576698