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

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: 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..efcecbcba1261eec1ae86b10a5b3a82067da65e8
--- /dev/null
+++ b/media/base/audio_fifo.h
@@ -0,0 +1,60 @@
+// 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. Each channel is stored in planar format
+// and guaranteed to be aligned by AudioBus::kChannelAlignment. The allocated
Chris Rogers 2012/09/04 20:07:20 comment nit: I'd simply remove this comment about
henrika (OOO until Aug 14) 2012/09/05 10:14:36 Done.
+// memory is utilized as a circular queue.
Chris Rogers 2012/09/04 20:07:20 nit: My preference is to avoid the word "queue" an
henrika (OOO until Aug 14) 2012/09/05 10:14:36 Done.
+class MEDIA_EXPORT AudioFifo {
+ public:
+ // Creates a new AudioFifo and allocates |channels| of length |frames|.
+ AudioFifo(int channels, int frames);
+ virtual ~AudioFifo();
+
+ // Appends all audio channel data from |source| to the FIFO.
+ // Returns false if the allocated space is not sufficient.
Chris Rogers 2012/09/04 20:07:20 and I would add that "partial data is not written"
henrika (OOO until Aug 14) 2012/09/05 10:14:36 Done.
+ bool Append(const AudioBus* source);
DaleCurtis 2012/09/05 10:34:18 Do we expect a recoverable / normal case where App
henrika (OOO until Aug 14) 2012/09/05 12:49:04 I discussed this off-line with Chris and his sugge
DaleCurtis 2012/09/05 13:09:22 I'd just prefer to not have to worry about the ret
+
+ // Removes |destination->frames()| audio frames from the FIFO and copies
+ // them to |destination|.
Chris Rogers 2012/09/04 20:07:20 and "Returns false if there's not enough data, not
henrika (OOO until Aug 14) 2012/09/05 10:14:36 Done.
+ bool Remove(AudioBus* destination);
DaleCurtis 2012/09/05 10:34:18 Kind of a misleading name, since it doesn't remove
henrika (OOO until Aug 14) 2012/09/05 12:49:04 Chris and I discussed this as well and landed at t
+
+ // Empties the FIFO without deallocating any memory.
+ void Clear();
+
+ // Helper methods.
+ int size() const { return size_; }
Chris Rogers 2012/09/04 20:07:20 I would tend to call this "available()" or "frames
henrika (OOO until Aug 14) 2012/09/05 10:14:36 I will wait for feedback from Dale as well. But av
DaleCurtis 2012/09/05 10:34:18 +1 for frames_available(). size() is inconsistent
henrika (OOO until Aug 14) 2012/09/05 12:49:04 OK, now I understand the point of using available.
+ int max_size() const { return audio_bus_->frames(); }
DaleCurtis 2012/09/05 10:34:18 Needed publicly?
henrika (OOO until Aug 14) 2012/09/05 12:49:04 nope; I just liked it. Will remove.
+ int channels() const { return audio_bus_->channels(); }
DaleCurtis 2012/09/05 10:34:18 Ditto.
henrika (OOO until Aug 14) 2012/09/05 12:49:04 got it, will remove.
+ bool empty() const { return (size_ == 0); }
+ bool full() const { return (size_ == max_size()); }
DaleCurtis 2012/09/05 10:34:18 Ditto / needed at all?
henrika (OOO until Aug 14) 2012/09/05 12:49:04 I dropped two of them but would like to keep these
DaleCurtis 2012/09/05 13:09:22 Seems you dropped them anyway? If you need them th
+
+ private:
+ // The actual FIFO is an audio bus implemented as a circular queue.
Chris Rogers 2012/09/04 20:07:20 queue -> buffer
henrika (OOO until Aug 14) 2012/09/05 10:14:36 Done.
+ scoped_ptr<AudioBus> audio_bus_;
+
+ // Number of actual elements in the FIFO.
+ int size_;
Chris Rogers 2012/09/04 20:07:20 size_ -> available_
henrika (OOO until Aug 14) 2012/09/05 10:14:36 I am inspired by: STL where queue::size() returns
+
+ // 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