blob: e07138a9a26bd4e431457af554148c3aced091c7 [file] [log] [blame]
pbos@webrtc.org2a9108f2013-05-16 12:08:03 +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
pbos@webrtc.org3f45c2e2013-08-05 16:22:53 +000011#include <stdio.h>
12
pbos@webrtc.org2a9108f2013-05-16 12:08:03 +000013#include <map>
14
mflodman@webrtc.orga93cbbf2013-05-27 15:52:38 +000015#include "testing/gtest/include/gtest/gtest.h"
16
pbos@webrtc.org24e20892013-10-28 16:32:01 +000017#include "webrtc/call.h"
pbos@webrtc.orgc1506a22013-05-29 13:41:03 +000018#include "webrtc/system_wrappers/interface/clock.h"
pbos@webrtc.orgb16cb052013-07-05 17:02:37 +000019#include "webrtc/system_wrappers/interface/scoped_ptr.h"
pbos@webrtc.org24e20892013-10-28 16:32:01 +000020#include "webrtc/test/direct_transport.h"
21#include "webrtc/test/flags.h"
22#include "webrtc/test/generate_ssrcs.h"
23#include "webrtc/test/run_loop.h"
24#include "webrtc/test/run_tests.h"
25#include "webrtc/test/video_capturer.h"
26#include "webrtc/test/video_renderer.h"
pbos@webrtc.org281cff82013-05-17 13:44:48 +000027#include "webrtc/typedefs.h"
pbos@webrtc.org2a9108f2013-05-16 12:08:03 +000028
29namespace webrtc {
30
31class LoopbackTest : public ::testing::Test {
32 protected:
pbos@webrtc.org2f02da82013-07-09 08:02:33 +000033 std::map<uint32_t, bool> reserved_ssrcs_;
pbos@webrtc.org2a9108f2013-05-16 12:08:03 +000034};
35
36TEST_F(LoopbackTest, Test) {
pbos@webrtc.orgb16cb052013-07-05 17:02:37 +000037 scoped_ptr<test::VideoRenderer> local_preview(test::VideoRenderer::Create(
38 "Local Preview", test::flags::Width(), test::flags::Height()));
39 scoped_ptr<test::VideoRenderer> loopback_video(test::VideoRenderer::Create(
40 "Loopback Video", test::flags::Width(), test::flags::Height()));
pbos@webrtc.org2a9108f2013-05-16 12:08:03 +000041
pbos@webrtc.orgfe881f62013-08-12 12:59:04 +000042 test::DirectTransport transport;
pbos@webrtc.orgbf6d5722013-09-09 15:04:25 +000043 Call::Config call_config(&transport);
mflodman@webrtc.orgbf76ae22013-07-23 11:35:00 +000044 call_config.overuse_detection = true;
pbos@webrtc.orgbf6d5722013-09-09 15:04:25 +000045 scoped_ptr<Call> call(Call::Create(call_config));
pbos@webrtc.org2a9108f2013-05-16 12:08:03 +000046
47 // Loopback, call sends to itself.
48 transport.SetReceiver(call->Receiver());
49
pbos@webrtc.orgc1797062013-08-23 09:19:30 +000050 VideoSendStream::Config send_config = call->GetDefaultSendConfig();
pbos@webrtc.org2f02da82013-07-09 08:02:33 +000051 test::GenerateRandomSsrcs(&send_config, &reserved_ssrcs_);
pbos@webrtc.org2a9108f2013-05-16 12:08:03 +000052
pbos@webrtc.orgb16cb052013-07-05 17:02:37 +000053 send_config.local_renderer = local_preview.get();
pbos@webrtc.org2a9108f2013-05-16 12:08:03 +000054
pbos@webrtc.org074eb202013-05-23 12:20:16 +000055 // TODO(pbos): static_cast shouldn't be required after mflodman refactors the
56 // VideoCodec struct.
mflodman@webrtc.orga93cbbf2013-05-27 15:52:38 +000057 send_config.codec.width = static_cast<uint16_t>(test::flags::Width());
58 send_config.codec.height = static_cast<uint16_t>(test::flags::Height());
pbos@webrtc.org074eb202013-05-23 12:20:16 +000059 send_config.codec.minBitrate =
60 static_cast<unsigned int>(test::flags::MinBitrate());
61 send_config.codec.startBitrate =
62 static_cast<unsigned int>(test::flags::StartBitrate());
63 send_config.codec.maxBitrate =
64 static_cast<unsigned int>(test::flags::MaxBitrate());
pbos@webrtc.org2a9108f2013-05-16 12:08:03 +000065
pbos@webrtc.org964d78e2013-11-20 10:40:25 +000066 VideoSendStream* send_stream = call->CreateVideoSendStream(send_config);
pbos@webrtc.org2a9108f2013-05-16 12:08:03 +000067
pbos@webrtc.orgc1506a22013-05-29 13:41:03 +000068 Clock* test_clock = Clock::GetRealTimeClock();
69
pbos@webrtc.orgb16cb052013-07-05 17:02:37 +000070 scoped_ptr<test::VideoCapturer> camera(
pbos@webrtc.org074eb202013-05-23 12:20:16 +000071 test::VideoCapturer::Create(send_stream->Input(),
72 test::flags::Width(),
73 test::flags::Height(),
pbos@webrtc.orgc1506a22013-05-29 13:41:03 +000074 test::flags::Fps(),
pbos@webrtc.orgb16cb052013-07-05 17:02:37 +000075 test_clock));
pbos@webrtc.org2a9108f2013-05-16 12:08:03 +000076
pbos@webrtc.orgbf6d5722013-09-09 15:04:25 +000077 VideoReceiveStream::Config receive_config = call->GetDefaultReceiveConfig();
pbos@webrtc.org2a9108f2013-05-16 12:08:03 +000078 receive_config.rtp.ssrc = send_config.rtp.ssrcs[0];
pbos@webrtc.orgb16cb052013-07-05 17:02:37 +000079 receive_config.renderer = loopback_video.get();
pbos@webrtc.org2a9108f2013-05-16 12:08:03 +000080
pbos@webrtc.orgc1797062013-08-23 09:19:30 +000081 VideoReceiveStream* receive_stream =
pbos@webrtc.org964d78e2013-11-20 10:40:25 +000082 call->CreateVideoReceiveStream(receive_config);
pbos@webrtc.org2a9108f2013-05-16 12:08:03 +000083
pbos@webrtc.org7f9f8402013-11-20 11:36:47 +000084 receive_stream->StartReceiving();
85 send_stream->StartSending();
pbos@webrtc.org2a9108f2013-05-16 12:08:03 +000086 camera->Start();
87
pbos@webrtc.org778a1722013-07-10 14:07:56 +000088 test::PressEnterToContinue();
pbos@webrtc.org2a9108f2013-05-16 12:08:03 +000089
pbos@webrtc.orgb16cb052013-07-05 17:02:37 +000090 camera->Stop();
pbos@webrtc.org7f9f8402013-11-20 11:36:47 +000091 send_stream->StopSending();
92 receive_stream->StopReceiving();
pbos@webrtc.org2a9108f2013-05-16 12:08:03 +000093
pbos@webrtc.org12a93e02013-11-21 13:49:43 +000094 call->DestroyVideoReceiveStream(receive_stream);
95 call->DestroyVideoSendStream(send_stream);
pbos@webrtc.orgfe881f62013-08-12 12:59:04 +000096
97 transport.StopSending();
pbos@webrtc.org2a9108f2013-05-16 12:08:03 +000098}
99} // webrtc