pbos@webrtc.org | 119a1cc | 2013-08-20 13:14:07 +0000 | [diff] [blame] | 1 | /* |
| 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.org | 013d994 | 2013-08-22 09:42:17 +0000 | [diff] [blame] | 12 | #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" |
pbos@webrtc.org | 119a1cc | 2013-08-20 13:14:07 +0000 | [diff] [blame] | 13 | #include "webrtc/system_wrappers/interface/event_wrapper.h" |
| 14 | #include "webrtc/system_wrappers/interface/scoped_ptr.h" |
pbos@webrtc.org | cb5118c | 2013-09-03 09:10:37 +0000 | [diff] [blame] | 15 | #include "webrtc/video_engine/test/common/fake_encoder.h" |
pbos@webrtc.org | 119a1cc | 2013-08-20 13:14:07 +0000 | [diff] [blame] | 16 | #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 | |
| 22 | namespace webrtc { |
| 23 | |
pbos@webrtc.org | 119a1cc | 2013-08-20 13:14:07 +0000 | [diff] [blame] | 24 | class 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.org | 013d994 | 2013-08-22 09:42:17 +0000 | [diff] [blame] | 43 | class VideoSendStreamTest : public ::testing::Test { |
pbos@webrtc.org | cb5118c | 2013-09-03 09:10:37 +0000 | [diff] [blame] | 44 | public: |
| 45 | VideoSendStreamTest() : fake_encoder_(Clock::GetRealTimeClock()) {} |
pbos@webrtc.org | 013d994 | 2013-08-22 09:42:17 +0000 | [diff] [blame] | 46 | protected: |
| 47 | static const uint32_t kSendSsrc; |
pbos@webrtc.org | 74fa489 | 2013-08-23 09:19:30 +0000 | [diff] [blame] | 48 | void RunSendTest(VideoCall* call, |
| 49 | const VideoSendStream::Config& config, |
pbos@webrtc.org | 013d994 | 2013-08-22 09:42:17 +0000 | [diff] [blame] | 50 | SendTransportObserver* observer) { |
pbos@webrtc.org | 74fa489 | 2013-08-23 09:19:30 +0000 | [diff] [blame] | 51 | VideoSendStream* send_stream = call->CreateSendStream(config); |
pbos@webrtc.org | 013d994 | 2013-08-22 09:42:17 +0000 | [diff] [blame] | 52 | 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.org | cb5118c | 2013-09-03 09:10:37 +0000 | [diff] [blame] | 66 | |
| 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.org | 013d994 | 2013-08-22 09:42:17 +0000 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | const uint32_t VideoSendStreamTest::kSendSsrc = 0xC0FFEE; |
| 80 | |
pbos@webrtc.org | 119a1cc | 2013-08-20 13:14:07 +0000 | [diff] [blame] | 81 | TEST_F(VideoSendStreamTest, SendsSetSsrc) { |
pbos@webrtc.org | 119a1cc | 2013-08-20 13:14:07 +0000 | [diff] [blame] | 82 | 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.org | 74fa489 | 2013-08-23 09:19:30 +0000 | [diff] [blame] | 98 | VideoCall::Config call_config(&observer); |
| 99 | scoped_ptr<VideoCall> call(VideoCall::Create(call_config)); |
pbos@webrtc.org | 119a1cc | 2013-08-20 13:14:07 +0000 | [diff] [blame] | 100 | |
pbos@webrtc.org | cb5118c | 2013-09-03 09:10:37 +0000 | [diff] [blame] | 101 | VideoSendStream::Config send_config = GetSendTestConfig(call.get()); |
pbos@webrtc.org | 119a1cc | 2013-08-20 13:14:07 +0000 | [diff] [blame] | 102 | send_config.rtp.ssrcs.push_back(kSendSsrc); |
pbos@webrtc.org | 119a1cc | 2013-08-20 13:14:07 +0000 | [diff] [blame] | 103 | |
pbos@webrtc.org | 013d994 | 2013-08-22 09:42:17 +0000 | [diff] [blame] | 104 | RunSendTest(call.get(), send_config, &observer); |
| 105 | } |
pbos@webrtc.org | 119a1cc | 2013-08-20 13:14:07 +0000 | [diff] [blame] | 106 | |
pbos@webrtc.org | 013d994 | 2013-08-22 09:42:17 +0000 | [diff] [blame] | 107 | TEST_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.org | 74fa489 | 2013-08-23 09:19:30 +0000 | [diff] [blame] | 131 | VideoCall::Config call_config(&observer); |
| 132 | scoped_ptr<VideoCall> call(VideoCall::Create(call_config)); |
pbos@webrtc.org | 013d994 | 2013-08-22 09:42:17 +0000 | [diff] [blame] | 133 | |
pbos@webrtc.org | cb5118c | 2013-09-03 09:10:37 +0000 | [diff] [blame] | 134 | VideoSendStream::Config send_config = GetSendTestConfig(call.get()); |
pbos@webrtc.org | 013d994 | 2013-08-22 09:42:17 +0000 | [diff] [blame] | 135 | send_config.rtp.ssrcs.push_back(kSendSsrc); |
| 136 | send_config.rtp.c_name = kCName; |
| 137 | |
| 138 | RunSendTest(call.get(), send_config, &observer); |
pbos@webrtc.org | 119a1cc | 2013-08-20 13:14:07 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | } // namespace webrtc |