blob: f92e606c338119e22e43b11357ffb8bac230aa6c [file] [log] [blame]
Donald E Curtisa8736442015-08-05 15:48:13 -07001/*
2 * Copyright 2012 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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "examples/peerconnection/client/conductor.h"
12#include "examples/peerconnection/client/flagdefs.h"
13#include "examples/peerconnection/client/main_wnd.h"
14#include "examples/peerconnection/client/peer_connection_client.h"
15#include "rtc_base/checks.h"
16#include "rtc_base/ssladapter.h"
17#include "rtc_base/win32socketinit.h"
18#include "rtc_base/win32socketserver.h"
Bjorn Terelius3e676762018-10-29 15:26:27 +010019#include "system_wrappers/include/field_trial.h"
20#include "test/field_trial.h"
Donald E Curtisa8736442015-08-05 15:48:13 -070021
Yves Gerey665174f2018-06-19 15:03:05 +020022int PASCAL wWinMain(HINSTANCE instance,
23 HINSTANCE prev_instance,
24 wchar_t* cmd_line,
25 int cmd_show) {
Mirko Bonadeiba5eaee2018-09-17 12:20:10 +020026 rtc::WinsockInitializer winsock_init;
nisse7eaa4ea2017-05-08 05:25:41 -070027 rtc::Win32SocketServer w32_ss;
28 rtc::Win32Thread w32_thread(&w32_ss);
Donald E Curtisa8736442015-08-05 15:48:13 -070029 rtc::ThreadManager::Instance()->SetCurrentThread(&w32_thread);
30
31 rtc::WindowsCommandLineArguments win_args;
32 int argc = win_args.argc();
Yves Gerey665174f2018-06-19 15:03:05 +020033 char** argv = win_args.argv();
Donald E Curtisa8736442015-08-05 15:48:13 -070034
35 rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true);
36 if (FLAG_help) {
37 rtc::FlagList::Print(NULL, false);
38 return 0;
39 }
40
Bjorn Terelius3e676762018-10-29 15:26:27 +010041 webrtc::test::ValidateFieldTrialsStringOrDie(FLAG_force_fieldtrials);
42 // InitFieldTrialsFromString stores the char*, so the char array must outlive
43 // the application.
44 webrtc::field_trial::InitFieldTrialsFromString(FLAG_force_fieldtrials);
45
Donald E Curtisa8736442015-08-05 15:48:13 -070046 // Abort if the user specifies a port that is outside the allowed
47 // range [1, 65535].
48 if ((FLAG_port < 1) || (FLAG_port > 65535)) {
49 printf("Error: %i is not a valid port.\n", FLAG_port);
50 return -1;
51 }
52
53 MainWnd wnd(FLAG_server, FLAG_port, FLAG_autoconnect, FLAG_autocall);
54 if (!wnd.Create()) {
nissec80e7412017-01-11 05:56:46 -080055 RTC_NOTREACHED();
Donald E Curtisa8736442015-08-05 15:48:13 -070056 return -1;
57 }
58
59 rtc::InitializeSSL();
60 PeerConnectionClient client;
61 rtc::scoped_refptr<Conductor> conductor(
Yves Gerey665174f2018-06-19 15:03:05 +020062 new rtc::RefCountedObject<Conductor>(&client, &wnd));
Donald E Curtisa8736442015-08-05 15:48:13 -070063
64 // Main loop.
65 MSG msg;
66 BOOL gm;
67 while ((gm = ::GetMessage(&msg, NULL, 0, 0)) != 0 && gm != -1) {
68 if (!wnd.PreTranslateMessage(&msg)) {
69 ::TranslateMessage(&msg);
70 ::DispatchMessage(&msg);
71 }
72 }
73
74 if (conductor->connection_active() || client.is_connected()) {
75 while ((conductor->connection_active() || client.is_connected()) &&
76 (gm = ::GetMessage(&msg, NULL, 0, 0)) != 0 && gm != -1) {
77 if (!wnd.PreTranslateMessage(&msg)) {
78 ::TranslateMessage(&msg);
79 ::DispatchMessage(&msg);
80 }
81 }
82 }
83
84 rtc::CleanupSSL();
85 return 0;
86}