OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ | 5 #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ |
6 #define MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ | 6 #define MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 12 matching lines...) Expand all Loading... | |
23 // namely the audio controller thread. | 23 // namely the audio controller thread. |
24 // | 24 // |
25 // All the public methods of AudioOutputController are non-blocking except | 25 // All the public methods of AudioOutputController are non-blocking except |
26 // close, the actual operations are performed on the audio controller thread. | 26 // close, the actual operations are performed on the audio controller thread. |
27 // | 27 // |
28 // Here is a state diagram for the AudioOutputController: | 28 // Here is a state diagram for the AudioOutputController: |
29 // | 29 // |
30 // .----> [ Closed / Error ] <------. | 30 // .----> [ Closed / Error ] <------. |
31 // | ^ | | 31 // | ^ | |
32 // | | | | 32 // | | | |
33 // [ Created ] --> [ Playing ] --> [ Paused ] | 33 // [ Created ] --> [ Playing ] --> [ Paused ] |
acolwell GONE FROM CHROMIUM
2011/10/24 03:47:15
Please update the diagram & comments to reflect th
enal1
2011/10/24 16:28:29
Done.
| |
34 // ^ ^ | | 34 // ^ ^ | |
35 // | | | | 35 // | | | |
36 // *[ Empty ] `-----------------' | 36 // *[ Empty ] `-----------------' |
37 // | 37 // |
38 // * Initial state | 38 // * Initial state |
39 // | 39 // |
40 // There are two modes of buffering operations supported by this class. | 40 // There are two modes of buffering operations supported by this class. |
41 // | 41 // |
42 // Regular latency mode: | 42 // Regular latency mode: |
43 // In this mode we receive signals from AudioOutputController and then we | 43 // In this mode we receive signals from AudioOutputController and then we |
44 // enqueue data into it. | 44 // enqueue data into it. |
45 // | 45 // |
46 // Low latency mode: | 46 // Low latency mode: |
47 // In this mode a DataSource object is given to the AudioOutputController | 47 // In this mode a DataSource object is given to the AudioOutputController |
48 // and AudioOutputController reads from it synchronously. | 48 // and AudioOutputController reads from it synchronously. |
49 // | 49 // |
50 #include "media/base/media_export.h" | 50 #include "media/base/media_export.h" |
51 | 51 |
52 namespace media { | 52 namespace media { |
53 | 53 |
54 class MEDIA_EXPORT AudioOutputController | 54 class MEDIA_EXPORT AudioOutputController |
55 : public base::RefCountedThreadSafe<AudioOutputController>, | 55 : public base::RefCountedThreadSafe<AudioOutputController>, |
56 public AudioOutputStream::AudioSourceCallback { | 56 public AudioOutputStream::AudioSourceCallback { |
57 public: | 57 public: |
58 // Internal state of the source. | |
59 enum State { | |
60 kEmpty, | |
61 kCreated, | |
62 kPlaying, | |
63 kPaused, | |
64 kClosed, | |
65 kError, | |
66 }; | |
67 | |
68 // Value sent by the controller to the renderer in low-latency mode | 58 // Value sent by the controller to the renderer in low-latency mode |
69 // indicating that the stream is paused. | 59 // indicating that the stream is paused. |
70 static const int kPauseMark; | 60 static const int kPauseMark; |
71 | 61 |
72 // An event handler that receives events from the AudioOutputController. The | 62 // An event handler that receives events from the AudioOutputController. The |
73 // following methods are called on the audio controller thread. | 63 // following methods are called on the audio controller thread. |
74 class MEDIA_EXPORT EventHandler { | 64 class MEDIA_EXPORT EventHandler { |
75 public: | 65 public: |
76 virtual ~EventHandler() {} | 66 virtual ~EventHandler() {} |
77 virtual void OnCreated(AudioOutputController* controller) = 0; | 67 virtual void OnCreated(AudioOutputController* controller) = 0; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 void EnqueueData(const uint8* data, uint32 size); | 152 void EnqueueData(const uint8* data, uint32 size); |
163 | 153 |
164 bool LowLatencyMode() const { return sync_reader_ != NULL; } | 154 bool LowLatencyMode() const { return sync_reader_ != NULL; } |
165 | 155 |
166 /////////////////////////////////////////////////////////////////////////// | 156 /////////////////////////////////////////////////////////////////////////// |
167 // AudioSourceCallback methods. | 157 // AudioSourceCallback methods. |
168 virtual uint32 OnMoreData(AudioOutputStream* stream, uint8* dest, | 158 virtual uint32 OnMoreData(AudioOutputStream* stream, uint8* dest, |
169 uint32 max_size, AudioBuffersState buffers_state); | 159 uint32 max_size, AudioBuffersState buffers_state); |
170 virtual void OnError(AudioOutputStream* stream, int code); | 160 virtual void OnError(AudioOutputStream* stream, int code); |
171 | 161 |
162 protected: | |
163 // Internal state of the source. | |
164 enum State { | |
165 kEmpty, | |
166 kCreated, | |
167 kPlaying, | |
168 kStarting, | |
169 kPaused, | |
170 kClosed, | |
171 kError, | |
172 }; | |
173 | |
172 private: | 174 private: |
173 // We are polling sync reader if data became available. | 175 // We are polling sync reader if data became available. |
174 static const int kPollNumAttempts; | 176 static const int kPollNumAttempts; |
175 static const int kPollPauseInMilliseconds; | 177 static const int kPollPauseInMilliseconds; |
176 | 178 |
177 AudioOutputController(EventHandler* handler, | 179 AudioOutputController(EventHandler* handler, |
178 uint32 capacity, SyncReader* sync_reader); | 180 uint32 capacity, SyncReader* sync_reader); |
179 | 181 |
180 // The following methods are executed on the audio controller thread. | 182 // The following methods are executed on the audio controller thread. |
181 void DoCreate(const AudioParameters& params); | 183 void DoCreate(const AudioParameters& params); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 // When starting stream we wait for data to become available. | 225 // When starting stream we wait for data to become available. |
224 // Number of times left. | 226 // Number of times left. |
225 int number_polling_attempts_left_; | 227 int number_polling_attempts_left_; |
226 | 228 |
227 DISALLOW_COPY_AND_ASSIGN(AudioOutputController); | 229 DISALLOW_COPY_AND_ASSIGN(AudioOutputController); |
228 }; | 230 }; |
229 | 231 |
230 } // namespace media | 232 } // namespace media |
231 | 233 |
232 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ | 234 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ |
OLD | NEW |