| 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 |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 #include "webrtc/audio/audio_send_stream.h" | 13 #include "webrtc/audio/audio_send_stream.h" |
| 14 #include "webrtc/audio/audio_state.h" | 14 #include "webrtc/audio/audio_state.h" |
| 15 #include "webrtc/audio/conversion.h" | 15 #include "webrtc/audio/conversion.h" |
| 16 #include "webrtc/test/mock_voice_engine.h" | 16 #include "webrtc/test/mock_voice_engine.h" |
| 17 | 17 |
| 18 namespace webrtc { | 18 namespace webrtc { |
| 19 namespace test { | 19 namespace test { |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 using testing::_; |
| 23 using testing::Return; |
| 24 |
| 22 const int kChannelId = 1; | 25 const int kChannelId = 1; |
| 23 const uint32_t kSsrc = 1234; | 26 const uint32_t kSsrc = 1234; |
| 27 const char* kCName = "foo_name"; |
| 28 const int kAudioLevelId = 2; |
| 29 const int kAbsSendTimeId = 3; |
| 24 const int kEchoDelayMedian = 254; | 30 const int kEchoDelayMedian = 254; |
| 25 const int kEchoDelayStdDev = -3; | 31 const int kEchoDelayStdDev = -3; |
| 26 const int kEchoReturnLoss = -65; | 32 const int kEchoReturnLoss = -65; |
| 27 const int kEchoReturnLossEnhancement = 101; | 33 const int kEchoReturnLossEnhancement = 101; |
| 28 const unsigned int kSpeechInputLevel = 96; | 34 const unsigned int kSpeechInputLevel = 96; |
| 29 const CallStatistics kCallStats = { | 35 const CallStatistics kCallStats = { |
| 30 1345, 1678, 1901, 1234, 112, 13456, 17890, 1567, -1890, -1123}; | 36 1345, 1678, 1901, 1234, 112, 13456, 17890, 1567, -1890, -1123}; |
| 31 const CodecInst kCodecInst = {-121, "codec_name_send", 48000, -231, -451, -671}; | 37 const CodecInst kCodecInst = {-121, "codec_name_send", 48000, -231, -451, -671}; |
| 32 const ReportBlock kReportBlock = {456, 780, 123, 567, 890, 132, 143, 13354}; | 38 const ReportBlock kReportBlock = {456, 780, 123, 567, 890, 132, 143, 13354}; |
| 33 | 39 |
| 34 struct ConfigHelper { | 40 struct ConfigHelper { |
| 35 ConfigHelper() : stream_config_(nullptr) { | 41 ConfigHelper() : stream_config_(nullptr) { |
| 42 using testing::StrEq; |
| 43 |
| 36 EXPECT_CALL(voice_engine_, | 44 EXPECT_CALL(voice_engine_, |
| 37 RegisterVoiceEngineObserver(testing::_)).WillOnce(testing::Return(0)); | 45 RegisterVoiceEngineObserver(_)).WillOnce(Return(0)); |
| 38 EXPECT_CALL(voice_engine_, | 46 EXPECT_CALL(voice_engine_, |
| 39 DeRegisterVoiceEngineObserver()).WillOnce(testing::Return(0)); | 47 DeRegisterVoiceEngineObserver()).WillOnce(Return(0)); |
| 40 AudioState::Config config; | 48 AudioState::Config config; |
| 41 config.voice_engine = &voice_engine_; | 49 config.voice_engine = &voice_engine_; |
| 42 audio_state_ = AudioState::Create(config); | 50 audio_state_ = AudioState::Create(config); |
| 51 |
| 52 EXPECT_CALL(voice_engine_, SetRTCPStatus(kChannelId, true)) |
| 53 .WillOnce(Return(0)); |
| 54 EXPECT_CALL(voice_engine_, SetLocalSSRC(kChannelId, kSsrc)) |
| 55 .WillOnce(Return(0)); |
| 56 EXPECT_CALL(voice_engine_, SetRTCP_CNAME(kChannelId, StrEq(kCName))) |
| 57 .WillOnce(Return(0)); |
| 58 EXPECT_CALL(voice_engine_, |
| 59 SetSendAbsoluteSenderTimeStatus(kChannelId, true, kAbsSendTimeId)) |
| 60 .WillOnce(Return(0)); |
| 61 EXPECT_CALL(voice_engine_, |
| 62 SetSendAudioLevelIndicationStatus(kChannelId, true, kAudioLevelId)) |
| 63 .WillOnce(Return(0)); |
| 43 stream_config_.voe_channel_id = kChannelId; | 64 stream_config_.voe_channel_id = kChannelId; |
| 44 stream_config_.rtp.ssrc = kSsrc; | 65 stream_config_.rtp.ssrc = kSsrc; |
| 66 stream_config_.rtp.c_name = kCName; |
| 67 stream_config_.rtp.extensions.push_back( |
| 68 RtpExtension(RtpExtension::kAudioLevel, kAudioLevelId)); |
| 69 stream_config_.rtp.extensions.push_back( |
| 70 RtpExtension(RtpExtension::kAbsSendTime, kAbsSendTimeId)); |
| 45 } | 71 } |
| 46 | 72 |
| 47 AudioSendStream::Config& config() { return stream_config_; } | 73 AudioSendStream::Config& config() { return stream_config_; } |
| 48 rtc::scoped_refptr<AudioState> audio_state() { return audio_state_; } | 74 rtc::scoped_refptr<AudioState> audio_state() { return audio_state_; } |
| 49 | 75 |
| 50 void SetupMockForGetStats() { | 76 void SetupMockForGetStats() { |
| 77 using testing::DoAll; |
| 78 using testing::SetArgPointee; |
| 79 using testing::SetArgReferee; |
| 80 |
| 51 std::vector<ReportBlock> report_blocks; | 81 std::vector<ReportBlock> report_blocks; |
| 52 webrtc::ReportBlock block = kReportBlock; | 82 webrtc::ReportBlock block = kReportBlock; |
| 53 report_blocks.push_back(block); // Has wrong SSRC. | 83 report_blocks.push_back(block); // Has wrong SSRC. |
| 54 block.source_SSRC = kSsrc; | 84 block.source_SSRC = kSsrc; |
| 55 report_blocks.push_back(block); // Correct block. | 85 report_blocks.push_back(block); // Correct block. |
| 56 block.fraction_lost = 0; | 86 block.fraction_lost = 0; |
| 57 report_blocks.push_back(block); // Duplicate SSRC, bad fraction_lost. | 87 report_blocks.push_back(block); // Duplicate SSRC, bad fraction_lost. |
| 58 | 88 |
| 59 using testing::_; | |
| 60 using testing::DoAll; | |
| 61 using testing::Return; | |
| 62 using testing::SetArgPointee; | |
| 63 using testing::SetArgReferee; | |
| 64 EXPECT_CALL(voice_engine_, GetLocalSSRC(kChannelId, _)) | 89 EXPECT_CALL(voice_engine_, GetLocalSSRC(kChannelId, _)) |
| 65 .WillRepeatedly(DoAll(SetArgReferee<1>(0), Return(0))); | 90 .WillRepeatedly(DoAll(SetArgReferee<1>(0), Return(0))); |
| 66 EXPECT_CALL(voice_engine_, GetRTCPStatistics(kChannelId, _)) | 91 EXPECT_CALL(voice_engine_, GetRTCPStatistics(kChannelId, _)) |
| 67 .WillRepeatedly(DoAll(SetArgReferee<1>(kCallStats), Return(0))); | 92 .WillRepeatedly(DoAll(SetArgReferee<1>(kCallStats), Return(0))); |
| 68 EXPECT_CALL(voice_engine_, GetSendCodec(kChannelId, _)) | 93 EXPECT_CALL(voice_engine_, GetSendCodec(kChannelId, _)) |
| 69 .WillRepeatedly(DoAll(SetArgReferee<1>(kCodecInst), Return(0))); | 94 .WillRepeatedly(DoAll(SetArgReferee<1>(kCodecInst), Return(0))); |
| 70 EXPECT_CALL(voice_engine_, GetRemoteRTCPReportBlocks(kChannelId, _)) | 95 EXPECT_CALL(voice_engine_, GetRemoteRTCPReportBlocks(kChannelId, _)) |
| 71 .WillRepeatedly(DoAll(SetArgPointee<1>(report_blocks), Return(0))); | 96 .WillRepeatedly(DoAll(SetArgPointee<1>(report_blocks), Return(0))); |
| 72 EXPECT_CALL(voice_engine_, GetSpeechInputLevelFullRange(_)) | 97 EXPECT_CALL(voice_engine_, GetSpeechInputLevelFullRange(_)) |
| 73 .WillRepeatedly(DoAll(SetArgReferee<0>(kSpeechInputLevel), Return(0))); | 98 .WillRepeatedly(DoAll(SetArgReferee<0>(kSpeechInputLevel), Return(0))); |
| 74 EXPECT_CALL(voice_engine_, GetEcMetricsStatus(_)) | 99 EXPECT_CALL(voice_engine_, GetEcMetricsStatus(_)) |
| 75 .WillRepeatedly(DoAll(SetArgReferee<0>(true), Return(0))); | 100 .WillRepeatedly(DoAll(SetArgReferee<0>(true), Return(0))); |
| 76 EXPECT_CALL(voice_engine_, GetEchoMetrics(_, _, _, _)) | 101 EXPECT_CALL(voice_engine_, GetEchoMetrics(_, _, _, _)) |
| 77 .WillRepeatedly(DoAll(SetArgReferee<0>(kEchoReturnLoss), | 102 .WillRepeatedly(DoAll(SetArgReferee<0>(kEchoReturnLoss), |
| 78 SetArgReferee<1>(kEchoReturnLossEnhancement), | 103 SetArgReferee<1>(kEchoReturnLossEnhancement), |
| 79 Return(0))); | 104 Return(0))); |
| 80 EXPECT_CALL(voice_engine_, GetEcDelayMetrics(_, _, _)) | 105 EXPECT_CALL(voice_engine_, GetEcDelayMetrics(_, _, _)) |
| 81 .WillRepeatedly(DoAll(SetArgReferee<0>(kEchoDelayMedian), | 106 .WillRepeatedly(DoAll(SetArgReferee<0>(kEchoDelayMedian), |
| 82 SetArgReferee<1>(kEchoDelayStdDev), Return(0))); | 107 SetArgReferee<1>(kEchoDelayStdDev), Return(0))); |
| 83 } | 108 } |
| 84 | 109 |
| 85 private: | 110 private: |
| 86 MockVoiceEngine voice_engine_; | 111 testing::StrictMock<MockVoiceEngine> voice_engine_; |
| 87 rtc::scoped_refptr<AudioState> audio_state_; | 112 rtc::scoped_refptr<AudioState> audio_state_; |
| 88 AudioSendStream::Config stream_config_; | 113 AudioSendStream::Config stream_config_; |
| 89 }; | 114 }; |
| 90 } // namespace | 115 } // namespace |
| 91 | 116 |
| 92 TEST(AudioSendStreamTest, ConfigToString) { | 117 TEST(AudioSendStreamTest, ConfigToString) { |
| 93 const int kAbsSendTimeId = 3; | |
| 94 AudioSendStream::Config config(nullptr); | 118 AudioSendStream::Config config(nullptr); |
| 95 config.rtp.ssrc = kSsrc; | 119 config.rtp.ssrc = kSsrc; |
| 96 config.rtp.extensions.push_back( | 120 config.rtp.extensions.push_back( |
| 97 RtpExtension(RtpExtension::kAbsSendTime, kAbsSendTimeId)); | 121 RtpExtension(RtpExtension::kAbsSendTime, kAbsSendTimeId)); |
| 122 config.rtp.c_name = kCName; |
| 98 config.voe_channel_id = kChannelId; | 123 config.voe_channel_id = kChannelId; |
| 99 config.cng_payload_type = 42; | 124 config.cng_payload_type = 42; |
| 100 config.red_payload_type = 17; | 125 config.red_payload_type = 17; |
| 101 EXPECT_EQ( | 126 EXPECT_EQ( |
| 102 "{rtp: {ssrc: 1234, extensions: [{name: " | 127 "{rtp: {ssrc: 1234, extensions: [{name: " |
| 103 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time, id: 3}]}, " | 128 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time, id: 3}], " |
| 104 "voe_channel_id: 1, cng_payload_type: 42, red_payload_type: 17}", | 129 "c_name: foo_name}, voe_channel_id: 1, cng_payload_type: 42, " |
| 130 "red_payload_type: 17}", |
| 105 config.ToString()); | 131 config.ToString()); |
| 106 } | 132 } |
| 107 | 133 |
| 108 TEST(AudioSendStreamTest, ConstructDestruct) { | 134 TEST(AudioSendStreamTest, ConstructDestruct) { |
| 109 ConfigHelper helper; | 135 ConfigHelper helper; |
| 110 internal::AudioSendStream send_stream(helper.config(), helper.audio_state()); | 136 internal::AudioSendStream send_stream(helper.config(), helper.audio_state()); |
| 111 } | 137 } |
| 112 | 138 |
| 113 TEST(AudioSendStreamTest, GetStats) { | 139 TEST(AudioSendStreamTest, GetStats) { |
| 114 ConfigHelper helper; | 140 ConfigHelper helper; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 static_cast<internal::AudioState*>(helper.audio_state().get()); | 173 static_cast<internal::AudioState*>(helper.audio_state().get()); |
| 148 VoiceEngineObserver* voe_observer = | 174 VoiceEngineObserver* voe_observer = |
| 149 static_cast<VoiceEngineObserver*>(internal_audio_state); | 175 static_cast<VoiceEngineObserver*>(internal_audio_state); |
| 150 voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_WARNING); | 176 voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_WARNING); |
| 151 EXPECT_TRUE(send_stream.GetStats().typing_noise_detected); | 177 EXPECT_TRUE(send_stream.GetStats().typing_noise_detected); |
| 152 voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_OFF_WARNING); | 178 voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_OFF_WARNING); |
| 153 EXPECT_FALSE(send_stream.GetStats().typing_noise_detected); | 179 EXPECT_FALSE(send_stream.GetStats().typing_noise_detected); |
| 154 } | 180 } |
| 155 } // namespace test | 181 } // namespace test |
| 156 } // namespace webrtc | 182 } // namespace webrtc |
| OLD | NEW |