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_voice_engine.h" | 17 #include "webrtc/test/mock_voice_engine.h" |
18 | 18 |
19 namespace webrtc { | 19 namespace webrtc { |
20 namespace test { | 20 namespace test { |
21 namespace { | 21 namespace { |
22 | 22 |
| 23 AudioDecodingCallStats MakeAudioDecodeStatsForTest() { |
| 24 AudioDecodingCallStats audio_decode_stats; |
| 25 audio_decode_stats.calls_to_silence_generator = 234; |
| 26 audio_decode_stats.calls_to_neteq = 567; |
| 27 audio_decode_stats.decoded_normal = 890; |
| 28 audio_decode_stats.decoded_plc = 123; |
| 29 audio_decode_stats.decoded_cng = 456; |
| 30 audio_decode_stats.decoded_plc_cng = 789; |
| 31 return audio_decode_stats; |
| 32 } |
| 33 |
23 const int kChannelId = 2; | 34 const int kChannelId = 2; |
24 const uint32_t kRemoteSsrc = 1234; | 35 const uint32_t kRemoteSsrc = 1234; |
25 const uint32_t kLocalSsrc = 5678; | 36 const uint32_t kLocalSsrc = 5678; |
26 const size_t kAbsoluteSendTimeLength = 4; | 37 const size_t kAbsoluteSendTimeLength = 4; |
| 38 const int kAbsSendTimeId = 3; |
| 39 const int kJitterBufferDelay = -7; |
| 40 const int kPlayoutBufferDelay = 302; |
| 41 const unsigned int kSpeechOutputLevel = 99; |
| 42 const CallStatistics kCallStats = { |
| 43 345, 678, 901, 234, -12, 3456, 7890, 567, 890, 123}; |
| 44 const CodecInst kCodecInst = { |
| 45 123, "codec_name_recv", 96000, -187, -198, -103}; |
| 46 const NetworkStatistics kNetworkStats = { |
| 47 123, 456, false, 0, 0, 789, 12, 345, 678, 901, -1, -1, -1, -1, -1, 0}; |
| 48 const AudioDecodingCallStats kAudioDecodeStats = MakeAudioDecodeStatsForTest(); |
| 49 |
| 50 struct ConfigHelper { |
| 51 ConfigHelper() { |
| 52 EXPECT_CALL(voice_engine_, |
| 53 RegisterVoiceEngineObserver(testing::_)).WillOnce(testing::Return(0)); |
| 54 EXPECT_CALL(voice_engine_, |
| 55 DeRegisterVoiceEngineObserver()).WillOnce(testing::Return(0)); |
| 56 AudioState::Config config; |
| 57 config.voice_engine = &voice_engine_; |
| 58 audio_state_ = AudioState::Create(config); |
| 59 stream_config_.voe_channel_id = kChannelId; |
| 60 stream_config_.rtp.local_ssrc = kLocalSsrc; |
| 61 stream_config_.rtp.remote_ssrc = kRemoteSsrc; |
| 62 } |
| 63 |
| 64 MockRemoteBitrateEstimator* remote_bitrate_estimator() { |
| 65 return &remote_bitrate_estimator_; |
| 66 } |
| 67 AudioReceiveStream::Config& config() { return stream_config_; } |
| 68 rtc::scoped_refptr<AudioState> audio_state() { return audio_state_; } |
| 69 MockVoiceEngine& voice_engine() { return voice_engine_; } |
| 70 |
| 71 void SetupMockForGetStats() { |
| 72 using testing::_; |
| 73 using testing::DoAll; |
| 74 using testing::Return; |
| 75 using testing::SetArgPointee; |
| 76 using testing::SetArgReferee; |
| 77 EXPECT_CALL(voice_engine_, GetRemoteSSRC(kChannelId, _)) |
| 78 .WillOnce(DoAll(SetArgReferee<1>(0), Return(0))); |
| 79 EXPECT_CALL(voice_engine_, GetRTCPStatistics(kChannelId, _)) |
| 80 .WillOnce(DoAll(SetArgReferee<1>(kCallStats), Return(0))); |
| 81 EXPECT_CALL(voice_engine_, GetRecCodec(kChannelId, _)) |
| 82 .WillOnce(DoAll(SetArgReferee<1>(kCodecInst), Return(0))); |
| 83 EXPECT_CALL(voice_engine_, GetDelayEstimate(kChannelId, _, _)) |
| 84 .WillOnce(DoAll(SetArgPointee<1>(kJitterBufferDelay), |
| 85 SetArgPointee<2>(kPlayoutBufferDelay), Return(0))); |
| 86 EXPECT_CALL(voice_engine_, |
| 87 GetSpeechOutputLevelFullRange(kChannelId, _)).WillOnce( |
| 88 DoAll(SetArgReferee<1>(kSpeechOutputLevel), Return(0))); |
| 89 EXPECT_CALL(voice_engine_, GetNetworkStatistics(kChannelId, _)) |
| 90 .WillOnce(DoAll(SetArgReferee<1>(kNetworkStats), Return(0))); |
| 91 EXPECT_CALL(voice_engine_, GetDecodingCallStatistics(kChannelId, _)) |
| 92 .WillOnce(DoAll(SetArgPointee<1>(kAudioDecodeStats), Return(0))); |
| 93 } |
| 94 |
| 95 private: |
| 96 MockRemoteBitrateEstimator remote_bitrate_estimator_; |
| 97 MockVoiceEngine voice_engine_; |
| 98 rtc::scoped_refptr<AudioState> audio_state_; |
| 99 AudioReceiveStream::Config stream_config_; |
| 100 }; |
27 | 101 |
28 void BuildAbsoluteSendTimeExtension(uint8_t* buffer, | 102 void BuildAbsoluteSendTimeExtension(uint8_t* buffer, |
29 int id, | 103 int id, |
30 uint32_t abs_send_time) { | 104 uint32_t abs_send_time) { |
31 const size_t kRtpOneByteHeaderLength = 4; | 105 const size_t kRtpOneByteHeaderLength = 4; |
32 const uint16_t kRtpOneByteHeaderExtensionId = 0xBEDE; | 106 const uint16_t kRtpOneByteHeaderExtensionId = 0xBEDE; |
33 ByteWriter<uint16_t>::WriteBigEndian(buffer, kRtpOneByteHeaderExtensionId); | 107 ByteWriter<uint16_t>::WriteBigEndian(buffer, kRtpOneByteHeaderExtensionId); |
34 | 108 |
35 const uint32_t kPosLength = 2; | 109 const uint32_t kPosLength = 2; |
36 ByteWriter<uint16_t>::WriteBigEndian(buffer + kPosLength, | 110 ByteWriter<uint16_t>::WriteBigEndian(buffer + kPosLength, |
(...skipping 18 matching lines...) Expand all Loading... |
55 int32_t rtp_header_length = webrtc::kRtpHeaderSize; | 129 int32_t rtp_header_length = webrtc::kRtpHeaderSize; |
56 | 130 |
57 BuildAbsoluteSendTimeExtension(header + rtp_header_length, extension_id, | 131 BuildAbsoluteSendTimeExtension(header + rtp_header_length, extension_id, |
58 abs_send_time); | 132 abs_send_time); |
59 rtp_header_length += kAbsoluteSendTimeLength; | 133 rtp_header_length += kAbsoluteSendTimeLength; |
60 return rtp_header_length; | 134 return rtp_header_length; |
61 } | 135 } |
62 } // namespace | 136 } // namespace |
63 | 137 |
64 TEST(AudioReceiveStreamTest, ConfigToString) { | 138 TEST(AudioReceiveStreamTest, ConfigToString) { |
65 const int kAbsSendTimeId = 3; | |
66 AudioReceiveStream::Config config; | 139 AudioReceiveStream::Config config; |
67 config.rtp.remote_ssrc = kRemoteSsrc; | 140 config.rtp.remote_ssrc = kRemoteSsrc; |
68 config.rtp.local_ssrc = kLocalSsrc; | 141 config.rtp.local_ssrc = kLocalSsrc; |
69 config.rtp.extensions.push_back( | 142 config.rtp.extensions.push_back( |
70 RtpExtension(RtpExtension::kAbsSendTime, kAbsSendTimeId)); | 143 RtpExtension(RtpExtension::kAbsSendTime, kAbsSendTimeId)); |
71 config.voe_channel_id = kChannelId; | 144 config.voe_channel_id = kChannelId; |
72 config.combined_audio_video_bwe = true; | 145 config.combined_audio_video_bwe = true; |
73 EXPECT_EQ( | 146 EXPECT_EQ( |
74 "{rtp: {remote_ssrc: 1234, local_ssrc: 5678, extensions: [{name: " | 147 "{rtp: {remote_ssrc: 1234, local_ssrc: 5678, extensions: [{name: " |
75 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time, id: 3}]}, " | 148 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time, id: 3}]}, " |
76 "receive_transport: nullptr, rtcp_send_transport: nullptr, " | 149 "receive_transport: nullptr, rtcp_send_transport: nullptr, " |
77 "voe_channel_id: 2, combined_audio_video_bwe: true}", | 150 "voe_channel_id: 2, combined_audio_video_bwe: true}", |
78 config.ToString()); | 151 config.ToString()); |
79 } | 152 } |
80 | 153 |
81 TEST(AudioReceiveStreamTest, ConstructDestruct) { | 154 TEST(AudioReceiveStreamTest, ConstructDestruct) { |
82 MockRemoteBitrateEstimator remote_bitrate_estimator; | 155 ConfigHelper helper; |
83 MockVoiceEngine voice_engine; | 156 internal::AudioReceiveStream recv_stream( |
84 AudioReceiveStream::Config config; | 157 helper.remote_bitrate_estimator(), helper.config(), helper.audio_state()); |
85 config.voe_channel_id = kChannelId; | |
86 internal::AudioReceiveStream recv_stream(&remote_bitrate_estimator, config, | |
87 &voice_engine); | |
88 } | 158 } |
89 | 159 |
90 TEST(AudioReceiveStreamTest, AudioPacketUpdatesBweWithTimestamp) { | 160 TEST(AudioReceiveStreamTest, AudioPacketUpdatesBweWithTimestamp) { |
91 MockRemoteBitrateEstimator remote_bitrate_estimator; | 161 ConfigHelper helper; |
92 MockVoiceEngine voice_engine; | 162 helper.config().combined_audio_video_bwe = true; |
93 AudioReceiveStream::Config config; | 163 helper.config().rtp.extensions.push_back( |
94 config.combined_audio_video_bwe = true; | |
95 config.voe_channel_id = kChannelId; | |
96 const int kAbsSendTimeId = 3; | |
97 config.rtp.extensions.push_back( | |
98 RtpExtension(RtpExtension::kAbsSendTime, kAbsSendTimeId)); | 164 RtpExtension(RtpExtension::kAbsSendTime, kAbsSendTimeId)); |
99 internal::AudioReceiveStream recv_stream(&remote_bitrate_estimator, config, | 165 internal::AudioReceiveStream recv_stream( |
100 &voice_engine); | 166 helper.remote_bitrate_estimator(), helper.config(), helper.audio_state()); |
101 uint8_t rtp_packet[30]; | 167 uint8_t rtp_packet[30]; |
102 const int kAbsSendTimeValue = 1234; | 168 const int kAbsSendTimeValue = 1234; |
103 CreateRtpHeaderWithAbsSendTime(rtp_packet, kAbsSendTimeId, kAbsSendTimeValue); | 169 CreateRtpHeaderWithAbsSendTime(rtp_packet, kAbsSendTimeId, kAbsSendTimeValue); |
104 PacketTime packet_time(5678000, 0); | 170 PacketTime packet_time(5678000, 0); |
105 const size_t kExpectedHeaderLength = 20; | 171 const size_t kExpectedHeaderLength = 20; |
106 EXPECT_CALL(remote_bitrate_estimator, | 172 EXPECT_CALL(*helper.remote_bitrate_estimator(), |
107 IncomingPacket(packet_time.timestamp / 1000, | 173 IncomingPacket(packet_time.timestamp / 1000, |
108 sizeof(rtp_packet) - kExpectedHeaderLength, | 174 sizeof(rtp_packet) - kExpectedHeaderLength, |
109 testing::_, false)) | 175 testing::_, false)) |
110 .Times(1); | 176 .Times(1); |
111 EXPECT_TRUE( | 177 EXPECT_TRUE( |
112 recv_stream.DeliverRtp(rtp_packet, sizeof(rtp_packet), packet_time)); | 178 recv_stream.DeliverRtp(rtp_packet, sizeof(rtp_packet), packet_time)); |
113 } | 179 } |
114 | 180 |
115 TEST(AudioReceiveStreamTest, GetStats) { | 181 TEST(AudioReceiveStreamTest, GetStats) { |
116 const int kJitterBufferDelay = -7; | 182 ConfigHelper helper; |
117 const int kPlayoutBufferDelay = 302; | 183 internal::AudioReceiveStream recv_stream( |
118 const unsigned int kSpeechOutputLevel = 99; | 184 helper.remote_bitrate_estimator(), helper.config(), helper.audio_state()); |
119 const CallStatistics kCallStats = {345, 678, 901, 234, -12, | 185 helper.SetupMockForGetStats(); |
120 3456, 7890, 567, 890, 123}; | |
121 | |
122 const CodecInst kCodecInst = {123, "codec_name_recv", 96000, -187, -198, | |
123 -103}; | |
124 | |
125 const NetworkStatistics kNetworkStats = { | |
126 123, 456, false, 0, 0, 789, 12, 345, 678, 901, -1, -1, -1, -1, -1, 0}; | |
127 | |
128 webrtc::AudioDecodingCallStats audio_decode_stats; | |
129 { | |
130 audio_decode_stats.calls_to_silence_generator = 234; | |
131 audio_decode_stats.calls_to_neteq = 567; | |
132 audio_decode_stats.decoded_normal = 890; | |
133 audio_decode_stats.decoded_plc = 123; | |
134 audio_decode_stats.decoded_cng = 456; | |
135 audio_decode_stats.decoded_plc_cng = 789; | |
136 } | |
137 | |
138 MockRemoteBitrateEstimator remote_bitrate_estimator; | |
139 MockVoiceEngine voice_engine; | |
140 AudioReceiveStream::Config config; | |
141 config.rtp.remote_ssrc = kRemoteSsrc; | |
142 config.voe_channel_id = kChannelId; | |
143 internal::AudioReceiveStream recv_stream(&remote_bitrate_estimator, config, | |
144 &voice_engine); | |
145 | |
146 using testing::_; | |
147 using testing::DoAll; | |
148 using testing::Return; | |
149 using testing::SetArgPointee; | |
150 using testing::SetArgReferee; | |
151 EXPECT_CALL(voice_engine, GetRemoteSSRC(kChannelId, _)) | |
152 .WillOnce(DoAll(SetArgReferee<1>(0), Return(0))); | |
153 EXPECT_CALL(voice_engine, GetRTCPStatistics(kChannelId, _)) | |
154 .WillOnce(DoAll(SetArgReferee<1>(kCallStats), Return(0))); | |
155 EXPECT_CALL(voice_engine, GetRecCodec(kChannelId, _)) | |
156 .WillOnce(DoAll(SetArgReferee<1>(kCodecInst), Return(0))); | |
157 EXPECT_CALL(voice_engine, GetDelayEstimate(kChannelId, _, _)) | |
158 .WillOnce(DoAll(SetArgPointee<1>(kJitterBufferDelay), | |
159 SetArgPointee<2>(kPlayoutBufferDelay), Return(0))); | |
160 EXPECT_CALL(voice_engine, GetSpeechOutputLevelFullRange(kChannelId, _)) | |
161 .WillOnce(DoAll(SetArgReferee<1>(kSpeechOutputLevel), Return(0))); | |
162 EXPECT_CALL(voice_engine, GetNetworkStatistics(kChannelId, _)) | |
163 .WillOnce(DoAll(SetArgReferee<1>(kNetworkStats), Return(0))); | |
164 EXPECT_CALL(voice_engine, GetDecodingCallStatistics(kChannelId, _)) | |
165 .WillOnce(DoAll(SetArgPointee<1>(audio_decode_stats), Return(0))); | |
166 | |
167 AudioReceiveStream::Stats stats = recv_stream.GetStats(); | 186 AudioReceiveStream::Stats stats = recv_stream.GetStats(); |
168 EXPECT_EQ(kRemoteSsrc, stats.remote_ssrc); | 187 EXPECT_EQ(kRemoteSsrc, stats.remote_ssrc); |
169 EXPECT_EQ(static_cast<int64_t>(kCallStats.bytesReceived), stats.bytes_rcvd); | 188 EXPECT_EQ(static_cast<int64_t>(kCallStats.bytesReceived), stats.bytes_rcvd); |
170 EXPECT_EQ(static_cast<uint32_t>(kCallStats.packetsReceived), | 189 EXPECT_EQ(static_cast<uint32_t>(kCallStats.packetsReceived), |
171 stats.packets_rcvd); | 190 stats.packets_rcvd); |
172 EXPECT_EQ(kCallStats.cumulativeLost, stats.packets_lost); | 191 EXPECT_EQ(kCallStats.cumulativeLost, stats.packets_lost); |
173 EXPECT_EQ(Q8ToFloat(kCallStats.fractionLost), stats.fraction_lost); | 192 EXPECT_EQ(Q8ToFloat(kCallStats.fractionLost), stats.fraction_lost); |
174 EXPECT_EQ(std::string(kCodecInst.plname), stats.codec_name); | 193 EXPECT_EQ(std::string(kCodecInst.plname), stats.codec_name); |
175 EXPECT_EQ(kCallStats.extendedMax, stats.ext_seqnum); | 194 EXPECT_EQ(kCallStats.extendedMax, stats.ext_seqnum); |
176 EXPECT_EQ(kCallStats.jitterSamples / (kCodecInst.plfreq / 1000), | 195 EXPECT_EQ(kCallStats.jitterSamples / (kCodecInst.plfreq / 1000), |
177 stats.jitter_ms); | 196 stats.jitter_ms); |
178 EXPECT_EQ(kNetworkStats.currentBufferSize, stats.jitter_buffer_ms); | 197 EXPECT_EQ(kNetworkStats.currentBufferSize, stats.jitter_buffer_ms); |
179 EXPECT_EQ(kNetworkStats.preferredBufferSize, | 198 EXPECT_EQ(kNetworkStats.preferredBufferSize, |
180 stats.jitter_buffer_preferred_ms); | 199 stats.jitter_buffer_preferred_ms); |
181 EXPECT_EQ(static_cast<uint32_t>(kJitterBufferDelay + kPlayoutBufferDelay), | 200 EXPECT_EQ(static_cast<uint32_t>(kJitterBufferDelay + kPlayoutBufferDelay), |
182 stats.delay_estimate_ms); | 201 stats.delay_estimate_ms); |
183 EXPECT_EQ(static_cast<int32_t>(kSpeechOutputLevel), stats.audio_level); | 202 EXPECT_EQ(static_cast<int32_t>(kSpeechOutputLevel), stats.audio_level); |
184 EXPECT_EQ(Q14ToFloat(kNetworkStats.currentExpandRate), stats.expand_rate); | 203 EXPECT_EQ(Q14ToFloat(kNetworkStats.currentExpandRate), stats.expand_rate); |
185 EXPECT_EQ(Q14ToFloat(kNetworkStats.currentSpeechExpandRate), | 204 EXPECT_EQ(Q14ToFloat(kNetworkStats.currentSpeechExpandRate), |
186 stats.speech_expand_rate); | 205 stats.speech_expand_rate); |
187 EXPECT_EQ(Q14ToFloat(kNetworkStats.currentSecondaryDecodedRate), | 206 EXPECT_EQ(Q14ToFloat(kNetworkStats.currentSecondaryDecodedRate), |
188 stats.secondary_decoded_rate); | 207 stats.secondary_decoded_rate); |
189 EXPECT_EQ(Q14ToFloat(kNetworkStats.currentAccelerateRate), | 208 EXPECT_EQ(Q14ToFloat(kNetworkStats.currentAccelerateRate), |
190 stats.accelerate_rate); | 209 stats.accelerate_rate); |
191 EXPECT_EQ(Q14ToFloat(kNetworkStats.currentPreemptiveRate), | 210 EXPECT_EQ(Q14ToFloat(kNetworkStats.currentPreemptiveRate), |
192 stats.preemptive_expand_rate); | 211 stats.preemptive_expand_rate); |
193 EXPECT_EQ(audio_decode_stats.calls_to_silence_generator, | 212 EXPECT_EQ(kAudioDecodeStats.calls_to_silence_generator, |
194 stats.decoding_calls_to_silence_generator); | 213 stats.decoding_calls_to_silence_generator); |
195 EXPECT_EQ(audio_decode_stats.calls_to_neteq, stats.decoding_calls_to_neteq); | 214 EXPECT_EQ(kAudioDecodeStats.calls_to_neteq, stats.decoding_calls_to_neteq); |
196 EXPECT_EQ(audio_decode_stats.decoded_normal, stats.decoding_normal); | 215 EXPECT_EQ(kAudioDecodeStats.decoded_normal, stats.decoding_normal); |
197 EXPECT_EQ(audio_decode_stats.decoded_plc, stats.decoding_plc); | 216 EXPECT_EQ(kAudioDecodeStats.decoded_plc, stats.decoding_plc); |
198 EXPECT_EQ(audio_decode_stats.decoded_cng, stats.decoding_cng); | 217 EXPECT_EQ(kAudioDecodeStats.decoded_cng, stats.decoding_cng); |
199 EXPECT_EQ(audio_decode_stats.decoded_plc_cng, stats.decoding_plc_cng); | 218 EXPECT_EQ(kAudioDecodeStats.decoded_plc_cng, stats.decoding_plc_cng); |
200 EXPECT_EQ(kCallStats.capture_start_ntp_time_ms_, | 219 EXPECT_EQ(kCallStats.capture_start_ntp_time_ms_, |
201 stats.capture_start_ntp_time_ms); | 220 stats.capture_start_ntp_time_ms); |
202 } | 221 } |
203 } // namespace test | 222 } // namespace test |
204 } // namespace webrtc | 223 } // namespace webrtc |
OLD | NEW |