Chromium Code Reviews| 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 <map> | |
|
o1ka
2016/04/22 12:24:24
move to .cc?
henrika (OOO until Aug 14)
2016/04/25 13:54:14
Used a map as member first. Then forgot to remove.
| |
| 12 #include <string> | 13 #include <string> |
| 13 | 14 |
| 14 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 15 #include "base/macros.h" | 16 #include "base/macros.h" |
| 16 #include "media/audio/audio_manager_base.h" | 17 #include "media/audio/audio_manager_base.h" |
| 17 #include "media/audio/mac/audio_device_listener_mac.h" | 18 #include "media/audio/mac/audio_device_listener_mac.h" |
| 18 | 19 |
| 19 namespace media { | 20 namespace media { |
| 20 | 21 |
| 21 class AUAudioInputStream; | 22 class AUAudioInputStream; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 bool* size_was_changed, | 103 bool* size_was_changed, |
| 103 size_t* io_buffer_frame_size); | 104 size_t* io_buffer_frame_size); |
| 104 | 105 |
| 105 // Number of constructed output and input streams. | 106 // Number of constructed output and input streams. |
| 106 size_t output_streams() const { return output_streams_.size(); } | 107 size_t output_streams() const { return output_streams_.size(); } |
| 107 size_t low_latency_input_streams() const { | 108 size_t low_latency_input_streams() const { |
| 108 return low_latency_input_streams_.size(); | 109 return low_latency_input_streams_.size(); |
| 109 } | 110 } |
| 110 size_t basic_input_streams() const { return basic_input_streams_.size(); } | 111 size_t basic_input_streams() const { return basic_input_streams_.size(); } |
| 111 | 112 |
| 113 #if !defined(NDEBUG) | |
| 114 // Prints a list of all existing output streams and there current buffer size | |
| 115 // state (required and actual). Does nothing in Release builds. | |
| 116 void PrintOutputBufferSizes(); | |
| 117 #endif // !defined(NDEBUG) | |
| 118 | |
| 119 // This method is called when an output stream has been released and it takes | |
| 120 // the given |device_id| and scans all active output streams that are | |
| 121 // using this id. The goal is to find a new (larger) I/O buffer size which | |
| 122 // can be applied to all active output streams since doing so will save | |
| 123 // system resources. | |
| 124 // Note that, it is only called if no input stream is also using the device. | |
| 125 // Example: two active output streams where #1 wants 1024 as buffer size but | |
| 126 // is using 256 since stream #2 wants it. Now, if stream #2 is closed down, | |
| 127 // the native I/O buffer size will be increased to 1024 instead of 256. | |
| 128 // TODO(henrika): possibly extend the scheme to also take input streams into | |
| 129 // account. | |
| 130 bool IncreaseIOBufferSizeIfPossible(AudioDeviceID device_id); | |
|
o1ka
2016/04/22 12:24:24
Protected?
henrika (OOO until Aug 14)
2016/04/25 13:54:14
My bad. Now even private.
| |
| 131 | |
| 112 protected: | 132 protected: |
| 113 ~AudioManagerMac() override; | 133 ~AudioManagerMac() override; |
| 114 | 134 |
| 115 AudioParameters GetPreferredOutputStreamParameters( | 135 AudioParameters GetPreferredOutputStreamParameters( |
| 116 const std::string& output_device_id, | 136 const std::string& output_device_id, |
| 117 const AudioParameters& input_params) override; | 137 const AudioParameters& input_params) override; |
| 118 | 138 |
| 119 private: | 139 private: |
| 120 void InitializeOnAudioThread(); | 140 void InitializeOnAudioThread(); |
| 121 | 141 |
| 122 int ChooseBufferSize(bool is_input, int sample_rate); | 142 int ChooseBufferSize(bool is_input, int sample_rate); |
| 123 | 143 |
| 124 // Notify streams of a device change if the default output device or its | 144 // Notify streams of a device change if the default output device or its |
| 125 // sample rate has changed, otherwise does nothing. | 145 // sample rate has changed, otherwise does nothing. |
| 126 void HandleDeviceChanges(); | 146 void HandleDeviceChanges(); |
| 127 | 147 |
| 148 // Returns true if any active input stream is using the specified |device_id|. | |
| 149 bool AudioDeviceIsUsedForInput(AudioDeviceID device_id); | |
| 150 | |
| 128 scoped_ptr<AudioDeviceListenerMac> output_device_listener_; | 151 scoped_ptr<AudioDeviceListenerMac> output_device_listener_; |
| 129 | 152 |
| 130 // Track the output sample-rate and the default output device | 153 // Track the output sample-rate and the default output device |
| 131 // so we can intelligently handle device notifications only when necessary. | 154 // so we can intelligently handle device notifications only when necessary. |
| 132 int current_sample_rate_; | 155 int current_sample_rate_; |
| 133 AudioDeviceID current_output_device_; | 156 AudioDeviceID current_output_device_; |
| 134 | 157 |
| 135 // Helper class which monitors power events to determine if output streams | 158 // Helper class which monitors power events to determine if output streams |
| 136 // should defer Start() calls. Required to workaround an OSX bug. See | 159 // should defer Start() calls. Required to workaround an OSX bug. See |
| 137 // http://crbug.com/160920 for more details. | 160 // http://crbug.com/160920 for more details. |
| 138 class AudioPowerObserver; | 161 class AudioPowerObserver; |
| 139 scoped_ptr<AudioPowerObserver> power_observer_; | 162 scoped_ptr<AudioPowerObserver> power_observer_; |
| 140 | 163 |
| 141 // Tracks all constructed input and output streams. | 164 // Tracks all constructed input and output streams. |
| 142 // TODO(alokp): We used to track these streams to close before destruction. | 165 // TODO(alokp): We used to track these streams to close before destruction. |
| 143 // We no longer close the streams, so we may be able to get rid of these | 166 // 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(). | 167 // member variables. They are currently used by MaybeChangeBufferSize(). |
| 145 // Investigate if we can remove these. | 168 // Investigate if we can remove these. |
| 146 std::list<AudioInputStream*> basic_input_streams_; | 169 std::list<AudioInputStream*> basic_input_streams_; |
| 147 std::list<AUAudioInputStream*> low_latency_input_streams_; | 170 std::list<AUAudioInputStream*> low_latency_input_streams_; |
| 148 std::list<AUHALStream*> output_streams_; | 171 std::list<AUHALStream*> output_streams_; |
| 149 | 172 |
| 150 DISALLOW_COPY_AND_ASSIGN(AudioManagerMac); | 173 DISALLOW_COPY_AND_ASSIGN(AudioManagerMac); |
| 151 }; | 174 }; |
| 152 | 175 |
| 153 } // namespace media | 176 } // namespace media |
| 154 | 177 |
| 155 #endif // MEDIA_AUDIO_MAC_AUDIO_MANAGER_MAC_H_ | 178 #endif // MEDIA_AUDIO_MAC_AUDIO_MANAGER_MAC_H_ |
| OLD | NEW |