OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
tkchin_webrtc
2015/07/06 03:46:28
I don't think that copyright years are supposed to
henrika_webrtc
2015/07/07 16:01:38
Fine, thanks ;-)
| |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_IOS_H | 11 #ifndef WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_IOS_H |
12 #define WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_IOS_H | 12 #define WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_IOS_H |
13 | 13 |
14 #include <AudioUnit/AudioUnit.h> | 14 #include <AudioUnit/AudioUnit.h> |
15 | 15 |
16 #include "webrtc/modules/audio_device/audio_device_generic.h" | 16 #include "webrtc/base/thread_checker.h" |
17 #include "webrtc/modules/audio_device/ios/audio_device_not_implemented_ios.h" | |
17 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" | 18 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
18 #include "webrtc/system_wrappers/interface/thread_wrapper.h" | 19 #include "webrtc/system_wrappers/interface/thread_wrapper.h" |
19 | 20 |
20 namespace webrtc { | 21 namespace webrtc { |
21 const uint32_t N_REC_SAMPLES_PER_SEC = 44000; | 22 const uint32_t N_REC_SAMPLES_PER_SEC = 44100; |
22 const uint32_t N_PLAY_SAMPLES_PER_SEC = 44000; | 23 const uint32_t N_PLAY_SAMPLES_PER_SEC = 44100; |
23 | |
24 const uint32_t N_REC_CHANNELS = 1; // default is mono recording | |
25 const uint32_t N_PLAY_CHANNELS = 1; // default is mono playout | |
26 const uint32_t N_DEVICE_CHANNELS = 8; | |
27 | 24 |
28 const uint32_t ENGINE_REC_BUF_SIZE_IN_SAMPLES = (N_REC_SAMPLES_PER_SEC / 100); | 25 const uint32_t ENGINE_REC_BUF_SIZE_IN_SAMPLES = (N_REC_SAMPLES_PER_SEC / 100); |
29 const uint32_t ENGINE_PLAY_BUF_SIZE_IN_SAMPLES = (N_PLAY_SAMPLES_PER_SEC / 100); | 26 const uint32_t ENGINE_PLAY_BUF_SIZE_IN_SAMPLES = (N_PLAY_SAMPLES_PER_SEC / 100); |
30 | 27 |
31 // Number of 10 ms recording blocks in recording buffer | 28 // Number of 10 ms recording blocks in recording buffer |
32 const uint16_t N_REC_BUFFERS = 20; | 29 const uint16_t N_REC_BUFFERS = 20; |
33 | 30 |
34 class AudioDeviceIOS : public AudioDeviceGeneric { | 31 class AudioDeviceIOS : public AudioDeviceNotImplementedIOS { |
35 public: | 32 public: |
36 AudioDeviceIOS(const int32_t id); | 33 AudioDeviceIOS(); |
37 ~AudioDeviceIOS(); | 34 ~AudioDeviceIOS(); |
38 | 35 |
39 // Retrieve the currently utilized audio layer | 36 void AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) override; |
40 virtual int32_t ActiveAudioLayer( | |
41 AudioDeviceModule::AudioLayer& audioLayer) const; | |
42 | 37 |
43 // Main initializaton and termination | 38 int32_t Init() override; |
44 virtual int32_t Init(); | 39 int32_t Terminate() override; |
45 virtual int32_t Terminate(); | 40 bool Initialized() const override { return _initialized; } |
46 virtual bool Initialized() const; | |
47 | 41 |
48 // Device enumeration | 42 int32_t InitPlayout() override; |
49 virtual int16_t PlayoutDevices(); | 43 bool PlayoutIsInitialized() const override { return _playIsInitialized; } |
50 virtual int16_t RecordingDevices(); | |
51 virtual int32_t PlayoutDeviceName(uint16_t index, | |
52 char name[kAdmMaxDeviceNameSize], | |
53 char guid[kAdmMaxGuidSize]); | |
54 virtual int32_t RecordingDeviceName(uint16_t index, | |
55 char name[kAdmMaxDeviceNameSize], | |
56 char guid[kAdmMaxGuidSize]); | |
57 | 44 |
58 // Device selection | 45 int32_t InitRecording() override; |
59 virtual int32_t SetPlayoutDevice(uint16_t index); | 46 bool RecordingIsInitialized() const override { return _recIsInitialized; } |
60 virtual int32_t SetPlayoutDevice(AudioDeviceModule::WindowsDeviceType device); | |
61 virtual int32_t SetRecordingDevice(uint16_t index); | |
62 virtual int32_t SetRecordingDevice( | |
63 AudioDeviceModule::WindowsDeviceType device); | |
64 | 47 |
65 // Audio transport initialization | 48 int32_t StartPlayout() override; |
66 virtual int32_t PlayoutIsAvailable(bool& available); | 49 int32_t StopPlayout() override; |
67 virtual int32_t InitPlayout(); | 50 bool Playing() const override { return _playing; } |
68 virtual bool PlayoutIsInitialized() const; | |
69 virtual int32_t RecordingIsAvailable(bool& available); | |
70 virtual int32_t InitRecording(); | |
71 virtual bool RecordingIsInitialized() const; | |
72 | 51 |
73 // Audio transport control | 52 int32_t StartRecording() override; |
74 virtual int32_t StartPlayout(); | 53 int32_t StopRecording() override; |
75 virtual int32_t StopPlayout(); | 54 bool Recording() const override { return _recording; } |
76 virtual bool Playing() const; | |
77 virtual int32_t StartRecording(); | |
78 virtual int32_t StopRecording(); | |
79 virtual bool Recording() const; | |
80 | 55 |
81 // Microphone Automatic Gain Control (AGC) | 56 int32_t SetLoudspeakerStatus(bool enable) override; |
82 virtual int32_t SetAGC(bool enable); | 57 int32_t GetLoudspeakerStatus(bool& enabled) const override; |
83 virtual bool AGC() const; | |
84 | 58 |
85 // Volume control based on the Windows Wave API (Windows only) | 59 // TODO(henrika): investigate if we can reduce the complexity here. |
86 virtual int32_t SetWaveOutVolume(uint16_t volumeLeft, uint16_t volumeRight); | 60 // Do we even need delay estimates? |
87 virtual int32_t WaveOutVolume(uint16_t& volumeLeft, | 61 int32_t PlayoutDelay(uint16_t& delayMS) const override; |
88 uint16_t& volumeRight) const; | 62 int32_t RecordingDelay(uint16_t& delayMS) const override; |
89 | 63 |
90 // Audio mixer initialization | 64 int32_t PlayoutBuffer(AudioDeviceModule::BufferType& type, |
91 virtual int32_t InitSpeaker(); | 65 uint16_t& sizeMS) const override; |
92 virtual bool SpeakerIsInitialized() const; | |
93 virtual int32_t InitMicrophone(); | |
94 virtual bool MicrophoneIsInitialized() const; | |
95 | 66 |
96 // Speaker volume controls | 67 // These methods are unique for the iOS implementation. |
97 virtual int32_t SpeakerVolumeIsAvailable(bool& available); | |
98 virtual int32_t SetSpeakerVolume(uint32_t volume); | |
99 virtual int32_t SpeakerVolume(uint32_t& volume) const; | |
100 virtual int32_t MaxSpeakerVolume(uint32_t& maxVolume) const; | |
101 virtual int32_t MinSpeakerVolume(uint32_t& minVolume) const; | |
102 virtual int32_t SpeakerVolumeStepSize(uint16_t& stepSize) const; | |
103 | 68 |
104 // Microphone volume controls | 69 // Native audio parameters stored during construction. |
105 virtual int32_t MicrophoneVolumeIsAvailable(bool& available); | 70 int GetPlayoutAudioParameters(AudioParameters* params) const override; |
106 virtual int32_t SetMicrophoneVolume(uint32_t volume); | 71 int GetRecordAudioParameters(AudioParameters* params) const override; |
107 virtual int32_t MicrophoneVolume(uint32_t& volume) const; | |
108 virtual int32_t MaxMicrophoneVolume(uint32_t& maxVolume) const; | |
109 virtual int32_t MinMicrophoneVolume(uint32_t& minVolume) const; | |
110 virtual int32_t MicrophoneVolumeStepSize(uint16_t& stepSize) const; | |
111 | |
112 // Microphone mute control | |
113 virtual int32_t MicrophoneMuteIsAvailable(bool& available); | |
114 virtual int32_t SetMicrophoneMute(bool enable); | |
115 virtual int32_t MicrophoneMute(bool& enabled) const; | |
116 | |
117 // Speaker mute control | |
118 virtual int32_t SpeakerMuteIsAvailable(bool& available); | |
119 virtual int32_t SetSpeakerMute(bool enable); | |
120 virtual int32_t SpeakerMute(bool& enabled) const; | |
121 | |
122 // Microphone boost control | |
123 virtual int32_t MicrophoneBoostIsAvailable(bool& available); | |
124 virtual int32_t SetMicrophoneBoost(bool enable); | |
125 virtual int32_t MicrophoneBoost(bool& enabled) const; | |
126 | |
127 // Stereo support | |
128 virtual int32_t StereoPlayoutIsAvailable(bool& available); | |
129 virtual int32_t SetStereoPlayout(bool enable); | |
130 virtual int32_t StereoPlayout(bool& enabled) const; | |
131 virtual int32_t StereoRecordingIsAvailable(bool& available); | |
132 virtual int32_t SetStereoRecording(bool enable); | |
133 virtual int32_t StereoRecording(bool& enabled) const; | |
134 | |
135 // Delay information and control | |
136 virtual int32_t SetPlayoutBuffer(const AudioDeviceModule::BufferType type, | |
137 uint16_t sizeMS); | |
138 virtual int32_t PlayoutBuffer(AudioDeviceModule::BufferType& type, | |
139 uint16_t& sizeMS) const; | |
140 virtual int32_t PlayoutDelay(uint16_t& delayMS) const; | |
141 virtual int32_t RecordingDelay(uint16_t& delayMS) const; | |
142 | |
143 // CPU load | |
144 virtual int32_t CPULoad(uint16_t& load) const; | |
145 | |
146 public: | |
147 virtual bool PlayoutWarning() const; | |
148 virtual bool PlayoutError() const; | |
149 virtual bool RecordingWarning() const; | |
150 virtual bool RecordingError() const; | |
151 virtual void ClearPlayoutWarning(); | |
152 virtual void ClearPlayoutError(); | |
153 virtual void ClearRecordingWarning(); | |
154 virtual void ClearRecordingError(); | |
155 | |
156 public: | |
157 virtual void AttachAudioBuffer(AudioDeviceBuffer* audioBuffer); | |
158 | |
159 // Reset Audio Device (for mobile devices only) | |
160 virtual int32_t ResetAudioDevice(); | |
161 | |
162 // enable or disable loud speaker (for iphone only) | |
163 virtual int32_t SetLoudspeakerStatus(bool enable); | |
164 virtual int32_t GetLoudspeakerStatus(bool& enabled) const; | |
165 | 72 |
166 private: | 73 private: |
74 // TODO(henrika): try to remove these. | |
167 void Lock() { | 75 void Lock() { |
168 _critSect.Enter(); | 76 _critSect.Enter(); |
169 } | 77 } |
170 | 78 |
171 void UnLock() { | 79 void UnLock() { |
172 _critSect.Leave(); | 80 _critSect.Leave(); |
173 } | 81 } |
174 | 82 |
175 int32_t Id() { | |
176 return _id; | |
177 } | |
178 | |
179 // Init and shutdown | 83 // Init and shutdown |
180 int32_t InitPlayOrRecord(); | 84 int32_t InitPlayOrRecord(); |
181 int32_t ShutdownPlayOrRecord(); | 85 int32_t ShutdownPlayOrRecord(); |
182 | 86 |
183 void UpdateRecordingDelay(); | 87 void UpdateRecordingDelay(); |
184 void UpdatePlayoutDelay(); | 88 void UpdatePlayoutDelay(); |
185 | 89 |
186 static OSStatus RecordProcess(void *inRefCon, | 90 static OSStatus RecordProcess(void *inRefCon, |
187 AudioUnitRenderActionFlags *ioActionFlags, | 91 AudioUnitRenderActionFlags *ioActionFlags, |
188 const AudioTimeStamp *timeStamp, | 92 const AudioTimeStamp *timeStamp, |
(...skipping 13 matching lines...) Expand all Loading... | |
202 uint32_t inBusNumber, | 106 uint32_t inBusNumber, |
203 uint32_t inNumberFrames); | 107 uint32_t inNumberFrames); |
204 | 108 |
205 OSStatus PlayoutProcessImpl(uint32_t inNumberFrames, | 109 OSStatus PlayoutProcessImpl(uint32_t inNumberFrames, |
206 AudioBufferList *ioData); | 110 AudioBufferList *ioData); |
207 | 111 |
208 static bool RunCapture(void* ptrThis); | 112 static bool RunCapture(void* ptrThis); |
209 bool CaptureWorkerThread(); | 113 bool CaptureWorkerThread(); |
210 | 114 |
211 private: | 115 private: |
212 AudioDeviceBuffer* _ptrAudioBuffer; | 116 rtc::ThreadChecker thread_checker_; |
117 | |
118 // Raw pointer handle provided to us in AttachAudioBuffer(). Owned by the | |
119 // AudioDeviceModuleImpl class and called by AudioDeviceModuleImpl::Create(). | |
120 // The AudioDeviceBuffer is a member of the AudioDeviceModuleImpl instance | |
121 // and therefore outlives this object. | |
122 AudioDeviceBuffer* audio_device_buffer_; | |
213 | 123 |
214 CriticalSectionWrapper& _critSect; | 124 CriticalSectionWrapper& _critSect; |
215 | 125 |
126 AudioParameters playout_parameters_; | |
127 AudioParameters record_parameters_; | |
128 | |
216 rtc::scoped_ptr<ThreadWrapper> _captureWorkerThread; | 129 rtc::scoped_ptr<ThreadWrapper> _captureWorkerThread; |
217 | 130 |
218 int32_t _id; | |
219 | |
220 AudioUnit _auVoiceProcessing; | 131 AudioUnit _auVoiceProcessing; |
221 void* _audioInterruptionObserver; | 132 void* _audioInterruptionObserver; |
222 | 133 |
223 private: | |
224 bool _initialized; | 134 bool _initialized; |
225 bool _isShutDown; | 135 bool _isShutDown; |
226 bool _recording; | 136 bool _recording; |
227 bool _playing; | 137 bool _playing; |
228 bool _recIsInitialized; | 138 bool _recIsInitialized; |
229 bool _playIsInitialized; | 139 bool _playIsInitialized; |
230 | 140 |
231 bool _recordingDeviceIsSpecified; | |
232 bool _playoutDeviceIsSpecified; | |
233 bool _micIsInitialized; | |
234 bool _speakerIsInitialized; | |
235 | |
236 bool _AGC; | |
237 | |
238 // The sampling rate to use with Audio Device Buffer | 141 // The sampling rate to use with Audio Device Buffer |
239 uint32_t _adbSampFreq; | 142 int _adbSampFreq; |
240 | 143 |
241 // Delay calculation | 144 // Delay calculation |
242 uint32_t _recordingDelay; | 145 uint32_t _recordingDelay; |
243 uint32_t _playoutDelay; | 146 uint32_t _playoutDelay; |
244 uint32_t _playoutDelayMeasurementCounter; | 147 uint32_t _playoutDelayMeasurementCounter; |
245 uint32_t _recordingDelayHWAndOS; | 148 uint32_t _recordingDelayHWAndOS; |
246 uint32_t _recordingDelayMeasurementCounter; | 149 uint32_t _recordingDelayMeasurementCounter; |
247 | 150 |
248 // Errors and warnings count | |
249 uint16_t _playWarning; | |
250 uint16_t _playError; | |
251 uint16_t _recWarning; | |
252 uint16_t _recError; | |
253 | |
254 // Playout buffer, needed for 44.0 / 44.1 kHz mismatch | 151 // Playout buffer, needed for 44.0 / 44.1 kHz mismatch |
255 int16_t _playoutBuffer[ENGINE_PLAY_BUF_SIZE_IN_SAMPLES]; | 152 int16_t _playoutBuffer[ENGINE_PLAY_BUF_SIZE_IN_SAMPLES]; |
256 uint32_t _playoutBufferUsed; // How much is filled | 153 uint32_t _playoutBufferUsed; // How much is filled |
257 | 154 |
258 // Recording buffers | 155 // Recording buffers |
259 int16_t _recordingBuffer[N_REC_BUFFERS][ENGINE_REC_BUF_SIZE_IN_SAMPLES]; | 156 int16_t _recordingBuffer[N_REC_BUFFERS][ENGINE_REC_BUF_SIZE_IN_SAMPLES]; |
260 uint32_t _recordingLength[N_REC_BUFFERS]; | 157 uint32_t _recordingLength[N_REC_BUFFERS]; |
261 uint32_t _recordingSeqNumber[N_REC_BUFFERS]; | 158 uint32_t _recordingSeqNumber[N_REC_BUFFERS]; |
262 uint32_t _recordingCurrentSeq; | 159 uint32_t _recordingCurrentSeq; |
263 | 160 |
264 // Current total size all data in buffers, used for delay estimate | 161 // Current total size all data in buffers, used for delay estimate |
265 uint32_t _recordingBufferTotalSize; | 162 uint32_t _recordingBufferTotalSize; |
266 }; | 163 }; |
267 | 164 |
268 } // namespace webrtc | 165 } // namespace webrtc |
269 | 166 |
270 #endif // WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_IOS_H | 167 #endif // WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_IOS_H |
OLD | NEW |