OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef MEDIA_BASE_AUDIO_BLOCK_FIFO_H_ |
| 6 #define MEDIA_BASE_AUDIO_BLOCK_FIFO_H_ |
| 7 |
| 8 #include <queue> |
| 9 |
| 10 #include "base/memory/scoped_vector.h" |
| 11 #include "media/base/audio_bus.h" |
| 12 #include "media/base/media_export.h" |
| 13 |
| 14 namespace media { |
| 15 |
| 16 // First-in first-out container for AudioBus elements. |
| 17 // The FIFO is composed of blocks of AudioBus elements, it accepts interleaved |
| 18 // data as input and will deinterleave it into the FIFO, and it only allows |
| 19 // consuming a whole block of AudioBus element. |
| 20 // This class is thread-unsafe. |
| 21 class MEDIA_EXPORT AudioBlockFifo { |
| 22 public: |
| 23 // Creates a new AudioBlockFifo and allocates |blocks| memory, each block |
| 24 // of memory can store |channels| of length |frames| data. |
| 25 AudioBlockFifo(int channels, int frames, int blocks); |
| 26 virtual ~AudioBlockFifo(); |
| 27 |
| 28 // Pushes interleaved audio data from |source| to the FIFO. |
| 29 // The method will deinterleave the data into a audio bus. |
| 30 // Push() will crash if the allocated space is insufficient. |
| 31 void Push(const void* source, int frames, int bytes_per_sample); |
| 32 |
| 33 // Consumes a block of audio from the FIFO. Returns an AudioBus which |
| 34 // contains the consumed audio data to avoid copying. |
| 35 // Consume() will crash if the FIFO does not contain a block of data. |
| 36 const AudioBus* Consume(); |
| 37 |
| 38 // Empties the FIFO without deallocating any memory. |
| 39 void Clear(); |
| 40 |
| 41 // Number of available block of memory ready to be consumed in the FIFO. |
| 42 int available_blocks() const { return filled_blocks_.size(); } |
| 43 |
| 44 // Number of unfilled frames in the whole FIFO. |
| 45 int unfilled_frames() const; |
| 46 |
| 47 private: |
| 48 // The actual FIFO is a vector of audio buses. |
| 49 ScopedVector<AudioBus> audio_blocks_; |
| 50 |
| 51 // Queues used to keep track which blocks of memory to be wirteen and |
| 52 // consumed. |
| 53 std::queue<AudioBus*> unfilled_blocks_; |
| 54 std::queue<AudioBus*> filled_blocks_; |
| 55 |
| 56 // Maximum number of frames of data one block of memory can contain. |
| 57 // This value is set by |frames| in the constructor. |
| 58 const int block_frames_; |
| 59 |
| 60 // Current write position in the current written block. |
| 61 int write_pos_; |
| 62 |
| 63 DISALLOW_COPY_AND_ASSIGN(AudioBlockFifo); |
| 64 }; |
| 65 |
| 66 } // namespace media |
| 67 |
| 68 #endif // MEDIA_BASE_AUDIO_BLOCK_FIFO_H_ |
OLD | NEW |