Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / modules / audio_device / ios / audio_device_ios.cc
index bad3915..7a7189a 100644 (file)
@@ -175,15 +175,6 @@ bool AudioDeviceIPhone::Initialized() const {
     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__);
@@ -214,30 +205,6 @@ int32_t AudioDeviceIPhone::InitSpeaker() {
     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__);
@@ -1332,7 +1299,7 @@ int32_t AudioDeviceIPhone::InitPlayOrRecord() {
     // 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;
@@ -1716,7 +1683,10 @@ void AudioDeviceIPhone::UpdatePlayoutDelay() {
     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);
@@ -1727,7 +1697,8 @@ void AudioDeviceIPhone::UpdatePlayoutDelay() {
             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;
@@ -1737,7 +1708,8 @@ void AudioDeviceIPhone::UpdatePlayoutDelay() {
             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);
@@ -1748,16 +1720,17 @@ void AudioDeviceIPhone::UpdatePlayoutDelay() {
             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() {
@@ -1766,7 +1739,10 @@ 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);
@@ -1777,7 +1753,8 @@ void AudioDeviceIPhone::UpdateRecordingDelay() {
             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;
@@ -1787,7 +1764,8 @@ void AudioDeviceIPhone::UpdateRecordingDelay() {
             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);
@@ -1799,10 +1777,12 @@ void AudioDeviceIPhone::UpdateRecordingDelay() {
             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;