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" |
| 15 | #include "webrtc/video_engine/test/common/frame_generator.h" |
| 16 | #include "webrtc/video_engine/test/common/frame_generator_capturer.h" |
| 17 | #include "webrtc/video_engine/test/common/null_transport.h" |
| 18 | #include "webrtc/video_engine/new_include/video_call.h" |
| 19 | #include "webrtc/video_engine/new_include/video_send_stream.h" |
| 20 | |
| 21 | namespace webrtc { |
| 22 | |
pbos@webrtc.org | 119a1cc | 2013-08-20 13:14:07 +0000 | [diff] [blame] | 23 | class SendTransportObserver : public test::NullTransport { |
| 24 | public: |
| 25 | explicit SendTransportObserver(unsigned long timeout_ms) |
| 26 | : rtp_header_parser_(RtpHeaderParser::Create()), |
| 27 | send_test_complete_(EventWrapper::Create()), |
| 28 | timeout_ms_(timeout_ms) {} |
| 29 | |
| 30 | EventTypeWrapper Wait() { |
| 31 | return send_test_complete_->Wait(timeout_ms_); |
| 32 | } |
| 33 | |
| 34 | protected: |
| 35 | scoped_ptr<RtpHeaderParser> rtp_header_parser_; |
| 36 | scoped_ptr<EventWrapper> send_test_complete_; |
| 37 | |
| 38 | private: |
| 39 | unsigned long timeout_ms_; |
| 40 | }; |
| 41 | |
pbos@webrtc.org | 013d994 | 2013-08-22 09:42:17 +0000 | [diff] [blame^] | 42 | class VideoSendStreamTest : public ::testing::Test { |
| 43 | protected: |
| 44 | static const uint32_t kSendSsrc; |
| 45 | void RunSendTest(newapi::VideoCall* call, |
| 46 | const newapi::VideoSendStream::Config& config, |
| 47 | SendTransportObserver* observer) { |
| 48 | newapi::VideoSendStream* send_stream = call->CreateSendStream(config); |
| 49 | scoped_ptr<test::FrameGeneratorCapturer> frame_generator_capturer( |
| 50 | test::FrameGeneratorCapturer::Create( |
| 51 | send_stream->Input(), |
| 52 | test::FrameGenerator::Create(320, 240, Clock::GetRealTimeClock()), |
| 53 | 30)); |
| 54 | send_stream->StartSend(); |
| 55 | frame_generator_capturer->Start(); |
| 56 | |
| 57 | EXPECT_EQ(kEventSignaled, observer->Wait()); |
| 58 | |
| 59 | frame_generator_capturer->Stop(); |
| 60 | send_stream->StopSend(); |
| 61 | call->DestroySendStream(send_stream); |
| 62 | } |
| 63 | }; |
| 64 | |
| 65 | const uint32_t VideoSendStreamTest::kSendSsrc = 0xC0FFEE; |
| 66 | |
pbos@webrtc.org | 119a1cc | 2013-08-20 13:14:07 +0000 | [diff] [blame] | 67 | TEST_F(VideoSendStreamTest, SendsSetSsrc) { |
pbos@webrtc.org | 119a1cc | 2013-08-20 13:14:07 +0000 | [diff] [blame] | 68 | class SendSsrcObserver : public SendTransportObserver { |
| 69 | public: |
| 70 | SendSsrcObserver() : SendTransportObserver(30 * 1000) {} |
| 71 | |
| 72 | virtual bool SendRTP(const uint8_t* packet, size_t length) OVERRIDE { |
| 73 | RTPHeader header; |
| 74 | EXPECT_TRUE( |
| 75 | rtp_header_parser_->Parse(packet, static_cast<int>(length), &header)); |
| 76 | |
| 77 | if (header.ssrc == kSendSsrc) |
| 78 | send_test_complete_->Set(); |
| 79 | |
| 80 | return true; |
| 81 | } |
| 82 | } observer; |
| 83 | |
| 84 | newapi::VideoCall::Config call_config(&observer); |
| 85 | scoped_ptr<newapi::VideoCall> call(newapi::VideoCall::Create(call_config)); |
| 86 | |
| 87 | newapi::VideoSendStream::Config send_config = call->GetDefaultSendConfig(); |
| 88 | send_config.rtp.ssrcs.push_back(kSendSsrc); |
pbos@webrtc.org | 119a1cc | 2013-08-20 13:14:07 +0000 | [diff] [blame] | 89 | |
pbos@webrtc.org | 013d994 | 2013-08-22 09:42:17 +0000 | [diff] [blame^] | 90 | RunSendTest(call.get(), send_config, &observer); |
| 91 | } |
pbos@webrtc.org | 119a1cc | 2013-08-20 13:14:07 +0000 | [diff] [blame] | 92 | |
pbos@webrtc.org | 013d994 | 2013-08-22 09:42:17 +0000 | [diff] [blame^] | 93 | TEST_F(VideoSendStreamTest, SupportsCName) { |
| 94 | static std::string kCName = "PjQatC14dGfbVwGPUOA9IH7RlsFDbWl4AhXEiDsBizo="; |
| 95 | class CNameObserver : public SendTransportObserver { |
| 96 | public: |
| 97 | CNameObserver() : SendTransportObserver(30 * 1000) {} |
| 98 | |
| 99 | virtual bool SendRTCP(const uint8_t* packet, size_t length) OVERRIDE { |
| 100 | RTCPUtility::RTCPParserV2 parser(packet, length, true); |
| 101 | EXPECT_TRUE(parser.IsValid()); |
| 102 | |
| 103 | RTCPUtility::RTCPPacketTypes packet_type = parser.Begin(); |
| 104 | while (packet_type != RTCPUtility::kRtcpNotValidCode) { |
| 105 | if (packet_type == RTCPUtility::kRtcpSdesChunkCode) { |
| 106 | EXPECT_EQ(parser.Packet().CName.CName, kCName); |
| 107 | send_test_complete_->Set(); |
| 108 | } |
| 109 | |
| 110 | packet_type = parser.Iterate(); |
| 111 | } |
| 112 | |
| 113 | return true; |
| 114 | } |
| 115 | } observer; |
| 116 | |
| 117 | newapi::VideoCall::Config call_config(&observer); |
| 118 | scoped_ptr<newapi::VideoCall> call(newapi::VideoCall::Create(call_config)); |
| 119 | |
| 120 | newapi::VideoSendStream::Config send_config = call->GetDefaultSendConfig(); |
| 121 | send_config.rtp.ssrcs.push_back(kSendSsrc); |
| 122 | send_config.rtp.c_name = kCName; |
| 123 | |
| 124 | RunSendTest(call.get(), send_config, &observer); |
pbos@webrtc.org | 119a1cc | 2013-08-20 13:14:07 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | } // namespace webrtc |