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

Side by Side Diff: media/audio/mac/audio_manager_mac.h

Issue 1903753002: Restores larger output buffer size when output stream requiring smaller size is closed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit 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_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>
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 bool* size_was_changed, 104 bool* size_was_changed,
105 size_t* io_buffer_frame_size); 105 size_t* io_buffer_frame_size);
106 106
107 // Number of constructed output and input streams. 107 // Number of constructed output and input streams.
108 size_t output_streams() const { return output_streams_.size(); } 108 size_t output_streams() const { return output_streams_.size(); }
109 size_t low_latency_input_streams() const { 109 size_t low_latency_input_streams() const {
110 return low_latency_input_streams_.size(); 110 return low_latency_input_streams_.size();
111 } 111 }
112 size_t basic_input_streams() const { return basic_input_streams_.size(); } 112 size_t basic_input_streams() const { return basic_input_streams_.size(); }
113 113
114 #if !defined(NDEBUG)
115 // Prints a list of all existing output streams and there current buffer size
116 // state (required and actual). Does nothing in Release builds.
117 void PrintOutputBufferSizes();
118 #endif // !defined(NDEBUG)
119
114 protected: 120 protected:
115 ~AudioManagerMac() override; 121 ~AudioManagerMac() override;
116 122
117 AudioParameters GetPreferredOutputStreamParameters( 123 AudioParameters GetPreferredOutputStreamParameters(
118 const std::string& output_device_id, 124 const std::string& output_device_id,
119 const AudioParameters& input_params) override; 125 const AudioParameters& input_params) override;
120 126
121 private: 127 private:
122 void InitializeOnAudioThread(); 128 void InitializeOnAudioThread();
123 129
124 int ChooseBufferSize(bool is_input, int sample_rate); 130 int ChooseBufferSize(bool is_input, int sample_rate);
125 131
126 // Notify streams of a device change if the default output device or its 132 // Notify streams of a device change if the default output device or its
127 // sample rate has changed, otherwise does nothing. 133 // sample rate has changed, otherwise does nothing.
128 void HandleDeviceChanges(); 134 void HandleDeviceChanges();
129 135
136 // Returns true if any active input stream is using the specified |device_id|.
137 bool AudioDeviceIsUsedForInput(AudioDeviceID device_id);
138
139 // This method is called when an output stream has been released and it takes
140 // the given |device_id| and scans all active output streams that are
141 // using this id. The goal is to find a new (larger) I/O buffer size which
142 // can be applied to all active output streams since doing so will save
143 // system resources.
144 // Note that, it is only called if no input stream is also using the device.
145 // Example: two active output streams where #1 wants 1024 as buffer size but
146 // is using 256 since stream #2 wants it. Now, if stream #2 is closed down,
147 // the native I/O buffer size will be increased to 1024 instead of 256.
148 // TODO(henrika): possibly extend the scheme to also take input streams into
149 // account.
150 bool IncreaseIOBufferSizeIfPossible(AudioDeviceID device_id);
151
130 std::unique_ptr<AudioDeviceListenerMac> output_device_listener_; 152 std::unique_ptr<AudioDeviceListenerMac> output_device_listener_;
131 153
132 // Track the output sample-rate and the default output device 154 // Track the output sample-rate and the default output device
133 // so we can intelligently handle device notifications only when necessary. 155 // so we can intelligently handle device notifications only when necessary.
134 int current_sample_rate_; 156 int current_sample_rate_;
135 AudioDeviceID current_output_device_; 157 AudioDeviceID current_output_device_;
136 158
137 // Helper class which monitors power events to determine if output streams 159 // Helper class which monitors power events to determine if output streams
138 // should defer Start() calls. Required to workaround an OSX bug. See 160 // should defer Start() calls. Required to workaround an OSX bug. See
139 // http://crbug.com/160920 for more details. 161 // http://crbug.com/160920 for more details.
140 class AudioPowerObserver; 162 class AudioPowerObserver;
141 std::unique_ptr<AudioPowerObserver> power_observer_; 163 std::unique_ptr<AudioPowerObserver> power_observer_;
142 164
143 // Tracks all constructed input and output streams. 165 // Tracks all constructed input and output streams.
144 // TODO(alokp): We used to track these streams to close before destruction. 166 // 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 167 // 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(). 168 // member variables. They are currently used by MaybeChangeBufferSize().
147 // Investigate if we can remove these. 169 // Investigate if we can remove these.
148 std::list<AudioInputStream*> basic_input_streams_; 170 std::list<AudioInputStream*> basic_input_streams_;
149 std::list<AUAudioInputStream*> low_latency_input_streams_; 171 std::list<AUAudioInputStream*> low_latency_input_streams_;
150 std::list<AUHALStream*> output_streams_; 172 std::list<AUHALStream*> output_streams_;
151 173
152 DISALLOW_COPY_AND_ASSIGN(AudioManagerMac); 174 DISALLOW_COPY_AND_ASSIGN(AudioManagerMac);
153 }; 175 };
154 176
155 } // namespace media 177 } // namespace media
156 178
157 #endif // MEDIA_AUDIO_MAC_AUDIO_MANAGER_MAC_H_ 179 #endif // MEDIA_AUDIO_MAC_AUDIO_MANAGER_MAC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698