blob: 93f2d839b36732c25e0bf11113f4fb0cd14ee794 [file] [log] [blame]
pbos@webrtc.org29d58392013-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.org12dc1a32013-08-05 16:22:53 +000011#include <stdio.h>
12
pbos@webrtc.org29d58392013-05-16 12:08:03 +000013#include <map>
14
mflodman@webrtc.org7f944f32013-05-27 15:52:38 +000015#include "testing/gtest/include/gtest/gtest.h"
16
pbos@webrtc.org26d12102013-05-29 13:41:03 +000017#include "webrtc/system_wrappers/interface/clock.h"
pbos@webrtc.org1932fe12013-07-05 17:02:37 +000018#include "webrtc/system_wrappers/interface/scoped_ptr.h"
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000019#include "webrtc/typedefs.h"
pbos@webrtc.org841c8a42013-09-09 15:04:25 +000020#include "webrtc/video_engine/new_include/call.h"
pbos@webrtc.org29d58392013-05-16 12:08:03 +000021#include "webrtc/video_engine/test/common/direct_transport.h"
pbos@webrtc.org771cdcb2013-05-23 12:20:16 +000022#include "webrtc/video_engine/test/common/flags.h"
pbos@webrtc.org29d58392013-05-16 12:08:03 +000023#include "webrtc/video_engine/test/common/generate_ssrcs.h"
pbos@webrtc.orgadf23a52013-07-10 14:07:56 +000024#include "webrtc/video_engine/test/common/run_loop.h"
25#include "webrtc/video_engine/test/common/run_tests.h"
pbos@webrtc.org29d58392013-05-16 12:08:03 +000026#include "webrtc/video_engine/test/common/video_capturer.h"
27#include "webrtc/video_engine/test/common/video_renderer.h"
pbos@webrtc.org29d58392013-05-16 12:08:03 +000028
29namespace webrtc {
30
31class LoopbackTest : public ::testing::Test {
32 protected:
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000033 std::map<uint32_t, bool> reserved_ssrcs_;
pbos@webrtc.org29d58392013-05-16 12:08:03 +000034};
35
36TEST_F(LoopbackTest, Test) {
pbos@webrtc.org1932fe12013-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.org29d58392013-05-16 12:08:03 +000041
pbos@webrtc.org96684672013-08-12 12:59:04 +000042 test::DirectTransport transport;
pbos@webrtc.org841c8a42013-09-09 15:04:25 +000043 Call::Config call_config(&transport);
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000044 call_config.overuse_detection = true;
pbos@webrtc.org841c8a42013-09-09 15:04:25 +000045 scoped_ptr<Call> call(Call::Create(call_config));
pbos@webrtc.org29d58392013-05-16 12:08:03 +000046
47 // Loopback, call sends to itself.
48 transport.SetReceiver(call->Receiver());
49
pbos@webrtc.org74fa4892013-08-23 09:19:30 +000050 VideoSendStream::Config send_config = call->GetDefaultSendConfig();
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000051 test::GenerateRandomSsrcs(&send_config, &reserved_ssrcs_);
pbos@webrtc.org29d58392013-05-16 12:08:03 +000052
pbos@webrtc.org1932fe12013-07-05 17:02:37 +000053 send_config.local_renderer = local_preview.get();
pbos@webrtc.org29d58392013-05-16 12:08:03 +000054
pbos@webrtc.org771cdcb2013-05-23 12:20:16 +000055 // TODO(pbos): static_cast shouldn't be required after mflodman refactors the
56 // VideoCodec struct.
mflodman@webrtc.org7f944f32013-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.org771cdcb2013-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.org29d58392013-05-16 12:08:03 +000065
pbos@webrtc.org74fa4892013-08-23 09:19:30 +000066 VideoSendStream* send_stream = call->CreateSendStream(send_config);
pbos@webrtc.org29d58392013-05-16 12:08:03 +000067
pbos@webrtc.org26d12102013-05-29 13:41:03 +000068 Clock* test_clock = Clock::GetRealTimeClock();
69
pbos@webrtc.org1932fe12013-07-05 17:02:37 +000070 scoped_ptr<test::VideoCapturer> camera(
pbos@webrtc.org771cdcb2013-05-23 12:20:16 +000071 test::VideoCapturer::Create(send_stream->Input(),
72 test::flags::Width(),
73 test::flags::Height(),
pbos@webrtc.org26d12102013-05-29 13:41:03 +000074 test::flags::Fps(),
pbos@webrtc.org1932fe12013-07-05 17:02:37 +000075 test_clock));
pbos@webrtc.org29d58392013-05-16 12:08:03 +000076
pbos@webrtc.org841c8a42013-09-09 15:04:25 +000077 VideoReceiveStream::Config receive_config = call->GetDefaultReceiveConfig();
pbos@webrtc.org29d58392013-05-16 12:08:03 +000078 receive_config.rtp.ssrc = send_config.rtp.ssrcs[0];
pbos@webrtc.org1932fe12013-07-05 17:02:37 +000079 receive_config.renderer = loopback_video.get();
pbos@webrtc.org29d58392013-05-16 12:08:03 +000080
pbos@webrtc.org74fa4892013-08-23 09:19:30 +000081 VideoReceiveStream* receive_stream =
pbos@webrtc.org29d58392013-05-16 12:08:03 +000082 call->CreateReceiveStream(receive_config);
83
84 receive_stream->StartReceive();
85 send_stream->StartSend();
pbos@webrtc.org29d58392013-05-16 12:08:03 +000086 camera->Start();
87
pbos@webrtc.orgadf23a52013-07-10 14:07:56 +000088 test::PressEnterToContinue();
pbos@webrtc.org29d58392013-05-16 12:08:03 +000089
pbos@webrtc.org1932fe12013-07-05 17:02:37 +000090 camera->Stop();
pbos@webrtc.org29d58392013-05-16 12:08:03 +000091 send_stream->StopSend();
pbos@webrtc.org1932fe12013-07-05 17:02:37 +000092 receive_stream->StopReceive();
pbos@webrtc.org29d58392013-05-16 12:08:03 +000093
94 call->DestroyReceiveStream(receive_stream);
95 call->DestroySendStream(send_stream);
pbos@webrtc.org96684672013-08-12 12:59:04 +000096
97 transport.StopSending();
pbos@webrtc.org29d58392013-05-16 12:08:03 +000098}
99} // webrtc