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