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