Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: webrtc/audio/audio_send_stream_unittest.cc

Issue 2705093002: Injectable audio encoders: WebRtcVoiceEngine and company (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <vector> 12 #include <vector>
13 13
14 #include "webrtc/audio/audio_send_stream.h" 14 #include "webrtc/audio/audio_send_stream.h"
15 #include "webrtc/audio/audio_state.h" 15 #include "webrtc/audio/audio_state.h"
16 #include "webrtc/audio/conversion.h" 16 #include "webrtc/audio/conversion.h"
17 #include "webrtc/base/task_queue.h" 17 #include "webrtc/base/task_queue.h"
18 #include "webrtc/logging/rtc_event_log/mock/mock_rtc_event_log.h" 18 #include "webrtc/logging/rtc_event_log/mock/mock_rtc_event_log.h"
19 #include "webrtc/modules/audio_coding/codecs/builtin_audio_encoder_factory.h"
19 #include "webrtc/modules/audio_mixer/audio_mixer_impl.h" 20 #include "webrtc/modules/audio_mixer/audio_mixer_impl.h"
20 #include "webrtc/modules/audio_processing/include/mock_audio_processing.h" 21 #include "webrtc/modules/audio_processing/include/mock_audio_processing.h"
21 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" 22 #include "webrtc/modules/congestion_controller/include/congestion_controller.h"
22 #include "webrtc/modules/congestion_controller/include/mock/mock_congestion_cont roller.h" 23 #include "webrtc/modules/congestion_controller/include/mock/mock_congestion_cont roller.h"
23 #include "webrtc/modules/pacing/paced_sender.h" 24 #include "webrtc/modules/pacing/paced_sender.h"
24 #include "webrtc/modules/remote_bitrate_estimator/include/mock/mock_remote_bitra te_estimator.h" 25 #include "webrtc/modules/remote_bitrate_estimator/include/mock/mock_remote_bitra te_estimator.h"
25 #include "webrtc/modules/rtp_rtcp/mocks/mock_rtcp_rtt_stats.h" 26 #include "webrtc/modules/rtp_rtcp/mocks/mock_rtcp_rtt_stats.h"
26 #include "webrtc/test/gtest.h" 27 #include "webrtc/test/gtest.h"
27 #include "webrtc/test/mock_voe_channel_proxy.h" 28 #include "webrtc/test/mock_voe_channel_proxy.h"
28 #include "webrtc/test/mock_voice_engine.h" 29 #include "webrtc/test/mock_voice_engine.h"
(...skipping 19 matching lines...) Expand all
48 const float kResidualEchoLikelihood = -1.0f; 49 const float kResidualEchoLikelihood = -1.0f;
49 const unsigned int kSpeechInputLevel = 96; 50 const unsigned int kSpeechInputLevel = 96;
50 const CallStatistics kCallStats = { 51 const CallStatistics kCallStats = {
51 1345, 1678, 1901, 1234, 112, 13456, 17890, 1567, -1890, -1123}; 52 1345, 1678, 1901, 1234, 112, 13456, 17890, 1567, -1890, -1123};
52 const ReportBlock kReportBlock = {456, 780, 123, 567, 890, 132, 143, 13354}; 53 const ReportBlock kReportBlock = {456, 780, 123, 567, 890, 132, 143, 13354};
53 const int kTelephoneEventPayloadType = 123; 54 const int kTelephoneEventPayloadType = 123;
54 const int kTelephoneEventPayloadFrequency = 65432; 55 const int kTelephoneEventPayloadFrequency = 65432;
55 const int kTelephoneEventCode = 45; 56 const int kTelephoneEventCode = 45;
56 const int kTelephoneEventDuration = 6789; 57 const int kTelephoneEventDuration = 6789;
57 const CodecInst kIsacCodec = {103, "isac", 16000, 320, 1, 32000}; 58 const CodecInst kIsacCodec = {103, "isac", 16000, 320, 1, 32000};
59 const int kIsacPayloadType = 103;
60 const SdpAudioFormat kIsacFormat = {"isac", 16000, 1};
58 61
59 class MockLimitObserver : public BitrateAllocator::LimitObserver { 62 class MockLimitObserver : public BitrateAllocator::LimitObserver {
60 public: 63 public:
61 MOCK_METHOD2(OnAllocationLimitsChanged, 64 MOCK_METHOD2(OnAllocationLimitsChanged,
62 void(uint32_t min_send_bitrate_bps, 65 void(uint32_t min_send_bitrate_bps,
63 uint32_t max_padding_bitrate_bps)); 66 uint32_t max_padding_bitrate_bps));
64 }; 67 };
65 68
66 struct ConfigHelper { 69 struct ConfigHelper {
67 explicit ConfigHelper(bool audio_bwe_enabled) 70 explicit ConfigHelper(bool audio_bwe_enabled)
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 stream_config_.rtp.extensions.push_back( 108 stream_config_.rtp.extensions.push_back(
106 RtpExtension(RtpExtension::kAudioLevelUri, kAudioLevelId)); 109 RtpExtension(RtpExtension::kAudioLevelUri, kAudioLevelId));
107 if (audio_bwe_enabled) { 110 if (audio_bwe_enabled) {
108 stream_config_.rtp.extensions.push_back( 111 stream_config_.rtp.extensions.push_back(
109 RtpExtension(RtpExtension::kTransportSequenceNumberUri, 112 RtpExtension(RtpExtension::kTransportSequenceNumberUri,
110 kTransportSequenceNumberId)); 113 kTransportSequenceNumberId));
111 stream_config_.send_codec_spec.transport_cc_enabled = true; 114 stream_config_.send_codec_spec.transport_cc_enabled = true;
112 } 115 }
113 // Use ISAC as default codec so as to prevent unnecessary |voice_engine_| 116 // Use ISAC as default codec so as to prevent unnecessary |voice_engine_|
114 // calls from the default ctor behavior. 117 // calls from the default ctor behavior.
115 stream_config_.send_codec_spec.codec_inst = kIsacCodec; 118 stream_config_.send_codec_spec.payload_type = kIsacPayloadType;
119 stream_config_.send_codec_spec.format.format = kIsacFormat;
116 stream_config_.min_bitrate_bps = 10000; 120 stream_config_.min_bitrate_bps = 10000;
117 stream_config_.max_bitrate_bps = 65000; 121 stream_config_.max_bitrate_bps = 65000;
118 } 122 }
119 123
120 AudioSendStream::Config& config() { return stream_config_; } 124 AudioSendStream::Config& config() { return stream_config_; }
121 rtc::scoped_refptr<AudioState> audio_state() { return audio_state_; } 125 rtc::scoped_refptr<AudioState> audio_state() { return audio_state_; }
122 MockVoEChannelProxy* channel_proxy() { return channel_proxy_; } 126 MockVoEChannelProxy* channel_proxy() { return channel_proxy_; }
123 PacketRouter* packet_router() { return &packet_router_; } 127 PacketRouter* packet_router() { return &packet_router_; }
124 CongestionController* congestion_controller() { 128 CongestionController* congestion_controller() {
125 return &congestion_controller_; 129 return &congestion_controller_;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 EXPECT_CALL(*channel_proxy_, SetRtcpRttStats(testing::IsNull())) 172 EXPECT_CALL(*channel_proxy_, SetRtcpRttStats(testing::IsNull()))
169 .Times(1); // Destructor resets the rtt stats. 173 .Times(1); // Destructor resets the rtt stats.
170 } 174 }
171 175
172 void SetupMockForSetupSendCodec() { 176 void SetupMockForSetupSendCodec() {
173 EXPECT_CALL(*channel_proxy_, SetVADStatus(false)) 177 EXPECT_CALL(*channel_proxy_, SetVADStatus(false))
174 .WillOnce(Return(true)); 178 .WillOnce(Return(true));
175 EXPECT_CALL(*channel_proxy_, SetCodecFECStatus(false)) 179 EXPECT_CALL(*channel_proxy_, SetCodecFECStatus(false))
176 .WillOnce(Return(true)); 180 .WillOnce(Return(true));
177 EXPECT_CALL(*channel_proxy_, DisableAudioNetworkAdaptor()); 181 EXPECT_CALL(*channel_proxy_, DisableAudioNetworkAdaptor());
178 // Let |GetSendCodec| return false for the first time to indicate that no 182 EXPECT_CALL(*channel_proxy_, SetSendFormat(_, _, _)).WillOnce(Return(true));
179 // send codec has been set. 183 // These should no longer be called.
180 EXPECT_CALL(*channel_proxy_, GetSendCodec(_)).WillOnce(Return(false)); 184 EXPECT_CALL(*channel_proxy_, GetSendCodec(_))
181 EXPECT_CALL(*channel_proxy_, SetSendCodec(_)).WillOnce(Return(true)); 185 .Times(0);
kwiberg-webrtc 2017/02/21 23:35:03 Won't clang-format remove this line break?
186 EXPECT_CALL(*channel_proxy_, SetSendCodec(_)).Times(0);
182 } 187 }
183 RtcpRttStats* rtcp_rtt_stats() { return &rtcp_rtt_stats_; } 188 RtcpRttStats* rtcp_rtt_stats() { return &rtcp_rtt_stats_; }
184 189
185 void SetupMockForSendTelephoneEvent() { 190 void SetupMockForSendTelephoneEvent() {
186 EXPECT_TRUE(channel_proxy_); 191 EXPECT_TRUE(channel_proxy_);
187 EXPECT_CALL(*channel_proxy_, 192 EXPECT_CALL(*channel_proxy_,
188 SetSendTelephoneEventPayloadType(kTelephoneEventPayloadType, 193 SetSendTelephoneEventPayloadType(kTelephoneEventPayloadType,
189 kTelephoneEventPayloadFrequency)) 194 kTelephoneEventPayloadFrequency))
190 .WillOnce(Return(true)); 195 .WillOnce(Return(true));
191 EXPECT_CALL(*channel_proxy_, 196 EXPECT_CALL(*channel_proxy_,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 261
257 TEST(AudioSendStreamTest, ConfigToString) { 262 TEST(AudioSendStreamTest, ConfigToString) {
258 AudioSendStream::Config config(nullptr); 263 AudioSendStream::Config config(nullptr);
259 config.rtp.ssrc = kSsrc; 264 config.rtp.ssrc = kSsrc;
260 config.rtp.c_name = kCName; 265 config.rtp.c_name = kCName;
261 config.voe_channel_id = kChannelId; 266 config.voe_channel_id = kChannelId;
262 config.min_bitrate_bps = 12000; 267 config.min_bitrate_bps = 12000;
263 config.max_bitrate_bps = 34000; 268 config.max_bitrate_bps = 34000;
264 config.send_codec_spec.nack_enabled = true; 269 config.send_codec_spec.nack_enabled = true;
265 config.send_codec_spec.transport_cc_enabled = false; 270 config.send_codec_spec.transport_cc_enabled = false;
266 config.send_codec_spec.enable_codec_fec = true;
267 config.send_codec_spec.enable_opus_dtx = false;
268 config.send_codec_spec.opus_max_playback_rate = 32000;
269 config.send_codec_spec.cng_payload_type = 42; 271 config.send_codec_spec.cng_payload_type = 42;
270 config.send_codec_spec.cng_plfreq = 56; 272 config.send_codec_spec.cng_plfreq = 56;
271 config.send_codec_spec.min_ptime_ms = 20; 273 config.send_codec_spec.payload_type = kIsacPayloadType;
272 config.send_codec_spec.max_ptime_ms = 60; 274 config.send_codec_spec.format.format = kIsacFormat;
273 config.send_codec_spec.codec_inst = kIsacCodec; 275 // TODO(ossu): Maybe mock this?
276 config.encoder_factory = CreateBuiltinAudioEncoderFactory();
274 config.rtp.extensions.push_back( 277 config.rtp.extensions.push_back(
275 RtpExtension(RtpExtension::kAudioLevelUri, kAudioLevelId)); 278 RtpExtension(RtpExtension::kAudioLevelUri, kAudioLevelId));
276 EXPECT_EQ( 279 EXPECT_EQ(
277 "{rtp: {ssrc: 1234, extensions: [{uri: " 280 "{rtp: {ssrc: 1234, extensions: [{uri: "
278 "urn:ietf:params:rtp-hdrext:ssrc-audio-level, id: 2}], nack: " 281 "urn:ietf:params:rtp-hdrext:ssrc-audio-level, id: 2}], nack: "
279 "{rtp_history_ms: 0}, c_name: foo_name}, send_transport: nullptr, " 282 "{rtp_history_ms: 0}, c_name: foo_name}, send_transport: nullptr, "
280 "voe_channel_id: 1, min_bitrate_bps: 12000, max_bitrate_bps: 34000, " 283 "voe_channel_id: 1, min_bitrate_bps: 12000, max_bitrate_bps: 34000, "
281 "send_codec_spec: {nack_enabled: true, transport_cc_enabled: false, " 284 "send_codec_spec: {nack_enabled: true, transport_cc_enabled: false, "
282 "enable_codec_fec: true, enable_opus_dtx: false, opus_max_playback_rate: " 285 "cng_payload_type: 42, cng_plfreq: 56, payload_type: 103, "
283 "32000, cng_payload_type: 42, cng_plfreq: 56, min_ptime: 20, max_ptime: " 286 "format: {name: isac, clockrate_hz: 16000, num_channels: 1, "
284 "60, codec_inst: {pltype: 103, plname: \"isac\", plfreq: 16000, pacsize: " 287 "parameters: {}}}}",
285 "320, channels: 1, rate: 32000}}}",
286 config.ToString()); 288 config.ToString());
287 } 289 }
288 290
289 TEST(AudioSendStreamTest, ConstructDestruct) { 291 TEST(AudioSendStreamTest, ConstructDestruct) {
290 ConfigHelper helper(false); 292 ConfigHelper helper(false);
291 internal::AudioSendStream send_stream( 293 internal::AudioSendStream send_stream(
292 helper.config(), helper.audio_state(), helper.worker_queue(), 294 helper.config(), helper.audio_state(), helper.worker_queue(),
293 helper.packet_router(), helper.congestion_controller(), 295 helper.packet_router(), helper.congestion_controller(),
294 helper.bitrate_allocator(), helper.event_log(), helper.rtcp_rtt_stats()); 296 helper.bitrate_allocator(), helper.event_log(), helper.rtcp_rtt_stats());
295 } 297 }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 static_cast<VoiceEngineObserver*>(internal_audio_state); 380 static_cast<VoiceEngineObserver*>(internal_audio_state);
379 voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_WARNING); 381 voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_WARNING);
380 EXPECT_TRUE(send_stream.GetStats().typing_noise_detected); 382 EXPECT_TRUE(send_stream.GetStats().typing_noise_detected);
381 voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_OFF_WARNING); 383 voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_OFF_WARNING);
382 EXPECT_FALSE(send_stream.GetStats().typing_noise_detected); 384 EXPECT_FALSE(send_stream.GetStats().typing_noise_detected);
383 } 385 }
384 386
385 TEST(AudioSendStreamTest, SendCodecAppliesConfigParams) { 387 TEST(AudioSendStreamTest, SendCodecAppliesConfigParams) {
386 ConfigHelper helper(false); 388 ConfigHelper helper(false);
387 auto stream_config = helper.config(); 389 auto stream_config = helper.config();
388 const CodecInst kOpusCodec = {111, "opus", 48000, 960, 2, 64000}; 390 const webrtc::SdpAudioFormat kOpusFormat = {"opus", 48000, 2};
kwiberg-webrtc 2017/02/21 23:35:03 Too bad we can't make this constexpr. Remind me to
389 stream_config.send_codec_spec.codec_inst = kOpusCodec; 391 stream_config.send_codec_spec.format.format = kOpusFormat;
390 stream_config.send_codec_spec.enable_codec_fec = true;
391 stream_config.send_codec_spec.enable_opus_dtx = true;
392 stream_config.send_codec_spec.opus_max_playback_rate = 12345;
393 stream_config.send_codec_spec.cng_plfreq = 16000; 392 stream_config.send_codec_spec.cng_plfreq = 16000;
394 stream_config.send_codec_spec.cng_payload_type = 105; 393 stream_config.send_codec_spec.cng_payload_type = 105;
395 stream_config.send_codec_spec.min_ptime_ms = 10;
396 stream_config.send_codec_spec.max_ptime_ms = 60;
397 stream_config.audio_network_adaptor_config = 394 stream_config.audio_network_adaptor_config =
398 rtc::Optional<std::string>("abced"); 395 rtc::Optional<std::string>("abced");
399 EXPECT_CALL(*helper.channel_proxy(), SetCodecFECStatus(true))
400 .WillOnce(Return(true));
401 EXPECT_CALL(
402 *helper.channel_proxy(),
403 SetOpusDtx(stream_config.send_codec_spec.enable_opus_dtx))
404 .WillOnce(Return(true));
405 EXPECT_CALL(
406 *helper.channel_proxy(),
407 SetOpusMaxPlaybackRate(
408 stream_config.send_codec_spec.opus_max_playback_rate))
409 .WillOnce(Return(true));
410 EXPECT_CALL(*helper.channel_proxy(), 396 EXPECT_CALL(*helper.channel_proxy(),
411 SetSendCNPayloadType( 397 SetSendCNPayloadType(
412 stream_config.send_codec_spec.cng_payload_type, 398 stream_config.send_codec_spec.cng_payload_type,
413 webrtc::kFreq16000Hz)) 399 webrtc::kFreq16000Hz))
414 .WillOnce(Return(true)); 400 .WillOnce(Return(true));
415 EXPECT_CALL( 401 EXPECT_CALL(
416 *helper.channel_proxy(), 402 *helper.channel_proxy(),
417 SetReceiverFrameLengthRange(stream_config.send_codec_spec.min_ptime_ms,
418 stream_config.send_codec_spec.max_ptime_ms));
419 EXPECT_CALL(
420 *helper.channel_proxy(),
421 EnableAudioNetworkAdaptor(*stream_config.audio_network_adaptor_config)); 403 EnableAudioNetworkAdaptor(*stream_config.audio_network_adaptor_config));
422 internal::AudioSendStream send_stream( 404 internal::AudioSendStream send_stream(
423 stream_config, helper.audio_state(), helper.worker_queue(), 405 stream_config, helper.audio_state(), helper.worker_queue(),
424 helper.packet_router(), helper.congestion_controller(), 406 helper.packet_router(), helper.congestion_controller(),
425 helper.bitrate_allocator(), helper.event_log(), helper.rtcp_rtt_stats()); 407 helper.bitrate_allocator(), helper.event_log(), helper.rtcp_rtt_stats());
426 } 408 }
427 409
428 // VAD is applied when codec is mono and the CNG frequency matches the codec 410 // VAD is applied when codec is mono and the CNG frequency matches the codec
429 // sample rate. 411 // sample rate.
430 TEST(AudioSendStreamTest, SendCodecCanApplyVad) { 412 TEST(AudioSendStreamTest, SendCodecCanApplyVad) {
431 ConfigHelper helper(false); 413 ConfigHelper helper(false);
432 auto stream_config = helper.config(); 414 auto stream_config = helper.config();
433 const CodecInst kG722Codec = {9, "g722", 8000, 160, 1, 16000}; 415 stream_config.send_codec_spec.payload_type = 9;
434 stream_config.send_codec_spec.codec_inst = kG722Codec; 416 stream_config.send_codec_spec.format.format = {"g722", 8000, 1};
417 stream_config.send_codec_spec.format.info = {16000, 1, 64000};
435 stream_config.send_codec_spec.cng_plfreq = 8000; 418 stream_config.send_codec_spec.cng_plfreq = 8000;
436 stream_config.send_codec_spec.cng_payload_type = 105; 419 stream_config.send_codec_spec.cng_payload_type = 105;
437 EXPECT_CALL(*helper.channel_proxy(), SetVADStatus(true)) 420 EXPECT_CALL(*helper.channel_proxy(), SetVADStatus(true))
438 .WillOnce(Return(true)); 421 .WillOnce(Return(true));
439 internal::AudioSendStream send_stream( 422 internal::AudioSendStream send_stream(
440 stream_config, helper.audio_state(), helper.worker_queue(), 423 stream_config, helper.audio_state(), helper.worker_queue(),
441 helper.packet_router(), helper.congestion_controller(), 424 helper.packet_router(), helper.congestion_controller(),
442 helper.bitrate_allocator(), helper.event_log(), helper.rtcp_rtt_stats()); 425 helper.bitrate_allocator(), helper.event_log(), helper.rtcp_rtt_stats());
443 } 426 }
444 427
(...skipping 14 matching lines...) Expand all
459 internal::AudioSendStream send_stream( 442 internal::AudioSendStream send_stream(
460 helper.config(), helper.audio_state(), helper.worker_queue(), 443 helper.config(), helper.audio_state(), helper.worker_queue(),
461 helper.packet_router(), helper.congestion_controller(), 444 helper.packet_router(), helper.congestion_controller(),
462 helper.bitrate_allocator(), helper.event_log(), helper.rtcp_rtt_stats()); 445 helper.bitrate_allocator(), helper.event_log(), helper.rtcp_rtt_stats());
463 EXPECT_CALL(*helper.channel_proxy(), SetBitrate(_, 5000)); 446 EXPECT_CALL(*helper.channel_proxy(), SetBitrate(_, 5000));
464 send_stream.OnBitrateUpdated(50000, 0.0, 50, 5000); 447 send_stream.OnBitrateUpdated(50000, 0.0, 50, 5000);
465 } 448 }
466 449
467 } // namespace test 450 } // namespace test
468 } // namespace webrtc 451 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698