Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: media/audio/audio_output_controller.h

Issue 10832285: Switch OnMoreData() to use AudioBus. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Comments. Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 // synchronous reading. 85 // synchronous reading.
86 class SyncReader { 86 class SyncReader {
87 public: 87 public:
88 virtual ~SyncReader() {} 88 virtual ~SyncReader() {}
89 89
90 // Notify the synchronous reader the number of bytes in the 90 // Notify the synchronous reader the number of bytes in the
91 // AudioOutputController not yet played. This is used by SyncReader to 91 // AudioOutputController not yet played. This is used by SyncReader to
92 // prepare more data and perform synchronization. 92 // prepare more data and perform synchronization.
93 virtual void UpdatePendingBytes(uint32 bytes) = 0; 93 virtual void UpdatePendingBytes(uint32 bytes) = 0;
94 94
95 // Read certain amount of data into |data|. This method returns if some 95 // Attempt to completely fill |audio_bus|, return the actual number of
96 // data is available. 96 // frames that could be read.
97 virtual uint32 Read(void* data, uint32 size) = 0; 97 virtual int Read(AudioBus* audio_bus) = 0;
98 98
99 // Close this synchronous reader. 99 // Close this synchronous reader.
100 virtual void Close() = 0; 100 virtual void Close() = 0;
101 101
102 // Poll if data is ready. 102 // Poll if data is ready.
103 // Not reliable, as there is no guarantee that renderer is "new-style" 103 // Not reliable, as there is no guarantee that renderer is "new-style"
104 // renderer that writes metadata into buffer. After several unsuccessful 104 // renderer that writes metadata into buffer. After several unsuccessful
105 // attempts caller should assume the data is ready even if that function 105 // attempts caller should assume the data is ready even if that function
106 // returns false. 106 // returns false.
107 virtual bool DataReady() = 0; 107 virtual bool DataReady() = 0;
(...skipping 29 matching lines...) Expand all
137 // 137 //
138 // It is safe to call this method more than once. Calls after the first one 138 // It is safe to call this method more than once. Calls after the first one
139 // will have no effect. 139 // will have no effect.
140 void Close(const base::Closure& closed_task); 140 void Close(const base::Closure& closed_task);
141 141
142 // Sets the volume of the audio output stream. 142 // Sets the volume of the audio output stream.
143 void SetVolume(double volume); 143 void SetVolume(double volume);
144 144
145 /////////////////////////////////////////////////////////////////////////// 145 ///////////////////////////////////////////////////////////////////////////
146 // AudioSourceCallback methods. 146 // AudioSourceCallback methods.
147 virtual uint32 OnMoreData(uint8* dest, 147 virtual int OnMoreData(AudioBus* audio_bus,
148 uint32 max_size, 148 AudioBuffersState buffers_state) OVERRIDE;
149 AudioBuffersState buffers_state) OVERRIDE;
150 virtual void OnError(AudioOutputStream* stream, int code) OVERRIDE; 149 virtual void OnError(AudioOutputStream* stream, int code) OVERRIDE;
151 virtual void WaitTillDataReady() OVERRIDE; 150 virtual void WaitTillDataReady() OVERRIDE;
152 151
153 protected: 152 protected:
154 // Internal state of the source. 153 // Internal state of the source.
155 enum State { 154 enum State {
156 kEmpty, 155 kEmpty,
157 kCreated, 156 kCreated,
158 kPlaying, 157 kPlaying,
159 kStarting, 158 kStarting,
160 kPausedWhenStarting, 159 kPausedWhenStarting,
161 kPaused, 160 kPaused,
162 kClosed, 161 kClosed,
163 kError, 162 kError,
164 }; 163 };
165 164
166 friend class base::RefCountedThreadSafe<AudioOutputController>; 165 friend class base::RefCountedThreadSafe<AudioOutputController>;
167 virtual ~AudioOutputController(); 166 virtual ~AudioOutputController();
168 167
169 private: 168 private:
170 // We are polling sync reader if data became available. 169 // We are polling sync reader if data became available.
171 static const int kPollNumAttempts; 170 static const int kPollNumAttempts;
172 static const int kPollPauseInMilliseconds; 171 static const int kPollPauseInMilliseconds;
173 172
174 AudioOutputController(EventHandler* handler, 173 AudioOutputController(EventHandler* handler,
175 SyncReader* sync_reader); 174 SyncReader* sync_reader,
175 const AudioParameters& params);
176 176
177 // The following methods are executed on the audio manager thread. 177 // The following methods are executed on the audio manager thread.
178 void DoCreate(AudioManager* audio_manager, const AudioParameters& params); 178 void DoCreate(AudioManager* audio_manager);
179 void DoPlay(); 179 void DoPlay();
180 void PollAndStartIfDataReady(); 180 void PollAndStartIfDataReady();
181 void DoPause(); 181 void DoPause();
182 void DoFlush(); 182 void DoFlush();
183 void DoClose(); 183 void DoClose();
184 void DoSetVolume(double volume); 184 void DoSetVolume(double volume);
185 void DoReportError(int code); 185 void DoReportError(int code);
186 186
187 // Helper method that starts physical stream. 187 // Helper method that starts physical stream.
188 void StartStream(); 188 void StartStream();
(...skipping 21 matching lines...) Expand all
210 // SyncReader is used only in low latency mode for synchronous reading. 210 // SyncReader is used only in low latency mode for synchronous reading.
211 SyncReader* sync_reader_; 211 SyncReader* sync_reader_;
212 212
213 // The message loop of audio manager thread that this object runs on. 213 // The message loop of audio manager thread that this object runs on.
214 scoped_refptr<base::MessageLoopProxy> message_loop_; 214 scoped_refptr<base::MessageLoopProxy> message_loop_;
215 215
216 // When starting stream we wait for data to become available. 216 // When starting stream we wait for data to become available.
217 // Number of times left. 217 // Number of times left.
218 int number_polling_attempts_left_; 218 int number_polling_attempts_left_;
219 219
220 AudioParameters params_;
221
220 // Used to post delayed tasks to ourselves that we can cancel. 222 // Used to post delayed tasks to ourselves that we can cancel.
221 // We don't want the tasks to hold onto a reference as it will slow down 223 // We don't want the tasks to hold onto a reference as it will slow down
222 // shutdown and force it to wait for the most delayed task. 224 // shutdown and force it to wait for the most delayed task.
223 // Also, if we're shutting down, we do not want to poll for more data. 225 // Also, if we're shutting down, we do not want to poll for more data.
224 base::WeakPtrFactory<AudioOutputController> weak_this_; 226 base::WeakPtrFactory<AudioOutputController> weak_this_;
225 227
226 DISALLOW_COPY_AND_ASSIGN(AudioOutputController); 228 DISALLOW_COPY_AND_ASSIGN(AudioOutputController);
227 }; 229 };
228 230
229 } // namespace media 231 } // namespace media
230 232
231 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ 233 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_
OLDNEW
« no previous file with comments | « media/audio/audio_low_latency_input_output_unittest.cc ('k') | media/audio/audio_output_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698