OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 |
(...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
818 std::max(kTestTimeOutInMilliseconds, 1000 * kMeasureLatencyTimeInSec)); | 818 std::max(kTestTimeOutInMilliseconds, 1000 * kMeasureLatencyTimeInSec)); |
819 StopPlayout(); | 819 StopPlayout(); |
820 StopRecording(); | 820 StopRecording(); |
821 // Verify that the correct number of transmitted impulses are detected. | 821 // Verify that the correct number of transmitted impulses are detected. |
822 EXPECT_EQ(latency_audio_stream->num_latency_values(), | 822 EXPECT_EQ(latency_audio_stream->num_latency_values(), |
823 static_cast<size_t>( | 823 static_cast<size_t>( |
824 kImpulseFrequencyInHz * kMeasureLatencyTimeInSec - 1)); | 824 kImpulseFrequencyInHz * kMeasureLatencyTimeInSec - 1)); |
825 latency_audio_stream->PrintResults(); | 825 latency_audio_stream->PrintResults(); |
826 } | 826 } |
827 | 827 |
| 828 // Verifies that the AudioDeviceIOS is_interrupted_ flag is reset correctly |
| 829 // after an iOS AVAudioSessionInterruptionTypeEnded notification event. |
| 830 // AudioDeviceIOS listens to RTCAudioSession interrupted notifications by: |
| 831 // - In AudioDeviceIOS.InitPlayOrRecord registers its audio_session_observer_ |
| 832 // callback with RTCAudioSession's delegate list. |
| 833 // - When RTCAudioSession receives an iOS audio interrupted notification, it |
| 834 // passes the notification to callbacks in its delegate list which sets |
| 835 // AudioDeviceIOS's is_interrupted_ flag to true. |
| 836 // - When AudioDeviceIOS.ShutdownPlayOrRecord is called, its |
| 837 // audio_session_observer_ callback is removed from RTCAudioSessions's |
| 838 // delegate list. |
| 839 // So if RTCAudioSession receives an iOS end audio interruption notification, |
| 840 // AudioDeviceIOS is not notified as its callback is not in RTCAudioSession's |
| 841 // delegate list. This causes AudioDeviceIOS's is_interrupted_ flag to be in |
| 842 // the wrong (true) state and the audio session will ignore audio changes. |
| 843 // As RTCAudioSession keeps its own interrupted state, the fix is to initialize |
| 844 // AudioDeviceIOS's is_interrupted_ flag to RTCAudioSession's isInterrupted |
| 845 // flag in AudioDeviceIOS.InitPlayOrRecord. |
828 TEST_F(AudioDeviceTest, testInterruptedAudioSession) { | 846 TEST_F(AudioDeviceTest, testInterruptedAudioSession) { |
829 RTCAudioSession *session = [RTCAudioSession sharedInstance]; | 847 RTCAudioSession *session = [RTCAudioSession sharedInstance]; |
830 std::unique_ptr<webrtc::AudioDeviceIOS> audio_device; | 848 std::unique_ptr<webrtc::AudioDeviceIOS> audio_device; |
831 audio_device.reset(new webrtc::AudioDeviceIOS()); | 849 audio_device.reset(new webrtc::AudioDeviceIOS()); |
832 std::unique_ptr<webrtc::AudioDeviceBuffer> audio_buffer; | 850 std::unique_ptr<webrtc::AudioDeviceBuffer> audio_buffer; |
833 audio_buffer.reset(new webrtc::AudioDeviceBuffer()); | 851 audio_buffer.reset(new webrtc::AudioDeviceBuffer()); |
834 audio_device->AttachAudioBuffer(audio_buffer.get()); | 852 audio_device->AttachAudioBuffer(audio_buffer.get()); |
835 audio_device->Init(); | 853 audio_device->Init(); |
836 audio_device->InitPlayout(); | 854 audio_device->InitPlayout(); |
837 // Force interruption. | 855 // Force interruption. |
(...skipping 13 matching lines...) Expand all Loading... |
851 // Wait for notification to propagate. | 869 // Wait for notification to propagate. |
852 rtc::MessageQueueManager::ProcessAllMessageQueues(); | 870 rtc::MessageQueueManager::ProcessAllMessageQueues(); |
853 EXPECT_TRUE(audio_device->is_interrupted_); | 871 EXPECT_TRUE(audio_device->is_interrupted_); |
854 | 872 |
855 audio_device->Init(); | 873 audio_device->Init(); |
856 audio_device->InitPlayout(); | 874 audio_device->InitPlayout(); |
857 EXPECT_FALSE(audio_device->is_interrupted_); | 875 EXPECT_FALSE(audio_device->is_interrupted_); |
858 } | 876 } |
859 | 877 |
860 } // namespace webrtc | 878 } // namespace webrtc |
OLD | NEW |