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