Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / video / loopback.cc
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
11 #include <stdio.h>
12
13 #include <map>
14
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 #include "webrtc/call.h"
18 #include "webrtc/system_wrappers/interface/clock.h"
19 #include "webrtc/system_wrappers/interface/scoped_ptr.h"
20 #include "webrtc/test/direct_transport.h"
21 #include "webrtc/test/flags.h"
22 #include "webrtc/test/run_loop.h"
23 #include "webrtc/test/run_tests.h"
24 #include "webrtc/test/video_capturer.h"
25 #include "webrtc/test/video_renderer.h"
26 #include "webrtc/typedefs.h"
27
28 namespace webrtc {
29
30 class LoopbackTest : public ::testing::Test {
31  protected:
32   std::map<uint32_t, bool> reserved_ssrcs_;
33 };
34
35 static const uint32_t kSendSsrc = 0x654321;
36 static const uint32_t kReceiverLocalSsrc = 0x123456;
37
38 TEST_F(LoopbackTest, Test) {
39   scoped_ptr<test::VideoRenderer> local_preview(test::VideoRenderer::Create(
40       "Local Preview", test::flags::Width(), test::flags::Height()));
41   scoped_ptr<test::VideoRenderer> loopback_video(test::VideoRenderer::Create(
42       "Loopback Video", test::flags::Width(), test::flags::Height()));
43
44   test::DirectTransport transport;
45   Call::Config call_config(&transport);
46   scoped_ptr<Call> call(Call::Create(call_config));
47
48   // Loopback, call sends to itself.
49   transport.SetReceiver(call->Receiver());
50
51   VideoSendStream::Config send_config = call->GetDefaultSendConfig();
52   send_config.rtp.ssrcs.push_back(kSendSsrc);
53
54   send_config.local_renderer = local_preview.get();
55
56   // TODO(pbos): static_cast shouldn't be required after mflodman refactors the
57   //             VideoCodec struct.
58   send_config.codec.width = static_cast<uint16_t>(test::flags::Width());
59   send_config.codec.height = static_cast<uint16_t>(test::flags::Height());
60   send_config.codec.minBitrate =
61       static_cast<unsigned int>(test::flags::MinBitrate());
62   send_config.codec.startBitrate =
63       static_cast<unsigned int>(test::flags::StartBitrate());
64   send_config.codec.maxBitrate =
65       static_cast<unsigned int>(test::flags::MaxBitrate());
66
67   VideoSendStream* send_stream = call->CreateVideoSendStream(send_config);
68
69   Clock* test_clock = Clock::GetRealTimeClock();
70
71   scoped_ptr<test::VideoCapturer> camera(
72       test::VideoCapturer::Create(send_stream->Input(),
73                                   test::flags::Width(),
74                                   test::flags::Height(),
75                                   test::flags::Fps(),
76                                   test_clock));
77
78   VideoReceiveStream::Config receive_config = call->GetDefaultReceiveConfig();
79   receive_config.rtp.remote_ssrc = send_config.rtp.ssrcs[0];
80   receive_config.rtp.local_ssrc = kReceiverLocalSsrc;
81   receive_config.renderer = loopback_video.get();
82
83   VideoReceiveStream* receive_stream =
84       call->CreateVideoReceiveStream(receive_config);
85
86   receive_stream->StartReceiving();
87   send_stream->StartSending();
88   camera->Start();
89
90   test::PressEnterToContinue();
91
92   camera->Stop();
93   send_stream->StopSending();
94   receive_stream->StopReceiving();
95
96   call->DestroyVideoReceiveStream(receive_stream);
97   call->DestroyVideoSendStream(send_stream);
98
99   transport.StopSending();
100 }
101 }  // namespace webrtc