blob: 0b142ae59a4a8e68ea338bb6de87ca3bc3a957eb [file] [log] [blame]
pbos@webrtc.org119a1cc2013-08-20 13:14:07 +00001/*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10#include "testing/gtest/include/gtest/gtest.h"
11#include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h"
pbos@webrtc.org013d9942013-08-22 09:42:17 +000012#include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
pbos@webrtc.org119a1cc2013-08-20 13:14:07 +000013#include "webrtc/system_wrappers/interface/event_wrapper.h"
14#include "webrtc/system_wrappers/interface/scoped_ptr.h"
pbos@webrtc.orgcb5118c2013-09-03 09:10:37 +000015#include "webrtc/video_engine/test/common/fake_encoder.h"
pbos@webrtc.org119a1cc2013-08-20 13:14:07 +000016#include "webrtc/video_engine/test/common/frame_generator.h"
17#include "webrtc/video_engine/test/common/frame_generator_capturer.h"
18#include "webrtc/video_engine/test/common/null_transport.h"
19#include "webrtc/video_engine/new_include/video_call.h"
20#include "webrtc/video_engine/new_include/video_send_stream.h"
21
22namespace webrtc {
23
pbos@webrtc.org119a1cc2013-08-20 13:14:07 +000024class SendTransportObserver : public test::NullTransport {
25 public:
26 explicit SendTransportObserver(unsigned long timeout_ms)
27 : rtp_header_parser_(RtpHeaderParser::Create()),
28 send_test_complete_(EventWrapper::Create()),
29 timeout_ms_(timeout_ms) {}
30
31 EventTypeWrapper Wait() {
32 return send_test_complete_->Wait(timeout_ms_);
33 }
34
35 protected:
36 scoped_ptr<RtpHeaderParser> rtp_header_parser_;
37 scoped_ptr<EventWrapper> send_test_complete_;
38
39 private:
40 unsigned long timeout_ms_;
41};
42
pbos@webrtc.org013d9942013-08-22 09:42:17 +000043class VideoSendStreamTest : public ::testing::Test {
pbos@webrtc.orgcb5118c2013-09-03 09:10:37 +000044 public:
45 VideoSendStreamTest() : fake_encoder_(Clock::GetRealTimeClock()) {}
pbos@webrtc.org013d9942013-08-22 09:42:17 +000046 protected:
47 static const uint32_t kSendSsrc;
pbos@webrtc.org74fa4892013-08-23 09:19:30 +000048 void RunSendTest(VideoCall* call,
49 const VideoSendStream::Config& config,
pbos@webrtc.org013d9942013-08-22 09:42:17 +000050 SendTransportObserver* observer) {
pbos@webrtc.org74fa4892013-08-23 09:19:30 +000051 VideoSendStream* send_stream = call->CreateSendStream(config);
pbos@webrtc.org013d9942013-08-22 09:42:17 +000052 scoped_ptr<test::FrameGeneratorCapturer> frame_generator_capturer(
53 test::FrameGeneratorCapturer::Create(
54 send_stream->Input(),
55 test::FrameGenerator::Create(320, 240, Clock::GetRealTimeClock()),
56 30));
57 send_stream->StartSend();
58 frame_generator_capturer->Start();
59
60 EXPECT_EQ(kEventSignaled, observer->Wait());
61
62 frame_generator_capturer->Stop();
63 send_stream->StopSend();
64 call->DestroySendStream(send_stream);
65 }
pbos@webrtc.orgcb5118c2013-09-03 09:10:37 +000066
67 VideoSendStream::Config GetSendTestConfig(VideoCall* call) {
68 VideoSendStream::Config config = call->GetDefaultSendConfig();
69 config.encoder = &fake_encoder_;
70 config.internal_source = false;
71 test::FakeEncoder::SetCodecStreamSettings(&config.codec, 1);
72 config.codec.plType = 100;
73 return config;
74 }
75
76 test::FakeEncoder fake_encoder_;
pbos@webrtc.org013d9942013-08-22 09:42:17 +000077};
78
79const uint32_t VideoSendStreamTest::kSendSsrc = 0xC0FFEE;
80
pbos@webrtc.org119a1cc2013-08-20 13:14:07 +000081TEST_F(VideoSendStreamTest, SendsSetSsrc) {
pbos@webrtc.org119a1cc2013-08-20 13:14:07 +000082 class SendSsrcObserver : public SendTransportObserver {
83 public:
84 SendSsrcObserver() : SendTransportObserver(30 * 1000) {}
85
86 virtual bool SendRTP(const uint8_t* packet, size_t length) OVERRIDE {
87 RTPHeader header;
88 EXPECT_TRUE(
89 rtp_header_parser_->Parse(packet, static_cast<int>(length), &header));
90
91 if (header.ssrc == kSendSsrc)
92 send_test_complete_->Set();
93
94 return true;
95 }
96 } observer;
97
pbos@webrtc.org74fa4892013-08-23 09:19:30 +000098 VideoCall::Config call_config(&observer);
99 scoped_ptr<VideoCall> call(VideoCall::Create(call_config));
pbos@webrtc.org119a1cc2013-08-20 13:14:07 +0000100
pbos@webrtc.orgcb5118c2013-09-03 09:10:37 +0000101 VideoSendStream::Config send_config = GetSendTestConfig(call.get());
pbos@webrtc.org119a1cc2013-08-20 13:14:07 +0000102 send_config.rtp.ssrcs.push_back(kSendSsrc);
pbos@webrtc.org119a1cc2013-08-20 13:14:07 +0000103
pbos@webrtc.org013d9942013-08-22 09:42:17 +0000104 RunSendTest(call.get(), send_config, &observer);
105}
pbos@webrtc.org119a1cc2013-08-20 13:14:07 +0000106
pbos@webrtc.org013d9942013-08-22 09:42:17 +0000107TEST_F(VideoSendStreamTest, SupportsCName) {
108 static std::string kCName = "PjQatC14dGfbVwGPUOA9IH7RlsFDbWl4AhXEiDsBizo=";
109 class CNameObserver : public SendTransportObserver {
110 public:
111 CNameObserver() : SendTransportObserver(30 * 1000) {}
112
113 virtual bool SendRTCP(const uint8_t* packet, size_t length) OVERRIDE {
114 RTCPUtility::RTCPParserV2 parser(packet, length, true);
115 EXPECT_TRUE(parser.IsValid());
116
117 RTCPUtility::RTCPPacketTypes packet_type = parser.Begin();
118 while (packet_type != RTCPUtility::kRtcpNotValidCode) {
119 if (packet_type == RTCPUtility::kRtcpSdesChunkCode) {
120 EXPECT_EQ(parser.Packet().CName.CName, kCName);
121 send_test_complete_->Set();
122 }
123
124 packet_type = parser.Iterate();
125 }
126
127 return true;
128 }
129 } observer;
130
pbos@webrtc.org74fa4892013-08-23 09:19:30 +0000131 VideoCall::Config call_config(&observer);
132 scoped_ptr<VideoCall> call(VideoCall::Create(call_config));
pbos@webrtc.org013d9942013-08-22 09:42:17 +0000133
pbos@webrtc.orgcb5118c2013-09-03 09:10:37 +0000134 VideoSendStream::Config send_config = GetSendTestConfig(call.get());
pbos@webrtc.org013d9942013-08-22 09:42:17 +0000135 send_config.rtp.ssrcs.push_back(kSendSsrc);
136 send_config.rtp.c_name = kCName;
137
138 RunSendTest(call.get(), send_config, &observer);
pbos@webrtc.org119a1cc2013-08-20 13:14:07 +0000139}
140
141} // namespace webrtc