]> git.sesse.net Git - casparcg/blob - shell/main.cpp
2.0.0.2: Display flash version in main window.
[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 <core/producer/flash/flash_producer.h>\r
37 \r
38 #include <common/exception/win32_exception.h>\r
39 #include <common/exception/exceptions.h>\r
40 #include <common/log/log.h>\r
41 #include <common/env.h>\r
42 #include <common/utility/assert.h>\r
43 #include <protocol/amcp/AMCPProtocolStrategy.h>\r
44 \r
45 #if defined(_MSC_VER)\r
46 #pragma warning (disable : 4244)\r
47 #endif\r
48 \r
49 extern "C" \r
50 {\r
51         #define __STDC_CONSTANT_MACROS\r
52         #define __STDC_LIMIT_MACROS\r
53         #include <libavformat/avformat.h>\r
54 }\r
55 \r
56 #include <atlbase.h>\r
57 \r
58 using namespace caspar;\r
59 using namespace caspar::core;\r
60 using namespace caspar::protocol;\r
61 \r
62 // NOTE: This is needed in order to make CComObject work since this is not a real ATL project.\r
63 CComModule _AtlModule;\r
64 extern __declspec(selectany) CAtlModule* _pAtlModule = &_AtlModule;\r
65 \r
66 class win32_handler_tbb_installer : public tbb::task_scheduler_observer\r
67 {\r
68 public:\r
69         win32_handler_tbb_installer()   {observe(true);}\r
70         void on_scheduler_entry(bool is_worker) \r
71         {\r
72                 //CASPAR_LOG(debug) << L"Started TBB Worker Thread.";\r
73                 win32_exception::install_handler();\r
74         }\r
75         void on_scheduler_exit()\r
76         {\r
77                 //CASPAR_LOG(debug) << L"Stopped TBB Worker Thread.";\r
78         }\r
79 };\r
80 \r
81 void setup_console_window()\r
82 {       \r
83         auto hOut = GetStdHandle(STD_OUTPUT_HANDLE);\r
84 \r
85         EnableMenuItem(GetSystemMenu(GetConsoleWindow(), FALSE), SC_CLOSE , MF_GRAYED);\r
86         DrawMenuBar(GetConsoleWindow());\r
87 \r
88         auto coord = GetLargestConsoleWindowSize(hOut);\r
89         coord.X /= 2;\r
90 \r
91         SetConsoleScreenBufferSize(hOut, coord);\r
92 \r
93         SMALL_RECT DisplayArea = {0, 0, 0, 0};\r
94         DisplayArea.Right = coord.X-1;\r
95         DisplayArea.Bottom = coord.Y-1;\r
96         SetConsoleWindowInfo(hOut, TRUE, &DisplayArea);\r
97                 \r
98         std::wstringstream str;\r
99         str << "CasparCG Server " << env::version() << L"      Flash " << flash::flash_producer::version();\r
100         SetConsoleTitle(str.str().c_str());\r
101 \r
102         std::wcout << L"Copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\n" << std::endl;\r
103         std::wcout << L"Starting CasparCG Video Playout Server Ver: " << env::version() << std::endl;\r
104 }\r
105  \r
106 int main(int argc, wchar_t* argv[])\r
107 {       \r
108         try \r
109         {\r
110                 win32_handler_tbb_installer win32_handler_tbb_installer;\r
111                 win32_exception::install_handler();\r
112 \r
113                 env::initialize("caspar.config");\r
114 \r
115                 // Init FFMPEG\r
116                 av_register_all();\r
117                 avcodec_init();\r
118 \r
119                 // Increase time precision\r
120                 timeBeginPeriod(1);\r
121 \r
122                 // Start caspar\r
123 \r
124                 setup_console_window();\r
125 \r
126         #ifdef _DEBUG\r
127                 _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF | _CRTDBG_CHECK_ALWAYS_DF );\r
128                 _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_DEBUG );\r
129                 _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_DEBUG );\r
130                 _CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_DEBUG );\r
131 \r
132                 MessageBox(nullptr, TEXT("Now is the time to connect for remote debugging..."), TEXT("Debug"), MB_OK | MB_TOPMOST);\r
133         #endif\r
134 \r
135                 log::add_file_sink(env::log_folder());\r
136                                 \r
137                 bootstrapper caspar_device;\r
138                                 \r
139                 auto dummy = std::make_shared<IO::DummyClientInfo>();\r
140                 amcp::AMCPProtocolStrategy amcp(caspar_device.get_channels());\r
141                 bool is_running = true;\r
142                 while(is_running)\r
143                 {\r
144                         std::wstring wcmd;\r
145                         std::getline(std::wcin, wcmd); // TODO: It's blocking...\r
146                         is_running = wcmd != L"exit" && wcmd != L"q";\r
147                         if(wcmd.substr(0, 2) == L"12")\r
148                         {\r
149                                 wcmd = L"LOADBG 1-1 A LOOP AUTOPLAY\r\n";\r
150                                 amcp.Parse(wcmd.c_str(), wcmd.length(), dummy);\r
151                                 wcmd = L"LOADBG 1-2 DV LOOP AUTOPLAY\r\n";\r
152                                 amcp.Parse(wcmd.c_str(), wcmd.length(), dummy);\r
153                                 wcmd = L"MIXER 1-1 VIDEO FIX_RECT 0.0 0.0 0.5 0.5\r\n";\r
154                                 amcp.Parse(wcmd.c_str(), wcmd.length(), dummy);\r
155                                 wcmd = L"MIXER 1-2 VIDEO FIX_RECT 0.5 0.0 0.5 0.5\r\n";\r
156                                 amcp.Parse(wcmd.c_str(), wcmd.length(), dummy);\r
157                         }\r
158                         else if(wcmd.substr(0, 2) == L"10")\r
159                                 wcmd = L"MIXER 1-1 VIDEO CLIP_RECT 0.4 0.4 0.5 0.5";\r
160                         if(wcmd.substr(0, 2) == L"11")\r
161                                 wcmd = L"MIXER 1-1 VIDEO FIX_RECT 0.4 0.4 0.5 0.5";\r
162                         else if(wcmd.substr(0, 1) == L"1")\r
163                                 wcmd = L"LOADBG 1-1 " + wcmd.substr(1, wcmd.length()-1) + L" SLIDE 100 LOOP AUTOPLAY";\r
164                         else if(wcmd.substr(0, 1) == L"2")\r
165                                 wcmd = L"LOADBG 1-1 " + wcmd.substr(1, wcmd.length()-1) + L" PUSH 100 LOOP AUTOPLAY";\r
166                         else if(wcmd.substr(0, 1) == L"3")\r
167                                 wcmd = L"LOADBG 1-1 " + wcmd.substr(1, wcmd.length()-1) + L" MIX 100 LOOP AUTOPLAY";\r
168                         else if(wcmd.substr(0, 1) == L"4")\r
169                                 wcmd = L"LOADBG 1-1 " + wcmd.substr(1, wcmd.length()-1) + L" WIPE 100 LOOP AUTOPLAY";\r
170                         else if(wcmd.substr(0, 1) == L"5")\r
171                                 wcmd = L"LOADBG 1-2 " + wcmd.substr(1, wcmd.length()-1) + L" LOOP AUTOPLAY";\r
172                         else if(wcmd.substr(0, 1) == L"6")\r
173                                 wcmd = L"CG 1-2 ADD 1 BBTELEFONARE 1";\r
174                         else if(wcmd.substr(0, 1) == L"7")\r
175                                 wcmd = L"LOAD 1-1 720p2500";\r
176                         else if(wcmd.substr(0, 1) == L"8")\r
177                                 wcmd = L"LOAD 1-1 #FFFFFFFF AUTOPLAY";\r
178                         else if(wcmd.substr(0, 1) == L"9")\r
179                                 wcmd = L"LOADBG 1-2 " + wcmd.substr(1, wcmd.length()-1) + L" [1.0-2.0] LOOP AUTOPLAY";\r
180 \r
181                         wcmd += L"\r\n";\r
182                         amcp.Parse(wcmd.c_str(), wcmd.length(), dummy);\r
183                 }\r
184         }\r
185         catch(const std::exception&)\r
186         {\r
187                 CASPAR_LOG(fatal) << "UNHANDLED EXCEPTION in main thread.";\r
188                 CASPAR_LOG_CURRENT_EXCEPTION();\r
189                 std::wcout << L"Press Any Key To Exit\n";\r
190                 _getwch();\r
191         }       \r
192 \r
193         timeEndPeriod(1);\r
194 \r
195         CASPAR_LOG(info) << "Successfully shutdown CasparCG Server";\r
196         \r
197         return 0;\r
198 }