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

Unified Diff: media/base/audio_fifo.h

Issue 10912079: Adds AudioFifo class to Chrome media. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added frames_to_consum to Consume() 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 | « no previous file | media/base/audio_fifo.cc » ('j') | media/base/audio_fifo.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/audio_fifo.h
diff --git a/media/base/audio_fifo.h b/media/base/audio_fifo.h
new file mode 100644
index 0000000000000000000000000000000000000000..98f6a27b6e4dbd4afc4d6dd79fd5be7722fa0f1e
--- /dev/null
+++ b/media/base/audio_fifo.h
@@ -0,0 +1,64 @@
+// 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_FIFO_H_
+#define MEDIA_BASE_AUDIO_FIFO_H_
+
+#include "media/base/audio_bus.h"
+#include "media/base/media_export.h"
+
+namespace media {
+
+// First-in first-out container for AudioBus elements.
+// The maximum number of audio frames in the FIFO is set at construction and
+// can not be extended dynamically. The allocated memory is utilized as a
+// ring buffer.
+class MEDIA_EXPORT AudioFifo {
+ public:
+ // Creates a new AudioFifo and allocates |channels| of length |frames|.
+ AudioFifo(int channels, int frames);
+ virtual ~AudioFifo();
+
+ // Pushes all audio channel data from |source| to the FIFO.
+ // Returns false if the allocated space is not sufficient. Partial data is
+ // not written to the FIFO for this overflow case.
+ bool Push(const AudioBus* source);
+
+ // Consumes |frames_to_consume| audio frames from the FIFO and copies
+ // them to |destination|.
+ // Returns false if the FIFO does not contain |frames_to_consume| frames
+ // or if there is not sufficient space in |destination| to store the frames.
+ bool Consume(AudioBus* destination, int frames_to_consume);
scherkus (not reviewing) 2012/09/06 13:53:57 are callees expected to check their own size / fra
henrika (OOO until Aug 14) 2012/09/07 14:10:37 Are you suggesting that I modify to void and add C
+
+ // Empties the FIFO without deallocating any memory.
+ void Clear();
+
+ // Number of actual audio bus frames in the FIFO.
+ int frames_in_fifo() const { return frames_in_fifo_; }
scherkus (not reviewing) 2012/09/06 13:53:57 s/frames_in_fifo/frames/ ? we're using a FIFO obj
henrika (OOO until Aug 14) 2012/09/07 14:10:37 LOL, that's my melody as well but not all reviewer
+
+ private:
+ int max_frames() const { return max_frames_in_fifo_; }
+
+ // The actual FIFO is an audio bus implemented as a ring buffer.
+ scoped_ptr<AudioBus> audio_bus_;
+
+ // Maximum number of elements the FIFO can contain.
+ // This value is set by |frames| in the constructor.
+ const int max_frames_in_fifo_;
+
+ // Number of actual elements in the FIFO.
+ int frames_in_fifo_;
+
+ // Current read position.
+ int read_pos_;
+
+ // Current write position.
+ int write_pos_;
+
+ DISALLOW_COPY_AND_ASSIGN(AudioFifo);
+};
+
+} // namespace media
+
+#endif // MEDIA_BASE_AUDIO_FIFO_H_
« no previous file with comments | « no previous file | media/base/audio_fifo.cc » ('j') | media/base/audio_fifo.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698