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 <string> | 11 #include <string> |
| 12 #include <utility> |
12 #include <vector> | 13 #include <vector> |
13 | 14 |
14 #include "webrtc/audio/audio_send_stream.h" | 15 #include "webrtc/audio/audio_send_stream.h" |
15 #include "webrtc/audio/audio_state.h" | 16 #include "webrtc/audio/audio_state.h" |
16 #include "webrtc/audio/conversion.h" | 17 #include "webrtc/audio/conversion.h" |
17 #include "webrtc/base/task_queue.h" | 18 #include "webrtc/base/task_queue.h" |
18 #include "webrtc/logging/rtc_event_log/mock/mock_rtc_event_log.h" | 19 #include "webrtc/logging/rtc_event_log/mock/mock_rtc_event_log.h" |
| 20 #include "webrtc/modules/audio_coding/codecs/mock/mock_audio_encoder.h" |
| 21 #include "webrtc/modules/audio_coding/codecs/mock/mock_audio_encoder_factory.h" |
19 #include "webrtc/modules/audio_mixer/audio_mixer_impl.h" | 22 #include "webrtc/modules/audio_mixer/audio_mixer_impl.h" |
20 #include "webrtc/modules/audio_processing/include/mock_audio_processing.h" | 23 #include "webrtc/modules/audio_processing/include/mock_audio_processing.h" |
21 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" | 24 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" |
22 #include "webrtc/modules/congestion_controller/include/mock/mock_congestion_cont
roller.h" | 25 #include "webrtc/modules/congestion_controller/include/mock/mock_congestion_cont
roller.h" |
23 #include "webrtc/modules/pacing/paced_sender.h" | 26 #include "webrtc/modules/pacing/paced_sender.h" |
24 #include "webrtc/modules/rtp_rtcp/mocks/mock_rtcp_rtt_stats.h" | 27 #include "webrtc/modules/rtp_rtcp/mocks/mock_rtcp_rtt_stats.h" |
25 #include "webrtc/test/gtest.h" | 28 #include "webrtc/test/gtest.h" |
26 #include "webrtc/test/mock_voe_channel_proxy.h" | 29 #include "webrtc/test/mock_voe_channel_proxy.h" |
27 #include "webrtc/test/mock_voice_engine.h" | 30 #include "webrtc/test/mock_voice_engine.h" |
28 #include "webrtc/voice_engine/transmit_mixer.h" | 31 #include "webrtc/voice_engine/transmit_mixer.h" |
29 | 32 |
30 namespace webrtc { | 33 namespace webrtc { |
31 namespace test { | 34 namespace test { |
32 namespace { | 35 namespace { |
33 | 36 |
34 using testing::_; | 37 using testing::_; |
35 using testing::Eq; | 38 using testing::Eq; |
36 using testing::Ne; | 39 using testing::Ne; |
| 40 using testing::Invoke; |
37 using testing::Return; | 41 using testing::Return; |
38 | 42 |
39 const int kChannelId = 1; | 43 const int kChannelId = 1; |
40 const uint32_t kSsrc = 1234; | 44 const uint32_t kSsrc = 1234; |
41 const char* kCName = "foo_name"; | 45 const char* kCName = "foo_name"; |
42 const int kAudioLevelId = 2; | 46 const int kAudioLevelId = 2; |
43 const int kTransportSequenceNumberId = 4; | 47 const int kTransportSequenceNumberId = 4; |
44 const int kEchoDelayMedian = 254; | 48 const int kEchoDelayMedian = 254; |
45 const int kEchoDelayStdDev = -3; | 49 const int kEchoDelayStdDev = -3; |
46 const int kEchoReturnLoss = -65; | 50 const int kEchoReturnLoss = -65; |
47 const int kEchoReturnLossEnhancement = 101; | 51 const int kEchoReturnLossEnhancement = 101; |
48 const float kResidualEchoLikelihood = -1.0f; | 52 const float kResidualEchoLikelihood = -1.0f; |
49 const int32_t kSpeechInputLevel = 96; | 53 const int32_t kSpeechInputLevel = 96; |
50 const CallStatistics kCallStats = { | 54 const CallStatistics kCallStats = { |
51 1345, 1678, 1901, 1234, 112, 13456, 17890, 1567, -1890, -1123}; | 55 1345, 1678, 1901, 1234, 112, 13456, 17890, 1567, -1890, -1123}; |
52 const ReportBlock kReportBlock = {456, 780, 123, 567, 890, 132, 143, 13354}; | 56 const ReportBlock kReportBlock = {456, 780, 123, 567, 890, 132, 143, 13354}; |
53 const int kTelephoneEventPayloadType = 123; | 57 const int kTelephoneEventPayloadType = 123; |
54 const int kTelephoneEventPayloadFrequency = 65432; | 58 const int kTelephoneEventPayloadFrequency = 65432; |
55 const int kTelephoneEventCode = 45; | 59 const int kTelephoneEventCode = 45; |
56 const int kTelephoneEventDuration = 6789; | 60 const int kTelephoneEventDuration = 6789; |
57 const CodecInst kIsacCodec = {103, "isac", 16000, 320, 1, 32000}; | 61 const CodecInst kIsacCodec = {103, "isac", 16000, 320, 1, 32000}; |
| 62 constexpr int kIsacPayloadType = 103; |
| 63 const SdpAudioFormat kIsacFormat = {"isac", 16000, 1}; |
| 64 const SdpAudioFormat kOpusFormat = {"opus", 48000, 2}; |
| 65 const SdpAudioFormat kG722Format = {"g722", 8000, 1}; |
| 66 const AudioCodecSpec kCodecSpecs[] = { |
| 67 {kIsacFormat, {16000, 1, 32000, 10000, 32000}}, |
| 68 {kOpusFormat, {48000, 1, 32000, 6000, 510000}}, |
| 69 {kG722Format, {16000, 1, 64000}}}; |
58 | 70 |
59 class MockLimitObserver : public BitrateAllocator::LimitObserver { | 71 class MockLimitObserver : public BitrateAllocator::LimitObserver { |
60 public: | 72 public: |
61 MOCK_METHOD2(OnAllocationLimitsChanged, | 73 MOCK_METHOD2(OnAllocationLimitsChanged, |
62 void(uint32_t min_send_bitrate_bps, | 74 void(uint32_t min_send_bitrate_bps, |
63 uint32_t max_padding_bitrate_bps)); | 75 uint32_t max_padding_bitrate_bps)); |
64 }; | 76 }; |
65 | 77 |
66 class MockTransmitMixer : public voe::TransmitMixer { | 78 class MockTransmitMixer : public voe::TransmitMixer { |
67 public: | 79 public: |
68 MOCK_CONST_METHOD0(AudioLevelFullRange, int16_t()); | 80 MOCK_CONST_METHOD0(AudioLevelFullRange, int16_t()); |
69 }; | 81 }; |
70 | 82 |
| 83 std::unique_ptr<MockAudioEncoder> SetupAudioEncoderMock( |
| 84 int payload_type, |
| 85 const SdpAudioFormat& format) { |
| 86 for (const auto& spec : kCodecSpecs) { |
| 87 if (format == spec.format) { |
| 88 std::unique_ptr<MockAudioEncoder> encoder(new MockAudioEncoder); |
| 89 ON_CALL(*encoder.get(), SampleRateHz()) |
| 90 .WillByDefault(Return(spec.info.sample_rate_hz)); |
| 91 ON_CALL(*encoder.get(), NumChannels()) |
| 92 .WillByDefault(Return(spec.info.num_channels)); |
| 93 ON_CALL(*encoder.get(), RtpTimestampRateHz()) |
| 94 .WillByDefault(Return(spec.format.clockrate_hz)); |
| 95 return encoder; |
| 96 } |
| 97 } |
| 98 return nullptr; |
| 99 } |
| 100 |
| 101 rtc::scoped_refptr<MockAudioEncoderFactory> SetupEncoderFactoryMock() { |
| 102 rtc::scoped_refptr<MockAudioEncoderFactory> factory = |
| 103 new rtc::RefCountedObject<MockAudioEncoderFactory>(); |
| 104 ON_CALL(*factory.get(), GetSupportedEncoders()) |
| 105 .WillByDefault( |
| 106 Return(std::vector<AudioCodecSpec>(std::begin(kCodecSpecs), |
| 107 std::end(kCodecSpecs)))); |
| 108 ON_CALL(*factory.get(), QueryAudioEncoder(_)) |
| 109 .WillByDefault(Invoke([] (const SdpAudioFormat& format) { |
| 110 for (const auto& spec : kCodecSpecs) { |
| 111 if (format == spec.format) { |
| 112 return rtc::Optional<AudioCodecInfo>(spec.info); |
| 113 } |
| 114 } |
| 115 return rtc::Optional<AudioCodecInfo>(); |
| 116 })); |
| 117 ON_CALL(*factory.get(), MakeAudioEncoderMock(_, _, _)) |
| 118 .WillByDefault(Invoke([](int payload_type, const SdpAudioFormat& format, |
| 119 std::unique_ptr<AudioEncoder>* return_value) { |
| 120 *return_value = SetupAudioEncoderMock(payload_type, format); |
| 121 })); |
| 122 return factory; |
| 123 } |
| 124 |
71 struct ConfigHelper { | 125 struct ConfigHelper { |
72 explicit ConfigHelper(bool audio_bwe_enabled) | 126 ConfigHelper(bool audio_bwe_enabled, bool expect_set_encoder_call) |
73 : simulated_clock_(123456), | 127 : simulated_clock_(123456), |
74 stream_config_(nullptr), | 128 stream_config_(nullptr), |
75 congestion_controller_(&simulated_clock_, | 129 congestion_controller_(&simulated_clock_, |
76 &bitrate_observer_, | 130 &bitrate_observer_, |
77 nullptr, | 131 nullptr, |
78 &event_log_, | 132 &event_log_, |
79 &packet_router_), | 133 &packet_router_), |
80 bitrate_allocator_(&limit_observer_), | 134 bitrate_allocator_(&limit_observer_), |
81 worker_queue_("ConfigHelper_worker_queue") { | 135 worker_queue_("ConfigHelper_worker_queue") { |
82 using testing::Invoke; | 136 using testing::Invoke; |
(...skipping 11 matching lines...) Expand all Loading... |
94 config.audio_mixer = AudioMixerImpl::Create(); | 148 config.audio_mixer = AudioMixerImpl::Create(); |
95 audio_state_ = AudioState::Create(config); | 149 audio_state_ = AudioState::Create(config); |
96 | 150 |
97 SetupDefaultChannelProxy(audio_bwe_enabled); | 151 SetupDefaultChannelProxy(audio_bwe_enabled); |
98 | 152 |
99 EXPECT_CALL(voice_engine_, ChannelProxyFactory(kChannelId)) | 153 EXPECT_CALL(voice_engine_, ChannelProxyFactory(kChannelId)) |
100 .WillOnce(Invoke([this](int channel_id) { | 154 .WillOnce(Invoke([this](int channel_id) { |
101 return channel_proxy_; | 155 return channel_proxy_; |
102 })); | 156 })); |
103 | 157 |
104 SetupMockForSetupSendCodec(); | 158 SetupMockForSetupSendCodec(expect_set_encoder_call); |
105 | 159 |
| 160 // Use ISAC as default codec so as to prevent unnecessary |voice_engine_| |
| 161 // calls from the default ctor behavior. |
| 162 stream_config_.send_codec_spec = |
| 163 rtc::Optional<AudioSendStream::Config::SendCodecSpec>( |
| 164 {kIsacPayloadType, kIsacFormat}); |
106 stream_config_.voe_channel_id = kChannelId; | 165 stream_config_.voe_channel_id = kChannelId; |
107 stream_config_.rtp.ssrc = kSsrc; | 166 stream_config_.rtp.ssrc = kSsrc; |
108 stream_config_.rtp.nack.rtp_history_ms = 200; | 167 stream_config_.rtp.nack.rtp_history_ms = 200; |
109 stream_config_.rtp.c_name = kCName; | 168 stream_config_.rtp.c_name = kCName; |
110 stream_config_.rtp.extensions.push_back( | 169 stream_config_.rtp.extensions.push_back( |
111 RtpExtension(RtpExtension::kAudioLevelUri, kAudioLevelId)); | 170 RtpExtension(RtpExtension::kAudioLevelUri, kAudioLevelId)); |
112 if (audio_bwe_enabled) { | 171 if (audio_bwe_enabled) { |
113 stream_config_.rtp.extensions.push_back( | 172 stream_config_.rtp.extensions.push_back( |
114 RtpExtension(RtpExtension::kTransportSequenceNumberUri, | 173 RtpExtension(RtpExtension::kTransportSequenceNumberUri, |
115 kTransportSequenceNumberId)); | 174 kTransportSequenceNumberId)); |
116 stream_config_.send_codec_spec.transport_cc_enabled = true; | 175 stream_config_.send_codec_spec->transport_cc_enabled = true; |
117 } | 176 } |
118 // Use ISAC as default codec so as to prevent unnecessary |voice_engine_| | 177 stream_config_.encoder_factory = SetupEncoderFactoryMock(); |
119 // calls from the default ctor behavior. | |
120 stream_config_.send_codec_spec.codec_inst = kIsacCodec; | |
121 stream_config_.min_bitrate_bps = 10000; | 178 stream_config_.min_bitrate_bps = 10000; |
122 stream_config_.max_bitrate_bps = 65000; | 179 stream_config_.max_bitrate_bps = 65000; |
123 } | 180 } |
124 | 181 |
125 AudioSendStream::Config& config() { return stream_config_; } | 182 AudioSendStream::Config& config() { return stream_config_; } |
| 183 MockAudioEncoderFactory& mock_encoder_factory() { |
| 184 return *static_cast<MockAudioEncoderFactory*>( |
| 185 stream_config_.encoder_factory.get()); |
| 186 } |
126 rtc::scoped_refptr<AudioState> audio_state() { return audio_state_; } | 187 rtc::scoped_refptr<AudioState> audio_state() { return audio_state_; } |
127 MockVoEChannelProxy* channel_proxy() { return channel_proxy_; } | 188 MockVoEChannelProxy* channel_proxy() { return channel_proxy_; } |
128 PacketRouter* packet_router() { return &packet_router_; } | 189 PacketRouter* packet_router() { return &packet_router_; } |
129 CongestionController* congestion_controller() { | 190 CongestionController* congestion_controller() { |
130 return &congestion_controller_; | 191 return &congestion_controller_; |
131 } | 192 } |
132 BitrateAllocator* bitrate_allocator() { return &bitrate_allocator_; } | 193 BitrateAllocator* bitrate_allocator() { return &bitrate_allocator_; } |
133 rtc::TaskQueue* worker_queue() { return &worker_queue_; } | 194 rtc::TaskQueue* worker_queue() { return &worker_queue_; } |
134 RtcEventLog* event_log() { return &event_log_; } | 195 RtcEventLog* event_log() { return &event_log_; } |
135 MockVoiceEngine* voice_engine() { return &voice_engine_; } | 196 MockVoiceEngine* voice_engine() { return &voice_engine_; } |
(...skipping 29 matching lines...) Expand all Loading... |
165 EXPECT_CALL(*channel_proxy_, RegisterExternalTransport(nullptr)).Times(1); | 226 EXPECT_CALL(*channel_proxy_, RegisterExternalTransport(nullptr)).Times(1); |
166 EXPECT_CALL(*channel_proxy_, DeRegisterExternalTransport()).Times(1); | 227 EXPECT_CALL(*channel_proxy_, DeRegisterExternalTransport()).Times(1); |
167 EXPECT_CALL(*channel_proxy_, SetRtcEventLog(testing::NotNull())).Times(1); | 228 EXPECT_CALL(*channel_proxy_, SetRtcEventLog(testing::NotNull())).Times(1); |
168 EXPECT_CALL(*channel_proxy_, SetRtcEventLog(testing::IsNull())) | 229 EXPECT_CALL(*channel_proxy_, SetRtcEventLog(testing::IsNull())) |
169 .Times(1); // Destructor resets the event log | 230 .Times(1); // Destructor resets the event log |
170 EXPECT_CALL(*channel_proxy_, SetRtcpRttStats(&rtcp_rtt_stats_)).Times(1); | 231 EXPECT_CALL(*channel_proxy_, SetRtcpRttStats(&rtcp_rtt_stats_)).Times(1); |
171 EXPECT_CALL(*channel_proxy_, SetRtcpRttStats(testing::IsNull())) | 232 EXPECT_CALL(*channel_proxy_, SetRtcpRttStats(testing::IsNull())) |
172 .Times(1); // Destructor resets the rtt stats. | 233 .Times(1); // Destructor resets the rtt stats. |
173 } | 234 } |
174 | 235 |
175 void SetupMockForSetupSendCodec() { | 236 void SetupMockForSetupSendCodec(bool expect_set_encoder_call) { |
176 EXPECT_CALL(*channel_proxy_, SetVADStatus(false)) | 237 if (expect_set_encoder_call) { |
177 .WillOnce(Return(true)); | 238 EXPECT_CALL(*channel_proxy_, SetEncoderForMock(_, _)) |
178 EXPECT_CALL(*channel_proxy_, SetCodecFECStatus(false)) | 239 .WillOnce(Return(true)); |
179 .WillOnce(Return(true)); | 240 } |
180 EXPECT_CALL(*channel_proxy_, DisableAudioNetworkAdaptor()); | |
181 // Let |GetSendCodec| return false for the first time to indicate that no | |
182 // send codec has been set. | |
183 EXPECT_CALL(*channel_proxy_, GetSendCodec(_)).WillOnce(Return(false)); | |
184 EXPECT_CALL(*channel_proxy_, SetSendCodec(_)).WillOnce(Return(true)); | |
185 } | 241 } |
| 242 |
186 RtcpRttStats* rtcp_rtt_stats() { return &rtcp_rtt_stats_; } | 243 RtcpRttStats* rtcp_rtt_stats() { return &rtcp_rtt_stats_; } |
187 | 244 |
188 void SetupMockForSendTelephoneEvent() { | 245 void SetupMockForSendTelephoneEvent() { |
189 EXPECT_TRUE(channel_proxy_); | 246 EXPECT_TRUE(channel_proxy_); |
190 EXPECT_CALL(*channel_proxy_, | 247 EXPECT_CALL(*channel_proxy_, |
191 SetSendTelephoneEventPayloadType(kTelephoneEventPayloadType, | 248 SetSendTelephoneEventPayloadType(kTelephoneEventPayloadType, |
192 kTelephoneEventPayloadFrequency)) | 249 kTelephoneEventPayloadFrequency)) |
193 .WillOnce(Return(true)); | 250 .WillOnce(Return(true)); |
194 EXPECT_CALL(*channel_proxy_, | 251 EXPECT_CALL(*channel_proxy_, |
195 SendTelephoneEventOutband(kTelephoneEventCode, kTelephoneEventDuration)) | 252 SendTelephoneEventOutband(kTelephoneEventCode, kTelephoneEventDuration)) |
(...skipping 11 matching lines...) Expand all Loading... |
207 block.source_SSRC = kSsrc; | 264 block.source_SSRC = kSsrc; |
208 report_blocks.push_back(block); // Correct block. | 265 report_blocks.push_back(block); // Correct block. |
209 block.fraction_lost = 0; | 266 block.fraction_lost = 0; |
210 report_blocks.push_back(block); // Duplicate SSRC, bad fraction_lost. | 267 report_blocks.push_back(block); // Duplicate SSRC, bad fraction_lost. |
211 | 268 |
212 EXPECT_TRUE(channel_proxy_); | 269 EXPECT_TRUE(channel_proxy_); |
213 EXPECT_CALL(*channel_proxy_, GetRTCPStatistics()) | 270 EXPECT_CALL(*channel_proxy_, GetRTCPStatistics()) |
214 .WillRepeatedly(Return(kCallStats)); | 271 .WillRepeatedly(Return(kCallStats)); |
215 EXPECT_CALL(*channel_proxy_, GetRemoteRTCPReportBlocks()) | 272 EXPECT_CALL(*channel_proxy_, GetRemoteRTCPReportBlocks()) |
216 .WillRepeatedly(Return(report_blocks)); | 273 .WillRepeatedly(Return(report_blocks)); |
217 EXPECT_CALL(*channel_proxy_, GetSendCodec(_)) | |
218 .WillRepeatedly(DoAll(SetArgPointee<0>(kIsacCodec), Return(true))); | |
219 EXPECT_CALL(voice_engine_, transmit_mixer()) | 274 EXPECT_CALL(voice_engine_, transmit_mixer()) |
220 .WillRepeatedly(Return(&transmit_mixer_)); | 275 .WillRepeatedly(Return(&transmit_mixer_)); |
221 EXPECT_CALL(voice_engine_, audio_processing()) | 276 EXPECT_CALL(voice_engine_, audio_processing()) |
222 .WillRepeatedly(Return(&audio_processing_)); | 277 .WillRepeatedly(Return(&audio_processing_)); |
223 | 278 |
224 EXPECT_CALL(transmit_mixer_, AudioLevelFullRange()) | 279 EXPECT_CALL(transmit_mixer_, AudioLevelFullRange()) |
225 .WillRepeatedly(Return(kSpeechInputLevel)); | 280 .WillRepeatedly(Return(kSpeechInputLevel)); |
226 | 281 |
227 // We have to set the instantaneous value, the average, min and max. We only | 282 // We have to set the instantaneous value, the average, min and max. We only |
228 // care about the instantaneous value, so we set all to the same value. | 283 // care about the instantaneous value, so we set all to the same value. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 }; | 315 }; |
261 } // namespace | 316 } // namespace |
262 | 317 |
263 TEST(AudioSendStreamTest, ConfigToString) { | 318 TEST(AudioSendStreamTest, ConfigToString) { |
264 AudioSendStream::Config config(nullptr); | 319 AudioSendStream::Config config(nullptr); |
265 config.rtp.ssrc = kSsrc; | 320 config.rtp.ssrc = kSsrc; |
266 config.rtp.c_name = kCName; | 321 config.rtp.c_name = kCName; |
267 config.voe_channel_id = kChannelId; | 322 config.voe_channel_id = kChannelId; |
268 config.min_bitrate_bps = 12000; | 323 config.min_bitrate_bps = 12000; |
269 config.max_bitrate_bps = 34000; | 324 config.max_bitrate_bps = 34000; |
270 config.send_codec_spec.nack_enabled = true; | 325 config.send_codec_spec = |
271 config.send_codec_spec.transport_cc_enabled = false; | 326 rtc::Optional<AudioSendStream::Config::SendCodecSpec>( |
272 config.send_codec_spec.enable_codec_fec = true; | 327 {kIsacPayloadType, kIsacFormat}); |
273 config.send_codec_spec.enable_opus_dtx = false; | 328 config.send_codec_spec->nack_enabled = true; |
274 config.send_codec_spec.opus_max_playback_rate = 32000; | 329 config.send_codec_spec->transport_cc_enabled = false; |
275 config.send_codec_spec.cng_payload_type = 42; | 330 config.send_codec_spec->cng_payload_type = 42; |
276 config.send_codec_spec.cng_plfreq = 56; | 331 config.encoder_factory = MockAudioEncoderFactory::CreateUnusedFactory(); |
277 config.send_codec_spec.min_ptime_ms = 20; | |
278 config.send_codec_spec.max_ptime_ms = 60; | |
279 config.send_codec_spec.codec_inst = kIsacCodec; | |
280 config.rtp.extensions.push_back( | 332 config.rtp.extensions.push_back( |
281 RtpExtension(RtpExtension::kAudioLevelUri, kAudioLevelId)); | 333 RtpExtension(RtpExtension::kAudioLevelUri, kAudioLevelId)); |
282 EXPECT_EQ( | 334 EXPECT_EQ( |
283 "{rtp: {ssrc: 1234, extensions: [{uri: " | 335 "{rtp: {ssrc: 1234, extensions: [{uri: " |
284 "urn:ietf:params:rtp-hdrext:ssrc-audio-level, id: 2}], nack: " | 336 "urn:ietf:params:rtp-hdrext:ssrc-audio-level, id: 2}], nack: " |
285 "{rtp_history_ms: 0}, c_name: foo_name}, send_transport: null, " | 337 "{rtp_history_ms: 0}, c_name: foo_name}, send_transport: null, " |
286 "voe_channel_id: 1, min_bitrate_bps: 12000, max_bitrate_bps: 34000, " | 338 "voe_channel_id: 1, min_bitrate_bps: 12000, max_bitrate_bps: 34000, " |
287 "send_codec_spec: {nack_enabled: true, transport_cc_enabled: false, " | 339 "send_codec_spec: {nack_enabled: true, transport_cc_enabled: false, " |
288 "enable_codec_fec: true, enable_opus_dtx: false, opus_max_playback_rate: " | 340 "cng_payload_type: 42, payload_type: 103, " |
289 "32000, cng_payload_type: 42, cng_plfreq: 56, min_ptime: 20, max_ptime: " | 341 "format: {name: isac, clockrate_hz: 16000, num_channels: 1, " |
290 "60, codec_inst: {pltype: 103, plname: \"isac\", plfreq: 16000, pacsize: " | 342 "parameters: {}}}}", |
291 "320, channels: 1, rate: 32000}}}", | |
292 config.ToString()); | 343 config.ToString()); |
293 } | 344 } |
294 | 345 |
295 TEST(AudioSendStreamTest, ConstructDestruct) { | 346 TEST(AudioSendStreamTest, ConstructDestruct) { |
296 ConfigHelper helper(false); | 347 ConfigHelper helper(false, true); |
297 internal::AudioSendStream send_stream( | 348 internal::AudioSendStream send_stream( |
298 helper.config(), helper.audio_state(), helper.worker_queue(), | 349 helper.config(), helper.audio_state(), helper.worker_queue(), |
299 helper.packet_router(), helper.congestion_controller(), | 350 helper.packet_router(), helper.congestion_controller(), |
300 helper.bitrate_allocator(), helper.event_log(), helper.rtcp_rtt_stats()); | 351 helper.bitrate_allocator(), helper.event_log(), helper.rtcp_rtt_stats()); |
301 } | 352 } |
302 | 353 |
303 TEST(AudioSendStreamTest, SendTelephoneEvent) { | 354 TEST(AudioSendStreamTest, SendTelephoneEvent) { |
304 ConfigHelper helper(false); | 355 ConfigHelper helper(false, true); |
305 internal::AudioSendStream send_stream( | 356 internal::AudioSendStream send_stream( |
306 helper.config(), helper.audio_state(), helper.worker_queue(), | 357 helper.config(), helper.audio_state(), helper.worker_queue(), |
307 helper.packet_router(), helper.congestion_controller(), | 358 helper.packet_router(), helper.congestion_controller(), |
308 helper.bitrate_allocator(), helper.event_log(), helper.rtcp_rtt_stats()); | 359 helper.bitrate_allocator(), helper.event_log(), helper.rtcp_rtt_stats()); |
309 helper.SetupMockForSendTelephoneEvent(); | 360 helper.SetupMockForSendTelephoneEvent(); |
310 EXPECT_TRUE(send_stream.SendTelephoneEvent(kTelephoneEventPayloadType, | 361 EXPECT_TRUE(send_stream.SendTelephoneEvent(kTelephoneEventPayloadType, |
311 kTelephoneEventPayloadFrequency, kTelephoneEventCode, | 362 kTelephoneEventPayloadFrequency, kTelephoneEventCode, |
312 kTelephoneEventDuration)); | 363 kTelephoneEventDuration)); |
313 } | 364 } |
314 | 365 |
315 TEST(AudioSendStreamTest, SetMuted) { | 366 TEST(AudioSendStreamTest, SetMuted) { |
316 ConfigHelper helper(false); | 367 ConfigHelper helper(false, true); |
317 internal::AudioSendStream send_stream( | 368 internal::AudioSendStream send_stream( |
318 helper.config(), helper.audio_state(), helper.worker_queue(), | 369 helper.config(), helper.audio_state(), helper.worker_queue(), |
319 helper.packet_router(), helper.congestion_controller(), | 370 helper.packet_router(), helper.congestion_controller(), |
320 helper.bitrate_allocator(), helper.event_log(), helper.rtcp_rtt_stats()); | 371 helper.bitrate_allocator(), helper.event_log(), helper.rtcp_rtt_stats()); |
321 EXPECT_CALL(*helper.channel_proxy(), SetInputMute(true)); | 372 EXPECT_CALL(*helper.channel_proxy(), SetInputMute(true)); |
322 send_stream.SetMuted(true); | 373 send_stream.SetMuted(true); |
323 } | 374 } |
324 | 375 |
325 TEST(AudioSendStreamTest, AudioBweCorrectObjectsOnChannelProxy) { | 376 TEST(AudioSendStreamTest, AudioBweCorrectObjectsOnChannelProxy) { |
326 ConfigHelper helper(true); | 377 ConfigHelper helper(true, true); |
327 internal::AudioSendStream send_stream( | 378 internal::AudioSendStream send_stream( |
328 helper.config(), helper.audio_state(), helper.worker_queue(), | 379 helper.config(), helper.audio_state(), helper.worker_queue(), |
329 helper.packet_router(), helper.congestion_controller(), | 380 helper.packet_router(), helper.congestion_controller(), |
330 helper.bitrate_allocator(), helper.event_log(), helper.rtcp_rtt_stats()); | 381 helper.bitrate_allocator(), helper.event_log(), helper.rtcp_rtt_stats()); |
331 } | 382 } |
332 | 383 |
333 TEST(AudioSendStreamTest, NoAudioBweCorrectObjectsOnChannelProxy) { | 384 TEST(AudioSendStreamTest, NoAudioBweCorrectObjectsOnChannelProxy) { |
334 ConfigHelper helper(false); | 385 ConfigHelper helper(false, true); |
335 internal::AudioSendStream send_stream( | 386 internal::AudioSendStream send_stream( |
336 helper.config(), helper.audio_state(), helper.worker_queue(), | 387 helper.config(), helper.audio_state(), helper.worker_queue(), |
337 helper.packet_router(), helper.congestion_controller(), | 388 helper.packet_router(), helper.congestion_controller(), |
338 helper.bitrate_allocator(), helper.event_log(), helper.rtcp_rtt_stats()); | 389 helper.bitrate_allocator(), helper.event_log(), helper.rtcp_rtt_stats()); |
339 } | 390 } |
340 | 391 |
341 TEST(AudioSendStreamTest, GetStats) { | 392 TEST(AudioSendStreamTest, GetStats) { |
342 ConfigHelper helper(false); | 393 ConfigHelper helper(false, true); |
343 internal::AudioSendStream send_stream( | 394 internal::AudioSendStream send_stream( |
344 helper.config(), helper.audio_state(), helper.worker_queue(), | 395 helper.config(), helper.audio_state(), helper.worker_queue(), |
345 helper.packet_router(), helper.congestion_controller(), | 396 helper.packet_router(), helper.congestion_controller(), |
346 helper.bitrate_allocator(), helper.event_log(), helper.rtcp_rtt_stats()); | 397 helper.bitrate_allocator(), helper.event_log(), helper.rtcp_rtt_stats()); |
347 helper.SetupMockForGetStats(); | 398 helper.SetupMockForGetStats(); |
348 AudioSendStream::Stats stats = send_stream.GetStats(); | 399 AudioSendStream::Stats stats = send_stream.GetStats(); |
349 EXPECT_EQ(kSsrc, stats.local_ssrc); | 400 EXPECT_EQ(kSsrc, stats.local_ssrc); |
350 EXPECT_EQ(static_cast<int64_t>(kCallStats.bytesSent), stats.bytes_sent); | 401 EXPECT_EQ(static_cast<int64_t>(kCallStats.bytesSent), stats.bytes_sent); |
351 EXPECT_EQ(kCallStats.packetsSent, stats.packets_sent); | 402 EXPECT_EQ(kCallStats.packetsSent, stats.packets_sent); |
352 EXPECT_EQ(static_cast<int32_t>(kReportBlock.cumulative_num_packets_lost), | 403 EXPECT_EQ(static_cast<int32_t>(kReportBlock.cumulative_num_packets_lost), |
(...skipping 10 matching lines...) Expand all Loading... |
363 EXPECT_EQ(-1, stats.aec_quality_min); | 414 EXPECT_EQ(-1, stats.aec_quality_min); |
364 EXPECT_EQ(kEchoDelayMedian, stats.echo_delay_median_ms); | 415 EXPECT_EQ(kEchoDelayMedian, stats.echo_delay_median_ms); |
365 EXPECT_EQ(kEchoDelayStdDev, stats.echo_delay_std_ms); | 416 EXPECT_EQ(kEchoDelayStdDev, stats.echo_delay_std_ms); |
366 EXPECT_EQ(kEchoReturnLoss, stats.echo_return_loss); | 417 EXPECT_EQ(kEchoReturnLoss, stats.echo_return_loss); |
367 EXPECT_EQ(kEchoReturnLossEnhancement, stats.echo_return_loss_enhancement); | 418 EXPECT_EQ(kEchoReturnLossEnhancement, stats.echo_return_loss_enhancement); |
368 EXPECT_EQ(kResidualEchoLikelihood, stats.residual_echo_likelihood); | 419 EXPECT_EQ(kResidualEchoLikelihood, stats.residual_echo_likelihood); |
369 EXPECT_FALSE(stats.typing_noise_detected); | 420 EXPECT_FALSE(stats.typing_noise_detected); |
370 } | 421 } |
371 | 422 |
372 TEST(AudioSendStreamTest, GetStatsTypingNoiseDetected) { | 423 TEST(AudioSendStreamTest, GetStatsTypingNoiseDetected) { |
373 ConfigHelper helper(false); | 424 ConfigHelper helper(false, true); |
374 internal::AudioSendStream send_stream( | 425 internal::AudioSendStream send_stream( |
375 helper.config(), helper.audio_state(), helper.worker_queue(), | 426 helper.config(), helper.audio_state(), helper.worker_queue(), |
376 helper.packet_router(), helper.congestion_controller(), | 427 helper.packet_router(), helper.congestion_controller(), |
377 helper.bitrate_allocator(), helper.event_log(), helper.rtcp_rtt_stats()); | 428 helper.bitrate_allocator(), helper.event_log(), helper.rtcp_rtt_stats()); |
378 helper.SetupMockForGetStats(); | 429 helper.SetupMockForGetStats(); |
379 EXPECT_FALSE(send_stream.GetStats().typing_noise_detected); | 430 EXPECT_FALSE(send_stream.GetStats().typing_noise_detected); |
380 | 431 |
381 internal::AudioState* internal_audio_state = | 432 internal::AudioState* internal_audio_state = |
382 static_cast<internal::AudioState*>(helper.audio_state().get()); | 433 static_cast<internal::AudioState*>(helper.audio_state().get()); |
383 VoiceEngineObserver* voe_observer = | 434 VoiceEngineObserver* voe_observer = |
384 static_cast<VoiceEngineObserver*>(internal_audio_state); | 435 static_cast<VoiceEngineObserver*>(internal_audio_state); |
385 voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_WARNING); | 436 voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_WARNING); |
386 EXPECT_TRUE(send_stream.GetStats().typing_noise_detected); | 437 EXPECT_TRUE(send_stream.GetStats().typing_noise_detected); |
387 voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_OFF_WARNING); | 438 voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_OFF_WARNING); |
388 EXPECT_FALSE(send_stream.GetStats().typing_noise_detected); | 439 EXPECT_FALSE(send_stream.GetStats().typing_noise_detected); |
389 } | 440 } |
390 | 441 |
391 TEST(AudioSendStreamTest, SendCodecAppliesConfigParams) { | 442 TEST(AudioSendStreamTest, SendCodecAppliesNetworkAdaptor) { |
392 ConfigHelper helper(false); | 443 ConfigHelper helper(false, true); |
393 auto stream_config = helper.config(); | 444 auto stream_config = helper.config(); |
394 const CodecInst kOpusCodec = {111, "opus", 48000, 960, 2, 64000}; | 445 stream_config.send_codec_spec = |
395 stream_config.send_codec_spec.codec_inst = kOpusCodec; | 446 rtc::Optional<AudioSendStream::Config::SendCodecSpec>({0, kOpusFormat}); |
396 stream_config.send_codec_spec.enable_codec_fec = true; | |
397 stream_config.send_codec_spec.enable_opus_dtx = true; | |
398 stream_config.send_codec_spec.opus_max_playback_rate = 12345; | |
399 stream_config.send_codec_spec.cng_plfreq = 16000; | |
400 stream_config.send_codec_spec.cng_payload_type = 105; | |
401 stream_config.send_codec_spec.min_ptime_ms = 10; | |
402 stream_config.send_codec_spec.max_ptime_ms = 60; | |
403 stream_config.audio_network_adaptor_config = | 447 stream_config.audio_network_adaptor_config = |
404 rtc::Optional<std::string>("abced"); | 448 rtc::Optional<std::string>("abced"); |
405 EXPECT_CALL(*helper.channel_proxy(), SetCodecFECStatus(true)) | 449 |
406 .WillOnce(Return(true)); | 450 EXPECT_CALL(helper.mock_encoder_factory(), MakeAudioEncoderMock(_, _, _)) |
407 EXPECT_CALL( | 451 .WillOnce(Invoke([](int payload_type, const SdpAudioFormat& format, |
408 *helper.channel_proxy(), | 452 std::unique_ptr<AudioEncoder>* return_value) { |
409 SetOpusDtx(stream_config.send_codec_spec.enable_opus_dtx)) | 453 auto mock_encoder = SetupAudioEncoderMock(payload_type, format); |
410 .WillOnce(Return(true)); | 454 EXPECT_CALL(*mock_encoder.get(), EnableAudioNetworkAdaptor(_, _, _)) |
411 EXPECT_CALL( | 455 .WillOnce(Return(true)); |
412 *helper.channel_proxy(), | 456 *return_value = std::move(mock_encoder); |
413 SetOpusMaxPlaybackRate( | 457 })); |
414 stream_config.send_codec_spec.opus_max_playback_rate)) | 458 |
415 .WillOnce(Return(true)); | |
416 EXPECT_CALL(*helper.channel_proxy(), | |
417 SetSendCNPayloadType( | |
418 stream_config.send_codec_spec.cng_payload_type, | |
419 webrtc::kFreq16000Hz)) | |
420 .WillOnce(Return(true)); | |
421 EXPECT_CALL( | |
422 *helper.channel_proxy(), | |
423 SetReceiverFrameLengthRange(stream_config.send_codec_spec.min_ptime_ms, | |
424 stream_config.send_codec_spec.max_ptime_ms)); | |
425 EXPECT_CALL( | |
426 *helper.channel_proxy(), | |
427 EnableAudioNetworkAdaptor(*stream_config.audio_network_adaptor_config)); | |
428 internal::AudioSendStream send_stream( | 459 internal::AudioSendStream send_stream( |
429 stream_config, helper.audio_state(), helper.worker_queue(), | 460 stream_config, helper.audio_state(), helper.worker_queue(), |
430 helper.packet_router(), helper.congestion_controller(), | 461 helper.packet_router(), helper.congestion_controller(), |
431 helper.bitrate_allocator(), helper.event_log(), helper.rtcp_rtt_stats()); | 462 helper.bitrate_allocator(), helper.event_log(), helper.rtcp_rtt_stats()); |
432 } | 463 } |
433 | 464 |
434 // VAD is applied when codec is mono and the CNG frequency matches the codec | 465 // VAD is applied when codec is mono and the CNG frequency matches the codec |
435 // sample rate. | 466 // clock rate. |
436 TEST(AudioSendStreamTest, SendCodecCanApplyVad) { | 467 TEST(AudioSendStreamTest, SendCodecCanApplyVad) { |
437 ConfigHelper helper(false); | 468 ConfigHelper helper(false, false); |
438 auto stream_config = helper.config(); | 469 auto stream_config = helper.config(); |
439 const CodecInst kG722Codec = {9, "g722", 8000, 160, 1, 16000}; | 470 stream_config.send_codec_spec = |
440 stream_config.send_codec_spec.codec_inst = kG722Codec; | 471 rtc::Optional<AudioSendStream::Config::SendCodecSpec>({9, kG722Format}); |
441 stream_config.send_codec_spec.cng_plfreq = 8000; | 472 stream_config.send_codec_spec->cng_payload_type = 105; |
442 stream_config.send_codec_spec.cng_payload_type = 105; | 473 using ::testing::Invoke; |
443 EXPECT_CALL(*helper.channel_proxy(), SetVADStatus(true)) | 474 std::unique_ptr<AudioEncoder> stolen_encoder; |
444 .WillOnce(Return(true)); | 475 EXPECT_CALL(*helper.channel_proxy(), SetEncoderForMock(_, _)) |
| 476 .WillOnce(Invoke([&stolen_encoder]( |
| 477 int payload_type, std::unique_ptr<AudioEncoder>* encoder) { |
| 478 stolen_encoder = std::move(*encoder); |
| 479 return true; |
| 480 })); |
| 481 |
445 internal::AudioSendStream send_stream( | 482 internal::AudioSendStream send_stream( |
446 stream_config, helper.audio_state(), helper.worker_queue(), | 483 stream_config, helper.audio_state(), helper.worker_queue(), |
447 helper.packet_router(), helper.congestion_controller(), | 484 helper.packet_router(), helper.congestion_controller(), |
448 helper.bitrate_allocator(), helper.event_log(), helper.rtcp_rtt_stats()); | 485 helper.bitrate_allocator(), helper.event_log(), helper.rtcp_rtt_stats()); |
| 486 |
| 487 // We cannot truly determine if the encoder created is an AudioEncoderCng. It |
| 488 // is the only reasonable implementation that will return something from |
| 489 // ReclaimContainedEncoders, though. |
| 490 ASSERT_TRUE(stolen_encoder); |
| 491 EXPECT_FALSE(stolen_encoder->ReclaimContainedEncoders().empty()); |
449 } | 492 } |
450 | 493 |
451 TEST(AudioSendStreamTest, DoesNotPassHigherBitrateThanMaxBitrate) { | 494 TEST(AudioSendStreamTest, DoesNotPassHigherBitrateThanMaxBitrate) { |
452 ConfigHelper helper(false); | 495 ConfigHelper helper(false, true); |
453 internal::AudioSendStream send_stream( | 496 internal::AudioSendStream send_stream( |
454 helper.config(), helper.audio_state(), helper.worker_queue(), | 497 helper.config(), helper.audio_state(), helper.worker_queue(), |
455 helper.packet_router(), helper.congestion_controller(), | 498 helper.packet_router(), helper.congestion_controller(), |
456 helper.bitrate_allocator(), helper.event_log(), helper.rtcp_rtt_stats()); | 499 helper.bitrate_allocator(), helper.event_log(), helper.rtcp_rtt_stats()); |
457 EXPECT_CALL(*helper.channel_proxy(), | 500 EXPECT_CALL(*helper.channel_proxy(), |
458 SetBitrate(helper.config().max_bitrate_bps, _)); | 501 SetBitrate(helper.config().max_bitrate_bps, _)); |
459 send_stream.OnBitrateUpdated(helper.config().max_bitrate_bps + 5000, 0.0, 50, | 502 send_stream.OnBitrateUpdated(helper.config().max_bitrate_bps + 5000, 0.0, 50, |
460 6000); | 503 6000); |
461 } | 504 } |
462 | 505 |
463 TEST(AudioSendStreamTest, ProbingIntervalOnBitrateUpdated) { | 506 TEST(AudioSendStreamTest, ProbingIntervalOnBitrateUpdated) { |
464 ConfigHelper helper(false); | 507 ConfigHelper helper(false, true); |
465 internal::AudioSendStream send_stream( | 508 internal::AudioSendStream send_stream( |
466 helper.config(), helper.audio_state(), helper.worker_queue(), | 509 helper.config(), helper.audio_state(), helper.worker_queue(), |
467 helper.packet_router(), helper.congestion_controller(), | 510 helper.packet_router(), helper.congestion_controller(), |
468 helper.bitrate_allocator(), helper.event_log(), helper.rtcp_rtt_stats()); | 511 helper.bitrate_allocator(), helper.event_log(), helper.rtcp_rtt_stats()); |
469 EXPECT_CALL(*helper.channel_proxy(), SetBitrate(_, 5000)); | 512 EXPECT_CALL(*helper.channel_proxy(), SetBitrate(_, 5000)); |
470 send_stream.OnBitrateUpdated(50000, 0.0, 50, 5000); | 513 send_stream.OnBitrateUpdated(50000, 0.0, 50, 5000); |
471 } | 514 } |
472 | 515 |
473 } // namespace test | 516 } // namespace test |
474 } // namespace webrtc | 517 } // namespace webrtc |
OLD | NEW |