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 // Implementation of AudioInputStream for Mac OS X using the special AUHAL | 5 // Implementation of AudioInputStream for Mac OS X using the special AUHAL |
6 // input Audio Unit present in OS 10.4 and later. | 6 // input Audio Unit present in OS 10.4 and later. |
7 // The AUHAL input Audio Unit is for low-latency audio I/O. | 7 // The AUHAL input Audio Unit is for low-latency audio I/O. |
8 // | 8 // |
9 // Overview of operation: | 9 // Overview of operation: |
10 // | 10 // |
(...skipping 21 matching lines...) Expand all Loading... | |
32 // latency; | 32 // latency; |
33 // 2) The delay between the actual recording instant and the time when the | 33 // 2) The delay between the actual recording instant and the time when the |
34 // data packet is provided as a callback. | 34 // data packet is provided as a callback. |
35 // | 35 // |
36 #ifndef MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_INPUT_MAC_H_ | 36 #ifndef MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_INPUT_MAC_H_ |
37 #define MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_INPUT_MAC_H_ | 37 #define MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_INPUT_MAC_H_ |
38 | 38 |
39 #include <AudioUnit/AudioUnit.h> | 39 #include <AudioUnit/AudioUnit.h> |
40 #include <CoreAudio/CoreAudio.h> | 40 #include <CoreAudio/CoreAudio.h> |
41 | 41 |
42 #include "base/atomicops.h" | |
42 #include "base/cancelable_callback.h" | 43 #include "base/cancelable_callback.h" |
43 #include "base/memory/scoped_ptr.h" | 44 #include "base/memory/scoped_ptr.h" |
44 #include "base/synchronization/lock.h" | 45 #include "base/synchronization/lock.h" |
46 #include "base/threading/thread_checker.h" | |
45 #include "base/time/time.h" | 47 #include "base/time/time.h" |
48 #include "base/timer/timer.h" | |
46 #include "media/audio/agc_audio_stream.h" | 49 #include "media/audio/agc_audio_stream.h" |
47 #include "media/audio/audio_io.h" | 50 #include "media/audio/audio_io.h" |
48 #include "media/audio/audio_parameters.h" | 51 #include "media/audio/audio_parameters.h" |
49 #include "media/base/audio_block_fifo.h" | 52 #include "media/base/audio_block_fifo.h" |
50 | 53 |
51 namespace media { | 54 namespace media { |
52 | 55 |
53 class AudioBus; | 56 class AudioBus; |
54 class AudioManagerMac; | 57 class AudioManagerMac; |
55 class DataBuffer; | 58 class DataBuffer; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 // Gets the number of channels for a stream of audio data. | 110 // Gets the number of channels for a stream of audio data. |
108 int GetNumberOfChannelsFromStream(); | 111 int GetNumberOfChannelsFromStream(); |
109 | 112 |
110 // Issues the OnError() callback to the |sink_|. | 113 // Issues the OnError() callback to the |sink_|. |
111 void HandleError(OSStatus err); | 114 void HandleError(OSStatus err); |
112 | 115 |
113 // Helper function to check if the volume control is avialable on specific | 116 // Helper function to check if the volume control is avialable on specific |
114 // channel. | 117 // channel. |
115 bool IsVolumeSettableOnChannel(int channel); | 118 bool IsVolumeSettableOnChannel(int channel); |
116 | 119 |
120 // Helper methods to set and get atomic |input_callback_is_active_|. | |
121 void SetInputCallbackIsActive(bool active); | |
122 bool GetInputCallbackIsActive(); | |
123 | |
124 // Checks if a strem was started successfully and the audio unit also starts | |
tommi (sloooow) - chröme
2015/10/30 15:08:44
strem -> stream
henrika (OOO until Aug 14)
2015/10/30 15:56:35
Done.
| |
125 // to call InputProc() as it should. This method is called once when a timer | |
126 // expires 5 seconds after calling Start(). | |
127 void CheckInputStartupSuccess(); | |
128 | |
129 // Verifies that Open(), Start(), Stop() and Close() are all called on the | |
130 // creating thread which is the main browser thread (CrBrowserMain) on Mac. | |
131 base::ThreadChecker thread_checker_; | |
tommi (sloooow) - chröme
2015/10/30 15:08:44
nice
henrika (OOO until Aug 14)
2015/10/30 15:56:35
Thanks
| |
132 | |
117 // Our creator, the audio manager needs to be notified when we close. | 133 // Our creator, the audio manager needs to be notified when we close. |
118 AudioManagerMac* manager_; | 134 AudioManagerMac* const manager_; |
119 | 135 |
120 // Contains the desired number of audio frames in each callback. | 136 // Contains the desired number of audio frames in each callback. |
121 const size_t number_of_frames_; | 137 const size_t number_of_frames_; |
122 | 138 |
123 // Pointer to the object that will receive the recorded audio samples. | 139 // Pointer to the object that will receive the recorded audio samples. |
124 AudioInputCallback* sink_; | 140 AudioInputCallback* sink_; |
125 | 141 |
126 // Structure that holds the desired output format of the stream. | 142 // Structure that holds the desired output format of the stream. |
127 // Note that, this format can differ from the device(=input) format. | 143 // Note that, this format can differ from the device(=input) format. |
128 AudioStreamBasicDescription format_; | 144 AudioStreamBasicDescription format_; |
129 | 145 |
130 // The special Audio Unit called AUHAL, which allows us to pass audio data | 146 // The special Audio Unit called AUHAL, which allows us to pass audio data |
131 // directly from a microphone, through the HAL, and to our application. | 147 // directly from a microphone, through the HAL, and to our application. |
132 // The AUHAL also enables selection of non default devices. | 148 // The AUHAL also enables selection of non default devices. |
133 AudioUnit audio_unit_; | 149 AudioUnit audio_unit_; |
134 | 150 |
135 // The UID refers to the current input audio device. | 151 // The UID refers to the current input audio device. |
136 AudioDeviceID input_device_id_; | 152 const AudioDeviceID input_device_id_; |
137 | 153 |
138 // Provides a mechanism for encapsulating one or more buffers of audio data. | 154 // Provides a mechanism for encapsulating one or more buffers of audio data. |
139 AudioBufferList audio_buffer_list_; | 155 AudioBufferList audio_buffer_list_; |
140 | 156 |
141 // Temporary storage for recorded data. The InputProc() renders into this | 157 // Temporary storage for recorded data. The InputProc() renders into this |
142 // array as soon as a frame of the desired buffer size has been recorded. | 158 // array as soon as a frame of the desired buffer size has been recorded. |
143 scoped_ptr<uint8[]> audio_data_buffer_; | 159 scoped_ptr<uint8[]> audio_data_buffer_; |
144 | 160 |
145 // True after successfull Start(), false after successful Stop(). | 161 // True after successfull Start(), false after successful Stop(). |
146 bool started_; | 162 bool started_; |
(...skipping 10 matching lines...) Expand all Loading... | |
157 | 173 |
158 // Used to defer Start() to workaround http://crbug.com/160920. | 174 // Used to defer Start() to workaround http://crbug.com/160920. |
159 base::CancelableClosure deferred_start_cb_; | 175 base::CancelableClosure deferred_start_cb_; |
160 | 176 |
161 // Contains time of last successful call to AudioUnitRender(). | 177 // Contains time of last successful call to AudioUnitRender(). |
162 // Initialized first time in Start() and then updated for each valid | 178 // Initialized first time in Start() and then updated for each valid |
163 // audio buffer. Used to detect long error sequences and to take actions | 179 // audio buffer. Used to detect long error sequences and to take actions |
164 // if length of error sequence is above a certain limit. | 180 // if length of error sequence is above a certain limit. |
165 base::TimeTicks last_success_time_; | 181 base::TimeTicks last_success_time_; |
166 | 182 |
183 // Is set to true on the internal AUHAL IO thread in the first input callback | |
184 // after Start() has bee called. | |
185 base::subtle::Atomic32 input_callback_is_active_; | |
186 | |
187 // Timer which triggers CheckInputStartupSuccess() to verify that input | |
188 // callbacks have started as intended after a successful call to Start(). | |
189 // This timer lives on the main browser thread. | |
190 scoped_ptr<base::OneShotTimer> input_callback_timer_; | |
191 | |
167 DISALLOW_COPY_AND_ASSIGN(AUAudioInputStream); | 192 DISALLOW_COPY_AND_ASSIGN(AUAudioInputStream); |
168 }; | 193 }; |
169 | 194 |
170 } // namespace media | 195 } // namespace media |
171 | 196 |
172 #endif // MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_INPUT_MAC_H_ | 197 #endif // MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_INPUT_MAC_H_ |
OLD | NEW |