| 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 | 11 |
| 12 #include <list> | 12 #include <list> |
| 13 #include <map> |
| 13 #include <memory> | 14 #include <memory> |
| 14 #include <string> | 15 #include <string> |
| 15 | 16 |
| 16 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
| 17 #include "base/macros.h" | 18 #include "base/macros.h" |
| 18 #include "media/audio/audio_manager_base.h" | 19 #include "media/audio/audio_manager_base.h" |
| 19 #include "media/audio/mac/audio_device_listener_mac.h" | 20 #include "media/audio/mac/audio_device_listener_mac.h" |
| 20 | 21 |
| 21 namespace media { | 22 namespace media { |
| 22 | 23 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 | 121 |
| 121 private: | 122 private: |
| 122 void InitializeOnAudioThread(); | 123 void InitializeOnAudioThread(); |
| 123 | 124 |
| 124 int ChooseBufferSize(bool is_input, int sample_rate); | 125 int ChooseBufferSize(bool is_input, int sample_rate); |
| 125 | 126 |
| 126 // Notify streams of a device change if the default output device or its | 127 // Notify streams of a device change if the default output device or its |
| 127 // sample rate has changed, otherwise does nothing. | 128 // sample rate has changed, otherwise does nothing. |
| 128 void HandleDeviceChanges(); | 129 void HandleDeviceChanges(); |
| 129 | 130 |
| 131 // Returns true if any active input stream is using the specified |device_id|. |
| 132 bool AudioDeviceIsUsedForInput(AudioDeviceID device_id); |
| 133 |
| 134 // This method is called when an output stream has been released and it takes |
| 135 // the given |device_id| and scans all active output streams that are |
| 136 // using this id. The goal is to find a new (larger) I/O buffer size which |
| 137 // can be applied to all active output streams since doing so will save |
| 138 // system resources. |
| 139 // Note that, it is only called if no input stream is also using the device. |
| 140 // Example: two active output streams where #1 wants 1024 as buffer size but |
| 141 // is using 256 since stream #2 wants it. Now, if stream #2 is closed down, |
| 142 // the native I/O buffer size will be increased to 1024 instead of 256. |
| 143 // Returns true if it was possible to increase the I/O buffer size and |
| 144 // false otherwise. |
| 145 // TODO(henrika): possibly extend the scheme to also take input streams into |
| 146 // account. |
| 147 bool IncreaseIOBufferSizeIfPossible(AudioDeviceID device_id); |
| 148 |
| 130 std::unique_ptr<AudioDeviceListenerMac> output_device_listener_; | 149 std::unique_ptr<AudioDeviceListenerMac> output_device_listener_; |
| 131 | 150 |
| 132 // Track the output sample-rate and the default output device | 151 // Track the output sample-rate and the default output device |
| 133 // so we can intelligently handle device notifications only when necessary. | 152 // so we can intelligently handle device notifications only when necessary. |
| 134 int current_sample_rate_; | 153 int current_sample_rate_; |
| 135 AudioDeviceID current_output_device_; | 154 AudioDeviceID current_output_device_; |
| 136 | 155 |
| 137 // Helper class which monitors power events to determine if output streams | 156 // Helper class which monitors power events to determine if output streams |
| 138 // should defer Start() calls. Required to workaround an OSX bug. See | 157 // should defer Start() calls. Required to workaround an OSX bug. See |
| 139 // http://crbug.com/160920 for more details. | 158 // http://crbug.com/160920 for more details. |
| 140 class AudioPowerObserver; | 159 class AudioPowerObserver; |
| 141 std::unique_ptr<AudioPowerObserver> power_observer_; | 160 std::unique_ptr<AudioPowerObserver> power_observer_; |
| 142 | 161 |
| 143 // Tracks all constructed input and output streams. | 162 // Tracks all constructed input and output streams. |
| 144 // TODO(alokp): We used to track these streams to close before destruction. | 163 // TODO(alokp): We used to track these streams to close before destruction. |
| 145 // We no longer close the streams, so we may be able to get rid of these | 164 // We no longer close the streams, so we may be able to get rid of these |
| 146 // member variables. They are currently used by MaybeChangeBufferSize(). | 165 // member variables. They are currently used by MaybeChangeBufferSize(). |
| 147 // Investigate if we can remove these. | 166 // Investigate if we can remove these. |
| 148 std::list<AudioInputStream*> basic_input_streams_; | 167 std::list<AudioInputStream*> basic_input_streams_; |
| 149 std::list<AUAudioInputStream*> low_latency_input_streams_; | 168 std::list<AUAudioInputStream*> low_latency_input_streams_; |
| 150 std::list<AUHALStream*> output_streams_; | 169 std::list<AUHALStream*> output_streams_; |
| 151 | 170 |
| 171 // Maps device IDs and their corresponding actual (I/O) buffer sizes for |
| 172 // all output streams using the specific device. |
| 173 std::map<AudioDeviceID, size_t> output_io_buffer_size_map_; |
| 174 |
| 152 DISALLOW_COPY_AND_ASSIGN(AudioManagerMac); | 175 DISALLOW_COPY_AND_ASSIGN(AudioManagerMac); |
| 153 }; | 176 }; |
| 154 | 177 |
| 155 } // namespace media | 178 } // namespace media |
| 156 | 179 |
| 157 #endif // MEDIA_AUDIO_MAC_AUDIO_MANAGER_MAC_H_ | 180 #endif // MEDIA_AUDIO_MAC_AUDIO_MANAGER_MAC_H_ |
| OLD | NEW |