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" |
pbos@webrtc.org | 841c8a4 | 2013-09-09 15:04:25 +0000 | [diff] [blame^] | 19 | #include "webrtc/video_engine/new_include/call.h" |
pbos@webrtc.org | 119a1cc | 2013-08-20 13:14:07 +0000 | [diff] [blame] | 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 | |
pbos@webrtc.org | 841c8a4 | 2013-09-09 15:04:25 +0000 | [diff] [blame^] | 31 | EventTypeWrapper Wait() { return send_test_complete_->Wait(timeout_ms_); } |
pbos@webrtc.org | 119a1cc | 2013-08-20 13:14:07 +0000 | [diff] [blame] | 32 | |
| 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.org | 013d994 | 2013-08-22 09:42:17 +0000 | [diff] [blame] | 41 | class VideoSendStreamTest : public ::testing::Test { |
pbos@webrtc.org | cb5118c | 2013-09-03 09:10:37 +0000 | [diff] [blame] | 42 | public: |
| 43 | VideoSendStreamTest() : fake_encoder_(Clock::GetRealTimeClock()) {} |
pbos@webrtc.org | 841c8a4 | 2013-09-09 15:04:25 +0000 | [diff] [blame^] | 44 | |
pbos@webrtc.org | 013d994 | 2013-08-22 09:42:17 +0000 | [diff] [blame] | 45 | protected: |
| 46 | static const uint32_t kSendSsrc; |
pbos@webrtc.org | 841c8a4 | 2013-09-09 15:04:25 +0000 | [diff] [blame^] | 47 | void RunSendTest(Call* call, |
pbos@webrtc.org | 74fa489 | 2013-08-23 09:19:30 +0000 | [diff] [blame] | 48 | const VideoSendStream::Config& config, |
pbos@webrtc.org | 013d994 | 2013-08-22 09:42:17 +0000 | [diff] [blame] | 49 | SendTransportObserver* observer) { |
pbos@webrtc.org | 74fa489 | 2013-08-23 09:19:30 +0000 | [diff] [blame] | 50 | VideoSendStream* send_stream = call->CreateSendStream(config); |
pbos@webrtc.org | 013d994 | 2013-08-22 09:42:17 +0000 | [diff] [blame] | 51 | 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.org | cb5118c | 2013-09-03 09:10:37 +0000 | [diff] [blame] | 65 | |
pbos@webrtc.org | 841c8a4 | 2013-09-09 15:04:25 +0000 | [diff] [blame^] | 66 | VideoSendStream::Config GetSendTestConfig(Call* call) { |
pbos@webrtc.org | cb5118c | 2013-09-03 09:10:37 +0000 | [diff] [blame] | 67 | VideoSendStream::Config config = call->GetDefaultSendConfig(); |
| 68 | config.encoder = &fake_encoder_; |
| 69 | config.internal_source = false; |
pbos@webrtc.org | 0181b5f | 2013-09-09 08:26:30 +0000 | [diff] [blame] | 70 | test::FakeEncoder::SetCodecSettings(&config.codec, 1); |
pbos@webrtc.org | cb5118c | 2013-09-03 09:10:37 +0000 | [diff] [blame] | 71 | return config; |
| 72 | } |
| 73 | |
| 74 | test::FakeEncoder fake_encoder_; |
pbos@webrtc.org | 013d994 | 2013-08-22 09:42:17 +0000 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | const uint32_t VideoSendStreamTest::kSendSsrc = 0xC0FFEE; |
| 78 | |
pbos@webrtc.org | 119a1cc | 2013-08-20 13:14:07 +0000 | [diff] [blame] | 79 | TEST_F(VideoSendStreamTest, SendsSetSsrc) { |
pbos@webrtc.org | 119a1cc | 2013-08-20 13:14:07 +0000 | [diff] [blame] | 80 | 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.org | 841c8a4 | 2013-09-09 15:04:25 +0000 | [diff] [blame^] | 96 | Call::Config call_config(&observer); |
| 97 | scoped_ptr<Call> call(Call::Create(call_config)); |
pbos@webrtc.org | 119a1cc | 2013-08-20 13:14:07 +0000 | [diff] [blame] | 98 | |
pbos@webrtc.org | cb5118c | 2013-09-03 09:10:37 +0000 | [diff] [blame] | 99 | VideoSendStream::Config send_config = GetSendTestConfig(call.get()); |
pbos@webrtc.org | 119a1cc | 2013-08-20 13:14:07 +0000 | [diff] [blame] | 100 | send_config.rtp.ssrcs.push_back(kSendSsrc); |
pbos@webrtc.org | 119a1cc | 2013-08-20 13:14:07 +0000 | [diff] [blame] | 101 | |
pbos@webrtc.org | 013d994 | 2013-08-22 09:42:17 +0000 | [diff] [blame] | 102 | RunSendTest(call.get(), send_config, &observer); |
| 103 | } |
pbos@webrtc.org | 119a1cc | 2013-08-20 13:14:07 +0000 | [diff] [blame] | 104 | |
pbos@webrtc.org | 013d994 | 2013-08-22 09:42:17 +0000 | [diff] [blame] | 105 | TEST_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.org | 841c8a4 | 2013-09-09 15:04:25 +0000 | [diff] [blame^] | 129 | Call::Config call_config(&observer); |
| 130 | scoped_ptr<Call> call(Call::Create(call_config)); |
pbos@webrtc.org | 013d994 | 2013-08-22 09:42:17 +0000 | [diff] [blame] | 131 | |
pbos@webrtc.org | cb5118c | 2013-09-03 09:10:37 +0000 | [diff] [blame] | 132 | VideoSendStream::Config send_config = GetSendTestConfig(call.get()); |
pbos@webrtc.org | 013d994 | 2013-08-22 09:42:17 +0000 | [diff] [blame] | 133 | send_config.rtp.ssrcs.push_back(kSendSsrc); |
| 134 | send_config.rtp.c_name = kCName; |
| 135 | |
| 136 | RunSendTest(call.get(), send_config, &observer); |
pbos@webrtc.org | 119a1cc | 2013-08-20 13:14:07 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | } // namespace webrtc |