blob: d6e259d31e58e0fbc8932a179639269f9d1ac7b5 [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
deadbeefcbecd352015-09-23 11:50:27 -0700129 ChannelTest(const uint8* rtp_data,
130 int rtp_len,
131 const uint8* rtcp_data,
132 int rtcp_len)
133 : transport_controller1_(cricket::ICEROLE_CONTROLLING),
134 transport_controller2_(cricket::ICEROLE_CONTROLLED),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000135 media_channel1_(NULL),
136 media_channel2_(NULL),
137 rtp_packet_(reinterpret_cast<const char*>(rtp_data), rtp_len),
138 rtcp_packet_(reinterpret_cast<const char*>(rtcp_data), rtcp_len),
139 media_info_callbacks1_(),
140 media_info_callbacks2_(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000141 ssrc_(0),
deadbeefcbecd352015-09-23 11:50:27 -0700142 error_(T::MediaChannel::ERROR_NONE) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000143
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000144 void CreateChannels(int flags1, int flags2) {
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200145 CreateChannels(new typename T::MediaChannel(NULL, typename T::Options()),
146 new typename T::MediaChannel(NULL, typename T::Options()),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000147 flags1, flags2, rtc::Thread::Current());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000148 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000149 void CreateChannels(
150 typename T::MediaChannel* ch1, typename T::MediaChannel* ch2,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000151 int flags1, int flags2, rtc::Thread* thread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000152 media_channel1_ = ch1;
153 media_channel2_ = ch2;
deadbeefcbecd352015-09-23 11:50:27 -0700154 channel1_.reset(CreateChannel(thread, &media_engine_, ch1,
155 &transport_controller1_,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000156 (flags1 & RTCP) != 0));
deadbeefcbecd352015-09-23 11:50:27 -0700157 channel2_.reset(CreateChannel(thread, &media_engine_, ch2,
158 &transport_controller2_,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000159 (flags2 & RTCP) != 0));
160 channel1_->SignalMediaMonitor.connect(
161 this, &ChannelTest<T>::OnMediaMonitor);
162 channel2_->SignalMediaMonitor.connect(
163 this, &ChannelTest<T>::OnMediaMonitor);
164 channel1_->SignalMediaError.connect(
165 this, &ChannelTest<T>::OnMediaChannelError);
166 channel2_->SignalMediaError.connect(
167 this, &ChannelTest<T>::OnMediaChannelError);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000168 if ((flags1 & DTLS) && (flags2 & DTLS)) {
169 flags1 = (flags1 & ~SECURE);
170 flags2 = (flags2 & ~SECURE);
171 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000172 CreateContent(flags1, kPcmuCodec, kH264Codec,
173 &local_media_content1_);
174 CreateContent(flags2, kPcmuCodec, kH264Codec,
175 &local_media_content2_);
176 CopyContent(local_media_content1_, &remote_media_content1_);
177 CopyContent(local_media_content2_, &remote_media_content2_);
178
179 if (flags1 & DTLS) {
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200180 // Confirmed to work with KT_RSA and KT_ECDSA.
deadbeefcbecd352015-09-23 11:50:27 -0700181 transport_controller1_.SetLocalCertificate(rtc::RTCCertificate::Create(
182 rtc::scoped_ptr<rtc::SSLIdentity>(
183 rtc::SSLIdentity::Generate("session1", rtc::KT_DEFAULT))
184 .Pass()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000185 }
186 if (flags2 & DTLS) {
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200187 // Confirmed to work with KT_RSA and KT_ECDSA.
deadbeefcbecd352015-09-23 11:50:27 -0700188 transport_controller2_.SetLocalCertificate(rtc::RTCCertificate::Create(
189 rtc::scoped_ptr<rtc::SSLIdentity>(
190 rtc::SSLIdentity::Generate("session2", rtc::KT_DEFAULT))
191 .Pass()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000192 }
193
194 // Add stream information (SSRC) to the local content but not to the remote
195 // content. This means that we per default know the SSRC of what we send but
196 // not what we receive.
197 AddLegacyStreamInContent(kSsrc1, flags1, &local_media_content1_);
198 AddLegacyStreamInContent(kSsrc2, flags2, &local_media_content2_);
199
200 // If SSRC_MUX is used we also need to know the SSRC of the incoming stream.
201 if (flags1 & SSRC_MUX) {
202 AddLegacyStreamInContent(kSsrc1, flags1, &remote_media_content1_);
203 }
204 if (flags2 & SSRC_MUX) {
205 AddLegacyStreamInContent(kSsrc2, flags2, &remote_media_content2_);
206 }
207 }
deadbeefcbecd352015-09-23 11:50:27 -0700208 typename T::Channel* CreateChannel(
209 rtc::Thread* thread,
210 cricket::MediaEngineInterface* engine,
211 typename T::MediaChannel* ch,
212 cricket::TransportController* transport_controller,
213 bool rtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000214 typename T::Channel* channel = new typename T::Channel(
deadbeefcbecd352015-09-23 11:50:27 -0700215 thread, engine, ch, transport_controller, cricket::CN_AUDIO, rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000216 if (!channel->Init()) {
217 delete channel;
218 channel = NULL;
219 }
220 return channel;
221 }
222
223 bool SendInitiate() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000224 bool result = channel1_->SetLocalContent(&local_media_content1_,
225 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000226 if (result) {
227 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000228 result = channel2_->SetRemoteContent(&remote_media_content1_,
229 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000230 if (result) {
deadbeefcbecd352015-09-23 11:50:27 -0700231 transport_controller1_.Connect(&transport_controller2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000232
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000233 result = channel2_->SetLocalContent(&local_media_content2_,
234 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000235 }
236 }
237 return result;
238 }
239
240 bool SendAccept() {
241 channel2_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000242 return channel1_->SetRemoteContent(&remote_media_content2_,
243 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000244 }
245
246 bool SendOffer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000247 bool result = channel1_->SetLocalContent(&local_media_content1_,
248 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000249 if (result) {
250 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000251 result = channel2_->SetRemoteContent(&remote_media_content1_,
252 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000253 }
254 return result;
255 }
256
257 bool SendProvisionalAnswer() {
258 bool result = channel2_->SetLocalContent(&local_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000259 CA_PRANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000260 if (result) {
261 channel2_->Enable(true);
262 result = channel1_->SetRemoteContent(&remote_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000263 CA_PRANSWER, NULL);
deadbeefcbecd352015-09-23 11:50:27 -0700264 transport_controller1_.Connect(&transport_controller2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000265 }
266 return result;
267 }
268
269 bool SendFinalAnswer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000270 bool result = channel2_->SetLocalContent(&local_media_content2_,
271 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000272 if (result)
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000273 result = channel1_->SetRemoteContent(&remote_media_content2_,
274 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000275 return result;
276 }
277
278 bool SendTerminate() {
279 channel1_.reset();
280 channel2_.reset();
281 return true;
282 }
283
284 bool AddStream1(int id) {
285 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
286 }
287 bool RemoveStream1(int id) {
288 return channel1_->RemoveRecvStream(id);
289 }
290
deadbeefcbecd352015-09-23 11:50:27 -0700291 // Calling "_w" method here is ok since we only use one thread for this test
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000292 cricket::FakeTransport* GetTransport1() {
deadbeefcbecd352015-09-23 11:50:27 -0700293 return transport_controller1_.GetTransport_w(channel1_->content_name());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000294 }
295 cricket::FakeTransport* GetTransport2() {
deadbeefcbecd352015-09-23 11:50:27 -0700296 return transport_controller2_.GetTransport_w(channel2_->content_name());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000297 }
298
299 bool SendRtp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000300 return media_channel1_->SendRtp(rtp_packet_.c_str(),
301 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000302 }
303 bool SendRtp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000304 return media_channel2_->SendRtp(rtp_packet_.c_str(),
305 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000306 }
307 bool SendRtcp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000308 return media_channel1_->SendRtcp(rtcp_packet_.c_str(),
309 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000310 }
311 bool SendRtcp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000312 return media_channel2_->SendRtcp(rtcp_packet_.c_str(),
313 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000314 }
315 // Methods to send custom data.
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000316 bool SendCustomRtp1(uint32 ssrc, int sequence_number, int pl_type = -1) {
317 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000318 return media_channel1_->SendRtp(data.c_str(),
319 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000320 }
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000321 bool SendCustomRtp2(uint32 ssrc, int sequence_number, int pl_type = -1) {
322 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000323 return media_channel2_->SendRtp(data.c_str(),
324 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000325 }
326 bool SendCustomRtcp1(uint32 ssrc) {
327 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000328 return media_channel1_->SendRtcp(data.c_str(),
329 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000330 }
331 bool SendCustomRtcp2(uint32 ssrc) {
332 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000333 return media_channel2_->SendRtcp(data.c_str(),
334 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000335 }
336 bool CheckRtp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000337 return media_channel1_->CheckRtp(rtp_packet_.c_str(),
338 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000339 }
340 bool CheckRtp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000341 return media_channel2_->CheckRtp(rtp_packet_.c_str(),
342 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000343 }
344 bool CheckRtcp1() {
345 return media_channel1_->CheckRtcp(rtcp_packet_.c_str(),
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000346 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000347 }
348 bool CheckRtcp2() {
349 return media_channel2_->CheckRtcp(rtcp_packet_.c_str(),
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000350 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000351 }
352 // Methods to check custom data.
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000353 bool CheckCustomRtp1(uint32 ssrc, int sequence_number, int pl_type = -1 ) {
354 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000355 return media_channel1_->CheckRtp(data.c_str(),
356 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000357 }
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000358 bool CheckCustomRtp2(uint32 ssrc, int sequence_number, int pl_type = -1) {
359 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000360 return media_channel2_->CheckRtp(data.c_str(),
361 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000362 }
363 bool CheckCustomRtcp1(uint32 ssrc) {
364 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000365 return media_channel1_->CheckRtcp(data.c_str(),
366 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000367 }
368 bool CheckCustomRtcp2(uint32 ssrc) {
369 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000370 return media_channel2_->CheckRtcp(data.c_str(),
371 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000372 }
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000373 std::string CreateRtpData(uint32 ssrc, int sequence_number, int pl_type) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000374 std::string data(rtp_packet_);
375 // Set SSRC in the rtp packet copy.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000376 rtc::SetBE32(const_cast<char*>(data.c_str()) + 8, ssrc);
377 rtc::SetBE16(const_cast<char*>(data.c_str()) + 2, sequence_number);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000378 if (pl_type >= 0) {
pkasting@chromium.org0e81fdf2015-02-02 23:54:03 +0000379 rtc::Set8(const_cast<char*>(data.c_str()), 1,
380 static_cast<uint8_t>(pl_type));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000381 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000382 return data;
383 }
384 std::string CreateRtcpData(uint32 ssrc) {
385 std::string data(rtcp_packet_);
386 // Set SSRC in the rtcp packet copy.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000387 rtc::SetBE32(const_cast<char*>(data.c_str()) + 4, ssrc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000388 return data;
389 }
390
391 bool CheckNoRtp1() {
392 return media_channel1_->CheckNoRtp();
393 }
394 bool CheckNoRtp2() {
395 return media_channel2_->CheckNoRtp();
396 }
397 bool CheckNoRtcp1() {
398 return media_channel1_->CheckNoRtcp();
399 }
400 bool CheckNoRtcp2() {
401 return media_channel2_->CheckNoRtcp();
402 }
403
404 void CreateContent(int flags,
405 const cricket::AudioCodec& audio_codec,
406 const cricket::VideoCodec& video_codec,
407 typename T::Content* content) {
408 // overridden in specialized classes
409 }
410 void CopyContent(const typename T::Content& source,
411 typename T::Content* content) {
412 // overridden in specialized classes
413 }
414
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000415 // Creates a cricket::SessionDescription with one MediaContent and one stream.
416 // kPcmuCodec is used as audio codec and kH264Codec is used as video codec.
417 cricket::SessionDescription* CreateSessionDescriptionWithStream(uint32 ssrc) {
418 typename T::Content content;
419 cricket::SessionDescription* sdesc = new cricket::SessionDescription();
420 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content);
421 AddLegacyStreamInContent(ssrc, 0, &content);
422 sdesc->AddContent("DUMMY_CONTENT_NAME",
423 cricket::NS_JINGLE_RTP, content.Copy());
424 return sdesc;
425 }
426
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000427 class CallThread : public rtc::SignalThread {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000428 public:
429 typedef bool (ChannelTest<T>::*Method)();
430 CallThread(ChannelTest<T>* obj, Method method, bool* result)
431 : obj_(obj),
432 method_(method),
433 result_(result) {
434 *result = false;
435 }
436 virtual void DoWork() {
437 bool result = (*obj_.*method_)();
438 if (result_) {
439 *result_ = result;
440 }
441 }
442 private:
443 ChannelTest<T>* obj_;
444 Method method_;
445 bool* result_;
446 };
447 void CallOnThread(typename CallThread::Method method, bool* result) {
448 CallThread* thread = new CallThread(this, method, result);
449 thread->Start();
450 thread->Release();
451 }
452
453 void CallOnThreadAndWaitForDone(typename CallThread::Method method,
454 bool* result) {
455 CallThread* thread = new CallThread(this, method, result);
456 thread->Start();
457 thread->Destroy(true);
458 }
459
460 bool CodecMatches(const typename T::Codec& c1, const typename T::Codec& c2) {
461 return false; // overridden in specialized classes
462 }
463
464 void OnMediaMonitor(typename T::Channel* channel,
465 const typename T::MediaInfo& info) {
466 if (channel == channel1_.get()) {
467 media_info_callbacks1_++;
468 } else if (channel == channel2_.get()) {
469 media_info_callbacks2_++;
470 }
471 }
472
473 void OnMediaChannelError(typename T::Channel* channel,
474 uint32 ssrc,
475 typename T::MediaChannel::Error error) {
476 ssrc_ = ssrc;
477 error_ = error;
478 }
479
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000480 void AddLegacyStreamInContent(uint32 ssrc, int flags,
481 typename T::Content* content) {
482 // Base implementation.
483 }
484
485 // Tests that can be used by derived classes.
486
487 // Basic sanity check.
488 void TestInit() {
489 CreateChannels(0, 0);
490 EXPECT_FALSE(channel1_->secure());
491 EXPECT_FALSE(media_channel1_->sending());
492 EXPECT_FALSE(media_channel1_->playout());
493 EXPECT_TRUE(media_channel1_->codecs().empty());
494 EXPECT_TRUE(media_channel1_->recv_streams().empty());
495 EXPECT_TRUE(media_channel1_->rtp_packets().empty());
496 EXPECT_TRUE(media_channel1_->rtcp_packets().empty());
497 }
498
499 // Test that SetLocalContent and SetRemoteContent properly configure
500 // the codecs.
501 void TestSetContents() {
502 CreateChannels(0, 0);
503 typename T::Content content;
504 CreateContent(0, kPcmuCodec, kH264Codec, &content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000505 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000506 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000507 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000508 ASSERT_EQ(1U, media_channel1_->codecs().size());
509 EXPECT_TRUE(CodecMatches(content.codecs()[0],
510 media_channel1_->codecs()[0]));
511 }
512
513 // Test that SetLocalContent and SetRemoteContent properly deals
514 // with an empty offer.
515 void TestSetContentsNullOffer() {
516 CreateChannels(0, 0);
517 typename T::Content content;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000518 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000519 CreateContent(0, kPcmuCodec, kH264Codec, &content);
520 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000521 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000522 ASSERT_EQ(1U, media_channel1_->codecs().size());
523 EXPECT_TRUE(CodecMatches(content.codecs()[0],
524 media_channel1_->codecs()[0]));
525 }
526
527 // Test that SetLocalContent and SetRemoteContent properly set RTCP
528 // mux.
529 void TestSetContentsRtcpMux() {
530 CreateChannels(RTCP, RTCP);
531 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
532 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
533 typename T::Content content;
534 CreateContent(0, kPcmuCodec, kH264Codec, &content);
535 // Both sides agree on mux. Should no longer be a separate RTCP channel.
536 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000537 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
538 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000539 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
540 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000541 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000542 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000543 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000544 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
545 }
546
547 // Test that SetLocalContent and SetRemoteContent properly set RTCP
548 // mux when a provisional answer is received.
549 void TestSetContentsRtcpMuxWithPrAnswer() {
550 CreateChannels(RTCP, RTCP);
551 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
552 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
553 typename T::Content content;
554 CreateContent(0, kPcmuCodec, kH264Codec, &content);
555 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000556 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
557 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000558 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000559 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000560 // Both sides agree on mux. Should no longer be a separate RTCP channel.
561 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
562 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000563 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000564 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000565 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_PRANSWER, NULL));
566 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000567 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
568 }
569
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000570 // Test that SetRemoteContent properly deals with a content update.
571 void TestSetRemoteContentUpdate() {
572 CreateChannels(0, 0);
573 typename T::Content content;
574 CreateContent(RTCP | RTCP_MUX | SECURE,
575 kPcmuCodec, kH264Codec,
576 &content);
577 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000578 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
579 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000580 ASSERT_EQ(1U, media_channel1_->codecs().size());
581 EXPECT_TRUE(CodecMatches(content.codecs()[0],
582 media_channel1_->codecs()[0]));
583 // Now update with other codecs.
584 typename T::Content update_content;
585 update_content.set_partial(true);
586 CreateContent(0, kIsacCodec, kH264SvcCodec,
587 &update_content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000588 EXPECT_TRUE(channel1_->SetRemoteContent(&update_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000589 ASSERT_EQ(1U, media_channel1_->codecs().size());
590 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
591 media_channel1_->codecs()[0]));
592 // Now update without any codecs. This is ignored.
593 typename T::Content empty_content;
594 empty_content.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000595 EXPECT_TRUE(channel1_->SetRemoteContent(&empty_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000596 ASSERT_EQ(1U, media_channel1_->codecs().size());
597 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
598 media_channel1_->codecs()[0]));
599 }
600
601 // Test that Add/RemoveStream properly forward to the media channel.
602 void TestStreams() {
603 CreateChannels(0, 0);
604 EXPECT_TRUE(AddStream1(1));
605 EXPECT_TRUE(AddStream1(2));
606 EXPECT_EQ(2U, media_channel1_->recv_streams().size());
607 EXPECT_TRUE(RemoveStream1(2));
608 EXPECT_EQ(1U, media_channel1_->recv_streams().size());
609 EXPECT_TRUE(RemoveStream1(1));
610 EXPECT_EQ(0U, media_channel1_->recv_streams().size());
611 }
612
613 // Test that SetLocalContent properly handles adding and removing StreamParams
614 // to the local content description.
615 // This test uses the CA_UPDATE action that don't require a full
616 // MediaContentDescription to do an update.
617 void TestUpdateStreamsInLocalContent() {
618 cricket::StreamParams stream1;
619 stream1.groupid = "group1";
620 stream1.id = "stream1";
621 stream1.ssrcs.push_back(kSsrc1);
622 stream1.cname = "stream1_cname";
623
624 cricket::StreamParams stream2;
625 stream2.groupid = "group2";
626 stream2.id = "stream2";
627 stream2.ssrcs.push_back(kSsrc2);
628 stream2.cname = "stream2_cname";
629
630 cricket::StreamParams stream3;
631 stream3.groupid = "group3";
632 stream3.id = "stream3";
633 stream3.ssrcs.push_back(kSsrc3);
634 stream3.cname = "stream3_cname";
635
636 CreateChannels(0, 0);
637 typename T::Content content1;
638 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
639 content1.AddStream(stream1);
640 EXPECT_EQ(0u, media_channel1_->send_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000641 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000642
643 ASSERT_EQ(1u, media_channel1_->send_streams().size());
644 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
645
646 // Update the local streams by adding another sending stream.
647 // Use a partial updated session description.
648 typename T::Content content2;
649 content2.AddStream(stream2);
650 content2.AddStream(stream3);
651 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000652 EXPECT_TRUE(channel1_->SetLocalContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000653 ASSERT_EQ(3u, media_channel1_->send_streams().size());
654 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
655 EXPECT_EQ(stream2, media_channel1_->send_streams()[1]);
656 EXPECT_EQ(stream3, media_channel1_->send_streams()[2]);
657
658 // Update the local streams by removing the first sending stream.
659 // This is done by removing all SSRCS for this particular stream.
660 typename T::Content content3;
661 stream1.ssrcs.clear();
662 content3.AddStream(stream1);
663 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000664 EXPECT_TRUE(channel1_->SetLocalContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000665 ASSERT_EQ(2u, media_channel1_->send_streams().size());
666 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
667 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
668
669 // Update the local streams with a stream that does not change.
670 // THe update is ignored.
671 typename T::Content content4;
672 content4.AddStream(stream2);
673 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000674 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000675 ASSERT_EQ(2u, media_channel1_->send_streams().size());
676 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
677 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
678 }
679
680 // Test that SetRemoteContent properly handles adding and removing
681 // StreamParams to the remote content description.
682 // This test uses the CA_UPDATE action that don't require a full
683 // MediaContentDescription to do an update.
684 void TestUpdateStreamsInRemoteContent() {
685 cricket::StreamParams stream1;
686 stream1.id = "Stream1";
687 stream1.groupid = "1";
688 stream1.ssrcs.push_back(kSsrc1);
689 stream1.cname = "stream1_cname";
690
691 cricket::StreamParams stream2;
692 stream2.id = "Stream2";
693 stream2.groupid = "2";
694 stream2.ssrcs.push_back(kSsrc2);
695 stream2.cname = "stream2_cname";
696
697 cricket::StreamParams stream3;
698 stream3.id = "Stream3";
699 stream3.groupid = "3";
700 stream3.ssrcs.push_back(kSsrc3);
701 stream3.cname = "stream3_cname";
702
703 CreateChannels(0, 0);
704 typename T::Content content1;
705 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
706 content1.AddStream(stream1);
707 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000708 EXPECT_TRUE(channel1_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000709
710 ASSERT_EQ(1u, media_channel1_->codecs().size());
711 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
712 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
713
714 // Update the remote streams by adding another sending stream.
715 // Use a partial updated session description.
716 typename T::Content content2;
717 content2.AddStream(stream2);
718 content2.AddStream(stream3);
719 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000720 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000721 ASSERT_EQ(3u, media_channel1_->recv_streams().size());
722 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
723 EXPECT_EQ(stream2, media_channel1_->recv_streams()[1]);
724 EXPECT_EQ(stream3, media_channel1_->recv_streams()[2]);
725
726 // Update the remote streams by removing the first stream.
727 // This is done by removing all SSRCS for this particular stream.
728 typename T::Content content3;
729 stream1.ssrcs.clear();
730 content3.AddStream(stream1);
731 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000732 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000733 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
734 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
735 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
736
737 // Update the remote streams with a stream that does not change.
738 // The update is ignored.
739 typename T::Content content4;
740 content4.AddStream(stream2);
741 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000742 EXPECT_TRUE(channel1_->SetRemoteContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000743 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
744 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
745 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
746 }
747
748 // Test that SetLocalContent and SetRemoteContent properly
749 // handles adding and removing StreamParams when the action is a full
750 // CA_OFFER / CA_ANSWER.
751 void TestChangeStreamParamsInContent() {
752 cricket::StreamParams stream1;
753 stream1.groupid = "group1";
754 stream1.id = "stream1";
755 stream1.ssrcs.push_back(kSsrc1);
756 stream1.cname = "stream1_cname";
757
758 cricket::StreamParams stream2;
759 stream2.groupid = "group1";
760 stream2.id = "stream2";
761 stream2.ssrcs.push_back(kSsrc2);
762 stream2.cname = "stream2_cname";
763
764 // Setup a call where channel 1 send |stream1| to channel 2.
765 CreateChannels(0, 0);
766 typename T::Content content1;
767 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
768 content1.AddStream(stream1);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000769 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000770 EXPECT_TRUE(channel1_->Enable(true));
771 EXPECT_EQ(1u, media_channel1_->send_streams().size());
772
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000773 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000774 EXPECT_EQ(1u, media_channel2_->recv_streams().size());
deadbeefcbecd352015-09-23 11:50:27 -0700775 transport_controller1_.Connect(&transport_controller2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000776
777 // Channel 2 do not send anything.
778 typename T::Content content2;
779 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000780 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000781 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000782 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000783 EXPECT_TRUE(channel2_->Enable(true));
784 EXPECT_EQ(0u, media_channel2_->send_streams().size());
785
786 EXPECT_TRUE(SendCustomRtp1(kSsrc1, 0));
787 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, 0));
788
789 // Let channel 2 update the content by sending |stream2| and enable SRTP.
790 typename T::Content content3;
791 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content3);
792 content3.AddStream(stream2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000793 EXPECT_TRUE(channel2_->SetLocalContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000794 ASSERT_EQ(1u, media_channel2_->send_streams().size());
795 EXPECT_EQ(stream2, media_channel2_->send_streams()[0]);
796
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000797 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000798 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
799 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
800
801 // Channel 1 replies but stop sending stream1.
802 typename T::Content content4;
803 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content4);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000804 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000805 EXPECT_EQ(0u, media_channel1_->send_streams().size());
806
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000807 EXPECT_TRUE(channel2_->SetRemoteContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000808 EXPECT_EQ(0u, media_channel2_->recv_streams().size());
809
810 EXPECT_TRUE(channel1_->secure());
811 EXPECT_TRUE(channel2_->secure());
812 EXPECT_TRUE(SendCustomRtp2(kSsrc2, 0));
813 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, 0));
814 }
815
816 // Test that we only start playout and sending at the right times.
817 void TestPlayoutAndSendingStates() {
818 CreateChannels(0, 0);
819 EXPECT_FALSE(media_channel1_->playout());
820 EXPECT_FALSE(media_channel1_->sending());
821 EXPECT_FALSE(media_channel2_->playout());
822 EXPECT_FALSE(media_channel2_->sending());
823 EXPECT_TRUE(channel1_->Enable(true));
824 EXPECT_FALSE(media_channel1_->playout());
825 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000826 EXPECT_TRUE(channel1_->SetLocalContent(&local_media_content1_,
827 CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000828 EXPECT_TRUE(media_channel1_->playout());
829 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000830 EXPECT_TRUE(channel2_->SetRemoteContent(&local_media_content1_,
831 CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000832 EXPECT_FALSE(media_channel2_->playout());
833 EXPECT_FALSE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000834 EXPECT_TRUE(channel2_->SetLocalContent(&local_media_content2_,
835 CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000836 EXPECT_FALSE(media_channel2_->playout());
837 EXPECT_FALSE(media_channel2_->sending());
deadbeefcbecd352015-09-23 11:50:27 -0700838 transport_controller1_.Connect(&transport_controller2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000839 EXPECT_TRUE(media_channel1_->playout());
840 EXPECT_FALSE(media_channel1_->sending());
841 EXPECT_FALSE(media_channel2_->playout());
842 EXPECT_FALSE(media_channel2_->sending());
843 EXPECT_TRUE(channel2_->Enable(true));
844 EXPECT_TRUE(media_channel2_->playout());
845 EXPECT_TRUE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000846 EXPECT_TRUE(channel1_->SetRemoteContent(&local_media_content2_,
847 CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000848 EXPECT_TRUE(media_channel1_->playout());
849 EXPECT_TRUE(media_channel1_->sending());
850 }
851
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000852 // Test that changing the MediaContentDirection in the local and remote
853 // session description start playout and sending at the right time.
854 void TestMediaContentDirection() {
855 CreateChannels(0, 0);
856 typename T::Content content1;
857 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
858 typename T::Content content2;
859 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
860 // Set |content2| to be InActive.
861 content2.set_direction(cricket::MD_INACTIVE);
862
863 EXPECT_TRUE(channel1_->Enable(true));
864 EXPECT_TRUE(channel2_->Enable(true));
865 EXPECT_FALSE(media_channel1_->playout());
866 EXPECT_FALSE(media_channel1_->sending());
867 EXPECT_FALSE(media_channel2_->playout());
868 EXPECT_FALSE(media_channel2_->sending());
869
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000870 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
871 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
872 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
873 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700874 transport_controller1_.Connect(&transport_controller2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000875
876 EXPECT_TRUE(media_channel1_->playout());
877 EXPECT_FALSE(media_channel1_->sending()); // remote InActive
878 EXPECT_FALSE(media_channel2_->playout()); // local InActive
879 EXPECT_FALSE(media_channel2_->sending()); // local InActive
880
881 // Update |content2| to be RecvOnly.
882 content2.set_direction(cricket::MD_RECVONLY);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000883 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
884 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000885
886 EXPECT_TRUE(media_channel1_->playout());
887 EXPECT_TRUE(media_channel1_->sending());
888 EXPECT_TRUE(media_channel2_->playout()); // local RecvOnly
889 EXPECT_FALSE(media_channel2_->sending()); // local RecvOnly
890
891 // Update |content2| to be SendRecv.
892 content2.set_direction(cricket::MD_SENDRECV);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000893 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
894 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000895
896 EXPECT_TRUE(media_channel1_->playout());
897 EXPECT_TRUE(media_channel1_->sending());
898 EXPECT_TRUE(media_channel2_->playout());
899 EXPECT_TRUE(media_channel2_->sending());
900 }
901
902 // Test setting up a call.
903 void TestCallSetup() {
904 CreateChannels(0, 0);
905 EXPECT_FALSE(channel1_->secure());
906 EXPECT_TRUE(SendInitiate());
907 EXPECT_TRUE(media_channel1_->playout());
908 EXPECT_FALSE(media_channel1_->sending());
909 EXPECT_TRUE(SendAccept());
910 EXPECT_FALSE(channel1_->secure());
911 EXPECT_TRUE(media_channel1_->sending());
912 EXPECT_EQ(1U, media_channel1_->codecs().size());
913 EXPECT_TRUE(media_channel2_->playout());
914 EXPECT_TRUE(media_channel2_->sending());
915 EXPECT_EQ(1U, media_channel2_->codecs().size());
916 }
917
918 // Test that we don't crash if packets are sent during call teardown
919 // when RTCP mux is enabled. This is a regression test against a specific
920 // race condition that would only occur when a RTCP packet was sent during
921 // teardown of a channel on which RTCP mux was enabled.
922 void TestCallTeardownRtcpMux() {
923 class LastWordMediaChannel : public T::MediaChannel {
924 public:
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200925 LastWordMediaChannel() : T::MediaChannel(NULL, typename T::Options()) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000926 ~LastWordMediaChannel() {
927 T::MediaChannel::SendRtp(kPcmuFrame, sizeof(kPcmuFrame));
928 T::MediaChannel::SendRtcp(kRtcpReport, sizeof(kRtcpReport));
929 }
930 };
931 CreateChannels(new LastWordMediaChannel(), new LastWordMediaChannel(),
932 RTCP | RTCP_MUX, RTCP | RTCP_MUX,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000933 rtc::Thread::Current());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000934 EXPECT_TRUE(SendInitiate());
935 EXPECT_TRUE(SendAccept());
936 EXPECT_TRUE(SendTerminate());
937 }
938
939 // Send voice RTP data to the other side and ensure it gets there.
940 void SendRtpToRtp() {
941 CreateChannels(0, 0);
942 EXPECT_TRUE(SendInitiate());
943 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -0700944 ASSERT_TRUE(GetTransport1());
945 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000946 EXPECT_EQ(1U, GetTransport1()->channels().size());
947 EXPECT_EQ(1U, GetTransport2()->channels().size());
948 EXPECT_TRUE(SendRtp1());
949 EXPECT_TRUE(SendRtp2());
950 EXPECT_TRUE(CheckRtp1());
951 EXPECT_TRUE(CheckRtp2());
952 EXPECT_TRUE(CheckNoRtp1());
953 EXPECT_TRUE(CheckNoRtp2());
954 }
955
956 // Check that RTCP is not transmitted if both sides don't support RTCP.
957 void SendNoRtcpToNoRtcp() {
958 CreateChannels(0, 0);
959 EXPECT_TRUE(SendInitiate());
960 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -0700961 ASSERT_TRUE(GetTransport1());
962 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000963 EXPECT_EQ(1U, GetTransport1()->channels().size());
964 EXPECT_EQ(1U, GetTransport2()->channels().size());
965 EXPECT_FALSE(SendRtcp1());
966 EXPECT_FALSE(SendRtcp2());
967 EXPECT_TRUE(CheckNoRtcp1());
968 EXPECT_TRUE(CheckNoRtcp2());
969 }
970
971 // Check that RTCP is not transmitted if the callee doesn't support RTCP.
972 void SendNoRtcpToRtcp() {
973 CreateChannels(0, RTCP);
974 EXPECT_TRUE(SendInitiate());
975 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -0700976 ASSERT_TRUE(GetTransport1());
977 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000978 EXPECT_EQ(1U, GetTransport1()->channels().size());
979 EXPECT_EQ(2U, GetTransport2()->channels().size());
980 EXPECT_FALSE(SendRtcp1());
981 EXPECT_FALSE(SendRtcp2());
982 EXPECT_TRUE(CheckNoRtcp1());
983 EXPECT_TRUE(CheckNoRtcp2());
984 }
985
986 // Check that RTCP is not transmitted if the caller doesn't support RTCP.
987 void SendRtcpToNoRtcp() {
988 CreateChannels(RTCP, 0);
989 EXPECT_TRUE(SendInitiate());
990 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -0700991 ASSERT_TRUE(GetTransport1());
992 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000993 EXPECT_EQ(2U, GetTransport1()->channels().size());
994 EXPECT_EQ(1U, GetTransport2()->channels().size());
995 EXPECT_FALSE(SendRtcp1());
996 EXPECT_FALSE(SendRtcp2());
997 EXPECT_TRUE(CheckNoRtcp1());
998 EXPECT_TRUE(CheckNoRtcp2());
999 }
1000
1001 // Check that RTCP is transmitted if both sides support RTCP.
1002 void SendRtcpToRtcp() {
1003 CreateChannels(RTCP, RTCP);
1004 EXPECT_TRUE(SendInitiate());
1005 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001006 ASSERT_TRUE(GetTransport1());
1007 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001008 EXPECT_EQ(2U, GetTransport1()->channels().size());
1009 EXPECT_EQ(2U, GetTransport2()->channels().size());
1010 EXPECT_TRUE(SendRtcp1());
1011 EXPECT_TRUE(SendRtcp2());
1012 EXPECT_TRUE(CheckRtcp1());
1013 EXPECT_TRUE(CheckRtcp2());
1014 EXPECT_TRUE(CheckNoRtcp1());
1015 EXPECT_TRUE(CheckNoRtcp2());
1016 }
1017
1018 // Check that RTCP is transmitted if only the initiator supports mux.
1019 void SendRtcpMuxToRtcp() {
1020 CreateChannels(RTCP | RTCP_MUX, RTCP);
1021 EXPECT_TRUE(SendInitiate());
1022 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001023 ASSERT_TRUE(GetTransport1());
1024 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001025 EXPECT_EQ(2U, GetTransport1()->channels().size());
1026 EXPECT_EQ(2U, GetTransport2()->channels().size());
1027 EXPECT_TRUE(SendRtcp1());
1028 EXPECT_TRUE(SendRtcp2());
1029 EXPECT_TRUE(CheckRtcp1());
1030 EXPECT_TRUE(CheckRtcp2());
1031 EXPECT_TRUE(CheckNoRtcp1());
1032 EXPECT_TRUE(CheckNoRtcp2());
1033 }
1034
1035 // Check that RTP and RTCP are transmitted ok when both sides support mux.
1036 void SendRtcpMuxToRtcpMux() {
1037 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1038 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001039 ASSERT_TRUE(GetTransport1());
1040 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001041 EXPECT_EQ(2U, GetTransport1()->channels().size());
1042 EXPECT_EQ(1U, GetTransport2()->channels().size());
1043 EXPECT_TRUE(SendAccept());
1044 EXPECT_EQ(1U, GetTransport1()->channels().size());
1045 EXPECT_TRUE(SendRtp1());
1046 EXPECT_TRUE(SendRtp2());
1047 EXPECT_TRUE(SendRtcp1());
1048 EXPECT_TRUE(SendRtcp2());
1049 EXPECT_TRUE(CheckRtp1());
1050 EXPECT_TRUE(CheckRtp2());
1051 EXPECT_TRUE(CheckNoRtp1());
1052 EXPECT_TRUE(CheckNoRtp2());
1053 EXPECT_TRUE(CheckRtcp1());
1054 EXPECT_TRUE(CheckRtcp2());
1055 EXPECT_TRUE(CheckNoRtcp1());
1056 EXPECT_TRUE(CheckNoRtcp2());
1057 }
1058
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001059 // Check that RTP and RTCP are transmitted ok when both sides
1060 // support mux and one the offerer requires mux.
1061 void SendRequireRtcpMuxToRtcpMux() {
1062 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1063 channel1_->ActivateRtcpMux();
1064 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001065 ASSERT_TRUE(GetTransport1());
1066 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001067 EXPECT_EQ(1U, GetTransport1()->channels().size());
1068 EXPECT_EQ(1U, GetTransport2()->channels().size());
1069 EXPECT_TRUE(SendAccept());
1070 EXPECT_TRUE(SendRtp1());
1071 EXPECT_TRUE(SendRtp2());
1072 EXPECT_TRUE(SendRtcp1());
1073 EXPECT_TRUE(SendRtcp2());
1074 EXPECT_TRUE(CheckRtp1());
1075 EXPECT_TRUE(CheckRtp2());
1076 EXPECT_TRUE(CheckNoRtp1());
1077 EXPECT_TRUE(CheckNoRtp2());
1078 EXPECT_TRUE(CheckRtcp1());
1079 EXPECT_TRUE(CheckRtcp2());
1080 EXPECT_TRUE(CheckNoRtcp1());
1081 EXPECT_TRUE(CheckNoRtcp2());
1082 }
1083
1084 // Check that RTP and RTCP are transmitted ok when both sides
1085 // support mux and one the answerer requires rtcp mux.
1086 void SendRtcpMuxToRequireRtcpMux() {
1087 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1088 channel2_->ActivateRtcpMux();
1089 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001090 ASSERT_TRUE(GetTransport1());
1091 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001092 EXPECT_EQ(2U, GetTransport1()->channels().size());
1093 EXPECT_EQ(1U, GetTransport2()->channels().size());
1094 EXPECT_TRUE(SendAccept());
1095 EXPECT_EQ(1U, GetTransport1()->channels().size());
1096 EXPECT_TRUE(SendRtp1());
1097 EXPECT_TRUE(SendRtp2());
1098 EXPECT_TRUE(SendRtcp1());
1099 EXPECT_TRUE(SendRtcp2());
1100 EXPECT_TRUE(CheckRtp1());
1101 EXPECT_TRUE(CheckRtp2());
1102 EXPECT_TRUE(CheckNoRtp1());
1103 EXPECT_TRUE(CheckNoRtp2());
1104 EXPECT_TRUE(CheckRtcp1());
1105 EXPECT_TRUE(CheckRtcp2());
1106 EXPECT_TRUE(CheckNoRtcp1());
1107 EXPECT_TRUE(CheckNoRtcp2());
1108 }
1109
1110 // Check that RTP and RTCP are transmitted ok when both sides
1111 // require mux.
1112 void SendRequireRtcpMuxToRequireRtcpMux() {
1113 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1114 channel1_->ActivateRtcpMux();
1115 channel2_->ActivateRtcpMux();
1116 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001117 ASSERT_TRUE(GetTransport1());
1118 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001119 EXPECT_EQ(1U, GetTransport1()->channels().size());
1120 EXPECT_EQ(1U, GetTransport2()->channels().size());
1121 EXPECT_TRUE(SendAccept());
1122 EXPECT_EQ(1U, GetTransport1()->channels().size());
1123 EXPECT_TRUE(SendRtp1());
1124 EXPECT_TRUE(SendRtp2());
1125 EXPECT_TRUE(SendRtcp1());
1126 EXPECT_TRUE(SendRtcp2());
1127 EXPECT_TRUE(CheckRtp1());
1128 EXPECT_TRUE(CheckRtp2());
1129 EXPECT_TRUE(CheckNoRtp1());
1130 EXPECT_TRUE(CheckNoRtp2());
1131 EXPECT_TRUE(CheckRtcp1());
1132 EXPECT_TRUE(CheckRtcp2());
1133 EXPECT_TRUE(CheckNoRtcp1());
1134 EXPECT_TRUE(CheckNoRtcp2());
1135 }
1136
1137 // Check that SendAccept fails if the answerer doesn't support mux
1138 // and the offerer requires it.
1139 void SendRequireRtcpMuxToNoRtcpMux() {
1140 CreateChannels(RTCP | RTCP_MUX, RTCP);
1141 channel1_->ActivateRtcpMux();
1142 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001143 ASSERT_TRUE(GetTransport1());
1144 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001145 EXPECT_EQ(1U, GetTransport1()->channels().size());
1146 EXPECT_EQ(2U, GetTransport2()->channels().size());
1147 EXPECT_FALSE(SendAccept());
1148 }
1149
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001150 // Check that RTCP data sent by the initiator before the accept is not muxed.
1151 void SendEarlyRtcpMuxToRtcp() {
1152 CreateChannels(RTCP | RTCP_MUX, RTCP);
1153 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001154 ASSERT_TRUE(GetTransport1());
1155 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001156 EXPECT_EQ(2U, GetTransport1()->channels().size());
1157 EXPECT_EQ(2U, GetTransport2()->channels().size());
1158
1159 // RTCP can be sent before the call is accepted, if the transport is ready.
1160 // It should not be muxed though, as the remote side doesn't support mux.
1161 EXPECT_TRUE(SendRtcp1());
1162 EXPECT_TRUE(CheckNoRtp2());
1163 EXPECT_TRUE(CheckRtcp2());
1164
1165 // Send RTCP packet from callee and verify that it is received.
1166 EXPECT_TRUE(SendRtcp2());
1167 EXPECT_TRUE(CheckNoRtp1());
1168 EXPECT_TRUE(CheckRtcp1());
1169
1170 // Complete call setup and ensure everything is still OK.
1171 EXPECT_TRUE(SendAccept());
1172 EXPECT_EQ(2U, GetTransport1()->channels().size());
1173 EXPECT_TRUE(SendRtcp1());
1174 EXPECT_TRUE(CheckRtcp2());
1175 EXPECT_TRUE(SendRtcp2());
1176 EXPECT_TRUE(CheckRtcp1());
1177 }
1178
1179
1180 // Check that RTCP data is not muxed until both sides have enabled muxing,
1181 // but that we properly demux before we get the accept message, since there
1182 // is a race between RTP data and the jingle accept.
1183 void SendEarlyRtcpMuxToRtcpMux() {
1184 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1185 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001186 ASSERT_TRUE(GetTransport1());
1187 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001188 EXPECT_EQ(2U, GetTransport1()->channels().size());
1189 EXPECT_EQ(1U, GetTransport2()->channels().size());
1190
1191 // RTCP can't be sent yet, since the RTCP transport isn't writable, and
1192 // we haven't yet received the accept that says we should mux.
1193 EXPECT_FALSE(SendRtcp1());
1194
1195 // Send muxed RTCP packet from callee and verify that it is received.
1196 EXPECT_TRUE(SendRtcp2());
1197 EXPECT_TRUE(CheckNoRtp1());
1198 EXPECT_TRUE(CheckRtcp1());
1199
1200 // Complete call setup and ensure everything is still OK.
1201 EXPECT_TRUE(SendAccept());
1202 EXPECT_EQ(1U, GetTransport1()->channels().size());
1203 EXPECT_TRUE(SendRtcp1());
1204 EXPECT_TRUE(CheckRtcp2());
1205 EXPECT_TRUE(SendRtcp2());
1206 EXPECT_TRUE(CheckRtcp1());
1207 }
1208
1209 // Test that we properly send SRTP with RTCP in both directions.
1210 // You can pass in DTLS and/or RTCP_MUX as flags.
1211 void SendSrtpToSrtp(int flags1_in = 0, int flags2_in = 0) {
1212 ASSERT((flags1_in & ~(RTCP_MUX | DTLS)) == 0);
1213 ASSERT((flags2_in & ~(RTCP_MUX | DTLS)) == 0);
1214
1215 int flags1 = RTCP | SECURE | flags1_in;
1216 int flags2 = RTCP | SECURE | flags2_in;
1217 bool dtls1 = !!(flags1_in & DTLS);
1218 bool dtls2 = !!(flags2_in & DTLS);
1219 CreateChannels(flags1, flags2);
1220 EXPECT_FALSE(channel1_->secure());
1221 EXPECT_FALSE(channel2_->secure());
1222 EXPECT_TRUE(SendInitiate());
1223 EXPECT_TRUE_WAIT(channel1_->writable(), kEventTimeout);
1224 EXPECT_TRUE_WAIT(channel2_->writable(), kEventTimeout);
1225 EXPECT_TRUE(SendAccept());
1226 EXPECT_TRUE(channel1_->secure());
1227 EXPECT_TRUE(channel2_->secure());
1228 EXPECT_EQ(dtls1 && dtls2, channel1_->secure_dtls());
1229 EXPECT_EQ(dtls1 && dtls2, channel2_->secure_dtls());
1230 EXPECT_TRUE(SendRtp1());
1231 EXPECT_TRUE(SendRtp2());
1232 EXPECT_TRUE(SendRtcp1());
1233 EXPECT_TRUE(SendRtcp2());
1234 EXPECT_TRUE(CheckRtp1());
1235 EXPECT_TRUE(CheckRtp2());
1236 EXPECT_TRUE(CheckNoRtp1());
1237 EXPECT_TRUE(CheckNoRtp2());
1238 EXPECT_TRUE(CheckRtcp1());
1239 EXPECT_TRUE(CheckRtcp2());
1240 EXPECT_TRUE(CheckNoRtcp1());
1241 EXPECT_TRUE(CheckNoRtcp2());
1242 }
1243
1244 // Test that we properly handling SRTP negotiating down to RTP.
1245 void SendSrtpToRtp() {
1246 CreateChannels(RTCP | SECURE, RTCP);
1247 EXPECT_FALSE(channel1_->secure());
1248 EXPECT_FALSE(channel2_->secure());
1249 EXPECT_TRUE(SendInitiate());
1250 EXPECT_TRUE(SendAccept());
1251 EXPECT_FALSE(channel1_->secure());
1252 EXPECT_FALSE(channel2_->secure());
1253 EXPECT_TRUE(SendRtp1());
1254 EXPECT_TRUE(SendRtp2());
1255 EXPECT_TRUE(SendRtcp1());
1256 EXPECT_TRUE(SendRtcp2());
1257 EXPECT_TRUE(CheckRtp1());
1258 EXPECT_TRUE(CheckRtp2());
1259 EXPECT_TRUE(CheckNoRtp1());
1260 EXPECT_TRUE(CheckNoRtp2());
1261 EXPECT_TRUE(CheckRtcp1());
1262 EXPECT_TRUE(CheckRtcp2());
1263 EXPECT_TRUE(CheckNoRtcp1());
1264 EXPECT_TRUE(CheckNoRtcp2());
1265 }
1266
1267 // Test that we can send and receive early media when a provisional answer is
1268 // sent and received. The test uses SRTP, RTCP mux and SSRC mux.
1269 void SendEarlyMediaUsingRtcpMuxSrtp() {
1270 int sequence_number1_1 = 0, sequence_number2_2 = 0;
1271
1272 CreateChannels(SSRC_MUX | RTCP | RTCP_MUX | SECURE,
1273 SSRC_MUX | RTCP | RTCP_MUX | SECURE);
1274 EXPECT_TRUE(SendOffer());
1275 EXPECT_TRUE(SendProvisionalAnswer());
1276 EXPECT_TRUE(channel1_->secure());
1277 EXPECT_TRUE(channel2_->secure());
deadbeefcbecd352015-09-23 11:50:27 -07001278 ASSERT_TRUE(GetTransport1());
1279 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001280 EXPECT_EQ(2U, GetTransport1()->channels().size());
1281 EXPECT_EQ(2U, GetTransport2()->channels().size());
1282 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1283 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1284 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
1285 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1286
1287 // Send packets from callee and verify that it is received.
1288 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1289 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1290 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
1291 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1292
1293 // Complete call setup and ensure everything is still OK.
1294 EXPECT_TRUE(SendFinalAnswer());
1295 EXPECT_EQ(1U, GetTransport1()->channels().size());
1296 EXPECT_EQ(1U, GetTransport2()->channels().size());
1297 EXPECT_TRUE(channel1_->secure());
1298 EXPECT_TRUE(channel2_->secure());
1299 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1300 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1301 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
1302 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1303 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1304 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1305 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
1306 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1307 }
1308
1309 // Test that we properly send RTP without SRTP from a thread.
1310 void SendRtpToRtpOnThread() {
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +00001311 bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2;
1312 CreateChannels(RTCP, RTCP);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001313 EXPECT_TRUE(SendInitiate());
1314 EXPECT_TRUE(SendAccept());
1315 CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1);
1316 CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2);
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +00001317 CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1);
1318 CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001319 EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
1320 EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
1321 EXPECT_TRUE_WAIT(sent_rtp1, 1000);
1322 EXPECT_TRUE_WAIT(sent_rtp2, 1000);
1323 EXPECT_TRUE(CheckNoRtp1());
1324 EXPECT_TRUE(CheckNoRtp2());
1325 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
1326 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
1327 EXPECT_TRUE_WAIT(sent_rtcp1, 1000);
1328 EXPECT_TRUE_WAIT(sent_rtcp2, 1000);
1329 EXPECT_TRUE(CheckNoRtcp1());
1330 EXPECT_TRUE(CheckNoRtcp2());
1331 }
1332
1333 // Test that we properly send SRTP with RTCP from a thread.
1334 void SendSrtpToSrtpOnThread() {
1335 bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2;
1336 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1337 EXPECT_TRUE(SendInitiate());
1338 EXPECT_TRUE(SendAccept());
1339 CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1);
1340 CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2);
1341 CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1);
1342 CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2);
1343 EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
1344 EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
1345 EXPECT_TRUE_WAIT(sent_rtp1, 1000);
1346 EXPECT_TRUE_WAIT(sent_rtp2, 1000);
1347 EXPECT_TRUE(CheckNoRtp1());
1348 EXPECT_TRUE(CheckNoRtp2());
1349 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
1350 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
1351 EXPECT_TRUE_WAIT(sent_rtcp1, 1000);
1352 EXPECT_TRUE_WAIT(sent_rtcp2, 1000);
1353 EXPECT_TRUE(CheckNoRtcp1());
1354 EXPECT_TRUE(CheckNoRtcp2());
1355 }
1356
1357 // Test that the mediachannel retains its sending state after the transport
1358 // becomes non-writable.
1359 void SendWithWritabilityLoss() {
1360 CreateChannels(0, 0);
1361 EXPECT_TRUE(SendInitiate());
1362 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001363 ASSERT_TRUE(GetTransport1());
1364 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001365 EXPECT_EQ(1U, GetTransport1()->channels().size());
1366 EXPECT_EQ(1U, GetTransport2()->channels().size());
1367 EXPECT_TRUE(SendRtp1());
1368 EXPECT_TRUE(SendRtp2());
1369 EXPECT_TRUE(CheckRtp1());
1370 EXPECT_TRUE(CheckRtp2());
1371 EXPECT_TRUE(CheckNoRtp1());
1372 EXPECT_TRUE(CheckNoRtp2());
1373
wu@webrtc.org97077a32013-10-25 21:18:33 +00001374 // Lose writability, which should fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001375 GetTransport1()->SetWritable(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001376 EXPECT_FALSE(SendRtp1());
1377 EXPECT_TRUE(SendRtp2());
1378 EXPECT_TRUE(CheckRtp1());
1379 EXPECT_TRUE(CheckNoRtp2());
1380
1381 // Regain writability
1382 GetTransport1()->SetWritable(true);
1383 EXPECT_TRUE(media_channel1_->sending());
1384 EXPECT_TRUE(SendRtp1());
1385 EXPECT_TRUE(SendRtp2());
1386 EXPECT_TRUE(CheckRtp1());
1387 EXPECT_TRUE(CheckRtp2());
1388 EXPECT_TRUE(CheckNoRtp1());
1389 EXPECT_TRUE(CheckNoRtp2());
1390
1391 // Lose writability completely
1392 GetTransport1()->SetDestination(NULL);
1393 EXPECT_TRUE(media_channel1_->sending());
1394
wu@webrtc.org97077a32013-10-25 21:18:33 +00001395 // Should fail also.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001396 EXPECT_FALSE(SendRtp1());
1397 EXPECT_TRUE(SendRtp2());
1398 EXPECT_TRUE(CheckRtp1());
1399 EXPECT_TRUE(CheckNoRtp2());
1400
1401 // Gain writability back
1402 GetTransport1()->SetDestination(GetTransport2());
1403 EXPECT_TRUE(media_channel1_->sending());
1404 EXPECT_TRUE(SendRtp1());
1405 EXPECT_TRUE(SendRtp2());
1406 EXPECT_TRUE(CheckRtp1());
1407 EXPECT_TRUE(CheckRtp2());
1408 EXPECT_TRUE(CheckNoRtp1());
1409 EXPECT_TRUE(CheckNoRtp2());
1410 }
1411
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001412 void SendBundleToBundle(
1413 const int* pl_types, int len, bool rtcp_mux, bool secure) {
1414 ASSERT_EQ(2, len);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001415 int sequence_number1_1 = 0, sequence_number2_2 = 0;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001416 // Only pl_type1 was added to the bundle filter for both |channel1_|
1417 // and |channel2_|.
1418 int pl_type1 = pl_types[0];
1419 int pl_type2 = pl_types[1];
1420 int flags = SSRC_MUX | RTCP;
1421 if (secure) flags |= SECURE;
1422 uint32 expected_channels = 2U;
1423 if (rtcp_mux) {
1424 flags |= RTCP_MUX;
1425 expected_channels = 1U;
1426 }
1427 CreateChannels(flags, flags);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001428 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001429 ASSERT_TRUE(GetTransport1());
1430 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001431 EXPECT_EQ(2U, GetTransport1()->channels().size());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001432 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001433 EXPECT_TRUE(SendAccept());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001434 EXPECT_EQ(expected_channels, GetTransport1()->channels().size());
1435 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
1436 EXPECT_TRUE(channel1_->bundle_filter()->FindPayloadType(pl_type1));
1437 EXPECT_TRUE(channel2_->bundle_filter()->FindPayloadType(pl_type1));
1438 EXPECT_FALSE(channel1_->bundle_filter()->FindPayloadType(pl_type2));
1439 EXPECT_FALSE(channel2_->bundle_filter()->FindPayloadType(pl_type2));
1440 // channel1 - should only have media_content2 as remote. i.e. kSsrc2
1441 EXPECT_TRUE(channel1_->bundle_filter()->FindStream(kSsrc2));
1442 EXPECT_FALSE(channel1_->bundle_filter()->FindStream(kSsrc1));
1443 // channel2 - should only have media_content1 as remote. i.e. kSsrc1
1444 EXPECT_TRUE(channel2_->bundle_filter()->FindStream(kSsrc1));
1445 EXPECT_FALSE(channel2_->bundle_filter()->FindStream(kSsrc2));
1446
1447 // Both channels can receive pl_type1 only.
1448 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type1));
1449 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type1));
1450 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type1));
1451 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type1));
1452 EXPECT_TRUE(CheckNoRtp1());
1453 EXPECT_TRUE(CheckNoRtp2());
1454
1455 // RTCP test
1456 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type2));
1457 EXPECT_FALSE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type2));
1458 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type2));
1459 EXPECT_FALSE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type2));
1460
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001461 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1462 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001463 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1464 EXPECT_TRUE(CheckNoRtcp1());
1465 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1466 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001467
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001468 EXPECT_TRUE(SendCustomRtcp1(kSsrc2));
1469 EXPECT_TRUE(SendCustomRtcp2(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001470 EXPECT_FALSE(CheckCustomRtcp1(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001471 EXPECT_FALSE(CheckCustomRtcp2(kSsrc2));
1472 }
1473
1474 // Test that the media monitor can be run and gives timely callbacks.
1475 void TestMediaMonitor() {
1476 static const int kTimeout = 500;
1477 CreateChannels(0, 0);
1478 EXPECT_TRUE(SendInitiate());
1479 EXPECT_TRUE(SendAccept());
1480 channel1_->StartMediaMonitor(100);
1481 channel2_->StartMediaMonitor(100);
1482 // Ensure we get callbacks and stop.
1483 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1484 EXPECT_TRUE_WAIT(media_info_callbacks2_ > 0, kTimeout);
1485 channel1_->StopMediaMonitor();
1486 channel2_->StopMediaMonitor();
1487 // Ensure a restart of a stopped monitor works.
1488 channel1_->StartMediaMonitor(100);
1489 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1490 channel1_->StopMediaMonitor();
1491 // Ensure stopping a stopped monitor is OK.
1492 channel1_->StopMediaMonitor();
1493 }
1494
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001495 void TestSetContentFailure() {
1496 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001497
Peter Thatchera6d24442015-07-09 21:26:36 -07001498 auto sdesc = cricket::SessionDescription();
1499 sdesc.AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1500 new cricket::AudioContentDescription());
1501 sdesc.AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1502 new cricket::VideoContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001503
Peter Thatchera6d24442015-07-09 21:26:36 -07001504 std::string err;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001505 media_channel1_->set_fail_set_recv_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001506 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1507 &sdesc, cricket::CA_OFFER, &err));
1508 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1509 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001510
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001511 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001512 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1513 &sdesc, cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001514 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001515 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1516 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001517 }
1518
1519 void TestSendTwoOffers() {
1520 CreateChannels(0, 0);
1521
Peter Thatchera6d24442015-07-09 21:26:36 -07001522 std::string err;
1523 rtc::scoped_ptr<cricket::SessionDescription> sdesc1(
1524 CreateSessionDescriptionWithStream(1));
1525 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1526 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001527 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1528
Peter Thatchera6d24442015-07-09 21:26:36 -07001529 rtc::scoped_ptr<cricket::SessionDescription> sdesc2(
1530 CreateSessionDescriptionWithStream(2));
1531 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1532 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001533 EXPECT_FALSE(media_channel1_->HasSendStream(1));
1534 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1535 }
1536
1537 void TestReceiveTwoOffers() {
1538 CreateChannels(0, 0);
1539
Peter Thatchera6d24442015-07-09 21:26:36 -07001540 std::string err;
1541 rtc::scoped_ptr<cricket::SessionDescription> sdesc1(
1542 CreateSessionDescriptionWithStream(1));
1543 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1544 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001545 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1546
Peter Thatchera6d24442015-07-09 21:26:36 -07001547 rtc::scoped_ptr<cricket::SessionDescription> sdesc2(
1548 CreateSessionDescriptionWithStream(2));
1549 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1550 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001551 EXPECT_FALSE(media_channel1_->HasRecvStream(1));
1552 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1553 }
1554
1555 void TestSendPrAnswer() {
1556 CreateChannels(0, 0);
1557
Peter Thatchera6d24442015-07-09 21:26:36 -07001558 std::string err;
1559 // Receive offer
1560 rtc::scoped_ptr<cricket::SessionDescription> sdesc1(
1561 CreateSessionDescriptionWithStream(1));
1562 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1563 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001564 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1565
Peter Thatchera6d24442015-07-09 21:26:36 -07001566 // Send PR answer
1567 rtc::scoped_ptr<cricket::SessionDescription> sdesc2(
1568 CreateSessionDescriptionWithStream(2));
1569 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1570 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001571 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1572 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1573
Peter Thatchera6d24442015-07-09 21:26:36 -07001574 // Send answer
1575 rtc::scoped_ptr<cricket::SessionDescription> sdesc3(
1576 CreateSessionDescriptionWithStream(3));
1577 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1578 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001579 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1580 EXPECT_FALSE(media_channel1_->HasSendStream(2));
1581 EXPECT_TRUE(media_channel1_->HasSendStream(3));
1582 }
1583
1584 void TestReceivePrAnswer() {
1585 CreateChannels(0, 0);
1586
Peter Thatchera6d24442015-07-09 21:26:36 -07001587 std::string err;
1588 // Send offer
1589 rtc::scoped_ptr<cricket::SessionDescription> sdesc1(
1590 CreateSessionDescriptionWithStream(1));
1591 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1592 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001593 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1594
Peter Thatchera6d24442015-07-09 21:26:36 -07001595 // Receive PR answer
1596 rtc::scoped_ptr<cricket::SessionDescription> sdesc2(
1597 CreateSessionDescriptionWithStream(2));
1598 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1599 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001600 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1601 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1602
Peter Thatchera6d24442015-07-09 21:26:36 -07001603 // Receive answer
1604 rtc::scoped_ptr<cricket::SessionDescription> sdesc3(
1605 CreateSessionDescriptionWithStream(3));
1606 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1607 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001608 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1609 EXPECT_FALSE(media_channel1_->HasRecvStream(2));
1610 EXPECT_TRUE(media_channel1_->HasRecvStream(3));
1611 }
1612
1613 void TestFlushRtcp() {
1614 bool send_rtcp1;
1615
1616 CreateChannels(RTCP, RTCP);
1617 EXPECT_TRUE(SendInitiate());
1618 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001619 ASSERT_TRUE(GetTransport1());
1620 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001621 EXPECT_EQ(2U, GetTransport1()->channels().size());
1622 EXPECT_EQ(2U, GetTransport2()->channels().size());
1623
1624 // Send RTCP1 from a different thread.
1625 CallOnThreadAndWaitForDone(&ChannelTest<T>::SendRtcp1, &send_rtcp1);
1626 EXPECT_TRUE(send_rtcp1);
1627 // The sending message is only posted. channel2_ should be empty.
1628 EXPECT_TRUE(CheckNoRtcp2());
1629
1630 // When channel1_ is deleted, the RTCP packet should be sent out to
1631 // channel2_.
1632 channel1_.reset();
1633 EXPECT_TRUE(CheckRtcp2());
1634 }
1635
1636 void TestChangeStateError() {
1637 CreateChannels(RTCP, RTCP);
1638 EXPECT_TRUE(SendInitiate());
1639 media_channel2_->set_fail_set_send(true);
1640 EXPECT_TRUE(channel2_->Enable(true));
1641 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_DEVICE_OPEN_FAILED,
1642 error_);
1643 }
1644
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001645 void TestSrtpError(int pl_type) {
1646 // For Audio, only pl_type 0 is added to the bundle filter.
1647 // For Video, only pl_type 97 is added to the bundle filter.
1648 // So we need to pass in pl_type so that the packet can pass through
1649 // the bundle filter before it can be processed by the srtp filter.
1650 // The packet is not a valid srtp packet because it is too short.
pbos@webrtc.org910473b2014-06-06 15:44:00 +00001651 unsigned const char kBadPacket[] = {0x84,
1652 static_cast<unsigned char>(pl_type),
1653 0x00,
1654 0x01,
1655 0x00,
1656 0x00,
1657 0x00,
1658 0x00,
1659 0x00,
1660 0x00,
1661 0x00,
1662 0x01};
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001663 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1664 EXPECT_FALSE(channel1_->secure());
1665 EXPECT_FALSE(channel2_->secure());
1666 EXPECT_TRUE(SendInitiate());
1667 EXPECT_TRUE(SendAccept());
1668 EXPECT_TRUE(channel1_->secure());
1669 EXPECT_TRUE(channel2_->secure());
1670 channel2_->set_srtp_signal_silent_time(200);
1671
1672 // Testing failures in sending packets.
1673 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1674 // The first failure will trigger an error.
1675 EXPECT_EQ_WAIT(T::MediaChannel::ERROR_REC_SRTP_ERROR, error_, 500);
1676 error_ = T::MediaChannel::ERROR_NONE;
1677 // The next 1 sec failures will not trigger an error.
1678 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1679 // Wait for a while to ensure no message comes in.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001680 rtc::Thread::Current()->ProcessMessages(210);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001681 EXPECT_EQ(T::MediaChannel::ERROR_NONE, error_);
1682 // The error will be triggered again.
1683 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1684 EXPECT_EQ_WAIT(T::MediaChannel::ERROR_REC_SRTP_ERROR, error_, 500);
1685
1686 // Testing failures in receiving packets.
1687 error_ = T::MediaChannel::ERROR_NONE;
1688 cricket::TransportChannel* transport_channel =
1689 channel2_->transport_channel();
1690 transport_channel->SignalReadPacket(
1691 transport_channel, reinterpret_cast<const char*>(kBadPacket),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001692 sizeof(kBadPacket), rtc::PacketTime(), 0);
mallinath@webrtc.org4d3e8b82013-08-16 00:31:17 +00001693 EXPECT_EQ_WAIT(T::MediaChannel::ERROR_PLAY_SRTP_ERROR, error_, 500);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001694 }
1695
1696 void TestOnReadyToSend() {
1697 CreateChannels(RTCP, RTCP);
1698 TransportChannel* rtp = channel1_->transport_channel();
1699 TransportChannel* rtcp = channel1_->rtcp_transport_channel();
1700 EXPECT_FALSE(media_channel1_->ready_to_send());
1701 rtp->SignalReadyToSend(rtp);
1702 EXPECT_FALSE(media_channel1_->ready_to_send());
1703 rtcp->SignalReadyToSend(rtcp);
1704 // MediaChannel::OnReadyToSend only be called when both rtp and rtcp
1705 // channel are ready to send.
1706 EXPECT_TRUE(media_channel1_->ready_to_send());
1707
1708 // rtp channel becomes not ready to send will be propagated to mediachannel
deadbeefcbecd352015-09-23 11:50:27 -07001709 channel1_->SetReadyToSend(false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001710 EXPECT_FALSE(media_channel1_->ready_to_send());
deadbeefcbecd352015-09-23 11:50:27 -07001711 channel1_->SetReadyToSend(false, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001712 EXPECT_TRUE(media_channel1_->ready_to_send());
1713
1714 // rtcp channel becomes not ready to send will be propagated to mediachannel
deadbeefcbecd352015-09-23 11:50:27 -07001715 channel1_->SetReadyToSend(true, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001716 EXPECT_FALSE(media_channel1_->ready_to_send());
deadbeefcbecd352015-09-23 11:50:27 -07001717 channel1_->SetReadyToSend(true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001718 EXPECT_TRUE(media_channel1_->ready_to_send());
1719 }
1720
1721 void TestOnReadyToSendWithRtcpMux() {
1722 CreateChannels(RTCP, RTCP);
1723 typename T::Content content;
1724 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1725 // Both sides agree on mux. Should no longer be a separate RTCP channel.
1726 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001727 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
1728 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001729 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
1730 TransportChannel* rtp = channel1_->transport_channel();
1731 EXPECT_FALSE(media_channel1_->ready_to_send());
1732 // In the case of rtcp mux, the SignalReadyToSend() from rtp channel
1733 // should trigger the MediaChannel's OnReadyToSend.
1734 rtp->SignalReadyToSend(rtp);
1735 EXPECT_TRUE(media_channel1_->ready_to_send());
deadbeefcbecd352015-09-23 11:50:27 -07001736 channel1_->SetReadyToSend(false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001737 EXPECT_FALSE(media_channel1_->ready_to_send());
1738 }
1739
1740 protected:
deadbeefcbecd352015-09-23 11:50:27 -07001741 cricket::FakeTransportController transport_controller1_;
1742 cricket::FakeTransportController transport_controller2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001743 cricket::FakeMediaEngine media_engine_;
1744 // The media channels are owned by the voice channel objects below.
1745 typename T::MediaChannel* media_channel1_;
1746 typename T::MediaChannel* media_channel2_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001747 rtc::scoped_ptr<typename T::Channel> channel1_;
1748 rtc::scoped_ptr<typename T::Channel> channel2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001749 typename T::Content local_media_content1_;
1750 typename T::Content local_media_content2_;
1751 typename T::Content remote_media_content1_;
1752 typename T::Content remote_media_content2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001753 // The RTP and RTCP packets to send in the tests.
1754 std::string rtp_packet_;
1755 std::string rtcp_packet_;
1756 int media_info_callbacks1_;
1757 int media_info_callbacks2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001758
1759 uint32 ssrc_;
1760 typename T::MediaChannel::Error error_;
1761};
1762
1763
1764template<>
1765void ChannelTest<VoiceTraits>::CreateContent(
1766 int flags,
1767 const cricket::AudioCodec& audio_codec,
1768 const cricket::VideoCodec& video_codec,
1769 cricket::AudioContentDescription* audio) {
1770 audio->AddCodec(audio_codec);
1771 audio->set_rtcp_mux((flags & RTCP_MUX) != 0);
1772 if (flags & SECURE) {
1773 audio->AddCrypto(cricket::CryptoParams(
1774 1, cricket::CS_AES_CM_128_HMAC_SHA1_32,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001775 "inline:" + rtc::CreateRandomString(40), ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001776 }
1777}
1778
1779template<>
1780void ChannelTest<VoiceTraits>::CopyContent(
1781 const cricket::AudioContentDescription& source,
1782 cricket::AudioContentDescription* audio) {
1783 *audio = source;
1784}
1785
1786template<>
1787bool ChannelTest<VoiceTraits>::CodecMatches(const cricket::AudioCodec& c1,
1788 const cricket::AudioCodec& c2) {
1789 return c1.name == c2.name && c1.clockrate == c2.clockrate &&
1790 c1.bitrate == c2.bitrate && c1.channels == c2.channels;
1791}
1792
1793template<>
1794void ChannelTest<VoiceTraits>::AddLegacyStreamInContent(
1795 uint32 ssrc, int flags, cricket::AudioContentDescription* audio) {
1796 audio->AddLegacyStream(ssrc);
1797}
1798
1799class VoiceChannelTest
1800 : public ChannelTest<VoiceTraits> {
1801 public:
solenberg1dd98f32015-09-10 01:57:14 -07001802 typedef ChannelTest<VoiceTraits> Base;
deadbeefcbecd352015-09-23 11:50:27 -07001803 VoiceChannelTest()
1804 : Base(kPcmuFrame, sizeof(kPcmuFrame), kRtcpReport, sizeof(kRtcpReport)) {
1805 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001806};
1807
1808// override to add NULL parameter
deadbeefcbecd352015-09-23 11:50:27 -07001809template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001810cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
deadbeefcbecd352015-09-23 11:50:27 -07001811 rtc::Thread* thread,
1812 cricket::MediaEngineInterface* engine,
1813 cricket::FakeVideoMediaChannel* ch,
1814 cricket::TransportController* transport_controller,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001815 bool rtcp) {
1816 cricket::VideoChannel* channel = new cricket::VideoChannel(
deadbeefcbecd352015-09-23 11:50:27 -07001817 thread, ch, transport_controller, cricket::CN_VIDEO, rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001818 if (!channel->Init()) {
1819 delete channel;
1820 channel = NULL;
1821 }
1822 return channel;
1823}
1824
1825// override to add 0 parameter
1826template<>
1827bool ChannelTest<VideoTraits>::AddStream1(int id) {
1828 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
1829}
1830
1831template<>
1832void ChannelTest<VideoTraits>::CreateContent(
1833 int flags,
1834 const cricket::AudioCodec& audio_codec,
1835 const cricket::VideoCodec& video_codec,
1836 cricket::VideoContentDescription* video) {
1837 video->AddCodec(video_codec);
1838 video->set_rtcp_mux((flags & RTCP_MUX) != 0);
1839 if (flags & SECURE) {
1840 video->AddCrypto(cricket::CryptoParams(
1841 1, cricket::CS_AES_CM_128_HMAC_SHA1_80,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001842 "inline:" + rtc::CreateRandomString(40), ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001843 }
1844}
1845
1846template<>
1847void ChannelTest<VideoTraits>::CopyContent(
1848 const cricket::VideoContentDescription& source,
1849 cricket::VideoContentDescription* video) {
1850 *video = source;
1851}
1852
1853template<>
1854bool ChannelTest<VideoTraits>::CodecMatches(const cricket::VideoCodec& c1,
1855 const cricket::VideoCodec& c2) {
1856 return c1.name == c2.name && c1.width == c2.width && c1.height == c2.height &&
1857 c1.framerate == c2.framerate;
1858}
1859
1860template<>
1861void ChannelTest<VideoTraits>::AddLegacyStreamInContent(
1862 uint32 ssrc, int flags, cricket::VideoContentDescription* video) {
1863 video->AddLegacyStream(ssrc);
1864}
1865
1866class VideoChannelTest
1867 : public ChannelTest<VideoTraits> {
1868 public:
solenberg1dd98f32015-09-10 01:57:14 -07001869 typedef ChannelTest<VideoTraits> Base;
deadbeefcbecd352015-09-23 11:50:27 -07001870 VideoChannelTest()
1871 : Base(kH264Packet,
1872 sizeof(kH264Packet),
1873 kRtcpReport,
1874 sizeof(kRtcpReport)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001875};
1876
1877
1878// VoiceChannelTest
1879
1880TEST_F(VoiceChannelTest, TestInit) {
1881 Base::TestInit();
1882 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
1883 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
1884}
1885
1886TEST_F(VoiceChannelTest, TestSetContents) {
1887 Base::TestSetContents();
1888}
1889
1890TEST_F(VoiceChannelTest, TestSetContentsNullOffer) {
1891 Base::TestSetContentsNullOffer();
1892}
1893
1894TEST_F(VoiceChannelTest, TestSetContentsRtcpMux) {
1895 Base::TestSetContentsRtcpMux();
1896}
1897
1898TEST_F(VoiceChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
1899 Base::TestSetContentsRtcpMux();
1900}
1901
1902TEST_F(VoiceChannelTest, TestSetRemoteContentUpdate) {
1903 Base::TestSetRemoteContentUpdate();
1904}
1905
1906TEST_F(VoiceChannelTest, TestStreams) {
1907 Base::TestStreams();
1908}
1909
1910TEST_F(VoiceChannelTest, TestUpdateStreamsInLocalContent) {
1911 Base::TestUpdateStreamsInLocalContent();
1912}
1913
1914TEST_F(VoiceChannelTest, TestUpdateRemoteStreamsInContent) {
1915 Base::TestUpdateStreamsInRemoteContent();
1916}
1917
1918TEST_F(VoiceChannelTest, TestChangeStreamParamsInContent) {
1919 Base::TestChangeStreamParamsInContent();
1920}
1921
1922TEST_F(VoiceChannelTest, TestPlayoutAndSendingStates) {
1923 Base::TestPlayoutAndSendingStates();
1924}
1925
1926TEST_F(VoiceChannelTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07001927 CreateChannels(0, 0);
1928 // Test that we can Mute the default channel even though the sending SSRC
1929 // is unknown.
1930 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
1931 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
1932 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
1933 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
1934 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
1935
1936 // Test that we can not mute an unknown SSRC.
1937 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
1938
1939 SendInitiate();
1940 // After the local session description has been set, we can mute a stream
1941 // with its SSRC.
1942 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
1943 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
1944 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
1945 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001946}
1947
1948TEST_F(VoiceChannelTest, TestMediaContentDirection) {
1949 Base::TestMediaContentDirection();
1950}
1951
1952TEST_F(VoiceChannelTest, TestCallSetup) {
1953 Base::TestCallSetup();
1954}
1955
1956TEST_F(VoiceChannelTest, TestCallTeardownRtcpMux) {
1957 Base::TestCallTeardownRtcpMux();
1958}
1959
1960TEST_F(VoiceChannelTest, SendRtpToRtp) {
1961 Base::SendRtpToRtp();
1962}
1963
1964TEST_F(VoiceChannelTest, SendNoRtcpToNoRtcp) {
1965 Base::SendNoRtcpToNoRtcp();
1966}
1967
1968TEST_F(VoiceChannelTest, SendNoRtcpToRtcp) {
1969 Base::SendNoRtcpToRtcp();
1970}
1971
1972TEST_F(VoiceChannelTest, SendRtcpToNoRtcp) {
1973 Base::SendRtcpToNoRtcp();
1974}
1975
1976TEST_F(VoiceChannelTest, SendRtcpToRtcp) {
1977 Base::SendRtcpToRtcp();
1978}
1979
1980TEST_F(VoiceChannelTest, SendRtcpMuxToRtcp) {
1981 Base::SendRtcpMuxToRtcp();
1982}
1983
1984TEST_F(VoiceChannelTest, SendRtcpMuxToRtcpMux) {
1985 Base::SendRtcpMuxToRtcpMux();
1986}
1987
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001988TEST_F(VoiceChannelTest, SendRequireRtcpMuxToRtcpMux) {
1989 Base::SendRequireRtcpMuxToRtcpMux();
1990}
1991
1992TEST_F(VoiceChannelTest, SendRtcpMuxToRequireRtcpMux) {
1993 Base::SendRtcpMuxToRequireRtcpMux();
1994}
1995
1996TEST_F(VoiceChannelTest, SendRequireRtcpMuxToRequireRtcpMux) {
1997 Base::SendRequireRtcpMuxToRequireRtcpMux();
1998}
1999
2000TEST_F(VoiceChannelTest, SendRequireRtcpMuxToNoRtcpMux) {
2001 Base::SendRequireRtcpMuxToNoRtcpMux();
2002}
2003
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002004TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcp) {
2005 Base::SendEarlyRtcpMuxToRtcp();
2006}
2007
2008TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2009 Base::SendEarlyRtcpMuxToRtcpMux();
2010}
2011
2012TEST_F(VoiceChannelTest, SendSrtpToSrtpRtcpMux) {
2013 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2014}
2015
2016TEST_F(VoiceChannelTest, SendSrtpToRtp) {
2017 Base::SendSrtpToSrtp();
2018}
2019
2020TEST_F(VoiceChannelTest, SendSrtcpMux) {
2021 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2022}
2023
2024TEST_F(VoiceChannelTest, SendDtlsSrtpToSrtp) {
2025 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2026 Base::SendSrtpToSrtp(DTLS, 0);
2027}
2028
2029TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtp) {
2030 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2031 Base::SendSrtpToSrtp(DTLS, DTLS);
2032}
2033
2034TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2035 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2036 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2037}
2038
2039TEST_F(VoiceChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2040 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2041}
2042
2043TEST_F(VoiceChannelTest, SendRtpToRtpOnThread) {
2044 Base::SendRtpToRtpOnThread();
2045}
2046
2047TEST_F(VoiceChannelTest, SendSrtpToSrtpOnThread) {
2048 Base::SendSrtpToSrtpOnThread();
2049}
2050
2051TEST_F(VoiceChannelTest, SendWithWritabilityLoss) {
2052 Base::SendWithWritabilityLoss();
2053}
2054
2055TEST_F(VoiceChannelTest, TestMediaMonitor) {
2056 Base::TestMediaMonitor();
2057}
2058
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002059// Test that PressDTMF properly forwards to the media channel.
2060TEST_F(VoiceChannelTest, TestDtmf) {
2061 CreateChannels(0, 0);
2062 EXPECT_TRUE(SendInitiate());
2063 EXPECT_TRUE(SendAccept());
2064 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2065
2066 EXPECT_TRUE(channel1_->PressDTMF(1, true));
2067 EXPECT_TRUE(channel1_->PressDTMF(8, false));
2068
2069 ASSERT_EQ(2U, media_channel1_->dtmf_info_queue().size());
2070 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
2071 0, 1, 160, cricket::DF_PLAY | cricket::DF_SEND));
2072 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
2073 0, 8, 160, cricket::DF_SEND));
2074}
2075
2076// Test that InsertDtmf properly forwards to the media channel.
2077TEST_F(VoiceChannelTest, TestInsertDtmf) {
2078 CreateChannels(0, 0);
2079 EXPECT_TRUE(SendInitiate());
2080 EXPECT_TRUE(SendAccept());
2081 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2082
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002083 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100, cricket::DF_SEND));
2084 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110, cricket::DF_PLAY));
2085 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120,
2086 cricket::DF_PLAY | cricket::DF_SEND));
2087
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002088 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002089 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002090 1, 3, 100, cricket::DF_SEND));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002091 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002092 2, 5, 110, cricket::DF_PLAY));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002093 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002094 3, 7, 120, cricket::DF_PLAY | cricket::DF_SEND));
2095}
2096
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002097TEST_F(VoiceChannelTest, TestSetContentFailure) {
2098 Base::TestSetContentFailure();
2099}
2100
2101TEST_F(VoiceChannelTest, TestSendTwoOffers) {
2102 Base::TestSendTwoOffers();
2103}
2104
2105TEST_F(VoiceChannelTest, TestReceiveTwoOffers) {
2106 Base::TestReceiveTwoOffers();
2107}
2108
2109TEST_F(VoiceChannelTest, TestSendPrAnswer) {
2110 Base::TestSendPrAnswer();
2111}
2112
2113TEST_F(VoiceChannelTest, TestReceivePrAnswer) {
2114 Base::TestReceivePrAnswer();
2115}
2116
2117TEST_F(VoiceChannelTest, TestFlushRtcp) {
2118 Base::TestFlushRtcp();
2119}
2120
2121TEST_F(VoiceChannelTest, TestChangeStateError) {
2122 Base::TestChangeStateError();
2123}
2124
2125TEST_F(VoiceChannelTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002126 Base::TestSrtpError(kAudioPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002127}
2128
2129TEST_F(VoiceChannelTest, TestOnReadyToSend) {
2130 Base::TestOnReadyToSend();
2131}
2132
2133TEST_F(VoiceChannelTest, TestOnReadyToSendWithRtcpMux) {
2134 Base::TestOnReadyToSendWithRtcpMux();
2135}
2136
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002137// Test that we can scale the output volume properly for 1:1 calls.
2138TEST_F(VoiceChannelTest, TestScaleVolume1to1Call) {
2139 CreateChannels(RTCP, RTCP);
2140 EXPECT_TRUE(SendInitiate());
2141 EXPECT_TRUE(SendAccept());
2142 double left, right;
2143
2144 // Default is (1.0, 1.0).
2145 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2146 EXPECT_DOUBLE_EQ(1.0, left);
2147 EXPECT_DOUBLE_EQ(1.0, right);
2148 // invalid ssrc.
2149 EXPECT_FALSE(media_channel1_->GetOutputScaling(3, &left, &right));
2150
2151 // Set scale to (1.5, 0.5).
2152 EXPECT_TRUE(channel1_->SetOutputScaling(0, 1.5, 0.5));
2153 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2154 EXPECT_DOUBLE_EQ(1.5, left);
2155 EXPECT_DOUBLE_EQ(0.5, right);
2156
2157 // Set scale to (0, 0).
2158 EXPECT_TRUE(channel1_->SetOutputScaling(0, 0.0, 0.0));
2159 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2160 EXPECT_DOUBLE_EQ(0.0, left);
2161 EXPECT_DOUBLE_EQ(0.0, right);
2162}
2163
2164// Test that we can scale the output volume properly for multiway calls.
2165TEST_F(VoiceChannelTest, TestScaleVolumeMultiwayCall) {
2166 CreateChannels(RTCP, RTCP);
2167 EXPECT_TRUE(SendInitiate());
2168 EXPECT_TRUE(SendAccept());
2169 EXPECT_TRUE(AddStream1(1));
2170 EXPECT_TRUE(AddStream1(2));
2171
2172 double left, right;
2173 // Default is (1.0, 1.0).
2174 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2175 EXPECT_DOUBLE_EQ(1.0, left);
2176 EXPECT_DOUBLE_EQ(1.0, right);
2177 EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
2178 EXPECT_DOUBLE_EQ(1.0, left);
2179 EXPECT_DOUBLE_EQ(1.0, right);
2180 EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
2181 EXPECT_DOUBLE_EQ(1.0, left);
2182 EXPECT_DOUBLE_EQ(1.0, right);
2183 // invalid ssrc.
2184 EXPECT_FALSE(media_channel1_->GetOutputScaling(3, &left, &right));
2185
2186 // Set scale to (1.5, 0.5) for ssrc = 1.
2187 EXPECT_TRUE(channel1_->SetOutputScaling(1, 1.5, 0.5));
2188 EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
2189 EXPECT_DOUBLE_EQ(1.5, left);
2190 EXPECT_DOUBLE_EQ(0.5, right);
2191 EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
2192 EXPECT_DOUBLE_EQ(1.0, left);
2193 EXPECT_DOUBLE_EQ(1.0, right);
2194 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2195 EXPECT_DOUBLE_EQ(1.0, left);
2196 EXPECT_DOUBLE_EQ(1.0, right);
2197
2198 // Set scale to (0, 0) for all ssrcs.
2199 EXPECT_TRUE(channel1_->SetOutputScaling(0, 0.0, 0.0));
2200 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2201 EXPECT_DOUBLE_EQ(0.0, left);
2202 EXPECT_DOUBLE_EQ(0.0, right);
2203 EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
2204 EXPECT_DOUBLE_EQ(0.0, left);
2205 EXPECT_DOUBLE_EQ(0.0, right);
2206 EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
2207 EXPECT_DOUBLE_EQ(0.0, left);
2208 EXPECT_DOUBLE_EQ(0.0, right);
2209}
2210
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002211TEST_F(VoiceChannelTest, SendBundleToBundle) {
2212 Base::SendBundleToBundle(kAudioPts, ARRAY_SIZE(kAudioPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002213}
2214
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002215TEST_F(VoiceChannelTest, SendBundleToBundleSecure) {
2216 Base::SendBundleToBundle(kAudioPts, ARRAY_SIZE(kAudioPts), false, true);
2217}
2218
2219TEST_F(VoiceChannelTest, SendBundleToBundleWithRtcpMux) {
2220 Base::SendBundleToBundle(
2221 kAudioPts, ARRAY_SIZE(kAudioPts), true, false);
2222}
2223
2224TEST_F(VoiceChannelTest, SendBundleToBundleWithRtcpMuxSecure) {
2225 Base::SendBundleToBundle(
2226 kAudioPts, ARRAY_SIZE(kAudioPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002227}
2228
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002229// VideoChannelTest
2230TEST_F(VideoChannelTest, TestInit) {
2231 Base::TestInit();
2232}
2233
2234TEST_F(VideoChannelTest, TestSetContents) {
2235 Base::TestSetContents();
2236}
2237
2238TEST_F(VideoChannelTest, TestSetContentsNullOffer) {
2239 Base::TestSetContentsNullOffer();
2240}
2241
2242TEST_F(VideoChannelTest, TestSetContentsRtcpMux) {
2243 Base::TestSetContentsRtcpMux();
2244}
2245
2246TEST_F(VideoChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
2247 Base::TestSetContentsRtcpMux();
2248}
2249
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002250TEST_F(VideoChannelTest, TestSetRemoteContentUpdate) {
2251 Base::TestSetRemoteContentUpdate();
2252}
2253
2254TEST_F(VideoChannelTest, TestStreams) {
2255 Base::TestStreams();
2256}
2257
2258TEST_F(VideoChannelTest, TestScreencastEvents) {
2259 const int kTimeoutMs = 500;
2260 TestInit();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002261 cricket::ScreencastEventCatcher catcher;
2262 channel1_->SignalScreencastWindowEvent.connect(
2263 &catcher,
2264 &cricket::ScreencastEventCatcher::OnEvent);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002265
2266 rtc::scoped_ptr<cricket::FakeScreenCapturerFactory>
2267 screen_capturer_factory(new cricket::FakeScreenCapturerFactory());
2268 cricket::VideoCapturer* screen_capturer = screen_capturer_factory->Create(
2269 ScreencastId(WindowId(0)));
2270 ASSERT_TRUE(screen_capturer != NULL);
2271
2272 EXPECT_TRUE(channel1_->AddScreencast(0, screen_capturer));
2273 EXPECT_EQ_WAIT(cricket::CS_STOPPED, screen_capturer_factory->capture_state(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002274 kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002275
2276 screen_capturer->SignalStateChange(screen_capturer, cricket::CS_PAUSED);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002277 EXPECT_EQ_WAIT(rtc::WE_MINIMIZE, catcher.event(), kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002278
2279 screen_capturer->SignalStateChange(screen_capturer, cricket::CS_RUNNING);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002280 EXPECT_EQ_WAIT(rtc::WE_RESTORE, catcher.event(), kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002281
2282 screen_capturer->SignalStateChange(screen_capturer, cricket::CS_STOPPED);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002283 EXPECT_EQ_WAIT(rtc::WE_CLOSE, catcher.event(), kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002284
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002285 EXPECT_TRUE(channel1_->RemoveScreencast(0));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002286}
2287
2288TEST_F(VideoChannelTest, TestUpdateStreamsInLocalContent) {
2289 Base::TestUpdateStreamsInLocalContent();
2290}
2291
2292TEST_F(VideoChannelTest, TestUpdateRemoteStreamsInContent) {
2293 Base::TestUpdateStreamsInRemoteContent();
2294}
2295
2296TEST_F(VideoChannelTest, TestChangeStreamParamsInContent) {
2297 Base::TestChangeStreamParamsInContent();
2298}
2299
2300TEST_F(VideoChannelTest, TestPlayoutAndSendingStates) {
2301 Base::TestPlayoutAndSendingStates();
2302}
2303
2304TEST_F(VideoChannelTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002305 CreateChannels(0, 0);
2306 // Test that we can Mute the default channel even though the sending SSRC
2307 // is unknown.
2308 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2309 EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr));
2310 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2311 EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr));
2312 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2313 // Test that we can not mute an unknown SSRC.
2314 EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, true, nullptr));
2315 SendInitiate();
2316 // After the local session description has been set, we can mute a stream
2317 // with its SSRC.
2318 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr));
2319 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2320 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr));
2321 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002322}
2323
2324TEST_F(VideoChannelTest, TestMediaContentDirection) {
2325 Base::TestMediaContentDirection();
2326}
2327
2328TEST_F(VideoChannelTest, TestCallSetup) {
2329 Base::TestCallSetup();
2330}
2331
2332TEST_F(VideoChannelTest, TestCallTeardownRtcpMux) {
2333 Base::TestCallTeardownRtcpMux();
2334}
2335
2336TEST_F(VideoChannelTest, SendRtpToRtp) {
2337 Base::SendRtpToRtp();
2338}
2339
2340TEST_F(VideoChannelTest, SendNoRtcpToNoRtcp) {
2341 Base::SendNoRtcpToNoRtcp();
2342}
2343
2344TEST_F(VideoChannelTest, SendNoRtcpToRtcp) {
2345 Base::SendNoRtcpToRtcp();
2346}
2347
2348TEST_F(VideoChannelTest, SendRtcpToNoRtcp) {
2349 Base::SendRtcpToNoRtcp();
2350}
2351
2352TEST_F(VideoChannelTest, SendRtcpToRtcp) {
2353 Base::SendRtcpToRtcp();
2354}
2355
2356TEST_F(VideoChannelTest, SendRtcpMuxToRtcp) {
2357 Base::SendRtcpMuxToRtcp();
2358}
2359
2360TEST_F(VideoChannelTest, SendRtcpMuxToRtcpMux) {
2361 Base::SendRtcpMuxToRtcpMux();
2362}
2363
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002364TEST_F(VideoChannelTest, SendRequireRtcpMuxToRtcpMux) {
2365 Base::SendRequireRtcpMuxToRtcpMux();
2366}
2367
2368TEST_F(VideoChannelTest, SendRtcpMuxToRequireRtcpMux) {
2369 Base::SendRtcpMuxToRequireRtcpMux();
2370}
2371
2372TEST_F(VideoChannelTest, SendRequireRtcpMuxToRequireRtcpMux) {
2373 Base::SendRequireRtcpMuxToRequireRtcpMux();
2374}
2375
2376TEST_F(VideoChannelTest, SendRequireRtcpMuxToNoRtcpMux) {
2377 Base::SendRequireRtcpMuxToNoRtcpMux();
2378}
2379
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002380TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcp) {
2381 Base::SendEarlyRtcpMuxToRtcp();
2382}
2383
2384TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2385 Base::SendEarlyRtcpMuxToRtcpMux();
2386}
2387
2388TEST_F(VideoChannelTest, SendSrtpToSrtp) {
2389 Base::SendSrtpToSrtp();
2390}
2391
2392TEST_F(VideoChannelTest, SendSrtpToRtp) {
2393 Base::SendSrtpToSrtp();
2394}
2395
2396TEST_F(VideoChannelTest, SendDtlsSrtpToSrtp) {
2397 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2398 Base::SendSrtpToSrtp(DTLS, 0);
2399}
2400
2401TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtp) {
2402 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2403 Base::SendSrtpToSrtp(DTLS, DTLS);
2404}
2405
2406TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2407 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2408 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2409}
2410
2411TEST_F(VideoChannelTest, SendSrtcpMux) {
2412 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2413}
2414
2415TEST_F(VideoChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2416 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2417}
2418
2419TEST_F(VideoChannelTest, SendRtpToRtpOnThread) {
2420 Base::SendRtpToRtpOnThread();
2421}
2422
2423TEST_F(VideoChannelTest, SendSrtpToSrtpOnThread) {
2424 Base::SendSrtpToSrtpOnThread();
2425}
2426
2427TEST_F(VideoChannelTest, SendWithWritabilityLoss) {
2428 Base::SendWithWritabilityLoss();
2429}
2430
2431TEST_F(VideoChannelTest, TestMediaMonitor) {
2432 Base::TestMediaMonitor();
2433}
2434
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002435TEST_F(VideoChannelTest, TestSetContentFailure) {
2436 Base::TestSetContentFailure();
2437}
2438
2439TEST_F(VideoChannelTest, TestSendTwoOffers) {
2440 Base::TestSendTwoOffers();
2441}
2442
2443TEST_F(VideoChannelTest, TestReceiveTwoOffers) {
2444 Base::TestReceiveTwoOffers();
2445}
2446
2447TEST_F(VideoChannelTest, TestSendPrAnswer) {
2448 Base::TestSendPrAnswer();
2449}
2450
2451TEST_F(VideoChannelTest, TestReceivePrAnswer) {
2452 Base::TestReceivePrAnswer();
2453}
2454
2455TEST_F(VideoChannelTest, TestFlushRtcp) {
2456 Base::TestFlushRtcp();
2457}
2458
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002459TEST_F(VideoChannelTest, SendBundleToBundle) {
2460 Base::SendBundleToBundle(kVideoPts, ARRAY_SIZE(kVideoPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002461}
2462
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002463TEST_F(VideoChannelTest, SendBundleToBundleSecure) {
2464 Base::SendBundleToBundle(kVideoPts, ARRAY_SIZE(kVideoPts), false, true);
2465}
2466
2467TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMux) {
2468 Base::SendBundleToBundle(
2469 kVideoPts, ARRAY_SIZE(kVideoPts), true, false);
2470}
2471
2472TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMuxSecure) {
2473 Base::SendBundleToBundle(
2474 kVideoPts, ARRAY_SIZE(kVideoPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002475}
2476
2477// TODO(gangji): Add VideoChannelTest.TestChangeStateError.
2478
2479TEST_F(VideoChannelTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002480 Base::TestSrtpError(kVideoPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002481}
2482
2483TEST_F(VideoChannelTest, TestOnReadyToSend) {
2484 Base::TestOnReadyToSend();
2485}
2486
2487TEST_F(VideoChannelTest, TestOnReadyToSendWithRtcpMux) {
2488 Base::TestOnReadyToSendWithRtcpMux();
2489}
2490
2491TEST_F(VideoChannelTest, TestApplyViewRequest) {
2492 CreateChannels(0, 0);
2493 cricket::StreamParams stream2;
2494 stream2.id = "stream2";
2495 stream2.ssrcs.push_back(2222);
2496 local_media_content1_.AddStream(stream2);
2497
2498 EXPECT_TRUE(SendInitiate());
2499 EXPECT_TRUE(SendAccept());
2500
2501 cricket::VideoFormat send_format;
2502 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2503 EXPECT_EQ(640, send_format.width);
2504 EXPECT_EQ(400, send_format.height);
2505 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), send_format.interval);
2506
2507 cricket::ViewRequest request;
2508 // stream1: 320x200x15; stream2: 0x0x0
2509 request.static_video_views.push_back(cricket::StaticVideoView(
2510 cricket::StreamSelector(kSsrc1), 320, 200, 15));
2511 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2512 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2513 EXPECT_EQ(320, send_format.width);
2514 EXPECT_EQ(200, send_format.height);
2515 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(15), send_format.interval);
2516 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(2222, &send_format));
2517 EXPECT_EQ(0, send_format.width);
2518 EXPECT_EQ(0, send_format.height);
2519
2520 // stream1: 160x100x8; stream2: 0x0x0
2521 request.static_video_views.clear();
2522 request.static_video_views.push_back(cricket::StaticVideoView(
2523 cricket::StreamSelector(kSsrc1), 160, 100, 8));
2524 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2525 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2526 EXPECT_EQ(160, send_format.width);
2527 EXPECT_EQ(100, send_format.height);
2528 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(8), send_format.interval);
2529
2530 // stream1: 0x0x0; stream2: 640x400x30
2531 request.static_video_views.clear();
2532 request.static_video_views.push_back(cricket::StaticVideoView(
2533 cricket::StreamSelector("", stream2.id), 640, 400, 30));
2534 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2535 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2536 EXPECT_EQ(0, send_format.width);
2537 EXPECT_EQ(0, send_format.height);
2538 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(2222, &send_format));
2539 EXPECT_EQ(640, send_format.width);
2540 EXPECT_EQ(400, send_format.height);
2541 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), send_format.interval);
2542
2543 // stream1: 0x0x0; stream2: 0x0x0
2544 request.static_video_views.clear();
2545 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2546 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2547 EXPECT_EQ(0, send_format.width);
2548 EXPECT_EQ(0, send_format.height);
2549}
2550
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002551
2552// DataChannelTest
2553
2554class DataChannelTest
2555 : public ChannelTest<DataTraits> {
2556 public:
2557 typedef ChannelTest<DataTraits>
2558 Base;
2559 DataChannelTest() : Base(kDataPacket, sizeof(kDataPacket),
2560 kRtcpReport, sizeof(kRtcpReport)) {
2561 }
2562};
2563
2564// Override to avoid engine channel parameter.
deadbeefcbecd352015-09-23 11:50:27 -07002565template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002566cricket::DataChannel* ChannelTest<DataTraits>::CreateChannel(
deadbeefcbecd352015-09-23 11:50:27 -07002567 rtc::Thread* thread,
2568 cricket::MediaEngineInterface* engine,
2569 cricket::FakeDataMediaChannel* ch,
2570 cricket::TransportController* transport_controller,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002571 bool rtcp) {
2572 cricket::DataChannel* channel = new cricket::DataChannel(
deadbeefcbecd352015-09-23 11:50:27 -07002573 thread, ch, transport_controller, cricket::CN_DATA, rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002574 if (!channel->Init()) {
2575 delete channel;
2576 channel = NULL;
2577 }
2578 return channel;
2579}
2580
2581template<>
2582void ChannelTest<DataTraits>::CreateContent(
2583 int flags,
2584 const cricket::AudioCodec& audio_codec,
2585 const cricket::VideoCodec& video_codec,
2586 cricket::DataContentDescription* data) {
2587 data->AddCodec(kGoogleDataCodec);
2588 data->set_rtcp_mux((flags & RTCP_MUX) != 0);
2589 if (flags & SECURE) {
2590 data->AddCrypto(cricket::CryptoParams(
2591 1, cricket::CS_AES_CM_128_HMAC_SHA1_32,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002592 "inline:" + rtc::CreateRandomString(40), ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002593 }
2594}
2595
2596template<>
2597void ChannelTest<DataTraits>::CopyContent(
2598 const cricket::DataContentDescription& source,
2599 cricket::DataContentDescription* data) {
2600 *data = source;
2601}
2602
2603template<>
2604bool ChannelTest<DataTraits>::CodecMatches(const cricket::DataCodec& c1,
2605 const cricket::DataCodec& c2) {
2606 return c1.name == c2.name;
2607}
2608
2609template<>
2610void ChannelTest<DataTraits>::AddLegacyStreamInContent(
2611 uint32 ssrc, int flags, cricket::DataContentDescription* data) {
2612 data->AddLegacyStream(ssrc);
2613}
2614
2615TEST_F(DataChannelTest, TestInit) {
2616 Base::TestInit();
2617 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2618}
2619
2620TEST_F(DataChannelTest, TestSetContents) {
2621 Base::TestSetContents();
2622}
2623
2624TEST_F(DataChannelTest, TestSetContentsNullOffer) {
2625 Base::TestSetContentsNullOffer();
2626}
2627
2628TEST_F(DataChannelTest, TestSetContentsRtcpMux) {
2629 Base::TestSetContentsRtcpMux();
2630}
2631
2632TEST_F(DataChannelTest, TestSetRemoteContentUpdate) {
2633 Base::TestSetRemoteContentUpdate();
2634}
2635
2636TEST_F(DataChannelTest, TestStreams) {
2637 Base::TestStreams();
2638}
2639
2640TEST_F(DataChannelTest, TestUpdateStreamsInLocalContent) {
2641 Base::TestUpdateStreamsInLocalContent();
2642}
2643
2644TEST_F(DataChannelTest, TestUpdateRemoteStreamsInContent) {
2645 Base::TestUpdateStreamsInRemoteContent();
2646}
2647
2648TEST_F(DataChannelTest, TestChangeStreamParamsInContent) {
2649 Base::TestChangeStreamParamsInContent();
2650}
2651
2652TEST_F(DataChannelTest, TestPlayoutAndSendingStates) {
2653 Base::TestPlayoutAndSendingStates();
2654}
2655
2656TEST_F(DataChannelTest, TestMediaContentDirection) {
2657 Base::TestMediaContentDirection();
2658}
2659
2660TEST_F(DataChannelTest, TestCallSetup) {
2661 Base::TestCallSetup();
2662}
2663
2664TEST_F(DataChannelTest, TestCallTeardownRtcpMux) {
2665 Base::TestCallTeardownRtcpMux();
2666}
2667
2668TEST_F(DataChannelTest, TestOnReadyToSend) {
2669 Base::TestOnReadyToSend();
2670}
2671
2672TEST_F(DataChannelTest, TestOnReadyToSendWithRtcpMux) {
2673 Base::TestOnReadyToSendWithRtcpMux();
2674}
2675
2676TEST_F(DataChannelTest, SendRtpToRtp) {
2677 Base::SendRtpToRtp();
2678}
2679
2680TEST_F(DataChannelTest, SendNoRtcpToNoRtcp) {
2681 Base::SendNoRtcpToNoRtcp();
2682}
2683
2684TEST_F(DataChannelTest, SendNoRtcpToRtcp) {
2685 Base::SendNoRtcpToRtcp();
2686}
2687
2688TEST_F(DataChannelTest, SendRtcpToNoRtcp) {
2689 Base::SendRtcpToNoRtcp();
2690}
2691
2692TEST_F(DataChannelTest, SendRtcpToRtcp) {
2693 Base::SendRtcpToRtcp();
2694}
2695
2696TEST_F(DataChannelTest, SendRtcpMuxToRtcp) {
2697 Base::SendRtcpMuxToRtcp();
2698}
2699
2700TEST_F(DataChannelTest, SendRtcpMuxToRtcpMux) {
2701 Base::SendRtcpMuxToRtcpMux();
2702}
2703
2704TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcp) {
2705 Base::SendEarlyRtcpMuxToRtcp();
2706}
2707
2708TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2709 Base::SendEarlyRtcpMuxToRtcpMux();
2710}
2711
2712TEST_F(DataChannelTest, SendSrtpToSrtp) {
2713 Base::SendSrtpToSrtp();
2714}
2715
2716TEST_F(DataChannelTest, SendSrtpToRtp) {
2717 Base::SendSrtpToSrtp();
2718}
2719
2720TEST_F(DataChannelTest, SendSrtcpMux) {
2721 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2722}
2723
2724TEST_F(DataChannelTest, SendRtpToRtpOnThread) {
2725 Base::SendRtpToRtpOnThread();
2726}
2727
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002728TEST_F(DataChannelTest, SendSrtpToSrtpOnThread) {
2729 Base::SendSrtpToSrtpOnThread();
2730}
2731
2732TEST_F(DataChannelTest, SendWithWritabilityLoss) {
2733 Base::SendWithWritabilityLoss();
2734}
2735
2736TEST_F(DataChannelTest, TestMediaMonitor) {
2737 Base::TestMediaMonitor();
2738}
2739
2740TEST_F(DataChannelTest, TestSendData) {
2741 CreateChannels(0, 0);
2742 EXPECT_TRUE(SendInitiate());
2743 EXPECT_TRUE(SendAccept());
2744
2745 cricket::SendDataParams params;
2746 params.ssrc = 42;
2747 unsigned char data[] = {
2748 'f', 'o', 'o'
2749 };
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002750 rtc::Buffer payload(data, 3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002751 cricket::SendDataResult result;
2752 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
2753 EXPECT_EQ(params.ssrc,
2754 media_channel1_->last_sent_data_params().ssrc);
2755 EXPECT_EQ("foo", media_channel1_->last_sent_data());
2756}
2757
2758// TODO(pthatcher): TestSetReceiver?