| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2009 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2009 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 rtc::Pathname(path), "wb"); | 106 rtc::Pathname(path), "wb"); |
| 107 } | 107 } |
| 108 | 108 |
| 109 // Base class for Voice/VideoChannel tests | 109 // Base class for Voice/VideoChannel tests |
| 110 template<class T> | 110 template<class T> |
| 111 class ChannelTest : public testing::Test, public sigslot::has_slots<> { | 111 class ChannelTest : public testing::Test, public sigslot::has_slots<> { |
| 112 public: | 112 public: |
| 113 enum Flags { RTCP = 0x1, RTCP_MUX = 0x2, SECURE = 0x4, SSRC_MUX = 0x8, | 113 enum Flags { RTCP = 0x1, RTCP_MUX = 0x2, SECURE = 0x4, SSRC_MUX = 0x8, |
| 114 DTLS = 0x10 }; | 114 DTLS = 0x10 }; |
| 115 | 115 |
| 116 // TODO(danilchap): Make tests work with NetworkThread != WorkerThread. |
| 117 // In particular when NetworkThread != Thread::Current. |
| 118 static const bool kNetworkIsWorker = false; |
| 119 |
| 116 ChannelTest(bool verify_playout, | 120 ChannelTest(bool verify_playout, |
| 117 const uint8_t* rtp_data, | 121 const uint8_t* rtp_data, |
| 118 int rtp_len, | 122 int rtp_len, |
| 119 const uint8_t* rtcp_data, | 123 const uint8_t* rtcp_data, |
| 120 int rtcp_len) | 124 int rtcp_len) |
| 121 : verify_playout_(verify_playout), | 125 : verify_playout_(verify_playout), |
| 122 transport_controller1_(cricket::ICEROLE_CONTROLLING), | |
| 123 transport_controller2_(cricket::ICEROLE_CONTROLLED), | |
| 124 media_channel1_(NULL), | 126 media_channel1_(NULL), |
| 125 media_channel2_(NULL), | 127 media_channel2_(NULL), |
| 126 rtp_packet_(reinterpret_cast<const char*>(rtp_data), rtp_len), | 128 rtp_packet_(reinterpret_cast<const char*>(rtp_data), rtp_len), |
| 127 rtcp_packet_(reinterpret_cast<const char*>(rtcp_data), rtcp_len), | 129 rtcp_packet_(reinterpret_cast<const char*>(rtcp_data), rtcp_len), |
| 128 media_info_callbacks1_(), | 130 media_info_callbacks1_(), |
| 129 media_info_callbacks2_() {} | 131 media_info_callbacks2_() { |
| 132 if (kNetworkIsWorker) { |
| 133 network_thread_ = rtc::Thread::Current(); |
| 134 worker_thread_ = rtc::Thread::Current(); |
| 135 } else { |
| 136 network_thread_ = rtc::Thread::CreateWithSocketServer().release(); |
| 137 network_thread_->SetName("Network", nullptr); |
| 138 network_thread_->Start(); |
| 139 worker_thread_ = rtc::Thread::Create().release(); |
| 140 worker_thread_->SetName("Worker", nullptr); |
| 141 worker_thread_->Start(); |
| 142 } |
| 143 network_thread_->Invoke<void>([this] { |
| 144 transport_controller1_.reset( |
| 145 new cricket::FakeTransportController(cricket::ICEROLE_CONTROLLING)); |
| 146 transport_controller2_.reset( |
| 147 new cricket::FakeTransportController(cricket::ICEROLE_CONTROLLED)); |
| 148 }); |
| 149 } |
| 150 virtual ~ChannelTest() { |
| 151 worker_thread_->Invoke<void>([this] { |
| 152 channel2_.reset(nullptr); |
| 153 channel1_.reset(nullptr); |
| 154 }); |
| 155 // TODO(danilchap): Deinitialize tests with double-threading in mind. |
| 156 transport_controller1_.release(); |
| 157 transport_controller2_.release(); |
| 158 if (!worker_thread_->IsCurrent()) { |
| 159 worker_thread_->Stop(); |
| 160 } |
| 161 if (!network_thread_->IsCurrent()) { |
| 162 network_thread_->Stop(); |
| 163 } |
| 164 if (!worker_thread_->IsCurrent()) { |
| 165 delete worker_thread_; |
| 166 } |
| 167 if (!network_thread_->IsCurrent()) { |
| 168 delete network_thread_; |
| 169 } |
| 170 } |
| 130 | 171 |
| 131 void CreateChannels(int flags1, int flags2) { | 172 void CreateChannels(int flags1, int flags2) { |
| 132 CreateChannels(new typename T::MediaChannel(NULL, typename T::Options()), | 173 CreateChannels(new typename T::MediaChannel(NULL, typename T::Options()), |
| 133 new typename T::MediaChannel(NULL, typename T::Options()), | 174 new typename T::MediaChannel(NULL, typename T::Options()), |
| 134 flags1, flags2, rtc::Thread::Current()); | 175 flags1, flags2); |
| 135 } | 176 } |
| 136 void CreateChannels( | 177 void CreateChannels(typename T::MediaChannel* ch1, |
| 137 typename T::MediaChannel* ch1, typename T::MediaChannel* ch2, | 178 typename T::MediaChannel* ch2, |
| 138 int flags1, int flags2, rtc::Thread* thread) { | 179 int flags1, |
| 180 int flags2) { |
| 139 media_channel1_ = ch1; | 181 media_channel1_ = ch1; |
| 140 media_channel2_ = ch2; | 182 media_channel2_ = ch2; |
| 141 channel1_.reset(CreateChannel(thread, &media_engine_, ch1, | 183 worker_thread_->Invoke<void>([this, ch1, ch2, &flags1, &flags2] { |
| 142 &transport_controller1_, | 184 channel1_.reset( |
| 143 (flags1 & RTCP) != 0)); | 185 CreateChannel(worker_thread_, network_thread_, &media_engine_, ch1, |
| 144 channel2_.reset(CreateChannel(thread, &media_engine_, ch2, | 186 transport_controller1_.get(), (flags1 & RTCP) != 0)); |
| 145 &transport_controller2_, | 187 channel2_.reset( |
| 146 (flags2 & RTCP) != 0)); | 188 CreateChannel(worker_thread_, network_thread_, &media_engine_, ch2, |
| 147 channel1_->SignalMediaMonitor.connect( | 189 transport_controller2_.get(), (flags2 & RTCP) != 0)); |
| 148 this, &ChannelTest<T>::OnMediaMonitor); | 190 channel1_->SignalMediaMonitor.connect(this, |
| 149 channel2_->SignalMediaMonitor.connect( | 191 &ChannelTest<T>::OnMediaMonitor); |
| 150 this, &ChannelTest<T>::OnMediaMonitor); | 192 channel2_->SignalMediaMonitor.connect(this, |
| 151 if ((flags1 & DTLS) && (flags2 & DTLS)) { | 193 &ChannelTest<T>::OnMediaMonitor); |
| 152 flags1 = (flags1 & ~SECURE); | 194 if ((flags1 & DTLS) && (flags2 & DTLS)) { |
| 153 flags2 = (flags2 & ~SECURE); | 195 flags1 = (flags1 & ~SECURE); |
| 154 } | 196 flags2 = (flags2 & ~SECURE); |
| 155 CreateContent(flags1, kPcmuCodec, kH264Codec, | 197 } |
| 156 &local_media_content1_); | 198 CreateContent(flags1, kPcmuCodec, kH264Codec, &local_media_content1_); |
| 157 CreateContent(flags2, kPcmuCodec, kH264Codec, | 199 CreateContent(flags2, kPcmuCodec, kH264Codec, &local_media_content2_); |
| 158 &local_media_content2_); | 200 CopyContent(local_media_content1_, &remote_media_content1_); |
| 159 CopyContent(local_media_content1_, &remote_media_content1_); | 201 CopyContent(local_media_content2_, &remote_media_content2_); |
| 160 CopyContent(local_media_content2_, &remote_media_content2_); | |
| 161 | 202 |
| 162 if (flags1 & DTLS) { | 203 if (flags1 & DTLS) { |
| 163 // Confirmed to work with KT_RSA and KT_ECDSA. | 204 // Confirmed to work with KT_RSA and KT_ECDSA. |
| 164 transport_controller1_.SetLocalCertificate( | 205 transport_controller1_->SetLocalCertificate( |
| 165 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>( | 206 rtc::RTCCertificate::Create(rtc::scoped_ptr<rtc::SSLIdentity>( |
| 166 rtc::SSLIdentity::Generate("session1", rtc::KT_DEFAULT)))); | 207 rtc::SSLIdentity::Generate("session1", rtc::KT_DEFAULT)))); |
| 167 } | 208 } |
| 168 if (flags2 & DTLS) { | 209 if (flags2 & DTLS) { |
| 169 // Confirmed to work with KT_RSA and KT_ECDSA. | 210 // Confirmed to work with KT_RSA and KT_ECDSA. |
| 170 transport_controller2_.SetLocalCertificate( | 211 transport_controller2_->SetLocalCertificate( |
| 171 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>( | 212 rtc::RTCCertificate::Create(rtc::scoped_ptr<rtc::SSLIdentity>( |
| 172 rtc::SSLIdentity::Generate("session2", rtc::KT_DEFAULT)))); | 213 rtc::SSLIdentity::Generate("session2", rtc::KT_DEFAULT)))); |
| 173 } | 214 } |
| 174 | 215 |
| 175 // Add stream information (SSRC) to the local content but not to the remote | 216 // Add stream information (SSRC) to the local content but not to the |
| 176 // content. This means that we per default know the SSRC of what we send but | 217 // remote |
| 177 // not what we receive. | 218 // content. This means that we per default know the SSRC of what we send |
| 178 AddLegacyStreamInContent(kSsrc1, flags1, &local_media_content1_); | 219 // but |
| 179 AddLegacyStreamInContent(kSsrc2, flags2, &local_media_content2_); | 220 // not what we receive. |
| 180 | 221 AddLegacyStreamInContent(kSsrc1, flags1, &local_media_content1_); |
| 181 // If SSRC_MUX is used we also need to know the SSRC of the incoming stream. | 222 AddLegacyStreamInContent(kSsrc2, flags2, &local_media_content2_); |
| 182 if (flags1 & SSRC_MUX) { | 223 // If SSRC_MUX is used we also need to know the SSRC of the incoming |
| 183 AddLegacyStreamInContent(kSsrc1, flags1, &remote_media_content1_); | 224 // stream. |
| 184 } | 225 if (flags1 & SSRC_MUX) { |
| 185 if (flags2 & SSRC_MUX) { | 226 AddLegacyStreamInContent(kSsrc1, flags1, &remote_media_content1_); |
| 186 AddLegacyStreamInContent(kSsrc2, flags2, &remote_media_content2_); | 227 } |
| 187 } | 228 if (flags2 & SSRC_MUX) { |
| 229 AddLegacyStreamInContent(kSsrc2, flags2, &remote_media_content2_); |
| 230 } |
| 231 }); |
| 188 } | 232 } |
| 189 typename T::Channel* CreateChannel( | 233 typename T::Channel* CreateChannel( |
| 190 rtc::Thread* thread, | 234 rtc::Thread* worker_thread, |
| 235 rtc::Thread* network_thread, |
| 191 cricket::MediaEngineInterface* engine, | 236 cricket::MediaEngineInterface* engine, |
| 192 typename T::MediaChannel* ch, | 237 typename T::MediaChannel* ch, |
| 193 cricket::TransportController* transport_controller, | 238 cricket::TransportController* transport_controller, |
| 194 bool rtcp) { | 239 bool rtcp) { |
| 195 typename T::Channel* channel = new typename T::Channel( | 240 typename T::Channel* channel = |
| 196 thread, engine, ch, transport_controller, cricket::CN_AUDIO, rtcp); | 241 new typename T::Channel(worker_thread, network_thread, engine, ch, |
| 242 transport_controller, cricket::CN_AUDIO, rtcp); |
| 197 if (!channel->Init()) { | 243 if (!channel->Init()) { |
| 198 delete channel; | 244 delete channel; |
| 199 channel = NULL; | 245 channel = NULL; |
| 200 } | 246 } |
| 201 return channel; | 247 return channel; |
| 202 } | 248 } |
| 203 | 249 |
| 204 bool SendInitiate() { | 250 bool SendInitiate() { |
| 205 bool result = channel1_->SetLocalContent(&local_media_content1_, | 251 bool result = channel1_->SetLocalContent(&local_media_content1_, |
| 206 CA_OFFER, NULL); | 252 CA_OFFER, NULL); |
| 207 if (result) { | 253 if (result) { |
| 208 channel1_->Enable(true); | 254 channel1_->Enable(true); |
| 209 result = channel2_->SetRemoteContent(&remote_media_content1_, | 255 result = channel2_->SetRemoteContent(&remote_media_content1_, |
| 210 CA_OFFER, NULL); | 256 CA_OFFER, NULL); |
| 211 if (result) { | 257 if (result) { |
| 212 transport_controller1_.Connect(&transport_controller2_); | 258 transport_controller1_->Connect(transport_controller2_.get()); |
| 213 | 259 |
| 214 result = channel2_->SetLocalContent(&local_media_content2_, | 260 result = channel2_->SetLocalContent(&local_media_content2_, |
| 215 CA_ANSWER, NULL); | 261 CA_ANSWER, NULL); |
| 216 } | 262 } |
| 217 } | 263 } |
| 218 return result; | 264 return result; |
| 219 } | 265 } |
| 220 | 266 |
| 221 bool SendAccept() { | 267 bool SendAccept() { |
| 222 channel2_->Enable(true); | 268 channel2_->Enable(true); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 235 return result; | 281 return result; |
| 236 } | 282 } |
| 237 | 283 |
| 238 bool SendProvisionalAnswer() { | 284 bool SendProvisionalAnswer() { |
| 239 bool result = channel2_->SetLocalContent(&local_media_content2_, | 285 bool result = channel2_->SetLocalContent(&local_media_content2_, |
| 240 CA_PRANSWER, NULL); | 286 CA_PRANSWER, NULL); |
| 241 if (result) { | 287 if (result) { |
| 242 channel2_->Enable(true); | 288 channel2_->Enable(true); |
| 243 result = channel1_->SetRemoteContent(&remote_media_content2_, | 289 result = channel1_->SetRemoteContent(&remote_media_content2_, |
| 244 CA_PRANSWER, NULL); | 290 CA_PRANSWER, NULL); |
| 245 transport_controller1_.Connect(&transport_controller2_); | 291 transport_controller1_->Connect(transport_controller2_.get()); |
| 246 } | 292 } |
| 247 return result; | 293 return result; |
| 248 } | 294 } |
| 249 | 295 |
| 250 bool SendFinalAnswer() { | 296 bool SendFinalAnswer() { |
| 251 bool result = channel2_->SetLocalContent(&local_media_content2_, | 297 bool result = channel2_->SetLocalContent(&local_media_content2_, |
| 252 CA_ANSWER, NULL); | 298 CA_ANSWER, NULL); |
| 253 if (result) | 299 if (result) |
| 254 result = channel1_->SetRemoteContent(&remote_media_content2_, | 300 result = channel1_->SetRemoteContent(&remote_media_content2_, |
| 255 CA_ANSWER, NULL); | 301 CA_ANSWER, NULL); |
| 256 return result; | 302 return result; |
| 257 } | 303 } |
| 258 | 304 |
| 259 bool SendTerminate() { | 305 bool SendTerminate() { |
| 260 channel1_.reset(); | 306 worker_thread_->Invoke<void>([this] { |
| 261 channel2_.reset(); | 307 channel1_.reset(); |
| 308 channel2_.reset(); |
| 309 }); |
| 262 return true; | 310 return true; |
| 263 } | 311 } |
| 264 | 312 |
| 265 bool AddStream1(int id) { | 313 bool AddStream1(int id) { |
| 266 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id)); | 314 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id)); |
| 267 } | 315 } |
| 268 bool RemoveStream1(int id) { | 316 bool RemoveStream1(int id) { |
| 269 return channel1_->RemoveRecvStream(id); | 317 return channel1_->RemoveRecvStream(id); |
| 270 } | 318 } |
| 271 | 319 |
| 272 // Calling "_w" method here is ok since we only use one thread for this test | |
| 273 cricket::FakeTransport* GetTransport1() { | 320 cricket::FakeTransport* GetTransport1() { |
| 274 return transport_controller1_.GetTransport_w(channel1_->content_name()); | 321 std::string name = channel1_->content_name(); |
| 322 return network_thread_->Invoke<cricket::FakeTransport*>( |
| 323 [this, name] { return transport_controller1_->GetTransport_n(name); }); |
| 275 } | 324 } |
| 276 cricket::FakeTransport* GetTransport2() { | 325 cricket::FakeTransport* GetTransport2() { |
| 277 return transport_controller2_.GetTransport_w(channel2_->content_name()); | 326 std::string name = channel2_->content_name(); |
| 327 return network_thread_->Invoke<cricket::FakeTransport*>( |
| 328 [this, name] { return transport_controller2_->GetTransport_n(name); }); |
| 278 } | 329 } |
| 279 | 330 |
| 280 bool SendRtp1() { | 331 bool SendRtp1() { |
| 281 return media_channel1_->SendRtp(rtp_packet_.c_str(), | 332 bool res = media_channel1_->SendRtp(rtp_packet_.c_str(), |
| 282 static_cast<int>(rtp_packet_.size()), | 333 static_cast<int>(rtp_packet_.size()), |
| 283 rtc::PacketOptions()); | 334 rtc::PacketOptions()); |
| 335 WaitForThreads(); |
| 336 return res; |
| 284 } | 337 } |
| 285 bool SendRtp2() { | 338 bool SendRtp2() { |
| 286 return media_channel2_->SendRtp(rtp_packet_.c_str(), | 339 bool res = media_channel2_->SendRtp(rtp_packet_.c_str(), |
| 287 static_cast<int>(rtp_packet_.size()), | 340 static_cast<int>(rtp_packet_.size()), |
| 288 rtc::PacketOptions()); | 341 rtc::PacketOptions()); |
| 342 WaitForThreads(); |
| 343 return res; |
| 289 } | 344 } |
| 290 bool SendRtcp1() { | 345 bool SendRtcp1() { |
| 291 return media_channel1_->SendRtcp(rtcp_packet_.c_str(), | 346 bool res = media_channel1_->SendRtcp(rtcp_packet_.c_str(), |
| 292 static_cast<int>(rtcp_packet_.size())); | 347 static_cast<int>(rtcp_packet_.size())); |
| 348 WaitForThreads(); |
| 349 return res; |
| 293 } | 350 } |
| 294 bool SendRtcp2() { | 351 bool SendRtcp2() { |
| 295 return media_channel2_->SendRtcp(rtcp_packet_.c_str(), | 352 bool res = media_channel2_->SendRtcp(rtcp_packet_.c_str(), |
| 296 static_cast<int>(rtcp_packet_.size())); | 353 static_cast<int>(rtcp_packet_.size())); |
| 354 WaitForThreads(); |
| 355 return res; |
| 297 } | 356 } |
| 298 // Methods to send custom data. | 357 // Methods to send custom data. |
| 299 bool SendCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) { | 358 bool SendCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) { |
| 300 std::string data(CreateRtpData(ssrc, sequence_number, pl_type)); | 359 std::string data(CreateRtpData(ssrc, sequence_number, pl_type)); |
| 301 return media_channel1_->SendRtp(data.c_str(), static_cast<int>(data.size()), | 360 return media_channel1_->SendRtp(data.c_str(), static_cast<int>(data.size()), |
| 302 rtc::PacketOptions()); | 361 rtc::PacketOptions()); |
| 303 } | 362 } |
| 304 bool SendCustomRtp2(uint32_t ssrc, int sequence_number, int pl_type = -1) { | 363 bool SendCustomRtp2(uint32_t ssrc, int sequence_number, int pl_type = -1) { |
| 305 std::string data(CreateRtpData(ssrc, sequence_number, pl_type)); | 364 std::string data(CreateRtpData(ssrc, sequence_number, pl_type)); |
| 306 return media_channel2_->SendRtp(data.c_str(), static_cast<int>(data.size()), | 365 return media_channel2_->SendRtp(data.c_str(), static_cast<int>(data.size()), |
| (...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 CreateChannels(0, 0); | 844 CreateChannels(0, 0); |
| 786 typename T::Content content1; | 845 typename T::Content content1; |
| 787 CreateContent(0, kPcmuCodec, kH264Codec, &content1); | 846 CreateContent(0, kPcmuCodec, kH264Codec, &content1); |
| 788 content1.AddStream(stream1); | 847 content1.AddStream(stream1); |
| 789 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL)); | 848 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL)); |
| 790 EXPECT_TRUE(channel1_->Enable(true)); | 849 EXPECT_TRUE(channel1_->Enable(true)); |
| 791 EXPECT_EQ(1u, media_channel1_->send_streams().size()); | 850 EXPECT_EQ(1u, media_channel1_->send_streams().size()); |
| 792 | 851 |
| 793 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL)); | 852 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL)); |
| 794 EXPECT_EQ(1u, media_channel2_->recv_streams().size()); | 853 EXPECT_EQ(1u, media_channel2_->recv_streams().size()); |
| 795 transport_controller1_.Connect(&transport_controller2_); | 854 transport_controller1_->Connect(transport_controller2_.get()); |
| 796 | 855 |
| 797 // Channel 2 do not send anything. | 856 // Channel 2 do not send anything. |
| 798 typename T::Content content2; | 857 typename T::Content content2; |
| 799 CreateContent(0, kPcmuCodec, kH264Codec, &content2); | 858 CreateContent(0, kPcmuCodec, kH264Codec, &content2); |
| 800 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL)); | 859 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL)); |
| 801 EXPECT_EQ(0u, media_channel1_->recv_streams().size()); | 860 EXPECT_EQ(0u, media_channel1_->recv_streams().size()); |
| 802 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL)); | 861 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL)); |
| 803 EXPECT_TRUE(channel2_->Enable(true)); | 862 EXPECT_TRUE(channel2_->Enable(true)); |
| 804 EXPECT_EQ(0u, media_channel2_->send_streams().size()); | 863 EXPECT_EQ(0u, media_channel2_->send_streams().size()); |
| 805 | 864 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 860 if (verify_playout_) { | 919 if (verify_playout_) { |
| 861 EXPECT_FALSE(media_channel2_->playout()); | 920 EXPECT_FALSE(media_channel2_->playout()); |
| 862 } | 921 } |
| 863 EXPECT_FALSE(media_channel2_->sending()); | 922 EXPECT_FALSE(media_channel2_->sending()); |
| 864 EXPECT_TRUE(channel2_->SetLocalContent(&local_media_content2_, | 923 EXPECT_TRUE(channel2_->SetLocalContent(&local_media_content2_, |
| 865 CA_ANSWER, NULL)); | 924 CA_ANSWER, NULL)); |
| 866 if (verify_playout_) { | 925 if (verify_playout_) { |
| 867 EXPECT_FALSE(media_channel2_->playout()); | 926 EXPECT_FALSE(media_channel2_->playout()); |
| 868 } | 927 } |
| 869 EXPECT_FALSE(media_channel2_->sending()); | 928 EXPECT_FALSE(media_channel2_->sending()); |
| 870 transport_controller1_.Connect(&transport_controller2_); | 929 transport_controller1_->Connect(transport_controller2_.get()); |
| 871 if (verify_playout_) { | 930 if (verify_playout_) { |
| 872 EXPECT_TRUE(media_channel1_->playout()); | 931 EXPECT_TRUE(media_channel1_->playout()); |
| 873 } | 932 } |
| 874 EXPECT_FALSE(media_channel1_->sending()); | 933 EXPECT_FALSE(media_channel1_->sending()); |
| 875 if (verify_playout_) { | 934 if (verify_playout_) { |
| 876 EXPECT_FALSE(media_channel2_->playout()); | 935 EXPECT_FALSE(media_channel2_->playout()); |
| 877 } | 936 } |
| 878 EXPECT_FALSE(media_channel2_->sending()); | 937 EXPECT_FALSE(media_channel2_->sending()); |
| 879 EXPECT_TRUE(channel2_->Enable(true)); | 938 EXPECT_TRUE(channel2_->Enable(true)); |
| 880 if (verify_playout_) { | 939 if (verify_playout_) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 908 EXPECT_FALSE(media_channel1_->sending()); | 967 EXPECT_FALSE(media_channel1_->sending()); |
| 909 if (verify_playout_) { | 968 if (verify_playout_) { |
| 910 EXPECT_FALSE(media_channel2_->playout()); | 969 EXPECT_FALSE(media_channel2_->playout()); |
| 911 } | 970 } |
| 912 EXPECT_FALSE(media_channel2_->sending()); | 971 EXPECT_FALSE(media_channel2_->sending()); |
| 913 | 972 |
| 914 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL)); | 973 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL)); |
| 915 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL)); | 974 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL)); |
| 916 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL)); | 975 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL)); |
| 917 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL)); | 976 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL)); |
| 918 transport_controller1_.Connect(&transport_controller2_); | 977 transport_controller1_->Connect(transport_controller2_.get()); |
| 919 | 978 |
| 920 if (verify_playout_) { | 979 if (verify_playout_) { |
| 921 EXPECT_TRUE(media_channel1_->playout()); | 980 EXPECT_TRUE(media_channel1_->playout()); |
| 922 } | 981 } |
| 923 EXPECT_FALSE(media_channel1_->sending()); // remote InActive | 982 EXPECT_FALSE(media_channel1_->sending()); // remote InActive |
| 924 if (verify_playout_) { | 983 if (verify_playout_) { |
| 925 EXPECT_FALSE(media_channel2_->playout()); // local InActive | 984 EXPECT_FALSE(media_channel2_->playout()); // local InActive |
| 926 } | 985 } |
| 927 EXPECT_FALSE(media_channel2_->sending()); // local InActive | 986 EXPECT_FALSE(media_channel2_->sending()); // local InActive |
| 928 | 987 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 955 EXPECT_TRUE(media_channel2_->sending()); | 1014 EXPECT_TRUE(media_channel2_->sending()); |
| 956 } | 1015 } |
| 957 | 1016 |
| 958 // Tests that when the transport channel signals a candidate pair change | 1017 // Tests that when the transport channel signals a candidate pair change |
| 959 // event, the media channel will receive a call on the network route change. | 1018 // event, the media channel will receive a call on the network route change. |
| 960 void TestNetworkRouteChanges() { | 1019 void TestNetworkRouteChanges() { |
| 961 CreateChannels(0, 0); | 1020 CreateChannels(0, 0); |
| 962 | 1021 |
| 963 cricket::TransportChannel* transport_channel1 = | 1022 cricket::TransportChannel* transport_channel1 = |
| 964 channel1_->transport_channel(); | 1023 channel1_->transport_channel(); |
| 965 ASSERT_TRUE(transport_channel1 != nullptr); | 1024 ASSERT_TRUE(transport_channel1); |
| 966 typename T::MediaChannel* media_channel1 = | 1025 typename T::MediaChannel* media_channel1 = |
| 967 static_cast<typename T::MediaChannel*>(channel1_->media_channel()); | 1026 static_cast<typename T::MediaChannel*>(channel1_->media_channel()); |
| 968 ASSERT_TRUE(media_channel1 != nullptr); | 1027 ASSERT_TRUE(media_channel1); |
| 969 | 1028 |
| 970 media_channel1_->set_num_network_route_changes(0); | 1029 media_channel1_->set_num_network_route_changes(0); |
| 971 // The transport channel becomes disconnected. | 1030 network_thread_->Invoke<void>([this, transport_channel1, media_channel1] { |
| 972 transport_channel1->SignalSelectedCandidatePairChanged(transport_channel1, | 1031 // The transport channel becomes disconnected. |
| 973 nullptr, -1); | 1032 transport_channel1->SignalSelectedCandidatePairChanged(transport_channel1, |
| 974 EXPECT_EQ(1, media_channel1_->num_network_route_changes()); | 1033 nullptr, -1); |
| 975 EXPECT_FALSE(media_channel1->last_network_route().connected); | 1034 EXPECT_EQ(1, media_channel1_->num_network_route_changes()); |
| 1035 EXPECT_FALSE(media_channel1->last_network_route().connected); |
| 976 | 1036 |
| 977 media_channel1_->set_num_network_route_changes(0); | 1037 media_channel1_->set_num_network_route_changes(0); |
| 978 // The transport channel becomes connected. | 1038 // The transport channel becomes connected. |
| 979 rtc::SocketAddress local_address("192.168.1.1", 1000 /* port number */); | 1039 rtc::SocketAddress local_address("192.168.1.1", 1000 /* port number */); |
| 980 rtc::SocketAddress remote_address("192.168.1.2", 2000 /* port number */); | 1040 rtc::SocketAddress remote_address("192.168.1.2", 2000 /* port number */); |
| 981 uint16_t local_net_id = 1; | 1041 uint16_t local_net_id = 1; |
| 982 uint16_t remote_net_id = 2; | 1042 uint16_t remote_net_id = 2; |
| 983 int last_packet_id = 100; | 1043 int last_packet_id = 100; |
| 984 std::unique_ptr<cricket::CandidatePairInterface> candidate_pair( | 1044 rtc::scoped_ptr<cricket::CandidatePairInterface> candidate_pair( |
| 985 transport_controller1_.CreateFakeCandidatePair( | 1045 transport_controller1_->CreateFakeCandidatePair( |
| 986 local_address, local_net_id, remote_address, remote_net_id)); | 1046 local_address, local_net_id, remote_address, remote_net_id)); |
| 987 transport_channel1->SignalSelectedCandidatePairChanged( | 1047 transport_channel1->SignalSelectedCandidatePairChanged( |
| 988 transport_channel1, candidate_pair.get(), last_packet_id); | 1048 transport_channel1, candidate_pair.get(), last_packet_id); |
| 989 EXPECT_EQ(1, media_channel1_->num_network_route_changes()); | 1049 EXPECT_EQ(1, media_channel1_->num_network_route_changes()); |
| 990 rtc::NetworkRoute expected_network_route(local_net_id, remote_net_id, | 1050 rtc::NetworkRoute expected_network_route(local_net_id, remote_net_id, |
| 991 last_packet_id); | 1051 last_packet_id); |
| 992 EXPECT_EQ(expected_network_route, media_channel1->last_network_route()); | 1052 EXPECT_EQ(expected_network_route, media_channel1->last_network_route()); |
| 993 EXPECT_EQ(last_packet_id, | 1053 EXPECT_EQ(last_packet_id, |
| 994 media_channel1->last_network_route().last_sent_packet_id); | 1054 media_channel1->last_network_route().last_sent_packet_id); |
| 1055 }); |
| 995 } | 1056 } |
| 996 | 1057 |
| 997 // Test setting up a call. | 1058 // Test setting up a call. |
| 998 void TestCallSetup() { | 1059 void TestCallSetup() { |
| 999 CreateChannels(0, 0); | 1060 CreateChannels(0, 0); |
| 1000 EXPECT_FALSE(channel1_->secure()); | 1061 EXPECT_FALSE(channel1_->secure()); |
| 1001 EXPECT_TRUE(SendInitiate()); | 1062 EXPECT_TRUE(SendInitiate()); |
| 1002 if (verify_playout_) { | 1063 if (verify_playout_) { |
| 1003 EXPECT_TRUE(media_channel1_->playout()); | 1064 EXPECT_TRUE(media_channel1_->playout()); |
| 1004 } | 1065 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1022 class LastWordMediaChannel : public T::MediaChannel { | 1083 class LastWordMediaChannel : public T::MediaChannel { |
| 1023 public: | 1084 public: |
| 1024 LastWordMediaChannel() : T::MediaChannel(NULL, typename T::Options()) {} | 1085 LastWordMediaChannel() : T::MediaChannel(NULL, typename T::Options()) {} |
| 1025 ~LastWordMediaChannel() { | 1086 ~LastWordMediaChannel() { |
| 1026 T::MediaChannel::SendRtp(kPcmuFrame, sizeof(kPcmuFrame), | 1087 T::MediaChannel::SendRtp(kPcmuFrame, sizeof(kPcmuFrame), |
| 1027 rtc::PacketOptions()); | 1088 rtc::PacketOptions()); |
| 1028 T::MediaChannel::SendRtcp(kRtcpReport, sizeof(kRtcpReport)); | 1089 T::MediaChannel::SendRtcp(kRtcpReport, sizeof(kRtcpReport)); |
| 1029 } | 1090 } |
| 1030 }; | 1091 }; |
| 1031 CreateChannels(new LastWordMediaChannel(), new LastWordMediaChannel(), | 1092 CreateChannels(new LastWordMediaChannel(), new LastWordMediaChannel(), |
| 1032 RTCP | RTCP_MUX, RTCP | RTCP_MUX, | 1093 RTCP | RTCP_MUX, RTCP | RTCP_MUX); |
| 1033 rtc::Thread::Current()); | |
| 1034 EXPECT_TRUE(SendInitiate()); | 1094 EXPECT_TRUE(SendInitiate()); |
| 1035 EXPECT_TRUE(SendAccept()); | 1095 EXPECT_TRUE(SendAccept()); |
| 1036 EXPECT_TRUE(SendTerminate()); | 1096 EXPECT_TRUE(SendTerminate()); |
| 1037 } | 1097 } |
| 1038 | 1098 |
| 1039 // Send voice RTP data to the other side and ensure it gets there. | 1099 // Send voice RTP data to the other side and ensure it gets there. |
| 1040 void SendRtpToRtp() { | 1100 void SendRtpToRtp() { |
| 1041 CreateChannels(0, 0); | 1101 CreateChannels(0, 0); |
| 1042 EXPECT_TRUE(SendInitiate()); | 1102 EXPECT_TRUE(SendInitiate()); |
| 1043 EXPECT_TRUE(SendAccept()); | 1103 EXPECT_TRUE(SendAccept()); |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1463 EXPECT_EQ(1U, GetTransport1()->channels().size()); | 1523 EXPECT_EQ(1U, GetTransport1()->channels().size()); |
| 1464 EXPECT_EQ(1U, GetTransport2()->channels().size()); | 1524 EXPECT_EQ(1U, GetTransport2()->channels().size()); |
| 1465 EXPECT_TRUE(SendRtp1()); | 1525 EXPECT_TRUE(SendRtp1()); |
| 1466 EXPECT_TRUE(SendRtp2()); | 1526 EXPECT_TRUE(SendRtp2()); |
| 1467 EXPECT_TRUE(CheckRtp1()); | 1527 EXPECT_TRUE(CheckRtp1()); |
| 1468 EXPECT_TRUE(CheckRtp2()); | 1528 EXPECT_TRUE(CheckRtp2()); |
| 1469 EXPECT_TRUE(CheckNoRtp1()); | 1529 EXPECT_TRUE(CheckNoRtp1()); |
| 1470 EXPECT_TRUE(CheckNoRtp2()); | 1530 EXPECT_TRUE(CheckNoRtp2()); |
| 1471 | 1531 |
| 1472 // Lose writability, which should fail. | 1532 // Lose writability, which should fail. |
| 1473 GetTransport1()->SetWritable(false); | 1533 network_thread_->Invoke<void>( |
| 1534 [this] { GetTransport1()->SetWritable(false); }); |
| 1474 EXPECT_FALSE(SendRtp1()); | 1535 EXPECT_FALSE(SendRtp1()); |
| 1475 EXPECT_TRUE(SendRtp2()); | 1536 EXPECT_TRUE(SendRtp2()); |
| 1476 EXPECT_TRUE(CheckRtp1()); | 1537 EXPECT_TRUE(CheckRtp1()); |
| 1477 EXPECT_TRUE(CheckNoRtp2()); | 1538 EXPECT_TRUE(CheckNoRtp2()); |
| 1478 | 1539 |
| 1479 // Regain writability | 1540 // Regain writability |
| 1480 GetTransport1()->SetWritable(true); | 1541 network_thread_->Invoke<void>( |
| 1542 [this] { GetTransport1()->SetWritable(true); }); |
| 1481 EXPECT_TRUE(media_channel1_->sending()); | 1543 EXPECT_TRUE(media_channel1_->sending()); |
| 1482 EXPECT_TRUE(SendRtp1()); | 1544 EXPECT_TRUE(SendRtp1()); |
| 1483 EXPECT_TRUE(SendRtp2()); | 1545 EXPECT_TRUE(SendRtp2()); |
| 1484 EXPECT_TRUE(CheckRtp1()); | 1546 EXPECT_TRUE(CheckRtp1()); |
| 1485 EXPECT_TRUE(CheckRtp2()); | 1547 EXPECT_TRUE(CheckRtp2()); |
| 1486 EXPECT_TRUE(CheckNoRtp1()); | 1548 EXPECT_TRUE(CheckNoRtp1()); |
| 1487 EXPECT_TRUE(CheckNoRtp2()); | 1549 EXPECT_TRUE(CheckNoRtp2()); |
| 1488 | 1550 |
| 1489 // Lose writability completely | 1551 // Lose writability completely |
| 1490 GetTransport1()->SetDestination(NULL); | 1552 network_thread_->Invoke<void>( |
| 1553 [this] { GetTransport1()->SetDestination(NULL); }); |
| 1491 EXPECT_TRUE(media_channel1_->sending()); | 1554 EXPECT_TRUE(media_channel1_->sending()); |
| 1492 | 1555 |
| 1493 // Should fail also. | 1556 // Should fail also. |
| 1494 EXPECT_FALSE(SendRtp1()); | 1557 EXPECT_FALSE(SendRtp1()); |
| 1495 EXPECT_TRUE(SendRtp2()); | 1558 EXPECT_TRUE(SendRtp2()); |
| 1496 EXPECT_TRUE(CheckRtp1()); | 1559 EXPECT_TRUE(CheckRtp1()); |
| 1497 EXPECT_TRUE(CheckNoRtp2()); | 1560 EXPECT_TRUE(CheckNoRtp2()); |
| 1498 | 1561 |
| 1499 // Gain writability back | 1562 // Gain writability back |
| 1500 GetTransport1()->SetDestination(GetTransport2()); | 1563 network_thread_->Invoke<void>( |
| 1564 [this] { GetTransport1()->SetDestination(GetTransport2()); }); |
| 1501 EXPECT_TRUE(media_channel1_->sending()); | 1565 EXPECT_TRUE(media_channel1_->sending()); |
| 1502 EXPECT_TRUE(SendRtp1()); | 1566 EXPECT_TRUE(SendRtp1()); |
| 1503 EXPECT_TRUE(SendRtp2()); | 1567 EXPECT_TRUE(SendRtp2()); |
| 1504 EXPECT_TRUE(CheckRtp1()); | 1568 EXPECT_TRUE(CheckRtp1()); |
| 1505 EXPECT_TRUE(CheckRtp2()); | 1569 EXPECT_TRUE(CheckRtp2()); |
| 1506 EXPECT_TRUE(CheckNoRtp1()); | 1570 EXPECT_TRUE(CheckNoRtp1()); |
| 1507 EXPECT_TRUE(CheckNoRtp2()); | 1571 EXPECT_TRUE(CheckNoRtp2()); |
| 1508 } | 1572 } |
| 1509 | 1573 |
| 1510 void SendBundleToBundle( | 1574 void SendBundleToBundle( |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1714 EXPECT_EQ(2U, GetTransport2()->channels().size()); | 1778 EXPECT_EQ(2U, GetTransport2()->channels().size()); |
| 1715 | 1779 |
| 1716 // Send RTCP1 from a different thread. | 1780 // Send RTCP1 from a different thread. |
| 1717 CallOnThreadAndWaitForDone(&ChannelTest<T>::SendRtcp1, &send_rtcp1); | 1781 CallOnThreadAndWaitForDone(&ChannelTest<T>::SendRtcp1, &send_rtcp1); |
| 1718 EXPECT_TRUE(send_rtcp1); | 1782 EXPECT_TRUE(send_rtcp1); |
| 1719 // The sending message is only posted. channel2_ should be empty. | 1783 // The sending message is only posted. channel2_ should be empty. |
| 1720 EXPECT_TRUE(CheckNoRtcp2()); | 1784 EXPECT_TRUE(CheckNoRtcp2()); |
| 1721 | 1785 |
| 1722 // When channel1_ is deleted, the RTCP packet should be sent out to | 1786 // When channel1_ is deleted, the RTCP packet should be sent out to |
| 1723 // channel2_. | 1787 // channel2_. |
| 1724 channel1_.reset(); | 1788 worker_thread_->Invoke<void>([this] { channel1_.reset(); }); |
| 1725 EXPECT_TRUE(CheckRtcp2()); | 1789 EXPECT_TRUE(CheckRtcp2()); |
| 1726 } | 1790 } |
| 1727 | 1791 |
| 1728 void TestSrtpError(int pl_type) { | 1792 void TestSrtpError(int pl_type) { |
| 1729 struct SrtpErrorHandler : public sigslot::has_slots<> { | 1793 struct SrtpErrorHandler : public sigslot::has_slots<> { |
| 1730 SrtpErrorHandler() : | 1794 SrtpErrorHandler() : |
| 1731 mode_(cricket::SrtpFilter::UNPROTECT), | 1795 mode_(cricket::SrtpFilter::UNPROTECT), |
| 1732 error_(cricket::SrtpFilter::ERROR_NONE) {} | 1796 error_(cricket::SrtpFilter::ERROR_NONE) {} |
| 1733 void OnSrtpError(uint32 ssrc, cricket::SrtpFilter::Mode mode, | 1797 void OnSrtpError(uint32 ssrc, cricket::SrtpFilter::Mode mode, |
| 1734 cricket::SrtpFilter::Error error) { | 1798 cricket::SrtpFilter::Error error) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1786 rtc::Thread::Current()->ProcessMessages(200); | 1850 rtc::Thread::Current()->ProcessMessages(200); |
| 1787 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket), | 1851 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket), |
| 1788 rtc::PacketOptions())); | 1852 rtc::PacketOptions())); |
| 1789 EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500); | 1853 EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500); |
| 1790 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_); | 1854 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_); |
| 1791 | 1855 |
| 1792 // Testing failures in receiving packets. | 1856 // Testing failures in receiving packets. |
| 1793 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE; | 1857 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE; |
| 1794 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT; | 1858 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT; |
| 1795 | 1859 |
| 1796 cricket::TransportChannel* transport_channel = | 1860 network_thread_->Invoke<void>([this, kBadPacket] { |
| 1797 channel2_->transport_channel(); | 1861 cricket::TransportChannel* transport_channel = |
| 1798 transport_channel->SignalReadPacket( | 1862 channel2_->transport_channel(); |
| 1799 transport_channel, reinterpret_cast<const char*>(kBadPacket), | 1863 transport_channel->SignalReadPacket( |
| 1800 sizeof(kBadPacket), rtc::PacketTime(), 0); | 1864 transport_channel, reinterpret_cast<const char*>(kBadPacket), |
| 1865 sizeof(kBadPacket), rtc::PacketTime(), 0); |
| 1866 }); |
| 1801 EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500); | 1867 EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500); |
| 1802 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_); | 1868 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_); |
| 1803 } | 1869 } |
| 1804 | 1870 |
| 1805 void TestOnReadyToSend() { | 1871 void TestOnReadyToSend() { |
| 1806 CreateChannels(RTCP, RTCP); | 1872 CreateChannels(RTCP, RTCP); |
| 1807 TransportChannel* rtp = channel1_->transport_channel(); | 1873 TransportChannel* rtp = channel1_->transport_channel(); |
| 1808 TransportChannel* rtcp = channel1_->rtcp_transport_channel(); | 1874 TransportChannel* rtcp = channel1_->rtcp_transport_channel(); |
| 1809 EXPECT_FALSE(media_channel1_->ready_to_send()); | 1875 EXPECT_FALSE(media_channel1_->ready_to_send()); |
| 1810 rtp->SignalReadyToSend(rtp); | 1876 rtp->SignalReadyToSend(rtp); |
| 1811 EXPECT_FALSE(media_channel1_->ready_to_send()); | 1877 EXPECT_FALSE(media_channel1_->ready_to_send()); |
| 1812 rtcp->SignalReadyToSend(rtcp); | 1878 rtcp->SignalReadyToSend(rtcp); |
| 1813 // MediaChannel::OnReadyToSend only be called when both rtp and rtcp | 1879 // MediaChannel::OnReadyToSend only be called when both rtp and rtcp |
| 1814 // channel are ready to send. | 1880 // channel are ready to send. |
| 1815 EXPECT_TRUE(media_channel1_->ready_to_send()); | 1881 EXPECT_TRUE(media_channel1_->ready_to_send()); |
| 1816 | 1882 |
| 1817 // rtp channel becomes not ready to send will be propagated to mediachannel | 1883 // rtp channel becomes not ready to send will be propagated to mediachannel |
| 1818 channel1_->SetReadyToSend(false, false); | 1884 channel1_->SetReadyToSend_n(false, false); |
| 1819 EXPECT_FALSE(media_channel1_->ready_to_send()); | 1885 EXPECT_FALSE(media_channel1_->ready_to_send()); |
| 1820 channel1_->SetReadyToSend(false, true); | 1886 channel1_->SetReadyToSend_n(false, true); |
| 1821 EXPECT_TRUE(media_channel1_->ready_to_send()); | 1887 EXPECT_TRUE(media_channel1_->ready_to_send()); |
| 1822 | 1888 |
| 1823 // rtcp channel becomes not ready to send will be propagated to mediachannel | 1889 // rtcp channel becomes not ready to send will be propagated to mediachannel |
| 1824 channel1_->SetReadyToSend(true, false); | 1890 channel1_->SetReadyToSend_n(true, false); |
| 1825 EXPECT_FALSE(media_channel1_->ready_to_send()); | 1891 EXPECT_FALSE(media_channel1_->ready_to_send()); |
| 1826 channel1_->SetReadyToSend(true, true); | 1892 channel1_->SetReadyToSend_n(true, true); |
| 1827 EXPECT_TRUE(media_channel1_->ready_to_send()); | 1893 EXPECT_TRUE(media_channel1_->ready_to_send()); |
| 1828 } | 1894 } |
| 1829 | 1895 |
| 1830 void TestOnReadyToSendWithRtcpMux() { | 1896 void TestOnReadyToSendWithRtcpMux() { |
| 1831 CreateChannels(RTCP, RTCP); | 1897 CreateChannels(RTCP, RTCP); |
| 1832 typename T::Content content; | 1898 typename T::Content content; |
| 1833 CreateContent(0, kPcmuCodec, kH264Codec, &content); | 1899 CreateContent(0, kPcmuCodec, kH264Codec, &content); |
| 1834 // Both sides agree on mux. Should no longer be a separate RTCP channel. | 1900 // Both sides agree on mux. Should no longer be a separate RTCP channel. |
| 1835 content.set_rtcp_mux(true); | 1901 content.set_rtcp_mux(true); |
| 1836 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL)); | 1902 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL)); |
| 1837 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL)); | 1903 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL)); |
| 1838 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL); | 1904 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL); |
| 1839 TransportChannel* rtp = channel1_->transport_channel(); | 1905 TransportChannel* rtp = channel1_->transport_channel(); |
| 1840 EXPECT_FALSE(media_channel1_->ready_to_send()); | 1906 EXPECT_FALSE(media_channel1_->ready_to_send()); |
| 1841 // In the case of rtcp mux, the SignalReadyToSend() from rtp channel | 1907 // In the case of rtcp mux, the SignalReadyToSend() from rtp channel |
| 1842 // should trigger the MediaChannel's OnReadyToSend. | 1908 // should trigger the MediaChannel's OnReadyToSend. |
| 1843 rtp->SignalReadyToSend(rtp); | 1909 rtp->SignalReadyToSend(rtp); |
| 1844 EXPECT_TRUE(media_channel1_->ready_to_send()); | 1910 EXPECT_TRUE(media_channel1_->ready_to_send()); |
| 1845 channel1_->SetReadyToSend(false, false); | 1911 channel1_->SetReadyToSend_n(false, false); |
| 1846 EXPECT_FALSE(media_channel1_->ready_to_send()); | 1912 EXPECT_FALSE(media_channel1_->ready_to_send()); |
| 1847 } | 1913 } |
| 1848 | 1914 |
| 1849 bool SetRemoteContentWithBitrateLimit(int remote_limit) { | 1915 bool SetRemoteContentWithBitrateLimit(int remote_limit) { |
| 1850 typename T::Content content; | 1916 typename T::Content content; |
| 1851 CreateContent(0, kPcmuCodec, kH264Codec, &content); | 1917 CreateContent(0, kPcmuCodec, kH264Codec, &content); |
| 1852 content.set_bandwidth(remote_limit); | 1918 content.set_bandwidth(remote_limit); |
| 1853 return channel1_->SetRemoteContent(&content, CA_OFFER, NULL); | 1919 return channel1_->SetRemoteContent(&content, CA_OFFER, NULL); |
| 1854 } | 1920 } |
| 1855 | 1921 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1887 EXPECT_EQ(-1, media_channel1_->max_bps()); | 1953 EXPECT_EQ(-1, media_channel1_->max_bps()); |
| 1888 | 1954 |
| 1889 EXPECT_TRUE( | 1955 EXPECT_TRUE( |
| 1890 channel1_->SetRtpParameters(kSsrc1, BitrateLimitedParameters(-1))); | 1956 channel1_->SetRtpParameters(kSsrc1, BitrateLimitedParameters(-1))); |
| 1891 VerifyMaxBitrate(channel1_->GetRtpParameters(kSsrc1), -1); | 1957 VerifyMaxBitrate(channel1_->GetRtpParameters(kSsrc1), -1); |
| 1892 VerifyMaxBitrate(media_channel1_->GetRtpParameters(kSsrc1), -1); | 1958 VerifyMaxBitrate(media_channel1_->GetRtpParameters(kSsrc1), -1); |
| 1893 EXPECT_EQ(-1, media_channel1_->max_bps()); | 1959 EXPECT_EQ(-1, media_channel1_->max_bps()); |
| 1894 } | 1960 } |
| 1895 | 1961 |
| 1896 protected: | 1962 protected: |
| 1963 void WaitForThreads() { |
| 1964 rtc::Thread* threads[] = {worker_thread_, network_thread_}; |
| 1965 |
| 1966 rtc::Event waiter(false, false); |
| 1967 class EventWaiter : public rtc::MessageHandler { |
| 1968 public: |
| 1969 EventWaiter(rtc::Event* event) : event_(event) {} |
| 1970 void OnMessage(rtc::Message* /* msg */) override { event_->Set(); } |
| 1971 |
| 1972 private: |
| 1973 rtc::Event* const event_; |
| 1974 } handler(&waiter); |
| 1975 |
| 1976 bool all_empty = false; |
| 1977 while (!all_empty) { |
| 1978 all_empty = true; |
| 1979 for (rtc::Thread* thread : threads) { |
| 1980 if (thread->empty()) { |
| 1981 continue; |
| 1982 } |
| 1983 all_empty = false; |
| 1984 // Ensure all messages are processed by posting own to end of the queue |
| 1985 // and waiting for it. |
| 1986 RTC_CHECK(!thread->IsCurrent()); |
| 1987 thread->Post(&handler); |
| 1988 RTC_CHECK(waiter.Wait(1000)); |
| 1989 } |
| 1990 } |
| 1991 } |
| 1897 // TODO(pbos): Remove playout from all media channels and let renderers mute | 1992 // TODO(pbos): Remove playout from all media channels and let renderers mute |
| 1898 // themselves. | 1993 // themselves. |
| 1899 const bool verify_playout_; | 1994 const bool verify_playout_; |
| 1900 cricket::FakeTransportController transport_controller1_; | 1995 std::unique_ptr<cricket::FakeTransportController> transport_controller1_; |
| 1901 cricket::FakeTransportController transport_controller2_; | 1996 std::unique_ptr<cricket::FakeTransportController> transport_controller2_; |
| 1997 rtc::Thread* network_thread_; |
| 1998 rtc::Thread* worker_thread_; |
| 1902 cricket::FakeMediaEngine media_engine_; | 1999 cricket::FakeMediaEngine media_engine_; |
| 1903 // The media channels are owned by the voice channel objects below. | 2000 // The media channels are owned by the voice channel objects below. |
| 1904 typename T::MediaChannel* media_channel1_; | 2001 typename T::MediaChannel* media_channel1_; |
| 1905 typename T::MediaChannel* media_channel2_; | 2002 typename T::MediaChannel* media_channel2_; |
| 1906 std::unique_ptr<typename T::Channel> channel1_; | 2003 std::unique_ptr<typename T::Channel> channel1_; |
| 1907 std::unique_ptr<typename T::Channel> channel2_; | 2004 std::unique_ptr<typename T::Channel> channel2_; |
| 1908 typename T::Content local_media_content1_; | 2005 typename T::Content local_media_content1_; |
| 1909 typename T::Content local_media_content2_; | 2006 typename T::Content local_media_content2_; |
| 1910 typename T::Content remote_media_content1_; | 2007 typename T::Content remote_media_content1_; |
| 1911 typename T::Content remote_media_content2_; | 2008 typename T::Content remote_media_content2_; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1962 : Base(true, | 2059 : Base(true, |
| 1963 kPcmuFrame, | 2060 kPcmuFrame, |
| 1964 sizeof(kPcmuFrame), | 2061 sizeof(kPcmuFrame), |
| 1965 kRtcpReport, | 2062 kRtcpReport, |
| 1966 sizeof(kRtcpReport)) {} | 2063 sizeof(kRtcpReport)) {} |
| 1967 }; | 2064 }; |
| 1968 | 2065 |
| 1969 // override to add NULL parameter | 2066 // override to add NULL parameter |
| 1970 template <> | 2067 template <> |
| 1971 cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel( | 2068 cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel( |
| 1972 rtc::Thread* thread, | 2069 rtc::Thread* worker_thread, |
| 2070 rtc::Thread* network_thread, |
| 1973 cricket::MediaEngineInterface* engine, | 2071 cricket::MediaEngineInterface* engine, |
| 1974 cricket::FakeVideoMediaChannel* ch, | 2072 cricket::FakeVideoMediaChannel* ch, |
| 1975 cricket::TransportController* transport_controller, | 2073 cricket::TransportController* transport_controller, |
| 1976 bool rtcp) { | 2074 bool rtcp) { |
| 1977 cricket::VideoChannel* channel = new cricket::VideoChannel( | 2075 cricket::VideoChannel* channel = |
| 1978 thread, ch, transport_controller, cricket::CN_VIDEO, rtcp); | 2076 new cricket::VideoChannel(worker_thread, network_thread, ch, |
| 2077 transport_controller, cricket::CN_VIDEO, rtcp); |
| 1979 if (!channel->Init()) { | 2078 if (!channel->Init()) { |
| 1980 delete channel; | 2079 delete channel; |
| 1981 channel = NULL; | 2080 channel = NULL; |
| 1982 } | 2081 } |
| 1983 return channel; | 2082 return channel; |
| 1984 } | 2083 } |
| 1985 | 2084 |
| 1986 // override to add 0 parameter | 2085 // override to add 0 parameter |
| 1987 template<> | 2086 template<> |
| 1988 bool ChannelTest<VideoTraits>::AddStream1(int id) { | 2087 bool ChannelTest<VideoTraits>::AddStream1(int id) { |
| (...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2616 : Base(true, | 2715 : Base(true, |
| 2617 kDataPacket, | 2716 kDataPacket, |
| 2618 sizeof(kDataPacket), | 2717 sizeof(kDataPacket), |
| 2619 kRtcpReport, | 2718 kRtcpReport, |
| 2620 sizeof(kRtcpReport)) {} | 2719 sizeof(kRtcpReport)) {} |
| 2621 }; | 2720 }; |
| 2622 | 2721 |
| 2623 // Override to avoid engine channel parameter. | 2722 // Override to avoid engine channel parameter. |
| 2624 template <> | 2723 template <> |
| 2625 cricket::DataChannel* ChannelTest<DataTraits>::CreateChannel( | 2724 cricket::DataChannel* ChannelTest<DataTraits>::CreateChannel( |
| 2626 rtc::Thread* thread, | 2725 rtc::Thread* worker_thread, |
| 2726 rtc::Thread* network_thread, |
| 2627 cricket::MediaEngineInterface* engine, | 2727 cricket::MediaEngineInterface* engine, |
| 2628 cricket::FakeDataMediaChannel* ch, | 2728 cricket::FakeDataMediaChannel* ch, |
| 2629 cricket::TransportController* transport_controller, | 2729 cricket::TransportController* transport_controller, |
| 2630 bool rtcp) { | 2730 bool rtcp) { |
| 2631 cricket::DataChannel* channel = new cricket::DataChannel( | 2731 cricket::DataChannel* channel = |
| 2632 thread, ch, transport_controller, cricket::CN_DATA, rtcp); | 2732 new cricket::DataChannel(worker_thread, network_thread, ch, |
| 2733 transport_controller, cricket::CN_DATA, rtcp); |
| 2633 if (!channel->Init()) { | 2734 if (!channel->Init()) { |
| 2634 delete channel; | 2735 delete channel; |
| 2635 channel = NULL; | 2736 channel = NULL; |
| 2636 } | 2737 } |
| 2637 return channel; | 2738 return channel; |
| 2638 } | 2739 } |
| 2639 | 2740 |
| 2640 template<> | 2741 template<> |
| 2641 void ChannelTest<DataTraits>::CreateContent( | 2742 void ChannelTest<DataTraits>::CreateContent( |
| 2642 int flags, | 2743 int flags, |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2810 }; | 2911 }; |
| 2811 rtc::CopyOnWriteBuffer payload(data, 3); | 2912 rtc::CopyOnWriteBuffer payload(data, 3); |
| 2812 cricket::SendDataResult result; | 2913 cricket::SendDataResult result; |
| 2813 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result)); | 2914 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result)); |
| 2814 EXPECT_EQ(params.ssrc, | 2915 EXPECT_EQ(params.ssrc, |
| 2815 media_channel1_->last_sent_data_params().ssrc); | 2916 media_channel1_->last_sent_data_params().ssrc); |
| 2816 EXPECT_EQ("foo", media_channel1_->last_sent_data()); | 2917 EXPECT_EQ("foo", media_channel1_->last_sent_data()); |
| 2817 } | 2918 } |
| 2818 | 2919 |
| 2819 // TODO(pthatcher): TestSetReceiver? | 2920 // TODO(pthatcher): TestSetReceiver? |
| OLD | NEW |