2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
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.
15 #include "testing/gtest/include/gtest/gtest.h"
17 #include "webrtc/call.h"
18 #include "webrtc/system_wrappers/interface/clock.h"
19 #include "webrtc/system_wrappers/interface/scoped_ptr.h"
20 #include "webrtc/test/direct_transport.h"
21 #include "webrtc/test/flags.h"
22 #include "webrtc/test/run_loop.h"
23 #include "webrtc/test/run_tests.h"
24 #include "webrtc/test/video_capturer.h"
25 #include "webrtc/test/video_renderer.h"
26 #include "webrtc/typedefs.h"
30 class LoopbackTest : public ::testing::Test {
32 std::map<uint32_t, bool> reserved_ssrcs_;
35 static const uint32_t kSendSsrc = 0x654321;
36 static const uint32_t kReceiverLocalSsrc = 0x123456;
38 TEST_F(LoopbackTest, Test) {
39 scoped_ptr<test::VideoRenderer> local_preview(test::VideoRenderer::Create(
40 "Local Preview", test::flags::Width(), test::flags::Height()));
41 scoped_ptr<test::VideoRenderer> loopback_video(test::VideoRenderer::Create(
42 "Loopback Video", test::flags::Width(), test::flags::Height()));
44 test::DirectTransport transport;
45 Call::Config call_config(&transport);
46 scoped_ptr<Call> call(Call::Create(call_config));
48 // Loopback, call sends to itself.
49 transport.SetReceiver(call->Receiver());
51 VideoSendStream::Config send_config = call->GetDefaultSendConfig();
52 send_config.rtp.ssrcs.push_back(kSendSsrc);
54 send_config.local_renderer = local_preview.get();
56 // TODO(pbos): static_cast shouldn't be required after mflodman refactors the
58 send_config.codec.width = static_cast<uint16_t>(test::flags::Width());
59 send_config.codec.height = static_cast<uint16_t>(test::flags::Height());
60 send_config.codec.minBitrate =
61 static_cast<unsigned int>(test::flags::MinBitrate());
62 send_config.codec.startBitrate =
63 static_cast<unsigned int>(test::flags::StartBitrate());
64 send_config.codec.maxBitrate =
65 static_cast<unsigned int>(test::flags::MaxBitrate());
67 VideoSendStream* send_stream = call->CreateVideoSendStream(send_config);
69 Clock* test_clock = Clock::GetRealTimeClock();
71 scoped_ptr<test::VideoCapturer> camera(
72 test::VideoCapturer::Create(send_stream->Input(),
74 test::flags::Height(),
78 VideoReceiveStream::Config receive_config = call->GetDefaultReceiveConfig();
79 receive_config.rtp.remote_ssrc = send_config.rtp.ssrcs[0];
80 receive_config.rtp.local_ssrc = kReceiverLocalSsrc;
81 receive_config.renderer = loopback_video.get();
83 VideoReceiveStream* receive_stream =
84 call->CreateVideoReceiveStream(receive_config);
86 receive_stream->StartReceiving();
87 send_stream->StartSending();
90 test::PressEnterToContinue();
93 send_stream->StopSending();
94 receive_stream->StopReceiving();
96 call->DestroyVideoReceiveStream(receive_stream);
97 call->DestroyVideoSendStream(send_stream);
99 transport.StopSending();
101 } // namespace webrtc