| 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" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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 |
| 31 // Pushes the audio data from |source| to the FIFO. | |
| 32 // Push() will crash if the allocated space is insufficient. | |
| 33 void Push(const AudioBus* source); | |
| 34 | |
| 35 // Consumes a block of audio from the FIFO. Returns an AudioBus which | 31 // Consumes a block of audio from the FIFO. Returns an AudioBus which |
| 36 // contains the consumed audio data to avoid copying. | 32 // contains the consumed audio data to avoid copying. |
| 37 // Consume() will crash if the FIFO does not contain a block of data. | 33 // Consume() will crash if the FIFO does not contain a block of data. |
| 38 const AudioBus* Consume(); | 34 const AudioBus* Consume(); |
| 39 | 35 |
| 40 // Empties the FIFO without deallocating any memory. | 36 // Empties the FIFO without deallocating any memory. |
| 41 void Clear(); | 37 void Clear(); |
| 42 | 38 |
| 43 // Number of available block of memory ready to be consumed in the FIFO. | 39 // Number of available block of memory ready to be consumed in the FIFO. |
| 44 int available_blocks() const { return available_blocks_; } | 40 int available_blocks() const { return available_blocks_; } |
| 45 | 41 |
| 46 // Number of available frames of data in the FIFO. | 42 // Number of available frames of data in the FIFO. |
| 47 int GetAvailableFrames() const; | 43 int GetAvailableFrames() const; |
| 48 | 44 |
| 49 // Number of unfilled frames in the whole FIFO. | 45 // Number of unfilled frames in the whole FIFO. |
| 50 int GetUnfilledFrames() const; | 46 int GetUnfilledFrames() const; |
| 51 | 47 |
| 52 private: | 48 private: |
| 53 // Helper method to update the indexes in Push methods. | |
| 54 void UpdatePosition(int push_frames); | |
| 55 | |
| 56 // The actual FIFO is a vector of audio buses. | 49 // The actual FIFO is a vector of audio buses. |
| 57 ScopedVector<AudioBus> audio_blocks_; | 50 ScopedVector<AudioBus> audio_blocks_; |
| 58 | 51 |
| 59 // Maximum number of frames of data one block of memory can contain. | 52 // Maximum number of frames of data one block of memory can contain. |
| 60 // This value is set by |frames| in the constructor. | 53 // This value is set by |frames| in the constructor. |
| 61 const int block_frames_; | 54 const int block_frames_; |
| 62 | 55 |
| 63 // Used to keep track which block of memory to be written. | 56 // Used to keep track which block of memory to be written. |
| 64 int write_block_; | 57 int write_block_; |
| 65 | 58 |
| 66 // Used to keep track which block of memory to be consumed. | 59 // Used to keep track which block of memory to be consumed. |
| 67 int read_block_; | 60 int read_block_; |
| 68 | 61 |
| 69 // Number of available blocks of memory to be consumed. | 62 // Number of available blocks of memory to be consumed. |
| 70 int available_blocks_; | 63 int available_blocks_; |
| 71 | 64 |
| 72 // Current write position in the current written block. | 65 // Current write position in the current written block. |
| 73 int write_pos_; | 66 int write_pos_; |
| 74 | 67 |
| 75 DISALLOW_COPY_AND_ASSIGN(AudioBlockFifo); | 68 DISALLOW_COPY_AND_ASSIGN(AudioBlockFifo); |
| 76 }; | 69 }; |
| 77 | 70 |
| 78 } // namespace media | 71 } // namespace media |
| 79 | 72 |
| 80 #endif // MEDIA_BASE_AUDIO_BLOCK_FIFO_H_ | 73 #endif // MEDIA_BASE_AUDIO_BLOCK_FIFO_H_ |
| OLD | NEW |