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_receive_stream.h" | 13 #include "webrtc/audio/audio_receive_stream.h" |
14 #include "webrtc/audio/conversion.h" | 14 #include "webrtc/audio/conversion.h" |
15 #include "webrtc/modules/remote_bitrate_estimator/include/mock/mock_remote_bitra te_estimator.h" | 15 #include "webrtc/modules/remote_bitrate_estimator/include/mock/mock_remote_bitra te_estimator.h" |
16 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 16 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
17 #include "webrtc/test/mock_voe_channel_proxy.h" | |
17 #include "webrtc/test/mock_voice_engine.h" | 18 #include "webrtc/test/mock_voice_engine.h" |
18 | 19 |
19 namespace webrtc { | 20 namespace webrtc { |
20 namespace test { | 21 namespace test { |
21 namespace { | 22 namespace { |
22 | 23 |
23 using testing::_; | 24 using testing::_; |
24 using testing::Return; | 25 using testing::Return; |
25 | 26 |
26 AudioDecodingCallStats MakeAudioDecodeStatsForTest() { | 27 AudioDecodingCallStats MakeAudioDecodeStatsForTest() { |
(...skipping 19 matching lines...) Expand all Loading... | |
46 const CallStatistics kCallStats = { | 47 const CallStatistics kCallStats = { |
47 345, 678, 901, 234, -12, 3456, 7890, 567, 890, 123}; | 48 345, 678, 901, 234, -12, 3456, 7890, 567, 890, 123}; |
48 const CodecInst kCodecInst = { | 49 const CodecInst kCodecInst = { |
49 123, "codec_name_recv", 96000, -187, -198, -103}; | 50 123, "codec_name_recv", 96000, -187, -198, -103}; |
50 const NetworkStatistics kNetworkStats = { | 51 const NetworkStatistics kNetworkStats = { |
51 123, 456, false, 0, 0, 789, 12, 345, 678, 901, -1, -1, -1, -1, -1, 0}; | 52 123, 456, false, 0, 0, 789, 12, 345, 678, 901, -1, -1, -1, -1, -1, 0}; |
52 const AudioDecodingCallStats kAudioDecodeStats = MakeAudioDecodeStatsForTest(); | 53 const AudioDecodingCallStats kAudioDecodeStats = MakeAudioDecodeStatsForTest(); |
53 | 54 |
54 struct ConfigHelper { | 55 struct ConfigHelper { |
55 ConfigHelper() { | 56 ConfigHelper() { |
57 using testing::Invoke; | |
58 | |
56 EXPECT_CALL(voice_engine_, | 59 EXPECT_CALL(voice_engine_, |
57 RegisterVoiceEngineObserver(_)).WillOnce(Return(0)); | 60 RegisterVoiceEngineObserver(_)).WillOnce(Return(0)); |
58 EXPECT_CALL(voice_engine_, | 61 EXPECT_CALL(voice_engine_, |
59 DeRegisterVoiceEngineObserver()).WillOnce(Return(0)); | 62 DeRegisterVoiceEngineObserver()).WillOnce(Return(0)); |
60 AudioState::Config config; | 63 AudioState::Config config; |
61 config.voice_engine = &voice_engine_; | 64 config.voice_engine = &voice_engine_; |
62 audio_state_ = AudioState::Create(config); | 65 audio_state_ = AudioState::Create(config); |
63 | 66 |
64 EXPECT_CALL(voice_engine_, SetLocalSSRC(kChannelId, kLocalSsrc)) | 67 EXPECT_CALL(voice_engine_, GetChannelProxy(kChannelId)) |
65 .WillOnce(Return(0)); | 68 .WillOnce(Invoke(this, &ConfigHelper::CreateChannelProxy)); |
kwiberg-webrtc
2015/11/25 10:44:58
Can you do this with a lambda instead? Something l
the sun
2015/11/25 12:28:01
Great idea. I simply didn't think a lambda would w
| |
66 EXPECT_CALL(voice_engine_, | 69 EXPECT_CALL(voice_engine_, |
67 SetReceiveAbsoluteSenderTimeStatus(kChannelId, true, kAbsSendTimeId)) | 70 SetReceiveAbsoluteSenderTimeStatus(kChannelId, true, kAbsSendTimeId)) |
68 .WillOnce(Return(0)); | 71 .WillOnce(Return(0)); |
69 EXPECT_CALL(voice_engine_, | 72 EXPECT_CALL(voice_engine_, |
70 SetReceiveAudioLevelIndicationStatus(kChannelId, true, kAudioLevelId)) | 73 SetReceiveAudioLevelIndicationStatus(kChannelId, true, kAudioLevelId)) |
71 .WillOnce(Return(0)); | 74 .WillOnce(Return(0)); |
72 stream_config_.voe_channel_id = kChannelId; | 75 stream_config_.voe_channel_id = kChannelId; |
73 stream_config_.rtp.local_ssrc = kLocalSsrc; | 76 stream_config_.rtp.local_ssrc = kLocalSsrc; |
74 stream_config_.rtp.remote_ssrc = kRemoteSsrc; | 77 stream_config_.rtp.remote_ssrc = kRemoteSsrc; |
75 stream_config_.rtp.extensions.push_back( | 78 stream_config_.rtp.extensions.push_back( |
76 RtpExtension(RtpExtension::kAbsSendTime, kAbsSendTimeId)); | 79 RtpExtension(RtpExtension::kAbsSendTime, kAbsSendTimeId)); |
77 stream_config_.rtp.extensions.push_back( | 80 stream_config_.rtp.extensions.push_back( |
78 RtpExtension(RtpExtension::kAudioLevel, kAudioLevelId)); | 81 RtpExtension(RtpExtension::kAudioLevel, kAudioLevelId)); |
79 } | 82 } |
80 | 83 |
81 MockRemoteBitrateEstimator* remote_bitrate_estimator() { | 84 MockRemoteBitrateEstimator* remote_bitrate_estimator() { |
82 return &remote_bitrate_estimator_; | 85 return &remote_bitrate_estimator_; |
83 } | 86 } |
84 AudioReceiveStream::Config& config() { return stream_config_; } | 87 AudioReceiveStream::Config& config() { return stream_config_; } |
85 rtc::scoped_refptr<AudioState> audio_state() { return audio_state_; } | 88 rtc::scoped_refptr<AudioState> audio_state() { return audio_state_; } |
86 MockVoiceEngine& voice_engine() { return voice_engine_; } | 89 MockVoiceEngine& voice_engine() { return voice_engine_; } |
87 | 90 |
88 void SetupMockForGetStats() { | 91 void SetupMockForGetStats() { |
89 using testing::DoAll; | 92 using testing::DoAll; |
90 using testing::SetArgPointee; | 93 using testing::SetArgPointee; |
91 using testing::SetArgReferee; | 94 using testing::SetArgReferee; |
95 | |
92 EXPECT_CALL(voice_engine_, GetRTCPStatistics(kChannelId, _)) | 96 EXPECT_CALL(voice_engine_, GetRTCPStatistics(kChannelId, _)) |
93 .WillOnce(DoAll(SetArgReferee<1>(kCallStats), Return(0))); | 97 .WillOnce(DoAll(SetArgReferee<1>(kCallStats), Return(0))); |
94 EXPECT_CALL(voice_engine_, GetRecCodec(kChannelId, _)) | 98 EXPECT_CALL(voice_engine_, GetRecCodec(kChannelId, _)) |
95 .WillOnce(DoAll(SetArgReferee<1>(kCodecInst), Return(0))); | 99 .WillOnce(DoAll(SetArgReferee<1>(kCodecInst), Return(0))); |
96 EXPECT_CALL(voice_engine_, GetDelayEstimate(kChannelId, _, _)) | 100 EXPECT_CALL(voice_engine_, GetDelayEstimate(kChannelId, _, _)) |
97 .WillOnce(DoAll(SetArgPointee<1>(kJitterBufferDelay), | 101 .WillOnce(DoAll(SetArgPointee<1>(kJitterBufferDelay), |
98 SetArgPointee<2>(kPlayoutBufferDelay), Return(0))); | 102 SetArgPointee<2>(kPlayoutBufferDelay), Return(0))); |
99 EXPECT_CALL(voice_engine_, | 103 EXPECT_CALL(voice_engine_, |
100 GetSpeechOutputLevelFullRange(kChannelId, _)).WillOnce( | 104 GetSpeechOutputLevelFullRange(kChannelId, _)).WillOnce( |
101 DoAll(SetArgReferee<1>(kSpeechOutputLevel), Return(0))); | 105 DoAll(SetArgReferee<1>(kSpeechOutputLevel), Return(0))); |
102 EXPECT_CALL(voice_engine_, GetNetworkStatistics(kChannelId, _)) | 106 EXPECT_CALL(voice_engine_, GetNetworkStatistics(kChannelId, _)) |
103 .WillOnce(DoAll(SetArgReferee<1>(kNetworkStats), Return(0))); | 107 .WillOnce(DoAll(SetArgReferee<1>(kNetworkStats), Return(0))); |
104 EXPECT_CALL(voice_engine_, GetDecodingCallStatistics(kChannelId, _)) | 108 EXPECT_CALL(voice_engine_, GetDecodingCallStatistics(kChannelId, _)) |
105 .WillOnce(DoAll(SetArgPointee<1>(kAudioDecodeStats), Return(0))); | 109 .WillOnce(DoAll(SetArgPointee<1>(kAudioDecodeStats), Return(0))); |
106 } | 110 } |
107 | 111 |
108 private: | 112 private: |
113 voe::ChannelProxy* CreateChannelProxy(int channel_id) { | |
114 EXPECT_FALSE(channel_proxy_); | |
115 channel_proxy_ = new testing::StrictMock<MockVoEChannelProxy>(); | |
116 EXPECT_CALL(*channel_proxy_, SetLocalSSRC(kLocalSsrc)).Times(1); | |
117 return channel_proxy_; | |
118 } | |
119 | |
109 MockRemoteBitrateEstimator remote_bitrate_estimator_; | 120 MockRemoteBitrateEstimator remote_bitrate_estimator_; |
110 testing::StrictMock<MockVoiceEngine> voice_engine_; | 121 testing::StrictMock<MockVoiceEngine> voice_engine_; |
111 rtc::scoped_refptr<AudioState> audio_state_; | 122 rtc::scoped_refptr<AudioState> audio_state_; |
112 AudioReceiveStream::Config stream_config_; | 123 AudioReceiveStream::Config stream_config_; |
124 testing::StrictMock<MockVoEChannelProxy>* channel_proxy_ = nullptr; | |
113 }; | 125 }; |
114 | 126 |
115 void BuildAbsoluteSendTimeExtension(uint8_t* buffer, | 127 void BuildAbsoluteSendTimeExtension(uint8_t* buffer, |
116 int id, | 128 int id, |
117 uint32_t abs_send_time) { | 129 uint32_t abs_send_time) { |
118 const size_t kRtpOneByteHeaderLength = 4; | 130 const size_t kRtpOneByteHeaderLength = 4; |
119 const uint16_t kRtpOneByteHeaderExtensionId = 0xBEDE; | 131 const uint16_t kRtpOneByteHeaderExtensionId = 0xBEDE; |
120 ByteWriter<uint16_t>::WriteBigEndian(buffer, kRtpOneByteHeaderExtensionId); | 132 ByteWriter<uint16_t>::WriteBigEndian(buffer, kRtpOneByteHeaderExtensionId); |
121 | 133 |
122 const uint32_t kPosLength = 2; | 134 const uint32_t kPosLength = 2; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
225 EXPECT_EQ(kAudioDecodeStats.calls_to_neteq, stats.decoding_calls_to_neteq); | 237 EXPECT_EQ(kAudioDecodeStats.calls_to_neteq, stats.decoding_calls_to_neteq); |
226 EXPECT_EQ(kAudioDecodeStats.decoded_normal, stats.decoding_normal); | 238 EXPECT_EQ(kAudioDecodeStats.decoded_normal, stats.decoding_normal); |
227 EXPECT_EQ(kAudioDecodeStats.decoded_plc, stats.decoding_plc); | 239 EXPECT_EQ(kAudioDecodeStats.decoded_plc, stats.decoding_plc); |
228 EXPECT_EQ(kAudioDecodeStats.decoded_cng, stats.decoding_cng); | 240 EXPECT_EQ(kAudioDecodeStats.decoded_cng, stats.decoding_cng); |
229 EXPECT_EQ(kAudioDecodeStats.decoded_plc_cng, stats.decoding_plc_cng); | 241 EXPECT_EQ(kAudioDecodeStats.decoded_plc_cng, stats.decoding_plc_cng); |
230 EXPECT_EQ(kCallStats.capture_start_ntp_time_ms_, | 242 EXPECT_EQ(kCallStats.capture_start_ntp_time_ms_, |
231 stats.capture_start_ntp_time_ms); | 243 stats.capture_start_ntp_time_ms); |
232 } | 244 } |
233 } // namespace test | 245 } // namespace test |
234 } // namespace webrtc | 246 } // namespace webrtc |
OLD | NEW |