blob: ecc208909c452bfaf97eb51faac53a46337c9315 [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
pbos@webrtc.org023b1012014-05-13 11:26:40 +000015#include "gflags/gflags.h"
mflodman@webrtc.org7f944f32013-05-27 15:52:38 +000016#include "testing/gtest/include/gtest/gtest.h"
17
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000018#include "webrtc/call.h"
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +000019#include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h"
pbos@webrtc.org26d12102013-05-29 13:41:03 +000020#include "webrtc/system_wrappers/interface/clock.h"
pbos@webrtc.org1932fe12013-07-05 17:02:37 +000021#include "webrtc/system_wrappers/interface/scoped_ptr.h"
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000022#include "webrtc/test/direct_transport.h"
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +000023#include "webrtc/test/encoder_settings.h"
24#include "webrtc/test/fake_encoder.h"
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000025#include "webrtc/test/run_loop.h"
mflodman@webrtc.orgeae79242014-06-05 09:32:51 +000026#include "webrtc/test/run_test.h"
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000027#include "webrtc/test/video_capturer.h"
28#include "webrtc/test/video_renderer.h"
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000029#include "webrtc/typedefs.h"
pbos@webrtc.org29d58392013-05-16 12:08:03 +000030
31namespace webrtc {
pbos@webrtc.org023b1012014-05-13 11:26:40 +000032namespace flags {
pbos@webrtc.org29d58392013-05-16 12:08:03 +000033
pbos@webrtc.org023b1012014-05-13 11:26:40 +000034DEFINE_int32(width, 640, "Video width.");
35size_t Width() { return static_cast<size_t>(FLAGS_width); }
36
37DEFINE_int32(height, 480, "Video height.");
38size_t Height() { return static_cast<size_t>(FLAGS_height); }
39
40DEFINE_int32(fps, 30, "Frames per second.");
41int Fps() { return static_cast<int>(FLAGS_fps); }
42
43DEFINE_int32(min_bitrate, 50, "Minimum video bitrate.");
44size_t MinBitrate() { return static_cast<size_t>(FLAGS_min_bitrate); }
45
46DEFINE_int32(start_bitrate, 300, "Video starting bitrate.");
47size_t StartBitrate() { return static_cast<size_t>(FLAGS_start_bitrate); }
48
49DEFINE_int32(max_bitrate, 800, "Maximum video bitrate.");
50size_t MaxBitrate() { return static_cast<size_t>(FLAGS_max_bitrate); }
51} // namespace flags
pbos@webrtc.org29d58392013-05-16 12:08:03 +000052
pbos@webrtc.orgb613b5a2013-12-03 10:13:04 +000053static const uint32_t kSendSsrc = 0x654321;
54static const uint32_t kReceiverLocalSsrc = 0x123456;
55
pbos@webrtc.org023b1012014-05-13 11:26:40 +000056void Loopback() {
pbos@webrtc.org1932fe12013-07-05 17:02:37 +000057 scoped_ptr<test::VideoRenderer> local_preview(test::VideoRenderer::Create(
pbos@webrtc.org023b1012014-05-13 11:26:40 +000058 "Local Preview", flags::Width(), flags::Height()));
pbos@webrtc.org1932fe12013-07-05 17:02:37 +000059 scoped_ptr<test::VideoRenderer> loopback_video(test::VideoRenderer::Create(
pbos@webrtc.org023b1012014-05-13 11:26:40 +000060 "Loopback Video", flags::Width(), flags::Height()));
pbos@webrtc.org29d58392013-05-16 12:08:03 +000061
pbos@webrtc.org96684672013-08-12 12:59:04 +000062 test::DirectTransport transport;
pbos@webrtc.org841c8a42013-09-09 15:04:25 +000063 Call::Config call_config(&transport);
pbos@webrtc.org841c8a42013-09-09 15:04:25 +000064 scoped_ptr<Call> call(Call::Create(call_config));
pbos@webrtc.org29d58392013-05-16 12:08:03 +000065
66 // Loopback, call sends to itself.
67 transport.SetReceiver(call->Receiver());
68
pbos@webrtc.org74fa4892013-08-23 09:19:30 +000069 VideoSendStream::Config send_config = call->GetDefaultSendConfig();
pbos@webrtc.orgb613b5a2013-12-03 10:13:04 +000070 send_config.rtp.ssrcs.push_back(kSendSsrc);
pbos@webrtc.org29d58392013-05-16 12:08:03 +000071
pbos@webrtc.org1932fe12013-07-05 17:02:37 +000072 send_config.local_renderer = local_preview.get();
pbos@webrtc.org29d58392013-05-16 12:08:03 +000073
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +000074 scoped_ptr<VP8Encoder> encoder(VP8Encoder::Create());
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +000075 send_config.encoder_settings.encoder = encoder.get();
76 send_config.encoder_settings.payload_name = "VP8";
77 send_config.encoder_settings.payload_type = 124;
78 std::vector<VideoStream> video_streams = test::CreateVideoStreams(1);
79 VideoStream* stream = &video_streams[0];
pbos@webrtc.org023b1012014-05-13 11:26:40 +000080 stream->width = flags::Width();
81 stream->height = flags::Height();
82 stream->min_bitrate_bps = static_cast<int>(flags::MinBitrate()) * 1000;
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +000083 stream->target_bitrate_bps = static_cast<int>(flags::MaxBitrate()) * 1000;
pbos@webrtc.org023b1012014-05-13 11:26:40 +000084 stream->max_bitrate_bps = static_cast<int>(flags::MaxBitrate()) * 1000;
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +000085 stream->max_framerate = 30;
86 stream->max_qp = 56;
pbos@webrtc.org29d58392013-05-16 12:08:03 +000087
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +000088 VideoSendStream* send_stream =
89 call->CreateVideoSendStream(send_config, video_streams, NULL);
pbos@webrtc.org29d58392013-05-16 12:08:03 +000090
pbos@webrtc.org26d12102013-05-29 13:41:03 +000091 Clock* test_clock = Clock::GetRealTimeClock();
92
pbos@webrtc.org1932fe12013-07-05 17:02:37 +000093 scoped_ptr<test::VideoCapturer> camera(
pbos@webrtc.org771cdcb2013-05-23 12:20:16 +000094 test::VideoCapturer::Create(send_stream->Input(),
pbos@webrtc.org023b1012014-05-13 11:26:40 +000095 flags::Width(),
96 flags::Height(),
97 flags::Fps(),
pbos@webrtc.org1932fe12013-07-05 17:02:37 +000098 test_clock));
pbos@webrtc.org29d58392013-05-16 12:08:03 +000099
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000100 VideoReceiveStream::Config receive_config = call->GetDefaultReceiveConfig();
pbos@webrtc.orgb613b5a2013-12-03 10:13:04 +0000101 receive_config.rtp.remote_ssrc = send_config.rtp.ssrcs[0];
102 receive_config.rtp.local_ssrc = kReceiverLocalSsrc;
pbos@webrtc.org1932fe12013-07-05 17:02:37 +0000103 receive_config.renderer = loopback_video.get();
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +0000104 VideoCodec codec =
105 test::CreateDecoderVideoCodec(send_config.encoder_settings);
106 receive_config.codecs.push_back(codec);
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000107
pbos@webrtc.org74fa4892013-08-23 09:19:30 +0000108 VideoReceiveStream* receive_stream =
pbos@webrtc.org5a636552013-11-20 10:40:25 +0000109 call->CreateVideoReceiveStream(receive_config);
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000110
pbos@webrtc.orga5c8d2c2014-04-24 11:13:21 +0000111 receive_stream->Start();
112 send_stream->Start();
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000113 camera->Start();
114
pbos@webrtc.orgadf23a52013-07-10 14:07:56 +0000115 test::PressEnterToContinue();
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000116
pbos@webrtc.org1932fe12013-07-05 17:02:37 +0000117 camera->Stop();
pbos@webrtc.orga5c8d2c2014-04-24 11:13:21 +0000118 send_stream->Stop();
119 receive_stream->Stop();
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000120
pbos@webrtc.org2c46f8d2013-11-21 13:49:43 +0000121 call->DestroyVideoReceiveStream(receive_stream);
122 call->DestroyVideoSendStream(send_stream);
pbos@webrtc.org96684672013-08-12 12:59:04 +0000123
124 transport.StopSending();
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000125}
pbos@webrtc.orgc49d5b72013-12-05 12:11:47 +0000126} // namespace webrtc
pbos@webrtc.org023b1012014-05-13 11:26:40 +0000127
128int main(int argc, char* argv[]) {
129 ::testing::InitGoogleTest(&argc, argv);
130 google::ParseCommandLineFlags(&argc, &argv, true);
131
mflodman@webrtc.orgeae79242014-06-05 09:32:51 +0000132 webrtc::test::RunTest(webrtc::Loopback);
pbos@webrtc.org023b1012014-05-13 11:26:40 +0000133 return 0;
134}