pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 1 | /* |
| 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.org | 3f45c2e | 2013-08-05 16:22:53 +0000 | [diff] [blame] | 11 | #include <stdio.h> |
| 12 | |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 13 | #include <map> |
| 14 | |
mflodman@webrtc.org | a93cbbf | 2013-05-27 15:52:38 +0000 | [diff] [blame] | 15 | #include "testing/gtest/include/gtest/gtest.h" |
| 16 | |
pbos@webrtc.org | 24e2089 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 17 | #include "webrtc/call.h" |
pbos@webrtc.org | c1506a2 | 2013-05-29 13:41:03 +0000 | [diff] [blame] | 18 | #include "webrtc/system_wrappers/interface/clock.h" |
pbos@webrtc.org | b16cb05 | 2013-07-05 17:02:37 +0000 | [diff] [blame] | 19 | #include "webrtc/system_wrappers/interface/scoped_ptr.h" |
pbos@webrtc.org | 24e2089 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 20 | #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.org | 281cff8 | 2013-05-17 13:44:48 +0000 | [diff] [blame] | 27 | #include "webrtc/typedefs.h" |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 28 | |
| 29 | namespace webrtc { |
| 30 | |
| 31 | class LoopbackTest : public ::testing::Test { |
| 32 | protected: |
pbos@webrtc.org | 2f02da8 | 2013-07-09 08:02:33 +0000 | [diff] [blame] | 33 | std::map<uint32_t, bool> reserved_ssrcs_; |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 34 | }; |
| 35 | |
| 36 | TEST_F(LoopbackTest, Test) { |
pbos@webrtc.org | b16cb05 | 2013-07-05 17:02:37 +0000 | [diff] [blame] | 37 | 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.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 41 | |
pbos@webrtc.org | fe881f6 | 2013-08-12 12:59:04 +0000 | [diff] [blame] | 42 | test::DirectTransport transport; |
pbos@webrtc.org | bf6d572 | 2013-09-09 15:04:25 +0000 | [diff] [blame] | 43 | Call::Config call_config(&transport); |
mflodman@webrtc.org | bf76ae2 | 2013-07-23 11:35:00 +0000 | [diff] [blame] | 44 | call_config.overuse_detection = true; |
pbos@webrtc.org | bf6d572 | 2013-09-09 15:04:25 +0000 | [diff] [blame] | 45 | scoped_ptr<Call> call(Call::Create(call_config)); |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 46 | |
| 47 | // Loopback, call sends to itself. |
| 48 | transport.SetReceiver(call->Receiver()); |
| 49 | |
pbos@webrtc.org | c179706 | 2013-08-23 09:19:30 +0000 | [diff] [blame] | 50 | VideoSendStream::Config send_config = call->GetDefaultSendConfig(); |
pbos@webrtc.org | 2f02da8 | 2013-07-09 08:02:33 +0000 | [diff] [blame] | 51 | test::GenerateRandomSsrcs(&send_config, &reserved_ssrcs_); |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 52 | |
pbos@webrtc.org | b16cb05 | 2013-07-05 17:02:37 +0000 | [diff] [blame] | 53 | send_config.local_renderer = local_preview.get(); |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 54 | |
pbos@webrtc.org | 074eb20 | 2013-05-23 12:20:16 +0000 | [diff] [blame] | 55 | // TODO(pbos): static_cast shouldn't be required after mflodman refactors the |
| 56 | // VideoCodec struct. |
mflodman@webrtc.org | a93cbbf | 2013-05-27 15:52:38 +0000 | [diff] [blame] | 57 | 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.org | 074eb20 | 2013-05-23 12:20:16 +0000 | [diff] [blame] | 59 | 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.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 65 | |
pbos@webrtc.org | 964d78e | 2013-11-20 10:40:25 +0000 | [diff] [blame] | 66 | VideoSendStream* send_stream = call->CreateVideoSendStream(send_config); |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 67 | |
pbos@webrtc.org | c1506a2 | 2013-05-29 13:41:03 +0000 | [diff] [blame] | 68 | Clock* test_clock = Clock::GetRealTimeClock(); |
| 69 | |
pbos@webrtc.org | b16cb05 | 2013-07-05 17:02:37 +0000 | [diff] [blame] | 70 | scoped_ptr<test::VideoCapturer> camera( |
pbos@webrtc.org | 074eb20 | 2013-05-23 12:20:16 +0000 | [diff] [blame] | 71 | test::VideoCapturer::Create(send_stream->Input(), |
| 72 | test::flags::Width(), |
| 73 | test::flags::Height(), |
pbos@webrtc.org | c1506a2 | 2013-05-29 13:41:03 +0000 | [diff] [blame] | 74 | test::flags::Fps(), |
pbos@webrtc.org | b16cb05 | 2013-07-05 17:02:37 +0000 | [diff] [blame] | 75 | test_clock)); |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 76 | |
pbos@webrtc.org | bf6d572 | 2013-09-09 15:04:25 +0000 | [diff] [blame] | 77 | VideoReceiveStream::Config receive_config = call->GetDefaultReceiveConfig(); |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 78 | receive_config.rtp.ssrc = send_config.rtp.ssrcs[0]; |
pbos@webrtc.org | b16cb05 | 2013-07-05 17:02:37 +0000 | [diff] [blame] | 79 | receive_config.renderer = loopback_video.get(); |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 80 | |
pbos@webrtc.org | c179706 | 2013-08-23 09:19:30 +0000 | [diff] [blame] | 81 | VideoReceiveStream* receive_stream = |
pbos@webrtc.org | 964d78e | 2013-11-20 10:40:25 +0000 | [diff] [blame] | 82 | call->CreateVideoReceiveStream(receive_config); |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 83 | |
pbos@webrtc.org | 7f9f840 | 2013-11-20 11:36:47 +0000 | [diff] [blame] | 84 | receive_stream->StartReceiving(); |
| 85 | send_stream->StartSending(); |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 86 | camera->Start(); |
| 87 | |
pbos@webrtc.org | 778a172 | 2013-07-10 14:07:56 +0000 | [diff] [blame] | 88 | test::PressEnterToContinue(); |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 89 | |
pbos@webrtc.org | b16cb05 | 2013-07-05 17:02:37 +0000 | [diff] [blame] | 90 | camera->Stop(); |
pbos@webrtc.org | 7f9f840 | 2013-11-20 11:36:47 +0000 | [diff] [blame] | 91 | send_stream->StopSending(); |
| 92 | receive_stream->StopReceiving(); |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 93 | |
pbos@webrtc.org | 12a93e0 | 2013-11-21 13:49:43 +0000 | [diff] [blame^] | 94 | call->DestroyVideoReceiveStream(receive_stream); |
| 95 | call->DestroyVideoSendStream(send_stream); |
pbos@webrtc.org | fe881f6 | 2013-08-12 12:59:04 +0000 | [diff] [blame] | 96 | |
| 97 | transport.StopSending(); |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 98 | } |
| 99 | } // webrtc |