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

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

Issue 22339024: Crash fix: Remove MessageLoop from AudioPowerMonitor and instead use MessageLoopProxy in AudioOutpu… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: boolean style Created 7 years, 4 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
« no previous file with comments | « no previous file | media/audio/audio_output_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/timer/timer.h"
14 #include "media/audio/audio_io.h" 12 #include "media/audio/audio_io.h"
15 #include "media/audio/audio_manager.h" 13 #include "media/audio/audio_manager.h"
14 #include "media/audio/audio_power_monitor.h"
16 #include "media/audio/audio_source_diverter.h" 15 #include "media/audio/audio_source_diverter.h"
17 #include "media/audio/simple_sources.h" 16 #include "media/audio/simple_sources.h"
18 #include "media/base/media_export.h" 17 #include "media/base/media_export.h"
19 18
20 // An AudioOutputController controls an AudioOutputStream and provides data 19 // An AudioOutputController controls an AudioOutputStream and provides data
21 // to this output stream. It has an important function that it executes 20 // to this output stream. It has an important function that it executes
22 // audio operations like play, pause, stop, etc. on a separate thread, 21 // audio operations like play, pause, stop, etc. on a separate thread,
23 // namely the audio manager thread. 22 // namely the audio manager thread.
24 // 23 //
25 // All the public methods of AudioOutputController are non-blocking. 24 // All the public methods of AudioOutputController are non-blocking.
(...skipping 20 matching lines...) Expand all
46 // all functionally equivalent and require a Play() call to continue to the next 45 // all functionally equivalent and require a Play() call to continue to the next
47 // state. 46 // state.
48 // 47 //
49 // The AudioOutputStream can request data from the AudioOutputController via the 48 // The AudioOutputStream can request data from the AudioOutputController via the
50 // AudioSourceCallback interface. AudioOutputController uses the SyncReader 49 // AudioSourceCallback interface. AudioOutputController uses the SyncReader
51 // passed to it via construction to synchronously fulfill this read request. 50 // passed to it via construction to synchronously fulfill this read request.
52 // 51 //
53 52
54 namespace media { 53 namespace media {
55 54
56 class AudioPowerMonitor;
57
58 class MEDIA_EXPORT AudioOutputController 55 class MEDIA_EXPORT AudioOutputController
59 : public base::RefCountedThreadSafe<AudioOutputController>, 56 : public base::RefCountedThreadSafe<AudioOutputController>,
60 public AudioOutputStream::AudioSourceCallback, 57 public AudioOutputStream::AudioSourceCallback,
61 public AudioSourceDiverter, 58 public AudioSourceDiverter,
62 NON_EXPORTED_BASE(public AudioManager::AudioDeviceListener) { 59 NON_EXPORTED_BASE(public AudioManager::AudioDeviceListener) {
63 public: 60 public:
64 // An event handler that receives events from the AudioOutputController. The 61 // An event handler that receives events from the AudioOutputController. The
65 // following methods are called on the audio manager thread. 62 // following methods are called on the audio manager thread.
66 class MEDIA_EXPORT EventHandler { 63 class MEDIA_EXPORT EventHandler {
67 public: 64 public:
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 // The following methods are executed on the audio manager thread. 172 // The following methods are executed on the audio manager thread.
176 void DoCreate(bool is_for_device_change); 173 void DoCreate(bool is_for_device_change);
177 void DoPlay(); 174 void DoPlay();
178 void DoPause(); 175 void DoPause();
179 void DoClose(); 176 void DoClose();
180 void DoSetVolume(double volume); 177 void DoSetVolume(double volume);
181 void DoReportError(); 178 void DoReportError();
182 void DoStartDiverting(AudioOutputStream* to_stream); 179 void DoStartDiverting(AudioOutputStream* to_stream);
183 void DoStopDiverting(); 180 void DoStopDiverting();
184 181
185 // Called at regular intervals during playback to check for a change in 182 // Calls EventHandler::OnPowerMeasured() with the current power level and then
186 // silence and call EventHandler::OnAudible() when state changes occur. 183 // schedules itself to be called again later.
187 void MaybeInvokeAudibleCallback(); 184 void ReportPowerMeasurementPeriodically();
188 185
189 // Helper method that stops the physical stream. 186 // Helper method that stops the physical stream.
190 void StopStream(); 187 void StopStream();
191 188
192 // Helper method that stops, closes, and NULLs |*stream_|. 189 // Helper method that stops, closes, and NULLs |*stream_|.
193 void DoStopCloseAndClearStream(); 190 void DoStopCloseAndClearStream();
194 191
195 // Sanity-check that entry/exit to OnMoreIOData() by the hardware audio thread 192 // Sanity-check that entry/exit to OnMoreIOData() by the hardware audio thread
196 // happens only between AudioOutputStream::Start() and Stop(). 193 // happens only between AudioOutputStream::Start() and Stop().
197 void AllowEntryToOnMoreIOData(); 194 void AllowEntryToOnMoreIOData();
(...skipping 29 matching lines...) Expand all
227 // SyncReader is used only in low latency mode for synchronous reading. 224 // SyncReader is used only in low latency mode for synchronous reading.
228 SyncReader* const sync_reader_; 225 SyncReader* const sync_reader_;
229 226
230 // The message loop of audio manager thread that this object runs on. 227 // The message loop of audio manager thread that this object runs on.
231 const scoped_refptr<base::MessageLoopProxy> message_loop_; 228 const scoped_refptr<base::MessageLoopProxy> message_loop_;
232 229
233 // When starting stream we wait for data to become available. 230 // When starting stream we wait for data to become available.
234 // Number of times left. 231 // Number of times left.
235 int number_polling_attempts_left_; 232 int number_polling_attempts_left_;
236 233
237 // Scans audio samples from OnMoreIOData() as input and causes 234 // Scans audio samples from OnMoreIOData() as input to compute power levels.
238 // EventHandler::OnPowerMeasured() to be called with power level measurements 235 AudioPowerMonitor power_monitor_;
239 // at regular intervals. 236
240 scoped_ptr<AudioPowerMonitor> power_monitor_; 237 // Periodic callback to report power levels during playback.
241 base::CancelableCallback<void(float, bool)> power_monitor_callback_; 238 base::CancelableClosure power_poll_callback_;
242 239
243 DISALLOW_COPY_AND_ASSIGN(AudioOutputController); 240 DISALLOW_COPY_AND_ASSIGN(AudioOutputController);
244 }; 241 };
245 242
246 } // namespace media 243 } // namespace media
247 244
248 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ 245 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_
OLDNEW
« no previous file with comments | « no previous file | media/audio/audio_output_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698