1 /*
2 * Copyright 2009 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "pc/channel.h"
12
13 #include <cstdint>
14 #include <memory>
15 #include <utility>
16
17 #include "api/array_view.h"
18 #include "api/audio_options.h"
19 #include "api/rtp_parameters.h"
20 #include "media/base/codec.h"
21 #include "media/base/fake_media_engine.h"
22 #include "media/base/fake_rtp.h"
23 #include "media/base/media_channel.h"
24 #include "p2p/base/candidate_pair_interface.h"
25 #include "p2p/base/fake_dtls_transport.h"
26 #include "p2p/base/fake_packet_transport.h"
27 #include "p2p/base/ice_transport_internal.h"
28 #include "p2p/base/p2p_constants.h"
29 #include "pc/dtls_srtp_transport.h"
30 #include "pc/jsep_transport.h"
31 #include "pc/rtp_transport.h"
32 #include "rtc_base/arraysize.h"
33 #include "rtc_base/buffer.h"
34 #include "rtc_base/byte_order.h"
35 #include "rtc_base/checks.h"
36 #include "rtc_base/rtc_certificate.h"
37 #include "rtc_base/ssl_identity.h"
38 #include "test/gmock.h"
39 #include "test/gtest.h"
40
41 using cricket::DtlsTransportInternal;
42 using cricket::FakeVoiceMediaChannel;
43 using cricket::RidDescription;
44 using cricket::RidDirection;
45 using cricket::StreamParams;
46 using webrtc::RtpTransceiverDirection;
47 using webrtc::SdpType;
48
49 namespace {
50 const cricket::AudioCodec kPcmuCodec(0, "PCMU", 64000, 8000, 1);
51 const cricket::AudioCodec kPcmaCodec(8, "PCMA", 64000, 8000, 1);
52 const cricket::AudioCodec kIsacCodec(103, "ISAC", 40000, 16000, 1);
53 const cricket::VideoCodec kH264Codec(97, "H264");
54 const cricket::VideoCodec kH264SvcCodec(99, "H264-SVC");
55 const cricket::DataCodec kGoogleDataCodec(101, "google-data");
56 const uint32_t kSsrc1 = 0x1111;
57 const uint32_t kSsrc2 = 0x2222;
58 const uint32_t kSsrc3 = 0x3333;
59 const uint32_t kSsrc4 = 0x4444;
60 const int kAudioPts[] = {0, 8};
61 const int kVideoPts[] = {97, 99};
62 enum class NetworkIsWorker { Yes, No };
63
64 } // namespace
65
66 template <class ChannelT,
67 class MediaChannelT,
68 class ContentT,
69 class CodecT,
70 class MediaInfoT,
71 class OptionsT>
72 class Traits {
73 public:
74 typedef ChannelT Channel;
75 typedef MediaChannelT MediaChannel;
76 typedef ContentT Content;
77 typedef CodecT Codec;
78 typedef MediaInfoT MediaInfo;
79 typedef OptionsT Options;
80 };
81
82 class VoiceTraits : public Traits<cricket::VoiceChannel,
83 cricket::FakeVoiceMediaChannel,
84 cricket::AudioContentDescription,
85 cricket::AudioCodec,
86 cricket::VoiceMediaInfo,
87 cricket::AudioOptions> {};
88
89 class VideoTraits : public Traits<cricket::VideoChannel,
90 cricket::FakeVideoMediaChannel,
91 cricket::VideoContentDescription,
92 cricket::VideoCodec,
93 cricket::VideoMediaInfo,
94 cricket::VideoOptions> {};
95
96 class DataTraits : public Traits<cricket::RtpDataChannel,
97 cricket::FakeDataMediaChannel,
98 cricket::RtpDataContentDescription,
99 cricket::RtpDataCodec,
100 cricket::DataMediaInfo,
101 cricket::DataOptions> {};
102
103 // Base class for Voice/Video/RtpDataChannel tests
104 template <class T>
105 class ChannelTest : public ::testing::Test, public sigslot::has_slots<> {
106 public:
107 enum Flags {
108 RTCP_MUX = 0x1,
109 SSRC_MUX = 0x8,
110 DTLS = 0x10,
111 // Use BaseChannel with PacketTransportInternal rather than
112 // DtlsTransportInternal.
113 RAW_PACKET_TRANSPORT = 0x20,
114 };
115
ChannelTest(bool verify_playout,rtc::ArrayView<const uint8_t> rtp_data,rtc::ArrayView<const uint8_t> rtcp_data,NetworkIsWorker network_is_worker)116 ChannelTest(bool verify_playout,
117 rtc::ArrayView<const uint8_t> rtp_data,
118 rtc::ArrayView<const uint8_t> rtcp_data,
119 NetworkIsWorker network_is_worker)
120 : verify_playout_(verify_playout),
121 rtp_packet_(rtp_data.data(), rtp_data.size()),
122 rtcp_packet_(rtcp_data.data(), rtcp_data.size()) {
123 if (network_is_worker == NetworkIsWorker::Yes) {
124 network_thread_ = rtc::Thread::Current();
125 } else {
126 network_thread_keeper_ = rtc::Thread::Create();
127 network_thread_keeper_->SetName("Network", nullptr);
128 network_thread_ = network_thread_keeper_.get();
129 }
130 }
131
CreateChannels(int flags1,int flags2)132 void CreateChannels(int flags1, int flags2) {
133 CreateChannels(std::make_unique<typename T::MediaChannel>(
134 nullptr, typename T::Options()),
135 std::make_unique<typename T::MediaChannel>(
136 nullptr, typename T::Options()),
137 flags1, flags2);
138 }
CreateChannels(std::unique_ptr<typename T::MediaChannel> ch1,std::unique_ptr<typename T::MediaChannel> ch2,int flags1,int flags2)139 void CreateChannels(std::unique_ptr<typename T::MediaChannel> ch1,
140 std::unique_ptr<typename T::MediaChannel> ch2,
141 int flags1,
142 int flags2) {
143 // Network thread is started in CreateChannels, to allow the test to
144 // configure a fake clock before any threads are spawned and attempt to
145 // access the time.
146 if (network_thread_keeper_) {
147 network_thread_keeper_->Start();
148 }
149
150 // Make sure if using raw packet transports, they're used for both
151 // channels.
152 RTC_DCHECK_EQ(flags1 & RAW_PACKET_TRANSPORT, flags2 & RAW_PACKET_TRANSPORT);
153 rtc::Thread* worker_thread = rtc::Thread::Current();
154 media_channel1_ = ch1.get();
155 media_channel2_ = ch2.get();
156 rtc::PacketTransportInternal* rtp1 = nullptr;
157 rtc::PacketTransportInternal* rtcp1 = nullptr;
158 rtc::PacketTransportInternal* rtp2 = nullptr;
159 rtc::PacketTransportInternal* rtcp2 = nullptr;
160 // Based on flags, create fake DTLS or raw packet transports.
161 if (flags1 & RAW_PACKET_TRANSPORT) {
162 fake_rtp_packet_transport1_.reset(
163 new rtc::FakePacketTransport("channel1_rtp"));
164 rtp1 = fake_rtp_packet_transport1_.get();
165 if (!(flags1 & RTCP_MUX)) {
166 fake_rtcp_packet_transport1_.reset(
167 new rtc::FakePacketTransport("channel1_rtcp"));
168 rtcp1 = fake_rtcp_packet_transport1_.get();
169 }
170 } else {
171 // Confirmed to work with KT_RSA and KT_ECDSA.
172 fake_rtp_dtls_transport1_.reset(new cricket::FakeDtlsTransport(
173 "channel1", cricket::ICE_CANDIDATE_COMPONENT_RTP));
174 rtp1 = fake_rtp_dtls_transport1_.get();
175 if (!(flags1 & RTCP_MUX)) {
176 fake_rtcp_dtls_transport1_.reset(new cricket::FakeDtlsTransport(
177 "channel1", cricket::ICE_CANDIDATE_COMPONENT_RTCP));
178 rtcp1 = fake_rtcp_dtls_transport1_.get();
179 }
180 if (flags1 & DTLS) {
181 auto cert1 = rtc::RTCCertificate::Create(
182 rtc::SSLIdentity::Create("session1", rtc::KT_DEFAULT));
183 fake_rtp_dtls_transport1_->SetLocalCertificate(cert1);
184 if (fake_rtcp_dtls_transport1_) {
185 fake_rtcp_dtls_transport1_->SetLocalCertificate(cert1);
186 }
187 }
188 }
189 // Based on flags, create fake DTLS or raw packet transports.
190 if (flags2 & RAW_PACKET_TRANSPORT) {
191 fake_rtp_packet_transport2_.reset(
192 new rtc::FakePacketTransport("channel2_rtp"));
193 rtp2 = fake_rtp_packet_transport2_.get();
194 if (!(flags2 & RTCP_MUX)) {
195 fake_rtcp_packet_transport2_.reset(
196 new rtc::FakePacketTransport("channel2_rtcp"));
197 rtcp2 = fake_rtcp_packet_transport2_.get();
198 }
199 } else {
200 // Confirmed to work with KT_RSA and KT_ECDSA.
201 fake_rtp_dtls_transport2_.reset(new cricket::FakeDtlsTransport(
202 "channel2", cricket::ICE_CANDIDATE_COMPONENT_RTP));
203 rtp2 = fake_rtp_dtls_transport2_.get();
204 if (!(flags2 & RTCP_MUX)) {
205 fake_rtcp_dtls_transport2_.reset(new cricket::FakeDtlsTransport(
206 "channel2", cricket::ICE_CANDIDATE_COMPONENT_RTCP));
207 rtcp2 = fake_rtcp_dtls_transport2_.get();
208 }
209 if (flags2 & DTLS) {
210 auto cert2 = rtc::RTCCertificate::Create(
211 rtc::SSLIdentity::Create("session2", rtc::KT_DEFAULT));
212 fake_rtp_dtls_transport2_->SetLocalCertificate(cert2);
213 if (fake_rtcp_dtls_transport2_) {
214 fake_rtcp_dtls_transport2_->SetLocalCertificate(cert2);
215 }
216 }
217 }
218 rtp_transport1_ = CreateRtpTransportBasedOnFlags(
219 fake_rtp_packet_transport1_.get(), fake_rtcp_packet_transport1_.get(),
220 fake_rtp_dtls_transport1_.get(), fake_rtcp_dtls_transport1_.get(),
221 flags1);
222 rtp_transport2_ = CreateRtpTransportBasedOnFlags(
223 fake_rtp_packet_transport2_.get(), fake_rtcp_packet_transport2_.get(),
224 fake_rtp_dtls_transport2_.get(), fake_rtcp_dtls_transport2_.get(),
225 flags2);
226
227 channel1_ = CreateChannel(worker_thread, network_thread_, std::move(ch1),
228 rtp_transport1_.get(), flags1);
229 channel2_ = CreateChannel(worker_thread, network_thread_, std::move(ch2),
230 rtp_transport2_.get(), flags2);
231 channel1_->SignalRtcpMuxFullyActive.connect(
232 this, &ChannelTest<T>::OnRtcpMuxFullyActive1);
233 channel2_->SignalRtcpMuxFullyActive.connect(
234 this, &ChannelTest<T>::OnRtcpMuxFullyActive2);
235 CreateContent(flags1, kPcmuCodec, kH264Codec, &local_media_content1_);
236 CreateContent(flags2, kPcmuCodec, kH264Codec, &local_media_content2_);
237 CopyContent(local_media_content1_, &remote_media_content1_);
238 CopyContent(local_media_content2_, &remote_media_content2_);
239
240 // Add stream information (SSRC) to the local content but not to the remote
241 // content. This means that we per default know the SSRC of what we send but
242 // not what we receive.
243 AddLegacyStreamInContent(kSsrc1, flags1, &local_media_content1_);
244 AddLegacyStreamInContent(kSsrc2, flags2, &local_media_content2_);
245
246 // If SSRC_MUX is used we also need to know the SSRC of the incoming stream.
247 if (flags1 & SSRC_MUX) {
248 AddLegacyStreamInContent(kSsrc1, flags1, &remote_media_content1_);
249 }
250 if (flags2 & SSRC_MUX) {
251 AddLegacyStreamInContent(kSsrc2, flags2, &remote_media_content2_);
252 }
253 }
254 std::unique_ptr<typename T::Channel> CreateChannel(
255 rtc::Thread* worker_thread,
256 rtc::Thread* network_thread,
257 std::unique_ptr<typename T::MediaChannel> ch,
258 webrtc::RtpTransportInternal* rtp_transport,
259 int flags);
260
CreateRtpTransportBasedOnFlags(rtc::PacketTransportInternal * rtp_packet_transport,rtc::PacketTransportInternal * rtcp_packet_transport,DtlsTransportInternal * rtp_dtls_transport,DtlsTransportInternal * rtcp_dtls_transport,int flags)261 std::unique_ptr<webrtc::RtpTransportInternal> CreateRtpTransportBasedOnFlags(
262 rtc::PacketTransportInternal* rtp_packet_transport,
263 rtc::PacketTransportInternal* rtcp_packet_transport,
264 DtlsTransportInternal* rtp_dtls_transport,
265 DtlsTransportInternal* rtcp_dtls_transport,
266 int flags) {
267 if (flags & RTCP_MUX) {
268 rtcp_packet_transport = nullptr;
269 rtcp_dtls_transport = nullptr;
270 }
271
272 if (flags & DTLS) {
273 return CreateDtlsSrtpTransport(rtp_dtls_transport, rtcp_dtls_transport);
274 } else {
275 if (flags & RAW_PACKET_TRANSPORT) {
276 return CreateUnencryptedTransport(rtp_packet_transport,
277 rtcp_packet_transport);
278 } else {
279 return CreateUnencryptedTransport(rtp_dtls_transport,
280 rtcp_dtls_transport);
281 }
282 }
283 }
284
CreateUnencryptedTransport(rtc::PacketTransportInternal * rtp_packet_transport,rtc::PacketTransportInternal * rtcp_packet_transport)285 std::unique_ptr<webrtc::RtpTransport> CreateUnencryptedTransport(
286 rtc::PacketTransportInternal* rtp_packet_transport,
287 rtc::PacketTransportInternal* rtcp_packet_transport) {
288 auto rtp_transport = std::make_unique<webrtc::RtpTransport>(
289 rtcp_packet_transport == nullptr);
290
291 rtp_transport->SetRtpPacketTransport(rtp_packet_transport);
292 if (rtcp_packet_transport) {
293 rtp_transport->SetRtcpPacketTransport(rtcp_packet_transport);
294 }
295 return rtp_transport;
296 }
297
CreateDtlsSrtpTransport(cricket::DtlsTransportInternal * rtp_dtls_transport,cricket::DtlsTransportInternal * rtcp_dtls_transport)298 std::unique_ptr<webrtc::DtlsSrtpTransport> CreateDtlsSrtpTransport(
299 cricket::DtlsTransportInternal* rtp_dtls_transport,
300 cricket::DtlsTransportInternal* rtcp_dtls_transport) {
301 auto dtls_srtp_transport = std::make_unique<webrtc::DtlsSrtpTransport>(
302 rtcp_dtls_transport == nullptr);
303
304 dtls_srtp_transport->SetDtlsTransports(rtp_dtls_transport,
305 rtcp_dtls_transport);
306 return dtls_srtp_transport;
307 }
308
ConnectFakeTransports()309 void ConnectFakeTransports() {
310 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
311 bool asymmetric = false;
312 // Depending on test flags, could be using DTLS or raw packet transport.
313 if (fake_rtp_dtls_transport1_ && fake_rtp_dtls_transport2_) {
314 fake_rtp_dtls_transport1_->SetDestination(
315 fake_rtp_dtls_transport2_.get(), asymmetric);
316 }
317 if (fake_rtcp_dtls_transport1_ && fake_rtcp_dtls_transport2_) {
318 fake_rtcp_dtls_transport1_->SetDestination(
319 fake_rtcp_dtls_transport2_.get(), asymmetric);
320 }
321 if (fake_rtp_packet_transport1_ && fake_rtp_packet_transport2_) {
322 fake_rtp_packet_transport1_->SetDestination(
323 fake_rtp_packet_transport2_.get(), asymmetric);
324 }
325 if (fake_rtcp_packet_transport1_ && fake_rtcp_packet_transport2_) {
326 fake_rtcp_packet_transport1_->SetDestination(
327 fake_rtcp_packet_transport2_.get(), asymmetric);
328 }
329 });
330 }
331
SendInitiate()332 bool SendInitiate() {
333 bool result = channel1_->SetLocalContent(&local_media_content1_,
334 SdpType::kOffer, NULL);
335 if (result) {
336 channel1_->Enable(true);
337 result = channel2_->SetRemoteContent(&remote_media_content1_,
338 SdpType::kOffer, NULL);
339 if (result) {
340 ConnectFakeTransports();
341 result = channel2_->SetLocalContent(&local_media_content2_,
342 SdpType::kAnswer, NULL);
343 }
344 }
345 return result;
346 }
347
SendAccept()348 bool SendAccept() {
349 channel2_->Enable(true);
350 return channel1_->SetRemoteContent(&remote_media_content2_,
351 SdpType::kAnswer, NULL);
352 }
353
SendOffer()354 bool SendOffer() {
355 bool result = channel1_->SetLocalContent(&local_media_content1_,
356 SdpType::kOffer, NULL);
357 if (result) {
358 channel1_->Enable(true);
359 result = channel2_->SetRemoteContent(&remote_media_content1_,
360 SdpType::kOffer, NULL);
361 }
362 return result;
363 }
364
SendProvisionalAnswer()365 bool SendProvisionalAnswer() {
366 bool result = channel2_->SetLocalContent(&local_media_content2_,
367 SdpType::kPrAnswer, NULL);
368 if (result) {
369 channel2_->Enable(true);
370 result = channel1_->SetRemoteContent(&remote_media_content2_,
371 SdpType::kPrAnswer, NULL);
372 ConnectFakeTransports();
373 }
374 return result;
375 }
376
SendFinalAnswer()377 bool SendFinalAnswer() {
378 bool result = channel2_->SetLocalContent(&local_media_content2_,
379 SdpType::kAnswer, NULL);
380 if (result)
381 result = channel1_->SetRemoteContent(&remote_media_content2_,
382 SdpType::kAnswer, NULL);
383 return result;
384 }
385
Terminate()386 bool Terminate() {
387 channel1_.reset();
388 channel2_.reset();
389 fake_rtp_dtls_transport1_.reset();
390 fake_rtcp_dtls_transport1_.reset();
391 fake_rtp_dtls_transport2_.reset();
392 fake_rtcp_dtls_transport2_.reset();
393 fake_rtp_packet_transport1_.reset();
394 fake_rtcp_packet_transport1_.reset();
395 fake_rtp_packet_transport2_.reset();
396 fake_rtcp_packet_transport2_.reset();
397 if (network_thread_keeper_) {
398 network_thread_keeper_.reset();
399 }
400 return true;
401 }
402
SendRtp1()403 void SendRtp1() {
404 media_channel1_->SendRtp(rtp_packet_.data(), rtp_packet_.size(),
405 rtc::PacketOptions());
406 }
SendRtp2()407 void SendRtp2() {
408 media_channel2_->SendRtp(rtp_packet_.data(), rtp_packet_.size(),
409 rtc::PacketOptions());
410 }
411 // Methods to send custom data.
SendCustomRtp1(uint32_t ssrc,int sequence_number,int pl_type=-1)412 void SendCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) {
413 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
414 media_channel1_->SendRtp(data.data(), data.size(), rtc::PacketOptions());
415 }
SendCustomRtp2(uint32_t ssrc,int sequence_number,int pl_type=-1)416 void SendCustomRtp2(uint32_t ssrc, int sequence_number, int pl_type = -1) {
417 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
418 media_channel2_->SendRtp(data.data(), data.size(), rtc::PacketOptions());
419 }
420
CheckRtp1()421 bool CheckRtp1() {
422 return media_channel1_->CheckRtp(rtp_packet_.data(), rtp_packet_.size());
423 }
CheckRtp2()424 bool CheckRtp2() {
425 return media_channel2_->CheckRtp(rtp_packet_.data(), rtp_packet_.size());
426 }
427 // Methods to check custom data.
CheckCustomRtp1(uint32_t ssrc,int sequence_number,int pl_type=-1)428 bool CheckCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) {
429 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
430 return media_channel1_->CheckRtp(data.data(), data.size());
431 }
CheckCustomRtp2(uint32_t ssrc,int sequence_number,int pl_type=-1)432 bool CheckCustomRtp2(uint32_t ssrc, int sequence_number, int pl_type = -1) {
433 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
434 return media_channel2_->CheckRtp(data.data(), data.size());
435 }
CreateRtpData(uint32_t ssrc,int sequence_number,int pl_type)436 rtc::Buffer CreateRtpData(uint32_t ssrc, int sequence_number, int pl_type) {
437 rtc::Buffer data(rtp_packet_.data(), rtp_packet_.size());
438 // Set SSRC in the rtp packet copy.
439 rtc::SetBE32(data.data() + 8, ssrc);
440 rtc::SetBE16(data.data() + 2, sequence_number);
441 if (pl_type >= 0) {
442 rtc::Set8(data.data(), 1, static_cast<uint8_t>(pl_type));
443 }
444 return data;
445 }
446
CheckNoRtp1()447 bool CheckNoRtp1() { return media_channel1_->CheckNoRtp(); }
CheckNoRtp2()448 bool CheckNoRtp2() { return media_channel2_->CheckNoRtp(); }
449
CreateContent(int flags,const cricket::AudioCodec & audio_codec,const cricket::VideoCodec & video_codec,typename T::Content * content)450 void CreateContent(int flags,
451 const cricket::AudioCodec& audio_codec,
452 const cricket::VideoCodec& video_codec,
453 typename T::Content* content) {
454 // overridden in specialized classes
455 }
CopyContent(const typename T::Content & source,typename T::Content * content)456 void CopyContent(const typename T::Content& source,
457 typename T::Content* content) {
458 // overridden in specialized classes
459 }
460
461 // Creates a MediaContent with one stream.
462 // kPcmuCodec is used as audio codec and kH264Codec is used as video codec.
CreateMediaContentWithStream(uint32_t ssrc)463 typename T::Content* CreateMediaContentWithStream(uint32_t ssrc) {
464 typename T::Content* content = new typename T::Content();
465 CreateContent(0, kPcmuCodec, kH264Codec, content);
466 AddLegacyStreamInContent(ssrc, 0, content);
467 return content;
468 }
469
470 // Will manage the lifetime of a CallThread, making sure it's
471 // destroyed before this object goes out of scope.
472 class ScopedCallThread {
473 public:
474 template <class FunctorT>
ScopedCallThread(FunctorT && functor)475 explicit ScopedCallThread(FunctorT&& functor)
476 : thread_(rtc::Thread::Create()) {
477 thread_->Start();
478 thread_->PostTask(RTC_FROM_HERE, std::forward<FunctorT>(functor));
479 }
480
~ScopedCallThread()481 ~ScopedCallThread() { thread_->Stop(); }
482
thread()483 rtc::Thread* thread() { return thread_.get(); }
484
485 private:
486 std::unique_ptr<rtc::Thread> thread_;
487 };
488
CodecMatches(const typename T::Codec & c1,const typename T::Codec & c2)489 bool CodecMatches(const typename T::Codec& c1, const typename T::Codec& c2) {
490 return false; // overridden in specialized classes
491 }
492
OnRtcpMuxFullyActive1(const std::string &)493 void OnRtcpMuxFullyActive1(const std::string&) {
494 rtcp_mux_activated_callbacks1_++;
495 }
OnRtcpMuxFullyActive2(const std::string &)496 void OnRtcpMuxFullyActive2(const std::string&) {
497 rtcp_mux_activated_callbacks2_++;
498 }
499
last_selected_candidate_pair()500 cricket::CandidatePairInterface* last_selected_candidate_pair() {
501 return last_selected_candidate_pair_;
502 }
503
AddLegacyStreamInContent(uint32_t ssrc,int flags,typename T::Content * content)504 void AddLegacyStreamInContent(uint32_t ssrc,
505 int flags,
506 typename T::Content* content) {
507 // Base implementation.
508 }
509
510 // Tests that can be used by derived classes.
511
512 // Basic sanity check.
TestInit()513 void TestInit() {
514 CreateChannels(0, 0);
515 EXPECT_FALSE(channel1_->srtp_active());
516 EXPECT_FALSE(media_channel1_->sending());
517 if (verify_playout_) {
518 EXPECT_FALSE(media_channel1_->playout());
519 }
520 EXPECT_TRUE(media_channel1_->codecs().empty());
521 EXPECT_TRUE(media_channel1_->recv_streams().empty());
522 EXPECT_TRUE(media_channel1_->rtp_packets().empty());
523 }
524
525 // Test that SetLocalContent and SetRemoteContent properly configure
526 // the codecs.
TestSetContents()527 void TestSetContents() {
528 CreateChannels(0, 0);
529 typename T::Content content;
530 CreateContent(0, kPcmuCodec, kH264Codec, &content);
531 EXPECT_TRUE(channel1_->SetLocalContent(&content, SdpType::kOffer, NULL));
532 EXPECT_EQ(0U, media_channel1_->codecs().size());
533 EXPECT_TRUE(channel1_->SetRemoteContent(&content, SdpType::kAnswer, NULL));
534 ASSERT_EQ(1U, media_channel1_->codecs().size());
535 EXPECT_TRUE(
536 CodecMatches(content.codecs()[0], media_channel1_->codecs()[0]));
537 }
538
539 // Test that SetLocalContent and SetRemoteContent properly configure
540 // extmap-allow-mixed.
TestSetContentsExtmapAllowMixedCaller(bool offer,bool answer)541 void TestSetContentsExtmapAllowMixedCaller(bool offer, bool answer) {
542 // For a caller, SetLocalContent() is called first with an offer and next
543 // SetRemoteContent() is called with the answer.
544 CreateChannels(0, 0);
545 typename T::Content content;
546 CreateContent(0, kPcmuCodec, kH264Codec, &content);
547 auto offer_enum = offer ? (T::Content::kSession) : (T::Content::kNo);
548 auto answer_enum = answer ? (T::Content::kSession) : (T::Content::kNo);
549 content.set_extmap_allow_mixed_enum(offer_enum);
550 EXPECT_TRUE(channel1_->SetLocalContent(&content, SdpType::kOffer, NULL));
551 content.set_extmap_allow_mixed_enum(answer_enum);
552 EXPECT_TRUE(channel1_->SetRemoteContent(&content, SdpType::kAnswer, NULL));
553 EXPECT_EQ(answer, media_channel1_->ExtmapAllowMixed());
554 }
TestSetContentsExtmapAllowMixedCallee(bool offer,bool answer)555 void TestSetContentsExtmapAllowMixedCallee(bool offer, bool answer) {
556 // For a callee, SetRemoteContent() is called first with an offer and next
557 // SetLocalContent() is called with the answer.
558 CreateChannels(0, 0);
559 typename T::Content content;
560 CreateContent(0, kPcmuCodec, kH264Codec, &content);
561 auto offer_enum = offer ? (T::Content::kSession) : (T::Content::kNo);
562 auto answer_enum = answer ? (T::Content::kSession) : (T::Content::kNo);
563 content.set_extmap_allow_mixed_enum(offer_enum);
564 EXPECT_TRUE(channel1_->SetRemoteContent(&content, SdpType::kOffer, NULL));
565 content.set_extmap_allow_mixed_enum(answer_enum);
566 EXPECT_TRUE(channel1_->SetLocalContent(&content, SdpType::kAnswer, NULL));
567 EXPECT_EQ(answer, media_channel1_->ExtmapAllowMixed());
568 }
569
570 // Test that SetLocalContent and SetRemoteContent properly deals
571 // with an empty offer.
TestSetContentsNullOffer()572 void TestSetContentsNullOffer() {
573 CreateChannels(0, 0);
574 typename T::Content content;
575 EXPECT_TRUE(channel1_->SetLocalContent(&content, SdpType::kOffer, NULL));
576 CreateContent(0, kPcmuCodec, kH264Codec, &content);
577 EXPECT_EQ(0U, media_channel1_->codecs().size());
578 EXPECT_TRUE(channel1_->SetRemoteContent(&content, SdpType::kAnswer, NULL));
579 ASSERT_EQ(1U, media_channel1_->codecs().size());
580 EXPECT_TRUE(
581 CodecMatches(content.codecs()[0], media_channel1_->codecs()[0]));
582 }
583
584 // Test that SetLocalContent and SetRemoteContent properly set RTCP
585 // mux.
TestSetContentsRtcpMux()586 void TestSetContentsRtcpMux() {
587 CreateChannels(0, 0);
588 typename T::Content content;
589 CreateContent(0, kPcmuCodec, kH264Codec, &content);
590 // Both sides agree on mux. Should no longer be a separate RTCP channel.
591 content.set_rtcp_mux(true);
592 EXPECT_TRUE(channel1_->SetLocalContent(&content, SdpType::kOffer, NULL));
593 EXPECT_TRUE(channel1_->SetRemoteContent(&content, SdpType::kAnswer, NULL));
594 // Only initiator supports mux. Should still have a separate RTCP channel.
595 EXPECT_TRUE(channel2_->SetLocalContent(&content, SdpType::kOffer, NULL));
596 content.set_rtcp_mux(false);
597 EXPECT_TRUE(channel2_->SetRemoteContent(&content, SdpType::kAnswer, NULL));
598 }
599
600 // Test that SetLocalContent and SetRemoteContent properly set RTCP
601 // mux when a provisional answer is received.
TestSetContentsRtcpMuxWithPrAnswer()602 void TestSetContentsRtcpMuxWithPrAnswer() {
603 CreateChannels(0, 0);
604 typename T::Content content;
605 CreateContent(0, kPcmuCodec, kH264Codec, &content);
606 content.set_rtcp_mux(true);
607 EXPECT_TRUE(channel1_->SetLocalContent(&content, SdpType::kOffer, NULL));
608 EXPECT_TRUE(
609 channel1_->SetRemoteContent(&content, SdpType::kPrAnswer, NULL));
610 // Both sides agree on mux. Should signal RTCP mux as fully activated.
611 EXPECT_EQ(0, rtcp_mux_activated_callbacks1_);
612 EXPECT_TRUE(channel1_->SetRemoteContent(&content, SdpType::kAnswer, NULL));
613 EXPECT_EQ(1, rtcp_mux_activated_callbacks1_);
614 // Only initiator supports mux. Should still have a separate RTCP channel.
615 EXPECT_TRUE(channel2_->SetLocalContent(&content, SdpType::kOffer, NULL));
616 content.set_rtcp_mux(false);
617 EXPECT_TRUE(
618 channel2_->SetRemoteContent(&content, SdpType::kPrAnswer, NULL));
619 EXPECT_TRUE(channel2_->SetRemoteContent(&content, SdpType::kAnswer, NULL));
620 EXPECT_EQ(0, rtcp_mux_activated_callbacks2_);
621 }
622
623 // Test that SetLocalContent and SetRemoteContent properly
624 // handles adding and removing StreamParams when the action is a full
625 // SdpType::kOffer / SdpType::kAnswer.
TestChangeStreamParamsInContent()626 void TestChangeStreamParamsInContent() {
627 cricket::StreamParams stream1;
628 stream1.groupid = "group1";
629 stream1.id = "stream1";
630 stream1.ssrcs.push_back(kSsrc1);
631 stream1.cname = "stream1_cname";
632
633 cricket::StreamParams stream2;
634 stream2.groupid = "group1";
635 stream2.id = "stream2";
636 stream2.ssrcs.push_back(kSsrc2);
637 stream2.cname = "stream2_cname";
638
639 // Setup a call where channel 1 send |stream1| to channel 2.
640 CreateChannels(0, 0);
641 typename T::Content content1;
642 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
643 content1.AddStream(stream1);
644 EXPECT_TRUE(channel1_->SetLocalContent(&content1, SdpType::kOffer, NULL));
645 EXPECT_TRUE(channel1_->Enable(true));
646 EXPECT_EQ(1u, media_channel1_->send_streams().size());
647
648 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, SdpType::kOffer, NULL));
649 EXPECT_EQ(1u, media_channel2_->recv_streams().size());
650 ConnectFakeTransports();
651
652 // Channel 2 do not send anything.
653 typename T::Content content2;
654 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
655 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, SdpType::kAnswer, NULL));
656 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
657 EXPECT_TRUE(channel2_->SetLocalContent(&content2, SdpType::kAnswer, NULL));
658 EXPECT_TRUE(channel2_->Enable(true));
659 EXPECT_EQ(0u, media_channel2_->send_streams().size());
660
661 SendCustomRtp1(kSsrc1, 0);
662 WaitForThreads();
663 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, 0));
664
665 // Let channel 2 update the content by sending |stream2| and enable SRTP.
666 typename T::Content content3;
667 CreateContent(0, kPcmuCodec, kH264Codec, &content3);
668 content3.AddStream(stream2);
669 EXPECT_TRUE(channel2_->SetLocalContent(&content3, SdpType::kOffer, NULL));
670 ASSERT_EQ(1u, media_channel2_->send_streams().size());
671 EXPECT_EQ(stream2, media_channel2_->send_streams()[0]);
672
673 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, SdpType::kOffer, NULL));
674 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
675 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
676
677 // Channel 1 replies but stop sending stream1.
678 typename T::Content content4;
679 CreateContent(0, kPcmuCodec, kH264Codec, &content4);
680 EXPECT_TRUE(channel1_->SetLocalContent(&content4, SdpType::kAnswer, NULL));
681 EXPECT_EQ(0u, media_channel1_->send_streams().size());
682
683 EXPECT_TRUE(channel2_->SetRemoteContent(&content4, SdpType::kAnswer, NULL));
684 EXPECT_EQ(0u, media_channel2_->recv_streams().size());
685
686 SendCustomRtp2(kSsrc2, 0);
687 WaitForThreads();
688 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, 0));
689 }
690
691 // Test that we only start playout and sending at the right times.
TestPlayoutAndSendingStates()692 void TestPlayoutAndSendingStates() {
693 CreateChannels(0, 0);
694 if (verify_playout_) {
695 EXPECT_FALSE(media_channel1_->playout());
696 }
697 EXPECT_FALSE(media_channel1_->sending());
698 if (verify_playout_) {
699 EXPECT_FALSE(media_channel2_->playout());
700 }
701 EXPECT_FALSE(media_channel2_->sending());
702 EXPECT_TRUE(channel1_->Enable(true));
703 if (verify_playout_) {
704 EXPECT_FALSE(media_channel1_->playout());
705 }
706 EXPECT_FALSE(media_channel1_->sending());
707 EXPECT_TRUE(channel1_->SetLocalContent(&local_media_content1_,
708 SdpType::kOffer, NULL));
709 if (verify_playout_) {
710 EXPECT_TRUE(media_channel1_->playout());
711 }
712 EXPECT_FALSE(media_channel1_->sending());
713 EXPECT_TRUE(channel2_->SetRemoteContent(&local_media_content1_,
714 SdpType::kOffer, NULL));
715 if (verify_playout_) {
716 EXPECT_FALSE(media_channel2_->playout());
717 }
718 EXPECT_FALSE(media_channel2_->sending());
719 EXPECT_TRUE(channel2_->SetLocalContent(&local_media_content2_,
720 SdpType::kAnswer, NULL));
721 if (verify_playout_) {
722 EXPECT_FALSE(media_channel2_->playout());
723 }
724 EXPECT_FALSE(media_channel2_->sending());
725 ConnectFakeTransports();
726 if (verify_playout_) {
727 EXPECT_TRUE(media_channel1_->playout());
728 }
729 EXPECT_FALSE(media_channel1_->sending());
730 if (verify_playout_) {
731 EXPECT_FALSE(media_channel2_->playout());
732 }
733 EXPECT_FALSE(media_channel2_->sending());
734 EXPECT_TRUE(channel2_->Enable(true));
735 if (verify_playout_) {
736 EXPECT_TRUE(media_channel2_->playout());
737 }
738 EXPECT_TRUE(media_channel2_->sending());
739 EXPECT_TRUE(channel1_->SetRemoteContent(&local_media_content2_,
740 SdpType::kAnswer, NULL));
741 if (verify_playout_) {
742 EXPECT_TRUE(media_channel1_->playout());
743 }
744 EXPECT_TRUE(media_channel1_->sending());
745 }
746
747 // Test that changing the MediaContentDirection in the local and remote
748 // session description start playout and sending at the right time.
TestMediaContentDirection()749 void TestMediaContentDirection() {
750 CreateChannels(0, 0);
751 typename T::Content content1;
752 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
753 typename T::Content content2;
754 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
755 // Set |content2| to be InActive.
756 content2.set_direction(RtpTransceiverDirection::kInactive);
757
758 EXPECT_TRUE(channel1_->Enable(true));
759 EXPECT_TRUE(channel2_->Enable(true));
760 if (verify_playout_) {
761 EXPECT_FALSE(media_channel1_->playout());
762 }
763 EXPECT_FALSE(media_channel1_->sending());
764 if (verify_playout_) {
765 EXPECT_FALSE(media_channel2_->playout());
766 }
767 EXPECT_FALSE(media_channel2_->sending());
768
769 EXPECT_TRUE(channel1_->SetLocalContent(&content1, SdpType::kOffer, NULL));
770 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, SdpType::kOffer, NULL));
771 EXPECT_TRUE(
772 channel2_->SetLocalContent(&content2, SdpType::kPrAnswer, NULL));
773 EXPECT_TRUE(
774 channel1_->SetRemoteContent(&content2, SdpType::kPrAnswer, NULL));
775 ConnectFakeTransports();
776
777 if (verify_playout_) {
778 EXPECT_TRUE(media_channel1_->playout());
779 }
780 EXPECT_FALSE(media_channel1_->sending()); // remote InActive
781 if (verify_playout_) {
782 EXPECT_FALSE(media_channel2_->playout()); // local InActive
783 }
784 EXPECT_FALSE(media_channel2_->sending()); // local InActive
785
786 // Update |content2| to be RecvOnly.
787 content2.set_direction(RtpTransceiverDirection::kRecvOnly);
788 EXPECT_TRUE(
789 channel2_->SetLocalContent(&content2, SdpType::kPrAnswer, NULL));
790 EXPECT_TRUE(
791 channel1_->SetRemoteContent(&content2, SdpType::kPrAnswer, NULL));
792
793 if (verify_playout_) {
794 EXPECT_TRUE(media_channel1_->playout());
795 }
796 EXPECT_TRUE(media_channel1_->sending());
797 if (verify_playout_) {
798 EXPECT_TRUE(media_channel2_->playout()); // local RecvOnly
799 }
800 EXPECT_FALSE(media_channel2_->sending()); // local RecvOnly
801
802 // Update |content2| to be SendRecv.
803 content2.set_direction(RtpTransceiverDirection::kSendRecv);
804 EXPECT_TRUE(channel2_->SetLocalContent(&content2, SdpType::kAnswer, NULL));
805 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, SdpType::kAnswer, NULL));
806
807 if (verify_playout_) {
808 EXPECT_TRUE(media_channel1_->playout());
809 }
810 EXPECT_TRUE(media_channel1_->sending());
811 if (verify_playout_) {
812 EXPECT_TRUE(media_channel2_->playout());
813 }
814 EXPECT_TRUE(media_channel2_->sending());
815 }
816
817 // Tests that when the transport channel signals a candidate pair change
818 // event, the media channel will receive a call on the network route change.
TestNetworkRouteChanges()819 void TestNetworkRouteChanges() {
820 static constexpr uint16_t kLocalNetId = 1;
821 static constexpr uint16_t kRemoteNetId = 2;
822 static constexpr int kLastPacketId = 100;
823 // Ipv4(20) + UDP(8).
824 static constexpr int kTransportOverheadPerPacket = 28;
825 static constexpr int kSrtpOverheadPerPacket = 10;
826
827 CreateChannels(DTLS, DTLS);
828 SendInitiate();
829
830 typename T::MediaChannel* media_channel1 =
831 static_cast<typename T::MediaChannel*>(channel1_->media_channel());
832 ASSERT_TRUE(media_channel1);
833
834 // Need to wait for the threads before calling
835 // |set_num_network_route_changes| because the network route would be set
836 // when creating the channel.
837 WaitForThreads();
838 media_channel1->set_num_network_route_changes(0);
839 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
840 rtc::NetworkRoute network_route;
841 // The transport channel becomes disconnected.
842 fake_rtp_dtls_transport1_->ice_transport()->SignalNetworkRouteChanged(
843 absl::optional<rtc::NetworkRoute>(network_route));
844 });
845 WaitForThreads();
846 EXPECT_EQ(1, media_channel1->num_network_route_changes());
847 EXPECT_FALSE(media_channel1->last_network_route().connected);
848 media_channel1->set_num_network_route_changes(0);
849
850 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
851 rtc::NetworkRoute network_route;
852 network_route.connected = true;
853 network_route.local =
854 rtc::RouteEndpoint::CreateWithNetworkId(kLocalNetId);
855 network_route.remote =
856 rtc::RouteEndpoint::CreateWithNetworkId(kRemoteNetId);
857 network_route.last_sent_packet_id = kLastPacketId;
858 network_route.packet_overhead = kTransportOverheadPerPacket;
859 // The transport channel becomes connected.
860 fake_rtp_dtls_transport1_->ice_transport()->SignalNetworkRouteChanged(
861
862 absl::optional<rtc::NetworkRoute>(network_route));
863 });
864 WaitForThreads();
865 EXPECT_EQ(1, media_channel1->num_network_route_changes());
866 EXPECT_TRUE(media_channel1->last_network_route().connected);
867 EXPECT_EQ(kLocalNetId,
868 media_channel1->last_network_route().local.network_id());
869 EXPECT_EQ(kRemoteNetId,
870 media_channel1->last_network_route().remote.network_id());
871 EXPECT_EQ(kLastPacketId,
872 media_channel1->last_network_route().last_sent_packet_id);
873 EXPECT_EQ(kTransportOverheadPerPacket + kSrtpOverheadPerPacket,
874 media_channel1->transport_overhead_per_packet());
875 }
876
877 // Test setting up a call.
TestCallSetup()878 void TestCallSetup() {
879 CreateChannels(0, 0);
880 EXPECT_FALSE(channel1_->srtp_active());
881 EXPECT_TRUE(SendInitiate());
882 if (verify_playout_) {
883 EXPECT_TRUE(media_channel1_->playout());
884 }
885 EXPECT_FALSE(media_channel1_->sending());
886 EXPECT_TRUE(SendAccept());
887 EXPECT_FALSE(channel1_->srtp_active());
888 EXPECT_TRUE(media_channel1_->sending());
889 EXPECT_EQ(1U, media_channel1_->codecs().size());
890 if (verify_playout_) {
891 EXPECT_TRUE(media_channel2_->playout());
892 }
893 EXPECT_TRUE(media_channel2_->sending());
894 EXPECT_EQ(1U, media_channel2_->codecs().size());
895 }
896
897 // Test that we don't crash if packets are sent during call teardown
898 // when RTCP mux is enabled. This is a regression test against a specific
899 // race condition that would only occur when a RTCP packet was sent during
900 // teardown of a channel on which RTCP mux was enabled.
TestCallTeardownRtcpMux()901 void TestCallTeardownRtcpMux() {
902 class LastWordMediaChannel : public T::MediaChannel {
903 public:
904 LastWordMediaChannel() : T::MediaChannel(NULL, typename T::Options()) {}
905 ~LastWordMediaChannel() {
906 T::MediaChannel::SendRtp(kPcmuFrame, sizeof(kPcmuFrame),
907 rtc::PacketOptions());
908 T::MediaChannel::SendRtcp(kRtcpReport, sizeof(kRtcpReport));
909 }
910 };
911 CreateChannels(std::make_unique<LastWordMediaChannel>(),
912 std::make_unique<LastWordMediaChannel>(), RTCP_MUX,
913 RTCP_MUX);
914 EXPECT_TRUE(SendInitiate());
915 EXPECT_TRUE(SendAccept());
916 EXPECT_TRUE(Terminate());
917 }
918
919 // Send voice RTP data to the other side and ensure it gets there.
SendRtpToRtp()920 void SendRtpToRtp() {
921 CreateChannels(RTCP_MUX, RTCP_MUX);
922 EXPECT_TRUE(SendInitiate());
923 EXPECT_TRUE(SendAccept());
924 EXPECT_TRUE(channel1_->rtp_transport()->rtcp_mux_enabled());
925 EXPECT_TRUE(channel2_->rtp_transport()->rtcp_mux_enabled());
926 SendRtp1();
927 SendRtp2();
928 WaitForThreads();
929 EXPECT_TRUE(CheckRtp1());
930 EXPECT_TRUE(CheckRtp2());
931 EXPECT_TRUE(CheckNoRtp1());
932 EXPECT_TRUE(CheckNoRtp2());
933 }
934
TestDeinit()935 void TestDeinit() {
936 CreateChannels(0, 0);
937 EXPECT_TRUE(SendInitiate());
938 EXPECT_TRUE(SendAccept());
939 SendRtp1();
940 SendRtp2();
941 // Do not wait, destroy channels.
942 channel1_.reset(nullptr);
943 channel2_.reset(nullptr);
944 }
945
SendDtlsSrtpToDtlsSrtp(int flags1,int flags2)946 void SendDtlsSrtpToDtlsSrtp(int flags1, int flags2) {
947 CreateChannels(flags1 | DTLS, flags2 | DTLS);
948 EXPECT_FALSE(channel1_->srtp_active());
949 EXPECT_FALSE(channel2_->srtp_active());
950 EXPECT_TRUE(SendInitiate());
951 WaitForThreads();
952 EXPECT_TRUE(channel1_->writable());
953 EXPECT_TRUE(channel2_->writable());
954 EXPECT_TRUE(SendAccept());
955 EXPECT_TRUE(channel1_->srtp_active());
956 EXPECT_TRUE(channel2_->srtp_active());
957 SendRtp1();
958 SendRtp2();
959 WaitForThreads();
960 EXPECT_TRUE(CheckRtp1());
961 EXPECT_TRUE(CheckRtp2());
962 EXPECT_TRUE(CheckNoRtp1());
963 EXPECT_TRUE(CheckNoRtp2());
964 }
965
966 // Test that we can send and receive early media when a provisional answer is
967 // sent and received. The test uses SRTP, RTCP mux and SSRC mux.
SendEarlyMediaUsingRtcpMuxSrtp()968 void SendEarlyMediaUsingRtcpMuxSrtp() {
969 int sequence_number1_1 = 0, sequence_number2_2 = 0;
970
971 CreateChannels(SSRC_MUX | RTCP_MUX | DTLS, SSRC_MUX | RTCP_MUX | DTLS);
972 EXPECT_TRUE(SendOffer());
973 EXPECT_TRUE(SendProvisionalAnswer());
974 EXPECT_TRUE(channel1_->srtp_active());
975 EXPECT_TRUE(channel2_->srtp_active());
976 EXPECT_TRUE(channel1_->rtp_transport()->rtcp_mux_enabled());
977 EXPECT_TRUE(channel2_->rtp_transport()->rtcp_mux_enabled());
978 WaitForThreads(); // Wait for 'sending' flag go through network thread.
979 SendCustomRtp1(kSsrc1, ++sequence_number1_1);
980 WaitForThreads();
981 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
982
983 // Send packets from callee and verify that it is received.
984 SendCustomRtp2(kSsrc2, ++sequence_number2_2);
985 WaitForThreads();
986 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
987
988 // Complete call setup and ensure everything is still OK.
989 EXPECT_TRUE(SendFinalAnswer());
990 EXPECT_TRUE(channel1_->srtp_active());
991 EXPECT_TRUE(channel2_->srtp_active());
992 SendCustomRtp1(kSsrc1, ++sequence_number1_1);
993 SendCustomRtp2(kSsrc2, ++sequence_number2_2);
994 WaitForThreads();
995 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
996 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
997 }
998
999 // Test that we properly send RTP without SRTP from a thread.
SendRtpToRtpOnThread()1000 void SendRtpToRtpOnThread() {
1001 CreateChannels(0, 0);
1002 EXPECT_TRUE(SendInitiate());
1003 EXPECT_TRUE(SendAccept());
1004 ScopedCallThread send_rtp1([this] { SendRtp1(); });
1005 ScopedCallThread send_rtp2([this] { SendRtp2(); });
1006 rtc::Thread* involved_threads[] = {send_rtp1.thread(), send_rtp2.thread()};
1007 WaitForThreads(involved_threads);
1008 EXPECT_TRUE(CheckRtp1());
1009 EXPECT_TRUE(CheckRtp2());
1010 EXPECT_TRUE(CheckNoRtp1());
1011 EXPECT_TRUE(CheckNoRtp2());
1012 }
1013
1014 // Test that the mediachannel retains its sending state after the transport
1015 // becomes non-writable.
SendWithWritabilityLoss()1016 void SendWithWritabilityLoss() {
1017 CreateChannels(RTCP_MUX, RTCP_MUX);
1018 EXPECT_TRUE(SendInitiate());
1019 EXPECT_TRUE(SendAccept());
1020 EXPECT_TRUE(channel1_->rtp_transport()->rtcp_mux_enabled());
1021 EXPECT_TRUE(channel2_->rtp_transport()->rtcp_mux_enabled());
1022 SendRtp1();
1023 SendRtp2();
1024 WaitForThreads();
1025 EXPECT_TRUE(CheckRtp1());
1026 EXPECT_TRUE(CheckRtp2());
1027 EXPECT_TRUE(CheckNoRtp1());
1028 EXPECT_TRUE(CheckNoRtp2());
1029
1030 // Lose writability, which should fail.
1031 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1032 fake_rtp_dtls_transport1_->SetWritable(false);
1033 });
1034 SendRtp1();
1035 SendRtp2();
1036 WaitForThreads();
1037 EXPECT_TRUE(CheckRtp1());
1038 EXPECT_TRUE(CheckNoRtp2());
1039
1040 // Regain writability
1041 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1042 fake_rtp_dtls_transport1_->SetWritable(true);
1043 });
1044 EXPECT_TRUE(media_channel1_->sending());
1045 SendRtp1();
1046 SendRtp2();
1047 WaitForThreads();
1048 EXPECT_TRUE(CheckRtp1());
1049 EXPECT_TRUE(CheckRtp2());
1050 EXPECT_TRUE(CheckNoRtp1());
1051 EXPECT_TRUE(CheckNoRtp2());
1052
1053 // Lose writability completely
1054 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1055 bool asymmetric = true;
1056 fake_rtp_dtls_transport1_->SetDestination(nullptr, asymmetric);
1057 });
1058 EXPECT_TRUE(media_channel1_->sending());
1059
1060 // Should fail also.
1061 SendRtp1();
1062 SendRtp2();
1063 WaitForThreads();
1064 EXPECT_TRUE(CheckRtp1());
1065 EXPECT_TRUE(CheckNoRtp2());
1066 EXPECT_TRUE(CheckNoRtp1());
1067
1068 // Gain writability back
1069 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1070 bool asymmetric = true;
1071 fake_rtp_dtls_transport1_->SetDestination(fake_rtp_dtls_transport2_.get(),
1072 asymmetric);
1073 });
1074 EXPECT_TRUE(media_channel1_->sending());
1075 SendRtp1();
1076 SendRtp2();
1077 WaitForThreads();
1078 EXPECT_TRUE(CheckRtp1());
1079 EXPECT_TRUE(CheckRtp2());
1080 EXPECT_TRUE(CheckNoRtp1());
1081 EXPECT_TRUE(CheckNoRtp2());
1082 }
1083
SendBundleToBundle(const int * pl_types,int len,bool rtcp_mux,bool secure)1084 void SendBundleToBundle(const int* pl_types,
1085 int len,
1086 bool rtcp_mux,
1087 bool secure) {
1088 ASSERT_EQ(2, len);
1089 int sequence_number1_1 = 0, sequence_number2_2 = 0;
1090 // Only pl_type1 was added to the bundle filter for both |channel1_|
1091 // and |channel2_|.
1092 int pl_type1 = pl_types[0];
1093 int pl_type2 = pl_types[1];
1094 int flags = SSRC_MUX;
1095 if (secure)
1096 flags |= DTLS;
1097 if (rtcp_mux) {
1098 flags |= RTCP_MUX;
1099 }
1100 CreateChannels(flags, flags);
1101 EXPECT_TRUE(SendInitiate());
1102 EXPECT_TRUE(SendAccept());
1103
1104 // Both channels can receive pl_type1 only.
1105 SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type1);
1106 SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type1);
1107 WaitForThreads();
1108 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type1));
1109 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type1));
1110 EXPECT_TRUE(CheckNoRtp1());
1111 EXPECT_TRUE(CheckNoRtp2());
1112
1113 SendCustomRtp1(kSsrc3, ++sequence_number1_1, pl_type2);
1114 SendCustomRtp2(kSsrc4, ++sequence_number2_2, pl_type2);
1115 WaitForThreads();
1116 EXPECT_FALSE(CheckCustomRtp2(kSsrc3, sequence_number1_1, pl_type2));
1117 EXPECT_FALSE(CheckCustomRtp1(kSsrc4, sequence_number2_2, pl_type2));
1118 }
1119
TestSetContentFailure()1120 void TestSetContentFailure() {
1121 CreateChannels(0, 0);
1122
1123 std::string err;
1124 std::unique_ptr<typename T::Content> content(
1125 CreateMediaContentWithStream(1));
1126
1127 media_channel1_->set_fail_set_recv_codecs(true);
1128 EXPECT_FALSE(
1129 channel1_->SetLocalContent(content.get(), SdpType::kOffer, &err));
1130 EXPECT_FALSE(
1131 channel1_->SetLocalContent(content.get(), SdpType::kAnswer, &err));
1132
1133 media_channel1_->set_fail_set_send_codecs(true);
1134 EXPECT_FALSE(
1135 channel1_->SetRemoteContent(content.get(), SdpType::kOffer, &err));
1136
1137 media_channel1_->set_fail_set_send_codecs(true);
1138 EXPECT_FALSE(
1139 channel1_->SetRemoteContent(content.get(), SdpType::kAnswer, &err));
1140 }
1141
TestSendTwoOffers()1142 void TestSendTwoOffers() {
1143 CreateChannels(0, 0);
1144
1145 std::string err;
1146 std::unique_ptr<typename T::Content> content1(
1147 CreateMediaContentWithStream(1));
1148 EXPECT_TRUE(
1149 channel1_->SetLocalContent(content1.get(), SdpType::kOffer, &err));
1150 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1151
1152 std::unique_ptr<typename T::Content> content2(
1153 CreateMediaContentWithStream(2));
1154 EXPECT_TRUE(
1155 channel1_->SetLocalContent(content2.get(), SdpType::kOffer, &err));
1156 EXPECT_FALSE(media_channel1_->HasSendStream(1));
1157 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1158 }
1159
TestReceiveTwoOffers()1160 void TestReceiveTwoOffers() {
1161 CreateChannels(0, 0);
1162
1163 std::string err;
1164 std::unique_ptr<typename T::Content> content1(
1165 CreateMediaContentWithStream(1));
1166 EXPECT_TRUE(
1167 channel1_->SetRemoteContent(content1.get(), SdpType::kOffer, &err));
1168 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1169
1170 std::unique_ptr<typename T::Content> content2(
1171 CreateMediaContentWithStream(2));
1172 EXPECT_TRUE(
1173 channel1_->SetRemoteContent(content2.get(), SdpType::kOffer, &err));
1174 EXPECT_FALSE(media_channel1_->HasRecvStream(1));
1175 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1176 }
1177
TestSendPrAnswer()1178 void TestSendPrAnswer() {
1179 CreateChannels(0, 0);
1180
1181 std::string err;
1182 // Receive offer
1183 std::unique_ptr<typename T::Content> content1(
1184 CreateMediaContentWithStream(1));
1185 EXPECT_TRUE(
1186 channel1_->SetRemoteContent(content1.get(), SdpType::kOffer, &err));
1187 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1188
1189 // Send PR answer
1190 std::unique_ptr<typename T::Content> content2(
1191 CreateMediaContentWithStream(2));
1192 EXPECT_TRUE(
1193 channel1_->SetLocalContent(content2.get(), SdpType::kPrAnswer, &err));
1194 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1195 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1196
1197 // Send answer
1198 std::unique_ptr<typename T::Content> content3(
1199 CreateMediaContentWithStream(3));
1200 EXPECT_TRUE(
1201 channel1_->SetLocalContent(content3.get(), SdpType::kAnswer, &err));
1202 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1203 EXPECT_FALSE(media_channel1_->HasSendStream(2));
1204 EXPECT_TRUE(media_channel1_->HasSendStream(3));
1205 }
1206
TestReceivePrAnswer()1207 void TestReceivePrAnswer() {
1208 CreateChannels(0, 0);
1209
1210 std::string err;
1211 // Send offer
1212 std::unique_ptr<typename T::Content> content1(
1213 CreateMediaContentWithStream(1));
1214 EXPECT_TRUE(
1215 channel1_->SetLocalContent(content1.get(), SdpType::kOffer, &err));
1216 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1217
1218 // Receive PR answer
1219 std::unique_ptr<typename T::Content> content2(
1220 CreateMediaContentWithStream(2));
1221 EXPECT_TRUE(
1222 channel1_->SetRemoteContent(content2.get(), SdpType::kPrAnswer, &err));
1223 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1224 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1225
1226 // Receive answer
1227 std::unique_ptr<typename T::Content> content3(
1228 CreateMediaContentWithStream(3));
1229 EXPECT_TRUE(
1230 channel1_->SetRemoteContent(content3.get(), SdpType::kAnswer, &err));
1231 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1232 EXPECT_FALSE(media_channel1_->HasRecvStream(2));
1233 EXPECT_TRUE(media_channel1_->HasRecvStream(3));
1234 }
1235
TestOnTransportReadyToSend()1236 void TestOnTransportReadyToSend() {
1237 CreateChannels(0, 0);
1238 EXPECT_FALSE(media_channel1_->ready_to_send());
1239
1240 channel1_->OnTransportReadyToSend(true);
1241 WaitForThreads();
1242 EXPECT_TRUE(media_channel1_->ready_to_send());
1243
1244 channel1_->OnTransportReadyToSend(false);
1245 WaitForThreads();
1246 EXPECT_FALSE(media_channel1_->ready_to_send());
1247 }
1248
SetRemoteContentWithBitrateLimit(int remote_limit)1249 bool SetRemoteContentWithBitrateLimit(int remote_limit) {
1250 typename T::Content content;
1251 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1252 content.set_bandwidth(remote_limit);
1253 return channel1_->SetRemoteContent(&content, SdpType::kOffer, NULL);
1254 }
1255
BitrateLimitedParameters(absl::optional<int> limit)1256 webrtc::RtpParameters BitrateLimitedParameters(absl::optional<int> limit) {
1257 webrtc::RtpParameters parameters;
1258 webrtc::RtpEncodingParameters encoding;
1259 encoding.max_bitrate_bps = limit;
1260 parameters.encodings.push_back(encoding);
1261 return parameters;
1262 }
1263
VerifyMaxBitrate(const webrtc::RtpParameters & parameters,absl::optional<int> expected_bitrate)1264 void VerifyMaxBitrate(const webrtc::RtpParameters& parameters,
1265 absl::optional<int> expected_bitrate) {
1266 EXPECT_EQ(1UL, parameters.encodings.size());
1267 EXPECT_EQ(expected_bitrate, parameters.encodings[0].max_bitrate_bps);
1268 }
1269
DefaultMaxBitrateIsUnlimited()1270 void DefaultMaxBitrateIsUnlimited() {
1271 CreateChannels(0, 0);
1272 EXPECT_TRUE(channel1_->SetLocalContent(&local_media_content1_,
1273 SdpType::kOffer, NULL));
1274 EXPECT_EQ(media_channel1_->max_bps(), -1);
1275 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1),
1276 absl::nullopt);
1277 }
1278
1279 // Test that when a channel gets new RtpTransport with a call to
1280 // |SetRtpTransport|, the socket options from the old RtpTransport is merged
1281 // with the options on the new one.
1282
1283 // For example, audio and video may use separate socket options, but initially
1284 // be unbundled, then later become bundled. When this happens, their preferred
1285 // socket options should be merged to the underlying transport they share.
SocketOptionsMergedOnSetTransport()1286 void SocketOptionsMergedOnSetTransport() {
1287 constexpr int kSndBufSize = 4000;
1288 constexpr int kRcvBufSize = 8000;
1289
1290 CreateChannels(DTLS, DTLS);
1291
1292 channel1_->SetOption(cricket::BaseChannel::ST_RTP,
1293 rtc::Socket::Option::OPT_SNDBUF, kSndBufSize);
1294 channel2_->SetOption(cricket::BaseChannel::ST_RTP,
1295 rtc::Socket::Option::OPT_RCVBUF, kRcvBufSize);
1296
1297 new_rtp_transport_ = CreateDtlsSrtpTransport(
1298 fake_rtp_dtls_transport2_.get(), fake_rtcp_dtls_transport2_.get());
1299 channel1_->SetRtpTransport(new_rtp_transport_.get());
1300
1301 int option_val;
1302 ASSERT_TRUE(fake_rtp_dtls_transport2_->GetOption(
1303 rtc::Socket::Option::OPT_SNDBUF, &option_val));
1304 EXPECT_EQ(kSndBufSize, option_val);
1305 ASSERT_TRUE(fake_rtp_dtls_transport2_->GetOption(
1306 rtc::Socket::Option::OPT_RCVBUF, &option_val));
1307 EXPECT_EQ(kRcvBufSize, option_val);
1308 }
1309
CreateSimulcastContent(const std::vector<std::string> & rids,typename T::Content * content)1310 void CreateSimulcastContent(const std::vector<std::string>& rids,
1311 typename T::Content* content) {
1312 std::vector<RidDescription> rid_descriptions;
1313 for (const std::string& name : rids) {
1314 rid_descriptions.push_back(RidDescription(name, RidDirection::kSend));
1315 }
1316
1317 StreamParams stream;
1318 stream.set_rids(rid_descriptions);
1319 CreateContent(0, kPcmuCodec, kH264Codec, content);
1320 // This is for unified plan, so there can be only one StreamParams.
1321 content->mutable_streams().clear();
1322 content->AddStream(stream);
1323 }
1324
VerifySimulcastStreamParams(const StreamParams & expected,const typename T::Channel * channel)1325 void VerifySimulcastStreamParams(const StreamParams& expected,
1326 const typename T::Channel* channel) {
1327 const std::vector<StreamParams>& streams = channel->local_streams();
1328 ASSERT_EQ(1u, streams.size());
1329 const StreamParams& result = streams[0];
1330 EXPECT_EQ(expected.rids(), result.rids());
1331 EXPECT_TRUE(result.has_ssrcs());
1332 EXPECT_EQ(expected.rids().size() * 2, result.ssrcs.size());
1333 std::vector<uint32_t> primary_ssrcs;
1334 result.GetPrimarySsrcs(&primary_ssrcs);
1335 EXPECT_EQ(expected.rids().size(), primary_ssrcs.size());
1336 }
1337
TestUpdateLocalStreamsWithSimulcast()1338 void TestUpdateLocalStreamsWithSimulcast() {
1339 CreateChannels(0, 0);
1340 typename T::Content content1, content2, content3;
1341 CreateSimulcastContent({"f", "h", "q"}, &content1);
1342 EXPECT_TRUE(
1343 channel1_->SetLocalContent(&content1, SdpType::kOffer, nullptr));
1344 VerifySimulcastStreamParams(content1.streams()[0], channel1_.get());
1345 StreamParams stream1 = channel1_->local_streams()[0];
1346
1347 // Create a similar offer. SetLocalContent should not remove and add.
1348 CreateSimulcastContent({"f", "h", "q"}, &content2);
1349 EXPECT_TRUE(
1350 channel1_->SetLocalContent(&content2, SdpType::kOffer, nullptr));
1351 VerifySimulcastStreamParams(content2.streams()[0], channel1_.get());
1352 StreamParams stream2 = channel1_->local_streams()[0];
1353 // Check that the streams are identical (SSRCs didn't change).
1354 EXPECT_EQ(stream1, stream2);
1355
1356 // Create third offer that has same RIDs in different order.
1357 CreateSimulcastContent({"f", "q", "h"}, &content3);
1358 EXPECT_TRUE(
1359 channel1_->SetLocalContent(&content3, SdpType::kOffer, nullptr));
1360 VerifySimulcastStreamParams(content3.streams()[0], channel1_.get());
1361 }
1362
1363 protected:
WaitForThreads()1364 void WaitForThreads() { WaitForThreads(rtc::ArrayView<rtc::Thread*>()); }
ProcessThreadQueue(rtc::Thread * thread)1365 static void ProcessThreadQueue(rtc::Thread* thread) {
1366 RTC_DCHECK(thread->IsCurrent());
1367 while (!thread->empty()) {
1368 thread->ProcessMessages(0);
1369 }
1370 }
WaitForThreads(rtc::ArrayView<rtc::Thread * > threads)1371 void WaitForThreads(rtc::ArrayView<rtc::Thread*> threads) {
1372 // |threads| and current thread post packets to network thread.
1373 for (rtc::Thread* thread : threads) {
1374 thread->Invoke<void>(RTC_FROM_HERE,
1375 [thread] { ProcessThreadQueue(thread); });
1376 }
1377 ProcessThreadQueue(rtc::Thread::Current());
1378 // Network thread move them around and post back to worker = current thread.
1379 if (!network_thread_->IsCurrent()) {
1380 network_thread_->Invoke<void>(
1381 RTC_FROM_HERE, [this] { ProcessThreadQueue(network_thread_); });
1382 }
1383 // Worker thread = current Thread process received messages.
1384 ProcessThreadQueue(rtc::Thread::Current());
1385 }
1386 // TODO(pbos): Remove playout from all media channels and let renderers mute
1387 // themselves.
1388 const bool verify_playout_;
1389 std::unique_ptr<rtc::Thread> network_thread_keeper_;
1390 rtc::Thread* network_thread_;
1391 std::unique_ptr<cricket::FakeDtlsTransport> fake_rtp_dtls_transport1_;
1392 std::unique_ptr<cricket::FakeDtlsTransport> fake_rtcp_dtls_transport1_;
1393 std::unique_ptr<cricket::FakeDtlsTransport> fake_rtp_dtls_transport2_;
1394 std::unique_ptr<cricket::FakeDtlsTransport> fake_rtcp_dtls_transport2_;
1395 std::unique_ptr<rtc::FakePacketTransport> fake_rtp_packet_transport1_;
1396 std::unique_ptr<rtc::FakePacketTransport> fake_rtcp_packet_transport1_;
1397 std::unique_ptr<rtc::FakePacketTransport> fake_rtp_packet_transport2_;
1398 std::unique_ptr<rtc::FakePacketTransport> fake_rtcp_packet_transport2_;
1399 std::unique_ptr<webrtc::RtpTransportInternal> rtp_transport1_;
1400 std::unique_ptr<webrtc::RtpTransportInternal> rtp_transport2_;
1401 std::unique_ptr<webrtc::RtpTransportInternal> new_rtp_transport_;
1402 cricket::FakeMediaEngine media_engine_;
1403 // The media channels are owned by the voice channel objects below.
1404 typename T::MediaChannel* media_channel1_ = nullptr;
1405 typename T::MediaChannel* media_channel2_ = nullptr;
1406 std::unique_ptr<typename T::Channel> channel1_;
1407 std::unique_ptr<typename T::Channel> channel2_;
1408 typename T::Content local_media_content1_;
1409 typename T::Content local_media_content2_;
1410 typename T::Content remote_media_content1_;
1411 typename T::Content remote_media_content2_;
1412 // The RTP and RTCP packets to send in the tests.
1413 rtc::Buffer rtp_packet_;
1414 rtc::Buffer rtcp_packet_;
1415 int rtcp_mux_activated_callbacks1_ = 0;
1416 int rtcp_mux_activated_callbacks2_ = 0;
1417 cricket::CandidatePairInterface* last_selected_candidate_pair_;
1418 rtc::UniqueRandomIdGenerator ssrc_generator_;
1419 };
1420
1421 template <>
CreateChannel(rtc::Thread * worker_thread,rtc::Thread * network_thread,std::unique_ptr<cricket::FakeVoiceMediaChannel> ch,webrtc::RtpTransportInternal * rtp_transport,int flags)1422 std::unique_ptr<cricket::VoiceChannel> ChannelTest<VoiceTraits>::CreateChannel(
1423 rtc::Thread* worker_thread,
1424 rtc::Thread* network_thread,
1425 std::unique_ptr<cricket::FakeVoiceMediaChannel> ch,
1426 webrtc::RtpTransportInternal* rtp_transport,
1427 int flags) {
1428 rtc::Thread* signaling_thread = rtc::Thread::Current();
1429 auto channel = std::make_unique<cricket::VoiceChannel>(
1430 worker_thread, network_thread, signaling_thread, std::move(ch),
1431 cricket::CN_AUDIO, (flags & DTLS) != 0, webrtc::CryptoOptions(),
1432 &ssrc_generator_);
1433 channel->Init_w(rtp_transport);
1434 return channel;
1435 }
1436
1437 template <>
CreateContent(int flags,const cricket::AudioCodec & audio_codec,const cricket::VideoCodec & video_codec,cricket::AudioContentDescription * audio)1438 void ChannelTest<VoiceTraits>::CreateContent(
1439 int flags,
1440 const cricket::AudioCodec& audio_codec,
1441 const cricket::VideoCodec& video_codec,
1442 cricket::AudioContentDescription* audio) {
1443 audio->AddCodec(audio_codec);
1444 audio->set_rtcp_mux((flags & RTCP_MUX) != 0);
1445 }
1446
1447 template <>
CopyContent(const cricket::AudioContentDescription & source,cricket::AudioContentDescription * audio)1448 void ChannelTest<VoiceTraits>::CopyContent(
1449 const cricket::AudioContentDescription& source,
1450 cricket::AudioContentDescription* audio) {
1451 *audio = source;
1452 }
1453
1454 template <>
CodecMatches(const cricket::AudioCodec & c1,const cricket::AudioCodec & c2)1455 bool ChannelTest<VoiceTraits>::CodecMatches(const cricket::AudioCodec& c1,
1456 const cricket::AudioCodec& c2) {
1457 return c1.name == c2.name && c1.clockrate == c2.clockrate &&
1458 c1.bitrate == c2.bitrate && c1.channels == c2.channels;
1459 }
1460
1461 template <>
AddLegacyStreamInContent(uint32_t ssrc,int flags,cricket::AudioContentDescription * audio)1462 void ChannelTest<VoiceTraits>::AddLegacyStreamInContent(
1463 uint32_t ssrc,
1464 int flags,
1465 cricket::AudioContentDescription* audio) {
1466 audio->AddLegacyStream(ssrc);
1467 }
1468
1469 class VoiceChannelSingleThreadTest : public ChannelTest<VoiceTraits> {
1470 public:
1471 typedef ChannelTest<VoiceTraits> Base;
VoiceChannelSingleThreadTest()1472 VoiceChannelSingleThreadTest()
1473 : Base(true, kPcmuFrame, kRtcpReport, NetworkIsWorker::Yes) {}
1474 };
1475
1476 class VoiceChannelDoubleThreadTest : public ChannelTest<VoiceTraits> {
1477 public:
1478 typedef ChannelTest<VoiceTraits> Base;
VoiceChannelDoubleThreadTest()1479 VoiceChannelDoubleThreadTest()
1480 : Base(true, kPcmuFrame, kRtcpReport, NetworkIsWorker::No) {}
1481 };
1482
1483 class VoiceChannelWithEncryptedRtpHeaderExtensionsSingleThreadTest
1484 : public ChannelTest<VoiceTraits> {
1485 public:
1486 typedef ChannelTest<VoiceTraits> Base;
VoiceChannelWithEncryptedRtpHeaderExtensionsSingleThreadTest()1487 VoiceChannelWithEncryptedRtpHeaderExtensionsSingleThreadTest()
1488 : Base(true,
1489 kPcmuFrameWithExtensions,
1490 kRtcpReport,
1491 NetworkIsWorker::Yes) {}
1492 };
1493
1494 class VoiceChannelWithEncryptedRtpHeaderExtensionsDoubleThreadTest
1495 : public ChannelTest<VoiceTraits> {
1496 public:
1497 typedef ChannelTest<VoiceTraits> Base;
VoiceChannelWithEncryptedRtpHeaderExtensionsDoubleThreadTest()1498 VoiceChannelWithEncryptedRtpHeaderExtensionsDoubleThreadTest()
1499 : Base(true, kPcmuFrameWithExtensions, kRtcpReport, NetworkIsWorker::No) {
1500 }
1501 };
1502
1503 // override to add NULL parameter
1504 template <>
CreateChannel(rtc::Thread * worker_thread,rtc::Thread * network_thread,std::unique_ptr<cricket::FakeVideoMediaChannel> ch,webrtc::RtpTransportInternal * rtp_transport,int flags)1505 std::unique_ptr<cricket::VideoChannel> ChannelTest<VideoTraits>::CreateChannel(
1506 rtc::Thread* worker_thread,
1507 rtc::Thread* network_thread,
1508 std::unique_ptr<cricket::FakeVideoMediaChannel> ch,
1509 webrtc::RtpTransportInternal* rtp_transport,
1510 int flags) {
1511 rtc::Thread* signaling_thread = rtc::Thread::Current();
1512 auto channel = std::make_unique<cricket::VideoChannel>(
1513 worker_thread, network_thread, signaling_thread, std::move(ch),
1514 cricket::CN_VIDEO, (flags & DTLS) != 0, webrtc::CryptoOptions(),
1515 &ssrc_generator_);
1516 channel->Init_w(rtp_transport);
1517 return channel;
1518 }
1519
1520 template <>
CreateContent(int flags,const cricket::AudioCodec & audio_codec,const cricket::VideoCodec & video_codec,cricket::VideoContentDescription * video)1521 void ChannelTest<VideoTraits>::CreateContent(
1522 int flags,
1523 const cricket::AudioCodec& audio_codec,
1524 const cricket::VideoCodec& video_codec,
1525 cricket::VideoContentDescription* video) {
1526 video->AddCodec(video_codec);
1527 video->set_rtcp_mux((flags & RTCP_MUX) != 0);
1528 }
1529
1530 template <>
CopyContent(const cricket::VideoContentDescription & source,cricket::VideoContentDescription * video)1531 void ChannelTest<VideoTraits>::CopyContent(
1532 const cricket::VideoContentDescription& source,
1533 cricket::VideoContentDescription* video) {
1534 *video = source;
1535 }
1536
1537 template <>
CodecMatches(const cricket::VideoCodec & c1,const cricket::VideoCodec & c2)1538 bool ChannelTest<VideoTraits>::CodecMatches(const cricket::VideoCodec& c1,
1539 const cricket::VideoCodec& c2) {
1540 return c1.name == c2.name;
1541 }
1542
1543 template <>
AddLegacyStreamInContent(uint32_t ssrc,int flags,cricket::VideoContentDescription * video)1544 void ChannelTest<VideoTraits>::AddLegacyStreamInContent(
1545 uint32_t ssrc,
1546 int flags,
1547 cricket::VideoContentDescription* video) {
1548 video->AddLegacyStream(ssrc);
1549 }
1550
1551 class VideoChannelSingleThreadTest : public ChannelTest<VideoTraits> {
1552 public:
1553 typedef ChannelTest<VideoTraits> Base;
VideoChannelSingleThreadTest()1554 VideoChannelSingleThreadTest()
1555 : Base(false, kH264Packet, kRtcpReport, NetworkIsWorker::Yes) {}
1556 };
1557
1558 class VideoChannelDoubleThreadTest : public ChannelTest<VideoTraits> {
1559 public:
1560 typedef ChannelTest<VideoTraits> Base;
VideoChannelDoubleThreadTest()1561 VideoChannelDoubleThreadTest()
1562 : Base(false, kH264Packet, kRtcpReport, NetworkIsWorker::No) {}
1563 };
1564
TEST_F(VoiceChannelSingleThreadTest,TestInit)1565 TEST_F(VoiceChannelSingleThreadTest, TestInit) {
1566 Base::TestInit();
1567 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
1568 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
1569 }
1570
TEST_F(VoiceChannelSingleThreadTest,TestDeinit)1571 TEST_F(VoiceChannelSingleThreadTest, TestDeinit) {
1572 Base::TestDeinit();
1573 }
1574
TEST_F(VoiceChannelSingleThreadTest,TestSetContents)1575 TEST_F(VoiceChannelSingleThreadTest, TestSetContents) {
1576 Base::TestSetContents();
1577 }
1578
TEST_F(VoiceChannelSingleThreadTest,TestSetContentsExtmapAllowMixedAsCaller)1579 TEST_F(VoiceChannelSingleThreadTest, TestSetContentsExtmapAllowMixedAsCaller) {
1580 Base::TestSetContentsExtmapAllowMixedCaller(/*offer=*/true, /*answer=*/true);
1581 }
1582
TEST_F(VoiceChannelSingleThreadTest,TestSetContentsExtmapAllowMixedNotSupportedAsCaller)1583 TEST_F(VoiceChannelSingleThreadTest,
1584 TestSetContentsExtmapAllowMixedNotSupportedAsCaller) {
1585 Base::TestSetContentsExtmapAllowMixedCaller(/*offer=*/true, /*answer=*/false);
1586 }
1587
TEST_F(VoiceChannelSingleThreadTest,TestSetContentsExtmapAllowMixedAsCallee)1588 TEST_F(VoiceChannelSingleThreadTest, TestSetContentsExtmapAllowMixedAsCallee) {
1589 Base::TestSetContentsExtmapAllowMixedCallee(/*offer=*/true, /*answer=*/true);
1590 }
1591
TEST_F(VoiceChannelSingleThreadTest,TestSetContentsExtmapAllowMixedNotSupportedAsCallee)1592 TEST_F(VoiceChannelSingleThreadTest,
1593 TestSetContentsExtmapAllowMixedNotSupportedAsCallee) {
1594 Base::TestSetContentsExtmapAllowMixedCallee(/*offer=*/true, /*answer=*/false);
1595 }
1596
TEST_F(VoiceChannelSingleThreadTest,TestSetContentsNullOffer)1597 TEST_F(VoiceChannelSingleThreadTest, TestSetContentsNullOffer) {
1598 Base::TestSetContentsNullOffer();
1599 }
1600
TEST_F(VoiceChannelSingleThreadTest,TestSetContentsRtcpMux)1601 TEST_F(VoiceChannelSingleThreadTest, TestSetContentsRtcpMux) {
1602 Base::TestSetContentsRtcpMux();
1603 }
1604
TEST_F(VoiceChannelSingleThreadTest,TestSetContentsRtcpMuxWithPrAnswer)1605 TEST_F(VoiceChannelSingleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
1606 Base::TestSetContentsRtcpMux();
1607 }
1608
TEST_F(VoiceChannelSingleThreadTest,TestChangeStreamParamsInContent)1609 TEST_F(VoiceChannelSingleThreadTest, TestChangeStreamParamsInContent) {
1610 Base::TestChangeStreamParamsInContent();
1611 }
1612
TEST_F(VoiceChannelSingleThreadTest,TestPlayoutAndSendingStates)1613 TEST_F(VoiceChannelSingleThreadTest, TestPlayoutAndSendingStates) {
1614 Base::TestPlayoutAndSendingStates();
1615 }
1616
TEST_F(VoiceChannelSingleThreadTest,TestMediaContentDirection)1617 TEST_F(VoiceChannelSingleThreadTest, TestMediaContentDirection) {
1618 Base::TestMediaContentDirection();
1619 }
1620
TEST_F(VoiceChannelSingleThreadTest,TestNetworkRouteChanges)1621 TEST_F(VoiceChannelSingleThreadTest, TestNetworkRouteChanges) {
1622 Base::TestNetworkRouteChanges();
1623 }
1624
TEST_F(VoiceChannelSingleThreadTest,TestCallSetup)1625 TEST_F(VoiceChannelSingleThreadTest, TestCallSetup) {
1626 Base::TestCallSetup();
1627 }
1628
TEST_F(VoiceChannelSingleThreadTest,TestCallTeardownRtcpMux)1629 TEST_F(VoiceChannelSingleThreadTest, TestCallTeardownRtcpMux) {
1630 Base::TestCallTeardownRtcpMux();
1631 }
1632
TEST_F(VoiceChannelSingleThreadTest,SendRtpToRtp)1633 TEST_F(VoiceChannelSingleThreadTest, SendRtpToRtp) {
1634 Base::SendRtpToRtp();
1635 }
1636
TEST_F(VoiceChannelSingleThreadTest,SendDtlsSrtpToDtlsSrtp)1637 TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtp) {
1638 Base::SendDtlsSrtpToDtlsSrtp(0, 0);
1639 }
1640
TEST_F(VoiceChannelSingleThreadTest,SendDtlsSrtpToDtlsSrtpRtcpMux)1641 TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
1642 Base::SendDtlsSrtpToDtlsSrtp(RTCP_MUX, RTCP_MUX);
1643 }
1644
TEST_F(VoiceChannelSingleThreadTest,SendEarlyMediaUsingRtcpMuxSrtp)1645 TEST_F(VoiceChannelSingleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
1646 Base::SendEarlyMediaUsingRtcpMuxSrtp();
1647 }
1648
TEST_F(VoiceChannelSingleThreadTest,SendRtpToRtpOnThread)1649 TEST_F(VoiceChannelSingleThreadTest, SendRtpToRtpOnThread) {
1650 Base::SendRtpToRtpOnThread();
1651 }
1652
TEST_F(VoiceChannelSingleThreadTest,SendWithWritabilityLoss)1653 TEST_F(VoiceChannelSingleThreadTest, SendWithWritabilityLoss) {
1654 Base::SendWithWritabilityLoss();
1655 }
1656
TEST_F(VoiceChannelSingleThreadTest,TestSetContentFailure)1657 TEST_F(VoiceChannelSingleThreadTest, TestSetContentFailure) {
1658 Base::TestSetContentFailure();
1659 }
1660
TEST_F(VoiceChannelSingleThreadTest,TestSendTwoOffers)1661 TEST_F(VoiceChannelSingleThreadTest, TestSendTwoOffers) {
1662 Base::TestSendTwoOffers();
1663 }
1664
TEST_F(VoiceChannelSingleThreadTest,TestReceiveTwoOffers)1665 TEST_F(VoiceChannelSingleThreadTest, TestReceiveTwoOffers) {
1666 Base::TestReceiveTwoOffers();
1667 }
1668
TEST_F(VoiceChannelSingleThreadTest,TestSendPrAnswer)1669 TEST_F(VoiceChannelSingleThreadTest, TestSendPrAnswer) {
1670 Base::TestSendPrAnswer();
1671 }
1672
TEST_F(VoiceChannelSingleThreadTest,TestReceivePrAnswer)1673 TEST_F(VoiceChannelSingleThreadTest, TestReceivePrAnswer) {
1674 Base::TestReceivePrAnswer();
1675 }
1676
TEST_F(VoiceChannelSingleThreadTest,TestOnTransportReadyToSend)1677 TEST_F(VoiceChannelSingleThreadTest, TestOnTransportReadyToSend) {
1678 Base::TestOnTransportReadyToSend();
1679 }
1680
TEST_F(VoiceChannelSingleThreadTest,SendBundleToBundle)1681 TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundle) {
1682 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false);
1683 }
1684
TEST_F(VoiceChannelSingleThreadTest,SendBundleToBundleSecure)1685 TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleSecure) {
1686 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true);
1687 }
1688
TEST_F(VoiceChannelSingleThreadTest,SendBundleToBundleWithRtcpMux)1689 TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleWithRtcpMux) {
1690 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false);
1691 }
1692
TEST_F(VoiceChannelSingleThreadTest,SendBundleToBundleWithRtcpMuxSecure)1693 TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
1694 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true);
1695 }
1696
TEST_F(VoiceChannelSingleThreadTest,DefaultMaxBitrateIsUnlimited)1697 TEST_F(VoiceChannelSingleThreadTest, DefaultMaxBitrateIsUnlimited) {
1698 Base::DefaultMaxBitrateIsUnlimited();
1699 }
1700
TEST_F(VoiceChannelSingleThreadTest,SocketOptionsMergedOnSetTransport)1701 TEST_F(VoiceChannelSingleThreadTest, SocketOptionsMergedOnSetTransport) {
1702 Base::SocketOptionsMergedOnSetTransport();
1703 }
1704
1705 // VoiceChannelDoubleThreadTest
TEST_F(VoiceChannelDoubleThreadTest,TestInit)1706 TEST_F(VoiceChannelDoubleThreadTest, TestInit) {
1707 Base::TestInit();
1708 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
1709 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
1710 }
1711
TEST_F(VoiceChannelDoubleThreadTest,TestDeinit)1712 TEST_F(VoiceChannelDoubleThreadTest, TestDeinit) {
1713 Base::TestDeinit();
1714 }
1715
TEST_F(VoiceChannelDoubleThreadTest,TestSetContents)1716 TEST_F(VoiceChannelDoubleThreadTest, TestSetContents) {
1717 Base::TestSetContents();
1718 }
1719
TEST_F(VoiceChannelDoubleThreadTest,TestSetContentsExtmapAllowMixedAsCaller)1720 TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsExtmapAllowMixedAsCaller) {
1721 Base::TestSetContentsExtmapAllowMixedCaller(/*offer=*/true, /*answer=*/true);
1722 }
1723
TEST_F(VoiceChannelDoubleThreadTest,TestSetContentsExtmapAllowMixedNotSupportedAsCaller)1724 TEST_F(VoiceChannelDoubleThreadTest,
1725 TestSetContentsExtmapAllowMixedNotSupportedAsCaller) {
1726 Base::TestSetContentsExtmapAllowMixedCaller(/*offer=*/true, /*answer=*/false);
1727 }
1728
TEST_F(VoiceChannelDoubleThreadTest,TestSetContentsExtmapAllowMixedAsCallee)1729 TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsExtmapAllowMixedAsCallee) {
1730 Base::TestSetContentsExtmapAllowMixedCallee(/*offer=*/true, /*answer=*/true);
1731 }
1732
TEST_F(VoiceChannelDoubleThreadTest,TestSetContentsExtmapAllowMixedNotSupportedAsCallee)1733 TEST_F(VoiceChannelDoubleThreadTest,
1734 TestSetContentsExtmapAllowMixedNotSupportedAsCallee) {
1735 Base::TestSetContentsExtmapAllowMixedCallee(/*offer=*/true, /*answer=*/false);
1736 }
1737
TEST_F(VoiceChannelDoubleThreadTest,TestSetContentsNullOffer)1738 TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsNullOffer) {
1739 Base::TestSetContentsNullOffer();
1740 }
1741
TEST_F(VoiceChannelDoubleThreadTest,TestSetContentsRtcpMux)1742 TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsRtcpMux) {
1743 Base::TestSetContentsRtcpMux();
1744 }
1745
TEST_F(VoiceChannelDoubleThreadTest,TestSetContentsRtcpMuxWithPrAnswer)1746 TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
1747 Base::TestSetContentsRtcpMux();
1748 }
1749
TEST_F(VoiceChannelDoubleThreadTest,TestChangeStreamParamsInContent)1750 TEST_F(VoiceChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
1751 Base::TestChangeStreamParamsInContent();
1752 }
1753
TEST_F(VoiceChannelDoubleThreadTest,TestPlayoutAndSendingStates)1754 TEST_F(VoiceChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
1755 Base::TestPlayoutAndSendingStates();
1756 }
1757
TEST_F(VoiceChannelDoubleThreadTest,TestMediaContentDirection)1758 TEST_F(VoiceChannelDoubleThreadTest, TestMediaContentDirection) {
1759 Base::TestMediaContentDirection();
1760 }
1761
TEST_F(VoiceChannelDoubleThreadTest,TestNetworkRouteChanges)1762 TEST_F(VoiceChannelDoubleThreadTest, TestNetworkRouteChanges) {
1763 Base::TestNetworkRouteChanges();
1764 }
1765
TEST_F(VoiceChannelDoubleThreadTest,TestCallSetup)1766 TEST_F(VoiceChannelDoubleThreadTest, TestCallSetup) {
1767 Base::TestCallSetup();
1768 }
1769
TEST_F(VoiceChannelDoubleThreadTest,TestCallTeardownRtcpMux)1770 TEST_F(VoiceChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
1771 Base::TestCallTeardownRtcpMux();
1772 }
1773
TEST_F(VoiceChannelDoubleThreadTest,SendRtpToRtp)1774 TEST_F(VoiceChannelDoubleThreadTest, SendRtpToRtp) {
1775 Base::SendRtpToRtp();
1776 }
1777
TEST_F(VoiceChannelDoubleThreadTest,SendDtlsSrtpToDtlsSrtp)1778 TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtp) {
1779 Base::SendDtlsSrtpToDtlsSrtp(0, 0);
1780 }
1781
TEST_F(VoiceChannelDoubleThreadTest,SendDtlsSrtpToDtlsSrtpRtcpMux)1782 TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
1783 Base::SendDtlsSrtpToDtlsSrtp(RTCP_MUX, RTCP_MUX);
1784 }
1785
TEST_F(VoiceChannelDoubleThreadTest,SendEarlyMediaUsingRtcpMuxSrtp)1786 TEST_F(VoiceChannelDoubleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
1787 Base::SendEarlyMediaUsingRtcpMuxSrtp();
1788 }
1789
TEST_F(VoiceChannelDoubleThreadTest,SendRtpToRtpOnThread)1790 TEST_F(VoiceChannelDoubleThreadTest, SendRtpToRtpOnThread) {
1791 Base::SendRtpToRtpOnThread();
1792 }
1793
TEST_F(VoiceChannelDoubleThreadTest,SendWithWritabilityLoss)1794 TEST_F(VoiceChannelDoubleThreadTest, SendWithWritabilityLoss) {
1795 Base::SendWithWritabilityLoss();
1796 }
1797
TEST_F(VoiceChannelDoubleThreadTest,TestSetContentFailure)1798 TEST_F(VoiceChannelDoubleThreadTest, TestSetContentFailure) {
1799 Base::TestSetContentFailure();
1800 }
1801
TEST_F(VoiceChannelDoubleThreadTest,TestSendTwoOffers)1802 TEST_F(VoiceChannelDoubleThreadTest, TestSendTwoOffers) {
1803 Base::TestSendTwoOffers();
1804 }
1805
TEST_F(VoiceChannelDoubleThreadTest,TestReceiveTwoOffers)1806 TEST_F(VoiceChannelDoubleThreadTest, TestReceiveTwoOffers) {
1807 Base::TestReceiveTwoOffers();
1808 }
1809
TEST_F(VoiceChannelDoubleThreadTest,TestSendPrAnswer)1810 TEST_F(VoiceChannelDoubleThreadTest, TestSendPrAnswer) {
1811 Base::TestSendPrAnswer();
1812 }
1813
TEST_F(VoiceChannelDoubleThreadTest,TestReceivePrAnswer)1814 TEST_F(VoiceChannelDoubleThreadTest, TestReceivePrAnswer) {
1815 Base::TestReceivePrAnswer();
1816 }
1817
TEST_F(VoiceChannelDoubleThreadTest,TestOnTransportReadyToSend)1818 TEST_F(VoiceChannelDoubleThreadTest, TestOnTransportReadyToSend) {
1819 Base::TestOnTransportReadyToSend();
1820 }
1821
TEST_F(VoiceChannelDoubleThreadTest,SendBundleToBundle)1822 TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundle) {
1823 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false);
1824 }
1825
TEST_F(VoiceChannelDoubleThreadTest,SendBundleToBundleSecure)1826 TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleSecure) {
1827 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true);
1828 }
1829
TEST_F(VoiceChannelDoubleThreadTest,SendBundleToBundleWithRtcpMux)1830 TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleWithRtcpMux) {
1831 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false);
1832 }
1833
TEST_F(VoiceChannelDoubleThreadTest,SendBundleToBundleWithRtcpMuxSecure)1834 TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
1835 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true);
1836 }
1837
TEST_F(VoiceChannelDoubleThreadTest,DefaultMaxBitrateIsUnlimited)1838 TEST_F(VoiceChannelDoubleThreadTest, DefaultMaxBitrateIsUnlimited) {
1839 Base::DefaultMaxBitrateIsUnlimited();
1840 }
1841
TEST_F(VoiceChannelDoubleThreadTest,SocketOptionsMergedOnSetTransport)1842 TEST_F(VoiceChannelDoubleThreadTest, SocketOptionsMergedOnSetTransport) {
1843 Base::SocketOptionsMergedOnSetTransport();
1844 }
1845
1846 // VideoChannelSingleThreadTest
TEST_F(VideoChannelSingleThreadTest,TestInit)1847 TEST_F(VideoChannelSingleThreadTest, TestInit) {
1848 Base::TestInit();
1849 }
1850
TEST_F(VideoChannelSingleThreadTest,TestDeinit)1851 TEST_F(VideoChannelSingleThreadTest, TestDeinit) {
1852 Base::TestDeinit();
1853 }
1854
TEST_F(VideoChannelSingleThreadTest,TestSetContents)1855 TEST_F(VideoChannelSingleThreadTest, TestSetContents) {
1856 Base::TestSetContents();
1857 }
1858
TEST_F(VideoChannelSingleThreadTest,TestSetContentsExtmapAllowMixedAsCaller)1859 TEST_F(VideoChannelSingleThreadTest, TestSetContentsExtmapAllowMixedAsCaller) {
1860 Base::TestSetContentsExtmapAllowMixedCaller(/*offer=*/true, /*answer=*/true);
1861 }
1862
TEST_F(VideoChannelSingleThreadTest,TestSetContentsExtmapAllowMixedNotSupportedAsCaller)1863 TEST_F(VideoChannelSingleThreadTest,
1864 TestSetContentsExtmapAllowMixedNotSupportedAsCaller) {
1865 Base::TestSetContentsExtmapAllowMixedCaller(/*offer=*/true, /*answer=*/false);
1866 }
1867
TEST_F(VideoChannelSingleThreadTest,TestSetContentsExtmapAllowMixedAsCallee)1868 TEST_F(VideoChannelSingleThreadTest, TestSetContentsExtmapAllowMixedAsCallee) {
1869 Base::TestSetContentsExtmapAllowMixedCallee(/*offer=*/true, /*answer=*/true);
1870 }
1871
TEST_F(VideoChannelSingleThreadTest,TestSetContentsExtmapAllowMixedNotSupportedAsCallee)1872 TEST_F(VideoChannelSingleThreadTest,
1873 TestSetContentsExtmapAllowMixedNotSupportedAsCallee) {
1874 Base::TestSetContentsExtmapAllowMixedCallee(/*offer=*/true, /*answer=*/false);
1875 }
1876
TEST_F(VideoChannelSingleThreadTest,TestSetContentsNullOffer)1877 TEST_F(VideoChannelSingleThreadTest, TestSetContentsNullOffer) {
1878 Base::TestSetContentsNullOffer();
1879 }
1880
TEST_F(VideoChannelSingleThreadTest,TestSetContentsRtcpMux)1881 TEST_F(VideoChannelSingleThreadTest, TestSetContentsRtcpMux) {
1882 Base::TestSetContentsRtcpMux();
1883 }
1884
TEST_F(VideoChannelSingleThreadTest,TestSetContentsRtcpMuxWithPrAnswer)1885 TEST_F(VideoChannelSingleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
1886 Base::TestSetContentsRtcpMux();
1887 }
1888
TEST_F(VideoChannelSingleThreadTest,TestChangeStreamParamsInContent)1889 TEST_F(VideoChannelSingleThreadTest, TestChangeStreamParamsInContent) {
1890 Base::TestChangeStreamParamsInContent();
1891 }
1892
TEST_F(VideoChannelSingleThreadTest,TestPlayoutAndSendingStates)1893 TEST_F(VideoChannelSingleThreadTest, TestPlayoutAndSendingStates) {
1894 Base::TestPlayoutAndSendingStates();
1895 }
1896
TEST_F(VideoChannelSingleThreadTest,TestMediaContentDirection)1897 TEST_F(VideoChannelSingleThreadTest, TestMediaContentDirection) {
1898 Base::TestMediaContentDirection();
1899 }
1900
TEST_F(VideoChannelSingleThreadTest,TestNetworkRouteChanges)1901 TEST_F(VideoChannelSingleThreadTest, TestNetworkRouteChanges) {
1902 Base::TestNetworkRouteChanges();
1903 }
1904
TEST_F(VideoChannelSingleThreadTest,TestCallSetup)1905 TEST_F(VideoChannelSingleThreadTest, TestCallSetup) {
1906 Base::TestCallSetup();
1907 }
1908
TEST_F(VideoChannelSingleThreadTest,TestCallTeardownRtcpMux)1909 TEST_F(VideoChannelSingleThreadTest, TestCallTeardownRtcpMux) {
1910 Base::TestCallTeardownRtcpMux();
1911 }
1912
TEST_F(VideoChannelSingleThreadTest,SendRtpToRtp)1913 TEST_F(VideoChannelSingleThreadTest, SendRtpToRtp) {
1914 Base::SendRtpToRtp();
1915 }
1916
TEST_F(VideoChannelSingleThreadTest,SendDtlsSrtpToDtlsSrtp)1917 TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtp) {
1918 Base::SendDtlsSrtpToDtlsSrtp(0, 0);
1919 }
1920
TEST_F(VideoChannelSingleThreadTest,SendDtlsSrtpToDtlsSrtpRtcpMux)1921 TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
1922 Base::SendDtlsSrtpToDtlsSrtp(RTCP_MUX, RTCP_MUX);
1923 }
1924
TEST_F(VideoChannelSingleThreadTest,SendEarlyMediaUsingRtcpMuxSrtp)1925 TEST_F(VideoChannelSingleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
1926 Base::SendEarlyMediaUsingRtcpMuxSrtp();
1927 }
1928
TEST_F(VideoChannelSingleThreadTest,SendRtpToRtpOnThread)1929 TEST_F(VideoChannelSingleThreadTest, SendRtpToRtpOnThread) {
1930 Base::SendRtpToRtpOnThread();
1931 }
1932
TEST_F(VideoChannelSingleThreadTest,SendWithWritabilityLoss)1933 TEST_F(VideoChannelSingleThreadTest, SendWithWritabilityLoss) {
1934 Base::SendWithWritabilityLoss();
1935 }
1936
TEST_F(VideoChannelSingleThreadTest,TestSetContentFailure)1937 TEST_F(VideoChannelSingleThreadTest, TestSetContentFailure) {
1938 Base::TestSetContentFailure();
1939 }
1940
TEST_F(VideoChannelSingleThreadTest,TestSendTwoOffers)1941 TEST_F(VideoChannelSingleThreadTest, TestSendTwoOffers) {
1942 Base::TestSendTwoOffers();
1943 }
1944
TEST_F(VideoChannelSingleThreadTest,TestReceiveTwoOffers)1945 TEST_F(VideoChannelSingleThreadTest, TestReceiveTwoOffers) {
1946 Base::TestReceiveTwoOffers();
1947 }
1948
TEST_F(VideoChannelSingleThreadTest,TestSendPrAnswer)1949 TEST_F(VideoChannelSingleThreadTest, TestSendPrAnswer) {
1950 Base::TestSendPrAnswer();
1951 }
1952
TEST_F(VideoChannelSingleThreadTest,TestReceivePrAnswer)1953 TEST_F(VideoChannelSingleThreadTest, TestReceivePrAnswer) {
1954 Base::TestReceivePrAnswer();
1955 }
1956
TEST_F(VideoChannelSingleThreadTest,SendBundleToBundle)1957 TEST_F(VideoChannelSingleThreadTest, SendBundleToBundle) {
1958 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, false);
1959 }
1960
TEST_F(VideoChannelSingleThreadTest,SendBundleToBundleSecure)1961 TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleSecure) {
1962 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, true);
1963 }
1964
TEST_F(VideoChannelSingleThreadTest,SendBundleToBundleWithRtcpMux)1965 TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleWithRtcpMux) {
1966 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, false);
1967 }
1968
TEST_F(VideoChannelSingleThreadTest,SendBundleToBundleWithRtcpMuxSecure)1969 TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
1970 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true);
1971 }
1972
TEST_F(VideoChannelSingleThreadTest,TestOnTransportReadyToSend)1973 TEST_F(VideoChannelSingleThreadTest, TestOnTransportReadyToSend) {
1974 Base::TestOnTransportReadyToSend();
1975 }
1976
TEST_F(VideoChannelSingleThreadTest,DefaultMaxBitrateIsUnlimited)1977 TEST_F(VideoChannelSingleThreadTest, DefaultMaxBitrateIsUnlimited) {
1978 Base::DefaultMaxBitrateIsUnlimited();
1979 }
1980
TEST_F(VideoChannelSingleThreadTest,SocketOptionsMergedOnSetTransport)1981 TEST_F(VideoChannelSingleThreadTest, SocketOptionsMergedOnSetTransport) {
1982 Base::SocketOptionsMergedOnSetTransport();
1983 }
1984
TEST_F(VideoChannelSingleThreadTest,UpdateLocalStreamsWithSimulcast)1985 TEST_F(VideoChannelSingleThreadTest, UpdateLocalStreamsWithSimulcast) {
1986 Base::TestUpdateLocalStreamsWithSimulcast();
1987 }
1988
TEST_F(VideoChannelSingleThreadTest,TestSetLocalOfferWithPacketization)1989 TEST_F(VideoChannelSingleThreadTest, TestSetLocalOfferWithPacketization) {
1990 const cricket::VideoCodec kVp8Codec(97, "VP8");
1991 cricket::VideoCodec vp9_codec(98, "VP9");
1992 vp9_codec.packetization = cricket::kPacketizationParamRaw;
1993 cricket::VideoContentDescription video;
1994 video.set_codecs({kVp8Codec, vp9_codec});
1995
1996 CreateChannels(0, 0);
1997
1998 EXPECT_TRUE(channel1_->SetLocalContent(&video, SdpType::kOffer, NULL));
1999 EXPECT_THAT(media_channel1_->send_codecs(), testing::IsEmpty());
2000 ASSERT_THAT(media_channel1_->recv_codecs(), testing::SizeIs(2));
2001 EXPECT_TRUE(media_channel1_->recv_codecs()[0].Matches(kVp8Codec));
2002 EXPECT_EQ(media_channel1_->recv_codecs()[0].packetization, absl::nullopt);
2003 EXPECT_TRUE(media_channel1_->recv_codecs()[1].Matches(vp9_codec));
2004 EXPECT_EQ(media_channel1_->recv_codecs()[1].packetization,
2005 cricket::kPacketizationParamRaw);
2006 }
2007
TEST_F(VideoChannelSingleThreadTest,TestSetRemoteOfferWithPacketization)2008 TEST_F(VideoChannelSingleThreadTest, TestSetRemoteOfferWithPacketization) {
2009 const cricket::VideoCodec kVp8Codec(97, "VP8");
2010 cricket::VideoCodec vp9_codec(98, "VP9");
2011 vp9_codec.packetization = cricket::kPacketizationParamRaw;
2012 cricket::VideoContentDescription video;
2013 video.set_codecs({kVp8Codec, vp9_codec});
2014
2015 CreateChannels(0, 0);
2016
2017 EXPECT_TRUE(channel1_->SetRemoteContent(&video, SdpType::kOffer, NULL));
2018 EXPECT_THAT(media_channel1_->recv_codecs(), testing::IsEmpty());
2019 ASSERT_THAT(media_channel1_->send_codecs(), testing::SizeIs(2));
2020 EXPECT_TRUE(media_channel1_->send_codecs()[0].Matches(kVp8Codec));
2021 EXPECT_EQ(media_channel1_->send_codecs()[0].packetization, absl::nullopt);
2022 EXPECT_TRUE(media_channel1_->send_codecs()[1].Matches(vp9_codec));
2023 EXPECT_EQ(media_channel1_->send_codecs()[1].packetization,
2024 cricket::kPacketizationParamRaw);
2025 }
2026
TEST_F(VideoChannelSingleThreadTest,TestSetAnswerWithPacketization)2027 TEST_F(VideoChannelSingleThreadTest, TestSetAnswerWithPacketization) {
2028 const cricket::VideoCodec kVp8Codec(97, "VP8");
2029 cricket::VideoCodec vp9_codec(98, "VP9");
2030 vp9_codec.packetization = cricket::kPacketizationParamRaw;
2031 cricket::VideoContentDescription video;
2032 video.set_codecs({kVp8Codec, vp9_codec});
2033
2034 CreateChannels(0, 0);
2035
2036 EXPECT_TRUE(channel1_->SetLocalContent(&video, SdpType::kOffer, NULL));
2037 EXPECT_TRUE(channel1_->SetRemoteContent(&video, SdpType::kAnswer, NULL));
2038 ASSERT_THAT(media_channel1_->recv_codecs(), testing::SizeIs(2));
2039 EXPECT_TRUE(media_channel1_->recv_codecs()[0].Matches(kVp8Codec));
2040 EXPECT_EQ(media_channel1_->recv_codecs()[0].packetization, absl::nullopt);
2041 EXPECT_TRUE(media_channel1_->recv_codecs()[1].Matches(vp9_codec));
2042 EXPECT_EQ(media_channel1_->recv_codecs()[1].packetization,
2043 cricket::kPacketizationParamRaw);
2044 EXPECT_THAT(media_channel1_->send_codecs(), testing::SizeIs(2));
2045 EXPECT_TRUE(media_channel1_->send_codecs()[0].Matches(kVp8Codec));
2046 EXPECT_EQ(media_channel1_->send_codecs()[0].packetization, absl::nullopt);
2047 EXPECT_TRUE(media_channel1_->send_codecs()[1].Matches(vp9_codec));
2048 EXPECT_EQ(media_channel1_->send_codecs()[1].packetization,
2049 cricket::kPacketizationParamRaw);
2050 }
2051
TEST_F(VideoChannelSingleThreadTest,TestSetLocalAnswerWithoutPacketization)2052 TEST_F(VideoChannelSingleThreadTest, TestSetLocalAnswerWithoutPacketization) {
2053 const cricket::VideoCodec kLocalCodec(98, "VP8");
2054 cricket::VideoCodec remote_codec(99, "VP8");
2055 remote_codec.packetization = cricket::kPacketizationParamRaw;
2056 cricket::VideoContentDescription local_video;
2057 local_video.set_codecs({kLocalCodec});
2058 cricket::VideoContentDescription remote_video;
2059 remote_video.set_codecs({remote_codec});
2060
2061 CreateChannels(0, 0);
2062
2063 EXPECT_TRUE(
2064 channel1_->SetRemoteContent(&remote_video, SdpType::kOffer, NULL));
2065 EXPECT_TRUE(channel1_->SetLocalContent(&local_video, SdpType::kAnswer, NULL));
2066 ASSERT_THAT(media_channel1_->recv_codecs(), testing::SizeIs(1));
2067 EXPECT_EQ(media_channel1_->recv_codecs()[0].packetization, absl::nullopt);
2068 ASSERT_THAT(media_channel1_->send_codecs(), testing::SizeIs(1));
2069 EXPECT_EQ(media_channel1_->send_codecs()[0].packetization, absl::nullopt);
2070 }
2071
TEST_F(VideoChannelSingleThreadTest,TestSetRemoteAnswerWithoutPacketization)2072 TEST_F(VideoChannelSingleThreadTest, TestSetRemoteAnswerWithoutPacketization) {
2073 cricket::VideoCodec local_codec(98, "VP8");
2074 local_codec.packetization = cricket::kPacketizationParamRaw;
2075 const cricket::VideoCodec kRemoteCodec(99, "VP8");
2076 cricket::VideoContentDescription local_video;
2077 local_video.set_codecs({local_codec});
2078 cricket::VideoContentDescription remote_video;
2079 remote_video.set_codecs({kRemoteCodec});
2080
2081 CreateChannels(0, 0);
2082
2083 EXPECT_TRUE(channel1_->SetLocalContent(&local_video, SdpType::kOffer, NULL));
2084 EXPECT_TRUE(
2085 channel1_->SetRemoteContent(&remote_video, SdpType::kAnswer, NULL));
2086 ASSERT_THAT(media_channel1_->recv_codecs(), testing::SizeIs(1));
2087 EXPECT_EQ(media_channel1_->recv_codecs()[0].packetization, absl::nullopt);
2088 ASSERT_THAT(media_channel1_->send_codecs(), testing::SizeIs(1));
2089 EXPECT_EQ(media_channel1_->send_codecs()[0].packetization, absl::nullopt);
2090 }
2091
TEST_F(VideoChannelSingleThreadTest,TestSetRemoteAnswerWithInvalidPacketization)2092 TEST_F(VideoChannelSingleThreadTest,
2093 TestSetRemoteAnswerWithInvalidPacketization) {
2094 cricket::VideoCodec local_codec(98, "VP8");
2095 local_codec.packetization = cricket::kPacketizationParamRaw;
2096 cricket::VideoCodec remote_codec(99, "VP8");
2097 remote_codec.packetization = "unknownpacketizationattributevalue";
2098 cricket::VideoContentDescription local_video;
2099 local_video.set_codecs({local_codec});
2100 cricket::VideoContentDescription remote_video;
2101 remote_video.set_codecs({remote_codec});
2102
2103 CreateChannels(0, 0);
2104
2105 EXPECT_TRUE(channel1_->SetLocalContent(&local_video, SdpType::kOffer, NULL));
2106 EXPECT_FALSE(
2107 channel1_->SetRemoteContent(&remote_video, SdpType::kAnswer, NULL));
2108 ASSERT_THAT(media_channel1_->recv_codecs(), testing::SizeIs(1));
2109 EXPECT_EQ(media_channel1_->recv_codecs()[0].packetization,
2110 cricket::kPacketizationParamRaw);
2111 EXPECT_THAT(media_channel1_->send_codecs(), testing::IsEmpty());
2112 }
2113
TEST_F(VideoChannelSingleThreadTest,TestSetLocalAnswerWithInvalidPacketization)2114 TEST_F(VideoChannelSingleThreadTest,
2115 TestSetLocalAnswerWithInvalidPacketization) {
2116 cricket::VideoCodec local_codec(98, "VP8");
2117 local_codec.packetization = cricket::kPacketizationParamRaw;
2118 const cricket::VideoCodec kRemoteCodec(99, "VP8");
2119 cricket::VideoContentDescription local_video;
2120 local_video.set_codecs({local_codec});
2121 cricket::VideoContentDescription remote_video;
2122 remote_video.set_codecs({kRemoteCodec});
2123
2124 CreateChannels(0, 0);
2125
2126 EXPECT_TRUE(
2127 channel1_->SetRemoteContent(&remote_video, SdpType::kOffer, NULL));
2128 EXPECT_FALSE(
2129 channel1_->SetLocalContent(&local_video, SdpType::kAnswer, NULL));
2130 EXPECT_THAT(media_channel1_->recv_codecs(), testing::IsEmpty());
2131 ASSERT_THAT(media_channel1_->send_codecs(), testing::SizeIs(1));
2132 EXPECT_EQ(media_channel1_->send_codecs()[0].packetization, absl::nullopt);
2133 }
2134
2135 // VideoChannelDoubleThreadTest
TEST_F(VideoChannelDoubleThreadTest,TestInit)2136 TEST_F(VideoChannelDoubleThreadTest, TestInit) {
2137 Base::TestInit();
2138 }
2139
TEST_F(VideoChannelDoubleThreadTest,TestDeinit)2140 TEST_F(VideoChannelDoubleThreadTest, TestDeinit) {
2141 Base::TestDeinit();
2142 }
2143
TEST_F(VideoChannelDoubleThreadTest,TestSetContents)2144 TEST_F(VideoChannelDoubleThreadTest, TestSetContents) {
2145 Base::TestSetContents();
2146 }
2147
TEST_F(VideoChannelDoubleThreadTest,TestSetContentsExtmapAllowMixedAsCaller)2148 TEST_F(VideoChannelDoubleThreadTest, TestSetContentsExtmapAllowMixedAsCaller) {
2149 Base::TestSetContentsExtmapAllowMixedCaller(/*offer=*/true, /*answer=*/true);
2150 }
2151
TEST_F(VideoChannelDoubleThreadTest,TestSetContentsExtmapAllowMixedNotSupportedAsCaller)2152 TEST_F(VideoChannelDoubleThreadTest,
2153 TestSetContentsExtmapAllowMixedNotSupportedAsCaller) {
2154 Base::TestSetContentsExtmapAllowMixedCaller(/*offer=*/true, /*answer=*/false);
2155 }
2156
TEST_F(VideoChannelDoubleThreadTest,TestSetContentsExtmapAllowMixedAsCallee)2157 TEST_F(VideoChannelDoubleThreadTest, TestSetContentsExtmapAllowMixedAsCallee) {
2158 Base::TestSetContentsExtmapAllowMixedCallee(/*offer=*/true, /*answer=*/true);
2159 }
2160
TEST_F(VideoChannelDoubleThreadTest,TestSetContentsExtmapAllowMixedNotSupportedAsCallee)2161 TEST_F(VideoChannelDoubleThreadTest,
2162 TestSetContentsExtmapAllowMixedNotSupportedAsCallee) {
2163 Base::TestSetContentsExtmapAllowMixedCallee(/*offer=*/true, /*answer=*/false);
2164 }
2165
TEST_F(VideoChannelDoubleThreadTest,TestSetContentsNullOffer)2166 TEST_F(VideoChannelDoubleThreadTest, TestSetContentsNullOffer) {
2167 Base::TestSetContentsNullOffer();
2168 }
2169
TEST_F(VideoChannelDoubleThreadTest,TestSetContentsRtcpMux)2170 TEST_F(VideoChannelDoubleThreadTest, TestSetContentsRtcpMux) {
2171 Base::TestSetContentsRtcpMux();
2172 }
2173
TEST_F(VideoChannelDoubleThreadTest,TestSetContentsRtcpMuxWithPrAnswer)2174 TEST_F(VideoChannelDoubleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
2175 Base::TestSetContentsRtcpMux();
2176 }
2177
TEST_F(VideoChannelDoubleThreadTest,TestChangeStreamParamsInContent)2178 TEST_F(VideoChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
2179 Base::TestChangeStreamParamsInContent();
2180 }
2181
TEST_F(VideoChannelDoubleThreadTest,TestPlayoutAndSendingStates)2182 TEST_F(VideoChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
2183 Base::TestPlayoutAndSendingStates();
2184 }
2185
TEST_F(VideoChannelDoubleThreadTest,TestMediaContentDirection)2186 TEST_F(VideoChannelDoubleThreadTest, TestMediaContentDirection) {
2187 Base::TestMediaContentDirection();
2188 }
2189
TEST_F(VideoChannelDoubleThreadTest,TestNetworkRouteChanges)2190 TEST_F(VideoChannelDoubleThreadTest, TestNetworkRouteChanges) {
2191 Base::TestNetworkRouteChanges();
2192 }
2193
TEST_F(VideoChannelDoubleThreadTest,TestCallSetup)2194 TEST_F(VideoChannelDoubleThreadTest, TestCallSetup) {
2195 Base::TestCallSetup();
2196 }
2197
TEST_F(VideoChannelDoubleThreadTest,TestCallTeardownRtcpMux)2198 TEST_F(VideoChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
2199 Base::TestCallTeardownRtcpMux();
2200 }
2201
TEST_F(VideoChannelDoubleThreadTest,SendRtpToRtp)2202 TEST_F(VideoChannelDoubleThreadTest, SendRtpToRtp) {
2203 Base::SendRtpToRtp();
2204 }
2205
TEST_F(VideoChannelDoubleThreadTest,SendDtlsSrtpToDtlsSrtp)2206 TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtp) {
2207 Base::SendDtlsSrtpToDtlsSrtp(0, 0);
2208 }
2209
TEST_F(VideoChannelDoubleThreadTest,SendDtlsSrtpToDtlsSrtpRtcpMux)2210 TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2211 Base::SendDtlsSrtpToDtlsSrtp(RTCP_MUX, RTCP_MUX);
2212 }
2213
TEST_F(VideoChannelDoubleThreadTest,SendEarlyMediaUsingRtcpMuxSrtp)2214 TEST_F(VideoChannelDoubleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2215 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2216 }
2217
TEST_F(VideoChannelDoubleThreadTest,SendRtpToRtpOnThread)2218 TEST_F(VideoChannelDoubleThreadTest, SendRtpToRtpOnThread) {
2219 Base::SendRtpToRtpOnThread();
2220 }
2221
TEST_F(VideoChannelDoubleThreadTest,SendWithWritabilityLoss)2222 TEST_F(VideoChannelDoubleThreadTest, SendWithWritabilityLoss) {
2223 Base::SendWithWritabilityLoss();
2224 }
2225
TEST_F(VideoChannelDoubleThreadTest,TestSetContentFailure)2226 TEST_F(VideoChannelDoubleThreadTest, TestSetContentFailure) {
2227 Base::TestSetContentFailure();
2228 }
2229
TEST_F(VideoChannelDoubleThreadTest,TestSendTwoOffers)2230 TEST_F(VideoChannelDoubleThreadTest, TestSendTwoOffers) {
2231 Base::TestSendTwoOffers();
2232 }
2233
TEST_F(VideoChannelDoubleThreadTest,TestReceiveTwoOffers)2234 TEST_F(VideoChannelDoubleThreadTest, TestReceiveTwoOffers) {
2235 Base::TestReceiveTwoOffers();
2236 }
2237
TEST_F(VideoChannelDoubleThreadTest,TestSendPrAnswer)2238 TEST_F(VideoChannelDoubleThreadTest, TestSendPrAnswer) {
2239 Base::TestSendPrAnswer();
2240 }
2241
TEST_F(VideoChannelDoubleThreadTest,TestReceivePrAnswer)2242 TEST_F(VideoChannelDoubleThreadTest, TestReceivePrAnswer) {
2243 Base::TestReceivePrAnswer();
2244 }
2245
TEST_F(VideoChannelDoubleThreadTest,SendBundleToBundle)2246 TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundle) {
2247 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, false);
2248 }
2249
TEST_F(VideoChannelDoubleThreadTest,SendBundleToBundleSecure)2250 TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleSecure) {
2251 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, true);
2252 }
2253
TEST_F(VideoChannelDoubleThreadTest,SendBundleToBundleWithRtcpMux)2254 TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleWithRtcpMux) {
2255 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, false);
2256 }
2257
TEST_F(VideoChannelDoubleThreadTest,SendBundleToBundleWithRtcpMuxSecure)2258 TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
2259 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true);
2260 }
2261
TEST_F(VideoChannelDoubleThreadTest,TestOnTransportReadyToSend)2262 TEST_F(VideoChannelDoubleThreadTest, TestOnTransportReadyToSend) {
2263 Base::TestOnTransportReadyToSend();
2264 }
2265
TEST_F(VideoChannelDoubleThreadTest,DefaultMaxBitrateIsUnlimited)2266 TEST_F(VideoChannelDoubleThreadTest, DefaultMaxBitrateIsUnlimited) {
2267 Base::DefaultMaxBitrateIsUnlimited();
2268 }
2269
TEST_F(VideoChannelDoubleThreadTest,SocketOptionsMergedOnSetTransport)2270 TEST_F(VideoChannelDoubleThreadTest, SocketOptionsMergedOnSetTransport) {
2271 Base::SocketOptionsMergedOnSetTransport();
2272 }
2273
2274 // RtpDataChannelSingleThreadTest
2275 class RtpDataChannelSingleThreadTest : public ChannelTest<DataTraits> {
2276 public:
2277 typedef ChannelTest<DataTraits> Base;
RtpDataChannelSingleThreadTest()2278 RtpDataChannelSingleThreadTest()
2279 : Base(true, kDataPacket, kRtcpReport, NetworkIsWorker::Yes) {}
2280 };
2281
2282 // RtpDataChannelDoubleThreadTest
2283 class RtpDataChannelDoubleThreadTest : public ChannelTest<DataTraits> {
2284 public:
2285 typedef ChannelTest<DataTraits> Base;
RtpDataChannelDoubleThreadTest()2286 RtpDataChannelDoubleThreadTest()
2287 : Base(true, kDataPacket, kRtcpReport, NetworkIsWorker::No) {}
2288 };
2289
2290 // Override to avoid engine channel parameter.
2291 template <>
CreateChannel(rtc::Thread * worker_thread,rtc::Thread * network_thread,std::unique_ptr<cricket::FakeDataMediaChannel> ch,webrtc::RtpTransportInternal * rtp_transport,int flags)2292 std::unique_ptr<cricket::RtpDataChannel> ChannelTest<DataTraits>::CreateChannel(
2293 rtc::Thread* worker_thread,
2294 rtc::Thread* network_thread,
2295 std::unique_ptr<cricket::FakeDataMediaChannel> ch,
2296 webrtc::RtpTransportInternal* rtp_transport,
2297 int flags) {
2298 rtc::Thread* signaling_thread = rtc::Thread::Current();
2299 auto channel = std::make_unique<cricket::RtpDataChannel>(
2300 worker_thread, network_thread, signaling_thread, std::move(ch),
2301 cricket::CN_DATA, (flags & DTLS) != 0, webrtc::CryptoOptions(),
2302 &ssrc_generator_);
2303 channel->Init_w(rtp_transport);
2304 return channel;
2305 }
2306
2307 template <>
CreateContent(int flags,const cricket::AudioCodec & audio_codec,const cricket::VideoCodec & video_codec,cricket::RtpDataContentDescription * data)2308 void ChannelTest<DataTraits>::CreateContent(
2309 int flags,
2310 const cricket::AudioCodec& audio_codec,
2311 const cricket::VideoCodec& video_codec,
2312 cricket::RtpDataContentDescription* data) {
2313 data->AddCodec(kGoogleDataCodec);
2314 data->set_rtcp_mux((flags & RTCP_MUX) != 0);
2315 }
2316
2317 template <>
CopyContent(const cricket::RtpDataContentDescription & source,cricket::RtpDataContentDescription * data)2318 void ChannelTest<DataTraits>::CopyContent(
2319 const cricket::RtpDataContentDescription& source,
2320 cricket::RtpDataContentDescription* data) {
2321 *data = source;
2322 }
2323
2324 template <>
CodecMatches(const cricket::DataCodec & c1,const cricket::DataCodec & c2)2325 bool ChannelTest<DataTraits>::CodecMatches(const cricket::DataCodec& c1,
2326 const cricket::DataCodec& c2) {
2327 return c1.name == c2.name;
2328 }
2329
2330 template <>
AddLegacyStreamInContent(uint32_t ssrc,int flags,cricket::RtpDataContentDescription * data)2331 void ChannelTest<DataTraits>::AddLegacyStreamInContent(
2332 uint32_t ssrc,
2333 int flags,
2334 cricket::RtpDataContentDescription* data) {
2335 data->AddLegacyStream(ssrc);
2336 }
2337
TEST_F(RtpDataChannelSingleThreadTest,TestInit)2338 TEST_F(RtpDataChannelSingleThreadTest, TestInit) {
2339 Base::TestInit();
2340 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2341 }
2342
TEST_F(RtpDataChannelSingleThreadTest,TestDeinit)2343 TEST_F(RtpDataChannelSingleThreadTest, TestDeinit) {
2344 Base::TestDeinit();
2345 }
2346
TEST_F(RtpDataChannelSingleThreadTest,TestSetContents)2347 TEST_F(RtpDataChannelSingleThreadTest, TestSetContents) {
2348 Base::TestSetContents();
2349 }
2350
TEST_F(RtpDataChannelSingleThreadTest,TestSetContentsNullOffer)2351 TEST_F(RtpDataChannelSingleThreadTest, TestSetContentsNullOffer) {
2352 Base::TestSetContentsNullOffer();
2353 }
2354
TEST_F(RtpDataChannelSingleThreadTest,TestSetContentsRtcpMux)2355 TEST_F(RtpDataChannelSingleThreadTest, TestSetContentsRtcpMux) {
2356 Base::TestSetContentsRtcpMux();
2357 }
2358
TEST_F(RtpDataChannelSingleThreadTest,TestChangeStreamParamsInContent)2359 TEST_F(RtpDataChannelSingleThreadTest, TestChangeStreamParamsInContent) {
2360 Base::TestChangeStreamParamsInContent();
2361 }
2362
TEST_F(RtpDataChannelSingleThreadTest,TestPlayoutAndSendingStates)2363 TEST_F(RtpDataChannelSingleThreadTest, TestPlayoutAndSendingStates) {
2364 Base::TestPlayoutAndSendingStates();
2365 }
2366
TEST_F(RtpDataChannelSingleThreadTest,TestMediaContentDirection)2367 TEST_F(RtpDataChannelSingleThreadTest, TestMediaContentDirection) {
2368 Base::TestMediaContentDirection();
2369 }
2370
TEST_F(RtpDataChannelSingleThreadTest,TestCallSetup)2371 TEST_F(RtpDataChannelSingleThreadTest, TestCallSetup) {
2372 Base::TestCallSetup();
2373 }
2374
TEST_F(RtpDataChannelSingleThreadTest,TestCallTeardownRtcpMux)2375 TEST_F(RtpDataChannelSingleThreadTest, TestCallTeardownRtcpMux) {
2376 Base::TestCallTeardownRtcpMux();
2377 }
2378
TEST_F(RtpDataChannelSingleThreadTest,TestOnTransportReadyToSend)2379 TEST_F(RtpDataChannelSingleThreadTest, TestOnTransportReadyToSend) {
2380 Base::TestOnTransportReadyToSend();
2381 }
2382
TEST_F(RtpDataChannelSingleThreadTest,SendRtpToRtp)2383 TEST_F(RtpDataChannelSingleThreadTest, SendRtpToRtp) {
2384 Base::SendRtpToRtp();
2385 }
2386
TEST_F(RtpDataChannelSingleThreadTest,SendRtpToRtpOnThread)2387 TEST_F(RtpDataChannelSingleThreadTest, SendRtpToRtpOnThread) {
2388 Base::SendRtpToRtpOnThread();
2389 }
2390
TEST_F(RtpDataChannelSingleThreadTest,SendWithWritabilityLoss)2391 TEST_F(RtpDataChannelSingleThreadTest, SendWithWritabilityLoss) {
2392 Base::SendWithWritabilityLoss();
2393 }
2394
TEST_F(RtpDataChannelSingleThreadTest,SocketOptionsMergedOnSetTransport)2395 TEST_F(RtpDataChannelSingleThreadTest, SocketOptionsMergedOnSetTransport) {
2396 Base::SocketOptionsMergedOnSetTransport();
2397 }
2398
TEST_F(RtpDataChannelSingleThreadTest,TestSendData)2399 TEST_F(RtpDataChannelSingleThreadTest, TestSendData) {
2400 CreateChannels(0, 0);
2401 EXPECT_TRUE(SendInitiate());
2402 EXPECT_TRUE(SendAccept());
2403
2404 cricket::SendDataParams params;
2405 params.ssrc = 42;
2406 unsigned char data[] = {'f', 'o', 'o'};
2407 rtc::CopyOnWriteBuffer payload(data, 3);
2408 cricket::SendDataResult result;
2409 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
2410 EXPECT_EQ(params.ssrc, media_channel1_->last_sent_data_params().ssrc);
2411 EXPECT_EQ("foo", media_channel1_->last_sent_data());
2412 }
2413
TEST_F(RtpDataChannelDoubleThreadTest,TestInit)2414 TEST_F(RtpDataChannelDoubleThreadTest, TestInit) {
2415 Base::TestInit();
2416 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2417 }
2418
TEST_F(RtpDataChannelDoubleThreadTest,TestDeinit)2419 TEST_F(RtpDataChannelDoubleThreadTest, TestDeinit) {
2420 Base::TestDeinit();
2421 }
2422
TEST_F(RtpDataChannelDoubleThreadTest,TestSetContents)2423 TEST_F(RtpDataChannelDoubleThreadTest, TestSetContents) {
2424 Base::TestSetContents();
2425 }
2426
TEST_F(RtpDataChannelDoubleThreadTest,TestSetContentsNullOffer)2427 TEST_F(RtpDataChannelDoubleThreadTest, TestSetContentsNullOffer) {
2428 Base::TestSetContentsNullOffer();
2429 }
2430
TEST_F(RtpDataChannelDoubleThreadTest,TestSetContentsRtcpMux)2431 TEST_F(RtpDataChannelDoubleThreadTest, TestSetContentsRtcpMux) {
2432 Base::TestSetContentsRtcpMux();
2433 }
2434
TEST_F(RtpDataChannelDoubleThreadTest,TestChangeStreamParamsInContent)2435 TEST_F(RtpDataChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
2436 Base::TestChangeStreamParamsInContent();
2437 }
2438
TEST_F(RtpDataChannelDoubleThreadTest,TestPlayoutAndSendingStates)2439 TEST_F(RtpDataChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
2440 Base::TestPlayoutAndSendingStates();
2441 }
2442
TEST_F(RtpDataChannelDoubleThreadTest,TestMediaContentDirection)2443 TEST_F(RtpDataChannelDoubleThreadTest, TestMediaContentDirection) {
2444 Base::TestMediaContentDirection();
2445 }
2446
TEST_F(RtpDataChannelDoubleThreadTest,TestCallSetup)2447 TEST_F(RtpDataChannelDoubleThreadTest, TestCallSetup) {
2448 Base::TestCallSetup();
2449 }
2450
TEST_F(RtpDataChannelDoubleThreadTest,TestCallTeardownRtcpMux)2451 TEST_F(RtpDataChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
2452 Base::TestCallTeardownRtcpMux();
2453 }
2454
TEST_F(RtpDataChannelDoubleThreadTest,TestOnTransportReadyToSend)2455 TEST_F(RtpDataChannelDoubleThreadTest, TestOnTransportReadyToSend) {
2456 Base::TestOnTransportReadyToSend();
2457 }
2458
TEST_F(RtpDataChannelDoubleThreadTest,SendRtpToRtp)2459 TEST_F(RtpDataChannelDoubleThreadTest, SendRtpToRtp) {
2460 Base::SendRtpToRtp();
2461 }
2462
TEST_F(RtpDataChannelDoubleThreadTest,SendRtpToRtpOnThread)2463 TEST_F(RtpDataChannelDoubleThreadTest, SendRtpToRtpOnThread) {
2464 Base::SendRtpToRtpOnThread();
2465 }
2466
TEST_F(RtpDataChannelDoubleThreadTest,SendWithWritabilityLoss)2467 TEST_F(RtpDataChannelDoubleThreadTest, SendWithWritabilityLoss) {
2468 Base::SendWithWritabilityLoss();
2469 }
2470
TEST_F(RtpDataChannelDoubleThreadTest,SocketOptionsMergedOnSetTransport)2471 TEST_F(RtpDataChannelDoubleThreadTest, SocketOptionsMergedOnSetTransport) {
2472 Base::SocketOptionsMergedOnSetTransport();
2473 }
2474
TEST_F(RtpDataChannelDoubleThreadTest,TestSendData)2475 TEST_F(RtpDataChannelDoubleThreadTest, TestSendData) {
2476 CreateChannels(0, 0);
2477 EXPECT_TRUE(SendInitiate());
2478 EXPECT_TRUE(SendAccept());
2479
2480 cricket::SendDataParams params;
2481 params.ssrc = 42;
2482 unsigned char data[] = {'f', 'o', 'o'};
2483 rtc::CopyOnWriteBuffer payload(data, 3);
2484 cricket::SendDataResult result;
2485 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
2486 EXPECT_EQ(params.ssrc, media_channel1_->last_sent_data_params().ssrc);
2487 EXPECT_EQ("foo", media_channel1_->last_sent_data());
2488 }
2489
2490 // TODO(pthatcher): TestSetReceiver?
2491