return (_initialized);
}
-int32_t AudioDeviceIPhone::SpeakerIsAvailable(bool& available) {
- WEBRTC_TRACE(kTraceModuleCall, kTraceAudioDevice, _id,
- "%s", __FUNCTION__);
-
- // speaker is always available in IOS
- available = true;
- return 0;
-}
-
int32_t AudioDeviceIPhone::InitSpeaker() {
WEBRTC_TRACE(kTraceModuleCall, kTraceAudioDevice, _id,
"%s", __FUNCTION__);
return 0;
}
-int32_t AudioDeviceIPhone::MicrophoneIsAvailable(bool& available) {
- WEBRTC_TRACE(kTraceModuleCall, kTraceAudioDevice, _id,
- "%s", __FUNCTION__);
-
- available = false;
-
- OSStatus result = -1;
- UInt32 channel = 0;
- UInt32 size = sizeof(channel);
- result = AudioSessionGetProperty(kAudioSessionProperty_AudioInputAvailable,
- &size, &channel);
- if (channel != 0) {
- // API is not supported on this platform, we return available = true
- WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice,
- _id, " API call not supported on this version");
- available = true;
- return 0;
- }
-
- available = (channel == 0) ? false : true;
-
- return 0;
-}
-
int32_t AudioDeviceIPhone::InitMicrophone() {
WEBRTC_TRACE(kTraceModuleCall, kTraceAudioDevice, _id,
"%s", __FUNCTION__);
// todo: Add 48 kHz (increase buffer sizes). Other fs?
if ((playoutDesc.mSampleRate > 44090.0)
&& (playoutDesc.mSampleRate < 44110.0)) {
- _adbSampFreq = 44000;
+ _adbSampFreq = 44100;
} else if ((playoutDesc.mSampleRate > 15990.0)
&& (playoutDesc.mSampleRate < 16010.0)) {
_adbSampFreq = 16000;
if (_playoutDelayMeasurementCounter >= 100) {
// Update HW and OS delay every second, unlikely to change
- _playoutDelay = 0;
+ // Since this is eventually rounded to integral ms, add 0.5ms
+ // here to get round-to-nearest-int behavior instead of
+ // truncation.
+ float totalDelaySeconds = 0.0005;
// HW output latency
Float32 f32(0);
WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id,
"error HW latency (result=%d)", result);
}
- _playoutDelay += static_cast<int>(f32 * 1000000);
+ assert(f32 >= 0);
+ totalDelaySeconds += f32;
// HW buffer duration
f32 = 0;
WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id,
"error HW buffer duration (result=%d)", result);
}
- _playoutDelay += static_cast<int>(f32 * 1000000);
+ assert(f32 >= 0);
+ totalDelaySeconds += f32;
// AU latency
Float64 f64(0);
WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id,
"error AU latency (result=%d)", result);
}
- _playoutDelay += static_cast<int>(f64 * 1000000);
+ assert(f64 >= 0);
+ totalDelaySeconds += f64;
// To ms
- _playoutDelay = (_playoutDelay - 500) / 1000;
+ _playoutDelay = static_cast<uint32_t>(totalDelaySeconds / 1000);
// Reset counter
_playoutDelayMeasurementCounter = 0;
}
- // todo: Add playout buffer? (Only used for 44.1 kHz)
+ // todo: Add playout buffer?
}
void AudioDeviceIPhone::UpdateRecordingDelay() {
if (_recordingDelayMeasurementCounter >= 100) {
// Update HW and OS delay every second, unlikely to change
- _recordingDelayHWAndOS = 0;
+ // Since this is eventually rounded to integral ms, add 0.5ms
+ // here to get round-to-nearest-int behavior instead of
+ // truncation.
+ float totalDelaySeconds = 0.0005;
// HW input latency
Float32 f32(0);
WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id,
"error HW latency (result=%d)", result);
}
- _recordingDelayHWAndOS += static_cast<int>(f32 * 1000000);
+ assert(f32 >= 0);
+ totalDelaySeconds += f32;
// HW buffer duration
f32 = 0;
WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id,
"error HW buffer duration (result=%d)", result);
}
- _recordingDelayHWAndOS += static_cast<int>(f32 * 1000000);
+ assert(f32 >= 0);
+ totalDelaySeconds += f32;
// AU latency
Float64 f64(0);
WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id,
"error AU latency (result=%d)", result);
}
- _recordingDelayHWAndOS += static_cast<int>(f64 * 1000000);
+ assert(f64 >= 0);
+ totalDelaySeconds += f64;
// To ms
- _recordingDelayHWAndOS = (_recordingDelayHWAndOS - 500) / 1000;
+ _recordingDelayHWAndOS =
+ static_cast<uint32_t>(totalDelaySeconds / 1000);
// Reset counter
_recordingDelayMeasurementCounter = 0;