From 119a1ccdcaeafd3c6141360920fb1cab4fba1dfc Mon Sep 17 00:00:00 2001 From: "pbos@webrtc.org" Date: Tue, 20 Aug 2013 13:14:07 +0000 Subject: [PATCH] VideoSendStream SSRC test. Verifies that the VideoSendStream starts sending the set SSRC over RTP. BUG=2227 R=stefan@webrtc.org Review URL: https://webrtc-codereview.appspot.com/2074004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@4573 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../test/common/null_transport.cc | 24 ++++++ .../video_engine/test/common/null_transport.h | 30 +++++++ webrtc/video_engine/test/send_stream_tests.cc | 81 +++++++++++++++++++ webrtc/video_engine/test/tests.gypi | 3 + 4 files changed, 138 insertions(+) create mode 100644 webrtc/video_engine/test/common/null_transport.cc create mode 100644 webrtc/video_engine/test/common/null_transport.h create mode 100644 webrtc/video_engine/test/send_stream_tests.cc diff --git a/webrtc/video_engine/test/common/null_transport.cc b/webrtc/video_engine/test/common/null_transport.cc new file mode 100644 index 000000000..1ce8e009a --- /dev/null +++ b/webrtc/video_engine/test/common/null_transport.cc @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ +#include "webrtc/video_engine/test/common/null_transport.h" + +namespace webrtc { +namespace test { + +bool NullTransport::SendRTP(const uint8_t* packet, size_t length) { + return true; +} + +bool NullTransport::SendRTCP(const uint8_t* packet, size_t length) { + return true; +} + +} // namespace test +} // namespace webrtc diff --git a/webrtc/video_engine/test/common/null_transport.h b/webrtc/video_engine/test/common/null_transport.h new file mode 100644 index 000000000..8af7d76cd --- /dev/null +++ b/webrtc/video_engine/test/common/null_transport.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ +#ifndef WEBRTC_VIDEO_ENGINE_TEST_COMMON_NULL_TRANSPORT_H_ +#define WEBRTC_VIDEO_ENGINE_TEST_COMMON_NULL_TRANSPORT_H_ + +#include "webrtc/video_engine/new_include/transport.h" + +namespace webrtc { + +namespace newapi { +class PacketReceiver; +} // namespace newapi + +namespace test { +class NullTransport : public newapi::Transport { + public: + virtual bool SendRTP(const uint8_t* packet, size_t length) OVERRIDE; + virtual bool SendRTCP(const uint8_t* packet, size_t length) OVERRIDE; +}; +} // namespace test +} // namespace webrtc + +#endif // WEBRTC_VIDEO_ENGINE_TEST_COMMON_NULL_TRANSPORT_H_ diff --git a/webrtc/video_engine/test/send_stream_tests.cc b/webrtc/video_engine/test/send_stream_tests.cc new file mode 100644 index 000000000..611e71f7a --- /dev/null +++ b/webrtc/video_engine/test/send_stream_tests.cc @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ +#include "testing/gtest/include/gtest/gtest.h" +#include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h" +#include "webrtc/system_wrappers/interface/event_wrapper.h" +#include "webrtc/system_wrappers/interface/scoped_ptr.h" +#include "webrtc/video_engine/test/common/frame_generator.h" +#include "webrtc/video_engine/test/common/frame_generator_capturer.h" +#include "webrtc/video_engine/test/common/null_transport.h" +#include "webrtc/video_engine/new_include/video_call.h" +#include "webrtc/video_engine/new_include/video_send_stream.h" + +namespace webrtc { + +class VideoSendStreamTest : public ::testing::Test {}; +class SendTransportObserver : public test::NullTransport { + public: + explicit SendTransportObserver(unsigned long timeout_ms) + : rtp_header_parser_(RtpHeaderParser::Create()), + send_test_complete_(EventWrapper::Create()), + timeout_ms_(timeout_ms) {} + + EventTypeWrapper Wait() { + return send_test_complete_->Wait(timeout_ms_); + } + + protected: + scoped_ptr rtp_header_parser_; + scoped_ptr send_test_complete_; + + private: + unsigned long timeout_ms_; +}; + +TEST_F(VideoSendStreamTest, SendsSetSsrc) { + static const uint32_t kSendSsrc = 0xC0FFEE; + class SendSsrcObserver : public SendTransportObserver { + public: + SendSsrcObserver() : SendTransportObserver(30 * 1000) {} + + virtual bool SendRTP(const uint8_t* packet, size_t length) OVERRIDE { + RTPHeader header; + EXPECT_TRUE( + rtp_header_parser_->Parse(packet, static_cast(length), &header)); + + if (header.ssrc == kSendSsrc) + send_test_complete_->Set(); + + return true; + } + } observer; + + newapi::VideoCall::Config call_config(&observer); + scoped_ptr call(newapi::VideoCall::Create(call_config)); + + newapi::VideoSendStream::Config send_config = call->GetDefaultSendConfig(); + send_config.rtp.ssrcs.push_back(kSendSsrc); + newapi::VideoSendStream* send_stream = call->CreateSendStream(send_config); + scoped_ptr frame_generator_capturer( + test::FrameGeneratorCapturer::Create( + send_stream->Input(), + test::FrameGenerator::Create(320, 240, Clock::GetRealTimeClock()), + 30)); + send_stream->StartSend(); + frame_generator_capturer->Start(); + + EXPECT_EQ(kEventSignaled, observer.Wait()); + + frame_generator_capturer->Stop(); + send_stream->StopSend(); + call->DestroySendStream(send_stream); +} + +} // namespace webrtc diff --git a/webrtc/video_engine/test/tests.gypi b/webrtc/video_engine/test/tests.gypi index 486f7686d..cb35d7247 100644 --- a/webrtc/video_engine/test/tests.gypi +++ b/webrtc/video_engine/test/tests.gypi @@ -32,6 +32,8 @@ 'common/mac/video_renderer_mac.h', 'common/mac/video_renderer_mac.mm', 'common/null_platform_renderer.cc', + 'common/null_transport.cc', + 'common/null_transport.h', 'common/rtp_rtcp_observer.h', 'common/run_tests.cc', 'common/run_tests.h', @@ -144,6 +146,7 @@ 'type': 'executable', 'sources': [ 'engine_tests.cc', + 'send_stream_tests.cc', 'test_main.cc', ], 'dependencies': [