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