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_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/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 virtual void OnPlaying(AudioOutputController* controller) = 0; | 76 virtual void OnPlaying(AudioOutputController* controller) = 0; |
77 virtual void OnPaused(AudioOutputController* controller) = 0; | 77 virtual void OnPaused(AudioOutputController* controller) = 0; |
78 virtual void OnError(AudioOutputController* controller, int error_code) = 0; | 78 virtual void OnError(AudioOutputController* controller, int error_code) = 0; |
79 | 79 |
80 protected: | 80 protected: |
81 virtual ~EventHandler() {} | 81 virtual ~EventHandler() {} |
82 }; | 82 }; |
83 | 83 |
84 // A synchronous reader interface used by AudioOutputController for | 84 // A synchronous reader interface used by AudioOutputController for |
85 // synchronous reading. | 85 // synchronous reading. |
| 86 // TODO(crogers): find a better name for this class and the Read() method |
| 87 // now that it can handle synchronized I/O. |
86 class SyncReader { | 88 class SyncReader { |
87 public: | 89 public: |
88 virtual ~SyncReader() {} | 90 virtual ~SyncReader() {} |
89 | 91 |
90 // Notify the synchronous reader the number of bytes in the | 92 // Notify the synchronous reader the number of bytes in the |
91 // AudioOutputController not yet played. This is used by SyncReader to | 93 // AudioOutputController not yet played. This is used by SyncReader to |
92 // prepare more data and perform synchronization. | 94 // prepare more data and perform synchronization. |
93 virtual void UpdatePendingBytes(uint32 bytes) = 0; | 95 virtual void UpdatePendingBytes(uint32 bytes) = 0; |
94 | 96 |
95 // Attempt to completely fill |audio_bus|, return the actual number of | 97 // Attempt to completely fill |dest|, return the actual number of |
96 // frames that could be read. | 98 // frames that could be read. |
97 virtual int Read(AudioBus* audio_bus) = 0; | 99 // |source| may optionally be provided for input data. |
| 100 virtual int Read(AudioBus* source, AudioBus* dest) = 0; |
98 | 101 |
99 // Close this synchronous reader. | 102 // Close this synchronous reader. |
100 virtual void Close() = 0; | 103 virtual void Close() = 0; |
101 | 104 |
102 // Poll if data is ready. | 105 // Poll if data is ready. |
103 // Not reliable, as there is no guarantee that renderer is "new-style" | 106 // Not reliable, as there is no guarantee that renderer is "new-style" |
104 // renderer that writes metadata into buffer. After several unsuccessful | 107 // renderer that writes metadata into buffer. After several unsuccessful |
105 // attempts caller should assume the data is ready even if that function | 108 // attempts caller should assume the data is ready even if that function |
106 // returns false. | 109 // returns false. |
107 virtual bool DataReady() = 0; | 110 virtual bool DataReady() = 0; |
(...skipping 29 matching lines...) Expand all Loading... |
137 // | 140 // |
138 // It is safe to call this method more than once. Calls after the first one | 141 // It is safe to call this method more than once. Calls after the first one |
139 // will have no effect. | 142 // will have no effect. |
140 void Close(const base::Closure& closed_task); | 143 void Close(const base::Closure& closed_task); |
141 | 144 |
142 // Sets the volume of the audio output stream. | 145 // Sets the volume of the audio output stream. |
143 void SetVolume(double volume); | 146 void SetVolume(double volume); |
144 | 147 |
145 /////////////////////////////////////////////////////////////////////////// | 148 /////////////////////////////////////////////////////////////////////////// |
146 // AudioSourceCallback methods. | 149 // AudioSourceCallback methods. |
147 virtual int OnMoreData(AudioBus* audio_bus, | 150 virtual int OnMoreData(AudioBus* dest, |
148 AudioBuffersState buffers_state) OVERRIDE; | 151 AudioBuffersState buffers_state) OVERRIDE; |
| 152 virtual int OnMoreIOData(AudioBus* source, |
| 153 AudioBus* dest, |
| 154 AudioBuffersState buffers_state) OVERRIDE; |
149 virtual void OnError(AudioOutputStream* stream, int code) OVERRIDE; | 155 virtual void OnError(AudioOutputStream* stream, int code) OVERRIDE; |
150 virtual void WaitTillDataReady() OVERRIDE; | 156 virtual void WaitTillDataReady() OVERRIDE; |
151 | 157 |
152 protected: | 158 protected: |
153 // Internal state of the source. | 159 // Internal state of the source. |
154 enum State { | 160 enum State { |
155 kEmpty, | 161 kEmpty, |
156 kCreated, | 162 kCreated, |
157 kPlaying, | 163 kPlaying, |
158 kStarting, | 164 kStarting, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 // shutdown and force it to wait for the most delayed task. | 230 // shutdown and force it to wait for the most delayed task. |
225 // Also, if we're shutting down, we do not want to poll for more data. | 231 // Also, if we're shutting down, we do not want to poll for more data. |
226 base::WeakPtrFactory<AudioOutputController> weak_this_; | 232 base::WeakPtrFactory<AudioOutputController> weak_this_; |
227 | 233 |
228 DISALLOW_COPY_AND_ASSIGN(AudioOutputController); | 234 DISALLOW_COPY_AND_ASSIGN(AudioOutputController); |
229 }; | 235 }; |
230 | 236 |
231 } // namespace media | 237 } // namespace media |
232 | 238 |
233 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ | 239 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ |
OLD | NEW |