blob: 9fef65ffd1b868de6e98e8c5b6a2d4750290ab0e [file] [log] [blame]
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00001/*
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.org28e20752013-07-10 00:45:36 +000027
henrike@webrtc.org28e20752013-07-10 00:45:36 +000028#include "talk/media/base/fakemediaengine.h"
29#include "talk/media/base/fakertp.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000030#include "talk/media/base/fakescreencapturerfactory.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000031#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"
deadbeefcbecd352015-09-23 11:50:27 -070036#include "webrtc/p2p/base/faketransportcontroller.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000037#include "talk/session/media/channel.h"
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +000038#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.org28e20752013-07-10 00:45:36 +000047
48#define MAYBE_SKIP_TEST(feature) \
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000049 if (!(rtc::SSLStreamAdapter::feature())) { \
henrike@webrtc.org28e20752013-07-10 00:45:36 +000050 LOG(LS_INFO) << "Feature disabled... skipping"; \
51 return; \
52 }
53
54using cricket::CA_OFFER;
55using cricket::CA_PRANSWER;
56using cricket::CA_ANSWER;
57using cricket::CA_UPDATE;
58using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000059using cricket::ScreencastId;
60using cricket::StreamParams;
61using cricket::TransportChannel;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000062using rtc::WindowId;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000063
64static const cricket::AudioCodec kPcmuCodec(0, "PCMU", 64000, 8000, 1, 0);
65static const cricket::AudioCodec kPcmaCodec(8, "PCMA", 64000, 8000, 1, 0);
66static const cricket::AudioCodec kIsacCodec(103, "ISAC", 40000, 16000, 1, 0);
67static const cricket::VideoCodec kH264Codec(97, "H264", 640, 400, 30, 0);
68static const cricket::VideoCodec kH264SvcCodec(99, "H264-SVC", 320, 200, 15, 0);
69static const cricket::DataCodec kGoogleDataCodec(101, "google-data", 0);
70static const uint32 kSsrc1 = 0x1111;
71static const uint32 kSsrc2 = 0x2222;
72static const uint32 kSsrc3 = 0x3333;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +000073static const int kAudioPts[] = {0, 8};
74static const int kVideoPts[] = {97, 99};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075
deadbeefcbecd352015-09-23 11:50:27 -070076template <class ChannelT,
77 class MediaChannelT,
78 class ContentT,
79 class CodecT,
80 class MediaInfoT,
81 class OptionsT>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000082class Traits {
83 public:
84 typedef ChannelT Channel;
85 typedef MediaChannelT MediaChannel;
86 typedef ContentT Content;
87 typedef CodecT Codec;
88 typedef MediaInfoT MediaInfo;
Fredrik Solenbergb071a192015-09-17 16:42:56 +020089 typedef OptionsT Options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000090};
91
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092// 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.
94static const int kEventTimeout = 5000;
95
96class VoiceTraits : public Traits<cricket::VoiceChannel,
97 cricket::FakeVoiceMediaChannel,
98 cricket::AudioContentDescription,
99 cricket::AudioCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200100 cricket::VoiceMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -0700101 cricket::AudioOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102
103class VideoTraits : public Traits<cricket::VideoChannel,
104 cricket::FakeVideoMediaChannel,
105 cricket::VideoContentDescription,
106 cricket::VideoCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200107 cricket::VideoMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -0700108 cricket::VideoOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000109
110class DataTraits : public Traits<cricket::DataChannel,
111 cricket::FakeDataMediaChannel,
112 cricket::DataContentDescription,
113 cricket::DataCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200114 cricket::DataMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -0700115 cricket::DataOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000116
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000117rtc::StreamInterface* Open(const std::string& path) {
118 return rtc::Filesystem::OpenFile(
119 rtc::Pathname(path), "wb");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000120}
121
122// Base class for Voice/VideoChannel tests
123template<class T>
124class 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öm34fbfff2015-09-24 19:20:30 +0200129 ChannelTest(bool verify_playout,
130 const uint8* rtp_data,
deadbeefcbecd352015-09-23 11:50:27 -0700131 int rtp_len,
132 const uint8* rtcp_data,
133 int rtcp_len)
Peter Boström34fbfff2015-09-24 19:20:30 +0200134 : verify_playout_(verify_playout),
135 transport_controller1_(cricket::ICEROLE_CONTROLLING),
deadbeefcbecd352015-09-23 11:50:27 -0700136 transport_controller2_(cricket::ICEROLE_CONTROLLED),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000137 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_(),
142 media_info_callbacks2_(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000143 ssrc_(0),
deadbeefcbecd352015-09-23 11:50:27 -0700144 error_(T::MediaChannel::ERROR_NONE) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000145
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000146 void CreateChannels(int flags1, int flags2) {
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200147 CreateChannels(new typename T::MediaChannel(NULL, typename T::Options()),
148 new typename T::MediaChannel(NULL, typename T::Options()),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000149 flags1, flags2, rtc::Thread::Current());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000150 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000151 void CreateChannels(
152 typename T::MediaChannel* ch1, typename T::MediaChannel* ch2,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000153 int flags1, int flags2, rtc::Thread* thread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000154 media_channel1_ = ch1;
155 media_channel2_ = ch2;
deadbeefcbecd352015-09-23 11:50:27 -0700156 channel1_.reset(CreateChannel(thread, &media_engine_, ch1,
157 &transport_controller1_,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000158 (flags1 & RTCP) != 0));
deadbeefcbecd352015-09-23 11:50:27 -0700159 channel2_.reset(CreateChannel(thread, &media_engine_, ch2,
160 &transport_controller2_,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000161 (flags2 & RTCP) != 0));
162 channel1_->SignalMediaMonitor.connect(
163 this, &ChannelTest<T>::OnMediaMonitor);
164 channel2_->SignalMediaMonitor.connect(
165 this, &ChannelTest<T>::OnMediaMonitor);
166 channel1_->SignalMediaError.connect(
167 this, &ChannelTest<T>::OnMediaChannelError);
168 channel2_->SignalMediaError.connect(
169 this, &ChannelTest<T>::OnMediaChannelError);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000170 if ((flags1 & DTLS) && (flags2 & DTLS)) {
171 flags1 = (flags1 & ~SECURE);
172 flags2 = (flags2 & ~SECURE);
173 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000174 CreateContent(flags1, kPcmuCodec, kH264Codec,
175 &local_media_content1_);
176 CreateContent(flags2, kPcmuCodec, kH264Codec,
177 &local_media_content2_);
178 CopyContent(local_media_content1_, &remote_media_content1_);
179 CopyContent(local_media_content2_, &remote_media_content2_);
180
181 if (flags1 & DTLS) {
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200182 // Confirmed to work with KT_RSA and KT_ECDSA.
deadbeefcbecd352015-09-23 11:50:27 -0700183 transport_controller1_.SetLocalCertificate(rtc::RTCCertificate::Create(
184 rtc::scoped_ptr<rtc::SSLIdentity>(
185 rtc::SSLIdentity::Generate("session1", rtc::KT_DEFAULT))
186 .Pass()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000187 }
188 if (flags2 & DTLS) {
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200189 // Confirmed to work with KT_RSA and KT_ECDSA.
deadbeefcbecd352015-09-23 11:50:27 -0700190 transport_controller2_.SetLocalCertificate(rtc::RTCCertificate::Create(
191 rtc::scoped_ptr<rtc::SSLIdentity>(
192 rtc::SSLIdentity::Generate("session2", rtc::KT_DEFAULT))
193 .Pass()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000194 }
195
196 // Add stream information (SSRC) to the local content but not to the remote
197 // content. This means that we per default know the SSRC of what we send but
198 // not what we receive.
199 AddLegacyStreamInContent(kSsrc1, flags1, &local_media_content1_);
200 AddLegacyStreamInContent(kSsrc2, flags2, &local_media_content2_);
201
202 // If SSRC_MUX is used we also need to know the SSRC of the incoming stream.
203 if (flags1 & SSRC_MUX) {
204 AddLegacyStreamInContent(kSsrc1, flags1, &remote_media_content1_);
205 }
206 if (flags2 & SSRC_MUX) {
207 AddLegacyStreamInContent(kSsrc2, flags2, &remote_media_content2_);
208 }
209 }
deadbeefcbecd352015-09-23 11:50:27 -0700210 typename T::Channel* CreateChannel(
211 rtc::Thread* thread,
212 cricket::MediaEngineInterface* engine,
213 typename T::MediaChannel* ch,
214 cricket::TransportController* transport_controller,
215 bool rtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000216 typename T::Channel* channel = new typename T::Channel(
deadbeefcbecd352015-09-23 11:50:27 -0700217 thread, engine, ch, transport_controller, cricket::CN_AUDIO, rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000218 if (!channel->Init()) {
219 delete channel;
220 channel = NULL;
221 }
222 return channel;
223 }
224
225 bool SendInitiate() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000226 bool result = channel1_->SetLocalContent(&local_media_content1_,
227 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000228 if (result) {
229 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000230 result = channel2_->SetRemoteContent(&remote_media_content1_,
231 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000232 if (result) {
deadbeefcbecd352015-09-23 11:50:27 -0700233 transport_controller1_.Connect(&transport_controller2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000234
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000235 result = channel2_->SetLocalContent(&local_media_content2_,
236 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000237 }
238 }
239 return result;
240 }
241
242 bool SendAccept() {
243 channel2_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000244 return channel1_->SetRemoteContent(&remote_media_content2_,
245 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000246 }
247
248 bool SendOffer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000249 bool result = channel1_->SetLocalContent(&local_media_content1_,
250 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000251 if (result) {
252 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000253 result = channel2_->SetRemoteContent(&remote_media_content1_,
254 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000255 }
256 return result;
257 }
258
259 bool SendProvisionalAnswer() {
260 bool result = channel2_->SetLocalContent(&local_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000261 CA_PRANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000262 if (result) {
263 channel2_->Enable(true);
264 result = channel1_->SetRemoteContent(&remote_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000265 CA_PRANSWER, NULL);
deadbeefcbecd352015-09-23 11:50:27 -0700266 transport_controller1_.Connect(&transport_controller2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000267 }
268 return result;
269 }
270
271 bool SendFinalAnswer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000272 bool result = channel2_->SetLocalContent(&local_media_content2_,
273 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000274 if (result)
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000275 result = channel1_->SetRemoteContent(&remote_media_content2_,
276 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000277 return result;
278 }
279
280 bool SendTerminate() {
281 channel1_.reset();
282 channel2_.reset();
283 return true;
284 }
285
286 bool AddStream1(int id) {
287 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
288 }
289 bool RemoveStream1(int id) {
290 return channel1_->RemoveRecvStream(id);
291 }
292
deadbeefcbecd352015-09-23 11:50:27 -0700293 // Calling "_w" method here is ok since we only use one thread for this test
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000294 cricket::FakeTransport* GetTransport1() {
deadbeefcbecd352015-09-23 11:50:27 -0700295 return transport_controller1_.GetTransport_w(channel1_->content_name());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000296 }
297 cricket::FakeTransport* GetTransport2() {
deadbeefcbecd352015-09-23 11:50:27 -0700298 return transport_controller2_.GetTransport_w(channel2_->content_name());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000299 }
300
301 bool SendRtp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000302 return media_channel1_->SendRtp(rtp_packet_.c_str(),
303 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000304 }
305 bool SendRtp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000306 return media_channel2_->SendRtp(rtp_packet_.c_str(),
307 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000308 }
309 bool SendRtcp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000310 return media_channel1_->SendRtcp(rtcp_packet_.c_str(),
311 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000312 }
313 bool SendRtcp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000314 return media_channel2_->SendRtcp(rtcp_packet_.c_str(),
315 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000316 }
317 // Methods to send custom data.
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000318 bool SendCustomRtp1(uint32 ssrc, int sequence_number, int pl_type = -1) {
319 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000320 return media_channel1_->SendRtp(data.c_str(),
321 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000322 }
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000323 bool SendCustomRtp2(uint32 ssrc, int sequence_number, int pl_type = -1) {
324 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000325 return media_channel2_->SendRtp(data.c_str(),
326 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000327 }
328 bool SendCustomRtcp1(uint32 ssrc) {
329 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000330 return media_channel1_->SendRtcp(data.c_str(),
331 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000332 }
333 bool SendCustomRtcp2(uint32 ssrc) {
334 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000335 return media_channel2_->SendRtcp(data.c_str(),
336 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000337 }
338 bool CheckRtp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000339 return media_channel1_->CheckRtp(rtp_packet_.c_str(),
340 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000341 }
342 bool CheckRtp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000343 return media_channel2_->CheckRtp(rtp_packet_.c_str(),
344 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000345 }
346 bool CheckRtcp1() {
347 return media_channel1_->CheckRtcp(rtcp_packet_.c_str(),
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000348 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000349 }
350 bool CheckRtcp2() {
351 return media_channel2_->CheckRtcp(rtcp_packet_.c_str(),
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000352 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000353 }
354 // Methods to check custom data.
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000355 bool CheckCustomRtp1(uint32 ssrc, int sequence_number, int pl_type = -1 ) {
356 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000357 return media_channel1_->CheckRtp(data.c_str(),
358 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000359 }
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000360 bool CheckCustomRtp2(uint32 ssrc, int sequence_number, int pl_type = -1) {
361 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000362 return media_channel2_->CheckRtp(data.c_str(),
363 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000364 }
365 bool CheckCustomRtcp1(uint32 ssrc) {
366 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000367 return media_channel1_->CheckRtcp(data.c_str(),
368 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000369 }
370 bool CheckCustomRtcp2(uint32 ssrc) {
371 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000372 return media_channel2_->CheckRtcp(data.c_str(),
373 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000374 }
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000375 std::string CreateRtpData(uint32 ssrc, int sequence_number, int pl_type) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000376 std::string data(rtp_packet_);
377 // Set SSRC in the rtp packet copy.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000378 rtc::SetBE32(const_cast<char*>(data.c_str()) + 8, ssrc);
379 rtc::SetBE16(const_cast<char*>(data.c_str()) + 2, sequence_number);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000380 if (pl_type >= 0) {
pkasting@chromium.org0e81fdf2015-02-02 23:54:03 +0000381 rtc::Set8(const_cast<char*>(data.c_str()), 1,
382 static_cast<uint8_t>(pl_type));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000383 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000384 return data;
385 }
386 std::string CreateRtcpData(uint32 ssrc) {
387 std::string data(rtcp_packet_);
388 // Set SSRC in the rtcp packet copy.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000389 rtc::SetBE32(const_cast<char*>(data.c_str()) + 4, ssrc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000390 return data;
391 }
392
393 bool CheckNoRtp1() {
394 return media_channel1_->CheckNoRtp();
395 }
396 bool CheckNoRtp2() {
397 return media_channel2_->CheckNoRtp();
398 }
399 bool CheckNoRtcp1() {
400 return media_channel1_->CheckNoRtcp();
401 }
402 bool CheckNoRtcp2() {
403 return media_channel2_->CheckNoRtcp();
404 }
405
406 void CreateContent(int flags,
407 const cricket::AudioCodec& audio_codec,
408 const cricket::VideoCodec& video_codec,
409 typename T::Content* content) {
410 // overridden in specialized classes
411 }
412 void CopyContent(const typename T::Content& source,
413 typename T::Content* content) {
414 // overridden in specialized classes
415 }
416
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000417 // Creates a cricket::SessionDescription with one MediaContent and one stream.
418 // kPcmuCodec is used as audio codec and kH264Codec is used as video codec.
419 cricket::SessionDescription* CreateSessionDescriptionWithStream(uint32 ssrc) {
420 typename T::Content content;
421 cricket::SessionDescription* sdesc = new cricket::SessionDescription();
422 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content);
423 AddLegacyStreamInContent(ssrc, 0, &content);
424 sdesc->AddContent("DUMMY_CONTENT_NAME",
425 cricket::NS_JINGLE_RTP, content.Copy());
426 return sdesc;
427 }
428
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000429 class CallThread : public rtc::SignalThread {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000430 public:
431 typedef bool (ChannelTest<T>::*Method)();
432 CallThread(ChannelTest<T>* obj, Method method, bool* result)
433 : obj_(obj),
434 method_(method),
435 result_(result) {
436 *result = false;
437 }
438 virtual void DoWork() {
439 bool result = (*obj_.*method_)();
440 if (result_) {
441 *result_ = result;
442 }
443 }
444 private:
445 ChannelTest<T>* obj_;
446 Method method_;
447 bool* result_;
448 };
449 void CallOnThread(typename CallThread::Method method, bool* result) {
450 CallThread* thread = new CallThread(this, method, result);
451 thread->Start();
452 thread->Release();
453 }
454
455 void CallOnThreadAndWaitForDone(typename CallThread::Method method,
456 bool* result) {
457 CallThread* thread = new CallThread(this, method, result);
458 thread->Start();
459 thread->Destroy(true);
460 }
461
462 bool CodecMatches(const typename T::Codec& c1, const typename T::Codec& c2) {
463 return false; // overridden in specialized classes
464 }
465
466 void OnMediaMonitor(typename T::Channel* channel,
467 const typename T::MediaInfo& info) {
468 if (channel == channel1_.get()) {
469 media_info_callbacks1_++;
470 } else if (channel == channel2_.get()) {
471 media_info_callbacks2_++;
472 }
473 }
474
475 void OnMediaChannelError(typename T::Channel* channel,
476 uint32 ssrc,
477 typename T::MediaChannel::Error error) {
478 ssrc_ = ssrc;
479 error_ = error;
480 }
481
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000482 void AddLegacyStreamInContent(uint32 ssrc, int flags,
483 typename T::Content* content) {
484 // Base implementation.
485 }
486
487 // Tests that can be used by derived classes.
488
489 // Basic sanity check.
490 void TestInit() {
491 CreateChannels(0, 0);
492 EXPECT_FALSE(channel1_->secure());
493 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200494 if (verify_playout_) {
495 EXPECT_FALSE(media_channel1_->playout());
496 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000497 EXPECT_TRUE(media_channel1_->codecs().empty());
498 EXPECT_TRUE(media_channel1_->recv_streams().empty());
499 EXPECT_TRUE(media_channel1_->rtp_packets().empty());
500 EXPECT_TRUE(media_channel1_->rtcp_packets().empty());
501 }
502
503 // Test that SetLocalContent and SetRemoteContent properly configure
504 // the codecs.
505 void TestSetContents() {
506 CreateChannels(0, 0);
507 typename T::Content content;
508 CreateContent(0, kPcmuCodec, kH264Codec, &content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000509 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000510 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000511 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000512 ASSERT_EQ(1U, media_channel1_->codecs().size());
513 EXPECT_TRUE(CodecMatches(content.codecs()[0],
514 media_channel1_->codecs()[0]));
515 }
516
517 // Test that SetLocalContent and SetRemoteContent properly deals
518 // with an empty offer.
519 void TestSetContentsNullOffer() {
520 CreateChannels(0, 0);
521 typename T::Content content;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000522 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000523 CreateContent(0, kPcmuCodec, kH264Codec, &content);
524 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000525 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000526 ASSERT_EQ(1U, media_channel1_->codecs().size());
527 EXPECT_TRUE(CodecMatches(content.codecs()[0],
528 media_channel1_->codecs()[0]));
529 }
530
531 // Test that SetLocalContent and SetRemoteContent properly set RTCP
532 // mux.
533 void TestSetContentsRtcpMux() {
534 CreateChannels(RTCP, RTCP);
535 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
536 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
537 typename T::Content content;
538 CreateContent(0, kPcmuCodec, kH264Codec, &content);
539 // Both sides agree on mux. Should no longer be a separate RTCP channel.
540 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000541 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
542 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000543 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
544 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000545 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000546 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000547 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000548 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
549 }
550
551 // Test that SetLocalContent and SetRemoteContent properly set RTCP
552 // mux when a provisional answer is received.
553 void TestSetContentsRtcpMuxWithPrAnswer() {
554 CreateChannels(RTCP, RTCP);
555 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
556 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
557 typename T::Content content;
558 CreateContent(0, kPcmuCodec, kH264Codec, &content);
559 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000560 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
561 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000562 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000563 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000564 // Both sides agree on mux. Should no longer be a separate RTCP channel.
565 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
566 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000567 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000568 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000569 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_PRANSWER, NULL));
570 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000571 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
572 }
573
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000574 // Test that SetRemoteContent properly deals with a content update.
575 void TestSetRemoteContentUpdate() {
576 CreateChannels(0, 0);
577 typename T::Content content;
578 CreateContent(RTCP | RTCP_MUX | SECURE,
579 kPcmuCodec, kH264Codec,
580 &content);
581 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000582 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
583 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000584 ASSERT_EQ(1U, media_channel1_->codecs().size());
585 EXPECT_TRUE(CodecMatches(content.codecs()[0],
586 media_channel1_->codecs()[0]));
587 // Now update with other codecs.
588 typename T::Content update_content;
589 update_content.set_partial(true);
590 CreateContent(0, kIsacCodec, kH264SvcCodec,
591 &update_content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000592 EXPECT_TRUE(channel1_->SetRemoteContent(&update_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000593 ASSERT_EQ(1U, media_channel1_->codecs().size());
594 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
595 media_channel1_->codecs()[0]));
596 // Now update without any codecs. This is ignored.
597 typename T::Content empty_content;
598 empty_content.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000599 EXPECT_TRUE(channel1_->SetRemoteContent(&empty_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000600 ASSERT_EQ(1U, media_channel1_->codecs().size());
601 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
602 media_channel1_->codecs()[0]));
603 }
604
605 // Test that Add/RemoveStream properly forward to the media channel.
606 void TestStreams() {
607 CreateChannels(0, 0);
608 EXPECT_TRUE(AddStream1(1));
609 EXPECT_TRUE(AddStream1(2));
610 EXPECT_EQ(2U, media_channel1_->recv_streams().size());
611 EXPECT_TRUE(RemoveStream1(2));
612 EXPECT_EQ(1U, media_channel1_->recv_streams().size());
613 EXPECT_TRUE(RemoveStream1(1));
614 EXPECT_EQ(0U, media_channel1_->recv_streams().size());
615 }
616
617 // Test that SetLocalContent properly handles adding and removing StreamParams
618 // to the local content description.
619 // This test uses the CA_UPDATE action that don't require a full
620 // MediaContentDescription to do an update.
621 void TestUpdateStreamsInLocalContent() {
622 cricket::StreamParams stream1;
623 stream1.groupid = "group1";
624 stream1.id = "stream1";
625 stream1.ssrcs.push_back(kSsrc1);
626 stream1.cname = "stream1_cname";
627
628 cricket::StreamParams stream2;
629 stream2.groupid = "group2";
630 stream2.id = "stream2";
631 stream2.ssrcs.push_back(kSsrc2);
632 stream2.cname = "stream2_cname";
633
634 cricket::StreamParams stream3;
635 stream3.groupid = "group3";
636 stream3.id = "stream3";
637 stream3.ssrcs.push_back(kSsrc3);
638 stream3.cname = "stream3_cname";
639
640 CreateChannels(0, 0);
641 typename T::Content content1;
642 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
643 content1.AddStream(stream1);
644 EXPECT_EQ(0u, media_channel1_->send_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000645 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000646
647 ASSERT_EQ(1u, media_channel1_->send_streams().size());
648 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
649
650 // Update the local streams by adding another sending stream.
651 // Use a partial updated session description.
652 typename T::Content content2;
653 content2.AddStream(stream2);
654 content2.AddStream(stream3);
655 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000656 EXPECT_TRUE(channel1_->SetLocalContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000657 ASSERT_EQ(3u, media_channel1_->send_streams().size());
658 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
659 EXPECT_EQ(stream2, media_channel1_->send_streams()[1]);
660 EXPECT_EQ(stream3, media_channel1_->send_streams()[2]);
661
662 // Update the local streams by removing the first sending stream.
663 // This is done by removing all SSRCS for this particular stream.
664 typename T::Content content3;
665 stream1.ssrcs.clear();
666 content3.AddStream(stream1);
667 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000668 EXPECT_TRUE(channel1_->SetLocalContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000669 ASSERT_EQ(2u, media_channel1_->send_streams().size());
670 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
671 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
672
673 // Update the local streams with a stream that does not change.
674 // THe update is ignored.
675 typename T::Content content4;
676 content4.AddStream(stream2);
677 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000678 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000679 ASSERT_EQ(2u, media_channel1_->send_streams().size());
680 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
681 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
682 }
683
684 // Test that SetRemoteContent properly handles adding and removing
685 // StreamParams to the remote content description.
686 // This test uses the CA_UPDATE action that don't require a full
687 // MediaContentDescription to do an update.
688 void TestUpdateStreamsInRemoteContent() {
689 cricket::StreamParams stream1;
690 stream1.id = "Stream1";
691 stream1.groupid = "1";
692 stream1.ssrcs.push_back(kSsrc1);
693 stream1.cname = "stream1_cname";
694
695 cricket::StreamParams stream2;
696 stream2.id = "Stream2";
697 stream2.groupid = "2";
698 stream2.ssrcs.push_back(kSsrc2);
699 stream2.cname = "stream2_cname";
700
701 cricket::StreamParams stream3;
702 stream3.id = "Stream3";
703 stream3.groupid = "3";
704 stream3.ssrcs.push_back(kSsrc3);
705 stream3.cname = "stream3_cname";
706
707 CreateChannels(0, 0);
708 typename T::Content content1;
709 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
710 content1.AddStream(stream1);
711 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000712 EXPECT_TRUE(channel1_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000713
714 ASSERT_EQ(1u, media_channel1_->codecs().size());
715 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
716 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
717
718 // Update the remote streams by adding another sending stream.
719 // Use a partial updated session description.
720 typename T::Content content2;
721 content2.AddStream(stream2);
722 content2.AddStream(stream3);
723 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000724 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000725 ASSERT_EQ(3u, media_channel1_->recv_streams().size());
726 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
727 EXPECT_EQ(stream2, media_channel1_->recv_streams()[1]);
728 EXPECT_EQ(stream3, media_channel1_->recv_streams()[2]);
729
730 // Update the remote streams by removing the first stream.
731 // This is done by removing all SSRCS for this particular stream.
732 typename T::Content content3;
733 stream1.ssrcs.clear();
734 content3.AddStream(stream1);
735 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000736 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000737 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
738 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
739 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
740
741 // Update the remote streams with a stream that does not change.
742 // The update is ignored.
743 typename T::Content content4;
744 content4.AddStream(stream2);
745 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000746 EXPECT_TRUE(channel1_->SetRemoteContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000747 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
748 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
749 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
750 }
751
752 // Test that SetLocalContent and SetRemoteContent properly
753 // handles adding and removing StreamParams when the action is a full
754 // CA_OFFER / CA_ANSWER.
755 void TestChangeStreamParamsInContent() {
756 cricket::StreamParams stream1;
757 stream1.groupid = "group1";
758 stream1.id = "stream1";
759 stream1.ssrcs.push_back(kSsrc1);
760 stream1.cname = "stream1_cname";
761
762 cricket::StreamParams stream2;
763 stream2.groupid = "group1";
764 stream2.id = "stream2";
765 stream2.ssrcs.push_back(kSsrc2);
766 stream2.cname = "stream2_cname";
767
768 // Setup a call where channel 1 send |stream1| to channel 2.
769 CreateChannels(0, 0);
770 typename T::Content content1;
771 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
772 content1.AddStream(stream1);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000773 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000774 EXPECT_TRUE(channel1_->Enable(true));
775 EXPECT_EQ(1u, media_channel1_->send_streams().size());
776
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000777 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000778 EXPECT_EQ(1u, media_channel2_->recv_streams().size());
deadbeefcbecd352015-09-23 11:50:27 -0700779 transport_controller1_.Connect(&transport_controller2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000780
781 // Channel 2 do not send anything.
782 typename T::Content content2;
783 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000784 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000785 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000786 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000787 EXPECT_TRUE(channel2_->Enable(true));
788 EXPECT_EQ(0u, media_channel2_->send_streams().size());
789
790 EXPECT_TRUE(SendCustomRtp1(kSsrc1, 0));
791 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, 0));
792
793 // Let channel 2 update the content by sending |stream2| and enable SRTP.
794 typename T::Content content3;
795 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content3);
796 content3.AddStream(stream2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000797 EXPECT_TRUE(channel2_->SetLocalContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000798 ASSERT_EQ(1u, media_channel2_->send_streams().size());
799 EXPECT_EQ(stream2, media_channel2_->send_streams()[0]);
800
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000801 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000802 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
803 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
804
805 // Channel 1 replies but stop sending stream1.
806 typename T::Content content4;
807 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content4);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000808 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000809 EXPECT_EQ(0u, media_channel1_->send_streams().size());
810
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000811 EXPECT_TRUE(channel2_->SetRemoteContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000812 EXPECT_EQ(0u, media_channel2_->recv_streams().size());
813
814 EXPECT_TRUE(channel1_->secure());
815 EXPECT_TRUE(channel2_->secure());
816 EXPECT_TRUE(SendCustomRtp2(kSsrc2, 0));
817 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, 0));
818 }
819
820 // Test that we only start playout and sending at the right times.
821 void TestPlayoutAndSendingStates() {
822 CreateChannels(0, 0);
Peter Boström34fbfff2015-09-24 19:20:30 +0200823 if (verify_playout_) {
824 EXPECT_FALSE(media_channel1_->playout());
825 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000826 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200827 if (verify_playout_) {
828 EXPECT_FALSE(media_channel2_->playout());
829 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000830 EXPECT_FALSE(media_channel2_->sending());
831 EXPECT_TRUE(channel1_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200832 if (verify_playout_) {
833 EXPECT_FALSE(media_channel1_->playout());
834 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000835 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000836 EXPECT_TRUE(channel1_->SetLocalContent(&local_media_content1_,
837 CA_OFFER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200838 if (verify_playout_) {
839 EXPECT_TRUE(media_channel1_->playout());
840 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000841 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000842 EXPECT_TRUE(channel2_->SetRemoteContent(&local_media_content1_,
843 CA_OFFER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200844 if (verify_playout_) {
845 EXPECT_FALSE(media_channel2_->playout());
846 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000847 EXPECT_FALSE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000848 EXPECT_TRUE(channel2_->SetLocalContent(&local_media_content2_,
849 CA_ANSWER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200850 if (verify_playout_) {
851 EXPECT_FALSE(media_channel2_->playout());
852 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000853 EXPECT_FALSE(media_channel2_->sending());
deadbeefcbecd352015-09-23 11:50:27 -0700854 transport_controller1_.Connect(&transport_controller2_);
Peter Boström34fbfff2015-09-24 19:20:30 +0200855 if (verify_playout_) {
856 EXPECT_TRUE(media_channel1_->playout());
857 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000858 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200859 if (verify_playout_) {
860 EXPECT_FALSE(media_channel2_->playout());
861 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000862 EXPECT_FALSE(media_channel2_->sending());
863 EXPECT_TRUE(channel2_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200864 if (verify_playout_) {
865 EXPECT_TRUE(media_channel2_->playout());
866 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000867 EXPECT_TRUE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000868 EXPECT_TRUE(channel1_->SetRemoteContent(&local_media_content2_,
869 CA_ANSWER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200870 if (verify_playout_) {
871 EXPECT_TRUE(media_channel1_->playout());
872 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000873 EXPECT_TRUE(media_channel1_->sending());
874 }
875
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000876 // Test that changing the MediaContentDirection in the local and remote
877 // session description start playout and sending at the right time.
878 void TestMediaContentDirection() {
879 CreateChannels(0, 0);
880 typename T::Content content1;
881 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
882 typename T::Content content2;
883 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
884 // Set |content2| to be InActive.
885 content2.set_direction(cricket::MD_INACTIVE);
886
887 EXPECT_TRUE(channel1_->Enable(true));
888 EXPECT_TRUE(channel2_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200889 if (verify_playout_) {
890 EXPECT_FALSE(media_channel1_->playout());
891 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000892 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200893 if (verify_playout_) {
894 EXPECT_FALSE(media_channel2_->playout());
895 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000896 EXPECT_FALSE(media_channel2_->sending());
897
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000898 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
899 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
900 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
901 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700902 transport_controller1_.Connect(&transport_controller2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000903
Peter Boström34fbfff2015-09-24 19:20:30 +0200904 if (verify_playout_) {
905 EXPECT_TRUE(media_channel1_->playout());
906 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000907 EXPECT_FALSE(media_channel1_->sending()); // remote InActive
Peter Boström34fbfff2015-09-24 19:20:30 +0200908 if (verify_playout_) {
909 EXPECT_FALSE(media_channel2_->playout()); // local InActive
910 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000911 EXPECT_FALSE(media_channel2_->sending()); // local InActive
912
913 // Update |content2| to be RecvOnly.
914 content2.set_direction(cricket::MD_RECVONLY);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000915 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
916 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000917
Peter Boström34fbfff2015-09-24 19:20:30 +0200918 if (verify_playout_) {
919 EXPECT_TRUE(media_channel1_->playout());
920 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000921 EXPECT_TRUE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200922 if (verify_playout_) {
923 EXPECT_TRUE(media_channel2_->playout()); // local RecvOnly
924 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000925 EXPECT_FALSE(media_channel2_->sending()); // local RecvOnly
926
927 // Update |content2| to be SendRecv.
928 content2.set_direction(cricket::MD_SENDRECV);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000929 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
930 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000931
Peter Boström34fbfff2015-09-24 19:20:30 +0200932 if (verify_playout_) {
933 EXPECT_TRUE(media_channel1_->playout());
934 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000935 EXPECT_TRUE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200936 if (verify_playout_) {
937 EXPECT_TRUE(media_channel2_->playout());
938 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000939 EXPECT_TRUE(media_channel2_->sending());
940 }
941
942 // Test setting up a call.
943 void TestCallSetup() {
944 CreateChannels(0, 0);
945 EXPECT_FALSE(channel1_->secure());
946 EXPECT_TRUE(SendInitiate());
Peter Boström34fbfff2015-09-24 19:20:30 +0200947 if (verify_playout_) {
948 EXPECT_TRUE(media_channel1_->playout());
949 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000950 EXPECT_FALSE(media_channel1_->sending());
951 EXPECT_TRUE(SendAccept());
952 EXPECT_FALSE(channel1_->secure());
953 EXPECT_TRUE(media_channel1_->sending());
954 EXPECT_EQ(1U, media_channel1_->codecs().size());
Peter Boström34fbfff2015-09-24 19:20:30 +0200955 if (verify_playout_) {
956 EXPECT_TRUE(media_channel2_->playout());
957 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000958 EXPECT_TRUE(media_channel2_->sending());
959 EXPECT_EQ(1U, media_channel2_->codecs().size());
960 }
961
962 // Test that we don't crash if packets are sent during call teardown
963 // when RTCP mux is enabled. This is a regression test against a specific
964 // race condition that would only occur when a RTCP packet was sent during
965 // teardown of a channel on which RTCP mux was enabled.
966 void TestCallTeardownRtcpMux() {
967 class LastWordMediaChannel : public T::MediaChannel {
968 public:
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200969 LastWordMediaChannel() : T::MediaChannel(NULL, typename T::Options()) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000970 ~LastWordMediaChannel() {
971 T::MediaChannel::SendRtp(kPcmuFrame, sizeof(kPcmuFrame));
972 T::MediaChannel::SendRtcp(kRtcpReport, sizeof(kRtcpReport));
973 }
974 };
975 CreateChannels(new LastWordMediaChannel(), new LastWordMediaChannel(),
976 RTCP | RTCP_MUX, RTCP | RTCP_MUX,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000977 rtc::Thread::Current());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000978 EXPECT_TRUE(SendInitiate());
979 EXPECT_TRUE(SendAccept());
980 EXPECT_TRUE(SendTerminate());
981 }
982
983 // Send voice RTP data to the other side and ensure it gets there.
984 void SendRtpToRtp() {
985 CreateChannels(0, 0);
986 EXPECT_TRUE(SendInitiate());
987 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -0700988 ASSERT_TRUE(GetTransport1());
989 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000990 EXPECT_EQ(1U, GetTransport1()->channels().size());
991 EXPECT_EQ(1U, GetTransport2()->channels().size());
992 EXPECT_TRUE(SendRtp1());
993 EXPECT_TRUE(SendRtp2());
994 EXPECT_TRUE(CheckRtp1());
995 EXPECT_TRUE(CheckRtp2());
996 EXPECT_TRUE(CheckNoRtp1());
997 EXPECT_TRUE(CheckNoRtp2());
998 }
999
1000 // Check that RTCP is not transmitted if both sides don't support RTCP.
1001 void SendNoRtcpToNoRtcp() {
1002 CreateChannels(0, 0);
1003 EXPECT_TRUE(SendInitiate());
1004 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001005 ASSERT_TRUE(GetTransport1());
1006 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001007 EXPECT_EQ(1U, GetTransport1()->channels().size());
1008 EXPECT_EQ(1U, GetTransport2()->channels().size());
1009 EXPECT_FALSE(SendRtcp1());
1010 EXPECT_FALSE(SendRtcp2());
1011 EXPECT_TRUE(CheckNoRtcp1());
1012 EXPECT_TRUE(CheckNoRtcp2());
1013 }
1014
1015 // Check that RTCP is not transmitted if the callee doesn't support RTCP.
1016 void SendNoRtcpToRtcp() {
1017 CreateChannels(0, RTCP);
1018 EXPECT_TRUE(SendInitiate());
1019 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001020 ASSERT_TRUE(GetTransport1());
1021 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001022 EXPECT_EQ(1U, GetTransport1()->channels().size());
1023 EXPECT_EQ(2U, GetTransport2()->channels().size());
1024 EXPECT_FALSE(SendRtcp1());
1025 EXPECT_FALSE(SendRtcp2());
1026 EXPECT_TRUE(CheckNoRtcp1());
1027 EXPECT_TRUE(CheckNoRtcp2());
1028 }
1029
1030 // Check that RTCP is not transmitted if the caller doesn't support RTCP.
1031 void SendRtcpToNoRtcp() {
1032 CreateChannels(RTCP, 0);
1033 EXPECT_TRUE(SendInitiate());
1034 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001035 ASSERT_TRUE(GetTransport1());
1036 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001037 EXPECT_EQ(2U, GetTransport1()->channels().size());
1038 EXPECT_EQ(1U, GetTransport2()->channels().size());
1039 EXPECT_FALSE(SendRtcp1());
1040 EXPECT_FALSE(SendRtcp2());
1041 EXPECT_TRUE(CheckNoRtcp1());
1042 EXPECT_TRUE(CheckNoRtcp2());
1043 }
1044
1045 // Check that RTCP is transmitted if both sides support RTCP.
1046 void SendRtcpToRtcp() {
1047 CreateChannels(RTCP, RTCP);
1048 EXPECT_TRUE(SendInitiate());
1049 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001050 ASSERT_TRUE(GetTransport1());
1051 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001052 EXPECT_EQ(2U, GetTransport1()->channels().size());
1053 EXPECT_EQ(2U, GetTransport2()->channels().size());
1054 EXPECT_TRUE(SendRtcp1());
1055 EXPECT_TRUE(SendRtcp2());
1056 EXPECT_TRUE(CheckRtcp1());
1057 EXPECT_TRUE(CheckRtcp2());
1058 EXPECT_TRUE(CheckNoRtcp1());
1059 EXPECT_TRUE(CheckNoRtcp2());
1060 }
1061
1062 // Check that RTCP is transmitted if only the initiator supports mux.
1063 void SendRtcpMuxToRtcp() {
1064 CreateChannels(RTCP | RTCP_MUX, RTCP);
1065 EXPECT_TRUE(SendInitiate());
1066 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001067 ASSERT_TRUE(GetTransport1());
1068 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001069 EXPECT_EQ(2U, GetTransport1()->channels().size());
1070 EXPECT_EQ(2U, GetTransport2()->channels().size());
1071 EXPECT_TRUE(SendRtcp1());
1072 EXPECT_TRUE(SendRtcp2());
1073 EXPECT_TRUE(CheckRtcp1());
1074 EXPECT_TRUE(CheckRtcp2());
1075 EXPECT_TRUE(CheckNoRtcp1());
1076 EXPECT_TRUE(CheckNoRtcp2());
1077 }
1078
1079 // Check that RTP and RTCP are transmitted ok when both sides support mux.
1080 void SendRtcpMuxToRtcpMux() {
1081 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1082 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001083 ASSERT_TRUE(GetTransport1());
1084 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001085 EXPECT_EQ(2U, GetTransport1()->channels().size());
1086 EXPECT_EQ(1U, GetTransport2()->channels().size());
1087 EXPECT_TRUE(SendAccept());
1088 EXPECT_EQ(1U, GetTransport1()->channels().size());
1089 EXPECT_TRUE(SendRtp1());
1090 EXPECT_TRUE(SendRtp2());
1091 EXPECT_TRUE(SendRtcp1());
1092 EXPECT_TRUE(SendRtcp2());
1093 EXPECT_TRUE(CheckRtp1());
1094 EXPECT_TRUE(CheckRtp2());
1095 EXPECT_TRUE(CheckNoRtp1());
1096 EXPECT_TRUE(CheckNoRtp2());
1097 EXPECT_TRUE(CheckRtcp1());
1098 EXPECT_TRUE(CheckRtcp2());
1099 EXPECT_TRUE(CheckNoRtcp1());
1100 EXPECT_TRUE(CheckNoRtcp2());
1101 }
1102
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001103 // Check that RTP and RTCP are transmitted ok when both sides
1104 // support mux and one the offerer requires mux.
1105 void SendRequireRtcpMuxToRtcpMux() {
1106 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1107 channel1_->ActivateRtcpMux();
1108 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001109 ASSERT_TRUE(GetTransport1());
1110 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001111 EXPECT_EQ(1U, GetTransport1()->channels().size());
1112 EXPECT_EQ(1U, GetTransport2()->channels().size());
1113 EXPECT_TRUE(SendAccept());
1114 EXPECT_TRUE(SendRtp1());
1115 EXPECT_TRUE(SendRtp2());
1116 EXPECT_TRUE(SendRtcp1());
1117 EXPECT_TRUE(SendRtcp2());
1118 EXPECT_TRUE(CheckRtp1());
1119 EXPECT_TRUE(CheckRtp2());
1120 EXPECT_TRUE(CheckNoRtp1());
1121 EXPECT_TRUE(CheckNoRtp2());
1122 EXPECT_TRUE(CheckRtcp1());
1123 EXPECT_TRUE(CheckRtcp2());
1124 EXPECT_TRUE(CheckNoRtcp1());
1125 EXPECT_TRUE(CheckNoRtcp2());
1126 }
1127
1128 // Check that RTP and RTCP are transmitted ok when both sides
1129 // support mux and one the answerer requires rtcp mux.
1130 void SendRtcpMuxToRequireRtcpMux() {
1131 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1132 channel2_->ActivateRtcpMux();
1133 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001134 ASSERT_TRUE(GetTransport1());
1135 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001136 EXPECT_EQ(2U, GetTransport1()->channels().size());
1137 EXPECT_EQ(1U, GetTransport2()->channels().size());
1138 EXPECT_TRUE(SendAccept());
1139 EXPECT_EQ(1U, GetTransport1()->channels().size());
1140 EXPECT_TRUE(SendRtp1());
1141 EXPECT_TRUE(SendRtp2());
1142 EXPECT_TRUE(SendRtcp1());
1143 EXPECT_TRUE(SendRtcp2());
1144 EXPECT_TRUE(CheckRtp1());
1145 EXPECT_TRUE(CheckRtp2());
1146 EXPECT_TRUE(CheckNoRtp1());
1147 EXPECT_TRUE(CheckNoRtp2());
1148 EXPECT_TRUE(CheckRtcp1());
1149 EXPECT_TRUE(CheckRtcp2());
1150 EXPECT_TRUE(CheckNoRtcp1());
1151 EXPECT_TRUE(CheckNoRtcp2());
1152 }
1153
1154 // Check that RTP and RTCP are transmitted ok when both sides
1155 // require mux.
1156 void SendRequireRtcpMuxToRequireRtcpMux() {
1157 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1158 channel1_->ActivateRtcpMux();
1159 channel2_->ActivateRtcpMux();
1160 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001161 ASSERT_TRUE(GetTransport1());
1162 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001163 EXPECT_EQ(1U, GetTransport1()->channels().size());
1164 EXPECT_EQ(1U, GetTransport2()->channels().size());
1165 EXPECT_TRUE(SendAccept());
1166 EXPECT_EQ(1U, GetTransport1()->channels().size());
1167 EXPECT_TRUE(SendRtp1());
1168 EXPECT_TRUE(SendRtp2());
1169 EXPECT_TRUE(SendRtcp1());
1170 EXPECT_TRUE(SendRtcp2());
1171 EXPECT_TRUE(CheckRtp1());
1172 EXPECT_TRUE(CheckRtp2());
1173 EXPECT_TRUE(CheckNoRtp1());
1174 EXPECT_TRUE(CheckNoRtp2());
1175 EXPECT_TRUE(CheckRtcp1());
1176 EXPECT_TRUE(CheckRtcp2());
1177 EXPECT_TRUE(CheckNoRtcp1());
1178 EXPECT_TRUE(CheckNoRtcp2());
1179 }
1180
1181 // Check that SendAccept fails if the answerer doesn't support mux
1182 // and the offerer requires it.
1183 void SendRequireRtcpMuxToNoRtcpMux() {
1184 CreateChannels(RTCP | RTCP_MUX, RTCP);
1185 channel1_->ActivateRtcpMux();
1186 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001187 ASSERT_TRUE(GetTransport1());
1188 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001189 EXPECT_EQ(1U, GetTransport1()->channels().size());
1190 EXPECT_EQ(2U, GetTransport2()->channels().size());
1191 EXPECT_FALSE(SendAccept());
1192 }
1193
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001194 // Check that RTCP data sent by the initiator before the accept is not muxed.
1195 void SendEarlyRtcpMuxToRtcp() {
1196 CreateChannels(RTCP | RTCP_MUX, RTCP);
1197 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001198 ASSERT_TRUE(GetTransport1());
1199 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001200 EXPECT_EQ(2U, GetTransport1()->channels().size());
1201 EXPECT_EQ(2U, GetTransport2()->channels().size());
1202
1203 // RTCP can be sent before the call is accepted, if the transport is ready.
1204 // It should not be muxed though, as the remote side doesn't support mux.
1205 EXPECT_TRUE(SendRtcp1());
1206 EXPECT_TRUE(CheckNoRtp2());
1207 EXPECT_TRUE(CheckRtcp2());
1208
1209 // Send RTCP packet from callee and verify that it is received.
1210 EXPECT_TRUE(SendRtcp2());
1211 EXPECT_TRUE(CheckNoRtp1());
1212 EXPECT_TRUE(CheckRtcp1());
1213
1214 // Complete call setup and ensure everything is still OK.
1215 EXPECT_TRUE(SendAccept());
1216 EXPECT_EQ(2U, GetTransport1()->channels().size());
1217 EXPECT_TRUE(SendRtcp1());
1218 EXPECT_TRUE(CheckRtcp2());
1219 EXPECT_TRUE(SendRtcp2());
1220 EXPECT_TRUE(CheckRtcp1());
1221 }
1222
1223
1224 // Check that RTCP data is not muxed until both sides have enabled muxing,
1225 // but that we properly demux before we get the accept message, since there
1226 // is a race between RTP data and the jingle accept.
1227 void SendEarlyRtcpMuxToRtcpMux() {
1228 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1229 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001230 ASSERT_TRUE(GetTransport1());
1231 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001232 EXPECT_EQ(2U, GetTransport1()->channels().size());
1233 EXPECT_EQ(1U, GetTransport2()->channels().size());
1234
1235 // RTCP can't be sent yet, since the RTCP transport isn't writable, and
1236 // we haven't yet received the accept that says we should mux.
1237 EXPECT_FALSE(SendRtcp1());
1238
1239 // Send muxed RTCP packet from callee and verify that it is received.
1240 EXPECT_TRUE(SendRtcp2());
1241 EXPECT_TRUE(CheckNoRtp1());
1242 EXPECT_TRUE(CheckRtcp1());
1243
1244 // Complete call setup and ensure everything is still OK.
1245 EXPECT_TRUE(SendAccept());
1246 EXPECT_EQ(1U, GetTransport1()->channels().size());
1247 EXPECT_TRUE(SendRtcp1());
1248 EXPECT_TRUE(CheckRtcp2());
1249 EXPECT_TRUE(SendRtcp2());
1250 EXPECT_TRUE(CheckRtcp1());
1251 }
1252
1253 // Test that we properly send SRTP with RTCP in both directions.
1254 // You can pass in DTLS and/or RTCP_MUX as flags.
1255 void SendSrtpToSrtp(int flags1_in = 0, int flags2_in = 0) {
1256 ASSERT((flags1_in & ~(RTCP_MUX | DTLS)) == 0);
1257 ASSERT((flags2_in & ~(RTCP_MUX | DTLS)) == 0);
1258
1259 int flags1 = RTCP | SECURE | flags1_in;
1260 int flags2 = RTCP | SECURE | flags2_in;
1261 bool dtls1 = !!(flags1_in & DTLS);
1262 bool dtls2 = !!(flags2_in & DTLS);
1263 CreateChannels(flags1, flags2);
1264 EXPECT_FALSE(channel1_->secure());
1265 EXPECT_FALSE(channel2_->secure());
1266 EXPECT_TRUE(SendInitiate());
1267 EXPECT_TRUE_WAIT(channel1_->writable(), kEventTimeout);
1268 EXPECT_TRUE_WAIT(channel2_->writable(), kEventTimeout);
1269 EXPECT_TRUE(SendAccept());
1270 EXPECT_TRUE(channel1_->secure());
1271 EXPECT_TRUE(channel2_->secure());
1272 EXPECT_EQ(dtls1 && dtls2, channel1_->secure_dtls());
1273 EXPECT_EQ(dtls1 && dtls2, channel2_->secure_dtls());
1274 EXPECT_TRUE(SendRtp1());
1275 EXPECT_TRUE(SendRtp2());
1276 EXPECT_TRUE(SendRtcp1());
1277 EXPECT_TRUE(SendRtcp2());
1278 EXPECT_TRUE(CheckRtp1());
1279 EXPECT_TRUE(CheckRtp2());
1280 EXPECT_TRUE(CheckNoRtp1());
1281 EXPECT_TRUE(CheckNoRtp2());
1282 EXPECT_TRUE(CheckRtcp1());
1283 EXPECT_TRUE(CheckRtcp2());
1284 EXPECT_TRUE(CheckNoRtcp1());
1285 EXPECT_TRUE(CheckNoRtcp2());
1286 }
1287
1288 // Test that we properly handling SRTP negotiating down to RTP.
1289 void SendSrtpToRtp() {
1290 CreateChannels(RTCP | SECURE, RTCP);
1291 EXPECT_FALSE(channel1_->secure());
1292 EXPECT_FALSE(channel2_->secure());
1293 EXPECT_TRUE(SendInitiate());
1294 EXPECT_TRUE(SendAccept());
1295 EXPECT_FALSE(channel1_->secure());
1296 EXPECT_FALSE(channel2_->secure());
1297 EXPECT_TRUE(SendRtp1());
1298 EXPECT_TRUE(SendRtp2());
1299 EXPECT_TRUE(SendRtcp1());
1300 EXPECT_TRUE(SendRtcp2());
1301 EXPECT_TRUE(CheckRtp1());
1302 EXPECT_TRUE(CheckRtp2());
1303 EXPECT_TRUE(CheckNoRtp1());
1304 EXPECT_TRUE(CheckNoRtp2());
1305 EXPECT_TRUE(CheckRtcp1());
1306 EXPECT_TRUE(CheckRtcp2());
1307 EXPECT_TRUE(CheckNoRtcp1());
1308 EXPECT_TRUE(CheckNoRtcp2());
1309 }
1310
1311 // Test that we can send and receive early media when a provisional answer is
1312 // sent and received. The test uses SRTP, RTCP mux and SSRC mux.
1313 void SendEarlyMediaUsingRtcpMuxSrtp() {
1314 int sequence_number1_1 = 0, sequence_number2_2 = 0;
1315
1316 CreateChannels(SSRC_MUX | RTCP | RTCP_MUX | SECURE,
1317 SSRC_MUX | RTCP | RTCP_MUX | SECURE);
1318 EXPECT_TRUE(SendOffer());
1319 EXPECT_TRUE(SendProvisionalAnswer());
1320 EXPECT_TRUE(channel1_->secure());
1321 EXPECT_TRUE(channel2_->secure());
deadbeefcbecd352015-09-23 11:50:27 -07001322 ASSERT_TRUE(GetTransport1());
1323 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001324 EXPECT_EQ(2U, GetTransport1()->channels().size());
1325 EXPECT_EQ(2U, GetTransport2()->channels().size());
1326 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1327 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1328 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
1329 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1330
1331 // Send packets from callee and verify that it is received.
1332 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1333 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1334 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
1335 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1336
1337 // Complete call setup and ensure everything is still OK.
1338 EXPECT_TRUE(SendFinalAnswer());
1339 EXPECT_EQ(1U, GetTransport1()->channels().size());
1340 EXPECT_EQ(1U, GetTransport2()->channels().size());
1341 EXPECT_TRUE(channel1_->secure());
1342 EXPECT_TRUE(channel2_->secure());
1343 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1344 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1345 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
1346 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1347 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1348 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1349 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
1350 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1351 }
1352
1353 // Test that we properly send RTP without SRTP from a thread.
1354 void SendRtpToRtpOnThread() {
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +00001355 bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2;
1356 CreateChannels(RTCP, RTCP);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001357 EXPECT_TRUE(SendInitiate());
1358 EXPECT_TRUE(SendAccept());
1359 CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1);
1360 CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2);
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +00001361 CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1);
1362 CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001363 EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
1364 EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
1365 EXPECT_TRUE_WAIT(sent_rtp1, 1000);
1366 EXPECT_TRUE_WAIT(sent_rtp2, 1000);
1367 EXPECT_TRUE(CheckNoRtp1());
1368 EXPECT_TRUE(CheckNoRtp2());
1369 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
1370 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
1371 EXPECT_TRUE_WAIT(sent_rtcp1, 1000);
1372 EXPECT_TRUE_WAIT(sent_rtcp2, 1000);
1373 EXPECT_TRUE(CheckNoRtcp1());
1374 EXPECT_TRUE(CheckNoRtcp2());
1375 }
1376
1377 // Test that we properly send SRTP with RTCP from a thread.
1378 void SendSrtpToSrtpOnThread() {
1379 bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2;
1380 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1381 EXPECT_TRUE(SendInitiate());
1382 EXPECT_TRUE(SendAccept());
1383 CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1);
1384 CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2);
1385 CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1);
1386 CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2);
1387 EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
1388 EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
1389 EXPECT_TRUE_WAIT(sent_rtp1, 1000);
1390 EXPECT_TRUE_WAIT(sent_rtp2, 1000);
1391 EXPECT_TRUE(CheckNoRtp1());
1392 EXPECT_TRUE(CheckNoRtp2());
1393 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
1394 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
1395 EXPECT_TRUE_WAIT(sent_rtcp1, 1000);
1396 EXPECT_TRUE_WAIT(sent_rtcp2, 1000);
1397 EXPECT_TRUE(CheckNoRtcp1());
1398 EXPECT_TRUE(CheckNoRtcp2());
1399 }
1400
1401 // Test that the mediachannel retains its sending state after the transport
1402 // becomes non-writable.
1403 void SendWithWritabilityLoss() {
1404 CreateChannels(0, 0);
1405 EXPECT_TRUE(SendInitiate());
1406 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001407 ASSERT_TRUE(GetTransport1());
1408 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001409 EXPECT_EQ(1U, GetTransport1()->channels().size());
1410 EXPECT_EQ(1U, GetTransport2()->channels().size());
1411 EXPECT_TRUE(SendRtp1());
1412 EXPECT_TRUE(SendRtp2());
1413 EXPECT_TRUE(CheckRtp1());
1414 EXPECT_TRUE(CheckRtp2());
1415 EXPECT_TRUE(CheckNoRtp1());
1416 EXPECT_TRUE(CheckNoRtp2());
1417
wu@webrtc.org97077a32013-10-25 21:18:33 +00001418 // Lose writability, which should fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001419 GetTransport1()->SetWritable(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001420 EXPECT_FALSE(SendRtp1());
1421 EXPECT_TRUE(SendRtp2());
1422 EXPECT_TRUE(CheckRtp1());
1423 EXPECT_TRUE(CheckNoRtp2());
1424
1425 // Regain writability
1426 GetTransport1()->SetWritable(true);
1427 EXPECT_TRUE(media_channel1_->sending());
1428 EXPECT_TRUE(SendRtp1());
1429 EXPECT_TRUE(SendRtp2());
1430 EXPECT_TRUE(CheckRtp1());
1431 EXPECT_TRUE(CheckRtp2());
1432 EXPECT_TRUE(CheckNoRtp1());
1433 EXPECT_TRUE(CheckNoRtp2());
1434
1435 // Lose writability completely
1436 GetTransport1()->SetDestination(NULL);
1437 EXPECT_TRUE(media_channel1_->sending());
1438
wu@webrtc.org97077a32013-10-25 21:18:33 +00001439 // Should fail also.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001440 EXPECT_FALSE(SendRtp1());
1441 EXPECT_TRUE(SendRtp2());
1442 EXPECT_TRUE(CheckRtp1());
1443 EXPECT_TRUE(CheckNoRtp2());
1444
1445 // Gain writability back
1446 GetTransport1()->SetDestination(GetTransport2());
1447 EXPECT_TRUE(media_channel1_->sending());
1448 EXPECT_TRUE(SendRtp1());
1449 EXPECT_TRUE(SendRtp2());
1450 EXPECT_TRUE(CheckRtp1());
1451 EXPECT_TRUE(CheckRtp2());
1452 EXPECT_TRUE(CheckNoRtp1());
1453 EXPECT_TRUE(CheckNoRtp2());
1454 }
1455
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001456 void SendBundleToBundle(
1457 const int* pl_types, int len, bool rtcp_mux, bool secure) {
1458 ASSERT_EQ(2, len);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001459 int sequence_number1_1 = 0, sequence_number2_2 = 0;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001460 // Only pl_type1 was added to the bundle filter for both |channel1_|
1461 // and |channel2_|.
1462 int pl_type1 = pl_types[0];
1463 int pl_type2 = pl_types[1];
1464 int flags = SSRC_MUX | RTCP;
1465 if (secure) flags |= SECURE;
1466 uint32 expected_channels = 2U;
1467 if (rtcp_mux) {
1468 flags |= RTCP_MUX;
1469 expected_channels = 1U;
1470 }
1471 CreateChannels(flags, flags);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001472 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001473 ASSERT_TRUE(GetTransport1());
1474 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001475 EXPECT_EQ(2U, GetTransport1()->channels().size());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001476 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001477 EXPECT_TRUE(SendAccept());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001478 EXPECT_EQ(expected_channels, GetTransport1()->channels().size());
1479 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
1480 EXPECT_TRUE(channel1_->bundle_filter()->FindPayloadType(pl_type1));
1481 EXPECT_TRUE(channel2_->bundle_filter()->FindPayloadType(pl_type1));
1482 EXPECT_FALSE(channel1_->bundle_filter()->FindPayloadType(pl_type2));
1483 EXPECT_FALSE(channel2_->bundle_filter()->FindPayloadType(pl_type2));
1484 // channel1 - should only have media_content2 as remote. i.e. kSsrc2
1485 EXPECT_TRUE(channel1_->bundle_filter()->FindStream(kSsrc2));
1486 EXPECT_FALSE(channel1_->bundle_filter()->FindStream(kSsrc1));
1487 // channel2 - should only have media_content1 as remote. i.e. kSsrc1
1488 EXPECT_TRUE(channel2_->bundle_filter()->FindStream(kSsrc1));
1489 EXPECT_FALSE(channel2_->bundle_filter()->FindStream(kSsrc2));
1490
1491 // Both channels can receive pl_type1 only.
1492 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type1));
1493 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type1));
1494 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type1));
1495 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type1));
1496 EXPECT_TRUE(CheckNoRtp1());
1497 EXPECT_TRUE(CheckNoRtp2());
1498
1499 // RTCP test
1500 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type2));
1501 EXPECT_FALSE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type2));
1502 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type2));
1503 EXPECT_FALSE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type2));
1504
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001505 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1506 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001507 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1508 EXPECT_TRUE(CheckNoRtcp1());
1509 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1510 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001511
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001512 EXPECT_TRUE(SendCustomRtcp1(kSsrc2));
1513 EXPECT_TRUE(SendCustomRtcp2(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001514 EXPECT_FALSE(CheckCustomRtcp1(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001515 EXPECT_FALSE(CheckCustomRtcp2(kSsrc2));
1516 }
1517
1518 // Test that the media monitor can be run and gives timely callbacks.
1519 void TestMediaMonitor() {
1520 static const int kTimeout = 500;
1521 CreateChannels(0, 0);
1522 EXPECT_TRUE(SendInitiate());
1523 EXPECT_TRUE(SendAccept());
1524 channel1_->StartMediaMonitor(100);
1525 channel2_->StartMediaMonitor(100);
1526 // Ensure we get callbacks and stop.
1527 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1528 EXPECT_TRUE_WAIT(media_info_callbacks2_ > 0, kTimeout);
1529 channel1_->StopMediaMonitor();
1530 channel2_->StopMediaMonitor();
1531 // Ensure a restart of a stopped monitor works.
1532 channel1_->StartMediaMonitor(100);
1533 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1534 channel1_->StopMediaMonitor();
1535 // Ensure stopping a stopped monitor is OK.
1536 channel1_->StopMediaMonitor();
1537 }
1538
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001539 void TestSetContentFailure() {
1540 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001541
Peter Thatchera6d24442015-07-09 21:26:36 -07001542 auto sdesc = cricket::SessionDescription();
1543 sdesc.AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1544 new cricket::AudioContentDescription());
1545 sdesc.AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1546 new cricket::VideoContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001547
Peter Thatchera6d24442015-07-09 21:26:36 -07001548 std::string err;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001549 media_channel1_->set_fail_set_recv_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001550 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1551 &sdesc, cricket::CA_OFFER, &err));
1552 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1553 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001554
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001555 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001556 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1557 &sdesc, cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001558 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001559 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1560 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001561 }
1562
1563 void TestSendTwoOffers() {
1564 CreateChannels(0, 0);
1565
Peter Thatchera6d24442015-07-09 21:26:36 -07001566 std::string err;
1567 rtc::scoped_ptr<cricket::SessionDescription> sdesc1(
1568 CreateSessionDescriptionWithStream(1));
1569 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1570 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001571 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1572
Peter Thatchera6d24442015-07-09 21:26:36 -07001573 rtc::scoped_ptr<cricket::SessionDescription> sdesc2(
1574 CreateSessionDescriptionWithStream(2));
1575 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1576 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001577 EXPECT_FALSE(media_channel1_->HasSendStream(1));
1578 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1579 }
1580
1581 void TestReceiveTwoOffers() {
1582 CreateChannels(0, 0);
1583
Peter Thatchera6d24442015-07-09 21:26:36 -07001584 std::string err;
1585 rtc::scoped_ptr<cricket::SessionDescription> sdesc1(
1586 CreateSessionDescriptionWithStream(1));
1587 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1588 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001589 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1590
Peter Thatchera6d24442015-07-09 21:26:36 -07001591 rtc::scoped_ptr<cricket::SessionDescription> sdesc2(
1592 CreateSessionDescriptionWithStream(2));
1593 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1594 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001595 EXPECT_FALSE(media_channel1_->HasRecvStream(1));
1596 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1597 }
1598
1599 void TestSendPrAnswer() {
1600 CreateChannels(0, 0);
1601
Peter Thatchera6d24442015-07-09 21:26:36 -07001602 std::string err;
1603 // Receive offer
1604 rtc::scoped_ptr<cricket::SessionDescription> sdesc1(
1605 CreateSessionDescriptionWithStream(1));
1606 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1607 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001608 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1609
Peter Thatchera6d24442015-07-09 21:26:36 -07001610 // Send PR answer
1611 rtc::scoped_ptr<cricket::SessionDescription> sdesc2(
1612 CreateSessionDescriptionWithStream(2));
1613 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1614 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001615 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1616 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1617
Peter Thatchera6d24442015-07-09 21:26:36 -07001618 // Send answer
1619 rtc::scoped_ptr<cricket::SessionDescription> sdesc3(
1620 CreateSessionDescriptionWithStream(3));
1621 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1622 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001623 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1624 EXPECT_FALSE(media_channel1_->HasSendStream(2));
1625 EXPECT_TRUE(media_channel1_->HasSendStream(3));
1626 }
1627
1628 void TestReceivePrAnswer() {
1629 CreateChannels(0, 0);
1630
Peter Thatchera6d24442015-07-09 21:26:36 -07001631 std::string err;
1632 // Send offer
1633 rtc::scoped_ptr<cricket::SessionDescription> sdesc1(
1634 CreateSessionDescriptionWithStream(1));
1635 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1636 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001637 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1638
Peter Thatchera6d24442015-07-09 21:26:36 -07001639 // Receive PR answer
1640 rtc::scoped_ptr<cricket::SessionDescription> sdesc2(
1641 CreateSessionDescriptionWithStream(2));
1642 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1643 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001644 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1645 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1646
Peter Thatchera6d24442015-07-09 21:26:36 -07001647 // Receive answer
1648 rtc::scoped_ptr<cricket::SessionDescription> sdesc3(
1649 CreateSessionDescriptionWithStream(3));
1650 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1651 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001652 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1653 EXPECT_FALSE(media_channel1_->HasRecvStream(2));
1654 EXPECT_TRUE(media_channel1_->HasRecvStream(3));
1655 }
1656
1657 void TestFlushRtcp() {
1658 bool send_rtcp1;
1659
1660 CreateChannels(RTCP, RTCP);
1661 EXPECT_TRUE(SendInitiate());
1662 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001663 ASSERT_TRUE(GetTransport1());
1664 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001665 EXPECT_EQ(2U, GetTransport1()->channels().size());
1666 EXPECT_EQ(2U, GetTransport2()->channels().size());
1667
1668 // Send RTCP1 from a different thread.
1669 CallOnThreadAndWaitForDone(&ChannelTest<T>::SendRtcp1, &send_rtcp1);
1670 EXPECT_TRUE(send_rtcp1);
1671 // The sending message is only posted. channel2_ should be empty.
1672 EXPECT_TRUE(CheckNoRtcp2());
1673
1674 // When channel1_ is deleted, the RTCP packet should be sent out to
1675 // channel2_.
1676 channel1_.reset();
1677 EXPECT_TRUE(CheckRtcp2());
1678 }
1679
1680 void TestChangeStateError() {
1681 CreateChannels(RTCP, RTCP);
1682 EXPECT_TRUE(SendInitiate());
1683 media_channel2_->set_fail_set_send(true);
1684 EXPECT_TRUE(channel2_->Enable(true));
1685 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_DEVICE_OPEN_FAILED,
1686 error_);
1687 }
1688
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001689 void TestSrtpError(int pl_type) {
1690 // For Audio, only pl_type 0 is added to the bundle filter.
1691 // For Video, only pl_type 97 is added to the bundle filter.
1692 // So we need to pass in pl_type so that the packet can pass through
1693 // the bundle filter before it can be processed by the srtp filter.
1694 // The packet is not a valid srtp packet because it is too short.
pbos@webrtc.org910473b2014-06-06 15:44:00 +00001695 unsigned const char kBadPacket[] = {0x84,
1696 static_cast<unsigned char>(pl_type),
1697 0x00,
1698 0x01,
1699 0x00,
1700 0x00,
1701 0x00,
1702 0x00,
1703 0x00,
1704 0x00,
1705 0x00,
1706 0x01};
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001707 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1708 EXPECT_FALSE(channel1_->secure());
1709 EXPECT_FALSE(channel2_->secure());
1710 EXPECT_TRUE(SendInitiate());
1711 EXPECT_TRUE(SendAccept());
1712 EXPECT_TRUE(channel1_->secure());
1713 EXPECT_TRUE(channel2_->secure());
1714 channel2_->set_srtp_signal_silent_time(200);
1715
1716 // Testing failures in sending packets.
1717 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1718 // The first failure will trigger an error.
1719 EXPECT_EQ_WAIT(T::MediaChannel::ERROR_REC_SRTP_ERROR, error_, 500);
1720 error_ = T::MediaChannel::ERROR_NONE;
1721 // The next 1 sec failures will not trigger an error.
1722 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1723 // Wait for a while to ensure no message comes in.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001724 rtc::Thread::Current()->ProcessMessages(210);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001725 EXPECT_EQ(T::MediaChannel::ERROR_NONE, error_);
1726 // The error will be triggered again.
1727 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1728 EXPECT_EQ_WAIT(T::MediaChannel::ERROR_REC_SRTP_ERROR, error_, 500);
1729
1730 // Testing failures in receiving packets.
1731 error_ = T::MediaChannel::ERROR_NONE;
1732 cricket::TransportChannel* transport_channel =
1733 channel2_->transport_channel();
1734 transport_channel->SignalReadPacket(
1735 transport_channel, reinterpret_cast<const char*>(kBadPacket),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001736 sizeof(kBadPacket), rtc::PacketTime(), 0);
mallinath@webrtc.org4d3e8b82013-08-16 00:31:17 +00001737 EXPECT_EQ_WAIT(T::MediaChannel::ERROR_PLAY_SRTP_ERROR, error_, 500);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001738 }
1739
1740 void TestOnReadyToSend() {
1741 CreateChannels(RTCP, RTCP);
1742 TransportChannel* rtp = channel1_->transport_channel();
1743 TransportChannel* rtcp = channel1_->rtcp_transport_channel();
1744 EXPECT_FALSE(media_channel1_->ready_to_send());
1745 rtp->SignalReadyToSend(rtp);
1746 EXPECT_FALSE(media_channel1_->ready_to_send());
1747 rtcp->SignalReadyToSend(rtcp);
1748 // MediaChannel::OnReadyToSend only be called when both rtp and rtcp
1749 // channel are ready to send.
1750 EXPECT_TRUE(media_channel1_->ready_to_send());
1751
1752 // rtp channel becomes not ready to send will be propagated to mediachannel
deadbeefcbecd352015-09-23 11:50:27 -07001753 channel1_->SetReadyToSend(false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001754 EXPECT_FALSE(media_channel1_->ready_to_send());
deadbeefcbecd352015-09-23 11:50:27 -07001755 channel1_->SetReadyToSend(false, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001756 EXPECT_TRUE(media_channel1_->ready_to_send());
1757
1758 // rtcp channel becomes not ready to send will be propagated to mediachannel
deadbeefcbecd352015-09-23 11:50:27 -07001759 channel1_->SetReadyToSend(true, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001760 EXPECT_FALSE(media_channel1_->ready_to_send());
deadbeefcbecd352015-09-23 11:50:27 -07001761 channel1_->SetReadyToSend(true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001762 EXPECT_TRUE(media_channel1_->ready_to_send());
1763 }
1764
1765 void TestOnReadyToSendWithRtcpMux() {
1766 CreateChannels(RTCP, RTCP);
1767 typename T::Content content;
1768 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1769 // Both sides agree on mux. Should no longer be a separate RTCP channel.
1770 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001771 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
1772 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001773 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
1774 TransportChannel* rtp = channel1_->transport_channel();
1775 EXPECT_FALSE(media_channel1_->ready_to_send());
1776 // In the case of rtcp mux, the SignalReadyToSend() from rtp channel
1777 // should trigger the MediaChannel's OnReadyToSend.
1778 rtp->SignalReadyToSend(rtp);
1779 EXPECT_TRUE(media_channel1_->ready_to_send());
deadbeefcbecd352015-09-23 11:50:27 -07001780 channel1_->SetReadyToSend(false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001781 EXPECT_FALSE(media_channel1_->ready_to_send());
1782 }
1783
1784 protected:
Peter Boström34fbfff2015-09-24 19:20:30 +02001785 // TODO(pbos): Remove playout from all media channels and let renderers mute
1786 // themselves.
1787 const bool verify_playout_;
deadbeefcbecd352015-09-23 11:50:27 -07001788 cricket::FakeTransportController transport_controller1_;
1789 cricket::FakeTransportController transport_controller2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001790 cricket::FakeMediaEngine media_engine_;
1791 // The media channels are owned by the voice channel objects below.
1792 typename T::MediaChannel* media_channel1_;
1793 typename T::MediaChannel* media_channel2_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001794 rtc::scoped_ptr<typename T::Channel> channel1_;
1795 rtc::scoped_ptr<typename T::Channel> channel2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001796 typename T::Content local_media_content1_;
1797 typename T::Content local_media_content2_;
1798 typename T::Content remote_media_content1_;
1799 typename T::Content remote_media_content2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001800 // The RTP and RTCP packets to send in the tests.
1801 std::string rtp_packet_;
1802 std::string rtcp_packet_;
1803 int media_info_callbacks1_;
1804 int media_info_callbacks2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001805
1806 uint32 ssrc_;
1807 typename T::MediaChannel::Error error_;
1808};
1809
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001810template<>
1811void ChannelTest<VoiceTraits>::CreateContent(
1812 int flags,
1813 const cricket::AudioCodec& audio_codec,
1814 const cricket::VideoCodec& video_codec,
1815 cricket::AudioContentDescription* audio) {
1816 audio->AddCodec(audio_codec);
1817 audio->set_rtcp_mux((flags & RTCP_MUX) != 0);
1818 if (flags & SECURE) {
1819 audio->AddCrypto(cricket::CryptoParams(
1820 1, cricket::CS_AES_CM_128_HMAC_SHA1_32,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001821 "inline:" + rtc::CreateRandomString(40), ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001822 }
1823}
1824
1825template<>
1826void ChannelTest<VoiceTraits>::CopyContent(
1827 const cricket::AudioContentDescription& source,
1828 cricket::AudioContentDescription* audio) {
1829 *audio = source;
1830}
1831
1832template<>
1833bool ChannelTest<VoiceTraits>::CodecMatches(const cricket::AudioCodec& c1,
1834 const cricket::AudioCodec& c2) {
1835 return c1.name == c2.name && c1.clockrate == c2.clockrate &&
1836 c1.bitrate == c2.bitrate && c1.channels == c2.channels;
1837}
1838
1839template<>
1840void ChannelTest<VoiceTraits>::AddLegacyStreamInContent(
1841 uint32 ssrc, int flags, cricket::AudioContentDescription* audio) {
1842 audio->AddLegacyStream(ssrc);
1843}
1844
1845class VoiceChannelTest
1846 : public ChannelTest<VoiceTraits> {
1847 public:
solenberg1dd98f32015-09-10 01:57:14 -07001848 typedef ChannelTest<VoiceTraits> Base;
deadbeefcbecd352015-09-23 11:50:27 -07001849 VoiceChannelTest()
Peter Boström34fbfff2015-09-24 19:20:30 +02001850 : Base(true,
1851 kPcmuFrame,
1852 sizeof(kPcmuFrame),
1853 kRtcpReport,
1854 sizeof(kRtcpReport)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001855};
1856
1857// override to add NULL parameter
deadbeefcbecd352015-09-23 11:50:27 -07001858template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001859cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
deadbeefcbecd352015-09-23 11:50:27 -07001860 rtc::Thread* thread,
1861 cricket::MediaEngineInterface* engine,
1862 cricket::FakeVideoMediaChannel* ch,
1863 cricket::TransportController* transport_controller,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001864 bool rtcp) {
1865 cricket::VideoChannel* channel = new cricket::VideoChannel(
deadbeefcbecd352015-09-23 11:50:27 -07001866 thread, ch, transport_controller, cricket::CN_VIDEO, rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001867 if (!channel->Init()) {
1868 delete channel;
1869 channel = NULL;
1870 }
1871 return channel;
1872}
1873
1874// override to add 0 parameter
1875template<>
1876bool ChannelTest<VideoTraits>::AddStream1(int id) {
1877 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
1878}
1879
1880template<>
1881void ChannelTest<VideoTraits>::CreateContent(
1882 int flags,
1883 const cricket::AudioCodec& audio_codec,
1884 const cricket::VideoCodec& video_codec,
1885 cricket::VideoContentDescription* video) {
1886 video->AddCodec(video_codec);
1887 video->set_rtcp_mux((flags & RTCP_MUX) != 0);
1888 if (flags & SECURE) {
1889 video->AddCrypto(cricket::CryptoParams(
1890 1, cricket::CS_AES_CM_128_HMAC_SHA1_80,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001891 "inline:" + rtc::CreateRandomString(40), ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001892 }
1893}
1894
1895template<>
1896void ChannelTest<VideoTraits>::CopyContent(
1897 const cricket::VideoContentDescription& source,
1898 cricket::VideoContentDescription* video) {
1899 *video = source;
1900}
1901
1902template<>
1903bool ChannelTest<VideoTraits>::CodecMatches(const cricket::VideoCodec& c1,
1904 const cricket::VideoCodec& c2) {
1905 return c1.name == c2.name && c1.width == c2.width && c1.height == c2.height &&
1906 c1.framerate == c2.framerate;
1907}
1908
1909template<>
1910void ChannelTest<VideoTraits>::AddLegacyStreamInContent(
1911 uint32 ssrc, int flags, cricket::VideoContentDescription* video) {
1912 video->AddLegacyStream(ssrc);
1913}
1914
1915class VideoChannelTest
1916 : public ChannelTest<VideoTraits> {
1917 public:
solenberg1dd98f32015-09-10 01:57:14 -07001918 typedef ChannelTest<VideoTraits> Base;
deadbeefcbecd352015-09-23 11:50:27 -07001919 VideoChannelTest()
Peter Boström34fbfff2015-09-24 19:20:30 +02001920 : Base(false,
1921 kH264Packet,
deadbeefcbecd352015-09-23 11:50:27 -07001922 sizeof(kH264Packet),
1923 kRtcpReport,
1924 sizeof(kRtcpReport)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001925};
1926
1927
1928// VoiceChannelTest
1929
1930TEST_F(VoiceChannelTest, TestInit) {
1931 Base::TestInit();
1932 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
1933 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
1934}
1935
1936TEST_F(VoiceChannelTest, TestSetContents) {
1937 Base::TestSetContents();
1938}
1939
1940TEST_F(VoiceChannelTest, TestSetContentsNullOffer) {
1941 Base::TestSetContentsNullOffer();
1942}
1943
1944TEST_F(VoiceChannelTest, TestSetContentsRtcpMux) {
1945 Base::TestSetContentsRtcpMux();
1946}
1947
1948TEST_F(VoiceChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
1949 Base::TestSetContentsRtcpMux();
1950}
1951
1952TEST_F(VoiceChannelTest, TestSetRemoteContentUpdate) {
1953 Base::TestSetRemoteContentUpdate();
1954}
1955
1956TEST_F(VoiceChannelTest, TestStreams) {
1957 Base::TestStreams();
1958}
1959
1960TEST_F(VoiceChannelTest, TestUpdateStreamsInLocalContent) {
1961 Base::TestUpdateStreamsInLocalContent();
1962}
1963
1964TEST_F(VoiceChannelTest, TestUpdateRemoteStreamsInContent) {
1965 Base::TestUpdateStreamsInRemoteContent();
1966}
1967
1968TEST_F(VoiceChannelTest, TestChangeStreamParamsInContent) {
1969 Base::TestChangeStreamParamsInContent();
1970}
1971
1972TEST_F(VoiceChannelTest, TestPlayoutAndSendingStates) {
1973 Base::TestPlayoutAndSendingStates();
1974}
1975
1976TEST_F(VoiceChannelTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07001977 CreateChannels(0, 0);
1978 // Test that we can Mute the default channel even though the sending SSRC
1979 // is unknown.
1980 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
1981 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
1982 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
1983 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
1984 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
1985
1986 // Test that we can not mute an unknown SSRC.
1987 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
1988
1989 SendInitiate();
1990 // After the local session description has been set, we can mute a stream
1991 // with its SSRC.
1992 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
1993 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
1994 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
1995 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001996}
1997
1998TEST_F(VoiceChannelTest, TestMediaContentDirection) {
1999 Base::TestMediaContentDirection();
2000}
2001
2002TEST_F(VoiceChannelTest, TestCallSetup) {
2003 Base::TestCallSetup();
2004}
2005
2006TEST_F(VoiceChannelTest, TestCallTeardownRtcpMux) {
2007 Base::TestCallTeardownRtcpMux();
2008}
2009
2010TEST_F(VoiceChannelTest, SendRtpToRtp) {
2011 Base::SendRtpToRtp();
2012}
2013
2014TEST_F(VoiceChannelTest, SendNoRtcpToNoRtcp) {
2015 Base::SendNoRtcpToNoRtcp();
2016}
2017
2018TEST_F(VoiceChannelTest, SendNoRtcpToRtcp) {
2019 Base::SendNoRtcpToRtcp();
2020}
2021
2022TEST_F(VoiceChannelTest, SendRtcpToNoRtcp) {
2023 Base::SendRtcpToNoRtcp();
2024}
2025
2026TEST_F(VoiceChannelTest, SendRtcpToRtcp) {
2027 Base::SendRtcpToRtcp();
2028}
2029
2030TEST_F(VoiceChannelTest, SendRtcpMuxToRtcp) {
2031 Base::SendRtcpMuxToRtcp();
2032}
2033
2034TEST_F(VoiceChannelTest, SendRtcpMuxToRtcpMux) {
2035 Base::SendRtcpMuxToRtcpMux();
2036}
2037
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002038TEST_F(VoiceChannelTest, SendRequireRtcpMuxToRtcpMux) {
2039 Base::SendRequireRtcpMuxToRtcpMux();
2040}
2041
2042TEST_F(VoiceChannelTest, SendRtcpMuxToRequireRtcpMux) {
2043 Base::SendRtcpMuxToRequireRtcpMux();
2044}
2045
2046TEST_F(VoiceChannelTest, SendRequireRtcpMuxToRequireRtcpMux) {
2047 Base::SendRequireRtcpMuxToRequireRtcpMux();
2048}
2049
2050TEST_F(VoiceChannelTest, SendRequireRtcpMuxToNoRtcpMux) {
2051 Base::SendRequireRtcpMuxToNoRtcpMux();
2052}
2053
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002054TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcp) {
2055 Base::SendEarlyRtcpMuxToRtcp();
2056}
2057
2058TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2059 Base::SendEarlyRtcpMuxToRtcpMux();
2060}
2061
2062TEST_F(VoiceChannelTest, SendSrtpToSrtpRtcpMux) {
2063 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2064}
2065
2066TEST_F(VoiceChannelTest, SendSrtpToRtp) {
2067 Base::SendSrtpToSrtp();
2068}
2069
2070TEST_F(VoiceChannelTest, SendSrtcpMux) {
2071 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2072}
2073
2074TEST_F(VoiceChannelTest, SendDtlsSrtpToSrtp) {
2075 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2076 Base::SendSrtpToSrtp(DTLS, 0);
2077}
2078
2079TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtp) {
2080 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2081 Base::SendSrtpToSrtp(DTLS, DTLS);
2082}
2083
2084TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2085 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2086 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2087}
2088
2089TEST_F(VoiceChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2090 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2091}
2092
2093TEST_F(VoiceChannelTest, SendRtpToRtpOnThread) {
2094 Base::SendRtpToRtpOnThread();
2095}
2096
2097TEST_F(VoiceChannelTest, SendSrtpToSrtpOnThread) {
2098 Base::SendSrtpToSrtpOnThread();
2099}
2100
2101TEST_F(VoiceChannelTest, SendWithWritabilityLoss) {
2102 Base::SendWithWritabilityLoss();
2103}
2104
2105TEST_F(VoiceChannelTest, TestMediaMonitor) {
2106 Base::TestMediaMonitor();
2107}
2108
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002109// Test that PressDTMF properly forwards to the media channel.
2110TEST_F(VoiceChannelTest, TestDtmf) {
2111 CreateChannels(0, 0);
2112 EXPECT_TRUE(SendInitiate());
2113 EXPECT_TRUE(SendAccept());
2114 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2115
2116 EXPECT_TRUE(channel1_->PressDTMF(1, true));
2117 EXPECT_TRUE(channel1_->PressDTMF(8, false));
2118
2119 ASSERT_EQ(2U, media_channel1_->dtmf_info_queue().size());
2120 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
2121 0, 1, 160, cricket::DF_PLAY | cricket::DF_SEND));
2122 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
2123 0, 8, 160, cricket::DF_SEND));
2124}
2125
2126// Test that InsertDtmf properly forwards to the media channel.
2127TEST_F(VoiceChannelTest, TestInsertDtmf) {
2128 CreateChannels(0, 0);
2129 EXPECT_TRUE(SendInitiate());
2130 EXPECT_TRUE(SendAccept());
2131 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2132
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002133 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100, cricket::DF_SEND));
2134 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110, cricket::DF_PLAY));
2135 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120,
2136 cricket::DF_PLAY | cricket::DF_SEND));
2137
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002138 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002139 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002140 1, 3, 100, cricket::DF_SEND));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002141 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002142 2, 5, 110, cricket::DF_PLAY));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002143 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002144 3, 7, 120, cricket::DF_PLAY | cricket::DF_SEND));
2145}
2146
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002147TEST_F(VoiceChannelTest, TestSetContentFailure) {
2148 Base::TestSetContentFailure();
2149}
2150
2151TEST_F(VoiceChannelTest, TestSendTwoOffers) {
2152 Base::TestSendTwoOffers();
2153}
2154
2155TEST_F(VoiceChannelTest, TestReceiveTwoOffers) {
2156 Base::TestReceiveTwoOffers();
2157}
2158
2159TEST_F(VoiceChannelTest, TestSendPrAnswer) {
2160 Base::TestSendPrAnswer();
2161}
2162
2163TEST_F(VoiceChannelTest, TestReceivePrAnswer) {
2164 Base::TestReceivePrAnswer();
2165}
2166
2167TEST_F(VoiceChannelTest, TestFlushRtcp) {
2168 Base::TestFlushRtcp();
2169}
2170
2171TEST_F(VoiceChannelTest, TestChangeStateError) {
2172 Base::TestChangeStateError();
2173}
2174
2175TEST_F(VoiceChannelTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002176 Base::TestSrtpError(kAudioPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002177}
2178
2179TEST_F(VoiceChannelTest, TestOnReadyToSend) {
2180 Base::TestOnReadyToSend();
2181}
2182
2183TEST_F(VoiceChannelTest, TestOnReadyToSendWithRtcpMux) {
2184 Base::TestOnReadyToSendWithRtcpMux();
2185}
2186
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002187// Test that we can scale the output volume properly for 1:1 calls.
2188TEST_F(VoiceChannelTest, TestScaleVolume1to1Call) {
2189 CreateChannels(RTCP, RTCP);
2190 EXPECT_TRUE(SendInitiate());
2191 EXPECT_TRUE(SendAccept());
2192 double left, right;
2193
2194 // Default is (1.0, 1.0).
2195 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2196 EXPECT_DOUBLE_EQ(1.0, left);
2197 EXPECT_DOUBLE_EQ(1.0, right);
2198 // invalid ssrc.
2199 EXPECT_FALSE(media_channel1_->GetOutputScaling(3, &left, &right));
2200
2201 // Set scale to (1.5, 0.5).
2202 EXPECT_TRUE(channel1_->SetOutputScaling(0, 1.5, 0.5));
2203 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2204 EXPECT_DOUBLE_EQ(1.5, left);
2205 EXPECT_DOUBLE_EQ(0.5, right);
2206
2207 // Set scale to (0, 0).
2208 EXPECT_TRUE(channel1_->SetOutputScaling(0, 0.0, 0.0));
2209 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2210 EXPECT_DOUBLE_EQ(0.0, left);
2211 EXPECT_DOUBLE_EQ(0.0, right);
2212}
2213
2214// Test that we can scale the output volume properly for multiway calls.
2215TEST_F(VoiceChannelTest, TestScaleVolumeMultiwayCall) {
2216 CreateChannels(RTCP, RTCP);
2217 EXPECT_TRUE(SendInitiate());
2218 EXPECT_TRUE(SendAccept());
2219 EXPECT_TRUE(AddStream1(1));
2220 EXPECT_TRUE(AddStream1(2));
2221
2222 double left, right;
2223 // Default is (1.0, 1.0).
2224 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2225 EXPECT_DOUBLE_EQ(1.0, left);
2226 EXPECT_DOUBLE_EQ(1.0, right);
2227 EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
2228 EXPECT_DOUBLE_EQ(1.0, left);
2229 EXPECT_DOUBLE_EQ(1.0, right);
2230 EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
2231 EXPECT_DOUBLE_EQ(1.0, left);
2232 EXPECT_DOUBLE_EQ(1.0, right);
2233 // invalid ssrc.
2234 EXPECT_FALSE(media_channel1_->GetOutputScaling(3, &left, &right));
2235
2236 // Set scale to (1.5, 0.5) for ssrc = 1.
2237 EXPECT_TRUE(channel1_->SetOutputScaling(1, 1.5, 0.5));
2238 EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
2239 EXPECT_DOUBLE_EQ(1.5, left);
2240 EXPECT_DOUBLE_EQ(0.5, right);
2241 EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
2242 EXPECT_DOUBLE_EQ(1.0, left);
2243 EXPECT_DOUBLE_EQ(1.0, right);
2244 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2245 EXPECT_DOUBLE_EQ(1.0, left);
2246 EXPECT_DOUBLE_EQ(1.0, right);
2247
2248 // Set scale to (0, 0) for all ssrcs.
2249 EXPECT_TRUE(channel1_->SetOutputScaling(0, 0.0, 0.0));
2250 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2251 EXPECT_DOUBLE_EQ(0.0, left);
2252 EXPECT_DOUBLE_EQ(0.0, right);
2253 EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
2254 EXPECT_DOUBLE_EQ(0.0, left);
2255 EXPECT_DOUBLE_EQ(0.0, right);
2256 EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
2257 EXPECT_DOUBLE_EQ(0.0, left);
2258 EXPECT_DOUBLE_EQ(0.0, right);
2259}
2260
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002261TEST_F(VoiceChannelTest, SendBundleToBundle) {
2262 Base::SendBundleToBundle(kAudioPts, ARRAY_SIZE(kAudioPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002263}
2264
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002265TEST_F(VoiceChannelTest, SendBundleToBundleSecure) {
2266 Base::SendBundleToBundle(kAudioPts, ARRAY_SIZE(kAudioPts), false, true);
2267}
2268
2269TEST_F(VoiceChannelTest, SendBundleToBundleWithRtcpMux) {
2270 Base::SendBundleToBundle(
2271 kAudioPts, ARRAY_SIZE(kAudioPts), true, false);
2272}
2273
2274TEST_F(VoiceChannelTest, SendBundleToBundleWithRtcpMuxSecure) {
2275 Base::SendBundleToBundle(
2276 kAudioPts, ARRAY_SIZE(kAudioPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002277}
2278
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002279// VideoChannelTest
2280TEST_F(VideoChannelTest, TestInit) {
2281 Base::TestInit();
2282}
2283
2284TEST_F(VideoChannelTest, TestSetContents) {
2285 Base::TestSetContents();
2286}
2287
2288TEST_F(VideoChannelTest, TestSetContentsNullOffer) {
2289 Base::TestSetContentsNullOffer();
2290}
2291
2292TEST_F(VideoChannelTest, TestSetContentsRtcpMux) {
2293 Base::TestSetContentsRtcpMux();
2294}
2295
2296TEST_F(VideoChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
2297 Base::TestSetContentsRtcpMux();
2298}
2299
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002300TEST_F(VideoChannelTest, TestSetRemoteContentUpdate) {
2301 Base::TestSetRemoteContentUpdate();
2302}
2303
2304TEST_F(VideoChannelTest, TestStreams) {
2305 Base::TestStreams();
2306}
2307
2308TEST_F(VideoChannelTest, TestScreencastEvents) {
2309 const int kTimeoutMs = 500;
2310 TestInit();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002311 cricket::ScreencastEventCatcher catcher;
2312 channel1_->SignalScreencastWindowEvent.connect(
2313 &catcher,
2314 &cricket::ScreencastEventCatcher::OnEvent);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002315
2316 rtc::scoped_ptr<cricket::FakeScreenCapturerFactory>
2317 screen_capturer_factory(new cricket::FakeScreenCapturerFactory());
2318 cricket::VideoCapturer* screen_capturer = screen_capturer_factory->Create(
2319 ScreencastId(WindowId(0)));
2320 ASSERT_TRUE(screen_capturer != NULL);
2321
2322 EXPECT_TRUE(channel1_->AddScreencast(0, screen_capturer));
2323 EXPECT_EQ_WAIT(cricket::CS_STOPPED, screen_capturer_factory->capture_state(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002324 kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002325
2326 screen_capturer->SignalStateChange(screen_capturer, cricket::CS_PAUSED);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002327 EXPECT_EQ_WAIT(rtc::WE_MINIMIZE, catcher.event(), kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002328
2329 screen_capturer->SignalStateChange(screen_capturer, cricket::CS_RUNNING);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002330 EXPECT_EQ_WAIT(rtc::WE_RESTORE, catcher.event(), kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002331
2332 screen_capturer->SignalStateChange(screen_capturer, cricket::CS_STOPPED);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002333 EXPECT_EQ_WAIT(rtc::WE_CLOSE, catcher.event(), kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002334
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002335 EXPECT_TRUE(channel1_->RemoveScreencast(0));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002336}
2337
2338TEST_F(VideoChannelTest, TestUpdateStreamsInLocalContent) {
2339 Base::TestUpdateStreamsInLocalContent();
2340}
2341
2342TEST_F(VideoChannelTest, TestUpdateRemoteStreamsInContent) {
2343 Base::TestUpdateStreamsInRemoteContent();
2344}
2345
2346TEST_F(VideoChannelTest, TestChangeStreamParamsInContent) {
2347 Base::TestChangeStreamParamsInContent();
2348}
2349
2350TEST_F(VideoChannelTest, TestPlayoutAndSendingStates) {
2351 Base::TestPlayoutAndSendingStates();
2352}
2353
2354TEST_F(VideoChannelTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002355 CreateChannels(0, 0);
2356 // Test that we can Mute the default channel even though the sending SSRC
2357 // is unknown.
2358 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2359 EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr));
2360 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2361 EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr));
2362 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2363 // Test that we can not mute an unknown SSRC.
2364 EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, true, nullptr));
2365 SendInitiate();
2366 // After the local session description has been set, we can mute a stream
2367 // with its SSRC.
2368 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr));
2369 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2370 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr));
2371 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002372}
2373
2374TEST_F(VideoChannelTest, TestMediaContentDirection) {
2375 Base::TestMediaContentDirection();
2376}
2377
2378TEST_F(VideoChannelTest, TestCallSetup) {
2379 Base::TestCallSetup();
2380}
2381
2382TEST_F(VideoChannelTest, TestCallTeardownRtcpMux) {
2383 Base::TestCallTeardownRtcpMux();
2384}
2385
2386TEST_F(VideoChannelTest, SendRtpToRtp) {
2387 Base::SendRtpToRtp();
2388}
2389
2390TEST_F(VideoChannelTest, SendNoRtcpToNoRtcp) {
2391 Base::SendNoRtcpToNoRtcp();
2392}
2393
2394TEST_F(VideoChannelTest, SendNoRtcpToRtcp) {
2395 Base::SendNoRtcpToRtcp();
2396}
2397
2398TEST_F(VideoChannelTest, SendRtcpToNoRtcp) {
2399 Base::SendRtcpToNoRtcp();
2400}
2401
2402TEST_F(VideoChannelTest, SendRtcpToRtcp) {
2403 Base::SendRtcpToRtcp();
2404}
2405
2406TEST_F(VideoChannelTest, SendRtcpMuxToRtcp) {
2407 Base::SendRtcpMuxToRtcp();
2408}
2409
2410TEST_F(VideoChannelTest, SendRtcpMuxToRtcpMux) {
2411 Base::SendRtcpMuxToRtcpMux();
2412}
2413
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002414TEST_F(VideoChannelTest, SendRequireRtcpMuxToRtcpMux) {
2415 Base::SendRequireRtcpMuxToRtcpMux();
2416}
2417
2418TEST_F(VideoChannelTest, SendRtcpMuxToRequireRtcpMux) {
2419 Base::SendRtcpMuxToRequireRtcpMux();
2420}
2421
2422TEST_F(VideoChannelTest, SendRequireRtcpMuxToRequireRtcpMux) {
2423 Base::SendRequireRtcpMuxToRequireRtcpMux();
2424}
2425
2426TEST_F(VideoChannelTest, SendRequireRtcpMuxToNoRtcpMux) {
2427 Base::SendRequireRtcpMuxToNoRtcpMux();
2428}
2429
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002430TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcp) {
2431 Base::SendEarlyRtcpMuxToRtcp();
2432}
2433
2434TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2435 Base::SendEarlyRtcpMuxToRtcpMux();
2436}
2437
2438TEST_F(VideoChannelTest, SendSrtpToSrtp) {
2439 Base::SendSrtpToSrtp();
2440}
2441
2442TEST_F(VideoChannelTest, SendSrtpToRtp) {
2443 Base::SendSrtpToSrtp();
2444}
2445
2446TEST_F(VideoChannelTest, SendDtlsSrtpToSrtp) {
2447 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2448 Base::SendSrtpToSrtp(DTLS, 0);
2449}
2450
2451TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtp) {
2452 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2453 Base::SendSrtpToSrtp(DTLS, DTLS);
2454}
2455
2456TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2457 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2458 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2459}
2460
2461TEST_F(VideoChannelTest, SendSrtcpMux) {
2462 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2463}
2464
2465TEST_F(VideoChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2466 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2467}
2468
2469TEST_F(VideoChannelTest, SendRtpToRtpOnThread) {
2470 Base::SendRtpToRtpOnThread();
2471}
2472
2473TEST_F(VideoChannelTest, SendSrtpToSrtpOnThread) {
2474 Base::SendSrtpToSrtpOnThread();
2475}
2476
2477TEST_F(VideoChannelTest, SendWithWritabilityLoss) {
2478 Base::SendWithWritabilityLoss();
2479}
2480
2481TEST_F(VideoChannelTest, TestMediaMonitor) {
2482 Base::TestMediaMonitor();
2483}
2484
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002485TEST_F(VideoChannelTest, TestSetContentFailure) {
2486 Base::TestSetContentFailure();
2487}
2488
2489TEST_F(VideoChannelTest, TestSendTwoOffers) {
2490 Base::TestSendTwoOffers();
2491}
2492
2493TEST_F(VideoChannelTest, TestReceiveTwoOffers) {
2494 Base::TestReceiveTwoOffers();
2495}
2496
2497TEST_F(VideoChannelTest, TestSendPrAnswer) {
2498 Base::TestSendPrAnswer();
2499}
2500
2501TEST_F(VideoChannelTest, TestReceivePrAnswer) {
2502 Base::TestReceivePrAnswer();
2503}
2504
2505TEST_F(VideoChannelTest, TestFlushRtcp) {
2506 Base::TestFlushRtcp();
2507}
2508
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002509TEST_F(VideoChannelTest, SendBundleToBundle) {
2510 Base::SendBundleToBundle(kVideoPts, ARRAY_SIZE(kVideoPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002511}
2512
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002513TEST_F(VideoChannelTest, SendBundleToBundleSecure) {
2514 Base::SendBundleToBundle(kVideoPts, ARRAY_SIZE(kVideoPts), false, true);
2515}
2516
2517TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMux) {
2518 Base::SendBundleToBundle(
2519 kVideoPts, ARRAY_SIZE(kVideoPts), true, false);
2520}
2521
2522TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMuxSecure) {
2523 Base::SendBundleToBundle(
2524 kVideoPts, ARRAY_SIZE(kVideoPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002525}
2526
2527// TODO(gangji): Add VideoChannelTest.TestChangeStateError.
2528
2529TEST_F(VideoChannelTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002530 Base::TestSrtpError(kVideoPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002531}
2532
2533TEST_F(VideoChannelTest, TestOnReadyToSend) {
2534 Base::TestOnReadyToSend();
2535}
2536
2537TEST_F(VideoChannelTest, TestOnReadyToSendWithRtcpMux) {
2538 Base::TestOnReadyToSendWithRtcpMux();
2539}
2540
2541TEST_F(VideoChannelTest, TestApplyViewRequest) {
2542 CreateChannels(0, 0);
2543 cricket::StreamParams stream2;
2544 stream2.id = "stream2";
2545 stream2.ssrcs.push_back(2222);
2546 local_media_content1_.AddStream(stream2);
2547
2548 EXPECT_TRUE(SendInitiate());
2549 EXPECT_TRUE(SendAccept());
2550
2551 cricket::VideoFormat send_format;
2552 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2553 EXPECT_EQ(640, send_format.width);
2554 EXPECT_EQ(400, send_format.height);
2555 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), send_format.interval);
2556
2557 cricket::ViewRequest request;
2558 // stream1: 320x200x15; stream2: 0x0x0
2559 request.static_video_views.push_back(cricket::StaticVideoView(
2560 cricket::StreamSelector(kSsrc1), 320, 200, 15));
2561 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2562 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2563 EXPECT_EQ(320, send_format.width);
2564 EXPECT_EQ(200, send_format.height);
2565 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(15), send_format.interval);
2566 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(2222, &send_format));
2567 EXPECT_EQ(0, send_format.width);
2568 EXPECT_EQ(0, send_format.height);
2569
2570 // stream1: 160x100x8; stream2: 0x0x0
2571 request.static_video_views.clear();
2572 request.static_video_views.push_back(cricket::StaticVideoView(
2573 cricket::StreamSelector(kSsrc1), 160, 100, 8));
2574 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2575 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2576 EXPECT_EQ(160, send_format.width);
2577 EXPECT_EQ(100, send_format.height);
2578 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(8), send_format.interval);
2579
2580 // stream1: 0x0x0; stream2: 640x400x30
2581 request.static_video_views.clear();
2582 request.static_video_views.push_back(cricket::StaticVideoView(
2583 cricket::StreamSelector("", stream2.id), 640, 400, 30));
2584 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2585 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2586 EXPECT_EQ(0, send_format.width);
2587 EXPECT_EQ(0, send_format.height);
2588 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(2222, &send_format));
2589 EXPECT_EQ(640, send_format.width);
2590 EXPECT_EQ(400, send_format.height);
2591 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), send_format.interval);
2592
2593 // stream1: 0x0x0; stream2: 0x0x0
2594 request.static_video_views.clear();
2595 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2596 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2597 EXPECT_EQ(0, send_format.width);
2598 EXPECT_EQ(0, send_format.height);
2599}
2600
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002601
2602// DataChannelTest
2603
2604class DataChannelTest
2605 : public ChannelTest<DataTraits> {
2606 public:
2607 typedef ChannelTest<DataTraits>
2608 Base;
Peter Boström34fbfff2015-09-24 19:20:30 +02002609 DataChannelTest()
2610 : Base(true,
2611 kDataPacket,
2612 sizeof(kDataPacket),
2613 kRtcpReport,
2614 sizeof(kRtcpReport)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002615};
2616
2617// Override to avoid engine channel parameter.
deadbeefcbecd352015-09-23 11:50:27 -07002618template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002619cricket::DataChannel* ChannelTest<DataTraits>::CreateChannel(
deadbeefcbecd352015-09-23 11:50:27 -07002620 rtc::Thread* thread,
2621 cricket::MediaEngineInterface* engine,
2622 cricket::FakeDataMediaChannel* ch,
2623 cricket::TransportController* transport_controller,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002624 bool rtcp) {
2625 cricket::DataChannel* channel = new cricket::DataChannel(
deadbeefcbecd352015-09-23 11:50:27 -07002626 thread, ch, transport_controller, cricket::CN_DATA, rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002627 if (!channel->Init()) {
2628 delete channel;
2629 channel = NULL;
2630 }
2631 return channel;
2632}
2633
2634template<>
2635void ChannelTest<DataTraits>::CreateContent(
2636 int flags,
2637 const cricket::AudioCodec& audio_codec,
2638 const cricket::VideoCodec& video_codec,
2639 cricket::DataContentDescription* data) {
2640 data->AddCodec(kGoogleDataCodec);
2641 data->set_rtcp_mux((flags & RTCP_MUX) != 0);
2642 if (flags & SECURE) {
2643 data->AddCrypto(cricket::CryptoParams(
2644 1, cricket::CS_AES_CM_128_HMAC_SHA1_32,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002645 "inline:" + rtc::CreateRandomString(40), ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002646 }
2647}
2648
2649template<>
2650void ChannelTest<DataTraits>::CopyContent(
2651 const cricket::DataContentDescription& source,
2652 cricket::DataContentDescription* data) {
2653 *data = source;
2654}
2655
2656template<>
2657bool ChannelTest<DataTraits>::CodecMatches(const cricket::DataCodec& c1,
2658 const cricket::DataCodec& c2) {
2659 return c1.name == c2.name;
2660}
2661
2662template<>
2663void ChannelTest<DataTraits>::AddLegacyStreamInContent(
2664 uint32 ssrc, int flags, cricket::DataContentDescription* data) {
2665 data->AddLegacyStream(ssrc);
2666}
2667
2668TEST_F(DataChannelTest, TestInit) {
2669 Base::TestInit();
2670 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2671}
2672
2673TEST_F(DataChannelTest, TestSetContents) {
2674 Base::TestSetContents();
2675}
2676
2677TEST_F(DataChannelTest, TestSetContentsNullOffer) {
2678 Base::TestSetContentsNullOffer();
2679}
2680
2681TEST_F(DataChannelTest, TestSetContentsRtcpMux) {
2682 Base::TestSetContentsRtcpMux();
2683}
2684
2685TEST_F(DataChannelTest, TestSetRemoteContentUpdate) {
2686 Base::TestSetRemoteContentUpdate();
2687}
2688
2689TEST_F(DataChannelTest, TestStreams) {
2690 Base::TestStreams();
2691}
2692
2693TEST_F(DataChannelTest, TestUpdateStreamsInLocalContent) {
2694 Base::TestUpdateStreamsInLocalContent();
2695}
2696
2697TEST_F(DataChannelTest, TestUpdateRemoteStreamsInContent) {
2698 Base::TestUpdateStreamsInRemoteContent();
2699}
2700
2701TEST_F(DataChannelTest, TestChangeStreamParamsInContent) {
2702 Base::TestChangeStreamParamsInContent();
2703}
2704
2705TEST_F(DataChannelTest, TestPlayoutAndSendingStates) {
2706 Base::TestPlayoutAndSendingStates();
2707}
2708
2709TEST_F(DataChannelTest, TestMediaContentDirection) {
2710 Base::TestMediaContentDirection();
2711}
2712
2713TEST_F(DataChannelTest, TestCallSetup) {
2714 Base::TestCallSetup();
2715}
2716
2717TEST_F(DataChannelTest, TestCallTeardownRtcpMux) {
2718 Base::TestCallTeardownRtcpMux();
2719}
2720
2721TEST_F(DataChannelTest, TestOnReadyToSend) {
2722 Base::TestOnReadyToSend();
2723}
2724
2725TEST_F(DataChannelTest, TestOnReadyToSendWithRtcpMux) {
2726 Base::TestOnReadyToSendWithRtcpMux();
2727}
2728
2729TEST_F(DataChannelTest, SendRtpToRtp) {
2730 Base::SendRtpToRtp();
2731}
2732
2733TEST_F(DataChannelTest, SendNoRtcpToNoRtcp) {
2734 Base::SendNoRtcpToNoRtcp();
2735}
2736
2737TEST_F(DataChannelTest, SendNoRtcpToRtcp) {
2738 Base::SendNoRtcpToRtcp();
2739}
2740
2741TEST_F(DataChannelTest, SendRtcpToNoRtcp) {
2742 Base::SendRtcpToNoRtcp();
2743}
2744
2745TEST_F(DataChannelTest, SendRtcpToRtcp) {
2746 Base::SendRtcpToRtcp();
2747}
2748
2749TEST_F(DataChannelTest, SendRtcpMuxToRtcp) {
2750 Base::SendRtcpMuxToRtcp();
2751}
2752
2753TEST_F(DataChannelTest, SendRtcpMuxToRtcpMux) {
2754 Base::SendRtcpMuxToRtcpMux();
2755}
2756
2757TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcp) {
2758 Base::SendEarlyRtcpMuxToRtcp();
2759}
2760
2761TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2762 Base::SendEarlyRtcpMuxToRtcpMux();
2763}
2764
2765TEST_F(DataChannelTest, SendSrtpToSrtp) {
2766 Base::SendSrtpToSrtp();
2767}
2768
2769TEST_F(DataChannelTest, SendSrtpToRtp) {
2770 Base::SendSrtpToSrtp();
2771}
2772
2773TEST_F(DataChannelTest, SendSrtcpMux) {
2774 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2775}
2776
2777TEST_F(DataChannelTest, SendRtpToRtpOnThread) {
2778 Base::SendRtpToRtpOnThread();
2779}
2780
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002781TEST_F(DataChannelTest, SendSrtpToSrtpOnThread) {
2782 Base::SendSrtpToSrtpOnThread();
2783}
2784
2785TEST_F(DataChannelTest, SendWithWritabilityLoss) {
2786 Base::SendWithWritabilityLoss();
2787}
2788
2789TEST_F(DataChannelTest, TestMediaMonitor) {
2790 Base::TestMediaMonitor();
2791}
2792
2793TEST_F(DataChannelTest, TestSendData) {
2794 CreateChannels(0, 0);
2795 EXPECT_TRUE(SendInitiate());
2796 EXPECT_TRUE(SendAccept());
2797
2798 cricket::SendDataParams params;
2799 params.ssrc = 42;
2800 unsigned char data[] = {
2801 'f', 'o', 'o'
2802 };
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002803 rtc::Buffer payload(data, 3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002804 cricket::SendDataResult result;
2805 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
2806 EXPECT_EQ(params.ssrc,
2807 media_channel1_->last_sent_data_params().ssrc);
2808 EXPECT_EQ("foo", media_channel1_->last_sent_data());
2809}
2810
2811// TODO(pthatcher): TestSetReceiver?