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