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

Side by Side Diff: webrtc/modules/audio_device/ios/audio_device_ios.h

Issue 1206783002: Cleanup of iOS AudioDevice implementation (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebased Created 5 years, 5 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 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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/base/thread_checker.h"
16 #include "webrtc/modules/audio_device/audio_device_generic.h" 17 #include "webrtc/modules/audio_device/audio_device_generic.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 AudioDeviceGeneric {
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 72
112 // Microphone mute control 73 // These methods are currently not implemented on iOS.
113 virtual int32_t MicrophoneMuteIsAvailable(bool& available); 74 // See audio_device_not_implemented_ios.mm for dummy implementations.
114 virtual int32_t SetMicrophoneMute(bool enable);
115 virtual int32_t MicrophoneMute(bool& enabled) const;
116 75
117 // Speaker mute control 76 int32_t ActiveAudioLayer(AudioDeviceModule::AudioLayer& audioLayer) const;
118 virtual int32_t SpeakerMuteIsAvailable(bool& available); 77 int32_t ResetAudioDevice() override;
119 virtual int32_t SetSpeakerMute(bool enable); 78 int32_t PlayoutIsAvailable(bool& available) override;
120 virtual int32_t SpeakerMute(bool& enabled) const; 79 int32_t RecordingIsAvailable(bool& available) override;
121 80 int32_t SetAGC(bool enable) override;
122 // Microphone boost control 81 bool AGC() const override;
123 virtual int32_t MicrophoneBoostIsAvailable(bool& available); 82 int16_t PlayoutDevices() override;
124 virtual int32_t SetMicrophoneBoost(bool enable); 83 int16_t RecordingDevices() override;
125 virtual int32_t MicrophoneBoost(bool& enabled) const; 84 int32_t PlayoutDeviceName(uint16_t index,
126 85 char name[kAdmMaxDeviceNameSize],
127 // Stereo support 86 char guid[kAdmMaxGuidSize]) override;
128 virtual int32_t StereoPlayoutIsAvailable(bool& available); 87 int32_t RecordingDeviceName(uint16_t index,
129 virtual int32_t SetStereoPlayout(bool enable); 88 char name[kAdmMaxDeviceNameSize],
130 virtual int32_t StereoPlayout(bool& enabled) const; 89 char guid[kAdmMaxGuidSize]) override;
131 virtual int32_t StereoRecordingIsAvailable(bool& available); 90 int32_t SetPlayoutDevice(uint16_t index) override;
132 virtual int32_t SetStereoRecording(bool enable); 91 int32_t SetPlayoutDevice(
133 virtual int32_t StereoRecording(bool& enabled) const; 92 AudioDeviceModule::WindowsDeviceType device) override;
134 93 int32_t SetRecordingDevice(uint16_t index) override;
135 // Delay information and control 94 int32_t SetRecordingDevice(
136 virtual int32_t SetPlayoutBuffer(const AudioDeviceModule::BufferType type, 95 AudioDeviceModule::WindowsDeviceType device) override;
137 uint16_t sizeMS); 96 int32_t SetWaveOutVolume(uint16_t volumeLeft, uint16_t volumeRight) override;
138 virtual int32_t PlayoutBuffer(AudioDeviceModule::BufferType& type, 97 int32_t WaveOutVolume(uint16_t& volumeLeft,
139 uint16_t& sizeMS) const; 98 uint16_t& volumeRight) const override;
140 virtual int32_t PlayoutDelay(uint16_t& delayMS) const; 99 int32_t InitSpeaker() override;
141 virtual int32_t RecordingDelay(uint16_t& delayMS) const; 100 bool SpeakerIsInitialized() const override;
142 101 int32_t InitMicrophone() override;
143 // CPU load 102 bool MicrophoneIsInitialized() const override;
144 virtual int32_t CPULoad(uint16_t& load) const; 103 int32_t SpeakerVolumeIsAvailable(bool& available) override;
145 104 int32_t SetSpeakerVolume(uint32_t volume) override;
146 public: 105 int32_t SpeakerVolume(uint32_t& volume) const override;
147 virtual bool PlayoutWarning() const; 106 int32_t MaxSpeakerVolume(uint32_t& maxVolume) const override;
148 virtual bool PlayoutError() const; 107 int32_t MinSpeakerVolume(uint32_t& minVolume) const override;
149 virtual bool RecordingWarning() const; 108 int32_t SpeakerVolumeStepSize(uint16_t& stepSize) const override;
150 virtual bool RecordingError() const; 109 int32_t MicrophoneVolumeIsAvailable(bool& available) override;
151 virtual void ClearPlayoutWarning(); 110 int32_t SetMicrophoneVolume(uint32_t volume) override;
152 virtual void ClearPlayoutError(); 111 int32_t MicrophoneVolume(uint32_t& volume) const override;
153 virtual void ClearRecordingWarning(); 112 int32_t MaxMicrophoneVolume(uint32_t& maxVolume) const override;
154 virtual void ClearRecordingError(); 113 int32_t MinMicrophoneVolume(uint32_t& minVolume) const override;
155 114 int32_t MicrophoneVolumeStepSize(uint16_t& stepSize) const override;
156 public: 115 int32_t MicrophoneMuteIsAvailable(bool& available) override;
157 virtual void AttachAudioBuffer(AudioDeviceBuffer* audioBuffer); 116 int32_t SetMicrophoneMute(bool enable) override;
158 117 int32_t MicrophoneMute(bool& enabled) const override;
159 // Reset Audio Device (for mobile devices only) 118 int32_t SpeakerMuteIsAvailable(bool& available) override;
160 virtual int32_t ResetAudioDevice(); 119 int32_t SetSpeakerMute(bool enable) override;
161 120 int32_t SpeakerMute(bool& enabled) const override;
162 // enable or disable loud speaker (for iphone only) 121 int32_t MicrophoneBoostIsAvailable(bool& available) override;
163 virtual int32_t SetLoudspeakerStatus(bool enable); 122 int32_t SetMicrophoneBoost(bool enable) override;
164 virtual int32_t GetLoudspeakerStatus(bool& enabled) const; 123 int32_t MicrophoneBoost(bool& enabled) const override;
124 int32_t StereoPlayoutIsAvailable(bool& available) override;
125 int32_t SetStereoPlayout(bool enable) override;
126 int32_t StereoPlayout(bool& enabled) const override;
127 int32_t StereoRecordingIsAvailable(bool& available) override;
128 int32_t SetStereoRecording(bool enable) override;
129 int32_t StereoRecording(bool& enabled) const override;
130 int32_t SetPlayoutBuffer(const AudioDeviceModule::BufferType type,
131 uint16_t sizeMS) override;
132 int32_t CPULoad(uint16_t& load) const override;
133 bool PlayoutWarning() const override;
134 bool PlayoutError() const override;
135 bool RecordingWarning() const override;
136 bool RecordingError() const override;
137 void ClearPlayoutWarning() override{};
138 void ClearPlayoutError() override{};
139 void ClearRecordingWarning() override{};
140 void ClearRecordingError() override{};
165 141
166 private: 142 private:
143 // TODO(henrika): try to remove these.
167 void Lock() { 144 void Lock() {
168 _critSect.Enter(); 145 _critSect.Enter();
169 } 146 }
170 147
171 void UnLock() { 148 void UnLock() {
172 _critSect.Leave(); 149 _critSect.Leave();
173 } 150 }
174 151
175 int32_t Id() {
176 return _id;
177 }
178
179 // Init and shutdown 152 // Init and shutdown
180 int32_t InitPlayOrRecord(); 153 int32_t InitPlayOrRecord();
181 int32_t ShutdownPlayOrRecord(); 154 int32_t ShutdownPlayOrRecord();
182 155
183 void UpdateRecordingDelay(); 156 void UpdateRecordingDelay();
184 void UpdatePlayoutDelay(); 157 void UpdatePlayoutDelay();
185 158
186 static OSStatus RecordProcess(void *inRefCon, 159 static OSStatus RecordProcess(void *inRefCon,
187 AudioUnitRenderActionFlags *ioActionFlags, 160 AudioUnitRenderActionFlags *ioActionFlags,
188 const AudioTimeStamp *timeStamp, 161 const AudioTimeStamp *timeStamp,
(...skipping 13 matching lines...) Expand all
202 uint32_t inBusNumber, 175 uint32_t inBusNumber,
203 uint32_t inNumberFrames); 176 uint32_t inNumberFrames);
204 177
205 OSStatus PlayoutProcessImpl(uint32_t inNumberFrames, 178 OSStatus PlayoutProcessImpl(uint32_t inNumberFrames,
206 AudioBufferList *ioData); 179 AudioBufferList *ioData);
207 180
208 static bool RunCapture(void* ptrThis); 181 static bool RunCapture(void* ptrThis);
209 bool CaptureWorkerThread(); 182 bool CaptureWorkerThread();
210 183
211 private: 184 private:
212 AudioDeviceBuffer* _ptrAudioBuffer; 185 rtc::ThreadChecker thread_checker_;
186
187 // Raw pointer handle provided to us in AttachAudioBuffer(). Owned by the
188 // AudioDeviceModuleImpl class and called by AudioDeviceModuleImpl::Create().
189 // The AudioDeviceBuffer is a member of the AudioDeviceModuleImpl instance
190 // and therefore outlives this object.
191 AudioDeviceBuffer* audio_device_buffer_;
213 192
214 CriticalSectionWrapper& _critSect; 193 CriticalSectionWrapper& _critSect;
215 194
195 AudioParameters playout_parameters_;
196 AudioParameters record_parameters_;
197
216 rtc::scoped_ptr<ThreadWrapper> _captureWorkerThread; 198 rtc::scoped_ptr<ThreadWrapper> _captureWorkerThread;
217 199
218 int32_t _id;
219
220 AudioUnit _auVoiceProcessing; 200 AudioUnit _auVoiceProcessing;
221 void* _audioInterruptionObserver; 201 void* _audioInterruptionObserver;
222 202
223 private:
224 bool _initialized; 203 bool _initialized;
225 bool _isShutDown; 204 bool _isShutDown;
226 bool _recording; 205 bool _recording;
227 bool _playing; 206 bool _playing;
228 bool _recIsInitialized; 207 bool _recIsInitialized;
229 bool _playIsInitialized; 208 bool _playIsInitialized;
230 209
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 210 // The sampling rate to use with Audio Device Buffer
239 uint32_t _adbSampFreq; 211 int _adbSampFreq;
240 212
241 // Delay calculation 213 // Delay calculation
242 uint32_t _recordingDelay; 214 uint32_t _recordingDelay;
243 uint32_t _playoutDelay; 215 uint32_t _playoutDelay;
244 uint32_t _playoutDelayMeasurementCounter; 216 uint32_t _playoutDelayMeasurementCounter;
245 uint32_t _recordingDelayHWAndOS; 217 uint32_t _recordingDelayHWAndOS;
246 uint32_t _recordingDelayMeasurementCounter; 218 uint32_t _recordingDelayMeasurementCounter;
247 219
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 220 // Playout buffer, needed for 44.0 / 44.1 kHz mismatch
255 int16_t _playoutBuffer[ENGINE_PLAY_BUF_SIZE_IN_SAMPLES]; 221 int16_t _playoutBuffer[ENGINE_PLAY_BUF_SIZE_IN_SAMPLES];
256 uint32_t _playoutBufferUsed; // How much is filled 222 uint32_t _playoutBufferUsed; // How much is filled
257 223
258 // Recording buffers 224 // Recording buffers
259 int16_t _recordingBuffer[N_REC_BUFFERS][ENGINE_REC_BUF_SIZE_IN_SAMPLES]; 225 int16_t _recordingBuffer[N_REC_BUFFERS][ENGINE_REC_BUF_SIZE_IN_SAMPLES];
260 uint32_t _recordingLength[N_REC_BUFFERS]; 226 uint32_t _recordingLength[N_REC_BUFFERS];
261 uint32_t _recordingSeqNumber[N_REC_BUFFERS]; 227 uint32_t _recordingSeqNumber[N_REC_BUFFERS];
262 uint32_t _recordingCurrentSeq; 228 uint32_t _recordingCurrentSeq;
263 229
264 // Current total size all data in buffers, used for delay estimate 230 // Current total size all data in buffers, used for delay estimate
265 uint32_t _recordingBufferTotalSize; 231 uint32_t _recordingBufferTotalSize;
266 }; 232 };
267 233
268 } // namespace webrtc 234 } // namespace webrtc
269 235
270 #endif // WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_IOS_H 236 #endif // WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_IOS_H
OLDNEW
« no previous file with comments | « webrtc/modules/audio_device/include/audio_device_defines.h ('k') | webrtc/modules/audio_device/ios/audio_device_ios.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698