blob: dcf2ec1688769d600d31848c3e5eb8c3b9b39082 [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"
pbos@webrtc.org841c8a42013-09-09 15:04:25 +000019#include "webrtc/video_engine/new_include/call.h"
pbos@webrtc.org119a1cc2013-08-20 13:14:07 +000020#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
pbos@webrtc.org841c8a42013-09-09 15:04:25 +000031 EventTypeWrapper Wait() { return send_test_complete_->Wait(timeout_ms_); }
pbos@webrtc.org119a1cc2013-08-20 13:14:07 +000032
33 protected:
34 scoped_ptr<RtpHeaderParser> rtp_header_parser_;
35 scoped_ptr<EventWrapper> send_test_complete_;
36
37 private:
38 unsigned long timeout_ms_;
39};
40
pbos@webrtc.org013d9942013-08-22 09:42:17 +000041class VideoSendStreamTest : public ::testing::Test {
pbos@webrtc.orgcb5118c2013-09-03 09:10:37 +000042 public:
43 VideoSendStreamTest() : fake_encoder_(Clock::GetRealTimeClock()) {}
pbos@webrtc.org841c8a42013-09-09 15:04:25 +000044
pbos@webrtc.org013d9942013-08-22 09:42:17 +000045 protected:
46 static const uint32_t kSendSsrc;
pbos@webrtc.org841c8a42013-09-09 15:04:25 +000047 void RunSendTest(Call* call,
pbos@webrtc.org74fa4892013-08-23 09:19:30 +000048 const VideoSendStream::Config& config,
pbos@webrtc.org013d9942013-08-22 09:42:17 +000049 SendTransportObserver* observer) {
pbos@webrtc.org74fa4892013-08-23 09:19:30 +000050 VideoSendStream* send_stream = call->CreateSendStream(config);
pbos@webrtc.org013d9942013-08-22 09:42:17 +000051 scoped_ptr<test::FrameGeneratorCapturer> frame_generator_capturer(
52 test::FrameGeneratorCapturer::Create(
53 send_stream->Input(),
54 test::FrameGenerator::Create(320, 240, Clock::GetRealTimeClock()),
55 30));
56 send_stream->StartSend();
57 frame_generator_capturer->Start();
58
59 EXPECT_EQ(kEventSignaled, observer->Wait());
60
61 frame_generator_capturer->Stop();
62 send_stream->StopSend();
63 call->DestroySendStream(send_stream);
64 }
pbos@webrtc.orgcb5118c2013-09-03 09:10:37 +000065
pbos@webrtc.org841c8a42013-09-09 15:04:25 +000066 VideoSendStream::Config GetSendTestConfig(Call* call) {
pbos@webrtc.orgcb5118c2013-09-03 09:10:37 +000067 VideoSendStream::Config config = call->GetDefaultSendConfig();
68 config.encoder = &fake_encoder_;
69 config.internal_source = false;
pbos@webrtc.org0181b5f2013-09-09 08:26:30 +000070 test::FakeEncoder::SetCodecSettings(&config.codec, 1);
pbos@webrtc.orgcb5118c2013-09-03 09:10:37 +000071 return config;
72 }
73
74 test::FakeEncoder fake_encoder_;
pbos@webrtc.org013d9942013-08-22 09:42:17 +000075};
76
77const uint32_t VideoSendStreamTest::kSendSsrc = 0xC0FFEE;
78
pbos@webrtc.org119a1cc2013-08-20 13:14:07 +000079TEST_F(VideoSendStreamTest, SendsSetSsrc) {
pbos@webrtc.org119a1cc2013-08-20 13:14:07 +000080 class SendSsrcObserver : public SendTransportObserver {
81 public:
82 SendSsrcObserver() : SendTransportObserver(30 * 1000) {}
83
84 virtual bool SendRTP(const uint8_t* packet, size_t length) OVERRIDE {
85 RTPHeader header;
86 EXPECT_TRUE(
87 rtp_header_parser_->Parse(packet, static_cast<int>(length), &header));
88
89 if (header.ssrc == kSendSsrc)
90 send_test_complete_->Set();
91
92 return true;
93 }
94 } observer;
95
pbos@webrtc.org841c8a42013-09-09 15:04:25 +000096 Call::Config call_config(&observer);
97 scoped_ptr<Call> call(Call::Create(call_config));
pbos@webrtc.org119a1cc2013-08-20 13:14:07 +000098
pbos@webrtc.orgcb5118c2013-09-03 09:10:37 +000099 VideoSendStream::Config send_config = GetSendTestConfig(call.get());
pbos@webrtc.org119a1cc2013-08-20 13:14:07 +0000100 send_config.rtp.ssrcs.push_back(kSendSsrc);
pbos@webrtc.org119a1cc2013-08-20 13:14:07 +0000101
pbos@webrtc.org013d9942013-08-22 09:42:17 +0000102 RunSendTest(call.get(), send_config, &observer);
103}
pbos@webrtc.org119a1cc2013-08-20 13:14:07 +0000104
pbos@webrtc.org013d9942013-08-22 09:42:17 +0000105TEST_F(VideoSendStreamTest, SupportsCName) {
106 static std::string kCName = "PjQatC14dGfbVwGPUOA9IH7RlsFDbWl4AhXEiDsBizo=";
107 class CNameObserver : public SendTransportObserver {
108 public:
109 CNameObserver() : SendTransportObserver(30 * 1000) {}
110
111 virtual bool SendRTCP(const uint8_t* packet, size_t length) OVERRIDE {
112 RTCPUtility::RTCPParserV2 parser(packet, length, true);
113 EXPECT_TRUE(parser.IsValid());
114
115 RTCPUtility::RTCPPacketTypes packet_type = parser.Begin();
116 while (packet_type != RTCPUtility::kRtcpNotValidCode) {
117 if (packet_type == RTCPUtility::kRtcpSdesChunkCode) {
118 EXPECT_EQ(parser.Packet().CName.CName, kCName);
119 send_test_complete_->Set();
120 }
121
122 packet_type = parser.Iterate();
123 }
124
125 return true;
126 }
127 } observer;
128
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000129 Call::Config call_config(&observer);
130 scoped_ptr<Call> call(Call::Create(call_config));
pbos@webrtc.org013d9942013-08-22 09:42:17 +0000131
pbos@webrtc.orgcb5118c2013-09-03 09:10:37 +0000132 VideoSendStream::Config send_config = GetSendTestConfig(call.get());
pbos@webrtc.org013d9942013-08-22 09:42:17 +0000133 send_config.rtp.ssrcs.push_back(kSendSsrc);
134 send_config.rtp.c_name = kCName;
135
136 RunSendTest(call.get(), send_config, &observer);
pbos@webrtc.org119a1cc2013-08-20 13:14:07 +0000137}
138
139} // namespace webrtc