2013-05-16 12:08:03 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-08-05 16:22:53 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
2013-05-16 12:08:03 +00:00
|
|
|
#include <map>
|
|
|
|
|
|
2014-05-13 11:26:40 +00:00
|
|
|
#include "gflags/gflags.h"
|
2013-05-27 15:52:38 +00:00
|
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
|
|
|
|
|
2013-10-28 16:32:01 +00:00
|
|
|
#include "webrtc/call.h"
|
2014-03-19 08:43:57 +00:00
|
|
|
#include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h"
|
2013-05-29 13:41:03 +00:00
|
|
|
#include "webrtc/system_wrappers/interface/clock.h"
|
2013-07-05 17:02:37 +00:00
|
|
|
#include "webrtc/system_wrappers/interface/scoped_ptr.h"
|
2013-10-28 16:32:01 +00:00
|
|
|
#include "webrtc/test/direct_transport.h"
|
2014-03-19 08:43:57 +00:00
|
|
|
#include "webrtc/test/encoder_settings.h"
|
|
|
|
|
#include "webrtc/test/fake_encoder.h"
|
2013-10-28 16:32:01 +00:00
|
|
|
#include "webrtc/test/run_loop.h"
|
2014-06-05 09:32:51 +00:00
|
|
|
#include "webrtc/test/run_test.h"
|
2013-10-28 16:32:01 +00:00
|
|
|
#include "webrtc/test/video_capturer.h"
|
|
|
|
|
#include "webrtc/test/video_renderer.h"
|
2013-05-17 13:44:48 +00:00
|
|
|
#include "webrtc/typedefs.h"
|
2013-05-16 12:08:03 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
2014-05-13 11:26:40 +00:00
|
|
|
namespace flags {
|
2013-05-16 12:08:03 +00:00
|
|
|
|
2014-05-13 11:26:40 +00:00
|
|
|
DEFINE_int32(width, 640, "Video width.");
|
|
|
|
|
size_t Width() { return static_cast<size_t>(FLAGS_width); }
|
|
|
|
|
|
|
|
|
|
DEFINE_int32(height, 480, "Video height.");
|
|
|
|
|
size_t Height() { return static_cast<size_t>(FLAGS_height); }
|
|
|
|
|
|
|
|
|
|
DEFINE_int32(fps, 30, "Frames per second.");
|
|
|
|
|
int Fps() { return static_cast<int>(FLAGS_fps); }
|
|
|
|
|
|
|
|
|
|
DEFINE_int32(min_bitrate, 50, "Minimum video bitrate.");
|
|
|
|
|
size_t MinBitrate() { return static_cast<size_t>(FLAGS_min_bitrate); }
|
|
|
|
|
|
|
|
|
|
DEFINE_int32(start_bitrate, 300, "Video starting bitrate.");
|
|
|
|
|
size_t StartBitrate() { return static_cast<size_t>(FLAGS_start_bitrate); }
|
|
|
|
|
|
|
|
|
|
DEFINE_int32(max_bitrate, 800, "Maximum video bitrate.");
|
|
|
|
|
size_t MaxBitrate() { return static_cast<size_t>(FLAGS_max_bitrate); }
|
|
|
|
|
} // namespace flags
|
2013-05-16 12:08:03 +00:00
|
|
|
|
2013-12-03 10:13:04 +00:00
|
|
|
static const uint32_t kSendSsrc = 0x654321;
|
|
|
|
|
static const uint32_t kReceiverLocalSsrc = 0x123456;
|
|
|
|
|
|
2014-05-13 11:26:40 +00:00
|
|
|
void Loopback() {
|
2013-07-05 17:02:37 +00:00
|
|
|
scoped_ptr<test::VideoRenderer> local_preview(test::VideoRenderer::Create(
|
2014-05-13 11:26:40 +00:00
|
|
|
"Local Preview", flags::Width(), flags::Height()));
|
2013-07-05 17:02:37 +00:00
|
|
|
scoped_ptr<test::VideoRenderer> loopback_video(test::VideoRenderer::Create(
|
2014-05-13 11:26:40 +00:00
|
|
|
"Loopback Video", flags::Width(), flags::Height()));
|
2013-05-16 12:08:03 +00:00
|
|
|
|
2013-08-12 12:59:04 +00:00
|
|
|
test::DirectTransport transport;
|
2013-09-09 15:04:25 +00:00
|
|
|
Call::Config call_config(&transport);
|
|
|
|
|
scoped_ptr<Call> call(Call::Create(call_config));
|
2013-05-16 12:08:03 +00:00
|
|
|
|
|
|
|
|
// Loopback, call sends to itself.
|
|
|
|
|
transport.SetReceiver(call->Receiver());
|
|
|
|
|
|
2013-08-23 09:19:30 +00:00
|
|
|
VideoSendStream::Config send_config = call->GetDefaultSendConfig();
|
2013-12-03 10:13:04 +00:00
|
|
|
send_config.rtp.ssrcs.push_back(kSendSsrc);
|
2013-05-16 12:08:03 +00:00
|
|
|
|
2013-07-05 17:02:37 +00:00
|
|
|
send_config.local_renderer = local_preview.get();
|
2013-05-16 12:08:03 +00:00
|
|
|
|
2014-03-19 08:43:57 +00:00
|
|
|
scoped_ptr<VP8Encoder> encoder(VP8Encoder::Create());
|
2014-06-06 10:49:19 +00:00
|
|
|
send_config.encoder_settings.encoder = encoder.get();
|
|
|
|
|
send_config.encoder_settings.payload_name = "VP8";
|
|
|
|
|
send_config.encoder_settings.payload_type = 124;
|
|
|
|
|
std::vector<VideoStream> video_streams = test::CreateVideoStreams(1);
|
|
|
|
|
VideoStream* stream = &video_streams[0];
|
2014-05-13 11:26:40 +00:00
|
|
|
stream->width = flags::Width();
|
|
|
|
|
stream->height = flags::Height();
|
|
|
|
|
stream->min_bitrate_bps = static_cast<int>(flags::MinBitrate()) * 1000;
|
2014-06-06 10:49:19 +00:00
|
|
|
stream->target_bitrate_bps = static_cast<int>(flags::MaxBitrate()) * 1000;
|
2014-05-13 11:26:40 +00:00
|
|
|
stream->max_bitrate_bps = static_cast<int>(flags::MaxBitrate()) * 1000;
|
2014-03-19 08:43:57 +00:00
|
|
|
stream->max_framerate = 30;
|
|
|
|
|
stream->max_qp = 56;
|
2013-05-16 12:08:03 +00:00
|
|
|
|
2014-06-06 10:49:19 +00:00
|
|
|
VideoSendStream* send_stream =
|
|
|
|
|
call->CreateVideoSendStream(send_config, video_streams, NULL);
|
2013-05-16 12:08:03 +00:00
|
|
|
|
2013-05-29 13:41:03 +00:00
|
|
|
Clock* test_clock = Clock::GetRealTimeClock();
|
|
|
|
|
|
2013-07-05 17:02:37 +00:00
|
|
|
scoped_ptr<test::VideoCapturer> camera(
|
2013-05-23 12:20:16 +00:00
|
|
|
test::VideoCapturer::Create(send_stream->Input(),
|
2014-05-13 11:26:40 +00:00
|
|
|
flags::Width(),
|
|
|
|
|
flags::Height(),
|
|
|
|
|
flags::Fps(),
|
2013-07-05 17:02:37 +00:00
|
|
|
test_clock));
|
2013-05-16 12:08:03 +00:00
|
|
|
|
2013-09-09 15:04:25 +00:00
|
|
|
VideoReceiveStream::Config receive_config = call->GetDefaultReceiveConfig();
|
2013-12-03 10:13:04 +00:00
|
|
|
receive_config.rtp.remote_ssrc = send_config.rtp.ssrcs[0];
|
|
|
|
|
receive_config.rtp.local_ssrc = kReceiverLocalSsrc;
|
2013-07-05 17:02:37 +00:00
|
|
|
receive_config.renderer = loopback_video.get();
|
2014-03-19 08:43:57 +00:00
|
|
|
VideoCodec codec =
|
|
|
|
|
test::CreateDecoderVideoCodec(send_config.encoder_settings);
|
|
|
|
|
receive_config.codecs.push_back(codec);
|
2013-05-16 12:08:03 +00:00
|
|
|
|
2013-08-23 09:19:30 +00:00
|
|
|
VideoReceiveStream* receive_stream =
|
2013-11-20 10:40:25 +00:00
|
|
|
call->CreateVideoReceiveStream(receive_config);
|
2013-05-16 12:08:03 +00:00
|
|
|
|
2014-04-24 11:13:21 +00:00
|
|
|
receive_stream->Start();
|
|
|
|
|
send_stream->Start();
|
2013-05-16 12:08:03 +00:00
|
|
|
camera->Start();
|
|
|
|
|
|
2013-07-10 14:07:56 +00:00
|
|
|
test::PressEnterToContinue();
|
2013-05-16 12:08:03 +00:00
|
|
|
|
2013-07-05 17:02:37 +00:00
|
|
|
camera->Stop();
|
2014-04-24 11:13:21 +00:00
|
|
|
send_stream->Stop();
|
|
|
|
|
receive_stream->Stop();
|
2013-05-16 12:08:03 +00:00
|
|
|
|
2013-11-21 13:49:43 +00:00
|
|
|
call->DestroyVideoReceiveStream(receive_stream);
|
|
|
|
|
call->DestroyVideoSendStream(send_stream);
|
2013-08-12 12:59:04 +00:00
|
|
|
|
|
|
|
|
transport.StopSending();
|
2013-05-16 12:08:03 +00:00
|
|
|
}
|
2013-12-05 12:11:47 +00:00
|
|
|
} // namespace webrtc
|
2014-05-13 11:26:40 +00:00
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
|
|
|
google::ParseCommandLineFlags(&argc, &argv, true);
|
|
|
|
|
|
2014-06-05 09:32:51 +00:00
|
|
|
webrtc::test::RunTest(webrtc::Loopback);
|
2014-05-13 11:26:40 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|