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