]> git.sesse.net Git - casparcg/blob - shell/main.cpp
2.0.0.2: Added performance graphs.
[casparcg] / shell / main.cpp
1 /*\r
2 * copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
3 *\r
4 *  This file is part of CasparCG.\r
5 *\r
6 *    CasparCG is free software: you can redistribute it and/or modify\r
7 *    it under the terms of the GNU General Public License as published by\r
8 *    the Free Software Foundation, either version 3 of the License, or\r
9 *    (at your option) any later version.\r
10 *\r
11 *    CasparCG is distributed in the hope that it will be useful,\r
12 *    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14 *    GNU General Public License for more details.\r
15 \r
16 *    You should have received a copy of the GNU General Public License\r
17 *    along with CasparCG.  If not, see <http://www.gnu.org/licenses/>.\r
18 *\r
19 */\r
20 \r
21 #include <Windows.h>\r
22 \r
23 #include <tbb/tbbmalloc_proxy.h>\r
24 #include <tbb/task_scheduler_observer.h>\r
25 \r
26 #ifdef _DEBUG\r
27         #define _CRTDBG_MAP_ALLOC\r
28         #include <stdlib.h>\r
29         #include <crtdbg.h>\r
30 #endif\r
31 \r
32 #include <conio.h>\r
33 \r
34 #include "bootstrapper.h"\r
35 \r
36 #include <common/exception/win32_exception.h>\r
37 #include <common/exception/exceptions.h>\r
38 #include <common/log/log.h>\r
39 #include <common/env.h>\r
40 #include <common/utility/assert.h>\r
41 #include <protocol/amcp/AMCPProtocolStrategy.h>\r
42 \r
43 #if defined(_MSC_VER)\r
44 #pragma warning (disable : 4244)\r
45 #endif\r
46 \r
47 extern "C" \r
48 {\r
49         #define __STDC_CONSTANT_MACROS\r
50         #define __STDC_LIMIT_MACROS\r
51         #include <libavformat/avformat.h>\r
52 }\r
53 \r
54 #include <atlbase.h>\r
55 \r
56 using namespace caspar;\r
57 using namespace caspar::core;\r
58 using namespace caspar::protocol;\r
59 \r
60 // NOTE: This is needed in order to make CComObject work since this is not a real ATL project.\r
61 CComModule _AtlModule;\r
62 extern __declspec(selectany) CAtlModule* _pAtlModule = &_AtlModule;\r
63 \r
64 class win32_handler_tbb_installer : public tbb::task_scheduler_observer\r
65 {\r
66 public:\r
67         win32_handler_tbb_installer()   {observe(true);}\r
68         void on_scheduler_entry(bool is_worker) \r
69         {\r
70                 //CASPAR_LOG(debug) << L"Started TBB Worker Thread.";\r
71                 win32_exception::install_handler();\r
72         }\r
73         void on_scheduler_exit()\r
74         {\r
75                 //CASPAR_LOG(debug) << L"Stopped TBB Worker Thread.";\r
76         }\r
77 };\r
78  \r
79 int main(int argc, wchar_t* argv[])\r
80 {\r
81         // Init FFMPEG\r
82         av_register_all();\r
83         avcodec_init();\r
84 \r
85         // Increase time precision\r
86         timeBeginPeriod(1);\r
87 \r
88         // Start caspar\r
89         std::wstringstream str;\r
90         str << "CasparCG " << env::version() << " " << env::version_tag();\r
91         SetConsoleTitle(str.str().c_str());\r
92 \r
93         std::wcout << L"Copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\n" << std::endl;\r
94         std::wcout << L"Starting CasparCG Video Playout Server Ver: " << env::version() << env::version_tag() << std::endl;\r
95 \r
96         EnableMenuItem(GetSystemMenu(GetConsoleWindow(), FALSE), SC_CLOSE , MF_GRAYED);\r
97         DrawMenuBar(GetConsoleWindow());\r
98         MoveWindow(GetConsoleWindow(), 800, 0, 800, 1000, true);\r
99 \r
100 #ifdef _DEBUG\r
101         _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF | _CRTDBG_CHECK_ALWAYS_DF );\r
102         _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_DEBUG );\r
103         _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_DEBUG );\r
104         _CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_DEBUG );\r
105 \r
106         MessageBox(nullptr, TEXT("Now is the time to connect for remote debugging..."), TEXT("Debug"), MB_OK | MB_TOPMOST);\r
107 #endif\r
108 \r
109         log::add_file_sink(env::log_folder());\r
110         \r
111         win32_handler_tbb_installer win32_handler_tbb_installer;\r
112         win32_exception::install_handler();\r
113                                 \r
114         try \r
115         {\r
116                 bootstrapper caspar_device;\r
117                                 \r
118                 auto dummy = std::make_shared<IO::DummyClientInfo>();\r
119                 amcp::AMCPProtocolStrategy amcp(caspar_device.get_channels());\r
120                 bool is_running = true;\r
121                 while(is_running)\r
122                 {\r
123                         std::wstring wcmd;\r
124                         std::getline(std::wcin, wcmd); // TODO: It's blocking...\r
125                         is_running = wcmd != L"exit" && wcmd != L"q";\r
126                         if(wcmd.substr(0, 2) == L"12")\r
127                         {\r
128                                 wcmd = L"LOADBG 1-1 A LOOP AUTOPLAY\r\n";\r
129                                 amcp.Parse(wcmd.c_str(), wcmd.length(), dummy);\r
130                                 wcmd = L"LOADBG 1-2 DV LOOP AUTOPLAY\r\n";\r
131                                 amcp.Parse(wcmd.c_str(), wcmd.length(), dummy);\r
132                                 wcmd = L"MIXER 1-1 VIDEO FIX_RECT 0.0 0.0 0.5 0.5\r\n";\r
133                                 amcp.Parse(wcmd.c_str(), wcmd.length(), dummy);\r
134                                 wcmd = L"MIXER 1-2 VIDEO FIX_RECT 0.5 0.0 0.5 0.5\r\n";\r
135                                 amcp.Parse(wcmd.c_str(), wcmd.length(), dummy);\r
136                         }\r
137                         else if(wcmd.substr(0, 2) == L"10")\r
138                                 wcmd = L"MIXER 1-1 VIDEO CLIP_RECT 0.4 0.4 0.5 0.5";\r
139                         if(wcmd.substr(0, 2) == L"11")\r
140                                 wcmd = L"MIXER 1-1 VIDEO FIX_RECT 0.4 0.4 0.5 0.5";\r
141                         else if(wcmd.substr(0, 1) == L"1")\r
142                                 wcmd = L"LOADBG 1-1 " + wcmd.substr(1, wcmd.length()-1) + L" SLIDE 100 LOOP AUTOPLAY";\r
143                         else if(wcmd.substr(0, 1) == L"2")\r
144                                 wcmd = L"LOADBG 1-1 " + wcmd.substr(1, wcmd.length()-1) + L" PUSH 100 LOOP AUTOPLAY";\r
145                         else if(wcmd.substr(0, 1) == L"3")\r
146                                 wcmd = L"LOADBG 1-1 " + wcmd.substr(1, wcmd.length()-1) + L" MIX 100 LOOP AUTOPLAY";\r
147                         else if(wcmd.substr(0, 1) == L"4")\r
148                                 wcmd = L"LOADBG 1-1 " + wcmd.substr(1, wcmd.length()-1) + L" WIPE 100 LOOP AUTOPLAY";\r
149                         else if(wcmd.substr(0, 1) == L"5")\r
150                                 wcmd = L"LOADBG 1-2 " + wcmd.substr(1, wcmd.length()-1) + L" LOOP AUTOPLAY";\r
151                         else if(wcmd.substr(0, 1) == L"6")\r
152                                 wcmd = L"CG 1-2 ADD 1 BBTELEFONARE 1";\r
153                         else if(wcmd.substr(0, 1) == L"7")\r
154                                 wcmd = L"LOAD 1-1 720p2500";\r
155                         else if(wcmd.substr(0, 1) == L"8")\r
156                                 wcmd = L"LOAD 1-1 #FFFFFFFF AUTOPLAY";\r
157                         else if(wcmd.substr(0, 1) == L"9")\r
158                                 wcmd = L"LOADBG 1-2 " + wcmd.substr(1, wcmd.length()-1) + L" [1.0-2.0] LOOP AUTOPLAY";\r
159 \r
160                         wcmd += L"\r\n";\r
161                         amcp.Parse(wcmd.c_str(), wcmd.length(), dummy);\r
162                 }\r
163         }\r
164         catch(const std::exception&)\r
165         {\r
166                 CASPAR_LOG(fatal) << "UNHANDLED EXCEPTION in main thread.";\r
167                 CASPAR_LOG_CURRENT_EXCEPTION();\r
168                 std::wcout << L"Press Any Key To Exit";\r
169                 _getwch();\r
170         }       \r
171 \r
172         timeEndPeriod(1);\r
173         \r
174         return 0;\r
175 }