blob: 611e71f7a00d3e947fd42fbada805d780e535521 [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"
12#include "webrtc/system_wrappers/interface/event_wrapper.h"
13#include "webrtc/system_wrappers/interface/scoped_ptr.h"
14#include "webrtc/video_engine/test/common/frame_generator.h"
15#include "webrtc/video_engine/test/common/frame_generator_capturer.h"
16#include "webrtc/video_engine/test/common/null_transport.h"
17#include "webrtc/video_engine/new_include/video_call.h"
18#include "webrtc/video_engine/new_include/video_send_stream.h"
19
20namespace webrtc {
21
22class VideoSendStreamTest : public ::testing::Test {};
23class 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
42TEST_F(VideoSendStreamTest, SendsSetSsrc) {
43 static const uint32_t kSendSsrc = 0xC0FFEE;
44 class SendSsrcObserver : public SendTransportObserver {
45 public:
46 SendSsrcObserver() : SendTransportObserver(30 * 1000) {}
47
48 virtual bool SendRTP(const uint8_t* packet, size_t length) OVERRIDE {
49 RTPHeader header;
50 EXPECT_TRUE(
51 rtp_header_parser_->Parse(packet, static_cast<int>(length), &header));
52
53 if (header.ssrc == kSendSsrc)
54 send_test_complete_->Set();
55
56 return true;
57 }
58 } observer;
59
60 newapi::VideoCall::Config call_config(&observer);
61 scoped_ptr<newapi::VideoCall> call(newapi::VideoCall::Create(call_config));
62
63 newapi::VideoSendStream::Config send_config = call->GetDefaultSendConfig();
64 send_config.rtp.ssrcs.push_back(kSendSsrc);
65 newapi::VideoSendStream* send_stream = call->CreateSendStream(send_config);
66 scoped_ptr<test::FrameGeneratorCapturer> frame_generator_capturer(
67 test::FrameGeneratorCapturer::Create(
68 send_stream->Input(),
69 test::FrameGenerator::Create(320, 240, Clock::GetRealTimeClock()),
70 30));
71 send_stream->StartSend();
72 frame_generator_capturer->Start();
73
74 EXPECT_EQ(kEventSignaled, observer.Wait());
75
76 frame_generator_capturer->Stop();
77 send_stream->StopSend();
78 call->DestroySendStream(send_stream);
79}
80
81} // namespace webrtc