henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | // libjingle |
| 2 | // Copyright 2009 Google Inc. |
| 3 | // |
| 4 | // Redistribution and use in source and binary forms, with or without |
| 5 | // modification, are permitted provided that the following conditions are met: |
| 6 | // |
| 7 | // 1. Redistributions of source code must retain the above copyright notice, |
| 8 | // this list of conditions and the following disclaimer. |
| 9 | // 2. Redistributions in binary form must reproduce the above copyright notice, |
| 10 | // this list of conditions and the following disclaimer in the documentation |
| 11 | // and/or other materials provided with the distribution. |
| 12 | // 3. The name of the author may not be used to endorse or promote products |
| 13 | // derived from this software without specific prior written permission. |
| 14 | // |
| 15 | // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 16 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 17 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 18 | // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 19 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 20 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 21 | // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 22 | // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 23 | // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 24 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | |
| 26 | #include "talk/base/fileutils.h" |
| 27 | #include "talk/base/gunit.h" |
| 28 | #include "talk/base/helpers.h" |
| 29 | #include "talk/base/logging.h" |
| 30 | #include "talk/base/pathutils.h" |
| 31 | #include "talk/base/signalthread.h" |
| 32 | #include "talk/base/ssladapter.h" |
| 33 | #include "talk/base/sslidentity.h" |
| 34 | #include "talk/base/window.h" |
| 35 | #include "talk/media/base/fakemediaengine.h" |
| 36 | #include "talk/media/base/fakertp.h" |
| 37 | #include "talk/media/base/fakevideocapturer.h" |
| 38 | #include "talk/media/base/mediachannel.h" |
| 39 | #include "talk/media/base/rtpdump.h" |
| 40 | #include "talk/media/base/screencastid.h" |
| 41 | #include "talk/media/base/testutils.h" |
| 42 | #include "talk/p2p/base/fakesession.h" |
| 43 | #include "talk/session/media/channel.h" |
| 44 | #include "talk/session/media/mediamessages.h" |
| 45 | #include "talk/session/media/mediarecorder.h" |
| 46 | #include "talk/session/media/mediasessionclient.h" |
| 47 | #include "talk/session/media/typingmonitor.h" |
| 48 | |
| 49 | #define MAYBE_SKIP_TEST(feature) \ |
| 50 | if (!(talk_base::SSLStreamAdapter::feature())) { \ |
| 51 | LOG(LS_INFO) << "Feature disabled... skipping"; \ |
| 52 | return; \ |
| 53 | } |
| 54 | |
| 55 | using cricket::CA_OFFER; |
| 56 | using cricket::CA_PRANSWER; |
| 57 | using cricket::CA_ANSWER; |
| 58 | using cricket::CA_UPDATE; |
| 59 | using cricket::FakeVoiceMediaChannel; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 60 | using cricket::ScreencastId; |
| 61 | using cricket::StreamParams; |
| 62 | using cricket::TransportChannel; |
| 63 | using talk_base::WindowId; |
| 64 | |
| 65 | static const cricket::AudioCodec kPcmuCodec(0, "PCMU", 64000, 8000, 1, 0); |
| 66 | static const cricket::AudioCodec kPcmaCodec(8, "PCMA", 64000, 8000, 1, 0); |
| 67 | static const cricket::AudioCodec kIsacCodec(103, "ISAC", 40000, 16000, 1, 0); |
| 68 | static const cricket::VideoCodec kH264Codec(97, "H264", 640, 400, 30, 0); |
| 69 | static const cricket::VideoCodec kH264SvcCodec(99, "H264-SVC", 320, 200, 15, 0); |
| 70 | static const cricket::DataCodec kGoogleDataCodec(101, "google-data", 0); |
| 71 | static const uint32 kSsrc1 = 0x1111; |
| 72 | static const uint32 kSsrc2 = 0x2222; |
| 73 | static const uint32 kSsrc3 = 0x3333; |
| 74 | static const char kCName[] = "a@b.com"; |
| 75 | |
| 76 | template<class ChannelT, |
| 77 | class MediaChannelT, |
| 78 | class ContentT, |
| 79 | class CodecT, |
| 80 | class MediaInfoT> |
| 81 | class Traits { |
| 82 | public: |
| 83 | typedef ChannelT Channel; |
| 84 | typedef MediaChannelT MediaChannel; |
| 85 | typedef ContentT Content; |
| 86 | typedef CodecT Codec; |
| 87 | typedef MediaInfoT MediaInfo; |
| 88 | }; |
| 89 | |
| 90 | class FakeScreenCaptureFactory |
| 91 | : public cricket::VideoChannel::ScreenCapturerFactory, |
| 92 | public sigslot::has_slots<> { |
| 93 | public: |
| 94 | FakeScreenCaptureFactory() |
| 95 | : window_capturer_(NULL), |
| 96 | capture_state_(cricket::CS_STOPPED) {} |
| 97 | |
| 98 | virtual cricket::VideoCapturer* CreateScreenCapturer( |
| 99 | const ScreencastId& window) { |
| 100 | if (window_capturer_ != NULL) { |
| 101 | // Class is only designed to handle one fake screencapturer. |
| 102 | ADD_FAILURE(); |
| 103 | return NULL; |
| 104 | } |
| 105 | window_capturer_ = new cricket::FakeVideoCapturer; |
| 106 | window_capturer_->SignalDestroyed.connect( |
| 107 | this, |
| 108 | &FakeScreenCaptureFactory::OnWindowCapturerDestroyed); |
| 109 | window_capturer_->SignalStateChange.connect( |
| 110 | this, |
| 111 | &FakeScreenCaptureFactory::OnStateChange); |
| 112 | return window_capturer_; |
| 113 | } |
| 114 | |
| 115 | cricket::FakeVideoCapturer* window_capturer() { return window_capturer_; } |
| 116 | |
| 117 | cricket::CaptureState capture_state() { return capture_state_; } |
| 118 | |
| 119 | private: |
| 120 | void OnWindowCapturerDestroyed(cricket::FakeVideoCapturer* capturer) { |
| 121 | if (capturer == window_capturer_) { |
| 122 | window_capturer_ = NULL; |
| 123 | } |
| 124 | } |
| 125 | void OnStateChange(cricket::VideoCapturer*, cricket::CaptureState state) { |
| 126 | capture_state_ = state; |
| 127 | } |
| 128 | |
| 129 | cricket::FakeVideoCapturer* window_capturer_; |
| 130 | cricket::CaptureState capture_state_; |
| 131 | }; |
| 132 | |
| 133 | // Controls how long we wait for a session to send messages that we |
| 134 | // expect, in milliseconds. We put it high to avoid flaky tests. |
| 135 | static const int kEventTimeout = 5000; |
| 136 | |
| 137 | class VoiceTraits : public Traits<cricket::VoiceChannel, |
| 138 | cricket::FakeVoiceMediaChannel, |
| 139 | cricket::AudioContentDescription, |
| 140 | cricket::AudioCodec, |
| 141 | cricket::VoiceMediaInfo> { |
| 142 | }; |
| 143 | |
| 144 | class VideoTraits : public Traits<cricket::VideoChannel, |
| 145 | cricket::FakeVideoMediaChannel, |
| 146 | cricket::VideoContentDescription, |
| 147 | cricket::VideoCodec, |
| 148 | cricket::VideoMediaInfo> { |
| 149 | }; |
| 150 | |
| 151 | class DataTraits : public Traits<cricket::DataChannel, |
| 152 | cricket::FakeDataMediaChannel, |
| 153 | cricket::DataContentDescription, |
| 154 | cricket::DataCodec, |
| 155 | cricket::DataMediaInfo> { |
| 156 | }; |
| 157 | |
| 158 | |
| 159 | talk_base::StreamInterface* Open(const std::string& path) { |
| 160 | return talk_base::Filesystem::OpenFile( |
| 161 | talk_base::Pathname(path), "wb"); |
| 162 | } |
| 163 | |
| 164 | // Base class for Voice/VideoChannel tests |
| 165 | template<class T> |
| 166 | class ChannelTest : public testing::Test, public sigslot::has_slots<> { |
| 167 | public: |
| 168 | enum Flags { RTCP = 0x1, RTCP_MUX = 0x2, SECURE = 0x4, SSRC_MUX = 0x8, |
| 169 | DTLS = 0x10 }; |
| 170 | |
| 171 | ChannelTest(const uint8* rtp_data, int rtp_len, |
| 172 | const uint8* rtcp_data, int rtcp_len) |
| 173 | : session1_(true), |
| 174 | session2_(false), |
| 175 | media_channel1_(NULL), |
| 176 | media_channel2_(NULL), |
| 177 | rtp_packet_(reinterpret_cast<const char*>(rtp_data), rtp_len), |
| 178 | rtcp_packet_(reinterpret_cast<const char*>(rtcp_data), rtcp_len), |
| 179 | media_info_callbacks1_(), |
| 180 | media_info_callbacks2_(), |
| 181 | mute_callback_recved_(false), |
| 182 | mute_callback_value_(false), |
| 183 | ssrc_(0), |
| 184 | error_(T::MediaChannel::ERROR_NONE) { |
| 185 | } |
| 186 | |
| 187 | static void SetUpTestCase() { |
| 188 | talk_base::InitializeSSL(); |
| 189 | } |
| 190 | |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 191 | static void TearDownTestCase() { |
| 192 | talk_base::CleanupSSL(); |
| 193 | } |
| 194 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 195 | void CreateChannels(int flags1, int flags2) { |
| 196 | CreateChannels(new typename T::MediaChannel(NULL), |
| 197 | new typename T::MediaChannel(NULL), |
| 198 | flags1, flags2, talk_base::Thread::Current()); |
| 199 | } |
| 200 | void CreateChannels(int flags) { |
| 201 | CreateChannels(new typename T::MediaChannel(NULL), |
| 202 | new typename T::MediaChannel(NULL), |
| 203 | flags, talk_base::Thread::Current()); |
| 204 | } |
| 205 | void CreateChannels(int flags1, int flags2, |
| 206 | talk_base::Thread* thread) { |
| 207 | CreateChannels(new typename T::MediaChannel(NULL), |
| 208 | new typename T::MediaChannel(NULL), |
| 209 | flags1, flags2, thread); |
| 210 | } |
| 211 | void CreateChannels(int flags, |
| 212 | talk_base::Thread* thread) { |
| 213 | CreateChannels(new typename T::MediaChannel(NULL), |
| 214 | new typename T::MediaChannel(NULL), |
| 215 | flags, thread); |
| 216 | } |
| 217 | void CreateChannels( |
| 218 | typename T::MediaChannel* ch1, typename T::MediaChannel* ch2, |
| 219 | int flags1, int flags2, talk_base::Thread* thread) { |
| 220 | media_channel1_ = ch1; |
| 221 | media_channel2_ = ch2; |
| 222 | channel1_.reset(CreateChannel(thread, &media_engine_, ch1, &session1_, |
| 223 | (flags1 & RTCP) != 0)); |
| 224 | channel2_.reset(CreateChannel(thread, &media_engine_, ch2, &session2_, |
| 225 | (flags2 & RTCP) != 0)); |
| 226 | channel1_->SignalMediaMonitor.connect( |
| 227 | this, &ChannelTest<T>::OnMediaMonitor); |
| 228 | channel2_->SignalMediaMonitor.connect( |
| 229 | this, &ChannelTest<T>::OnMediaMonitor); |
| 230 | channel1_->SignalMediaError.connect( |
| 231 | this, &ChannelTest<T>::OnMediaChannelError); |
| 232 | channel2_->SignalMediaError.connect( |
| 233 | this, &ChannelTest<T>::OnMediaChannelError); |
| 234 | channel1_->SignalAutoMuted.connect( |
| 235 | this, &ChannelTest<T>::OnMediaMuted); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 236 | if ((flags1 & DTLS) && (flags2 & DTLS)) { |
| 237 | flags1 = (flags1 & ~SECURE); |
| 238 | flags2 = (flags2 & ~SECURE); |
| 239 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 240 | CreateContent(flags1, kPcmuCodec, kH264Codec, |
| 241 | &local_media_content1_); |
| 242 | CreateContent(flags2, kPcmuCodec, kH264Codec, |
| 243 | &local_media_content2_); |
| 244 | CopyContent(local_media_content1_, &remote_media_content1_); |
| 245 | CopyContent(local_media_content2_, &remote_media_content2_); |
| 246 | |
| 247 | if (flags1 & DTLS) { |
| 248 | identity1_.reset(talk_base::SSLIdentity::Generate("session1")); |
| 249 | session1_.set_ssl_identity(identity1_.get()); |
| 250 | } |
| 251 | if (flags2 & DTLS) { |
| 252 | identity2_.reset(talk_base::SSLIdentity::Generate("session2")); |
| 253 | session2_.set_ssl_identity(identity2_.get()); |
| 254 | } |
| 255 | |
| 256 | // Add stream information (SSRC) to the local content but not to the remote |
| 257 | // content. This means that we per default know the SSRC of what we send but |
| 258 | // not what we receive. |
| 259 | AddLegacyStreamInContent(kSsrc1, flags1, &local_media_content1_); |
| 260 | AddLegacyStreamInContent(kSsrc2, flags2, &local_media_content2_); |
| 261 | |
| 262 | // If SSRC_MUX is used we also need to know the SSRC of the incoming stream. |
| 263 | if (flags1 & SSRC_MUX) { |
| 264 | AddLegacyStreamInContent(kSsrc1, flags1, &remote_media_content1_); |
| 265 | } |
| 266 | if (flags2 & SSRC_MUX) { |
| 267 | AddLegacyStreamInContent(kSsrc2, flags2, &remote_media_content2_); |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | void CreateChannels( |
| 272 | typename T::MediaChannel* ch1, typename T::MediaChannel* ch2, |
| 273 | int flags, talk_base::Thread* thread) { |
| 274 | media_channel1_ = ch1; |
| 275 | media_channel2_ = ch2; |
| 276 | |
| 277 | channel1_.reset(CreateChannel(thread, &media_engine_, ch1, &session1_, |
| 278 | (flags & RTCP) != 0)); |
| 279 | channel2_.reset(CreateChannel(thread, &media_engine_, ch2, &session1_, |
| 280 | (flags & RTCP) != 0)); |
| 281 | channel1_->SignalMediaMonitor.connect( |
| 282 | this, &ChannelTest<T>::OnMediaMonitor); |
| 283 | channel2_->SignalMediaMonitor.connect( |
| 284 | this, &ChannelTest<T>::OnMediaMonitor); |
| 285 | channel2_->SignalMediaError.connect( |
| 286 | this, &ChannelTest<T>::OnMediaChannelError); |
| 287 | CreateContent(flags, kPcmuCodec, kH264Codec, |
| 288 | &local_media_content1_); |
| 289 | CreateContent(flags, kPcmuCodec, kH264Codec, |
| 290 | &local_media_content2_); |
| 291 | CopyContent(local_media_content1_, &remote_media_content1_); |
| 292 | CopyContent(local_media_content2_, &remote_media_content2_); |
| 293 | // Add stream information (SSRC) to the local content but not to the remote |
| 294 | // content. This means that we per default know the SSRC of what we send but |
| 295 | // not what we receive. |
| 296 | AddLegacyStreamInContent(kSsrc1, flags, &local_media_content1_); |
| 297 | AddLegacyStreamInContent(kSsrc2, flags, &local_media_content2_); |
| 298 | |
| 299 | // If SSRC_MUX is used we also need to know the SSRC of the incoming stream. |
| 300 | if (flags & SSRC_MUX) { |
| 301 | AddLegacyStreamInContent(kSsrc1, flags, &remote_media_content1_); |
| 302 | AddLegacyStreamInContent(kSsrc2, flags, &remote_media_content2_); |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | typename T::Channel* CreateChannel(talk_base::Thread* thread, |
| 307 | cricket::MediaEngineInterface* engine, |
| 308 | typename T::MediaChannel* ch, |
| 309 | cricket::BaseSession* session, |
| 310 | bool rtcp) { |
| 311 | typename T::Channel* channel = new typename T::Channel( |
| 312 | thread, engine, ch, session, cricket::CN_AUDIO, rtcp); |
| 313 | if (!channel->Init()) { |
| 314 | delete channel; |
| 315 | channel = NULL; |
| 316 | } |
| 317 | return channel; |
| 318 | } |
| 319 | |
| 320 | bool SendInitiate() { |
| 321 | bool result = channel1_->SetLocalContent(&local_media_content1_, CA_OFFER); |
| 322 | if (result) { |
| 323 | channel1_->Enable(true); |
| 324 | result = channel2_->SetRemoteContent(&remote_media_content1_, CA_OFFER); |
| 325 | if (result) { |
| 326 | session1_.Connect(&session2_); |
| 327 | |
| 328 | result = channel2_->SetLocalContent(&local_media_content2_, CA_ANSWER); |
| 329 | } |
| 330 | } |
| 331 | return result; |
| 332 | } |
| 333 | |
| 334 | bool SendAccept() { |
| 335 | channel2_->Enable(true); |
| 336 | return channel1_->SetRemoteContent(&remote_media_content2_, CA_ANSWER); |
| 337 | } |
| 338 | |
| 339 | bool SendOffer() { |
| 340 | bool result = channel1_->SetLocalContent(&local_media_content1_, CA_OFFER); |
| 341 | if (result) { |
| 342 | channel1_->Enable(true); |
| 343 | result = channel2_->SetRemoteContent(&remote_media_content1_, CA_OFFER); |
| 344 | } |
| 345 | return result; |
| 346 | } |
| 347 | |
| 348 | bool SendProvisionalAnswer() { |
| 349 | bool result = channel2_->SetLocalContent(&local_media_content2_, |
| 350 | CA_PRANSWER); |
| 351 | if (result) { |
| 352 | channel2_->Enable(true); |
| 353 | result = channel1_->SetRemoteContent(&remote_media_content2_, |
| 354 | CA_PRANSWER); |
| 355 | session1_.Connect(&session2_); |
| 356 | } |
| 357 | return result; |
| 358 | } |
| 359 | |
| 360 | bool SendFinalAnswer() { |
| 361 | bool result = channel2_->SetLocalContent(&local_media_content2_, CA_ANSWER); |
| 362 | if (result) |
| 363 | result = channel1_->SetRemoteContent(&remote_media_content2_, CA_ANSWER); |
| 364 | return result; |
| 365 | } |
| 366 | |
| 367 | bool SendTerminate() { |
| 368 | channel1_.reset(); |
| 369 | channel2_.reset(); |
| 370 | return true; |
| 371 | } |
| 372 | |
| 373 | bool AddStream1(int id) { |
| 374 | return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id)); |
| 375 | } |
| 376 | bool RemoveStream1(int id) { |
| 377 | return channel1_->RemoveRecvStream(id); |
| 378 | } |
| 379 | |
| 380 | cricket::FakeTransport* GetTransport1() { |
| 381 | return session1_.GetTransport(channel1_->content_name()); |
| 382 | } |
| 383 | cricket::FakeTransport* GetTransport2() { |
| 384 | return session2_.GetTransport(channel2_->content_name()); |
| 385 | } |
| 386 | |
| 387 | bool SendRtp1() { |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 388 | return media_channel1_->SendRtp(rtp_packet_.c_str(), |
| 389 | static_cast<int>(rtp_packet_.size())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 390 | } |
| 391 | bool SendRtp2() { |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 392 | return media_channel2_->SendRtp(rtp_packet_.c_str(), |
| 393 | static_cast<int>(rtp_packet_.size())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 394 | } |
| 395 | bool SendRtcp1() { |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 396 | return media_channel1_->SendRtcp(rtcp_packet_.c_str(), |
| 397 | static_cast<int>(rtcp_packet_.size())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 398 | } |
| 399 | bool SendRtcp2() { |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 400 | return media_channel2_->SendRtcp(rtcp_packet_.c_str(), |
| 401 | static_cast<int>(rtcp_packet_.size())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 402 | } |
| 403 | // Methods to send custom data. |
| 404 | bool SendCustomRtp1(uint32 ssrc, int sequence_number) { |
| 405 | std::string data(CreateRtpData(ssrc, sequence_number)); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 406 | return media_channel1_->SendRtp(data.c_str(), |
| 407 | static_cast<int>(data.size())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 408 | } |
| 409 | bool SendCustomRtp2(uint32 ssrc, int sequence_number) { |
| 410 | std::string data(CreateRtpData(ssrc, sequence_number)); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 411 | return media_channel2_->SendRtp(data.c_str(), |
| 412 | static_cast<int>(data.size())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 413 | } |
| 414 | bool SendCustomRtcp1(uint32 ssrc) { |
| 415 | std::string data(CreateRtcpData(ssrc)); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 416 | return media_channel1_->SendRtcp(data.c_str(), |
| 417 | static_cast<int>(data.size())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 418 | } |
| 419 | bool SendCustomRtcp2(uint32 ssrc) { |
| 420 | std::string data(CreateRtcpData(ssrc)); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 421 | return media_channel2_->SendRtcp(data.c_str(), |
| 422 | static_cast<int>(data.size())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 423 | } |
| 424 | bool CheckRtp1() { |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 425 | return media_channel1_->CheckRtp(rtp_packet_.c_str(), |
| 426 | static_cast<int>(rtp_packet_.size())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 427 | } |
| 428 | bool CheckRtp2() { |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 429 | return media_channel2_->CheckRtp(rtp_packet_.c_str(), |
| 430 | static_cast<int>(rtp_packet_.size())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 431 | } |
| 432 | bool CheckRtcp1() { |
| 433 | return media_channel1_->CheckRtcp(rtcp_packet_.c_str(), |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 434 | static_cast<int>(rtcp_packet_.size())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 435 | } |
| 436 | bool CheckRtcp2() { |
| 437 | return media_channel2_->CheckRtcp(rtcp_packet_.c_str(), |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 438 | static_cast<int>(rtcp_packet_.size())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 439 | } |
| 440 | // Methods to check custom data. |
| 441 | bool CheckCustomRtp1(uint32 ssrc, int sequence_number) { |
| 442 | std::string data(CreateRtpData(ssrc, sequence_number)); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 443 | return media_channel1_->CheckRtp(data.c_str(), |
| 444 | static_cast<int>(data.size())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 445 | } |
| 446 | bool CheckCustomRtp2(uint32 ssrc, int sequence_number) { |
| 447 | std::string data(CreateRtpData(ssrc, sequence_number)); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 448 | return media_channel2_->CheckRtp(data.c_str(), |
| 449 | static_cast<int>(data.size())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 450 | } |
| 451 | bool CheckCustomRtcp1(uint32 ssrc) { |
| 452 | std::string data(CreateRtcpData(ssrc)); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 453 | return media_channel1_->CheckRtcp(data.c_str(), |
| 454 | static_cast<int>(data.size())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 455 | } |
| 456 | bool CheckCustomRtcp2(uint32 ssrc) { |
| 457 | std::string data(CreateRtcpData(ssrc)); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 458 | return media_channel2_->CheckRtcp(data.c_str(), |
| 459 | static_cast<int>(data.size())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 460 | } |
| 461 | std::string CreateRtpData(uint32 ssrc, int sequence_number) { |
| 462 | std::string data(rtp_packet_); |
| 463 | // Set SSRC in the rtp packet copy. |
| 464 | talk_base::SetBE32(const_cast<char*>(data.c_str()) + 8, ssrc); |
| 465 | talk_base::SetBE16(const_cast<char*>(data.c_str()) + 2, sequence_number); |
| 466 | return data; |
| 467 | } |
| 468 | std::string CreateRtcpData(uint32 ssrc) { |
| 469 | std::string data(rtcp_packet_); |
| 470 | // Set SSRC in the rtcp packet copy. |
| 471 | talk_base::SetBE32(const_cast<char*>(data.c_str()) + 4, ssrc); |
| 472 | return data; |
| 473 | } |
| 474 | |
| 475 | bool CheckNoRtp1() { |
| 476 | return media_channel1_->CheckNoRtp(); |
| 477 | } |
| 478 | bool CheckNoRtp2() { |
| 479 | return media_channel2_->CheckNoRtp(); |
| 480 | } |
| 481 | bool CheckNoRtcp1() { |
| 482 | return media_channel1_->CheckNoRtcp(); |
| 483 | } |
| 484 | bool CheckNoRtcp2() { |
| 485 | return media_channel2_->CheckNoRtcp(); |
| 486 | } |
| 487 | |
| 488 | void CreateContent(int flags, |
| 489 | const cricket::AudioCodec& audio_codec, |
| 490 | const cricket::VideoCodec& video_codec, |
| 491 | typename T::Content* content) { |
| 492 | // overridden in specialized classes |
| 493 | } |
| 494 | void CopyContent(const typename T::Content& source, |
| 495 | typename T::Content* content) { |
| 496 | // overridden in specialized classes |
| 497 | } |
| 498 | |
| 499 | void SetOptimisticDataSend(bool optimistic_data_send) { |
| 500 | channel1_->set_optimistic_data_send(optimistic_data_send); |
| 501 | channel2_->set_optimistic_data_send(optimistic_data_send); |
| 502 | } |
| 503 | |
| 504 | // Creates a cricket::SessionDescription with one MediaContent and one stream. |
| 505 | // kPcmuCodec is used as audio codec and kH264Codec is used as video codec. |
| 506 | cricket::SessionDescription* CreateSessionDescriptionWithStream(uint32 ssrc) { |
| 507 | typename T::Content content; |
| 508 | cricket::SessionDescription* sdesc = new cricket::SessionDescription(); |
| 509 | CreateContent(SECURE, kPcmuCodec, kH264Codec, &content); |
| 510 | AddLegacyStreamInContent(ssrc, 0, &content); |
| 511 | sdesc->AddContent("DUMMY_CONTENT_NAME", |
| 512 | cricket::NS_JINGLE_RTP, content.Copy()); |
| 513 | return sdesc; |
| 514 | } |
| 515 | |
| 516 | class CallThread : public talk_base::SignalThread { |
| 517 | public: |
| 518 | typedef bool (ChannelTest<T>::*Method)(); |
| 519 | CallThread(ChannelTest<T>* obj, Method method, bool* result) |
| 520 | : obj_(obj), |
| 521 | method_(method), |
| 522 | result_(result) { |
| 523 | *result = false; |
| 524 | } |
| 525 | virtual void DoWork() { |
| 526 | bool result = (*obj_.*method_)(); |
| 527 | if (result_) { |
| 528 | *result_ = result; |
| 529 | } |
| 530 | } |
| 531 | private: |
| 532 | ChannelTest<T>* obj_; |
| 533 | Method method_; |
| 534 | bool* result_; |
| 535 | }; |
| 536 | void CallOnThread(typename CallThread::Method method, bool* result) { |
| 537 | CallThread* thread = new CallThread(this, method, result); |
| 538 | thread->Start(); |
| 539 | thread->Release(); |
| 540 | } |
| 541 | |
| 542 | void CallOnThreadAndWaitForDone(typename CallThread::Method method, |
| 543 | bool* result) { |
| 544 | CallThread* thread = new CallThread(this, method, result); |
| 545 | thread->Start(); |
| 546 | thread->Destroy(true); |
| 547 | } |
| 548 | |
| 549 | bool CodecMatches(const typename T::Codec& c1, const typename T::Codec& c2) { |
| 550 | return false; // overridden in specialized classes |
| 551 | } |
| 552 | |
| 553 | void OnMediaMonitor(typename T::Channel* channel, |
| 554 | const typename T::MediaInfo& info) { |
| 555 | if (channel == channel1_.get()) { |
| 556 | media_info_callbacks1_++; |
| 557 | } else if (channel == channel2_.get()) { |
| 558 | media_info_callbacks2_++; |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | void OnMediaChannelError(typename T::Channel* channel, |
| 563 | uint32 ssrc, |
| 564 | typename T::MediaChannel::Error error) { |
| 565 | ssrc_ = ssrc; |
| 566 | error_ = error; |
| 567 | } |
| 568 | |
| 569 | void OnMediaMuted(cricket::BaseChannel* channel, bool muted) { |
| 570 | mute_callback_recved_ = true; |
| 571 | mute_callback_value_ = muted; |
| 572 | } |
| 573 | |
| 574 | void AddLegacyStreamInContent(uint32 ssrc, int flags, |
| 575 | typename T::Content* content) { |
| 576 | // Base implementation. |
| 577 | } |
| 578 | |
| 579 | // Tests that can be used by derived classes. |
| 580 | |
| 581 | // Basic sanity check. |
| 582 | void TestInit() { |
| 583 | CreateChannels(0, 0); |
| 584 | EXPECT_FALSE(channel1_->secure()); |
| 585 | EXPECT_FALSE(media_channel1_->sending()); |
| 586 | EXPECT_FALSE(media_channel1_->playout()); |
| 587 | EXPECT_TRUE(media_channel1_->codecs().empty()); |
| 588 | EXPECT_TRUE(media_channel1_->recv_streams().empty()); |
| 589 | EXPECT_TRUE(media_channel1_->rtp_packets().empty()); |
| 590 | EXPECT_TRUE(media_channel1_->rtcp_packets().empty()); |
| 591 | } |
| 592 | |
| 593 | // Test that SetLocalContent and SetRemoteContent properly configure |
| 594 | // the codecs. |
| 595 | void TestSetContents() { |
| 596 | CreateChannels(0, 0); |
| 597 | typename T::Content content; |
| 598 | CreateContent(0, kPcmuCodec, kH264Codec, &content); |
| 599 | EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER)); |
| 600 | EXPECT_EQ(0U, media_channel1_->codecs().size()); |
| 601 | EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER)); |
| 602 | ASSERT_EQ(1U, media_channel1_->codecs().size()); |
| 603 | EXPECT_TRUE(CodecMatches(content.codecs()[0], |
| 604 | media_channel1_->codecs()[0])); |
| 605 | } |
| 606 | |
| 607 | // Test that SetLocalContent and SetRemoteContent properly deals |
| 608 | // with an empty offer. |
| 609 | void TestSetContentsNullOffer() { |
| 610 | CreateChannels(0, 0); |
| 611 | typename T::Content content; |
| 612 | EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER)); |
| 613 | CreateContent(0, kPcmuCodec, kH264Codec, &content); |
| 614 | EXPECT_EQ(0U, media_channel1_->codecs().size()); |
| 615 | EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER)); |
| 616 | ASSERT_EQ(1U, media_channel1_->codecs().size()); |
| 617 | EXPECT_TRUE(CodecMatches(content.codecs()[0], |
| 618 | media_channel1_->codecs()[0])); |
| 619 | } |
| 620 | |
| 621 | // Test that SetLocalContent and SetRemoteContent properly set RTCP |
| 622 | // mux. |
| 623 | void TestSetContentsRtcpMux() { |
| 624 | CreateChannels(RTCP, RTCP); |
| 625 | EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL); |
| 626 | EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL); |
| 627 | typename T::Content content; |
| 628 | CreateContent(0, kPcmuCodec, kH264Codec, &content); |
| 629 | // Both sides agree on mux. Should no longer be a separate RTCP channel. |
| 630 | content.set_rtcp_mux(true); |
| 631 | EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER)); |
| 632 | EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER)); |
| 633 | EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL); |
| 634 | // Only initiator supports mux. Should still have a separate RTCP channel. |
| 635 | EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER)); |
| 636 | content.set_rtcp_mux(false); |
| 637 | EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER)); |
| 638 | EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL); |
| 639 | } |
| 640 | |
| 641 | // Test that SetLocalContent and SetRemoteContent properly set RTCP |
| 642 | // mux when a provisional answer is received. |
| 643 | void TestSetContentsRtcpMuxWithPrAnswer() { |
| 644 | CreateChannels(RTCP, RTCP); |
| 645 | EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL); |
| 646 | EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL); |
| 647 | typename T::Content content; |
| 648 | CreateContent(0, kPcmuCodec, kH264Codec, &content); |
| 649 | content.set_rtcp_mux(true); |
| 650 | EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER)); |
| 651 | EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_PRANSWER)); |
| 652 | EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL); |
| 653 | EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER)); |
| 654 | // Both sides agree on mux. Should no longer be a separate RTCP channel. |
| 655 | EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL); |
| 656 | // Only initiator supports mux. Should still have a separate RTCP channel. |
| 657 | EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER)); |
| 658 | content.set_rtcp_mux(false); |
| 659 | EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_PRANSWER)); |
| 660 | EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER)); |
| 661 | EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL); |
| 662 | } |
| 663 | |
| 664 | // Test that SetLocalContent and SetRemoteContent properly set |
| 665 | // video options to the media channel. |
| 666 | void TestSetContentsVideoOptions() { |
| 667 | CreateChannels(0, 0); |
| 668 | typename T::Content content; |
| 669 | CreateContent(0, kPcmuCodec, kH264Codec, &content); |
| 670 | content.set_buffered_mode_latency(101); |
| 671 | EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER)); |
| 672 | EXPECT_EQ(0U, media_channel1_->codecs().size()); |
| 673 | cricket::VideoOptions options; |
| 674 | ASSERT_TRUE(media_channel1_->GetOptions(&options)); |
| 675 | int latency = 0; |
| 676 | EXPECT_TRUE(options.buffered_mode_latency.Get(&latency)); |
| 677 | EXPECT_EQ(101, latency); |
| 678 | content.set_buffered_mode_latency(102); |
| 679 | EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER)); |
| 680 | ASSERT_EQ(1U, media_channel1_->codecs().size()); |
| 681 | EXPECT_TRUE(CodecMatches(content.codecs()[0], |
| 682 | media_channel1_->codecs()[0])); |
| 683 | ASSERT_TRUE(media_channel1_->GetOptions(&options)); |
| 684 | EXPECT_TRUE(options.buffered_mode_latency.Get(&latency)); |
| 685 | EXPECT_EQ(102, latency); |
| 686 | } |
| 687 | |
| 688 | // Test that SetRemoteContent properly deals with a content update. |
| 689 | void TestSetRemoteContentUpdate() { |
| 690 | CreateChannels(0, 0); |
| 691 | typename T::Content content; |
| 692 | CreateContent(RTCP | RTCP_MUX | SECURE, |
| 693 | kPcmuCodec, kH264Codec, |
| 694 | &content); |
| 695 | EXPECT_EQ(0U, media_channel1_->codecs().size()); |
| 696 | EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER)); |
| 697 | EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER)); |
| 698 | ASSERT_EQ(1U, media_channel1_->codecs().size()); |
| 699 | EXPECT_TRUE(CodecMatches(content.codecs()[0], |
| 700 | media_channel1_->codecs()[0])); |
| 701 | // Now update with other codecs. |
| 702 | typename T::Content update_content; |
| 703 | update_content.set_partial(true); |
| 704 | CreateContent(0, kIsacCodec, kH264SvcCodec, |
| 705 | &update_content); |
| 706 | EXPECT_TRUE(channel1_->SetRemoteContent(&update_content, CA_UPDATE)); |
| 707 | ASSERT_EQ(1U, media_channel1_->codecs().size()); |
| 708 | EXPECT_TRUE(CodecMatches(update_content.codecs()[0], |
| 709 | media_channel1_->codecs()[0])); |
| 710 | // Now update without any codecs. This is ignored. |
| 711 | typename T::Content empty_content; |
| 712 | empty_content.set_partial(true); |
| 713 | EXPECT_TRUE(channel1_->SetRemoteContent(&empty_content, CA_UPDATE)); |
| 714 | ASSERT_EQ(1U, media_channel1_->codecs().size()); |
| 715 | EXPECT_TRUE(CodecMatches(update_content.codecs()[0], |
| 716 | media_channel1_->codecs()[0])); |
| 717 | } |
| 718 | |
| 719 | // Test that Add/RemoveStream properly forward to the media channel. |
| 720 | void TestStreams() { |
| 721 | CreateChannels(0, 0); |
| 722 | EXPECT_TRUE(AddStream1(1)); |
| 723 | EXPECT_TRUE(AddStream1(2)); |
| 724 | EXPECT_EQ(2U, media_channel1_->recv_streams().size()); |
| 725 | EXPECT_TRUE(RemoveStream1(2)); |
| 726 | EXPECT_EQ(1U, media_channel1_->recv_streams().size()); |
| 727 | EXPECT_TRUE(RemoveStream1(1)); |
| 728 | EXPECT_EQ(0U, media_channel1_->recv_streams().size()); |
| 729 | } |
| 730 | |
| 731 | // Test that SetLocalContent properly handles adding and removing StreamParams |
| 732 | // to the local content description. |
| 733 | // This test uses the CA_UPDATE action that don't require a full |
| 734 | // MediaContentDescription to do an update. |
| 735 | void TestUpdateStreamsInLocalContent() { |
| 736 | cricket::StreamParams stream1; |
| 737 | stream1.groupid = "group1"; |
| 738 | stream1.id = "stream1"; |
| 739 | stream1.ssrcs.push_back(kSsrc1); |
| 740 | stream1.cname = "stream1_cname"; |
| 741 | |
| 742 | cricket::StreamParams stream2; |
| 743 | stream2.groupid = "group2"; |
| 744 | stream2.id = "stream2"; |
| 745 | stream2.ssrcs.push_back(kSsrc2); |
| 746 | stream2.cname = "stream2_cname"; |
| 747 | |
| 748 | cricket::StreamParams stream3; |
| 749 | stream3.groupid = "group3"; |
| 750 | stream3.id = "stream3"; |
| 751 | stream3.ssrcs.push_back(kSsrc3); |
| 752 | stream3.cname = "stream3_cname"; |
| 753 | |
| 754 | CreateChannels(0, 0); |
| 755 | typename T::Content content1; |
| 756 | CreateContent(0, kPcmuCodec, kH264Codec, &content1); |
| 757 | content1.AddStream(stream1); |
| 758 | EXPECT_EQ(0u, media_channel1_->send_streams().size()); |
| 759 | EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER)); |
| 760 | |
| 761 | ASSERT_EQ(1u, media_channel1_->send_streams().size()); |
| 762 | EXPECT_EQ(stream1, media_channel1_->send_streams()[0]); |
| 763 | |
| 764 | // Update the local streams by adding another sending stream. |
| 765 | // Use a partial updated session description. |
| 766 | typename T::Content content2; |
| 767 | content2.AddStream(stream2); |
| 768 | content2.AddStream(stream3); |
| 769 | content2.set_partial(true); |
| 770 | EXPECT_TRUE(channel1_->SetLocalContent(&content2, CA_UPDATE)); |
| 771 | ASSERT_EQ(3u, media_channel1_->send_streams().size()); |
| 772 | EXPECT_EQ(stream1, media_channel1_->send_streams()[0]); |
| 773 | EXPECT_EQ(stream2, media_channel1_->send_streams()[1]); |
| 774 | EXPECT_EQ(stream3, media_channel1_->send_streams()[2]); |
| 775 | |
| 776 | // Update the local streams by removing the first sending stream. |
| 777 | // This is done by removing all SSRCS for this particular stream. |
| 778 | typename T::Content content3; |
| 779 | stream1.ssrcs.clear(); |
| 780 | content3.AddStream(stream1); |
| 781 | content3.set_partial(true); |
| 782 | EXPECT_TRUE(channel1_->SetLocalContent(&content3, CA_UPDATE)); |
| 783 | ASSERT_EQ(2u, media_channel1_->send_streams().size()); |
| 784 | EXPECT_EQ(stream2, media_channel1_->send_streams()[0]); |
| 785 | EXPECT_EQ(stream3, media_channel1_->send_streams()[1]); |
| 786 | |
| 787 | // Update the local streams with a stream that does not change. |
| 788 | // THe update is ignored. |
| 789 | typename T::Content content4; |
| 790 | content4.AddStream(stream2); |
| 791 | content4.set_partial(true); |
| 792 | EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_UPDATE)); |
| 793 | ASSERT_EQ(2u, media_channel1_->send_streams().size()); |
| 794 | EXPECT_EQ(stream2, media_channel1_->send_streams()[0]); |
| 795 | EXPECT_EQ(stream3, media_channel1_->send_streams()[1]); |
| 796 | } |
| 797 | |
| 798 | // Test that SetRemoteContent properly handles adding and removing |
| 799 | // StreamParams to the remote content description. |
| 800 | // This test uses the CA_UPDATE action that don't require a full |
| 801 | // MediaContentDescription to do an update. |
| 802 | void TestUpdateStreamsInRemoteContent() { |
| 803 | cricket::StreamParams stream1; |
| 804 | stream1.id = "Stream1"; |
| 805 | stream1.groupid = "1"; |
| 806 | stream1.ssrcs.push_back(kSsrc1); |
| 807 | stream1.cname = "stream1_cname"; |
| 808 | |
| 809 | cricket::StreamParams stream2; |
| 810 | stream2.id = "Stream2"; |
| 811 | stream2.groupid = "2"; |
| 812 | stream2.ssrcs.push_back(kSsrc2); |
| 813 | stream2.cname = "stream2_cname"; |
| 814 | |
| 815 | cricket::StreamParams stream3; |
| 816 | stream3.id = "Stream3"; |
| 817 | stream3.groupid = "3"; |
| 818 | stream3.ssrcs.push_back(kSsrc3); |
| 819 | stream3.cname = "stream3_cname"; |
| 820 | |
| 821 | CreateChannels(0, 0); |
| 822 | typename T::Content content1; |
| 823 | CreateContent(0, kPcmuCodec, kH264Codec, &content1); |
| 824 | content1.AddStream(stream1); |
| 825 | EXPECT_EQ(0u, media_channel1_->recv_streams().size()); |
| 826 | EXPECT_TRUE(channel1_->SetRemoteContent(&content1, CA_OFFER)); |
| 827 | |
| 828 | ASSERT_EQ(1u, media_channel1_->codecs().size()); |
| 829 | ASSERT_EQ(1u, media_channel1_->recv_streams().size()); |
| 830 | EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]); |
| 831 | |
| 832 | // Update the remote streams by adding another sending stream. |
| 833 | // Use a partial updated session description. |
| 834 | typename T::Content content2; |
| 835 | content2.AddStream(stream2); |
| 836 | content2.AddStream(stream3); |
| 837 | content2.set_partial(true); |
| 838 | EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_UPDATE)); |
| 839 | ASSERT_EQ(3u, media_channel1_->recv_streams().size()); |
| 840 | EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]); |
| 841 | EXPECT_EQ(stream2, media_channel1_->recv_streams()[1]); |
| 842 | EXPECT_EQ(stream3, media_channel1_->recv_streams()[2]); |
| 843 | |
| 844 | // Update the remote streams by removing the first stream. |
| 845 | // This is done by removing all SSRCS for this particular stream. |
| 846 | typename T::Content content3; |
| 847 | stream1.ssrcs.clear(); |
| 848 | content3.AddStream(stream1); |
| 849 | content3.set_partial(true); |
| 850 | EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_UPDATE)); |
| 851 | ASSERT_EQ(2u, media_channel1_->recv_streams().size()); |
| 852 | EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]); |
| 853 | EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]); |
| 854 | |
| 855 | // Update the remote streams with a stream that does not change. |
| 856 | // The update is ignored. |
| 857 | typename T::Content content4; |
| 858 | content4.AddStream(stream2); |
| 859 | content4.set_partial(true); |
| 860 | EXPECT_TRUE(channel1_->SetRemoteContent(&content4, CA_UPDATE)); |
| 861 | ASSERT_EQ(2u, media_channel1_->recv_streams().size()); |
| 862 | EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]); |
| 863 | EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]); |
| 864 | } |
| 865 | |
| 866 | // Test that SetLocalContent and SetRemoteContent properly |
| 867 | // handles adding and removing StreamParams when the action is a full |
| 868 | // CA_OFFER / CA_ANSWER. |
| 869 | void TestChangeStreamParamsInContent() { |
| 870 | cricket::StreamParams stream1; |
| 871 | stream1.groupid = "group1"; |
| 872 | stream1.id = "stream1"; |
| 873 | stream1.ssrcs.push_back(kSsrc1); |
| 874 | stream1.cname = "stream1_cname"; |
| 875 | |
| 876 | cricket::StreamParams stream2; |
| 877 | stream2.groupid = "group1"; |
| 878 | stream2.id = "stream2"; |
| 879 | stream2.ssrcs.push_back(kSsrc2); |
| 880 | stream2.cname = "stream2_cname"; |
| 881 | |
| 882 | // Setup a call where channel 1 send |stream1| to channel 2. |
| 883 | CreateChannels(0, 0); |
| 884 | typename T::Content content1; |
| 885 | CreateContent(0, kPcmuCodec, kH264Codec, &content1); |
| 886 | content1.AddStream(stream1); |
| 887 | EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER)); |
| 888 | EXPECT_TRUE(channel1_->Enable(true)); |
| 889 | EXPECT_EQ(1u, media_channel1_->send_streams().size()); |
| 890 | |
| 891 | EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER)); |
| 892 | EXPECT_EQ(1u, media_channel2_->recv_streams().size()); |
| 893 | session1_.Connect(&session2_); |
| 894 | |
| 895 | // Channel 2 do not send anything. |
| 896 | typename T::Content content2; |
| 897 | CreateContent(0, kPcmuCodec, kH264Codec, &content2); |
| 898 | EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER)); |
| 899 | EXPECT_EQ(0u, media_channel1_->recv_streams().size()); |
| 900 | EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER)); |
| 901 | EXPECT_TRUE(channel2_->Enable(true)); |
| 902 | EXPECT_EQ(0u, media_channel2_->send_streams().size()); |
| 903 | |
| 904 | EXPECT_TRUE(SendCustomRtp1(kSsrc1, 0)); |
| 905 | EXPECT_TRUE(CheckCustomRtp2(kSsrc1, 0)); |
| 906 | |
| 907 | // Let channel 2 update the content by sending |stream2| and enable SRTP. |
| 908 | typename T::Content content3; |
| 909 | CreateContent(SECURE, kPcmuCodec, kH264Codec, &content3); |
| 910 | content3.AddStream(stream2); |
| 911 | EXPECT_TRUE(channel2_->SetLocalContent(&content3, CA_OFFER)); |
| 912 | ASSERT_EQ(1u, media_channel2_->send_streams().size()); |
| 913 | EXPECT_EQ(stream2, media_channel2_->send_streams()[0]); |
| 914 | |
| 915 | EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_OFFER)); |
| 916 | ASSERT_EQ(1u, media_channel1_->recv_streams().size()); |
| 917 | EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]); |
| 918 | |
| 919 | // Channel 1 replies but stop sending stream1. |
| 920 | typename T::Content content4; |
| 921 | CreateContent(SECURE, kPcmuCodec, kH264Codec, &content4); |
| 922 | EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_ANSWER)); |
| 923 | EXPECT_EQ(0u, media_channel1_->send_streams().size()); |
| 924 | |
| 925 | EXPECT_TRUE(channel2_->SetRemoteContent(&content4, CA_ANSWER)); |
| 926 | EXPECT_EQ(0u, media_channel2_->recv_streams().size()); |
| 927 | |
| 928 | EXPECT_TRUE(channel1_->secure()); |
| 929 | EXPECT_TRUE(channel2_->secure()); |
| 930 | EXPECT_TRUE(SendCustomRtp2(kSsrc2, 0)); |
| 931 | EXPECT_TRUE(CheckCustomRtp1(kSsrc2, 0)); |
| 932 | } |
| 933 | |
| 934 | // Test that we only start playout and sending at the right times. |
| 935 | void TestPlayoutAndSendingStates() { |
| 936 | CreateChannels(0, 0); |
| 937 | EXPECT_FALSE(media_channel1_->playout()); |
| 938 | EXPECT_FALSE(media_channel1_->sending()); |
| 939 | EXPECT_FALSE(media_channel2_->playout()); |
| 940 | EXPECT_FALSE(media_channel2_->sending()); |
| 941 | EXPECT_TRUE(channel1_->Enable(true)); |
| 942 | EXPECT_FALSE(media_channel1_->playout()); |
| 943 | EXPECT_FALSE(media_channel1_->sending()); |
| 944 | EXPECT_TRUE(channel1_->SetLocalContent(&local_media_content1_, CA_OFFER)); |
| 945 | EXPECT_TRUE(media_channel1_->playout()); |
| 946 | EXPECT_FALSE(media_channel1_->sending()); |
| 947 | EXPECT_TRUE(channel2_->SetRemoteContent(&local_media_content1_, CA_OFFER)); |
| 948 | EXPECT_FALSE(media_channel2_->playout()); |
| 949 | EXPECT_FALSE(media_channel2_->sending()); |
| 950 | EXPECT_TRUE(channel2_->SetLocalContent(&local_media_content2_, CA_ANSWER)); |
| 951 | EXPECT_FALSE(media_channel2_->playout()); |
| 952 | EXPECT_FALSE(media_channel2_->sending()); |
| 953 | session1_.Connect(&session2_); |
| 954 | EXPECT_TRUE(media_channel1_->playout()); |
| 955 | EXPECT_FALSE(media_channel1_->sending()); |
| 956 | EXPECT_FALSE(media_channel2_->playout()); |
| 957 | EXPECT_FALSE(media_channel2_->sending()); |
| 958 | EXPECT_TRUE(channel2_->Enable(true)); |
| 959 | EXPECT_TRUE(media_channel2_->playout()); |
| 960 | EXPECT_TRUE(media_channel2_->sending()); |
| 961 | EXPECT_TRUE(channel1_->SetRemoteContent(&local_media_content2_, CA_ANSWER)); |
| 962 | EXPECT_TRUE(media_channel1_->playout()); |
| 963 | EXPECT_TRUE(media_channel1_->sending()); |
| 964 | } |
| 965 | |
| 966 | void TestMuteStream() { |
| 967 | CreateChannels(0, 0); |
| 968 | // Test that we can Mute the default channel even though the sending SSRC is |
| 969 | // unknown. |
| 970 | EXPECT_FALSE(media_channel1_->IsStreamMuted(0)); |
| 971 | EXPECT_TRUE(channel1_->MuteStream(0, true)); |
| 972 | EXPECT_TRUE(media_channel1_->IsStreamMuted(0)); |
| 973 | EXPECT_TRUE(channel1_->MuteStream(0, false)); |
| 974 | EXPECT_FALSE(media_channel1_->IsStreamMuted(0)); |
| 975 | |
| 976 | // Test that we can not mute an unknown SSRC. |
| 977 | EXPECT_FALSE(channel1_->MuteStream(kSsrc1, true)); |
| 978 | |
| 979 | SendInitiate(); |
| 980 | // After the local session description has been set, we can mute a stream |
| 981 | // with its SSRC. |
| 982 | EXPECT_TRUE(channel1_->MuteStream(kSsrc1, true)); |
| 983 | EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1)); |
| 984 | EXPECT_TRUE(channel1_->MuteStream(kSsrc1, false)); |
| 985 | EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1)); |
| 986 | } |
| 987 | |
| 988 | // Test that changing the MediaContentDirection in the local and remote |
| 989 | // session description start playout and sending at the right time. |
| 990 | void TestMediaContentDirection() { |
| 991 | CreateChannels(0, 0); |
| 992 | typename T::Content content1; |
| 993 | CreateContent(0, kPcmuCodec, kH264Codec, &content1); |
| 994 | typename T::Content content2; |
| 995 | CreateContent(0, kPcmuCodec, kH264Codec, &content2); |
| 996 | // Set |content2| to be InActive. |
| 997 | content2.set_direction(cricket::MD_INACTIVE); |
| 998 | |
| 999 | EXPECT_TRUE(channel1_->Enable(true)); |
| 1000 | EXPECT_TRUE(channel2_->Enable(true)); |
| 1001 | EXPECT_FALSE(media_channel1_->playout()); |
| 1002 | EXPECT_FALSE(media_channel1_->sending()); |
| 1003 | EXPECT_FALSE(media_channel2_->playout()); |
| 1004 | EXPECT_FALSE(media_channel2_->sending()); |
| 1005 | |
| 1006 | EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER)); |
| 1007 | EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER)); |
| 1008 | EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER)); |
| 1009 | EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER)); |
| 1010 | session1_.Connect(&session2_); |
| 1011 | |
| 1012 | EXPECT_TRUE(media_channel1_->playout()); |
| 1013 | EXPECT_FALSE(media_channel1_->sending()); // remote InActive |
| 1014 | EXPECT_FALSE(media_channel2_->playout()); // local InActive |
| 1015 | EXPECT_FALSE(media_channel2_->sending()); // local InActive |
| 1016 | |
| 1017 | // Update |content2| to be RecvOnly. |
| 1018 | content2.set_direction(cricket::MD_RECVONLY); |
| 1019 | EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER)); |
| 1020 | EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER)); |
| 1021 | |
| 1022 | EXPECT_TRUE(media_channel1_->playout()); |
| 1023 | EXPECT_TRUE(media_channel1_->sending()); |
| 1024 | EXPECT_TRUE(media_channel2_->playout()); // local RecvOnly |
| 1025 | EXPECT_FALSE(media_channel2_->sending()); // local RecvOnly |
| 1026 | |
| 1027 | // Update |content2| to be SendRecv. |
| 1028 | content2.set_direction(cricket::MD_SENDRECV); |
| 1029 | EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER)); |
| 1030 | EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER)); |
| 1031 | |
| 1032 | EXPECT_TRUE(media_channel1_->playout()); |
| 1033 | EXPECT_TRUE(media_channel1_->sending()); |
| 1034 | EXPECT_TRUE(media_channel2_->playout()); |
| 1035 | EXPECT_TRUE(media_channel2_->sending()); |
| 1036 | } |
| 1037 | |
| 1038 | // Test setting up a call. |
| 1039 | void TestCallSetup() { |
| 1040 | CreateChannels(0, 0); |
| 1041 | EXPECT_FALSE(channel1_->secure()); |
| 1042 | EXPECT_TRUE(SendInitiate()); |
| 1043 | EXPECT_TRUE(media_channel1_->playout()); |
| 1044 | EXPECT_FALSE(media_channel1_->sending()); |
| 1045 | EXPECT_TRUE(SendAccept()); |
| 1046 | EXPECT_FALSE(channel1_->secure()); |
| 1047 | EXPECT_TRUE(media_channel1_->sending()); |
| 1048 | EXPECT_EQ(1U, media_channel1_->codecs().size()); |
| 1049 | EXPECT_TRUE(media_channel2_->playout()); |
| 1050 | EXPECT_TRUE(media_channel2_->sending()); |
| 1051 | EXPECT_EQ(1U, media_channel2_->codecs().size()); |
| 1052 | } |
| 1053 | |
| 1054 | // Test that we don't crash if packets are sent during call teardown |
| 1055 | // when RTCP mux is enabled. This is a regression test against a specific |
| 1056 | // race condition that would only occur when a RTCP packet was sent during |
| 1057 | // teardown of a channel on which RTCP mux was enabled. |
| 1058 | void TestCallTeardownRtcpMux() { |
| 1059 | class LastWordMediaChannel : public T::MediaChannel { |
| 1060 | public: |
| 1061 | LastWordMediaChannel() : T::MediaChannel(NULL) {} |
| 1062 | ~LastWordMediaChannel() { |
| 1063 | T::MediaChannel::SendRtp(kPcmuFrame, sizeof(kPcmuFrame)); |
| 1064 | T::MediaChannel::SendRtcp(kRtcpReport, sizeof(kRtcpReport)); |
| 1065 | } |
| 1066 | }; |
| 1067 | CreateChannels(new LastWordMediaChannel(), new LastWordMediaChannel(), |
| 1068 | RTCP | RTCP_MUX, RTCP | RTCP_MUX, |
| 1069 | talk_base::Thread::Current()); |
| 1070 | EXPECT_TRUE(SendInitiate()); |
| 1071 | EXPECT_TRUE(SendAccept()); |
| 1072 | EXPECT_TRUE(SendTerminate()); |
| 1073 | } |
| 1074 | |
| 1075 | // Send voice RTP data to the other side and ensure it gets there. |
| 1076 | void SendRtpToRtp() { |
| 1077 | CreateChannels(0, 0); |
| 1078 | EXPECT_TRUE(SendInitiate()); |
| 1079 | EXPECT_TRUE(SendAccept()); |
| 1080 | EXPECT_EQ(1U, GetTransport1()->channels().size()); |
| 1081 | EXPECT_EQ(1U, GetTransport2()->channels().size()); |
| 1082 | EXPECT_TRUE(SendRtp1()); |
| 1083 | EXPECT_TRUE(SendRtp2()); |
| 1084 | EXPECT_TRUE(CheckRtp1()); |
| 1085 | EXPECT_TRUE(CheckRtp2()); |
| 1086 | EXPECT_TRUE(CheckNoRtp1()); |
| 1087 | EXPECT_TRUE(CheckNoRtp2()); |
| 1088 | } |
| 1089 | |
| 1090 | // Check that RTCP is not transmitted if both sides don't support RTCP. |
| 1091 | void SendNoRtcpToNoRtcp() { |
| 1092 | CreateChannels(0, 0); |
| 1093 | EXPECT_TRUE(SendInitiate()); |
| 1094 | EXPECT_TRUE(SendAccept()); |
| 1095 | EXPECT_EQ(1U, GetTransport1()->channels().size()); |
| 1096 | EXPECT_EQ(1U, GetTransport2()->channels().size()); |
| 1097 | EXPECT_FALSE(SendRtcp1()); |
| 1098 | EXPECT_FALSE(SendRtcp2()); |
| 1099 | EXPECT_TRUE(CheckNoRtcp1()); |
| 1100 | EXPECT_TRUE(CheckNoRtcp2()); |
| 1101 | } |
| 1102 | |
| 1103 | // Check that RTCP is not transmitted if the callee doesn't support RTCP. |
| 1104 | void SendNoRtcpToRtcp() { |
| 1105 | CreateChannels(0, RTCP); |
| 1106 | EXPECT_TRUE(SendInitiate()); |
| 1107 | EXPECT_TRUE(SendAccept()); |
| 1108 | EXPECT_EQ(1U, GetTransport1()->channels().size()); |
| 1109 | EXPECT_EQ(2U, GetTransport2()->channels().size()); |
| 1110 | EXPECT_FALSE(SendRtcp1()); |
| 1111 | EXPECT_FALSE(SendRtcp2()); |
| 1112 | EXPECT_TRUE(CheckNoRtcp1()); |
| 1113 | EXPECT_TRUE(CheckNoRtcp2()); |
| 1114 | } |
| 1115 | |
| 1116 | // Check that RTCP is not transmitted if the caller doesn't support RTCP. |
| 1117 | void SendRtcpToNoRtcp() { |
| 1118 | CreateChannels(RTCP, 0); |
| 1119 | EXPECT_TRUE(SendInitiate()); |
| 1120 | EXPECT_TRUE(SendAccept()); |
| 1121 | EXPECT_EQ(2U, GetTransport1()->channels().size()); |
| 1122 | EXPECT_EQ(1U, GetTransport2()->channels().size()); |
| 1123 | EXPECT_FALSE(SendRtcp1()); |
| 1124 | EXPECT_FALSE(SendRtcp2()); |
| 1125 | EXPECT_TRUE(CheckNoRtcp1()); |
| 1126 | EXPECT_TRUE(CheckNoRtcp2()); |
| 1127 | } |
| 1128 | |
| 1129 | // Check that RTCP is transmitted if both sides support RTCP. |
| 1130 | void SendRtcpToRtcp() { |
| 1131 | CreateChannels(RTCP, RTCP); |
| 1132 | EXPECT_TRUE(SendInitiate()); |
| 1133 | EXPECT_TRUE(SendAccept()); |
| 1134 | EXPECT_EQ(2U, GetTransport1()->channels().size()); |
| 1135 | EXPECT_EQ(2U, GetTransport2()->channels().size()); |
| 1136 | EXPECT_TRUE(SendRtcp1()); |
| 1137 | EXPECT_TRUE(SendRtcp2()); |
| 1138 | EXPECT_TRUE(CheckRtcp1()); |
| 1139 | EXPECT_TRUE(CheckRtcp2()); |
| 1140 | EXPECT_TRUE(CheckNoRtcp1()); |
| 1141 | EXPECT_TRUE(CheckNoRtcp2()); |
| 1142 | } |
| 1143 | |
| 1144 | // Check that RTCP is transmitted if only the initiator supports mux. |
| 1145 | void SendRtcpMuxToRtcp() { |
| 1146 | CreateChannels(RTCP | RTCP_MUX, RTCP); |
| 1147 | EXPECT_TRUE(SendInitiate()); |
| 1148 | EXPECT_TRUE(SendAccept()); |
| 1149 | EXPECT_EQ(2U, GetTransport1()->channels().size()); |
| 1150 | EXPECT_EQ(2U, GetTransport2()->channels().size()); |
| 1151 | EXPECT_TRUE(SendRtcp1()); |
| 1152 | EXPECT_TRUE(SendRtcp2()); |
| 1153 | EXPECT_TRUE(CheckRtcp1()); |
| 1154 | EXPECT_TRUE(CheckRtcp2()); |
| 1155 | EXPECT_TRUE(CheckNoRtcp1()); |
| 1156 | EXPECT_TRUE(CheckNoRtcp2()); |
| 1157 | } |
| 1158 | |
| 1159 | // Check that RTP and RTCP are transmitted ok when both sides support mux. |
| 1160 | void SendRtcpMuxToRtcpMux() { |
| 1161 | CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX); |
| 1162 | EXPECT_TRUE(SendInitiate()); |
| 1163 | EXPECT_EQ(2U, GetTransport1()->channels().size()); |
| 1164 | EXPECT_EQ(1U, GetTransport2()->channels().size()); |
| 1165 | EXPECT_TRUE(SendAccept()); |
| 1166 | EXPECT_EQ(1U, GetTransport1()->channels().size()); |
| 1167 | EXPECT_TRUE(SendRtp1()); |
| 1168 | EXPECT_TRUE(SendRtp2()); |
| 1169 | EXPECT_TRUE(SendRtcp1()); |
| 1170 | EXPECT_TRUE(SendRtcp2()); |
| 1171 | EXPECT_TRUE(CheckRtp1()); |
| 1172 | EXPECT_TRUE(CheckRtp2()); |
| 1173 | EXPECT_TRUE(CheckNoRtp1()); |
| 1174 | EXPECT_TRUE(CheckNoRtp2()); |
| 1175 | EXPECT_TRUE(CheckRtcp1()); |
| 1176 | EXPECT_TRUE(CheckRtcp2()); |
| 1177 | EXPECT_TRUE(CheckNoRtcp1()); |
| 1178 | EXPECT_TRUE(CheckNoRtcp2()); |
| 1179 | } |
| 1180 | |
| 1181 | // Check that RTCP data sent by the initiator before the accept is not muxed. |
| 1182 | void SendEarlyRtcpMuxToRtcp() { |
| 1183 | CreateChannels(RTCP | RTCP_MUX, RTCP); |
| 1184 | EXPECT_TRUE(SendInitiate()); |
| 1185 | EXPECT_EQ(2U, GetTransport1()->channels().size()); |
| 1186 | EXPECT_EQ(2U, GetTransport2()->channels().size()); |
| 1187 | |
| 1188 | // RTCP can be sent before the call is accepted, if the transport is ready. |
| 1189 | // It should not be muxed though, as the remote side doesn't support mux. |
| 1190 | EXPECT_TRUE(SendRtcp1()); |
| 1191 | EXPECT_TRUE(CheckNoRtp2()); |
| 1192 | EXPECT_TRUE(CheckRtcp2()); |
| 1193 | |
| 1194 | // Send RTCP packet from callee and verify that it is received. |
| 1195 | EXPECT_TRUE(SendRtcp2()); |
| 1196 | EXPECT_TRUE(CheckNoRtp1()); |
| 1197 | EXPECT_TRUE(CheckRtcp1()); |
| 1198 | |
| 1199 | // Complete call setup and ensure everything is still OK. |
| 1200 | EXPECT_TRUE(SendAccept()); |
| 1201 | EXPECT_EQ(2U, GetTransport1()->channels().size()); |
| 1202 | EXPECT_TRUE(SendRtcp1()); |
| 1203 | EXPECT_TRUE(CheckRtcp2()); |
| 1204 | EXPECT_TRUE(SendRtcp2()); |
| 1205 | EXPECT_TRUE(CheckRtcp1()); |
| 1206 | } |
| 1207 | |
| 1208 | |
| 1209 | // Check that RTCP data is not muxed until both sides have enabled muxing, |
| 1210 | // but that we properly demux before we get the accept message, since there |
| 1211 | // is a race between RTP data and the jingle accept. |
| 1212 | void SendEarlyRtcpMuxToRtcpMux() { |
| 1213 | CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX); |
| 1214 | EXPECT_TRUE(SendInitiate()); |
| 1215 | EXPECT_EQ(2U, GetTransport1()->channels().size()); |
| 1216 | EXPECT_EQ(1U, GetTransport2()->channels().size()); |
| 1217 | |
| 1218 | // RTCP can't be sent yet, since the RTCP transport isn't writable, and |
| 1219 | // we haven't yet received the accept that says we should mux. |
| 1220 | EXPECT_FALSE(SendRtcp1()); |
| 1221 | |
| 1222 | // Send muxed RTCP packet from callee and verify that it is received. |
| 1223 | EXPECT_TRUE(SendRtcp2()); |
| 1224 | EXPECT_TRUE(CheckNoRtp1()); |
| 1225 | EXPECT_TRUE(CheckRtcp1()); |
| 1226 | |
| 1227 | // Complete call setup and ensure everything is still OK. |
| 1228 | EXPECT_TRUE(SendAccept()); |
| 1229 | EXPECT_EQ(1U, GetTransport1()->channels().size()); |
| 1230 | EXPECT_TRUE(SendRtcp1()); |
| 1231 | EXPECT_TRUE(CheckRtcp2()); |
| 1232 | EXPECT_TRUE(SendRtcp2()); |
| 1233 | EXPECT_TRUE(CheckRtcp1()); |
| 1234 | } |
| 1235 | |
| 1236 | // Test that we properly send SRTP with RTCP in both directions. |
| 1237 | // You can pass in DTLS and/or RTCP_MUX as flags. |
| 1238 | void SendSrtpToSrtp(int flags1_in = 0, int flags2_in = 0) { |
| 1239 | ASSERT((flags1_in & ~(RTCP_MUX | DTLS)) == 0); |
| 1240 | ASSERT((flags2_in & ~(RTCP_MUX | DTLS)) == 0); |
| 1241 | |
| 1242 | int flags1 = RTCP | SECURE | flags1_in; |
| 1243 | int flags2 = RTCP | SECURE | flags2_in; |
| 1244 | bool dtls1 = !!(flags1_in & DTLS); |
| 1245 | bool dtls2 = !!(flags2_in & DTLS); |
| 1246 | CreateChannels(flags1, flags2); |
| 1247 | EXPECT_FALSE(channel1_->secure()); |
| 1248 | EXPECT_FALSE(channel2_->secure()); |
| 1249 | EXPECT_TRUE(SendInitiate()); |
| 1250 | EXPECT_TRUE_WAIT(channel1_->writable(), kEventTimeout); |
| 1251 | EXPECT_TRUE_WAIT(channel2_->writable(), kEventTimeout); |
| 1252 | EXPECT_TRUE(SendAccept()); |
| 1253 | EXPECT_TRUE(channel1_->secure()); |
| 1254 | EXPECT_TRUE(channel2_->secure()); |
| 1255 | EXPECT_EQ(dtls1 && dtls2, channel1_->secure_dtls()); |
| 1256 | EXPECT_EQ(dtls1 && dtls2, channel2_->secure_dtls()); |
| 1257 | EXPECT_TRUE(SendRtp1()); |
| 1258 | EXPECT_TRUE(SendRtp2()); |
| 1259 | EXPECT_TRUE(SendRtcp1()); |
| 1260 | EXPECT_TRUE(SendRtcp2()); |
| 1261 | EXPECT_TRUE(CheckRtp1()); |
| 1262 | EXPECT_TRUE(CheckRtp2()); |
| 1263 | EXPECT_TRUE(CheckNoRtp1()); |
| 1264 | EXPECT_TRUE(CheckNoRtp2()); |
| 1265 | EXPECT_TRUE(CheckRtcp1()); |
| 1266 | EXPECT_TRUE(CheckRtcp2()); |
| 1267 | EXPECT_TRUE(CheckNoRtcp1()); |
| 1268 | EXPECT_TRUE(CheckNoRtcp2()); |
| 1269 | } |
| 1270 | |
| 1271 | // Test that we properly handling SRTP negotiating down to RTP. |
| 1272 | void SendSrtpToRtp() { |
| 1273 | CreateChannels(RTCP | SECURE, RTCP); |
| 1274 | EXPECT_FALSE(channel1_->secure()); |
| 1275 | EXPECT_FALSE(channel2_->secure()); |
| 1276 | EXPECT_TRUE(SendInitiate()); |
| 1277 | EXPECT_TRUE(SendAccept()); |
| 1278 | EXPECT_FALSE(channel1_->secure()); |
| 1279 | EXPECT_FALSE(channel2_->secure()); |
| 1280 | EXPECT_TRUE(SendRtp1()); |
| 1281 | EXPECT_TRUE(SendRtp2()); |
| 1282 | EXPECT_TRUE(SendRtcp1()); |
| 1283 | EXPECT_TRUE(SendRtcp2()); |
| 1284 | EXPECT_TRUE(CheckRtp1()); |
| 1285 | EXPECT_TRUE(CheckRtp2()); |
| 1286 | EXPECT_TRUE(CheckNoRtp1()); |
| 1287 | EXPECT_TRUE(CheckNoRtp2()); |
| 1288 | EXPECT_TRUE(CheckRtcp1()); |
| 1289 | EXPECT_TRUE(CheckRtcp2()); |
| 1290 | EXPECT_TRUE(CheckNoRtcp1()); |
| 1291 | EXPECT_TRUE(CheckNoRtcp2()); |
| 1292 | } |
| 1293 | |
| 1294 | // Test that we can send and receive early media when a provisional answer is |
| 1295 | // sent and received. The test uses SRTP, RTCP mux and SSRC mux. |
| 1296 | void SendEarlyMediaUsingRtcpMuxSrtp() { |
| 1297 | int sequence_number1_1 = 0, sequence_number2_2 = 0; |
| 1298 | |
| 1299 | CreateChannels(SSRC_MUX | RTCP | RTCP_MUX | SECURE, |
| 1300 | SSRC_MUX | RTCP | RTCP_MUX | SECURE); |
| 1301 | EXPECT_TRUE(SendOffer()); |
| 1302 | EXPECT_TRUE(SendProvisionalAnswer()); |
| 1303 | EXPECT_TRUE(channel1_->secure()); |
| 1304 | EXPECT_TRUE(channel2_->secure()); |
| 1305 | EXPECT_EQ(2U, GetTransport1()->channels().size()); |
| 1306 | EXPECT_EQ(2U, GetTransport2()->channels().size()); |
| 1307 | EXPECT_TRUE(SendCustomRtcp1(kSsrc1)); |
| 1308 | EXPECT_TRUE(CheckCustomRtcp2(kSsrc1)); |
| 1309 | EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1)); |
| 1310 | EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1)); |
| 1311 | |
| 1312 | // Send packets from callee and verify that it is received. |
| 1313 | EXPECT_TRUE(SendCustomRtcp2(kSsrc2)); |
| 1314 | EXPECT_TRUE(CheckCustomRtcp1(kSsrc2)); |
| 1315 | EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2)); |
| 1316 | EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2)); |
| 1317 | |
| 1318 | // Complete call setup and ensure everything is still OK. |
| 1319 | EXPECT_TRUE(SendFinalAnswer()); |
| 1320 | EXPECT_EQ(1U, GetTransport1()->channels().size()); |
| 1321 | EXPECT_EQ(1U, GetTransport2()->channels().size()); |
| 1322 | EXPECT_TRUE(channel1_->secure()); |
| 1323 | EXPECT_TRUE(channel2_->secure()); |
| 1324 | EXPECT_TRUE(SendCustomRtcp1(kSsrc1)); |
| 1325 | EXPECT_TRUE(CheckCustomRtcp2(kSsrc1)); |
| 1326 | EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1)); |
| 1327 | EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1)); |
| 1328 | EXPECT_TRUE(SendCustomRtcp2(kSsrc2)); |
| 1329 | EXPECT_TRUE(CheckCustomRtcp1(kSsrc2)); |
| 1330 | EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2)); |
| 1331 | EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2)); |
| 1332 | } |
| 1333 | |
| 1334 | // Test that we properly send RTP without SRTP from a thread. |
| 1335 | void SendRtpToRtpOnThread() { |
| 1336 | bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2; |
| 1337 | CreateChannels(RTCP, RTCP); |
| 1338 | EXPECT_TRUE(SendInitiate()); |
| 1339 | EXPECT_TRUE(SendAccept()); |
| 1340 | CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1); |
| 1341 | CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2); |
| 1342 | CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1); |
| 1343 | CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2); |
| 1344 | EXPECT_TRUE_WAIT(CheckRtp1(), 1000); |
| 1345 | EXPECT_TRUE_WAIT(CheckRtp2(), 1000); |
| 1346 | EXPECT_TRUE_WAIT(sent_rtp1, 1000); |
| 1347 | EXPECT_TRUE_WAIT(sent_rtp2, 1000); |
| 1348 | EXPECT_TRUE(CheckNoRtp1()); |
| 1349 | EXPECT_TRUE(CheckNoRtp2()); |
| 1350 | EXPECT_TRUE_WAIT(CheckRtcp1(), 1000); |
| 1351 | EXPECT_TRUE_WAIT(CheckRtcp2(), 1000); |
| 1352 | EXPECT_TRUE_WAIT(sent_rtcp1, 1000); |
| 1353 | EXPECT_TRUE_WAIT(sent_rtcp2, 1000); |
| 1354 | EXPECT_TRUE(CheckNoRtcp1()); |
| 1355 | EXPECT_TRUE(CheckNoRtcp2()); |
| 1356 | } |
| 1357 | |
| 1358 | // Test that we properly send SRTP with RTCP from a thread. |
| 1359 | void SendSrtpToSrtpOnThread() { |
| 1360 | bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2; |
| 1361 | CreateChannels(RTCP | SECURE, RTCP | SECURE); |
| 1362 | EXPECT_TRUE(SendInitiate()); |
| 1363 | EXPECT_TRUE(SendAccept()); |
| 1364 | CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1); |
| 1365 | CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2); |
| 1366 | CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1); |
| 1367 | CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2); |
| 1368 | EXPECT_TRUE_WAIT(CheckRtp1(), 1000); |
| 1369 | EXPECT_TRUE_WAIT(CheckRtp2(), 1000); |
| 1370 | EXPECT_TRUE_WAIT(sent_rtp1, 1000); |
| 1371 | EXPECT_TRUE_WAIT(sent_rtp2, 1000); |
| 1372 | EXPECT_TRUE(CheckNoRtp1()); |
| 1373 | EXPECT_TRUE(CheckNoRtp2()); |
| 1374 | EXPECT_TRUE_WAIT(CheckRtcp1(), 1000); |
| 1375 | EXPECT_TRUE_WAIT(CheckRtcp2(), 1000); |
| 1376 | EXPECT_TRUE_WAIT(sent_rtcp1, 1000); |
| 1377 | EXPECT_TRUE_WAIT(sent_rtcp2, 1000); |
| 1378 | EXPECT_TRUE(CheckNoRtcp1()); |
| 1379 | EXPECT_TRUE(CheckNoRtcp2()); |
| 1380 | } |
| 1381 | |
| 1382 | // Test that the mediachannel retains its sending state after the transport |
| 1383 | // becomes non-writable. |
| 1384 | void SendWithWritabilityLoss() { |
| 1385 | CreateChannels(0, 0); |
| 1386 | EXPECT_TRUE(SendInitiate()); |
| 1387 | EXPECT_TRUE(SendAccept()); |
| 1388 | EXPECT_EQ(1U, GetTransport1()->channels().size()); |
| 1389 | EXPECT_EQ(1U, GetTransport2()->channels().size()); |
| 1390 | EXPECT_TRUE(SendRtp1()); |
| 1391 | EXPECT_TRUE(SendRtp2()); |
| 1392 | EXPECT_TRUE(CheckRtp1()); |
| 1393 | EXPECT_TRUE(CheckRtp2()); |
| 1394 | EXPECT_TRUE(CheckNoRtp1()); |
| 1395 | EXPECT_TRUE(CheckNoRtp2()); |
| 1396 | |
| 1397 | // Lose writability, with optimistic send |
| 1398 | SetOptimisticDataSend(true); |
| 1399 | GetTransport1()->SetWritable(false); |
| 1400 | EXPECT_TRUE(media_channel1_->sending()); |
| 1401 | EXPECT_TRUE(SendRtp1()); |
| 1402 | EXPECT_TRUE(SendRtp2()); |
| 1403 | EXPECT_TRUE(CheckRtp1()); |
| 1404 | EXPECT_TRUE(CheckRtp2()); |
| 1405 | EXPECT_TRUE(CheckNoRtp1()); |
| 1406 | EXPECT_TRUE(CheckNoRtp2()); |
| 1407 | |
| 1408 | // Check again with optimistic send off, which should fail. |
| 1409 | SetOptimisticDataSend(false); |
| 1410 | EXPECT_FALSE(SendRtp1()); |
| 1411 | EXPECT_TRUE(SendRtp2()); |
| 1412 | EXPECT_TRUE(CheckRtp1()); |
| 1413 | EXPECT_TRUE(CheckNoRtp2()); |
| 1414 | |
| 1415 | // Regain writability |
| 1416 | GetTransport1()->SetWritable(true); |
| 1417 | EXPECT_TRUE(media_channel1_->sending()); |
| 1418 | EXPECT_TRUE(SendRtp1()); |
| 1419 | EXPECT_TRUE(SendRtp2()); |
| 1420 | EXPECT_TRUE(CheckRtp1()); |
| 1421 | EXPECT_TRUE(CheckRtp2()); |
| 1422 | EXPECT_TRUE(CheckNoRtp1()); |
| 1423 | EXPECT_TRUE(CheckNoRtp2()); |
| 1424 | |
| 1425 | // Lose writability completely |
| 1426 | GetTransport1()->SetDestination(NULL); |
| 1427 | EXPECT_TRUE(media_channel1_->sending()); |
| 1428 | |
| 1429 | // Should fail regardless of optimistic send at this point. |
| 1430 | SetOptimisticDataSend(true); |
| 1431 | EXPECT_FALSE(SendRtp1()); |
| 1432 | EXPECT_TRUE(SendRtp2()); |
| 1433 | EXPECT_TRUE(CheckRtp1()); |
| 1434 | EXPECT_TRUE(CheckNoRtp2()); |
| 1435 | SetOptimisticDataSend(false); |
| 1436 | EXPECT_FALSE(SendRtp1()); |
| 1437 | EXPECT_TRUE(SendRtp2()); |
| 1438 | EXPECT_TRUE(CheckRtp1()); |
| 1439 | EXPECT_TRUE(CheckNoRtp2()); |
| 1440 | |
| 1441 | // Gain writability back |
| 1442 | GetTransport1()->SetDestination(GetTransport2()); |
| 1443 | EXPECT_TRUE(media_channel1_->sending()); |
| 1444 | EXPECT_TRUE(SendRtp1()); |
| 1445 | EXPECT_TRUE(SendRtp2()); |
| 1446 | EXPECT_TRUE(CheckRtp1()); |
| 1447 | EXPECT_TRUE(CheckRtp2()); |
| 1448 | EXPECT_TRUE(CheckNoRtp1()); |
| 1449 | EXPECT_TRUE(CheckNoRtp2()); |
| 1450 | } |
| 1451 | |
| 1452 | void SendSsrcMuxToSsrcMuxWithRtcpMux() { |
| 1453 | int sequence_number1_1 = 0, sequence_number2_2 = 0; |
| 1454 | CreateChannels(SSRC_MUX | RTCP | RTCP_MUX, SSRC_MUX | RTCP | RTCP_MUX); |
| 1455 | EXPECT_TRUE(SendInitiate()); |
| 1456 | EXPECT_EQ(2U, GetTransport1()->channels().size()); |
| 1457 | EXPECT_EQ(1U, GetTransport2()->channels().size()); |
| 1458 | EXPECT_TRUE(SendAccept()); |
| 1459 | EXPECT_EQ(1U, GetTransport1()->channels().size()); |
| 1460 | EXPECT_EQ(1U, GetTransport2()->channels().size()); |
| 1461 | EXPECT_TRUE(channel1_->ssrc_filter()->IsActive()); |
| 1462 | // channel1 - should have media_content2 as remote. i.e. kSsrc2 |
| 1463 | EXPECT_TRUE(channel1_->ssrc_filter()->FindStream(kSsrc2)); |
| 1464 | EXPECT_TRUE(channel2_->ssrc_filter()->IsActive()); |
| 1465 | // channel2 - should have media_content1 as remote. i.e. kSsrc1 |
| 1466 | EXPECT_TRUE(channel2_->ssrc_filter()->FindStream(kSsrc1)); |
| 1467 | EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1)); |
| 1468 | EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2)); |
| 1469 | EXPECT_TRUE(SendCustomRtcp1(kSsrc1)); |
| 1470 | EXPECT_TRUE(SendCustomRtcp2(kSsrc2)); |
| 1471 | EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2)); |
| 1472 | EXPECT_TRUE(CheckNoRtp1()); |
| 1473 | EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1)); |
| 1474 | EXPECT_TRUE(CheckNoRtp2()); |
| 1475 | EXPECT_TRUE(CheckCustomRtcp1(kSsrc2)); |
| 1476 | EXPECT_TRUE(CheckNoRtcp1()); |
| 1477 | EXPECT_TRUE(CheckCustomRtcp2(kSsrc1)); |
| 1478 | EXPECT_TRUE(CheckNoRtcp2()); |
| 1479 | } |
| 1480 | |
| 1481 | void SendSsrcMuxToSsrcMux() { |
| 1482 | int sequence_number1_1 = 0, sequence_number2_2 = 0; |
| 1483 | CreateChannels(SSRC_MUX | RTCP, SSRC_MUX | RTCP); |
| 1484 | EXPECT_TRUE(SendInitiate()); |
| 1485 | EXPECT_EQ(2U, GetTransport1()->channels().size()); |
| 1486 | EXPECT_EQ(2U, GetTransport2()->channels().size()); |
| 1487 | EXPECT_TRUE(SendAccept()); |
| 1488 | EXPECT_EQ(2U, GetTransport1()->channels().size()); |
| 1489 | EXPECT_EQ(2U, GetTransport2()->channels().size()); |
| 1490 | EXPECT_TRUE(channel1_->ssrc_filter()->IsActive()); |
| 1491 | // channel1 - should have media_content2 as remote. i.e. kSsrc2 |
| 1492 | EXPECT_TRUE(channel1_->ssrc_filter()->FindStream(kSsrc2)); |
| 1493 | EXPECT_TRUE(channel2_->ssrc_filter()->IsActive()); |
| 1494 | // channel2 - should have media_content1 as remote. i.e. kSsrc1 |
| 1495 | EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1)); |
| 1496 | EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2)); |
| 1497 | EXPECT_TRUE(SendCustomRtcp1(kSsrc1)); |
| 1498 | EXPECT_TRUE(SendCustomRtcp2(kSsrc2)); |
| 1499 | EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2)); |
| 1500 | EXPECT_FALSE(CheckCustomRtp1(kSsrc1, sequence_number2_2)); |
| 1501 | EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1)); |
| 1502 | EXPECT_FALSE(CheckCustomRtp2(kSsrc2, sequence_number1_1)); |
| 1503 | EXPECT_TRUE(CheckCustomRtcp1(kSsrc2)); |
| 1504 | EXPECT_FALSE(CheckCustomRtcp1(kSsrc1)); |
| 1505 | EXPECT_TRUE(CheckCustomRtcp2(kSsrc1)); |
| 1506 | EXPECT_FALSE(CheckCustomRtcp2(kSsrc2)); |
| 1507 | } |
| 1508 | |
| 1509 | // Test that the media monitor can be run and gives timely callbacks. |
| 1510 | void TestMediaMonitor() { |
| 1511 | static const int kTimeout = 500; |
| 1512 | CreateChannels(0, 0); |
| 1513 | EXPECT_TRUE(SendInitiate()); |
| 1514 | EXPECT_TRUE(SendAccept()); |
| 1515 | channel1_->StartMediaMonitor(100); |
| 1516 | channel2_->StartMediaMonitor(100); |
| 1517 | // Ensure we get callbacks and stop. |
| 1518 | EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout); |
| 1519 | EXPECT_TRUE_WAIT(media_info_callbacks2_ > 0, kTimeout); |
| 1520 | channel1_->StopMediaMonitor(); |
| 1521 | channel2_->StopMediaMonitor(); |
| 1522 | // Ensure a restart of a stopped monitor works. |
| 1523 | channel1_->StartMediaMonitor(100); |
| 1524 | EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout); |
| 1525 | channel1_->StopMediaMonitor(); |
| 1526 | // Ensure stopping a stopped monitor is OK. |
| 1527 | channel1_->StopMediaMonitor(); |
| 1528 | } |
| 1529 | |
| 1530 | void TestMediaSinks() { |
| 1531 | CreateChannels(0, 0); |
| 1532 | EXPECT_TRUE(SendInitiate()); |
| 1533 | EXPECT_TRUE(SendAccept()); |
| 1534 | EXPECT_FALSE(channel1_->HasSendSinks(cricket::SINK_POST_CRYPTO)); |
| 1535 | EXPECT_FALSE(channel1_->HasRecvSinks(cricket::SINK_POST_CRYPTO)); |
| 1536 | EXPECT_FALSE(channel1_->HasSendSinks(cricket::SINK_PRE_CRYPTO)); |
| 1537 | EXPECT_FALSE(channel1_->HasRecvSinks(cricket::SINK_PRE_CRYPTO)); |
| 1538 | |
| 1539 | talk_base::Pathname path; |
| 1540 | EXPECT_TRUE(talk_base::Filesystem::GetTemporaryFolder(path, true, NULL)); |
| 1541 | path.SetFilename("sink-test.rtpdump"); |
| 1542 | talk_base::scoped_ptr<cricket::RtpDumpSink> sink( |
| 1543 | new cricket::RtpDumpSink(Open(path.pathname()))); |
| 1544 | sink->set_packet_filter(cricket::PF_ALL); |
| 1545 | EXPECT_TRUE(sink->Enable(true)); |
| 1546 | channel1_->RegisterSendSink( |
| 1547 | sink.get(), &cricket::RtpDumpSink::OnPacket, cricket::SINK_POST_CRYPTO); |
| 1548 | EXPECT_TRUE(channel1_->HasSendSinks(cricket::SINK_POST_CRYPTO)); |
| 1549 | EXPECT_FALSE(channel1_->HasRecvSinks(cricket::SINK_POST_CRYPTO)); |
| 1550 | EXPECT_FALSE(channel1_->HasSendSinks(cricket::SINK_PRE_CRYPTO)); |
| 1551 | EXPECT_FALSE(channel1_->HasRecvSinks(cricket::SINK_PRE_CRYPTO)); |
| 1552 | |
| 1553 | // The first packet is recorded with header + data. |
| 1554 | EXPECT_TRUE(SendRtp1()); |
| 1555 | // The second packet is recorded with header only. |
| 1556 | sink->set_packet_filter(cricket::PF_RTPHEADER); |
| 1557 | EXPECT_TRUE(SendRtp1()); |
| 1558 | // The third packet is not recorded since sink is disabled. |
| 1559 | EXPECT_TRUE(sink->Enable(false)); |
| 1560 | EXPECT_TRUE(SendRtp1()); |
| 1561 | // The fourth packet is not recorded since sink is unregistered. |
| 1562 | EXPECT_TRUE(sink->Enable(true)); |
| 1563 | channel1_->UnregisterSendSink(sink.get(), cricket::SINK_POST_CRYPTO); |
| 1564 | EXPECT_TRUE(SendRtp1()); |
| 1565 | sink.reset(); // This will close the file. |
| 1566 | |
| 1567 | // Read the recorded file and verify two packets. |
| 1568 | talk_base::scoped_ptr<talk_base::StreamInterface> stream( |
| 1569 | talk_base::Filesystem::OpenFile(path, "rb")); |
| 1570 | |
| 1571 | cricket::RtpDumpReader reader(stream.get()); |
| 1572 | cricket::RtpDumpPacket packet; |
| 1573 | EXPECT_EQ(talk_base::SR_SUCCESS, reader.ReadPacket(&packet)); |
| 1574 | std::string read_packet(reinterpret_cast<const char*>(&packet.data[0]), |
| 1575 | packet.data.size()); |
| 1576 | EXPECT_EQ(rtp_packet_, read_packet); |
| 1577 | |
| 1578 | EXPECT_EQ(talk_base::SR_SUCCESS, reader.ReadPacket(&packet)); |
| 1579 | size_t len = 0; |
| 1580 | packet.GetRtpHeaderLen(&len); |
| 1581 | EXPECT_EQ(len, packet.data.size()); |
| 1582 | EXPECT_EQ(0, memcmp(&packet.data[0], rtp_packet_.c_str(), len)); |
| 1583 | |
| 1584 | EXPECT_EQ(talk_base::SR_EOS, reader.ReadPacket(&packet)); |
| 1585 | |
| 1586 | // Delete the file for media recording. |
| 1587 | stream.reset(); |
| 1588 | EXPECT_TRUE(talk_base::Filesystem::DeleteFile(path)); |
| 1589 | } |
| 1590 | |
| 1591 | void TestSetContentFailure() { |
| 1592 | CreateChannels(0, 0); |
| 1593 | typename T::Content content; |
| 1594 | cricket::SessionDescription* sdesc_loc = new cricket::SessionDescription(); |
| 1595 | cricket::SessionDescription* sdesc_rem = new cricket::SessionDescription(); |
| 1596 | |
| 1597 | // Set up the session description. |
| 1598 | CreateContent(0, kPcmuCodec, kH264Codec, &content); |
| 1599 | sdesc_loc->AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP, |
| 1600 | new cricket::AudioContentDescription()); |
| 1601 | sdesc_loc->AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP, |
| 1602 | new cricket::VideoContentDescription()); |
| 1603 | EXPECT_TRUE(session1_.set_local_description(sdesc_loc)); |
| 1604 | sdesc_rem->AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP, |
| 1605 | new cricket::AudioContentDescription()); |
| 1606 | sdesc_rem->AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP, |
| 1607 | new cricket::VideoContentDescription()); |
| 1608 | EXPECT_TRUE(session1_.set_remote_description(sdesc_rem)); |
| 1609 | |
| 1610 | // Test failures in SetLocalContent. |
| 1611 | media_channel1_->set_fail_set_recv_codecs(true); |
| 1612 | session1_.SetError(cricket::BaseSession::ERROR_NONE); |
| 1613 | session1_.SetState(cricket::Session::STATE_SENTINITIATE); |
| 1614 | EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error()); |
| 1615 | media_channel1_->set_fail_set_recv_codecs(true); |
| 1616 | session1_.SetError(cricket::BaseSession::ERROR_NONE); |
| 1617 | session1_.SetState(cricket::Session::STATE_SENTACCEPT); |
| 1618 | EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error()); |
| 1619 | |
| 1620 | // Test failures in SetRemoteContent. |
| 1621 | media_channel1_->set_fail_set_send_codecs(true); |
| 1622 | session1_.SetError(cricket::BaseSession::ERROR_NONE); |
| 1623 | session1_.SetState(cricket::Session::STATE_RECEIVEDINITIATE); |
| 1624 | EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error()); |
| 1625 | media_channel1_->set_fail_set_send_codecs(true); |
| 1626 | session1_.SetError(cricket::BaseSession::ERROR_NONE); |
| 1627 | session1_.SetState(cricket::Session::STATE_RECEIVEDACCEPT); |
| 1628 | EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error()); |
| 1629 | } |
| 1630 | |
| 1631 | void TestSendTwoOffers() { |
| 1632 | CreateChannels(0, 0); |
| 1633 | |
| 1634 | // Set up the initial session description. |
| 1635 | cricket::SessionDescription* sdesc = CreateSessionDescriptionWithStream(1); |
| 1636 | EXPECT_TRUE(session1_.set_local_description(sdesc)); |
| 1637 | |
| 1638 | session1_.SetError(cricket::BaseSession::ERROR_NONE); |
| 1639 | session1_.SetState(cricket::Session::STATE_SENTINITIATE); |
| 1640 | EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error()); |
| 1641 | EXPECT_TRUE(media_channel1_->HasSendStream(1)); |
| 1642 | |
| 1643 | // Update the local description and set the state again. |
| 1644 | sdesc = CreateSessionDescriptionWithStream(2); |
| 1645 | EXPECT_TRUE(session1_.set_local_description(sdesc)); |
| 1646 | |
| 1647 | session1_.SetState(cricket::Session::STATE_SENTINITIATE); |
| 1648 | EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error()); |
| 1649 | EXPECT_FALSE(media_channel1_->HasSendStream(1)); |
| 1650 | EXPECT_TRUE(media_channel1_->HasSendStream(2)); |
| 1651 | } |
| 1652 | |
| 1653 | void TestReceiveTwoOffers() { |
| 1654 | CreateChannels(0, 0); |
| 1655 | |
| 1656 | // Set up the initial session description. |
| 1657 | cricket::SessionDescription* sdesc = CreateSessionDescriptionWithStream(1); |
| 1658 | EXPECT_TRUE(session1_.set_remote_description(sdesc)); |
| 1659 | |
| 1660 | session1_.SetError(cricket::BaseSession::ERROR_NONE); |
| 1661 | session1_.SetState(cricket::Session::STATE_RECEIVEDINITIATE); |
| 1662 | EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error()); |
| 1663 | EXPECT_TRUE(media_channel1_->HasRecvStream(1)); |
| 1664 | |
| 1665 | sdesc = CreateSessionDescriptionWithStream(2); |
| 1666 | EXPECT_TRUE(session1_.set_remote_description(sdesc)); |
| 1667 | session1_.SetState(cricket::Session::STATE_RECEIVEDINITIATE); |
| 1668 | EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error()); |
| 1669 | EXPECT_FALSE(media_channel1_->HasRecvStream(1)); |
| 1670 | EXPECT_TRUE(media_channel1_->HasRecvStream(2)); |
| 1671 | } |
| 1672 | |
| 1673 | void TestSendPrAnswer() { |
| 1674 | CreateChannels(0, 0); |
| 1675 | |
| 1676 | // Set up the initial session description. |
| 1677 | cricket::SessionDescription* sdesc = CreateSessionDescriptionWithStream(1); |
| 1678 | EXPECT_TRUE(session1_.set_remote_description(sdesc)); |
| 1679 | |
| 1680 | session1_.SetError(cricket::BaseSession::ERROR_NONE); |
| 1681 | session1_.SetState(cricket::Session::STATE_RECEIVEDINITIATE); |
| 1682 | EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error()); |
| 1683 | EXPECT_TRUE(media_channel1_->HasRecvStream(1)); |
| 1684 | |
| 1685 | // Send PRANSWER |
| 1686 | sdesc = CreateSessionDescriptionWithStream(2); |
| 1687 | EXPECT_TRUE(session1_.set_local_description(sdesc)); |
| 1688 | |
| 1689 | session1_.SetState(cricket::Session::STATE_SENTPRACCEPT); |
| 1690 | EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error()); |
| 1691 | EXPECT_TRUE(media_channel1_->HasRecvStream(1)); |
| 1692 | EXPECT_TRUE(media_channel1_->HasSendStream(2)); |
| 1693 | |
| 1694 | // Send ACCEPT |
| 1695 | sdesc = CreateSessionDescriptionWithStream(3); |
| 1696 | EXPECT_TRUE(session1_.set_local_description(sdesc)); |
| 1697 | |
| 1698 | session1_.SetState(cricket::Session::STATE_SENTACCEPT); |
| 1699 | EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error()); |
| 1700 | EXPECT_TRUE(media_channel1_->HasRecvStream(1)); |
| 1701 | EXPECT_FALSE(media_channel1_->HasSendStream(2)); |
| 1702 | EXPECT_TRUE(media_channel1_->HasSendStream(3)); |
| 1703 | } |
| 1704 | |
| 1705 | void TestReceivePrAnswer() { |
| 1706 | CreateChannels(0, 0); |
| 1707 | |
| 1708 | // Set up the initial session description. |
| 1709 | cricket::SessionDescription* sdesc = CreateSessionDescriptionWithStream(1); |
| 1710 | EXPECT_TRUE(session1_.set_local_description(sdesc)); |
| 1711 | |
| 1712 | session1_.SetError(cricket::BaseSession::ERROR_NONE); |
| 1713 | session1_.SetState(cricket::Session::STATE_SENTINITIATE); |
| 1714 | EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error()); |
| 1715 | EXPECT_TRUE(media_channel1_->HasSendStream(1)); |
| 1716 | |
| 1717 | // Receive PRANSWER |
| 1718 | sdesc = CreateSessionDescriptionWithStream(2); |
| 1719 | EXPECT_TRUE(session1_.set_remote_description(sdesc)); |
| 1720 | |
| 1721 | session1_.SetState(cricket::Session::STATE_RECEIVEDPRACCEPT); |
| 1722 | EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error()); |
| 1723 | EXPECT_TRUE(media_channel1_->HasSendStream(1)); |
| 1724 | EXPECT_TRUE(media_channel1_->HasRecvStream(2)); |
| 1725 | |
| 1726 | // Receive ACCEPT |
| 1727 | sdesc = CreateSessionDescriptionWithStream(3); |
| 1728 | EXPECT_TRUE(session1_.set_remote_description(sdesc)); |
| 1729 | |
| 1730 | session1_.SetState(cricket::Session::STATE_RECEIVEDACCEPT); |
| 1731 | EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error()); |
| 1732 | EXPECT_TRUE(media_channel1_->HasSendStream(1)); |
| 1733 | EXPECT_FALSE(media_channel1_->HasRecvStream(2)); |
| 1734 | EXPECT_TRUE(media_channel1_->HasRecvStream(3)); |
| 1735 | } |
| 1736 | |
| 1737 | void TestFlushRtcp() { |
| 1738 | bool send_rtcp1; |
| 1739 | |
| 1740 | CreateChannels(RTCP, RTCP); |
| 1741 | EXPECT_TRUE(SendInitiate()); |
| 1742 | EXPECT_TRUE(SendAccept()); |
| 1743 | EXPECT_EQ(2U, GetTransport1()->channels().size()); |
| 1744 | EXPECT_EQ(2U, GetTransport2()->channels().size()); |
| 1745 | |
| 1746 | // Send RTCP1 from a different thread. |
| 1747 | CallOnThreadAndWaitForDone(&ChannelTest<T>::SendRtcp1, &send_rtcp1); |
| 1748 | EXPECT_TRUE(send_rtcp1); |
| 1749 | // The sending message is only posted. channel2_ should be empty. |
| 1750 | EXPECT_TRUE(CheckNoRtcp2()); |
| 1751 | |
| 1752 | // When channel1_ is deleted, the RTCP packet should be sent out to |
| 1753 | // channel2_. |
| 1754 | channel1_.reset(); |
| 1755 | EXPECT_TRUE(CheckRtcp2()); |
| 1756 | } |
| 1757 | |
| 1758 | void TestChangeStateError() { |
| 1759 | CreateChannels(RTCP, RTCP); |
| 1760 | EXPECT_TRUE(SendInitiate()); |
| 1761 | media_channel2_->set_fail_set_send(true); |
| 1762 | EXPECT_TRUE(channel2_->Enable(true)); |
| 1763 | EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_DEVICE_OPEN_FAILED, |
| 1764 | error_); |
| 1765 | } |
| 1766 | |
| 1767 | void TestSrtpError() { |
| 1768 | static const unsigned char kBadPacket[] = { |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 1769 | 0x84, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1770 | }; |
| 1771 | CreateChannels(RTCP | SECURE, RTCP | SECURE); |
| 1772 | EXPECT_FALSE(channel1_->secure()); |
| 1773 | EXPECT_FALSE(channel2_->secure()); |
| 1774 | EXPECT_TRUE(SendInitiate()); |
| 1775 | EXPECT_TRUE(SendAccept()); |
| 1776 | EXPECT_TRUE(channel1_->secure()); |
| 1777 | EXPECT_TRUE(channel2_->secure()); |
| 1778 | channel2_->set_srtp_signal_silent_time(200); |
| 1779 | |
| 1780 | // Testing failures in sending packets. |
| 1781 | EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket))); |
| 1782 | // The first failure will trigger an error. |
| 1783 | EXPECT_EQ_WAIT(T::MediaChannel::ERROR_REC_SRTP_ERROR, error_, 500); |
| 1784 | error_ = T::MediaChannel::ERROR_NONE; |
| 1785 | // The next 1 sec failures will not trigger an error. |
| 1786 | EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket))); |
| 1787 | // Wait for a while to ensure no message comes in. |
| 1788 | talk_base::Thread::Current()->ProcessMessages(210); |
| 1789 | EXPECT_EQ(T::MediaChannel::ERROR_NONE, error_); |
| 1790 | // The error will be triggered again. |
| 1791 | EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket))); |
| 1792 | EXPECT_EQ_WAIT(T::MediaChannel::ERROR_REC_SRTP_ERROR, error_, 500); |
| 1793 | |
| 1794 | // Testing failures in receiving packets. |
| 1795 | error_ = T::MediaChannel::ERROR_NONE; |
| 1796 | cricket::TransportChannel* transport_channel = |
| 1797 | channel2_->transport_channel(); |
| 1798 | transport_channel->SignalReadPacket( |
| 1799 | transport_channel, reinterpret_cast<const char*>(kBadPacket), |
| 1800 | sizeof(kBadPacket), 0); |
mallinath@webrtc.org | 4d3e8b8 | 2013-08-16 00:31:17 +0000 | [diff] [blame] | 1801 | EXPECT_EQ_WAIT(T::MediaChannel::ERROR_PLAY_SRTP_ERROR, error_, 500); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1802 | } |
| 1803 | |
| 1804 | void TestOnReadyToSend() { |
| 1805 | CreateChannels(RTCP, RTCP); |
| 1806 | TransportChannel* rtp = channel1_->transport_channel(); |
| 1807 | TransportChannel* rtcp = channel1_->rtcp_transport_channel(); |
| 1808 | EXPECT_FALSE(media_channel1_->ready_to_send()); |
| 1809 | rtp->SignalReadyToSend(rtp); |
| 1810 | EXPECT_FALSE(media_channel1_->ready_to_send()); |
| 1811 | rtcp->SignalReadyToSend(rtcp); |
| 1812 | // MediaChannel::OnReadyToSend only be called when both rtp and rtcp |
| 1813 | // channel are ready to send. |
| 1814 | EXPECT_TRUE(media_channel1_->ready_to_send()); |
| 1815 | |
| 1816 | // rtp channel becomes not ready to send will be propagated to mediachannel |
| 1817 | channel1_->SetReadyToSend(rtp, false); |
| 1818 | EXPECT_FALSE(media_channel1_->ready_to_send()); |
| 1819 | channel1_->SetReadyToSend(rtp, true); |
| 1820 | EXPECT_TRUE(media_channel1_->ready_to_send()); |
| 1821 | |
| 1822 | // rtcp channel becomes not ready to send will be propagated to mediachannel |
| 1823 | channel1_->SetReadyToSend(rtcp, false); |
| 1824 | EXPECT_FALSE(media_channel1_->ready_to_send()); |
| 1825 | channel1_->SetReadyToSend(rtcp, true); |
| 1826 | EXPECT_TRUE(media_channel1_->ready_to_send()); |
| 1827 | } |
| 1828 | |
| 1829 | void TestOnReadyToSendWithRtcpMux() { |
| 1830 | CreateChannels(RTCP, RTCP); |
| 1831 | typename T::Content content; |
| 1832 | CreateContent(0, kPcmuCodec, kH264Codec, &content); |
| 1833 | // Both sides agree on mux. Should no longer be a separate RTCP channel. |
| 1834 | content.set_rtcp_mux(true); |
| 1835 | EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER)); |
| 1836 | EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER)); |
| 1837 | EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL); |
| 1838 | TransportChannel* rtp = channel1_->transport_channel(); |
| 1839 | EXPECT_FALSE(media_channel1_->ready_to_send()); |
| 1840 | // In the case of rtcp mux, the SignalReadyToSend() from rtp channel |
| 1841 | // should trigger the MediaChannel's OnReadyToSend. |
| 1842 | rtp->SignalReadyToSend(rtp); |
| 1843 | EXPECT_TRUE(media_channel1_->ready_to_send()); |
| 1844 | channel1_->SetReadyToSend(rtp, false); |
| 1845 | EXPECT_FALSE(media_channel1_->ready_to_send()); |
| 1846 | } |
| 1847 | |
| 1848 | protected: |
| 1849 | cricket::FakeSession session1_; |
| 1850 | cricket::FakeSession session2_; |
| 1851 | cricket::FakeMediaEngine media_engine_; |
| 1852 | // The media channels are owned by the voice channel objects below. |
| 1853 | typename T::MediaChannel* media_channel1_; |
| 1854 | typename T::MediaChannel* media_channel2_; |
| 1855 | talk_base::scoped_ptr<typename T::Channel> channel1_; |
| 1856 | talk_base::scoped_ptr<typename T::Channel> channel2_; |
| 1857 | typename T::Content local_media_content1_; |
| 1858 | typename T::Content local_media_content2_; |
| 1859 | typename T::Content remote_media_content1_; |
| 1860 | typename T::Content remote_media_content2_; |
| 1861 | talk_base::scoped_ptr<talk_base::SSLIdentity> identity1_; |
| 1862 | talk_base::scoped_ptr<talk_base::SSLIdentity> identity2_; |
| 1863 | // The RTP and RTCP packets to send in the tests. |
| 1864 | std::string rtp_packet_; |
| 1865 | std::string rtcp_packet_; |
| 1866 | int media_info_callbacks1_; |
| 1867 | int media_info_callbacks2_; |
| 1868 | bool mute_callback_recved_; |
| 1869 | bool mute_callback_value_; |
| 1870 | |
| 1871 | uint32 ssrc_; |
| 1872 | typename T::MediaChannel::Error error_; |
| 1873 | }; |
| 1874 | |
| 1875 | |
| 1876 | template<> |
| 1877 | void ChannelTest<VoiceTraits>::CreateContent( |
| 1878 | int flags, |
| 1879 | const cricket::AudioCodec& audio_codec, |
| 1880 | const cricket::VideoCodec& video_codec, |
| 1881 | cricket::AudioContentDescription* audio) { |
| 1882 | audio->AddCodec(audio_codec); |
| 1883 | audio->set_rtcp_mux((flags & RTCP_MUX) != 0); |
| 1884 | if (flags & SECURE) { |
| 1885 | audio->AddCrypto(cricket::CryptoParams( |
| 1886 | 1, cricket::CS_AES_CM_128_HMAC_SHA1_32, |
| 1887 | "inline:" + talk_base::CreateRandomString(40), "")); |
| 1888 | } |
| 1889 | } |
| 1890 | |
| 1891 | template<> |
| 1892 | void ChannelTest<VoiceTraits>::CopyContent( |
| 1893 | const cricket::AudioContentDescription& source, |
| 1894 | cricket::AudioContentDescription* audio) { |
| 1895 | *audio = source; |
| 1896 | } |
| 1897 | |
| 1898 | template<> |
| 1899 | bool ChannelTest<VoiceTraits>::CodecMatches(const cricket::AudioCodec& c1, |
| 1900 | const cricket::AudioCodec& c2) { |
| 1901 | return c1.name == c2.name && c1.clockrate == c2.clockrate && |
| 1902 | c1.bitrate == c2.bitrate && c1.channels == c2.channels; |
| 1903 | } |
| 1904 | |
| 1905 | template<> |
| 1906 | void ChannelTest<VoiceTraits>::AddLegacyStreamInContent( |
| 1907 | uint32 ssrc, int flags, cricket::AudioContentDescription* audio) { |
| 1908 | audio->AddLegacyStream(ssrc); |
| 1909 | } |
| 1910 | |
| 1911 | class VoiceChannelTest |
| 1912 | : public ChannelTest<VoiceTraits> { |
| 1913 | public: |
| 1914 | typedef ChannelTest<VoiceTraits> |
| 1915 | Base; |
| 1916 | VoiceChannelTest() : Base(kPcmuFrame, sizeof(kPcmuFrame), |
| 1917 | kRtcpReport, sizeof(kRtcpReport)) { |
| 1918 | } |
| 1919 | |
| 1920 | void TestSetChannelOptions() { |
| 1921 | CreateChannels(0, 0); |
| 1922 | |
| 1923 | cricket::AudioOptions options1; |
| 1924 | options1.echo_cancellation.Set(false); |
| 1925 | cricket::AudioOptions options2; |
| 1926 | options2.echo_cancellation.Set(true); |
| 1927 | |
| 1928 | channel1_->SetChannelOptions(options1); |
| 1929 | channel2_->SetChannelOptions(options1); |
| 1930 | cricket::AudioOptions actual_options; |
| 1931 | ASSERT_TRUE(media_channel1_->GetOptions(&actual_options)); |
| 1932 | EXPECT_EQ(options1, actual_options); |
| 1933 | ASSERT_TRUE(media_channel2_->GetOptions(&actual_options)); |
| 1934 | EXPECT_EQ(options1, actual_options); |
| 1935 | |
| 1936 | channel1_->SetChannelOptions(options2); |
| 1937 | channel2_->SetChannelOptions(options2); |
| 1938 | ASSERT_TRUE(media_channel1_->GetOptions(&actual_options)); |
| 1939 | EXPECT_EQ(options2, actual_options); |
| 1940 | ASSERT_TRUE(media_channel2_->GetOptions(&actual_options)); |
| 1941 | EXPECT_EQ(options2, actual_options); |
| 1942 | } |
| 1943 | }; |
| 1944 | |
| 1945 | // override to add NULL parameter |
| 1946 | template<> |
| 1947 | cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel( |
| 1948 | talk_base::Thread* thread, cricket::MediaEngineInterface* engine, |
| 1949 | cricket::FakeVideoMediaChannel* ch, cricket::BaseSession* session, |
| 1950 | bool rtcp) { |
| 1951 | cricket::VideoChannel* channel = new cricket::VideoChannel( |
| 1952 | thread, engine, ch, session, cricket::CN_VIDEO, rtcp, NULL); |
| 1953 | if (!channel->Init()) { |
| 1954 | delete channel; |
| 1955 | channel = NULL; |
| 1956 | } |
| 1957 | return channel; |
| 1958 | } |
| 1959 | |
| 1960 | // override to add 0 parameter |
| 1961 | template<> |
| 1962 | bool ChannelTest<VideoTraits>::AddStream1(int id) { |
| 1963 | return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id)); |
| 1964 | } |
| 1965 | |
| 1966 | template<> |
| 1967 | void ChannelTest<VideoTraits>::CreateContent( |
| 1968 | int flags, |
| 1969 | const cricket::AudioCodec& audio_codec, |
| 1970 | const cricket::VideoCodec& video_codec, |
| 1971 | cricket::VideoContentDescription* video) { |
| 1972 | video->AddCodec(video_codec); |
| 1973 | video->set_rtcp_mux((flags & RTCP_MUX) != 0); |
| 1974 | if (flags & SECURE) { |
| 1975 | video->AddCrypto(cricket::CryptoParams( |
| 1976 | 1, cricket::CS_AES_CM_128_HMAC_SHA1_80, |
| 1977 | "inline:" + talk_base::CreateRandomString(40), "")); |
| 1978 | } |
| 1979 | } |
| 1980 | |
| 1981 | template<> |
| 1982 | void ChannelTest<VideoTraits>::CopyContent( |
| 1983 | const cricket::VideoContentDescription& source, |
| 1984 | cricket::VideoContentDescription* video) { |
| 1985 | *video = source; |
| 1986 | } |
| 1987 | |
| 1988 | template<> |
| 1989 | bool ChannelTest<VideoTraits>::CodecMatches(const cricket::VideoCodec& c1, |
| 1990 | const cricket::VideoCodec& c2) { |
| 1991 | return c1.name == c2.name && c1.width == c2.width && c1.height == c2.height && |
| 1992 | c1.framerate == c2.framerate; |
| 1993 | } |
| 1994 | |
| 1995 | template<> |
| 1996 | void ChannelTest<VideoTraits>::AddLegacyStreamInContent( |
| 1997 | uint32 ssrc, int flags, cricket::VideoContentDescription* video) { |
| 1998 | video->AddLegacyStream(ssrc); |
| 1999 | } |
| 2000 | |
| 2001 | class VideoChannelTest |
| 2002 | : public ChannelTest<VideoTraits> { |
| 2003 | public: |
| 2004 | typedef ChannelTest<VideoTraits> |
| 2005 | Base; |
| 2006 | VideoChannelTest() : Base(kH264Packet, sizeof(kH264Packet), |
| 2007 | kRtcpReport, sizeof(kRtcpReport)) { |
| 2008 | } |
| 2009 | |
| 2010 | void TestSetChannelOptions() { |
| 2011 | CreateChannels(0, 0); |
| 2012 | |
| 2013 | cricket::VideoOptions o1, o2; |
| 2014 | o1.video_noise_reduction.Set(true); |
| 2015 | |
| 2016 | channel1_->SetChannelOptions(o1); |
| 2017 | channel2_->SetChannelOptions(o1); |
| 2018 | EXPECT_TRUE(media_channel1_->GetOptions(&o2)); |
| 2019 | EXPECT_EQ(o1, o2); |
| 2020 | EXPECT_TRUE(media_channel2_->GetOptions(&o2)); |
| 2021 | EXPECT_EQ(o1, o2); |
| 2022 | |
| 2023 | o1.video_leaky_bucket.Set(true); |
| 2024 | channel1_->SetChannelOptions(o1); |
| 2025 | channel2_->SetChannelOptions(o1); |
| 2026 | EXPECT_TRUE(media_channel1_->GetOptions(&o2)); |
| 2027 | EXPECT_EQ(o1, o2); |
| 2028 | EXPECT_TRUE(media_channel2_->GetOptions(&o2)); |
| 2029 | EXPECT_EQ(o1, o2); |
| 2030 | } |
| 2031 | }; |
| 2032 | |
| 2033 | |
| 2034 | // VoiceChannelTest |
| 2035 | |
| 2036 | TEST_F(VoiceChannelTest, TestInit) { |
| 2037 | Base::TestInit(); |
| 2038 | EXPECT_FALSE(media_channel1_->IsStreamMuted(0)); |
| 2039 | EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty()); |
| 2040 | } |
| 2041 | |
| 2042 | TEST_F(VoiceChannelTest, TestSetContents) { |
| 2043 | Base::TestSetContents(); |
| 2044 | } |
| 2045 | |
| 2046 | TEST_F(VoiceChannelTest, TestSetContentsNullOffer) { |
| 2047 | Base::TestSetContentsNullOffer(); |
| 2048 | } |
| 2049 | |
| 2050 | TEST_F(VoiceChannelTest, TestSetContentsRtcpMux) { |
| 2051 | Base::TestSetContentsRtcpMux(); |
| 2052 | } |
| 2053 | |
| 2054 | TEST_F(VoiceChannelTest, TestSetContentsRtcpMuxWithPrAnswer) { |
| 2055 | Base::TestSetContentsRtcpMux(); |
| 2056 | } |
| 2057 | |
| 2058 | TEST_F(VoiceChannelTest, TestSetRemoteContentUpdate) { |
| 2059 | Base::TestSetRemoteContentUpdate(); |
| 2060 | } |
| 2061 | |
| 2062 | TEST_F(VoiceChannelTest, TestStreams) { |
| 2063 | Base::TestStreams(); |
| 2064 | } |
| 2065 | |
| 2066 | TEST_F(VoiceChannelTest, TestUpdateStreamsInLocalContent) { |
| 2067 | Base::TestUpdateStreamsInLocalContent(); |
| 2068 | } |
| 2069 | |
| 2070 | TEST_F(VoiceChannelTest, TestUpdateRemoteStreamsInContent) { |
| 2071 | Base::TestUpdateStreamsInRemoteContent(); |
| 2072 | } |
| 2073 | |
| 2074 | TEST_F(VoiceChannelTest, TestChangeStreamParamsInContent) { |
| 2075 | Base::TestChangeStreamParamsInContent(); |
| 2076 | } |
| 2077 | |
| 2078 | TEST_F(VoiceChannelTest, TestPlayoutAndSendingStates) { |
| 2079 | Base::TestPlayoutAndSendingStates(); |
| 2080 | } |
| 2081 | |
| 2082 | TEST_F(VoiceChannelTest, TestMuteStream) { |
| 2083 | Base::TestMuteStream(); |
| 2084 | } |
| 2085 | |
| 2086 | TEST_F(VoiceChannelTest, TestMediaContentDirection) { |
| 2087 | Base::TestMediaContentDirection(); |
| 2088 | } |
| 2089 | |
| 2090 | TEST_F(VoiceChannelTest, TestCallSetup) { |
| 2091 | Base::TestCallSetup(); |
| 2092 | } |
| 2093 | |
| 2094 | TEST_F(VoiceChannelTest, TestCallTeardownRtcpMux) { |
| 2095 | Base::TestCallTeardownRtcpMux(); |
| 2096 | } |
| 2097 | |
| 2098 | TEST_F(VoiceChannelTest, SendRtpToRtp) { |
| 2099 | Base::SendRtpToRtp(); |
| 2100 | } |
| 2101 | |
| 2102 | TEST_F(VoiceChannelTest, SendNoRtcpToNoRtcp) { |
| 2103 | Base::SendNoRtcpToNoRtcp(); |
| 2104 | } |
| 2105 | |
| 2106 | TEST_F(VoiceChannelTest, SendNoRtcpToRtcp) { |
| 2107 | Base::SendNoRtcpToRtcp(); |
| 2108 | } |
| 2109 | |
| 2110 | TEST_F(VoiceChannelTest, SendRtcpToNoRtcp) { |
| 2111 | Base::SendRtcpToNoRtcp(); |
| 2112 | } |
| 2113 | |
| 2114 | TEST_F(VoiceChannelTest, SendRtcpToRtcp) { |
| 2115 | Base::SendRtcpToRtcp(); |
| 2116 | } |
| 2117 | |
| 2118 | TEST_F(VoiceChannelTest, SendRtcpMuxToRtcp) { |
| 2119 | Base::SendRtcpMuxToRtcp(); |
| 2120 | } |
| 2121 | |
| 2122 | TEST_F(VoiceChannelTest, SendRtcpMuxToRtcpMux) { |
| 2123 | Base::SendRtcpMuxToRtcpMux(); |
| 2124 | } |
| 2125 | |
| 2126 | TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcp) { |
| 2127 | Base::SendEarlyRtcpMuxToRtcp(); |
| 2128 | } |
| 2129 | |
| 2130 | TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcpMux) { |
| 2131 | Base::SendEarlyRtcpMuxToRtcpMux(); |
| 2132 | } |
| 2133 | |
| 2134 | TEST_F(VoiceChannelTest, SendSrtpToSrtpRtcpMux) { |
| 2135 | Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX); |
| 2136 | } |
| 2137 | |
| 2138 | TEST_F(VoiceChannelTest, SendSrtpToRtp) { |
| 2139 | Base::SendSrtpToSrtp(); |
| 2140 | } |
| 2141 | |
| 2142 | TEST_F(VoiceChannelTest, SendSrtcpMux) { |
| 2143 | Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX); |
| 2144 | } |
| 2145 | |
| 2146 | TEST_F(VoiceChannelTest, SendDtlsSrtpToSrtp) { |
| 2147 | MAYBE_SKIP_TEST(HaveDtlsSrtp); |
| 2148 | Base::SendSrtpToSrtp(DTLS, 0); |
| 2149 | } |
| 2150 | |
| 2151 | TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtp) { |
| 2152 | MAYBE_SKIP_TEST(HaveDtlsSrtp); |
| 2153 | Base::SendSrtpToSrtp(DTLS, DTLS); |
| 2154 | } |
| 2155 | |
| 2156 | TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) { |
| 2157 | MAYBE_SKIP_TEST(HaveDtlsSrtp); |
| 2158 | Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX); |
| 2159 | } |
| 2160 | |
| 2161 | TEST_F(VoiceChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) { |
| 2162 | Base::SendEarlyMediaUsingRtcpMuxSrtp(); |
| 2163 | } |
| 2164 | |
| 2165 | TEST_F(VoiceChannelTest, SendRtpToRtpOnThread) { |
| 2166 | Base::SendRtpToRtpOnThread(); |
| 2167 | } |
| 2168 | |
| 2169 | TEST_F(VoiceChannelTest, SendSrtpToSrtpOnThread) { |
| 2170 | Base::SendSrtpToSrtpOnThread(); |
| 2171 | } |
| 2172 | |
| 2173 | TEST_F(VoiceChannelTest, SendWithWritabilityLoss) { |
| 2174 | Base::SendWithWritabilityLoss(); |
| 2175 | } |
| 2176 | |
| 2177 | TEST_F(VoiceChannelTest, TestMediaMonitor) { |
| 2178 | Base::TestMediaMonitor(); |
| 2179 | } |
| 2180 | |
| 2181 | // Test that MuteStream properly forwards to the media channel and does |
| 2182 | // not signal. |
| 2183 | TEST_F(VoiceChannelTest, TestVoiceSpecificMuteStream) { |
| 2184 | CreateChannels(0, 0); |
| 2185 | EXPECT_FALSE(media_channel1_->IsStreamMuted(0)); |
| 2186 | EXPECT_FALSE(mute_callback_recved_); |
| 2187 | EXPECT_TRUE(channel1_->MuteStream(0, true)); |
| 2188 | EXPECT_TRUE(media_channel1_->IsStreamMuted(0)); |
| 2189 | EXPECT_FALSE(mute_callback_recved_); |
| 2190 | EXPECT_TRUE(channel1_->MuteStream(0, false)); |
| 2191 | EXPECT_FALSE(media_channel1_->IsStreamMuted(0)); |
| 2192 | EXPECT_FALSE(mute_callback_recved_); |
| 2193 | } |
| 2194 | |
| 2195 | // Test that keyboard automute works correctly and signals upwards. |
asapersson@webrtc.org | b533a82 | 2013-09-23 19:47:49 +0000 | [diff] [blame] | 2196 | TEST_F(VoiceChannelTest, DISABLED_TestKeyboardMute) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2197 | CreateChannels(0, 0); |
| 2198 | EXPECT_FALSE(media_channel1_->IsStreamMuted(0)); |
| 2199 | EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_NONE, error_); |
| 2200 | |
| 2201 | cricket::VoiceMediaChannel::Error e = |
| 2202 | cricket::VoiceMediaChannel::ERROR_REC_TYPING_NOISE_DETECTED; |
| 2203 | |
| 2204 | // Typing doesn't mute automatically unless typing monitor has been installed |
| 2205 | media_channel1_->TriggerError(0, e); |
| 2206 | talk_base::Thread::Current()->ProcessMessages(0); |
| 2207 | EXPECT_EQ(e, error_); |
| 2208 | EXPECT_FALSE(media_channel1_->IsStreamMuted(0)); |
| 2209 | EXPECT_FALSE(mute_callback_recved_); |
| 2210 | |
| 2211 | cricket::TypingMonitorOptions o = {0}; |
| 2212 | o.mute_period = 1500; |
| 2213 | channel1_->StartTypingMonitor(o); |
| 2214 | media_channel1_->TriggerError(0, e); |
| 2215 | talk_base::Thread::Current()->ProcessMessages(0); |
| 2216 | EXPECT_TRUE(media_channel1_->IsStreamMuted(0)); |
| 2217 | EXPECT_TRUE(mute_callback_recved_); |
| 2218 | } |
| 2219 | |
| 2220 | // Test that PressDTMF properly forwards to the media channel. |
| 2221 | TEST_F(VoiceChannelTest, TestDtmf) { |
| 2222 | CreateChannels(0, 0); |
| 2223 | EXPECT_TRUE(SendInitiate()); |
| 2224 | EXPECT_TRUE(SendAccept()); |
| 2225 | EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size()); |
| 2226 | |
| 2227 | EXPECT_TRUE(channel1_->PressDTMF(1, true)); |
| 2228 | EXPECT_TRUE(channel1_->PressDTMF(8, false)); |
| 2229 | |
| 2230 | ASSERT_EQ(2U, media_channel1_->dtmf_info_queue().size()); |
| 2231 | EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0], |
| 2232 | 0, 1, 160, cricket::DF_PLAY | cricket::DF_SEND)); |
| 2233 | EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1], |
| 2234 | 0, 8, 160, cricket::DF_SEND)); |
| 2235 | } |
| 2236 | |
| 2237 | // Test that InsertDtmf properly forwards to the media channel. |
| 2238 | TEST_F(VoiceChannelTest, TestInsertDtmf) { |
| 2239 | CreateChannels(0, 0); |
| 2240 | EXPECT_TRUE(SendInitiate()); |
| 2241 | EXPECT_TRUE(SendAccept()); |
| 2242 | EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size()); |
| 2243 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2244 | EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100, cricket::DF_SEND)); |
| 2245 | EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110, cricket::DF_PLAY)); |
| 2246 | EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120, |
| 2247 | cricket::DF_PLAY | cricket::DF_SEND)); |
| 2248 | |
henrike@webrtc.org | 9de257d | 2013-07-17 14:42:53 +0000 | [diff] [blame] | 2249 | ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2250 | EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0], |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2251 | 1, 3, 100, cricket::DF_SEND)); |
henrike@webrtc.org | 9de257d | 2013-07-17 14:42:53 +0000 | [diff] [blame] | 2252 | EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1], |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2253 | 2, 5, 110, cricket::DF_PLAY)); |
henrike@webrtc.org | 9de257d | 2013-07-17 14:42:53 +0000 | [diff] [blame] | 2254 | EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2], |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2255 | 3, 7, 120, cricket::DF_PLAY | cricket::DF_SEND)); |
| 2256 | } |
| 2257 | |
| 2258 | TEST_F(VoiceChannelTest, TestMediaSinks) { |
| 2259 | Base::TestMediaSinks(); |
| 2260 | } |
| 2261 | |
| 2262 | TEST_F(VoiceChannelTest, TestSetContentFailure) { |
| 2263 | Base::TestSetContentFailure(); |
| 2264 | } |
| 2265 | |
| 2266 | TEST_F(VoiceChannelTest, TestSendTwoOffers) { |
| 2267 | Base::TestSendTwoOffers(); |
| 2268 | } |
| 2269 | |
| 2270 | TEST_F(VoiceChannelTest, TestReceiveTwoOffers) { |
| 2271 | Base::TestReceiveTwoOffers(); |
| 2272 | } |
| 2273 | |
| 2274 | TEST_F(VoiceChannelTest, TestSendPrAnswer) { |
| 2275 | Base::TestSendPrAnswer(); |
| 2276 | } |
| 2277 | |
| 2278 | TEST_F(VoiceChannelTest, TestReceivePrAnswer) { |
| 2279 | Base::TestReceivePrAnswer(); |
| 2280 | } |
| 2281 | |
| 2282 | TEST_F(VoiceChannelTest, TestFlushRtcp) { |
| 2283 | Base::TestFlushRtcp(); |
| 2284 | } |
| 2285 | |
| 2286 | TEST_F(VoiceChannelTest, TestChangeStateError) { |
| 2287 | Base::TestChangeStateError(); |
| 2288 | } |
| 2289 | |
| 2290 | TEST_F(VoiceChannelTest, TestSrtpError) { |
| 2291 | Base::TestSrtpError(); |
| 2292 | } |
| 2293 | |
| 2294 | TEST_F(VoiceChannelTest, TestOnReadyToSend) { |
| 2295 | Base::TestOnReadyToSend(); |
| 2296 | } |
| 2297 | |
| 2298 | TEST_F(VoiceChannelTest, TestOnReadyToSendWithRtcpMux) { |
| 2299 | Base::TestOnReadyToSendWithRtcpMux(); |
| 2300 | } |
| 2301 | |
| 2302 | // Test that we can play a ringback tone properly. |
| 2303 | TEST_F(VoiceChannelTest, TestRingbackTone) { |
| 2304 | CreateChannels(RTCP, RTCP); |
| 2305 | EXPECT_FALSE(media_channel1_->ringback_tone_play()); |
| 2306 | EXPECT_TRUE(channel1_->SetRingbackTone("RIFF", 4)); |
| 2307 | EXPECT_TRUE(SendInitiate()); |
| 2308 | EXPECT_TRUE(SendAccept()); |
| 2309 | // Play ringback tone, no loop. |
| 2310 | EXPECT_TRUE(channel1_->PlayRingbackTone(0, true, false)); |
| 2311 | EXPECT_EQ(0U, media_channel1_->ringback_tone_ssrc()); |
| 2312 | EXPECT_TRUE(media_channel1_->ringback_tone_play()); |
| 2313 | EXPECT_FALSE(media_channel1_->ringback_tone_loop()); |
| 2314 | // Stop the ringback tone. |
| 2315 | EXPECT_TRUE(channel1_->PlayRingbackTone(0, false, false)); |
| 2316 | EXPECT_FALSE(media_channel1_->ringback_tone_play()); |
| 2317 | // Add a stream. |
| 2318 | EXPECT_TRUE(AddStream1(1)); |
| 2319 | // Play ringback tone, looping, on the new stream. |
| 2320 | EXPECT_TRUE(channel1_->PlayRingbackTone(1, true, true)); |
| 2321 | EXPECT_EQ(1U, media_channel1_->ringback_tone_ssrc()); |
| 2322 | EXPECT_TRUE(media_channel1_->ringback_tone_play()); |
| 2323 | EXPECT_TRUE(media_channel1_->ringback_tone_loop()); |
| 2324 | // Stop the ringback tone. |
| 2325 | EXPECT_TRUE(channel1_->PlayRingbackTone(1, false, false)); |
| 2326 | EXPECT_FALSE(media_channel1_->ringback_tone_play()); |
| 2327 | } |
| 2328 | |
| 2329 | // Test that we can scale the output volume properly for 1:1 calls. |
| 2330 | TEST_F(VoiceChannelTest, TestScaleVolume1to1Call) { |
| 2331 | CreateChannels(RTCP, RTCP); |
| 2332 | EXPECT_TRUE(SendInitiate()); |
| 2333 | EXPECT_TRUE(SendAccept()); |
| 2334 | double left, right; |
| 2335 | |
| 2336 | // Default is (1.0, 1.0). |
| 2337 | EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right)); |
| 2338 | EXPECT_DOUBLE_EQ(1.0, left); |
| 2339 | EXPECT_DOUBLE_EQ(1.0, right); |
| 2340 | // invalid ssrc. |
| 2341 | EXPECT_FALSE(media_channel1_->GetOutputScaling(3, &left, &right)); |
| 2342 | |
| 2343 | // Set scale to (1.5, 0.5). |
| 2344 | EXPECT_TRUE(channel1_->SetOutputScaling(0, 1.5, 0.5)); |
| 2345 | EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right)); |
| 2346 | EXPECT_DOUBLE_EQ(1.5, left); |
| 2347 | EXPECT_DOUBLE_EQ(0.5, right); |
| 2348 | |
| 2349 | // Set scale to (0, 0). |
| 2350 | EXPECT_TRUE(channel1_->SetOutputScaling(0, 0.0, 0.0)); |
| 2351 | EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right)); |
| 2352 | EXPECT_DOUBLE_EQ(0.0, left); |
| 2353 | EXPECT_DOUBLE_EQ(0.0, right); |
| 2354 | } |
| 2355 | |
| 2356 | // Test that we can scale the output volume properly for multiway calls. |
| 2357 | TEST_F(VoiceChannelTest, TestScaleVolumeMultiwayCall) { |
| 2358 | CreateChannels(RTCP, RTCP); |
| 2359 | EXPECT_TRUE(SendInitiate()); |
| 2360 | EXPECT_TRUE(SendAccept()); |
| 2361 | EXPECT_TRUE(AddStream1(1)); |
| 2362 | EXPECT_TRUE(AddStream1(2)); |
| 2363 | |
| 2364 | double left, right; |
| 2365 | // Default is (1.0, 1.0). |
| 2366 | EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right)); |
| 2367 | EXPECT_DOUBLE_EQ(1.0, left); |
| 2368 | EXPECT_DOUBLE_EQ(1.0, right); |
| 2369 | EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right)); |
| 2370 | EXPECT_DOUBLE_EQ(1.0, left); |
| 2371 | EXPECT_DOUBLE_EQ(1.0, right); |
| 2372 | EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right)); |
| 2373 | EXPECT_DOUBLE_EQ(1.0, left); |
| 2374 | EXPECT_DOUBLE_EQ(1.0, right); |
| 2375 | // invalid ssrc. |
| 2376 | EXPECT_FALSE(media_channel1_->GetOutputScaling(3, &left, &right)); |
| 2377 | |
| 2378 | // Set scale to (1.5, 0.5) for ssrc = 1. |
| 2379 | EXPECT_TRUE(channel1_->SetOutputScaling(1, 1.5, 0.5)); |
| 2380 | EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right)); |
| 2381 | EXPECT_DOUBLE_EQ(1.5, left); |
| 2382 | EXPECT_DOUBLE_EQ(0.5, right); |
| 2383 | EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right)); |
| 2384 | EXPECT_DOUBLE_EQ(1.0, left); |
| 2385 | EXPECT_DOUBLE_EQ(1.0, right); |
| 2386 | EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right)); |
| 2387 | EXPECT_DOUBLE_EQ(1.0, left); |
| 2388 | EXPECT_DOUBLE_EQ(1.0, right); |
| 2389 | |
| 2390 | // Set scale to (0, 0) for all ssrcs. |
| 2391 | EXPECT_TRUE(channel1_->SetOutputScaling(0, 0.0, 0.0)); |
| 2392 | EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right)); |
| 2393 | EXPECT_DOUBLE_EQ(0.0, left); |
| 2394 | EXPECT_DOUBLE_EQ(0.0, right); |
| 2395 | EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right)); |
| 2396 | EXPECT_DOUBLE_EQ(0.0, left); |
| 2397 | EXPECT_DOUBLE_EQ(0.0, right); |
| 2398 | EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right)); |
| 2399 | EXPECT_DOUBLE_EQ(0.0, left); |
| 2400 | EXPECT_DOUBLE_EQ(0.0, right); |
| 2401 | } |
| 2402 | |
| 2403 | TEST_F(VoiceChannelTest, SendSsrcMuxToSsrcMux) { |
| 2404 | Base::SendSsrcMuxToSsrcMux(); |
| 2405 | } |
| 2406 | |
| 2407 | TEST_F(VoiceChannelTest, SendSsrcMuxToSsrcMuxWithRtcpMux) { |
| 2408 | Base::SendSsrcMuxToSsrcMuxWithRtcpMux(); |
| 2409 | } |
| 2410 | |
| 2411 | TEST_F(VoiceChannelTest, TestSetChannelOptions) { |
| 2412 | TestSetChannelOptions(); |
| 2413 | } |
| 2414 | |
| 2415 | // VideoChannelTest |
| 2416 | TEST_F(VideoChannelTest, TestInit) { |
| 2417 | Base::TestInit(); |
| 2418 | } |
| 2419 | |
| 2420 | TEST_F(VideoChannelTest, TestSetContents) { |
| 2421 | Base::TestSetContents(); |
| 2422 | } |
| 2423 | |
| 2424 | TEST_F(VideoChannelTest, TestSetContentsNullOffer) { |
| 2425 | Base::TestSetContentsNullOffer(); |
| 2426 | } |
| 2427 | |
| 2428 | TEST_F(VideoChannelTest, TestSetContentsRtcpMux) { |
| 2429 | Base::TestSetContentsRtcpMux(); |
| 2430 | } |
| 2431 | |
| 2432 | TEST_F(VideoChannelTest, TestSetContentsRtcpMuxWithPrAnswer) { |
| 2433 | Base::TestSetContentsRtcpMux(); |
| 2434 | } |
| 2435 | |
| 2436 | TEST_F(VideoChannelTest, TestSetContentsVideoOptions) { |
| 2437 | Base::TestSetContentsVideoOptions(); |
| 2438 | } |
| 2439 | |
| 2440 | TEST_F(VideoChannelTest, TestSetRemoteContentUpdate) { |
| 2441 | Base::TestSetRemoteContentUpdate(); |
| 2442 | } |
| 2443 | |
| 2444 | TEST_F(VideoChannelTest, TestStreams) { |
| 2445 | Base::TestStreams(); |
| 2446 | } |
| 2447 | |
| 2448 | TEST_F(VideoChannelTest, TestScreencastEvents) { |
| 2449 | const int kTimeoutMs = 500; |
| 2450 | TestInit(); |
| 2451 | FakeScreenCaptureFactory* screencapture_factory = |
| 2452 | new FakeScreenCaptureFactory(); |
| 2453 | channel1_->SetScreenCaptureFactory(screencapture_factory); |
| 2454 | cricket::ScreencastEventCatcher catcher; |
| 2455 | channel1_->SignalScreencastWindowEvent.connect( |
| 2456 | &catcher, |
| 2457 | &cricket::ScreencastEventCatcher::OnEvent); |
| 2458 | EXPECT_TRUE(channel1_->AddScreencast(0, ScreencastId(WindowId(0))) != NULL); |
| 2459 | ASSERT_TRUE(screencapture_factory->window_capturer() != NULL); |
| 2460 | EXPECT_EQ_WAIT(cricket::CS_STOPPED, screencapture_factory->capture_state(), |
| 2461 | kTimeoutMs); |
| 2462 | screencapture_factory->window_capturer()->SignalStateChange( |
| 2463 | screencapture_factory->window_capturer(), cricket::CS_PAUSED); |
| 2464 | EXPECT_EQ_WAIT(talk_base::WE_MINIMIZE, catcher.event(), kTimeoutMs); |
| 2465 | screencapture_factory->window_capturer()->SignalStateChange( |
| 2466 | screencapture_factory->window_capturer(), cricket::CS_RUNNING); |
| 2467 | EXPECT_EQ_WAIT(talk_base::WE_RESTORE, catcher.event(), kTimeoutMs); |
| 2468 | screencapture_factory->window_capturer()->SignalStateChange( |
| 2469 | screencapture_factory->window_capturer(), cricket::CS_STOPPED); |
| 2470 | EXPECT_EQ_WAIT(talk_base::WE_CLOSE, catcher.event(), kTimeoutMs); |
| 2471 | EXPECT_TRUE(channel1_->RemoveScreencast(0)); |
| 2472 | ASSERT_TRUE(screencapture_factory->window_capturer() == NULL); |
| 2473 | } |
| 2474 | |
| 2475 | TEST_F(VideoChannelTest, TestUpdateStreamsInLocalContent) { |
| 2476 | Base::TestUpdateStreamsInLocalContent(); |
| 2477 | } |
| 2478 | |
| 2479 | TEST_F(VideoChannelTest, TestUpdateRemoteStreamsInContent) { |
| 2480 | Base::TestUpdateStreamsInRemoteContent(); |
| 2481 | } |
| 2482 | |
| 2483 | TEST_F(VideoChannelTest, TestChangeStreamParamsInContent) { |
| 2484 | Base::TestChangeStreamParamsInContent(); |
| 2485 | } |
| 2486 | |
| 2487 | TEST_F(VideoChannelTest, TestPlayoutAndSendingStates) { |
| 2488 | Base::TestPlayoutAndSendingStates(); |
| 2489 | } |
| 2490 | |
| 2491 | TEST_F(VideoChannelTest, TestMuteStream) { |
| 2492 | Base::TestMuteStream(); |
| 2493 | } |
| 2494 | |
| 2495 | TEST_F(VideoChannelTest, TestMediaContentDirection) { |
| 2496 | Base::TestMediaContentDirection(); |
| 2497 | } |
| 2498 | |
| 2499 | TEST_F(VideoChannelTest, TestCallSetup) { |
| 2500 | Base::TestCallSetup(); |
| 2501 | } |
| 2502 | |
| 2503 | TEST_F(VideoChannelTest, TestCallTeardownRtcpMux) { |
| 2504 | Base::TestCallTeardownRtcpMux(); |
| 2505 | } |
| 2506 | |
| 2507 | TEST_F(VideoChannelTest, SendRtpToRtp) { |
| 2508 | Base::SendRtpToRtp(); |
| 2509 | } |
| 2510 | |
| 2511 | TEST_F(VideoChannelTest, SendNoRtcpToNoRtcp) { |
| 2512 | Base::SendNoRtcpToNoRtcp(); |
| 2513 | } |
| 2514 | |
| 2515 | TEST_F(VideoChannelTest, SendNoRtcpToRtcp) { |
| 2516 | Base::SendNoRtcpToRtcp(); |
| 2517 | } |
| 2518 | |
| 2519 | TEST_F(VideoChannelTest, SendRtcpToNoRtcp) { |
| 2520 | Base::SendRtcpToNoRtcp(); |
| 2521 | } |
| 2522 | |
| 2523 | TEST_F(VideoChannelTest, SendRtcpToRtcp) { |
| 2524 | Base::SendRtcpToRtcp(); |
| 2525 | } |
| 2526 | |
| 2527 | TEST_F(VideoChannelTest, SendRtcpMuxToRtcp) { |
| 2528 | Base::SendRtcpMuxToRtcp(); |
| 2529 | } |
| 2530 | |
| 2531 | TEST_F(VideoChannelTest, SendRtcpMuxToRtcpMux) { |
| 2532 | Base::SendRtcpMuxToRtcpMux(); |
| 2533 | } |
| 2534 | |
| 2535 | TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcp) { |
| 2536 | Base::SendEarlyRtcpMuxToRtcp(); |
| 2537 | } |
| 2538 | |
| 2539 | TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcpMux) { |
| 2540 | Base::SendEarlyRtcpMuxToRtcpMux(); |
| 2541 | } |
| 2542 | |
| 2543 | TEST_F(VideoChannelTest, SendSrtpToSrtp) { |
| 2544 | Base::SendSrtpToSrtp(); |
| 2545 | } |
| 2546 | |
| 2547 | TEST_F(VideoChannelTest, SendSrtpToRtp) { |
| 2548 | Base::SendSrtpToSrtp(); |
| 2549 | } |
| 2550 | |
| 2551 | TEST_F(VideoChannelTest, SendDtlsSrtpToSrtp) { |
| 2552 | MAYBE_SKIP_TEST(HaveDtlsSrtp); |
| 2553 | Base::SendSrtpToSrtp(DTLS, 0); |
| 2554 | } |
| 2555 | |
| 2556 | TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtp) { |
| 2557 | MAYBE_SKIP_TEST(HaveDtlsSrtp); |
| 2558 | Base::SendSrtpToSrtp(DTLS, DTLS); |
| 2559 | } |
| 2560 | |
| 2561 | TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) { |
| 2562 | MAYBE_SKIP_TEST(HaveDtlsSrtp); |
| 2563 | Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX); |
| 2564 | } |
| 2565 | |
| 2566 | TEST_F(VideoChannelTest, SendSrtcpMux) { |
| 2567 | Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX); |
| 2568 | } |
| 2569 | |
| 2570 | TEST_F(VideoChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) { |
| 2571 | Base::SendEarlyMediaUsingRtcpMuxSrtp(); |
| 2572 | } |
| 2573 | |
| 2574 | TEST_F(VideoChannelTest, SendRtpToRtpOnThread) { |
| 2575 | Base::SendRtpToRtpOnThread(); |
| 2576 | } |
| 2577 | |
| 2578 | TEST_F(VideoChannelTest, SendSrtpToSrtpOnThread) { |
| 2579 | Base::SendSrtpToSrtpOnThread(); |
| 2580 | } |
| 2581 | |
| 2582 | TEST_F(VideoChannelTest, SendWithWritabilityLoss) { |
| 2583 | Base::SendWithWritabilityLoss(); |
| 2584 | } |
| 2585 | |
| 2586 | TEST_F(VideoChannelTest, TestMediaMonitor) { |
| 2587 | Base::TestMediaMonitor(); |
| 2588 | } |
| 2589 | |
| 2590 | TEST_F(VideoChannelTest, TestMediaSinks) { |
| 2591 | Base::TestMediaSinks(); |
| 2592 | } |
| 2593 | |
| 2594 | TEST_F(VideoChannelTest, TestSetContentFailure) { |
| 2595 | Base::TestSetContentFailure(); |
| 2596 | } |
| 2597 | |
| 2598 | TEST_F(VideoChannelTest, TestSendTwoOffers) { |
| 2599 | Base::TestSendTwoOffers(); |
| 2600 | } |
| 2601 | |
| 2602 | TEST_F(VideoChannelTest, TestReceiveTwoOffers) { |
| 2603 | Base::TestReceiveTwoOffers(); |
| 2604 | } |
| 2605 | |
| 2606 | TEST_F(VideoChannelTest, TestSendPrAnswer) { |
| 2607 | Base::TestSendPrAnswer(); |
| 2608 | } |
| 2609 | |
| 2610 | TEST_F(VideoChannelTest, TestReceivePrAnswer) { |
| 2611 | Base::TestReceivePrAnswer(); |
| 2612 | } |
| 2613 | |
| 2614 | TEST_F(VideoChannelTest, TestFlushRtcp) { |
| 2615 | Base::TestFlushRtcp(); |
| 2616 | } |
| 2617 | |
| 2618 | TEST_F(VideoChannelTest, SendSsrcMuxToSsrcMux) { |
| 2619 | Base::SendSsrcMuxToSsrcMux(); |
| 2620 | } |
| 2621 | |
| 2622 | TEST_F(VideoChannelTest, SendSsrcMuxToSsrcMuxWithRtcpMux) { |
| 2623 | Base::SendSsrcMuxToSsrcMuxWithRtcpMux(); |
| 2624 | } |
| 2625 | |
| 2626 | // TODO(gangji): Add VideoChannelTest.TestChangeStateError. |
| 2627 | |
| 2628 | TEST_F(VideoChannelTest, TestSrtpError) { |
| 2629 | Base::TestSrtpError(); |
| 2630 | } |
| 2631 | |
| 2632 | TEST_F(VideoChannelTest, TestOnReadyToSend) { |
| 2633 | Base::TestOnReadyToSend(); |
| 2634 | } |
| 2635 | |
| 2636 | TEST_F(VideoChannelTest, TestOnReadyToSendWithRtcpMux) { |
| 2637 | Base::TestOnReadyToSendWithRtcpMux(); |
| 2638 | } |
| 2639 | |
| 2640 | TEST_F(VideoChannelTest, TestApplyViewRequest) { |
| 2641 | CreateChannels(0, 0); |
| 2642 | cricket::StreamParams stream2; |
| 2643 | stream2.id = "stream2"; |
| 2644 | stream2.ssrcs.push_back(2222); |
| 2645 | local_media_content1_.AddStream(stream2); |
| 2646 | |
| 2647 | EXPECT_TRUE(SendInitiate()); |
| 2648 | EXPECT_TRUE(SendAccept()); |
| 2649 | |
| 2650 | cricket::VideoFormat send_format; |
| 2651 | EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format)); |
| 2652 | EXPECT_EQ(640, send_format.width); |
| 2653 | EXPECT_EQ(400, send_format.height); |
| 2654 | EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), send_format.interval); |
| 2655 | |
| 2656 | cricket::ViewRequest request; |
| 2657 | // stream1: 320x200x15; stream2: 0x0x0 |
| 2658 | request.static_video_views.push_back(cricket::StaticVideoView( |
| 2659 | cricket::StreamSelector(kSsrc1), 320, 200, 15)); |
| 2660 | EXPECT_TRUE(channel1_->ApplyViewRequest(request)); |
| 2661 | EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format)); |
| 2662 | EXPECT_EQ(320, send_format.width); |
| 2663 | EXPECT_EQ(200, send_format.height); |
| 2664 | EXPECT_EQ(cricket::VideoFormat::FpsToInterval(15), send_format.interval); |
| 2665 | EXPECT_TRUE(media_channel1_->GetSendStreamFormat(2222, &send_format)); |
| 2666 | EXPECT_EQ(0, send_format.width); |
| 2667 | EXPECT_EQ(0, send_format.height); |
| 2668 | |
| 2669 | // stream1: 160x100x8; stream2: 0x0x0 |
| 2670 | request.static_video_views.clear(); |
| 2671 | request.static_video_views.push_back(cricket::StaticVideoView( |
| 2672 | cricket::StreamSelector(kSsrc1), 160, 100, 8)); |
| 2673 | EXPECT_TRUE(channel1_->ApplyViewRequest(request)); |
| 2674 | EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format)); |
| 2675 | EXPECT_EQ(160, send_format.width); |
| 2676 | EXPECT_EQ(100, send_format.height); |
| 2677 | EXPECT_EQ(cricket::VideoFormat::FpsToInterval(8), send_format.interval); |
| 2678 | |
| 2679 | // stream1: 0x0x0; stream2: 640x400x30 |
| 2680 | request.static_video_views.clear(); |
| 2681 | request.static_video_views.push_back(cricket::StaticVideoView( |
| 2682 | cricket::StreamSelector("", stream2.id), 640, 400, 30)); |
| 2683 | EXPECT_TRUE(channel1_->ApplyViewRequest(request)); |
| 2684 | EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format)); |
| 2685 | EXPECT_EQ(0, send_format.width); |
| 2686 | EXPECT_EQ(0, send_format.height); |
| 2687 | EXPECT_TRUE(media_channel1_->GetSendStreamFormat(2222, &send_format)); |
| 2688 | EXPECT_EQ(640, send_format.width); |
| 2689 | EXPECT_EQ(400, send_format.height); |
| 2690 | EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), send_format.interval); |
| 2691 | |
| 2692 | // stream1: 0x0x0; stream2: 0x0x0 |
| 2693 | request.static_video_views.clear(); |
| 2694 | EXPECT_TRUE(channel1_->ApplyViewRequest(request)); |
| 2695 | EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format)); |
| 2696 | EXPECT_EQ(0, send_format.width); |
| 2697 | EXPECT_EQ(0, send_format.height); |
| 2698 | } |
| 2699 | |
| 2700 | TEST_F(VideoChannelTest, TestSetChannelOptions) { |
| 2701 | TestSetChannelOptions(); |
| 2702 | } |
| 2703 | |
| 2704 | |
| 2705 | // DataChannelTest |
| 2706 | |
| 2707 | class DataChannelTest |
| 2708 | : public ChannelTest<DataTraits> { |
| 2709 | public: |
| 2710 | typedef ChannelTest<DataTraits> |
| 2711 | Base; |
| 2712 | DataChannelTest() : Base(kDataPacket, sizeof(kDataPacket), |
| 2713 | kRtcpReport, sizeof(kRtcpReport)) { |
| 2714 | } |
| 2715 | }; |
| 2716 | |
| 2717 | // Override to avoid engine channel parameter. |
| 2718 | template<> |
| 2719 | cricket::DataChannel* ChannelTest<DataTraits>::CreateChannel( |
| 2720 | talk_base::Thread* thread, cricket::MediaEngineInterface* engine, |
| 2721 | cricket::FakeDataMediaChannel* ch, cricket::BaseSession* session, |
| 2722 | bool rtcp) { |
| 2723 | cricket::DataChannel* channel = new cricket::DataChannel( |
| 2724 | thread, ch, session, cricket::CN_DATA, rtcp); |
| 2725 | if (!channel->Init()) { |
| 2726 | delete channel; |
| 2727 | channel = NULL; |
| 2728 | } |
| 2729 | return channel; |
| 2730 | } |
| 2731 | |
| 2732 | template<> |
| 2733 | void ChannelTest<DataTraits>::CreateContent( |
| 2734 | int flags, |
| 2735 | const cricket::AudioCodec& audio_codec, |
| 2736 | const cricket::VideoCodec& video_codec, |
| 2737 | cricket::DataContentDescription* data) { |
| 2738 | data->AddCodec(kGoogleDataCodec); |
| 2739 | data->set_rtcp_mux((flags & RTCP_MUX) != 0); |
| 2740 | if (flags & SECURE) { |
| 2741 | data->AddCrypto(cricket::CryptoParams( |
| 2742 | 1, cricket::CS_AES_CM_128_HMAC_SHA1_32, |
| 2743 | "inline:" + talk_base::CreateRandomString(40), "")); |
| 2744 | } |
| 2745 | } |
| 2746 | |
| 2747 | template<> |
| 2748 | void ChannelTest<DataTraits>::CopyContent( |
| 2749 | const cricket::DataContentDescription& source, |
| 2750 | cricket::DataContentDescription* data) { |
| 2751 | *data = source; |
| 2752 | } |
| 2753 | |
| 2754 | template<> |
| 2755 | bool ChannelTest<DataTraits>::CodecMatches(const cricket::DataCodec& c1, |
| 2756 | const cricket::DataCodec& c2) { |
| 2757 | return c1.name == c2.name; |
| 2758 | } |
| 2759 | |
| 2760 | template<> |
| 2761 | void ChannelTest<DataTraits>::AddLegacyStreamInContent( |
| 2762 | uint32 ssrc, int flags, cricket::DataContentDescription* data) { |
| 2763 | data->AddLegacyStream(ssrc); |
| 2764 | } |
| 2765 | |
| 2766 | TEST_F(DataChannelTest, TestInit) { |
| 2767 | Base::TestInit(); |
| 2768 | EXPECT_FALSE(media_channel1_->IsStreamMuted(0)); |
| 2769 | } |
| 2770 | |
| 2771 | TEST_F(DataChannelTest, TestSetContents) { |
| 2772 | Base::TestSetContents(); |
| 2773 | } |
| 2774 | |
| 2775 | TEST_F(DataChannelTest, TestSetContentsNullOffer) { |
| 2776 | Base::TestSetContentsNullOffer(); |
| 2777 | } |
| 2778 | |
| 2779 | TEST_F(DataChannelTest, TestSetContentsRtcpMux) { |
| 2780 | Base::TestSetContentsRtcpMux(); |
| 2781 | } |
| 2782 | |
| 2783 | TEST_F(DataChannelTest, TestSetRemoteContentUpdate) { |
| 2784 | Base::TestSetRemoteContentUpdate(); |
| 2785 | } |
| 2786 | |
| 2787 | TEST_F(DataChannelTest, TestStreams) { |
| 2788 | Base::TestStreams(); |
| 2789 | } |
| 2790 | |
| 2791 | TEST_F(DataChannelTest, TestUpdateStreamsInLocalContent) { |
| 2792 | Base::TestUpdateStreamsInLocalContent(); |
| 2793 | } |
| 2794 | |
| 2795 | TEST_F(DataChannelTest, TestUpdateRemoteStreamsInContent) { |
| 2796 | Base::TestUpdateStreamsInRemoteContent(); |
| 2797 | } |
| 2798 | |
| 2799 | TEST_F(DataChannelTest, TestChangeStreamParamsInContent) { |
| 2800 | Base::TestChangeStreamParamsInContent(); |
| 2801 | } |
| 2802 | |
| 2803 | TEST_F(DataChannelTest, TestPlayoutAndSendingStates) { |
| 2804 | Base::TestPlayoutAndSendingStates(); |
| 2805 | } |
| 2806 | |
| 2807 | TEST_F(DataChannelTest, TestMediaContentDirection) { |
| 2808 | Base::TestMediaContentDirection(); |
| 2809 | } |
| 2810 | |
| 2811 | TEST_F(DataChannelTest, TestCallSetup) { |
| 2812 | Base::TestCallSetup(); |
| 2813 | } |
| 2814 | |
| 2815 | TEST_F(DataChannelTest, TestCallTeardownRtcpMux) { |
| 2816 | Base::TestCallTeardownRtcpMux(); |
| 2817 | } |
| 2818 | |
| 2819 | TEST_F(DataChannelTest, TestOnReadyToSend) { |
| 2820 | Base::TestOnReadyToSend(); |
| 2821 | } |
| 2822 | |
| 2823 | TEST_F(DataChannelTest, TestOnReadyToSendWithRtcpMux) { |
| 2824 | Base::TestOnReadyToSendWithRtcpMux(); |
| 2825 | } |
| 2826 | |
| 2827 | TEST_F(DataChannelTest, SendRtpToRtp) { |
| 2828 | Base::SendRtpToRtp(); |
| 2829 | } |
| 2830 | |
| 2831 | TEST_F(DataChannelTest, SendNoRtcpToNoRtcp) { |
| 2832 | Base::SendNoRtcpToNoRtcp(); |
| 2833 | } |
| 2834 | |
| 2835 | TEST_F(DataChannelTest, SendNoRtcpToRtcp) { |
| 2836 | Base::SendNoRtcpToRtcp(); |
| 2837 | } |
| 2838 | |
| 2839 | TEST_F(DataChannelTest, SendRtcpToNoRtcp) { |
| 2840 | Base::SendRtcpToNoRtcp(); |
| 2841 | } |
| 2842 | |
| 2843 | TEST_F(DataChannelTest, SendRtcpToRtcp) { |
| 2844 | Base::SendRtcpToRtcp(); |
| 2845 | } |
| 2846 | |
| 2847 | TEST_F(DataChannelTest, SendRtcpMuxToRtcp) { |
| 2848 | Base::SendRtcpMuxToRtcp(); |
| 2849 | } |
| 2850 | |
| 2851 | TEST_F(DataChannelTest, SendRtcpMuxToRtcpMux) { |
| 2852 | Base::SendRtcpMuxToRtcpMux(); |
| 2853 | } |
| 2854 | |
| 2855 | TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcp) { |
| 2856 | Base::SendEarlyRtcpMuxToRtcp(); |
| 2857 | } |
| 2858 | |
| 2859 | TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcpMux) { |
| 2860 | Base::SendEarlyRtcpMuxToRtcpMux(); |
| 2861 | } |
| 2862 | |
| 2863 | TEST_F(DataChannelTest, SendSrtpToSrtp) { |
| 2864 | Base::SendSrtpToSrtp(); |
| 2865 | } |
| 2866 | |
| 2867 | TEST_F(DataChannelTest, SendSrtpToRtp) { |
| 2868 | Base::SendSrtpToSrtp(); |
| 2869 | } |
| 2870 | |
| 2871 | TEST_F(DataChannelTest, SendSrtcpMux) { |
| 2872 | Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX); |
| 2873 | } |
| 2874 | |
| 2875 | TEST_F(DataChannelTest, SendRtpToRtpOnThread) { |
| 2876 | Base::SendRtpToRtpOnThread(); |
| 2877 | } |
| 2878 | |
| 2879 | TEST_F(DataChannelTest, SendSrtpToSrtpOnThread) { |
| 2880 | Base::SendSrtpToSrtpOnThread(); |
| 2881 | } |
| 2882 | |
| 2883 | TEST_F(DataChannelTest, SendWithWritabilityLoss) { |
| 2884 | Base::SendWithWritabilityLoss(); |
| 2885 | } |
| 2886 | |
| 2887 | TEST_F(DataChannelTest, TestMediaMonitor) { |
| 2888 | Base::TestMediaMonitor(); |
| 2889 | } |
| 2890 | |
| 2891 | TEST_F(DataChannelTest, TestSendData) { |
| 2892 | CreateChannels(0, 0); |
| 2893 | EXPECT_TRUE(SendInitiate()); |
| 2894 | EXPECT_TRUE(SendAccept()); |
| 2895 | |
| 2896 | cricket::SendDataParams params; |
| 2897 | params.ssrc = 42; |
| 2898 | unsigned char data[] = { |
| 2899 | 'f', 'o', 'o' |
| 2900 | }; |
| 2901 | talk_base::Buffer payload(data, 3); |
| 2902 | cricket::SendDataResult result; |
| 2903 | ASSERT_TRUE(media_channel1_->SendData(params, payload, &result)); |
| 2904 | EXPECT_EQ(params.ssrc, |
| 2905 | media_channel1_->last_sent_data_params().ssrc); |
| 2906 | EXPECT_EQ("foo", media_channel1_->last_sent_data()); |
| 2907 | } |
| 2908 | |
| 2909 | // TODO(pthatcher): TestSetReceiver? |