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/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
10 #include "media/base/audio_bus.h" | 10 #include "media/base/audio_bus.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 // Creates a new AudioBlockFifo and allocates |blocks| memory, each block | 22 // Creates a new AudioBlockFifo and allocates |blocks| memory, each block |
23 // of memory can store |channels| of length |frames| data. | 23 // of memory can store |channels| of length |frames| data. |
24 AudioBlockFifo(int channels, int frames, int blocks); | 24 AudioBlockFifo(int channels, int frames, int blocks); |
25 virtual ~AudioBlockFifo(); | 25 virtual ~AudioBlockFifo(); |
26 | 26 |
27 // Pushes interleaved audio data from |source| to the FIFO. | 27 // Pushes interleaved audio data from |source| to the FIFO. |
28 // The method will deinterleave the data into a audio bus. | 28 // The method will deinterleave the data into a audio bus. |
29 // Push() will crash if the allocated space is insufficient. | 29 // Push() will crash if the allocated space is insufficient. |
30 void Push(const void* source, int frames, int bytes_per_sample); | 30 void Push(const void* source, int frames, int bytes_per_sample); |
31 | 31 |
| 32 // Pushes zeroed out frames to the FIFO. |
| 33 void PushSilence(int frames); |
| 34 |
32 // 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 |
33 // contains the consumed audio data to avoid copying. | 36 // contains the consumed audio data to avoid copying. |
34 // 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. |
35 const AudioBus* Consume(); | 38 const AudioBus* Consume(); |
36 | 39 |
37 // Empties the FIFO without deallocating any memory. | 40 // Empties the FIFO without deallocating any memory. |
38 void Clear(); | 41 void Clear(); |
39 | 42 |
40 // 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. |
41 int available_blocks() const { return available_blocks_; } | 44 int available_blocks() const { return available_blocks_; } |
42 | 45 |
43 // Number of available frames of data in the FIFO. | 46 // Number of available frames of data in the FIFO. |
44 int GetAvailableFrames() const; | 47 int GetAvailableFrames() const; |
45 | 48 |
46 // Number of unfilled frames in the whole FIFO. | 49 // Number of unfilled frames in the whole FIFO. |
47 int GetUnfilledFrames() const; | 50 int GetUnfilledFrames() const; |
48 | 51 |
49 // Dynamically increase |blocks| of memory to the FIFO. | 52 // Dynamically increase |blocks| of memory to the FIFO. |
50 void IncreaseCapacity(int blocks); | 53 void IncreaseCapacity(int blocks); |
51 | 54 |
52 private: | 55 private: |
| 56 // Common implementation for Push() and PushSilence. if |source| is nullptr, |
| 57 // silence will be pushed. To push silence, set source and bytes_per_sample to |
| 58 // nullptr and 0 respectively. |
| 59 void PushInternal(const void* source, int frames, int bytes_per_sample); |
| 60 |
53 // The actual FIFO is a vector of audio buses. | 61 // The actual FIFO is a vector of audio buses. |
54 ScopedVector<AudioBus> audio_blocks_; | 62 ScopedVector<AudioBus> audio_blocks_; |
55 | 63 |
56 // Number of channels in AudioBus. | 64 // Number of channels in AudioBus. |
57 const int channels_; | 65 const int channels_; |
58 | 66 |
59 // Maximum number of frames of data one block of memory can contain. | 67 // Maximum number of frames of data one block of memory can contain. |
60 // This value is set by |frames| in the constructor. | 68 // This value is set by |frames| in the constructor. |
61 const int block_frames_; | 69 const int block_frames_; |
62 | 70 |
63 // Used to keep track which block of memory to be written. | 71 // Used to keep track which block of memory to be written. |
64 int write_block_; | 72 int write_block_; |
65 | 73 |
66 // Used to keep track which block of memory to be consumed. | 74 // Used to keep track which block of memory to be consumed. |
67 int read_block_; | 75 int read_block_; |
68 | 76 |
69 // Number of available blocks of memory to be consumed. | 77 // Number of available blocks of memory to be consumed. |
70 int available_blocks_; | 78 int available_blocks_; |
71 | 79 |
72 // Current write position in the current written block. | 80 // Current write position in the current written block. |
73 int write_pos_; | 81 int write_pos_; |
74 | 82 |
75 DISALLOW_COPY_AND_ASSIGN(AudioBlockFifo); | 83 DISALLOW_COPY_AND_ASSIGN(AudioBlockFifo); |
76 }; | 84 }; |
77 | 85 |
78 } // namespace media | 86 } // namespace media |
79 | 87 |
80 #endif // MEDIA_BASE_AUDIO_BLOCK_FIFO_H_ | 88 #endif // MEDIA_BASE_AUDIO_BLOCK_FIFO_H_ |
OLD | NEW |