OLD | NEW |
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_MAC_AUDIO_MANAGER_MAC_H_ | 5 #ifndef MEDIA_AUDIO_MAC_AUDIO_MANAGER_MAC_H_ |
6 #define MEDIA_AUDIO_MAC_AUDIO_MANAGER_MAC_H_ | 6 #define MEDIA_AUDIO_MAC_AUDIO_MANAGER_MAC_H_ |
7 | 7 |
8 #include <AudioUnit/AudioUnit.h> | 8 #include <AudioUnit/AudioUnit.h> |
9 #include <CoreAudio/AudioHardware.h> | 9 #include <CoreAudio/AudioHardware.h> |
10 #include <stddef.h> | 10 #include <stddef.h> |
11 #include <list> | 11 #include <list> |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "media/audio/audio_manager_base.h" | 16 #include "media/audio/audio_manager_base.h" |
17 #include "media/audio/mac/audio_device_listener_mac.h" | 17 #include "media/audio/mac/audio_device_listener_mac.h" |
18 | 18 |
19 namespace media { | 19 namespace media { |
20 | 20 |
21 class AUAudioInputStream; | 21 class AUAudioInputStream; |
22 class AUHALStream; | 22 class AUHALStream; |
23 | 23 |
24 // Mac OS X implementation of the AudioManager singleton. This class is internal | 24 // Mac OS X implementation of the AudioManager singleton. This class is internal |
25 // to the audio output and only internal users can call methods not exposed by | 25 // to the audio output and only internal users can call methods not exposed by |
26 // the AudioManager class. | 26 // the AudioManager class. |
27 class MEDIA_EXPORT AudioManagerMac : public AudioManagerBase { | 27 class MEDIA_EXPORT AudioManagerMac : public AudioManagerBase { |
28 public: | 28 public: |
29 AudioManagerMac( | 29 AudioManagerMac(AudioLogFactory* audio_log_factory); |
30 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | |
31 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, | |
32 AudioLogFactory* audio_log_factory); | |
33 | 30 |
34 // Implementation of AudioManager. | 31 // Implementation of AudioManager. |
| 32 scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() override; |
| 33 scoped_refptr<base::SingleThreadTaskRunner> GetWorkerTaskRunner() override; |
35 bool HasAudioOutputDevices() override; | 34 bool HasAudioOutputDevices() override; |
36 bool HasAudioInputDevices() override; | 35 bool HasAudioInputDevices() override; |
37 void GetAudioInputDeviceNames(AudioDeviceNames* device_names) override; | 36 void GetAudioInputDeviceNames(AudioDeviceNames* device_names) override; |
38 void GetAudioOutputDeviceNames(AudioDeviceNames* device_names) override; | 37 void GetAudioOutputDeviceNames(AudioDeviceNames* device_names) override; |
39 AudioParameters GetInputStreamParameters( | 38 AudioParameters GetInputStreamParameters( |
40 const std::string& device_id) override; | 39 const std::string& device_id) override; |
41 std::string GetAssociatedOutputDeviceID( | 40 std::string GetAssociatedOutputDeviceID( |
42 const std::string& input_device_id) override; | 41 const std::string& input_device_id) override; |
43 | 42 |
44 // Implementation of AudioManagerBase. | 43 // Implementation of AudioManagerBase. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 | 110 |
112 protected: | 111 protected: |
113 ~AudioManagerMac() override; | 112 ~AudioManagerMac() override; |
114 | 113 |
115 AudioParameters GetPreferredOutputStreamParameters( | 114 AudioParameters GetPreferredOutputStreamParameters( |
116 const std::string& output_device_id, | 115 const std::string& output_device_id, |
117 const AudioParameters& input_params) override; | 116 const AudioParameters& input_params) override; |
118 | 117 |
119 private: | 118 private: |
120 void InitializeOnAudioThread(); | 119 void InitializeOnAudioThread(); |
| 120 void ShutdownOnAudioThread(); |
121 | 121 |
122 int ChooseBufferSize(bool is_input, int sample_rate); | 122 int ChooseBufferSize(bool is_input, int sample_rate); |
123 | 123 |
124 // Notify streams of a device change if the default output device or its | 124 // Notify streams of a device change if the default output device or its |
125 // sample rate has changed, otherwise does nothing. | 125 // sample rate has changed, otherwise does nothing. |
126 void HandleDeviceChanges(); | 126 void HandleDeviceChanges(); |
127 | 127 |
128 scoped_ptr<AudioDeviceListenerMac> output_device_listener_; | 128 scoped_ptr<AudioDeviceListenerMac> output_device_listener_; |
129 | 129 |
| 130 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 131 scoped_ptr<base::Thread> worker_thread_; |
| 132 |
130 // Track the output sample-rate and the default output device | 133 // Track the output sample-rate and the default output device |
131 // so we can intelligently handle device notifications only when necessary. | 134 // so we can intelligently handle device notifications only when necessary. |
132 int current_sample_rate_; | 135 int current_sample_rate_; |
133 AudioDeviceID current_output_device_; | 136 AudioDeviceID current_output_device_; |
134 | 137 |
135 // Helper class which monitors power events to determine if output streams | 138 // Helper class which monitors power events to determine if output streams |
136 // should defer Start() calls. Required to workaround an OSX bug. See | 139 // should defer Start() calls. Required to workaround an OSX bug. See |
137 // http://crbug.com/160920 for more details. | 140 // http://crbug.com/160920 for more details. |
138 class AudioPowerObserver; | 141 class AudioPowerObserver; |
139 scoped_ptr<AudioPowerObserver> power_observer_; | 142 scoped_ptr<AudioPowerObserver> power_observer_; |
140 | 143 |
141 // Tracks all constructed input and output streams. | 144 // Tracks all constructed input and output streams so they can be stopped at |
142 // TODO(alokp): We used to track these streams to close before destruction. | 145 // shutdown. See ShutdownOnAudioThread() for more details. |
143 // We no longer close the streams, so we may be able to get rid of these | |
144 // member variables. They are currently used by MaybeChangeBufferSize(). | |
145 // Investigate if we can remove these. | |
146 std::list<AudioInputStream*> basic_input_streams_; | 146 std::list<AudioInputStream*> basic_input_streams_; |
147 std::list<AUAudioInputStream*> low_latency_input_streams_; | 147 std::list<AUAudioInputStream*> low_latency_input_streams_; |
148 std::list<AUHALStream*> output_streams_; | 148 std::list<AUHALStream*> output_streams_; |
149 | 149 |
150 DISALLOW_COPY_AND_ASSIGN(AudioManagerMac); | 150 DISALLOW_COPY_AND_ASSIGN(AudioManagerMac); |
151 }; | 151 }; |
152 | 152 |
153 } // namespace media | 153 } // namespace media |
154 | 154 |
155 #endif // MEDIA_AUDIO_MAC_AUDIO_MANAGER_MAC_H_ | 155 #endif // MEDIA_AUDIO_MAC_AUDIO_MANAGER_MAC_H_ |
OLD | NEW |