OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_FIFO_H_ | 5 #ifndef MEDIA_BASE_AUDIO_FIFO_H_ |
6 #define MEDIA_BASE_AUDIO_FIFO_H_ | 6 #define MEDIA_BASE_AUDIO_FIFO_H_ |
7 | 7 |
8 #include "base/atomicops.h" | |
9 #include "media/base/audio_bus.h" | 8 #include "media/base/audio_bus.h" |
10 #include "media/base/media_export.h" | 9 #include "media/base/media_export.h" |
11 | 10 |
12 namespace media { | 11 namespace media { |
13 | 12 |
14 // First-in first-out container for AudioBus elements. | 13 // First-in first-out container for AudioBus elements. |
15 // The maximum number of audio frames in the FIFO is set at construction and | 14 // The maximum number of audio frames in the FIFO is set at construction and |
16 // can not be extended dynamically. The allocated memory is utilized as a | 15 // can not be extended dynamically. The allocated memory is utilized as a |
17 // ring buffer. | 16 // ring buffer. |
18 // This class is thread-safe in the limited sense that one thread may call | 17 // This class is thread-unsafe. |
19 // Push(), while a second thread calls Consume(). | |
20 class MEDIA_EXPORT AudioFifo { | 18 class MEDIA_EXPORT AudioFifo { |
21 public: | 19 public: |
22 // Creates a new AudioFifo and allocates |channels| of length |frames|. | 20 // Creates a new AudioFifo and allocates |channels| of length |frames|. |
23 AudioFifo(int channels, int frames); | 21 AudioFifo(int channels, int frames); |
24 virtual ~AudioFifo(); | 22 virtual ~AudioFifo(); |
25 | 23 |
26 // Pushes all audio channel data from |source| to the FIFO. | 24 // Pushes all audio channel data from |source| to the FIFO. |
27 // Push() will crash if the allocated space is insufficient. | 25 // Push() will crash if the allocated space is insufficient. |
28 void Push(const AudioBus* source); | 26 void Push(const AudioBus* source); |
29 | 27 |
(...skipping 14 matching lines...) Expand all Loading... |
44 | 42 |
45 private: | 43 private: |
46 // The actual FIFO is an audio bus implemented as a ring buffer. | 44 // The actual FIFO is an audio bus implemented as a ring buffer. |
47 scoped_ptr<AudioBus> audio_bus_; | 45 scoped_ptr<AudioBus> audio_bus_; |
48 | 46 |
49 // Maximum number of elements the FIFO can contain. | 47 // Maximum number of elements the FIFO can contain. |
50 // This value is set by |frames| in the constructor. | 48 // This value is set by |frames| in the constructor. |
51 const int max_frames_; | 49 const int max_frames_; |
52 | 50 |
53 // Number of actual elements in the FIFO. | 51 // Number of actual elements in the FIFO. |
54 volatile base::subtle::Atomic32 frames_pushed_; | 52 int frames_pushed_; |
55 volatile base::subtle::Atomic32 frames_consumed_; | 53 int frames_consumed_; |
56 | 54 |
57 // Current read position. | 55 // Current read position. |
58 int read_pos_; | 56 int read_pos_; |
59 | 57 |
60 // Current write position. | 58 // Current write position. |
61 int write_pos_; | 59 int write_pos_; |
62 | 60 |
63 DISALLOW_COPY_AND_ASSIGN(AudioFifo); | 61 DISALLOW_COPY_AND_ASSIGN(AudioFifo); |
64 }; | 62 }; |
65 | 63 |
66 } // namespace media | 64 } // namespace media |
67 | 65 |
68 #endif // MEDIA_BASE_AUDIO_FIFO_H_ | 66 #endif // MEDIA_BASE_AUDIO_FIFO_H_ |
OLD | NEW |