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

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

Issue 562863002: Gardening: Revert "Use AudioStreamMonitor to control power save blocking." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
« no previous file with comments | « content/public/browser/web_contents.h ('k') | 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/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/timer/timer.h" 11 #include "base/timer/timer.h"
12 #include "build/build_config.h"
13 #include "media/audio/audio_io.h" 12 #include "media/audio/audio_io.h"
14 #include "media/audio/audio_manager.h" 13 #include "media/audio/audio_manager.h"
15 #include "media/audio/audio_power_monitor.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,
(...skipping 23 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
55 // Only do power monitoring for non-mobile platforms that need it for the UI.
56 #if !defined(OS_ANDROID) && !defined(OS_IOS)
57 #define AUDIO_POWER_MONITORING
58 #endif
59
56 class MEDIA_EXPORT AudioOutputController 60 class MEDIA_EXPORT AudioOutputController
57 : public base::RefCountedThreadSafe<AudioOutputController>, 61 : public base::RefCountedThreadSafe<AudioOutputController>,
58 public AudioOutputStream::AudioSourceCallback, 62 public AudioOutputStream::AudioSourceCallback,
59 public AudioSourceDiverter, 63 public AudioSourceDiverter,
60 NON_EXPORTED_BASE(public AudioManager::AudioDeviceListener) { 64 NON_EXPORTED_BASE(public AudioManager::AudioDeviceListener) {
61 public: 65 public:
62 // An event handler that receives events from the AudioOutputController. The 66 // An event handler that receives events from the AudioOutputController. The
63 // following methods are called on the audio manager thread. 67 // following methods are called on the audio manager thread.
64 class MEDIA_EXPORT EventHandler { 68 class MEDIA_EXPORT EventHandler {
65 public: 69 public:
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 // thread, and if this is successful, the |event_handler| will receive an 103 // thread, and if this is successful, the |event_handler| will receive an
100 // OnCreated() call from the same audio manager thread. |audio_manager| must 104 // OnCreated() call from the same audio manager thread. |audio_manager| must
101 // outlive AudioOutputController. 105 // outlive AudioOutputController.
102 // The |output_device_id| can be either empty (default device) or specify a 106 // The |output_device_id| can be either empty (default device) or specify a
103 // specific hardware device for audio output. 107 // specific hardware device for audio output.
104 static scoped_refptr<AudioOutputController> Create( 108 static scoped_refptr<AudioOutputController> Create(
105 AudioManager* audio_manager, EventHandler* event_handler, 109 AudioManager* audio_manager, EventHandler* event_handler,
106 const AudioParameters& params, const std::string& output_device_id, 110 const AudioParameters& params, const std::string& output_device_id,
107 SyncReader* sync_reader); 111 SyncReader* sync_reader);
108 112
109 // Indicates whether audio power level analysis will be performed. If false,
110 // ReadCurrentPowerAndClip() can not be called.
111 static bool will_monitor_audio_levels() {
112 #if defined(OS_ANDROID) || defined(OS_IOS)
113 return false;
114 #else
115 return true;
116 #endif
117 }
118
119 // Methods to control playback of the stream. 113 // Methods to control playback of the stream.
120 114
121 // Starts the playback of this audio output stream. 115 // Starts the playback of this audio output stream.
122 void Play(); 116 void Play();
123 117
124 // Pause this audio output stream. 118 // Pause this audio output stream.
125 void Pause(); 119 void Pause();
126 120
127 // Closes the audio output stream. The state is changed and the resources 121 // Closes the audio output stream. The state is changed and the resources
128 // are freed on the audio manager thread. closed_task is executed after that. 122 // are freed on the audio manager thread. closed_task is executed after that.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 // Internal state of the source. 171 // Internal state of the source.
178 enum State { 172 enum State {
179 kEmpty, 173 kEmpty,
180 kCreated, 174 kCreated,
181 kPlaying, 175 kPlaying,
182 kPaused, 176 kPaused,
183 kClosed, 177 kClosed,
184 kError, 178 kError,
185 }; 179 };
186 180
187 // Time constant for AudioPowerMonitor. See AudioPowerMonitor ctor comments
188 // for semantics. This value was arbitrarily chosen, but seems to work well.
189 enum { kPowerMeasurementTimeConstantMillis = 10 };
190
191 friend class base::RefCountedThreadSafe<AudioOutputController>; 181 friend class base::RefCountedThreadSafe<AudioOutputController>;
192 virtual ~AudioOutputController(); 182 virtual ~AudioOutputController();
193 183
194 private: 184 private:
195 AudioOutputController(AudioManager* audio_manager, EventHandler* handler, 185 AudioOutputController(AudioManager* audio_manager, EventHandler* handler,
196 const AudioParameters& params, 186 const AudioParameters& params,
197 const std::string& output_device_id, 187 const std::string& output_device_id,
198 SyncReader* sync_reader); 188 SyncReader* sync_reader);
199 189
200 // The following methods are executed on the audio manager thread. 190 // The following methods are executed on the audio manager thread.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 // hardware audio thread. These operations need to be locked. But lock 228 // hardware audio thread. These operations need to be locked. But lock
239 // is not required for reading on the audio manager thread. 229 // is not required for reading on the audio manager thread.
240 State state_; 230 State state_;
241 231
242 // SyncReader is used only in low latency mode for synchronous reading. 232 // SyncReader is used only in low latency mode for synchronous reading.
243 SyncReader* const sync_reader_; 233 SyncReader* const sync_reader_;
244 234
245 // The message loop of audio manager thread that this object runs on. 235 // The message loop of audio manager thread that this object runs on.
246 const scoped_refptr<base::SingleThreadTaskRunner> message_loop_; 236 const scoped_refptr<base::SingleThreadTaskRunner> message_loop_;
247 237
238 #if defined(AUDIO_POWER_MONITORING)
248 // Scans audio samples from OnMoreData() as input to compute power levels. 239 // Scans audio samples from OnMoreData() as input to compute power levels.
249 AudioPowerMonitor power_monitor_; 240 AudioPowerMonitor power_monitor_;
241 #endif
250 242
251 // Flags when we've asked for a stream to start but it never did. 243 // Flags when we've asked for a stream to start but it never did.
252 base::AtomicRefCount on_more_io_data_called_; 244 base::AtomicRefCount on_more_io_data_called_;
253 scoped_ptr<base::OneShotTimer<AudioOutputController> > wedge_timer_; 245 scoped_ptr<base::OneShotTimer<AudioOutputController> > wedge_timer_;
254 246
255 DISALLOW_COPY_AND_ASSIGN(AudioOutputController); 247 DISALLOW_COPY_AND_ASSIGN(AudioOutputController);
256 }; 248 };
257 249
258 } // namespace media 250 } // namespace media
259 251
260 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ 252 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_
OLDNEW
« no previous file with comments | « content/public/browser/web_contents.h ('k') | media/audio/audio_output_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698