| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 const std::string& device_id) override; | 55 const std::string& device_id) override; |
| 55 AudioInputStream* MakeLowLatencyInputStream( | 56 AudioInputStream* MakeLowLatencyInputStream( |
| 56 const AudioParameters& params, | 57 const AudioParameters& params, |
| 57 const std::string& device_id) override; | 58 const std::string& device_id) override; |
| 58 std::string GetDefaultOutputDeviceID() override; | 59 std::string GetDefaultOutputDeviceID() override; |
| 59 | 60 |
| 60 // Used to track destruction of input and output streams. | 61 // Used to track destruction of input and output streams. |
| 61 void ReleaseOutputStream(AudioOutputStream* stream) override; | 62 void ReleaseOutputStream(AudioOutputStream* stream) override; |
| 62 void ReleaseInputStream(AudioInputStream* stream) override; | 63 void ReleaseInputStream(AudioInputStream* stream) override; |
| 63 | 64 |
| 65 // Called by AUHALStream::Close() before releasing the stream. |
| 66 // This method is a special contract between the real stream and the audio |
| 67 // manager and it ensures that we only try to increase the IO buffer size |
| 68 // for real streams and not for fake or mocked streams. |
| 69 void ReleaseOutputStreamUsingRealDevice(AudioOutputStream* stream, |
| 70 AudioDeviceID device_id); |
| 71 |
| 64 static bool GetDeviceChannels(AudioDeviceID device, | 72 static bool GetDeviceChannels(AudioDeviceID device, |
| 65 AudioObjectPropertyScope scope, | 73 AudioObjectPropertyScope scope, |
| 66 int* channels); | 74 int* channels); |
| 67 | 75 |
| 68 static int HardwareSampleRateForDevice(AudioDeviceID device_id); | 76 static int HardwareSampleRateForDevice(AudioDeviceID device_id); |
| 69 static int HardwareSampleRate(); | 77 static int HardwareSampleRate(); |
| 70 | 78 |
| 71 // OSX has issues with starting streams as the system goes into suspend and | 79 // OSX has issues with starting streams as the system goes into suspend and |
| 72 // immediately after it wakes up from resume. See http://crbug.com/160920. | 80 // immediately after it wakes up from resume. See http://crbug.com/160920. |
| 73 // As a workaround we delay Start() when it occurs after suspend and for a | 81 // As a workaround we delay Start() when it occurs after suspend and for a |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 | 128 |
| 121 private: | 129 private: |
| 122 void InitializeOnAudioThread(); | 130 void InitializeOnAudioThread(); |
| 123 | 131 |
| 124 int ChooseBufferSize(bool is_input, int sample_rate); | 132 int ChooseBufferSize(bool is_input, int sample_rate); |
| 125 | 133 |
| 126 // Notify streams of a device change if the default output device or its | 134 // Notify streams of a device change if the default output device or its |
| 127 // sample rate has changed, otherwise does nothing. | 135 // sample rate has changed, otherwise does nothing. |
| 128 void HandleDeviceChanges(); | 136 void HandleDeviceChanges(); |
| 129 | 137 |
| 138 // Returns true if any active input stream is using the specified |device_id|. |
| 139 bool AudioDeviceIsUsedForInput(AudioDeviceID device_id); |
| 140 |
| 141 // This method is called when an output stream has been released and it takes |
| 142 // the given |device_id| and scans all active output streams that are |
| 143 // using this id. The goal is to find a new (larger) I/O buffer size which |
| 144 // can be applied to all active output streams since doing so will save |
| 145 // system resources. |
| 146 // Note that, it is only called if no input stream is also using the device. |
| 147 // Example: two active output streams where #1 wants 1024 as buffer size but |
| 148 // is using 256 since stream #2 wants it. Now, if stream #2 is closed down, |
| 149 // the native I/O buffer size will be increased to 1024 instead of 256. |
| 150 // Returns true if it was possible to increase the I/O buffer size and |
| 151 // false otherwise. |
| 152 // TODO(henrika): possibly extend the scheme to also take input streams into |
| 153 // account. |
| 154 bool IncreaseIOBufferSizeIfPossible(AudioDeviceID device_id); |
| 155 |
| 130 std::unique_ptr<AudioDeviceListenerMac> output_device_listener_; | 156 std::unique_ptr<AudioDeviceListenerMac> output_device_listener_; |
| 131 | 157 |
| 132 // Track the output sample-rate and the default output device | 158 // Track the output sample-rate and the default output device |
| 133 // so we can intelligently handle device notifications only when necessary. | 159 // so we can intelligently handle device notifications only when necessary. |
| 134 int current_sample_rate_; | 160 int current_sample_rate_; |
| 135 AudioDeviceID current_output_device_; | 161 AudioDeviceID current_output_device_; |
| 136 | 162 |
| 137 // Helper class which monitors power events to determine if output streams | 163 // Helper class which monitors power events to determine if output streams |
| 138 // should defer Start() calls. Required to workaround an OSX bug. See | 164 // should defer Start() calls. Required to workaround an OSX bug. See |
| 139 // http://crbug.com/160920 for more details. | 165 // http://crbug.com/160920 for more details. |
| 140 class AudioPowerObserver; | 166 class AudioPowerObserver; |
| 141 std::unique_ptr<AudioPowerObserver> power_observer_; | 167 std::unique_ptr<AudioPowerObserver> power_observer_; |
| 142 | 168 |
| 143 // Tracks all constructed input and output streams. | 169 // Tracks all constructed input and output streams. |
| 144 // TODO(alokp): We used to track these streams to close before destruction. | 170 // 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 | 171 // 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(). | 172 // member variables. They are currently used by MaybeChangeBufferSize(). |
| 147 // Investigate if we can remove these. | 173 // Investigate if we can remove these. |
| 148 std::list<AudioInputStream*> basic_input_streams_; | 174 std::list<AudioInputStream*> basic_input_streams_; |
| 149 std::list<AUAudioInputStream*> low_latency_input_streams_; | 175 std::list<AUAudioInputStream*> low_latency_input_streams_; |
| 150 std::list<AUHALStream*> output_streams_; | 176 std::list<AUHALStream*> output_streams_; |
| 151 | 177 |
| 178 // Maps device IDs and their corresponding actual (I/O) buffer sizes for |
| 179 // all output streams using the specific device. |
| 180 std::map<AudioDeviceID, size_t> output_io_buffer_size_map_; |
| 181 |
| 152 DISALLOW_COPY_AND_ASSIGN(AudioManagerMac); | 182 DISALLOW_COPY_AND_ASSIGN(AudioManagerMac); |
| 153 }; | 183 }; |
| 154 | 184 |
| 155 } // namespace media | 185 } // namespace media |
| 156 | 186 |
| 157 #endif // MEDIA_AUDIO_MAC_AUDIO_MANAGER_MAC_H_ | 187 #endif // MEDIA_AUDIO_MAC_AUDIO_MANAGER_MAC_H_ |
| OLD | NEW |