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

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: rebased Created 4 years, 7 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>
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
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.
Henrik Grunell 2016/04/29 10:05:01 Explain what is returned.
henrika (OOO until Aug 14) 2016/04/29 12:08:27 Done.
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 // TODO(henrika): possibly extend the scheme to also take input streams into
144 // account.
145 bool IncreaseIOBufferSizeIfPossible(AudioDeviceID device_id);
146
130 std::unique_ptr<AudioDeviceListenerMac> output_device_listener_; 147 std::unique_ptr<AudioDeviceListenerMac> output_device_listener_;
131 148
132 // Track the output sample-rate and the default output device 149 // Track the output sample-rate and the default output device
133 // so we can intelligently handle device notifications only when necessary. 150 // so we can intelligently handle device notifications only when necessary.
134 int current_sample_rate_; 151 int current_sample_rate_;
135 AudioDeviceID current_output_device_; 152 AudioDeviceID current_output_device_;
136 153
137 // Helper class which monitors power events to determine if output streams 154 // Helper class which monitors power events to determine if output streams
138 // should defer Start() calls. Required to workaround an OSX bug. See 155 // should defer Start() calls. Required to workaround an OSX bug. See
139 // http://crbug.com/160920 for more details. 156 // http://crbug.com/160920 for more details.
140 class AudioPowerObserver; 157 class AudioPowerObserver;
141 std::unique_ptr<AudioPowerObserver> power_observer_; 158 std::unique_ptr<AudioPowerObserver> power_observer_;
142 159
143 // Tracks all constructed input and output streams. 160 // Tracks all constructed input and output streams.
144 // TODO(alokp): We used to track these streams to close before destruction. 161 // 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 162 // 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(). 163 // member variables. They are currently used by MaybeChangeBufferSize().
147 // Investigate if we can remove these. 164 // Investigate if we can remove these.
148 std::list<AudioInputStream*> basic_input_streams_; 165 std::list<AudioInputStream*> basic_input_streams_;
149 std::list<AUAudioInputStream*> low_latency_input_streams_; 166 std::list<AUAudioInputStream*> low_latency_input_streams_;
150 std::list<AUHALStream*> output_streams_; 167 std::list<AUHALStream*> output_streams_;
151 168
169 // Maps device IDs and their corresponding actual (I/O) buffer sizes for
170 // all output streams using the specific device.
171 std::map<AudioDeviceID, size_t> output_io_buffer_size_map_;
172
152 DISALLOW_COPY_AND_ASSIGN(AudioManagerMac); 173 DISALLOW_COPY_AND_ASSIGN(AudioManagerMac);
153 }; 174 };
154 175
155 } // namespace media 176 } // namespace media
156 177
157 #endif // MEDIA_AUDIO_MAC_AUDIO_MANAGER_MAC_H_ 178 #endif // MEDIA_AUDIO_MAC_AUDIO_MANAGER_MAC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698