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 "gflags/gflags.h"
16 #include "testing/gtest/include/gtest/gtest.h"
18 #include "webrtc/call.h"
19 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h"
20 #include "webrtc/system_wrappers/interface/clock.h"
21 #include "webrtc/system_wrappers/interface/scoped_ptr.h"
22 #include "webrtc/test/direct_transport.h"
23 #include "webrtc/test/encoder_settings.h"
24 #include "webrtc/test/fake_encoder.h"
25 #include "webrtc/test/run_loop.h"
26 #include "webrtc/test/run_test.h"
27 #include "webrtc/test/video_capturer.h"
28 #include "webrtc/test/video_renderer.h"
29 #include "webrtc/typedefs.h"
34 DEFINE_int32(width, 640, "Video width.");
35 size_t Width() { return static_cast<size_t>(FLAGS_width); }
37 DEFINE_int32(height, 480, "Video height.");
38 size_t Height() { return static_cast<size_t>(FLAGS_height); }
40 DEFINE_int32(fps, 30, "Frames per second.");
41 int Fps() { return static_cast<int>(FLAGS_fps); }
43 DEFINE_int32(min_bitrate, 50, "Minimum video bitrate.");
44 size_t MinBitrate() { return static_cast<size_t>(FLAGS_min_bitrate); }
46 DEFINE_int32(start_bitrate, 300, "Video starting bitrate.");
47 size_t StartBitrate() { return static_cast<size_t>(FLAGS_start_bitrate); }
49 DEFINE_int32(max_bitrate, 800, "Maximum video bitrate.");
50 size_t MaxBitrate() { return static_cast<size_t>(FLAGS_max_bitrate); }
52 DEFINE_string(codec, "VP8", "Video codec to use.");
53 std::string Codec() { return static_cast<std::string>(FLAGS_codec); }
55 DEFINE_int32(loss_percent, 0, "Percentage of packets randomly lost.");
57 return static_cast<int>(FLAGS_loss_percent);
60 DEFINE_int32(link_capacity,
62 "Capacity (kbps) of the fake link. 0 means infinite.");
64 return static_cast<int>(FLAGS_link_capacity);
67 DEFINE_int32(queue_size, 0, "Size of the bottleneck link queue in packets.");
69 return static_cast<int>(FLAGS_queue_size);
72 DEFINE_int32(avg_propagation_delay_ms,
74 "Average link propagation delay in ms.");
75 int AvgPropagationDelayMs() {
76 return static_cast<int>(FLAGS_avg_propagation_delay_ms);
79 DEFINE_int32(std_propagation_delay_ms,
81 "Link propagation delay standard deviation in ms.");
82 int StdPropagationDelayMs() {
83 return static_cast<int>(FLAGS_std_propagation_delay_ms);
87 static const uint32_t kSendSsrc = 0x654321;
88 static const uint32_t kSendRtxSsrc = 0x654322;
89 static const uint32_t kReceiverLocalSsrc = 0x123456;
91 static const uint8_t kRtxPayloadType = 96;
94 scoped_ptr<test::VideoRenderer> local_preview(test::VideoRenderer::Create(
95 "Local Preview", flags::Width(), flags::Height()));
96 scoped_ptr<test::VideoRenderer> loopback_video(test::VideoRenderer::Create(
97 "Loopback Video", flags::Width(), flags::Height()));
99 FakeNetworkPipe::Config pipe_config;
100 pipe_config.loss_percent = flags::LossPercent();
101 pipe_config.link_capacity_kbps = flags::LinkCapacity();
102 pipe_config.queue_length_packets = flags::QueueSize();
103 pipe_config.queue_delay_ms = flags::AvgPropagationDelayMs();
104 pipe_config.delay_standard_deviation_ms = flags::StdPropagationDelayMs();
105 test::DirectTransport transport(pipe_config);
106 Call::Config call_config(&transport);
107 call_config.start_bitrate_bps =
108 static_cast<int>(flags::StartBitrate()) * 1000;
109 scoped_ptr<Call> call(Call::Create(call_config));
111 // Loopback, call sends to itself.
112 transport.SetReceiver(call->Receiver());
114 VideoSendStream::Config send_config;
115 send_config.rtp.ssrcs.push_back(kSendSsrc);
116 send_config.rtp.rtx.ssrcs.push_back(kSendRtxSsrc);
117 send_config.rtp.rtx.payload_type = kRtxPayloadType;
118 send_config.rtp.nack.rtp_history_ms = 1000;
120 send_config.local_renderer = local_preview.get();
121 scoped_ptr<VideoEncoder> encoder;
122 if (flags::Codec() == "VP8") {
123 encoder.reset(VideoEncoder::Create(VideoEncoder::kVp8));
125 // Codec not supported.
126 assert(false && "Codec not supported!");
129 send_config.encoder_settings.encoder = encoder.get();
130 send_config.encoder_settings.payload_name = flags::Codec();
131 send_config.encoder_settings.payload_type = 124;
132 VideoEncoderConfig encoder_config;
133 encoder_config.streams = test::CreateVideoStreams(1);
134 VideoStream* stream = &encoder_config.streams[0];
135 stream->width = flags::Width();
136 stream->height = flags::Height();
137 stream->min_bitrate_bps = static_cast<int>(flags::MinBitrate()) * 1000;
138 stream->target_bitrate_bps = static_cast<int>(flags::MaxBitrate()) * 1000;
139 stream->max_bitrate_bps = static_cast<int>(flags::MaxBitrate()) * 1000;
140 stream->max_framerate = 30;
143 VideoSendStream* send_stream =
144 call->CreateVideoSendStream(send_config, encoder_config);
146 Clock* test_clock = Clock::GetRealTimeClock();
148 scoped_ptr<test::VideoCapturer> camera(
149 test::VideoCapturer::Create(send_stream->Input(),
155 VideoReceiveStream::Config receive_config;
156 receive_config.rtp.remote_ssrc = send_config.rtp.ssrcs[0];
157 receive_config.rtp.local_ssrc = kReceiverLocalSsrc;
158 receive_config.rtp.nack.rtp_history_ms = 1000;
159 receive_config.rtp.rtx[kRtxPayloadType].ssrc = kSendRtxSsrc;
160 receive_config.rtp.rtx[kRtxPayloadType].payload_type = kRtxPayloadType;
161 receive_config.renderer = loopback_video.get();
163 test::CreateDecoderVideoCodec(send_config.encoder_settings);
164 receive_config.codecs.push_back(codec);
166 VideoReceiveStream* receive_stream =
167 call->CreateVideoReceiveStream(receive_config);
169 receive_stream->Start();
170 send_stream->Start();
173 test::PressEnterToContinue();
177 receive_stream->Stop();
179 call->DestroyVideoReceiveStream(receive_stream);
180 call->DestroyVideoSendStream(send_stream);
182 transport.StopSending();
184 } // namespace webrtc
186 int main(int argc, char* argv[]) {
187 ::testing::InitGoogleTest(&argc, argv);
188 google::ParseCommandLineFlags(&argc, &argv, true);
190 webrtc::test::RunTest(webrtc::Loopback);