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