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

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

Issue 1897953003: Unmute Tab Audio For Desktop Share (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
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 <stdint.h> 8 #include <stdint.h>
9 #include <set>
9 10
10 #include "base/atomic_ref_count.h" 11 #include "base/atomic_ref_count.h"
11 #include "base/callback.h" 12 #include "base/callback.h"
12 #include "base/macros.h" 13 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
14 #include "base/threading/thread_checker.h" 15 #include "base/threading/thread_checker.h"
15 #include "base/timer/timer.h" 16 #include "base/timer/timer.h"
16 #include "build/build_config.h" 17 #include "build/build_config.h"
17 #include "media/audio/audio_io.h" 18 #include "media/audio/audio_io.h"
18 #include "media/audio/audio_manager.h" 19 #include "media/audio/audio_manager.h"
19 #include "media/audio/audio_power_monitor.h" 20 #include "media/audio/audio_power_monitor.h"
20 #include "media/audio/audio_source_diverter.h" 21 #include "media/audio/audio_source_diverter.h"
21 #include "media/audio/simple_sources.h" 22 #include "media/audio/simple_sources.h"
23 #include "media/audio/virtual_audio_sink.h"
22 #include "media/base/media_export.h" 24 #include "media/base/media_export.h"
23 25
24 // An AudioOutputController controls an AudioOutputStream and provides data 26 // An AudioOutputController controls an AudioOutputStream and provides data
25 // to this output stream. It has an important function that it executes 27 // to this output stream. It has an important function that it executes
26 // audio operations like play, pause, stop, etc. on a separate thread, 28 // audio operations like play, pause, stop, etc. on a separate thread,
27 // namely the audio manager thread. 29 // namely the audio manager thread.
28 // 30 //
29 // All the public methods of AudioOutputController are non-blocking. 31 // All the public methods of AudioOutputController are non-blocking.
30 // The actual operations are performed on the audio manager thread. 32 // The actual operations are performed on the audio manager thread.
31 // 33 //
(...skipping 18 matching lines...) Expand all
50 // all functionally equivalent and require a Play() call to continue to the next 52 // all functionally equivalent and require a Play() call to continue to the next
51 // state. 53 // state.
52 // 54 //
53 // The AudioOutputStream can request data from the AudioOutputController via the 55 // The AudioOutputStream can request data from the AudioOutputController via the
54 // AudioSourceCallback interface. AudioOutputController uses the SyncReader 56 // AudioSourceCallback interface. AudioOutputController uses the SyncReader
55 // passed to it via construction to synchronously fulfill this read request. 57 // passed to it via construction to synchronously fulfill this read request.
56 // 58 //
57 59
58 namespace media { 60 namespace media {
59 61
62 class VirtualAudioSink;
miu 2016/04/21 00:15:25 I think you intended to remove this (since it's no
qiangchen 2016/04/28 00:00:56 Done.
63
60 class MEDIA_EXPORT AudioOutputController 64 class MEDIA_EXPORT AudioOutputController
61 : public base::RefCountedThreadSafe<AudioOutputController>, 65 : public base::RefCountedThreadSafe<AudioOutputController>,
62 public AudioOutputStream::AudioSourceCallback, 66 public AudioOutputStream::AudioSourceCallback,
63 public AudioSourceDiverter, 67 public AudioSourceDiverter,
64 NON_EXPORTED_BASE(public AudioManager::AudioDeviceListener) { 68 NON_EXPORTED_BASE(public AudioManager::AudioDeviceListener) {
65 public: 69 public:
66 // An event handler that receives events from the AudioOutputController. The 70 // An event handler that receives events from the AudioOutputController. The
67 // following methods are called on the audio manager thread. 71 // following methods are called on the audio manager thread.
68 class MEDIA_EXPORT EventHandler { 72 class MEDIA_EXPORT EventHandler {
69 public: 73 public:
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 // AudioDeviceListener implementation. When called AudioOutputController will 173 // AudioDeviceListener implementation. When called AudioOutputController will
170 // shutdown the existing |stream_|, transition to the kRecreating state, 174 // shutdown the existing |stream_|, transition to the kRecreating state,
171 // create a new stream, and then transition back to an equivalent state prior 175 // create a new stream, and then transition back to an equivalent state prior
172 // to being called. 176 // to being called.
173 void OnDeviceChange() override; 177 void OnDeviceChange() override;
174 178
175 // AudioSourceDiverter implementation. 179 // AudioSourceDiverter implementation.
176 const AudioParameters& GetAudioParameters() override; 180 const AudioParameters& GetAudioParameters() override;
177 void StartDiverting(AudioOutputStream* to_stream) override; 181 void StartDiverting(AudioOutputStream* to_stream) override;
178 void StopDiverting() override; 182 void StopDiverting() override;
183 void StartDuplicating(AudioPushSink* sink) override;
184 void StopDuplicating(AudioPushSink* sink) override;
179 185
180 // Accessor for AudioPowerMonitor::ReadCurrentPowerAndClip(). See comments in 186 // Accessor for AudioPowerMonitor::ReadCurrentPowerAndClip(). See comments in
181 // audio_power_monitor.h for usage. This may be called on any thread. 187 // audio_power_monitor.h for usage. This may be called on any thread.
182 std::pair<float, bool> ReadCurrentPowerAndClip(); 188 std::pair<float, bool> ReadCurrentPowerAndClip();
183 189
184 protected: 190 protected:
185 // Internal state of the source. 191 // Internal state of the source.
186 enum State { 192 enum State {
187 kEmpty, 193 kEmpty,
188 kCreated, 194 kCreated,
(...skipping 20 matching lines...) Expand all
209 void DoCreate(bool is_for_device_change); 215 void DoCreate(bool is_for_device_change);
210 void DoPlay(); 216 void DoPlay();
211 void DoPause(); 217 void DoPause();
212 void DoClose(); 218 void DoClose();
213 void DoSetVolume(double volume); 219 void DoSetVolume(double volume);
214 std::string DoGetOutputDeviceId() const; 220 std::string DoGetOutputDeviceId() const;
215 void DoSwitchOutputDevice(const std::string& output_device_id); 221 void DoSwitchOutputDevice(const std::string& output_device_id);
216 void DoReportError(); 222 void DoReportError();
217 void DoStartDiverting(AudioOutputStream* to_stream); 223 void DoStartDiverting(AudioOutputStream* to_stream);
218 void DoStopDiverting(); 224 void DoStopDiverting();
225 void DoStartDuplicating(AudioPushSink* sink);
226 void DoStopDuplicating(AudioPushSink* sink);
219 227
220 // Helper method that stops the physical stream. 228 // Helper method that stops the physical stream.
221 void StopStream(); 229 void StopStream();
222 230
223 // Helper method that stops, closes, and NULLs |*stream_|. 231 // Helper method that stops, closes, and NULLs |*stream_|.
224 void DoStopCloseAndClearStream(); 232 void DoStopCloseAndClearStream(bool isForDeviceChange);
225 233
226 // Checks if a stream was started successfully but never calls OnMoreData(). 234 // Checks if a stream was started successfully but never calls OnMoreData().
227 void WedgeCheck(); 235 void WedgeCheck();
228 236
229 AudioManager* const audio_manager_; 237 AudioManager* const audio_manager_;
230 const AudioParameters params_; 238 const AudioParameters params_;
231 EventHandler* const handler_; 239 EventHandler* const handler_;
232 240
233 // Specifies the device id of the output device to open or empty for the 241 // Specifies the device id of the output device to open or empty for the
234 // default output device. 242 // default output device.
235 std::string output_device_id_; 243 std::string output_device_id_;
236 244
237 AudioOutputStream* stream_; 245 AudioOutputStream* stream_;
238 246
239 // When non-NULL, audio is being diverted to this stream. 247 // When non-NULL, audio is being diverted to this stream.
240 AudioOutputStream* diverting_to_stream_; 248 AudioOutputStream* diverting_to_stream_;
241 249
250 // The targets for audio stream to be copied to.
251 std::set<AudioPushSink*> duplicating_targets_;
252
242 // The current volume of the audio stream. 253 // The current volume of the audio stream.
243 double volume_; 254 double volume_;
244 255
245 // |state_| may only be used on the audio manager thread. 256 // |state_| may only be used on the audio manager thread.
246 State state_; 257 State state_;
247 258
248 // SyncReader is used only in low latency mode for synchronous reading. 259 // SyncReader is used only in low latency mode for synchronous reading.
249 SyncReader* const sync_reader_; 260 SyncReader* const sync_reader_;
250 261
251 // The message loop of audio manager thread that this object runs on. 262 // The message loop of audio manager thread that this object runs on.
(...skipping 15 matching lines...) Expand all
267 // be accessed while |error_lock_| is held. 278 // be accessed while |error_lock_| is held.
268 bool ignore_errors_during_stop_close_; 279 bool ignore_errors_during_stop_close_;
269 base::Lock error_lock_; 280 base::Lock error_lock_;
270 281
271 DISALLOW_COPY_AND_ASSIGN(AudioOutputController); 282 DISALLOW_COPY_AND_ASSIGN(AudioOutputController);
272 }; 283 };
273 284
274 } // namespace media 285 } // namespace media
275 286
276 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ 287 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698