| OLD | NEW | 
|     1 /* |     1 /* | 
|     2  *  Copyright (c) 2008 The WebRTC project authors. All Rights Reserved. |     2  *  Copyright (c) 2008 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 <memory> |    11 #include <memory> | 
|    12  |    12  | 
|    13 #include "webrtc/pc/channel.h" |    13 #include "webrtc/pc/channel.h" | 
|    14 #include "webrtc/base/arraysize.h" |    14 #include "webrtc/base/arraysize.h" | 
|    15 #include "webrtc/base/byteorder.h" |    15 #include "webrtc/base/byteorder.h" | 
|    16 #include "webrtc/base/gunit.h" |    16 #include "webrtc/base/gunit.h" | 
|    17 #include "webrtc/call.h" |    17 #include "webrtc/call.h" | 
|    18 #include "webrtc/p2p/base/faketransportcontroller.h" |    18 #include "webrtc/p2p/base/faketransportcontroller.h" | 
|    19 #include "webrtc/test/field_trial.h" |    19 #include "webrtc/test/field_trial.h" | 
 |    20 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" | 
|    20 #include "webrtc/media/base/fakemediaengine.h" |    21 #include "webrtc/media/base/fakemediaengine.h" | 
|    21 #include "webrtc/media/base/fakenetworkinterface.h" |    22 #include "webrtc/media/base/fakenetworkinterface.h" | 
|    22 #include "webrtc/media/base/fakertp.h" |    23 #include "webrtc/media/base/fakertp.h" | 
|    23 #include "webrtc/media/base/mediaconstants.h" |    24 #include "webrtc/media/base/mediaconstants.h" | 
|    24 #include "webrtc/media/engine/fakewebrtccall.h" |    25 #include "webrtc/media/engine/fakewebrtccall.h" | 
|    25 #include "webrtc/media/engine/fakewebrtcvoiceengine.h" |    26 #include "webrtc/media/engine/fakewebrtcvoiceengine.h" | 
|    26 #include "webrtc/media/engine/webrtcvoiceengine.h" |    27 #include "webrtc/media/engine/webrtcvoiceengine.h" | 
|    27 #include "webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.h" |    28 #include "webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.h" | 
|    28 #include "webrtc/modules/audio_coding/codecs/mock/mock_audio_decoder_factory.h" |    29 #include "webrtc/modules/audio_coding/codecs/mock/mock_audio_decoder_factory.h" | 
|    29 #include "webrtc/modules/audio_device/include/mock_audio_device.h" |    30 #include "webrtc/modules/audio_device/include/mock_audio_device.h" | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
|    55 class FakeVoEWrapper : public cricket::VoEWrapper { |    56 class FakeVoEWrapper : public cricket::VoEWrapper { | 
|    56  public: |    57  public: | 
|    57   explicit FakeVoEWrapper(cricket::FakeWebRtcVoiceEngine* engine) |    58   explicit FakeVoEWrapper(cricket::FakeWebRtcVoiceEngine* engine) | 
|    58       : cricket::VoEWrapper(engine,  // processing |    59       : cricket::VoEWrapper(engine,  // processing | 
|    59                             engine,  // base |    60                             engine,  // base | 
|    60                             engine,  // codec |    61                             engine,  // codec | 
|    61                             engine,  // hw |    62                             engine,  // hw | 
|    62                             engine) {  // volume |    63                             engine) {  // volume | 
|    63   } |    64   } | 
|    64 }; |    65 }; | 
 |    66  | 
|    65 }  // namespace |    67 }  // namespace | 
|    66  |    68  | 
|    67 // Tests that our stub library "works". |    69 // Tests that our stub library "works". | 
|    68 TEST(WebRtcVoiceEngineTestStubLibrary, StartupShutdown) { |    70 TEST(WebRtcVoiceEngineTestStubLibrary, StartupShutdown) { | 
|    69   StrictMock<webrtc::test::MockAudioDeviceModule> adm; |    71   StrictMock<webrtc::test::MockAudioDeviceModule> adm; | 
|    70   EXPECT_CALL(adm, AddRef()).WillOnce(Return(0)); |    72   EXPECT_CALL(adm, AddRef()).WillOnce(Return(0)); | 
|    71   EXPECT_CALL(adm, Release()).WillOnce(Return(0)); |    73   EXPECT_CALL(adm, Release()).WillOnce(Return(0)); | 
|    72   EXPECT_CALL(adm, BuiltInAECIsAvailable()).WillOnce(Return(false)); |    74   EXPECT_CALL(adm, BuiltInAECIsAvailable()).WillOnce(Return(false)); | 
|    73   EXPECT_CALL(adm, BuiltInAGCIsAvailable()).WillOnce(Return(false)); |    75   EXPECT_CALL(adm, BuiltInAGCIsAvailable()).WillOnce(Return(false)); | 
|    74   EXPECT_CALL(adm, BuiltInNSIsAvailable()).WillOnce(Return(false)); |    76   EXPECT_CALL(adm, BuiltInNSIsAvailable()).WillOnce(Return(false)); | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
|    90  |    92  | 
|    91 class FakeAudioSource : public cricket::AudioSource { |    93 class FakeAudioSource : public cricket::AudioSource { | 
|    92   void SetSink(Sink* sink) override {} |    94   void SetSink(Sink* sink) override {} | 
|    93 }; |    95 }; | 
|    94  |    96  | 
|    95 class WebRtcVoiceEngineTestFake : public testing::Test { |    97 class WebRtcVoiceEngineTestFake : public testing::Test { | 
|    96  public: |    98  public: | 
|    97   WebRtcVoiceEngineTestFake() : WebRtcVoiceEngineTestFake("") {} |    99   WebRtcVoiceEngineTestFake() : WebRtcVoiceEngineTestFake("") {} | 
|    98  |   100  | 
|    99   explicit WebRtcVoiceEngineTestFake(const char* field_trials) |   101   explicit WebRtcVoiceEngineTestFake(const char* field_trials) | 
|   100       : call_(webrtc::Call::Config()), override_field_trials_(field_trials) { |   102       : call_(webrtc::Call::Config(&event_log_)), | 
 |   103         override_field_trials_(field_trials) { | 
|   101     auto factory = webrtc::MockAudioDecoderFactory::CreateUnusedFactory(); |   104     auto factory = webrtc::MockAudioDecoderFactory::CreateUnusedFactory(); | 
|   102     EXPECT_CALL(adm_, AddRef()).WillOnce(Return(0)); |   105     EXPECT_CALL(adm_, AddRef()).WillOnce(Return(0)); | 
|   103     EXPECT_CALL(adm_, Release()).WillOnce(Return(0)); |   106     EXPECT_CALL(adm_, Release()).WillOnce(Return(0)); | 
|   104     EXPECT_CALL(adm_, BuiltInAECIsAvailable()).WillOnce(Return(false)); |   107     EXPECT_CALL(adm_, BuiltInAECIsAvailable()).WillOnce(Return(false)); | 
|   105     EXPECT_CALL(adm_, BuiltInAGCIsAvailable()).WillOnce(Return(false)); |   108     EXPECT_CALL(adm_, BuiltInAGCIsAvailable()).WillOnce(Return(false)); | 
|   106     EXPECT_CALL(adm_, BuiltInNSIsAvailable()).WillOnce(Return(false)); |   109     EXPECT_CALL(adm_, BuiltInNSIsAvailable()).WillOnce(Return(false)); | 
|   107     engine_.reset(new cricket::WebRtcVoiceEngine(&adm_, factory, |   110     engine_.reset(new cricket::WebRtcVoiceEngine(&adm_, factory, | 
|   108                                                  new FakeVoEWrapper(&voe_))); |   111                                                  new FakeVoEWrapper(&voe_))); | 
|   109     send_parameters_.codecs.push_back(kPcmuCodec); |   112     send_parameters_.codecs.push_back(kPcmuCodec); | 
|   110     recv_parameters_.codecs.push_back(kPcmuCodec); |   113     recv_parameters_.codecs.push_back(kPcmuCodec); | 
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   485     EXPECT_EQ(info.decoding_normal, stats.decoding_normal); |   488     EXPECT_EQ(info.decoding_normal, stats.decoding_normal); | 
|   486     EXPECT_EQ(info.decoding_plc, stats.decoding_plc); |   489     EXPECT_EQ(info.decoding_plc, stats.decoding_plc); | 
|   487     EXPECT_EQ(info.decoding_cng, stats.decoding_cng); |   490     EXPECT_EQ(info.decoding_cng, stats.decoding_cng); | 
|   488     EXPECT_EQ(info.decoding_plc_cng, stats.decoding_plc_cng); |   491     EXPECT_EQ(info.decoding_plc_cng, stats.decoding_plc_cng); | 
|   489     EXPECT_EQ(info.decoding_muted_output, stats.decoding_muted_output); |   492     EXPECT_EQ(info.decoding_muted_output, stats.decoding_muted_output); | 
|   490     EXPECT_EQ(info.capture_start_ntp_time_ms, stats.capture_start_ntp_time_ms); |   493     EXPECT_EQ(info.capture_start_ntp_time_ms, stats.capture_start_ntp_time_ms); | 
|   491   } |   494   } | 
|   492  |   495  | 
|   493  protected: |   496  protected: | 
|   494   StrictMock<webrtc::test::MockAudioDeviceModule> adm_; |   497   StrictMock<webrtc::test::MockAudioDeviceModule> adm_; | 
 |   498   webrtc::RtcEventLogNullImpl event_log_; | 
|   495   cricket::FakeCall call_; |   499   cricket::FakeCall call_; | 
|   496   cricket::FakeWebRtcVoiceEngine voe_; |   500   cricket::FakeWebRtcVoiceEngine voe_; | 
|   497   std::unique_ptr<cricket::WebRtcVoiceEngine> engine_; |   501   std::unique_ptr<cricket::WebRtcVoiceEngine> engine_; | 
|   498   cricket::VoiceMediaChannel* channel_ = nullptr; |   502   cricket::VoiceMediaChannel* channel_ = nullptr; | 
|   499   cricket::AudioSendParameters send_parameters_; |   503   cricket::AudioSendParameters send_parameters_; | 
|   500   cricket::AudioRecvParameters recv_parameters_; |   504   cricket::AudioRecvParameters recv_parameters_; | 
|   501   FakeAudioSource fake_source_; |   505   FakeAudioSource fake_source_; | 
|   502  private: |   506  private: | 
|   503   webrtc::test::ScopedFieldTrials override_field_trials_; |   507   webrtc::test::ScopedFieldTrials override_field_trials_; | 
|   504 }; |   508 }; | 
| (...skipping 2849 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  3354  |  3358  | 
|  3355   EXPECT_TRUE(GetRecvStream(kSsrc1).started()); |  3359   EXPECT_TRUE(GetRecvStream(kSsrc1).started()); | 
|  3356 } |  3360 } | 
|  3357  |  3361  | 
|  3358 // Tests that the library initializes and shuts down properly. |  3362 // Tests that the library initializes and shuts down properly. | 
|  3359 TEST(WebRtcVoiceEngineTest, StartupShutdown) { |  3363 TEST(WebRtcVoiceEngineTest, StartupShutdown) { | 
|  3360   // If the VoiceEngine wants to gather available codecs early, that's fine but |  3364   // If the VoiceEngine wants to gather available codecs early, that's fine but | 
|  3361   // we never want it to create a decoder at this stage. |  3365   // we never want it to create a decoder at this stage. | 
|  3362   cricket::WebRtcVoiceEngine engine( |  3366   cricket::WebRtcVoiceEngine engine( | 
|  3363       nullptr, webrtc::MockAudioDecoderFactory::CreateUnusedFactory()); |  3367       nullptr, webrtc::MockAudioDecoderFactory::CreateUnusedFactory()); | 
 |  3368   webrtc::RtcEventLogNullImpl event_log; | 
|  3364   std::unique_ptr<webrtc::Call> call( |  3369   std::unique_ptr<webrtc::Call> call( | 
|  3365       webrtc::Call::Create(webrtc::Call::Config())); |  3370       webrtc::Call::Create(webrtc::Call::Config(&event_log))); | 
|  3366   cricket::VoiceMediaChannel* channel = engine.CreateChannel( |  3371   cricket::VoiceMediaChannel* channel = engine.CreateChannel( | 
|  3367       call.get(), cricket::MediaConfig(), cricket::AudioOptions()); |  3372       call.get(), cricket::MediaConfig(), cricket::AudioOptions()); | 
|  3368   EXPECT_TRUE(channel != nullptr); |  3373   EXPECT_TRUE(channel != nullptr); | 
|  3369   delete channel; |  3374   delete channel; | 
|  3370 } |  3375 } | 
|  3371  |  3376  | 
|  3372 // Tests that reference counting on the external ADM is correct. |  3377 // Tests that reference counting on the external ADM is correct. | 
|  3373 TEST(WebRtcVoiceEngineTest, StartupShutdownWithExternalADM) { |  3378 TEST(WebRtcVoiceEngineTest, StartupShutdownWithExternalADM) { | 
|  3374   testing::NiceMock<webrtc::test::MockAudioDeviceModule> adm; |  3379   testing::NiceMock<webrtc::test::MockAudioDeviceModule> adm; | 
|  3375   EXPECT_CALL(adm, AddRef()).Times(3).WillRepeatedly(Return(0)); |  3380   EXPECT_CALL(adm, AddRef()).Times(3).WillRepeatedly(Return(0)); | 
|  3376   EXPECT_CALL(adm, Release()).Times(3).WillRepeatedly(Return(0)); |  3381   EXPECT_CALL(adm, Release()).Times(3).WillRepeatedly(Return(0)); | 
|  3377   { |  3382   { | 
|  3378     cricket::WebRtcVoiceEngine engine( |  3383     cricket::WebRtcVoiceEngine engine( | 
|  3379         &adm, webrtc::MockAudioDecoderFactory::CreateUnusedFactory()); |  3384         &adm, webrtc::MockAudioDecoderFactory::CreateUnusedFactory()); | 
 |  3385     webrtc::RtcEventLogNullImpl event_log; | 
|  3380     std::unique_ptr<webrtc::Call> call( |  3386     std::unique_ptr<webrtc::Call> call( | 
|  3381         webrtc::Call::Create(webrtc::Call::Config())); |  3387         webrtc::Call::Create(webrtc::Call::Config(&event_log))); | 
|  3382     cricket::VoiceMediaChannel* channel = engine.CreateChannel( |  3388     cricket::VoiceMediaChannel* channel = engine.CreateChannel( | 
|  3383         call.get(), cricket::MediaConfig(), cricket::AudioOptions()); |  3389         call.get(), cricket::MediaConfig(), cricket::AudioOptions()); | 
|  3384     EXPECT_TRUE(channel != nullptr); |  3390     EXPECT_TRUE(channel != nullptr); | 
|  3385     delete channel; |  3391     delete channel; | 
|  3386   } |  3392   } | 
|  3387 } |  3393 } | 
|  3388  |  3394  | 
|  3389 // Tests that the library is configured with the codecs we want. |  3395 // Tests that the library is configured with the codecs we want. | 
|  3390 TEST(WebRtcVoiceEngineTest, HasCorrectCodecs) { |  3396 TEST(WebRtcVoiceEngineTest, HasCorrectCodecs) { | 
|  3391   // TODO(ossu): These tests should move into a future "builtin audio codecs" |  3397   // TODO(ossu): These tests should move into a future "builtin audio codecs" | 
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  3468       ASSERT_TRUE(it->params.find("useinbandfec") != it->params.end()); |  3474       ASSERT_TRUE(it->params.find("useinbandfec") != it->params.end()); | 
|  3469       EXPECT_EQ("1", it->params.find("useinbandfec")->second); |  3475       EXPECT_EQ("1", it->params.find("useinbandfec")->second); | 
|  3470     } |  3476     } | 
|  3471   } |  3477   } | 
|  3472 } |  3478 } | 
|  3473  |  3479  | 
|  3474 // Tests that VoE supports at least 32 channels |  3480 // Tests that VoE supports at least 32 channels | 
|  3475 TEST(WebRtcVoiceEngineTest, Has32Channels) { |  3481 TEST(WebRtcVoiceEngineTest, Has32Channels) { | 
|  3476   cricket::WebRtcVoiceEngine engine( |  3482   cricket::WebRtcVoiceEngine engine( | 
|  3477       nullptr, webrtc::MockAudioDecoderFactory::CreateUnusedFactory()); |  3483       nullptr, webrtc::MockAudioDecoderFactory::CreateUnusedFactory()); | 
 |  3484   webrtc::RtcEventLogNullImpl event_log; | 
|  3478   std::unique_ptr<webrtc::Call> call( |  3485   std::unique_ptr<webrtc::Call> call( | 
|  3479       webrtc::Call::Create(webrtc::Call::Config())); |  3486       webrtc::Call::Create(webrtc::Call::Config(&event_log))); | 
|  3480  |  3487  | 
|  3481   cricket::VoiceMediaChannel* channels[32]; |  3488   cricket::VoiceMediaChannel* channels[32]; | 
|  3482   int num_channels = 0; |  3489   int num_channels = 0; | 
|  3483   while (num_channels < arraysize(channels)) { |  3490   while (num_channels < arraysize(channels)) { | 
|  3484     cricket::VoiceMediaChannel* channel = engine.CreateChannel( |  3491     cricket::VoiceMediaChannel* channel = engine.CreateChannel( | 
|  3485         call.get(), cricket::MediaConfig(), cricket::AudioOptions()); |  3492         call.get(), cricket::MediaConfig(), cricket::AudioOptions()); | 
|  3486     if (!channel) |  3493     if (!channel) | 
|  3487       break; |  3494       break; | 
|  3488     channels[num_channels++] = channel; |  3495     channels[num_channels++] = channel; | 
|  3489   } |  3496   } | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
|  3500 TEST(WebRtcVoiceEngineTest, SetRecvCodecs) { |  3507 TEST(WebRtcVoiceEngineTest, SetRecvCodecs) { | 
|  3501   // TODO(ossu): I'm not sure of the intent of this test. It's either: |  3508   // TODO(ossu): I'm not sure of the intent of this test. It's either: | 
|  3502   // - Check that our builtin codecs are usable by Channel. |  3509   // - Check that our builtin codecs are usable by Channel. | 
|  3503   // - The codecs provided by the engine is usable by Channel. |  3510   // - The codecs provided by the engine is usable by Channel. | 
|  3504   // It does not check that the codecs in the RecvParameters are actually |  3511   // It does not check that the codecs in the RecvParameters are actually | 
|  3505   // what we sent in - though it's probably reasonable to expect so, if |  3512   // what we sent in - though it's probably reasonable to expect so, if | 
|  3506   // SetRecvParameters returns true. |  3513   // SetRecvParameters returns true. | 
|  3507   // I think it will become clear once audio decoder injection is completed. |  3514   // I think it will become clear once audio decoder injection is completed. | 
|  3508   cricket::WebRtcVoiceEngine engine( |  3515   cricket::WebRtcVoiceEngine engine( | 
|  3509       nullptr, webrtc::CreateBuiltinAudioDecoderFactory()); |  3516       nullptr, webrtc::CreateBuiltinAudioDecoderFactory()); | 
 |  3517   webrtc::RtcEventLogNullImpl event_log; | 
|  3510   std::unique_ptr<webrtc::Call> call( |  3518   std::unique_ptr<webrtc::Call> call( | 
|  3511       webrtc::Call::Create(webrtc::Call::Config())); |  3519       webrtc::Call::Create(webrtc::Call::Config(&event_log))); | 
|  3512   cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(), |  3520   cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(), | 
|  3513                                            cricket::AudioOptions(), call.get()); |  3521                                            cricket::AudioOptions(), call.get()); | 
|  3514   cricket::AudioRecvParameters parameters; |  3522   cricket::AudioRecvParameters parameters; | 
|  3515   parameters.codecs = engine.recv_codecs(); |  3523   parameters.codecs = engine.recv_codecs(); | 
|  3516   EXPECT_TRUE(channel.SetRecvParameters(parameters)); |  3524   EXPECT_TRUE(channel.SetRecvParameters(parameters)); | 
|  3517 } |  3525 } | 
| OLD | NEW |