| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2012 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 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "webrtc/pc/videotrack.h" | 31 #include "webrtc/pc/videotrack.h" |
| 32 #include "webrtc/pc/videotracksource.h" | 32 #include "webrtc/pc/videotracksource.h" |
| 33 #include "webrtc/test/gmock.h" | 33 #include "webrtc/test/gmock.h" |
| 34 #include "webrtc/test/gtest.h" | 34 #include "webrtc/test/gtest.h" |
| 35 | 35 |
| 36 using ::testing::_; | 36 using ::testing::_; |
| 37 using ::testing::Exactly; | 37 using ::testing::Exactly; |
| 38 using ::testing::InvokeWithoutArgs; | 38 using ::testing::InvokeWithoutArgs; |
| 39 using ::testing::Return; | 39 using ::testing::Return; |
| 40 | 40 |
| 41 static const char kStreamLabel1[] = "local_stream_1"; | 41 static const char kStreamLabel1[] = "local_local_stream_1"; |
| 42 static const char kVideoTrackId[] = "video_1"; | 42 static const char kVideoTrackId[] = "video_1"; |
| 43 static const char kAudioTrackId[] = "audio_1"; | 43 static const char kAudioTrackId[] = "audio_1"; |
| 44 static const uint32_t kVideoSsrc = 98; | 44 static const uint32_t kVideoSsrc = 98; |
| 45 static const uint32_t kVideoSsrc2 = 100; | 45 static const uint32_t kVideoSsrc2 = 100; |
| 46 static const uint32_t kAudioSsrc = 99; | 46 static const uint32_t kAudioSsrc = 99; |
| 47 static const uint32_t kAudioSsrc2 = 101; | 47 static const uint32_t kAudioSsrc2 = 101; |
| 48 | 48 |
| 49 namespace webrtc { | 49 namespace webrtc { |
| 50 | 50 |
| 51 class RtpSenderReceiverTest : public testing::Test { | 51 class RtpSenderReceiverTest : public testing::Test { |
| 52 public: | 52 public: |
| 53 RtpSenderReceiverTest() | 53 RtpSenderReceiverTest() |
| 54 : // Create fake media engine/etc. so we can create channels to use to | 54 : // Create fake media engine/etc. so we can create channels to use to |
| 55 // test RtpSenders/RtpReceivers. | 55 // test RtpSenders/RtpReceivers. |
| 56 media_engine_(new cricket::FakeMediaEngine()), | 56 media_engine_(new cricket::FakeMediaEngine()), |
| 57 channel_manager_(media_engine_, | 57 channel_manager_( |
| 58 rtc::Thread::Current(), | 58 std::unique_ptr<cricket::MediaEngineInterface>(media_engine_), |
| 59 rtc::Thread::Current()), | 59 rtc::Thread::Current(), |
| 60 rtc::Thread::Current()), |
| 60 fake_call_(Call::Config(&event_log_)), | 61 fake_call_(Call::Config(&event_log_)), |
| 61 fake_media_controller_(&channel_manager_, &fake_call_), | 62 fake_media_controller_(&channel_manager_, &fake_call_), |
| 62 stream_(MediaStream::Create(kStreamLabel1)) { | 63 local_stream_(MediaStream::Create(kStreamLabel1)) { |
| 63 // Create channels to be used by the RtpSenders and RtpReceivers. | 64 // Create channels to be used by the RtpSenders and RtpReceivers. |
| 64 channel_manager_.Init(); | 65 channel_manager_.Init(); |
| 65 bool rtcp_mux_required = true; | |
| 66 bool srtp_required = true; | 66 bool srtp_required = true; |
| 67 cricket::DtlsTransportInternal* rtp_transport = | 67 cricket::DtlsTransportInternal* rtp_transport = |
| 68 fake_transport_controller_.CreateDtlsTransport( | 68 fake_transport_controller_.CreateDtlsTransport( |
| 69 cricket::CN_AUDIO, cricket::ICE_CANDIDATE_COMPONENT_RTP); | 69 cricket::CN_AUDIO, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
| 70 voice_channel_ = channel_manager_.CreateVoiceChannel( | 70 voice_channel_ = channel_manager_.CreateVoiceChannel( |
| 71 &fake_media_controller_, rtp_transport, nullptr, rtc::Thread::Current(), | 71 &fake_media_controller_, rtp_transport, nullptr, rtc::Thread::Current(), |
| 72 cricket::CN_AUDIO, nullptr, rtcp_mux_required, srtp_required, | 72 cricket::CN_AUDIO, srtp_required, cricket::AudioOptions()); |
| 73 cricket::AudioOptions()); | |
| 74 video_channel_ = channel_manager_.CreateVideoChannel( | 73 video_channel_ = channel_manager_.CreateVideoChannel( |
| 75 &fake_media_controller_, rtp_transport, nullptr, rtc::Thread::Current(), | 74 &fake_media_controller_, rtp_transport, nullptr, rtc::Thread::Current(), |
| 76 cricket::CN_VIDEO, nullptr, rtcp_mux_required, srtp_required, | 75 cricket::CN_VIDEO, srtp_required, cricket::VideoOptions()); |
| 77 cricket::VideoOptions()); | |
| 78 voice_media_channel_ = media_engine_->GetVoiceChannel(0); | 76 voice_media_channel_ = media_engine_->GetVoiceChannel(0); |
| 79 video_media_channel_ = media_engine_->GetVideoChannel(0); | 77 video_media_channel_ = media_engine_->GetVideoChannel(0); |
| 80 RTC_CHECK(voice_channel_); | 78 RTC_CHECK(voice_channel_); |
| 81 RTC_CHECK(video_channel_); | 79 RTC_CHECK(video_channel_); |
| 82 RTC_CHECK(voice_media_channel_); | 80 RTC_CHECK(voice_media_channel_); |
| 83 RTC_CHECK(video_media_channel_); | 81 RTC_CHECK(video_media_channel_); |
| 84 | 82 |
| 85 // Create streams for predefined SSRCs. Streams need to exist in order | 83 // Create streams for predefined SSRCs. Streams need to exist in order |
| 86 // for the senders and receievers to apply parameters to them. | 84 // for the senders and receievers to apply parameters to them. |
| 87 // Normally these would be created by SetLocalDescription and | 85 // Normally these would be created by SetLocalDescription and |
| (...skipping 17 matching lines...) Expand all Loading... |
| 105 } | 103 } |
| 106 | 104 |
| 107 void TearDown() override { channel_manager_.Terminate(); } | 105 void TearDown() override { channel_manager_.Terminate(); } |
| 108 | 106 |
| 109 void AddVideoTrack() { AddVideoTrack(false); } | 107 void AddVideoTrack() { AddVideoTrack(false); } |
| 110 | 108 |
| 111 void AddVideoTrack(bool is_screencast) { | 109 void AddVideoTrack(bool is_screencast) { |
| 112 rtc::scoped_refptr<VideoTrackSourceInterface> source( | 110 rtc::scoped_refptr<VideoTrackSourceInterface> source( |
| 113 FakeVideoTrackSource::Create(is_screencast)); | 111 FakeVideoTrackSource::Create(is_screencast)); |
| 114 video_track_ = VideoTrack::Create(kVideoTrackId, source); | 112 video_track_ = VideoTrack::Create(kVideoTrackId, source); |
| 115 EXPECT_TRUE(stream_->AddTrack(video_track_)); | 113 EXPECT_TRUE(local_stream_->AddTrack(video_track_)); |
| 116 } | 114 } |
| 117 | 115 |
| 118 void CreateAudioRtpSender() { CreateAudioRtpSender(nullptr); } | 116 void CreateAudioRtpSender() { CreateAudioRtpSender(nullptr); } |
| 119 | 117 |
| 120 void CreateAudioRtpSender(rtc::scoped_refptr<LocalAudioSource> source) { | 118 void CreateAudioRtpSender(rtc::scoped_refptr<LocalAudioSource> source) { |
| 121 audio_track_ = AudioTrack::Create(kAudioTrackId, source); | 119 audio_track_ = AudioTrack::Create(kAudioTrackId, source); |
| 122 EXPECT_TRUE(stream_->AddTrack(audio_track_)); | 120 EXPECT_TRUE(local_stream_->AddTrack(audio_track_)); |
| 123 audio_rtp_sender_ = | 121 audio_rtp_sender_ = |
| 124 new AudioRtpSender(stream_->GetAudioTracks()[0], stream_->label(), | 122 new AudioRtpSender(local_stream_->GetAudioTracks()[0], |
| 125 voice_channel_, nullptr); | 123 local_stream_->label(), voice_channel_, nullptr); |
| 126 audio_rtp_sender_->SetSsrc(kAudioSsrc); | 124 audio_rtp_sender_->SetSsrc(kAudioSsrc); |
| 127 VerifyVoiceChannelInput(); | 125 VerifyVoiceChannelInput(); |
| 128 } | 126 } |
| 129 | 127 |
| 130 void CreateVideoRtpSender() { CreateVideoRtpSender(false); } | 128 void CreateVideoRtpSender() { CreateVideoRtpSender(false); } |
| 131 | 129 |
| 132 void CreateVideoRtpSender(bool is_screencast) { | 130 void CreateVideoRtpSender(bool is_screencast) { |
| 133 AddVideoTrack(is_screencast); | 131 AddVideoTrack(is_screencast); |
| 134 video_rtp_sender_ = new VideoRtpSender(stream_->GetVideoTracks()[0], | 132 video_rtp_sender_ = |
| 135 stream_->label(), video_channel_); | 133 new VideoRtpSender(local_stream_->GetVideoTracks()[0], |
| 134 local_stream_->label(), video_channel_); |
| 136 video_rtp_sender_->SetSsrc(kVideoSsrc); | 135 video_rtp_sender_->SetSsrc(kVideoSsrc); |
| 137 VerifyVideoChannelInput(); | 136 VerifyVideoChannelInput(); |
| 138 } | 137 } |
| 139 | 138 |
| 140 void DestroyAudioRtpSender() { | 139 void DestroyAudioRtpSender() { |
| 141 audio_rtp_sender_ = nullptr; | 140 audio_rtp_sender_ = nullptr; |
| 142 VerifyVoiceChannelNoInput(); | 141 VerifyVoiceChannelNoInput(); |
| 143 } | 142 } |
| 144 | 143 |
| 145 void DestroyVideoRtpSender() { | 144 void DestroyVideoRtpSender() { |
| 146 video_rtp_sender_ = nullptr; | 145 video_rtp_sender_ = nullptr; |
| 147 VerifyVideoChannelNoInput(); | 146 VerifyVideoChannelNoInput(); |
| 148 } | 147 } |
| 149 | 148 |
| 150 void CreateAudioRtpReceiver() { | 149 void CreateAudioRtpReceiver() { |
| 151 audio_track_ = AudioTrack::Create( | 150 audio_rtp_receiver_ = |
| 152 kAudioTrackId, RemoteAudioSource::Create(kAudioSsrc, NULL)); | 151 new AudioRtpReceiver(kAudioTrackId, kAudioSsrc, voice_channel_); |
| 153 EXPECT_TRUE(stream_->AddTrack(audio_track_)); | |
| 154 audio_rtp_receiver_ = new AudioRtpReceiver(stream_, kAudioTrackId, | |
| 155 kAudioSsrc, voice_channel_); | |
| 156 audio_track_ = audio_rtp_receiver_->audio_track(); | 152 audio_track_ = audio_rtp_receiver_->audio_track(); |
| 157 VerifyVoiceChannelOutput(); | 153 VerifyVoiceChannelOutput(); |
| 158 } | 154 } |
| 159 | 155 |
| 160 void CreateVideoRtpReceiver() { | 156 void CreateVideoRtpReceiver() { |
| 161 video_rtp_receiver_ = | 157 video_rtp_receiver_ = new VideoRtpReceiver( |
| 162 new VideoRtpReceiver(stream_, kVideoTrackId, rtc::Thread::Current(), | 158 kVideoTrackId, rtc::Thread::Current(), kVideoSsrc, video_channel_); |
| 163 kVideoSsrc, video_channel_); | |
| 164 video_track_ = video_rtp_receiver_->video_track(); | 159 video_track_ = video_rtp_receiver_->video_track(); |
| 165 VerifyVideoChannelOutput(); | 160 VerifyVideoChannelOutput(); |
| 166 } | 161 } |
| 167 | 162 |
| 168 void DestroyAudioRtpReceiver() { | 163 void DestroyAudioRtpReceiver() { |
| 169 audio_rtp_receiver_ = nullptr; | 164 audio_rtp_receiver_ = nullptr; |
| 170 VerifyVoiceChannelNoOutput(); | 165 VerifyVoiceChannelNoOutput(); |
| 171 } | 166 } |
| 172 | 167 |
| 173 void DestroyVideoRtpReceiver() { | 168 void DestroyVideoRtpReceiver() { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 EXPECT_EQ(0, volume); | 219 EXPECT_EQ(0, volume); |
| 225 } | 220 } |
| 226 | 221 |
| 227 void VerifyVideoChannelNoOutput() { | 222 void VerifyVideoChannelNoOutput() { |
| 228 // Verify that the media channel's sink is reset. | 223 // Verify that the media channel's sink is reset. |
| 229 EXPECT_FALSE(video_media_channel_->HasSink(kVideoSsrc)); | 224 EXPECT_FALSE(video_media_channel_->HasSink(kVideoSsrc)); |
| 230 } | 225 } |
| 231 | 226 |
| 232 protected: | 227 protected: |
| 233 webrtc::RtcEventLogNullImpl event_log_; | 228 webrtc::RtcEventLogNullImpl event_log_; |
| 229 // |media_engine_| is owned by |channel_manager_|. |
| 234 cricket::FakeMediaEngine* media_engine_; | 230 cricket::FakeMediaEngine* media_engine_; |
| 235 cricket::FakeTransportController fake_transport_controller_; | 231 cricket::FakeTransportController fake_transport_controller_; |
| 236 cricket::ChannelManager channel_manager_; | 232 cricket::ChannelManager channel_manager_; |
| 237 cricket::FakeCall fake_call_; | 233 cricket::FakeCall fake_call_; |
| 238 cricket::FakeMediaController fake_media_controller_; | 234 cricket::FakeMediaController fake_media_controller_; |
| 239 cricket::VoiceChannel* voice_channel_; | 235 cricket::VoiceChannel* voice_channel_; |
| 240 cricket::VideoChannel* video_channel_; | 236 cricket::VideoChannel* video_channel_; |
| 241 cricket::FakeVoiceMediaChannel* voice_media_channel_; | 237 cricket::FakeVoiceMediaChannel* voice_media_channel_; |
| 242 cricket::FakeVideoMediaChannel* video_media_channel_; | 238 cricket::FakeVideoMediaChannel* video_media_channel_; |
| 243 rtc::scoped_refptr<AudioRtpSender> audio_rtp_sender_; | 239 rtc::scoped_refptr<AudioRtpSender> audio_rtp_sender_; |
| 244 rtc::scoped_refptr<VideoRtpSender> video_rtp_sender_; | 240 rtc::scoped_refptr<VideoRtpSender> video_rtp_sender_; |
| 245 rtc::scoped_refptr<AudioRtpReceiver> audio_rtp_receiver_; | 241 rtc::scoped_refptr<AudioRtpReceiver> audio_rtp_receiver_; |
| 246 rtc::scoped_refptr<VideoRtpReceiver> video_rtp_receiver_; | 242 rtc::scoped_refptr<VideoRtpReceiver> video_rtp_receiver_; |
| 247 rtc::scoped_refptr<MediaStreamInterface> stream_; | 243 rtc::scoped_refptr<MediaStreamInterface> local_stream_; |
| 248 rtc::scoped_refptr<VideoTrackInterface> video_track_; | 244 rtc::scoped_refptr<VideoTrackInterface> video_track_; |
| 249 rtc::scoped_refptr<AudioTrackInterface> audio_track_; | 245 rtc::scoped_refptr<AudioTrackInterface> audio_track_; |
| 250 }; | 246 }; |
| 251 | 247 |
| 252 // Test that |voice_channel_| is updated when an audio track is associated | 248 // Test that |voice_channel_| is updated when an audio track is associated |
| 253 // and disassociated with an AudioRtpSender. | 249 // and disassociated with an AudioRtpSender. |
| 254 TEST_F(RtpSenderReceiverTest, AddAndDestroyAudioRtpSender) { | 250 TEST_F(RtpSenderReceiverTest, AddAndDestroyAudioRtpSender) { |
| 255 CreateAudioRtpSender(); | 251 CreateAudioRtpSender(); |
| 256 DestroyAudioRtpSender(); | 252 DestroyAudioRtpSender(); |
| 257 } | 253 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 274 // associated and disassociated with a VideoRtpReceiver. | 270 // associated and disassociated with a VideoRtpReceiver. |
| 275 TEST_F(RtpSenderReceiverTest, AddAndDestroyVideoRtpReceiver) { | 271 TEST_F(RtpSenderReceiverTest, AddAndDestroyVideoRtpReceiver) { |
| 276 CreateVideoRtpReceiver(); | 272 CreateVideoRtpReceiver(); |
| 277 DestroyVideoRtpReceiver(); | 273 DestroyVideoRtpReceiver(); |
| 278 } | 274 } |
| 279 | 275 |
| 280 // Test that the AudioRtpSender applies options from the local audio source. | 276 // Test that the AudioRtpSender applies options from the local audio source. |
| 281 TEST_F(RtpSenderReceiverTest, LocalAudioSourceOptionsApplied) { | 277 TEST_F(RtpSenderReceiverTest, LocalAudioSourceOptionsApplied) { |
| 282 cricket::AudioOptions options; | 278 cricket::AudioOptions options; |
| 283 options.echo_cancellation = rtc::Optional<bool>(true); | 279 options.echo_cancellation = rtc::Optional<bool>(true); |
| 284 auto source = LocalAudioSource::Create( | 280 auto source = LocalAudioSource::Create(&options); |
| 285 PeerConnectionFactoryInterface::Options(), &options); | |
| 286 CreateAudioRtpSender(source.get()); | 281 CreateAudioRtpSender(source.get()); |
| 287 | 282 |
| 288 EXPECT_EQ(rtc::Optional<bool>(true), | 283 EXPECT_EQ(rtc::Optional<bool>(true), |
| 289 voice_media_channel_->options().echo_cancellation); | 284 voice_media_channel_->options().echo_cancellation); |
| 290 | 285 |
| 291 DestroyAudioRtpSender(); | 286 DestroyAudioRtpSender(); |
| 292 } | 287 } |
| 293 | 288 |
| 294 // Test that the stream is muted when the track is disabled, and unmuted when | 289 // Test that the stream is muted when the track is disabled, and unmuted when |
| 295 // the track is enabled. | 290 // the track is enabled. |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 } | 686 } |
| 692 | 687 |
| 693 // Test that makes sure any content hints that are set on a track before | 688 // Test that makes sure any content hints that are set on a track before |
| 694 // VideoRtpSender is ready to send are still applied when it gets ready to send. | 689 // VideoRtpSender is ready to send are still applied when it gets ready to send. |
| 695 TEST_F(RtpSenderReceiverTest, | 690 TEST_F(RtpSenderReceiverTest, |
| 696 PropagatesVideoTrackContentHintSetBeforeEnabling) { | 691 PropagatesVideoTrackContentHintSetBeforeEnabling) { |
| 697 AddVideoTrack(); | 692 AddVideoTrack(); |
| 698 // Setting detailed overrides the default non-screencast mode. This should be | 693 // Setting detailed overrides the default non-screencast mode. This should be |
| 699 // applied even if the track is set on construction. | 694 // applied even if the track is set on construction. |
| 700 video_track_->set_content_hint(VideoTrackInterface::ContentHint::kDetailed); | 695 video_track_->set_content_hint(VideoTrackInterface::ContentHint::kDetailed); |
| 701 video_rtp_sender_ = new VideoRtpSender(stream_->GetVideoTracks()[0], | 696 video_rtp_sender_ = |
| 702 stream_->label(), video_channel_); | 697 new VideoRtpSender(local_stream_->GetVideoTracks()[0], |
| 698 local_stream_->label(), video_channel_); |
| 703 video_track_->set_enabled(true); | 699 video_track_->set_enabled(true); |
| 704 | 700 |
| 705 // Sender is not ready to send (no SSRC) so no option should have been set. | 701 // Sender is not ready to send (no SSRC) so no option should have been set. |
| 706 EXPECT_EQ(rtc::Optional<bool>(), | 702 EXPECT_EQ(rtc::Optional<bool>(), |
| 707 video_media_channel_->options().is_screencast); | 703 video_media_channel_->options().is_screencast); |
| 708 | 704 |
| 709 // Verify that the content hint is accounted for when video_rtp_sender_ does | 705 // Verify that the content hint is accounted for when video_rtp_sender_ does |
| 710 // get enabled. | 706 // get enabled. |
| 711 video_rtp_sender_->SetSsrc(kVideoSsrc); | 707 video_rtp_sender_->SetSsrc(kVideoSsrc); |
| 712 EXPECT_EQ(rtc::Optional<bool>(true), | 708 EXPECT_EQ(rtc::Optional<bool>(true), |
| 713 video_media_channel_->options().is_screencast); | 709 video_media_channel_->options().is_screencast); |
| 714 | 710 |
| 715 // And removing the hint should go back to false (to verify that false was | 711 // And removing the hint should go back to false (to verify that false was |
| 716 // default correctly). | 712 // default correctly). |
| 717 video_track_->set_content_hint(VideoTrackInterface::ContentHint::kNone); | 713 video_track_->set_content_hint(VideoTrackInterface::ContentHint::kNone); |
| 718 EXPECT_EQ(rtc::Optional<bool>(false), | 714 EXPECT_EQ(rtc::Optional<bool>(false), |
| 719 video_media_channel_->options().is_screencast); | 715 video_media_channel_->options().is_screencast); |
| 720 | 716 |
| 721 DestroyVideoRtpSender(); | 717 DestroyVideoRtpSender(); |
| 722 } | 718 } |
| 723 | 719 |
| 724 } // namespace webrtc | 720 } // namespace webrtc |
| OLD | NEW |