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 <CoreAudio/AudioHardware.h> | 8 #include <CoreAudio/AudioHardware.h> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 | 54 |
55 static bool GetDefaultOutputChannels(int* channels); | 55 static bool GetDefaultOutputChannels(int* channels); |
56 | 56 |
57 static bool GetDeviceChannels(AudioDeviceID device, | 57 static bool GetDeviceChannels(AudioDeviceID device, |
58 AudioObjectPropertyScope scope, | 58 AudioObjectPropertyScope scope, |
59 int* channels); | 59 int* channels); |
60 | 60 |
61 static int HardwareSampleRateForDevice(AudioDeviceID device_id); | 61 static int HardwareSampleRateForDevice(AudioDeviceID device_id); |
62 static int HardwareSampleRate(); | 62 static int HardwareSampleRate(); |
63 | 63 |
| 64 // OSX has issues with starting streams as the sytem goes into suspend and |
| 65 // immediately after it wakes up from resume. See http://crbug.com/160920. |
| 66 // As a workaround we delay Start() when it occurs after suspend and for a |
| 67 // small amount of time after resume. |
| 68 // |
| 69 // Output streams should consult ShouldDeferOutputStreamStart() and if true |
| 70 // check the value again after |kStartDelayInSecsForPowerEvents| has elapsed. |
| 71 // If false, the stream may be started immediately. |
| 72 enum { kStartDelayInSecsForPowerEvents = 1 }; |
| 73 bool ShouldDeferOutputStreamStart(); |
| 74 |
64 protected: | 75 protected: |
65 virtual ~AudioManagerMac(); | 76 virtual ~AudioManagerMac(); |
66 | 77 |
67 virtual AudioParameters GetPreferredOutputStreamParameters( | 78 virtual AudioParameters GetPreferredOutputStreamParameters( |
68 const std::string& output_device_id, | 79 const std::string& output_device_id, |
69 const AudioParameters& input_params) OVERRIDE; | 80 const AudioParameters& input_params) OVERRIDE; |
70 | 81 |
71 private: | 82 private: |
72 bool HasUnifiedDefaultIO(); | 83 bool HasUnifiedDefaultIO(); |
73 | 84 |
74 // Helper methods for constructing AudioDeviceListenerMac on the audio thread. | 85 // Helper methods for constructing AudioDeviceListenerMac on the audio thread. |
75 void CreateDeviceListener(); | 86 void CreateDeviceListener(); |
76 void DestroyDeviceListener(); | 87 void DestroyDeviceListener(); |
77 | 88 |
78 int ChooseBufferSize(int output_sample_rate); | 89 int ChooseBufferSize(int output_sample_rate); |
79 | 90 |
80 // Notify streams of a device change if the default output device or its | 91 // Notify streams of a device change if the default output device or its |
81 // sample rate has changed, otherwise does nothing. | 92 // sample rate has changed, otherwise does nothing. |
82 void HandleDeviceChanges(); | 93 void HandleDeviceChanges(); |
83 | 94 |
84 scoped_ptr<AudioDeviceListenerMac> output_device_listener_; | 95 scoped_ptr<AudioDeviceListenerMac> output_device_listener_; |
85 | 96 |
86 // Track the output sample-rate and the default output device | 97 // Track the output sample-rate and the default output device |
87 // so we can intelligently handle device notifications only when necessary. | 98 // so we can intelligently handle device notifications only when necessary. |
88 int current_sample_rate_; | 99 int current_sample_rate_; |
89 AudioDeviceID current_output_device_; | 100 AudioDeviceID current_output_device_; |
90 | 101 |
91 AggregateDeviceManager aggregate_device_manager_; | 102 AggregateDeviceManager aggregate_device_manager_; |
92 | 103 |
| 104 // Helper class which monitors power events to determine if output streams |
| 105 // should defer Start() calls. Required to workaround an OSX bug. See |
| 106 // http://crbug.com/160920 for more details. |
| 107 class AudioPowerObserver; |
| 108 scoped_ptr<AudioPowerObserver> power_observer_; |
| 109 |
93 DISALLOW_COPY_AND_ASSIGN(AudioManagerMac); | 110 DISALLOW_COPY_AND_ASSIGN(AudioManagerMac); |
94 }; | 111 }; |
95 | 112 |
96 } // namespace media | 113 } // namespace media |
97 | 114 |
98 #endif // MEDIA_AUDIO_MAC_AUDIO_MANAGER_MAC_H_ | 115 #endif // MEDIA_AUDIO_MAC_AUDIO_MANAGER_MAC_H_ |
OLD | NEW |