blob: 1e1ac27c39bb7569a31f051557cfab07c4f444be [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;
pbos@webrtc.org0181b5f2013-09-09 08:26:30 +000071 test::FakeEncoder::SetCodecSettings(&config.codec, 1);
pbos@webrtc.orgcb5118c2013-09-03 09:10:37 +000072 return config;
73 }
74
75 test::FakeEncoder fake_encoder_;
pbos@webrtc.org013d9942013-08-22 09:42:17 +000076};
77
78const uint32_t VideoSendStreamTest::kSendSsrc = 0xC0FFEE;
79
pbos@webrtc.org119a1cc2013-08-20 13:14:07 +000080TEST_F(VideoSendStreamTest, SendsSetSsrc) {
pbos@webrtc.org119a1cc2013-08-20 13:14:07 +000081 class SendSsrcObserver : public SendTransportObserver {
82 public:
83 SendSsrcObserver() : SendTransportObserver(30 * 1000) {}
84
85 virtual bool SendRTP(const uint8_t* packet, size_t length) OVERRIDE {
86 RTPHeader header;
87 EXPECT_TRUE(
88 rtp_header_parser_->Parse(packet, static_cast<int>(length), &header));
89
90 if (header.ssrc == kSendSsrc)
91 send_test_complete_->Set();
92
93 return true;
94 }
95 } observer;
96
pbos@webrtc.org74fa4892013-08-23 09:19:30 +000097 VideoCall::Config call_config(&observer);
98 scoped_ptr<VideoCall> call(VideoCall::Create(call_config));
pbos@webrtc.org119a1cc2013-08-20 13:14:07 +000099
pbos@webrtc.orgcb5118c2013-09-03 09:10:37 +0000100 VideoSendStream::Config send_config = GetSendTestConfig(call.get());
pbos@webrtc.org119a1cc2013-08-20 13:14:07 +0000101 send_config.rtp.ssrcs.push_back(kSendSsrc);
pbos@webrtc.org119a1cc2013-08-20 13:14:07 +0000102
pbos@webrtc.org013d9942013-08-22 09:42:17 +0000103 RunSendTest(call.get(), send_config, &observer);
104}
pbos@webrtc.org119a1cc2013-08-20 13:14:07 +0000105
pbos@webrtc.org013d9942013-08-22 09:42:17 +0000106TEST_F(VideoSendStreamTest, SupportsCName) {
107 static std::string kCName = "PjQatC14dGfbVwGPUOA9IH7RlsFDbWl4AhXEiDsBizo=";
108 class CNameObserver : public SendTransportObserver {
109 public:
110 CNameObserver() : SendTransportObserver(30 * 1000) {}
111
112 virtual bool SendRTCP(const uint8_t* packet, size_t length) OVERRIDE {
113 RTCPUtility::RTCPParserV2 parser(packet, length, true);
114 EXPECT_TRUE(parser.IsValid());
115
116 RTCPUtility::RTCPPacketTypes packet_type = parser.Begin();
117 while (packet_type != RTCPUtility::kRtcpNotValidCode) {
118 if (packet_type == RTCPUtility::kRtcpSdesChunkCode) {
119 EXPECT_EQ(parser.Packet().CName.CName, kCName);
120 send_test_complete_->Set();
121 }
122
123 packet_type = parser.Iterate();
124 }
125
126 return true;
127 }
128 } observer;
129
pbos@webrtc.org74fa4892013-08-23 09:19:30 +0000130 VideoCall::Config call_config(&observer);
131 scoped_ptr<VideoCall> call(VideoCall::Create(call_config));
pbos@webrtc.org013d9942013-08-22 09:42:17 +0000132
pbos@webrtc.orgcb5118c2013-09-03 09:10:37 +0000133 VideoSendStream::Config send_config = GetSendTestConfig(call.get());
pbos@webrtc.org013d9942013-08-22 09:42:17 +0000134 send_config.rtp.ssrcs.push_back(kSendSsrc);
135 send_config.rtp.c_name = kCName;
136
137 RunSendTest(call.get(), send_config, &observer);
pbos@webrtc.org119a1cc2013-08-20 13:14:07 +0000138}
139
140} // namespace webrtc