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

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

Issue 188243002: Fix AudioEntry destruction order. Add debugging CHECKs for racy shutdown. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Typos. Created 6 years, 9 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/atomic_ref_count.h" 8 #include "base/atomic_ref_count.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/cancelable_callback.h" 10 #include "base/cancelable_callback.h"
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 // Calls EventHandler::OnPowerMeasured() with the current power level and then 208 // Calls EventHandler::OnPowerMeasured() with the current power level and then
209 // schedules itself to be called again later. 209 // schedules itself to be called again later.
210 void ReportPowerMeasurementPeriodically(); 210 void ReportPowerMeasurementPeriodically();
211 211
212 // Helper method that stops the physical stream. 212 // Helper method that stops the physical stream.
213 void StopStream(); 213 void StopStream();
214 214
215 // Helper method that stops, closes, and NULLs |*stream_|. 215 // Helper method that stops, closes, and NULLs |*stream_|.
216 void DoStopCloseAndClearStream(); 216 void DoStopCloseAndClearStream();
217 217
218 // Sanity-check that entry/exit to OnMoreIOData() by the hardware audio thread
219 // happens only between AudioOutputStream::Start() and Stop().
220 void AllowEntryToOnMoreIOData();
221 void DisallowEntryToOnMoreIOData();
222
223 // Checks if a stream was started successfully but never calls OnMoreIOData(). 218 // Checks if a stream was started successfully but never calls OnMoreIOData().
224 void WedgeCheck(); 219 void WedgeCheck();
225 220
226 AudioManager* const audio_manager_; 221 AudioManager* const audio_manager_;
227 const AudioParameters params_; 222 const AudioParameters params_;
228 EventHandler* const handler_; 223 EventHandler* const handler_;
229 224
230 // Specifies the device id of the output device to open or empty for the 225 // Specifies the device id of the output device to open or empty for the
231 // default output device. 226 // default output device.
232 std::string output_device_id_; 227 std::string output_device_id_;
233 228
234 AudioOutputStream* stream_; 229 AudioOutputStream* stream_;
235 230
236 // When non-NULL, audio is being diverted to this stream. 231 // When non-NULL, audio is being diverted to this stream.
237 AudioOutputStream* diverting_to_stream_; 232 AudioOutputStream* diverting_to_stream_;
238 233
239 // The current volume of the audio stream. 234 // The current volume of the audio stream.
240 double volume_; 235 double volume_;
241 236
242 // |state_| is written on the audio manager thread and is read on the 237 // |state_| is written on the audio manager thread and is read on the
243 // hardware audio thread. These operations need to be locked. But lock 238 // hardware audio thread. These operations need to be locked. But lock
244 // is not required for reading on the audio manager thread. 239 // is not required for reading on the audio manager thread.
245 State state_; 240 State state_;
246 241
247 // Binary semaphore, used to ensure that only one thread enters the 242 // Atomic ref count indicating when when we're in the middle of handling an
248 // OnMoreIOData() method, and only when it is valid to do so. This is for 243 // OnMoreIOData() callback. Will be CHECK'd to find crashes.
249 // sanity-checking the behavior of platform implementations of 244 // TODO(dalecurtis): Remove debug helpers for http://crbug.com/349651
250 // AudioOutputStream. In other words, multiple contention is not expected, 245 base::AtomicRefCount currently_in_on_more_io_data_;
251 // nor in the design here.
252 base::AtomicRefCount num_allowed_io_;
253 246
254 // SyncReader is used only in low latency mode for synchronous reading. 247 // SyncReader is used only in low latency mode for synchronous reading.
255 SyncReader* const sync_reader_; 248 SyncReader* const sync_reader_;
256 249
257 // The message loop of audio manager thread that this object runs on. 250 // The message loop of audio manager thread that this object runs on.
258 const scoped_refptr<base::SingleThreadTaskRunner> message_loop_; 251 const scoped_refptr<base::SingleThreadTaskRunner> message_loop_;
259 252
260 #if defined(AUDIO_POWER_MONITORING) 253 #if defined(AUDIO_POWER_MONITORING)
261 // Scans audio samples from OnMoreIOData() as input to compute power levels. 254 // Scans audio samples from OnMoreIOData() as input to compute power levels.
262 AudioPowerMonitor power_monitor_; 255 AudioPowerMonitor power_monitor_;
263 256
264 // Periodic callback to report power levels during playback. 257 // Periodic callback to report power levels during playback.
265 base::CancelableClosure power_poll_callback_; 258 base::CancelableClosure power_poll_callback_;
266 #endif 259 #endif
267 260
268 // Flags when we've asked for a stream to start but it never did. 261 // Flags when we've asked for a stream to start but it never did.
269 base::AtomicRefCount on_more_io_data_called_; 262 base::AtomicRefCount on_more_io_data_called_;
270 scoped_ptr<base::OneShotTimer<AudioOutputController> > wedge_timer_; 263 scoped_ptr<base::OneShotTimer<AudioOutputController> > wedge_timer_;
271 264
272 DISALLOW_COPY_AND_ASSIGN(AudioOutputController); 265 DISALLOW_COPY_AND_ASSIGN(AudioOutputController);
273 }; 266 };
274 267
275 } // namespace media 268 } // namespace media
276 269
277 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ 270 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698