Donald E Curtis | a873644 | 2015-08-05 15:48:13 -0700 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #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 Terelius | 3e67676 | 2018-10-29 15:26:27 +0100 | [diff] [blame] | 19 | #include "system_wrappers/include/field_trial.h" |
| 20 | #include "test/field_trial.h" |
Donald E Curtis | a873644 | 2015-08-05 15:48:13 -0700 | [diff] [blame] | 21 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 22 | int PASCAL wWinMain(HINSTANCE instance, |
| 23 | HINSTANCE prev_instance, |
| 24 | wchar_t* cmd_line, |
| 25 | int cmd_show) { |
Mirko Bonadei | ba5eaee | 2018-09-17 12:20:10 +0200 | [diff] [blame] | 26 | rtc::WinsockInitializer winsock_init; |
nisse | 7eaa4ea | 2017-05-08 05:25:41 -0700 | [diff] [blame] | 27 | rtc::Win32SocketServer w32_ss; |
| 28 | rtc::Win32Thread w32_thread(&w32_ss); |
Donald E Curtis | a873644 | 2015-08-05 15:48:13 -0700 | [diff] [blame] | 29 | rtc::ThreadManager::Instance()->SetCurrentThread(&w32_thread); |
| 30 | |
| 31 | rtc::WindowsCommandLineArguments win_args; |
| 32 | int argc = win_args.argc(); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 33 | char** argv = win_args.argv(); |
Donald E Curtis | a873644 | 2015-08-05 15:48:13 -0700 | [diff] [blame] | 34 | |
| 35 | rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true); |
| 36 | if (FLAG_help) { |
| 37 | rtc::FlagList::Print(NULL, false); |
| 38 | return 0; |
| 39 | } |
| 40 | |
Bjorn Terelius | 3e67676 | 2018-10-29 15:26:27 +0100 | [diff] [blame] | 41 | 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 Curtis | a873644 | 2015-08-05 15:48:13 -0700 | [diff] [blame] | 46 | // 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()) { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 55 | RTC_NOTREACHED(); |
Donald E Curtis | a873644 | 2015-08-05 15:48:13 -0700 | [diff] [blame] | 56 | return -1; |
| 57 | } |
| 58 | |
| 59 | rtc::InitializeSSL(); |
| 60 | PeerConnectionClient client; |
| 61 | rtc::scoped_refptr<Conductor> conductor( |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 62 | new rtc::RefCountedObject<Conductor>(&client, &wnd)); |
Donald E Curtis | a873644 | 2015-08-05 15:48:13 -0700 | [diff] [blame] | 63 | |
| 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 | } |