Chromium Code Reviews| 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..5bd9d477db345b16004281d7cae40287c1009081 |
| --- /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 |destination->frames()| audio frames from the FIFO and copies |
| + // them to |destination|. |
| + // Returns false if it is not possible to fill up the complete |destination|. |
|
DaleCurtis
2012/09/05 13:09:22
Reword, maybe: "Returns false if there are not eno
henrika (OOO until Aug 14)
2012/09/06 09:40:06
Modified the API.
|
| + // Partial data is not copied to the audio bus for this underrun case. |
| + bool Consume(AudioBus* destination); |
| + |
| + // Empties the FIFO without deallocating any memory. |
| + void Clear(); |
| + |
| + // Number of actual audio bus frames in the FIFO. |
|
DaleCurtis
2012/09/05 13:09:22
Drop the "bus".
henrika (OOO until Aug 14)
2012/09/05 15:26:32
Done.
DaleCurtis
2012/09/06 11:14:13
Looks unchanged still?
|
| + int frames_in_fifo() const { return frames_in_fifo_; } |
| + |
| + 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 size is set by |frames| in the constructor. |
|
DaleCurtis
2012/09/05 13:09:22
s/size/value/
henrika (OOO until Aug 14)
2012/09/05 15:26:32
Done.
|
| + 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_ |