Chromium Code Reviews| Index: media/base/audio_block_fifo.h |
| diff --git a/media/base/audio_block_fifo.h b/media/base/audio_block_fifo.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..08611ca98272fec0eca8b73f3a03486fad215693 |
| --- /dev/null |
| +++ b/media/base/audio_block_fifo.h |
| @@ -0,0 +1,67 @@ |
| +// Copyright 2014 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_BLOCK_FIFO_H_ |
| +#define MEDIA_BASE_AUDIO_BLOCK_FIFO_H_ |
| + |
| +#include <queue> |
| + |
| +#include "base/memory/scoped_vector.h" |
| +#include "media/base/audio_bus.h" |
| +#include "media/base/media_export.h" |
| + |
| +namespace media { |
| + |
| +// First-in first-out container for AudioBus elements. |
| +// The FIFO is composed of blocks of AudioBus elements, it accepts interleaved |
| +// data as input and will deinterleave it into the FIFO, and it only allows |
| +// consuming a whole block of AudioBus element. |
| +// This class is thread-unsafe. |
| +class MEDIA_EXPORT AudioBlockFifo { |
| + public: |
| + // Creates a new AudioBlockFifo and allocates |blocks| memory, each block |
| + // of memory can store |channels| of length |frames| data. |
| + AudioBlockFifo(int channels, int frames, int blocks); |
| + virtual ~AudioBlockFifo(); |
| + |
| + // Pushes interleaved audio data from |source| to the FIFO. |
| + // The method will deinterleave the data into a audio bus. |
| + // Push() will crash if the allocated space is insufficient. |
| + void Push(const void* source, int frames, int bytes_per_sample); |
| + |
| + // Consumes a block of audio from the FIFO. Returns an AudioBus which |
| + // contains the consumed audio data to avoid copying. |
| + // Consume() will crash if the FIFO does not contain a block of data. |
| + const AudioBus* Consume(); |
| + |
| + // Empties the FIFO without deallocating any memory. |
| + void Clear(); |
| + |
| + // Number of block of memory ready to be consumed in the FIFO. |
| + int filled_blocks() const; |
|
DaleCurtis
2014/07/11 22:33:33
Hacker_style requires the methods to be defined in
no longer working on chromium
2014/07/14 11:28:27
Done. Just a though, since I change the empty_fram
DaleCurtis
2014/07/14 20:14:26
I still like available better, but it's up to you.
|
| + |
| + int empty_frames() const; |
|
DaleCurtis
2014/07/11 22:33:33
Ditto. This also needs a comment since it's not r
no longer working on chromium
2014/07/14 11:28:27
I want this to tell the number of unfilled frames
|
| + |
| + private: |
| + // The actual FIFO is a vector of audio buses. |
| + ScopedVector<AudioBus> audio_blocks_; |
| + |
| + // Queues used to keep track which blocks of memory to be wirteen and |
| + // consumed. |
| + std::queue<AudioBus*> empty_blocks_; |
|
DaleCurtis
2014/07/11 22:33:33
Why do you need these? Shouldn't you just need a
no longer working on chromium
2014/07/14 11:28:27
Indexes might work but require more complicated lo
DaleCurtis
2014/07/14 20:14:26
Good point, you can just drop the head==tail check
no longer working on chromium
2014/07/15 21:51:42
:) Both work for me. But since you prefer indices,
|
| + std::queue<AudioBus*> filled_blocks_; |
| + |
| + // Maximum number of frames of data one block of memory can contain. |
| + // This value is set by |frames| in the constructor. |
| + const int block_frames_; |
| + |
| + // Current write position in the current written block. |
| + int write_pos_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(AudioBlockFifo); |
| +}; |
| + |
| +} // namespace media |
| + |
| +#endif // MEDIA_BASE_AUDIO_BLOCK_FIFO_H_ |