]> git.sesse.net Git - casparcg/blob - shell/main.cpp
2.0.0.2: Progress on animated values.
[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 #include <core/producer/flash/cg_producer.h>\r
38 #include <core/producer/image/image_producer.h>\r
39 #include <core/consumer/decklink/decklink_consumer.h>\r
40 #include <core/consumer/bluefish/bluefish_consumer.h>\r
41 \r
42 #include <common/exception/win32_exception.h>\r
43 #include <common/exception/exceptions.h>\r
44 #include <common/log/log.h>\r
45 #include <common/env.h>\r
46 #include <common/utility/assert.h>\r
47 \r
48 #include <mixer/gpu/ogl_device.h>\r
49 \r
50 #include <protocol/amcp/AMCPProtocolStrategy.h>\r
51 \r
52 #include <GLee.h>\r
53 \r
54 #include <boost/foreach.hpp>\r
55 \r
56 #if defined(_MSC_VER)\r
57 #pragma warning (disable : 4244)\r
58 #endif\r
59 \r
60 extern "C" \r
61 {\r
62         #define __STDC_CONSTANT_MACROS\r
63         #define __STDC_LIMIT_MACROS\r
64         #include <libavformat/avformat.h>\r
65         #include <libswscale/swscale.h>\r
66         #include <libavcodec/avcodec.h>\r
67 }\r
68 \r
69 #include <atlbase.h>\r
70 \r
71 using namespace caspar;\r
72 using namespace caspar::core;\r
73 using namespace caspar::protocol;\r
74 \r
75 // NOTE: This is needed in order to make CComObject work since this is not a real ATL project.\r
76 CComModule _AtlModule;\r
77 extern __declspec(selectany) CAtlModule* _pAtlModule = &_AtlModule;\r
78 \r
79 class win32_handler_tbb_installer : public tbb::task_scheduler_observer\r
80 {\r
81 public:\r
82         win32_handler_tbb_installer()   {observe(true);}\r
83         void on_scheduler_entry(bool is_worker) \r
84         {\r
85                 //CASPAR_LOG(debug) << L"Started TBB Worker Thread.";\r
86                 win32_exception::install_handler();\r
87         }\r
88         void on_scheduler_exit()\r
89         {\r
90                 //CASPAR_LOG(debug) << L"Stopped TBB Worker Thread.";\r
91         }\r
92 };\r
93 \r
94 void setup_console_window()\r
95 {       \r
96         auto hOut = GetStdHandle(STD_OUTPUT_HANDLE);\r
97 \r
98         EnableMenuItem(GetSystemMenu(GetConsoleWindow(), FALSE), SC_CLOSE , MF_GRAYED);\r
99         DrawMenuBar(GetConsoleWindow());\r
100 \r
101         auto coord = GetLargestConsoleWindowSize(hOut);\r
102         coord.X /= 2;\r
103 \r
104         SetConsoleScreenBufferSize(hOut, coord);\r
105 \r
106         SMALL_RECT DisplayArea = {0, 0, 0, 0};\r
107         DisplayArea.Right = coord.X-1;\r
108         DisplayArea.Bottom = coord.Y-1;\r
109         SetConsoleWindowInfo(hOut, TRUE, &DisplayArea);\r
110                 \r
111         std::wstringstream str;\r
112         str << "CasparCG Server " << env::version();\r
113         SetConsoleTitle(str.str().c_str());\r
114 }\r
115 \r
116 void print_version()\r
117 {       \r
118         CASPAR_LOG(info) << L"Copyright (c) 2010 Sveriges Television AB, www.casparcg.com, <info@casparcg.com>";\r
119         CASPAR_LOG(info) << L"Starting CasparCG Video and Graphics Playout Server " << env::version();\r
120         CASPAR_LOG(info) << L"Flash " << flash::get_flash_version();\r
121         CASPAR_LOG(info) << L"Flash-Template-Host " << flash::get_cg_version();\r
122         CASPAR_LOG(info) << L"FreeImage " << image::get_fill_version();\r
123         \r
124         std::wstring decklink_devices;\r
125         BOOST_FOREACH(auto& device, get_decklink_device_list())\r
126                 decklink_devices += L"\t" + device;\r
127         CASPAR_LOG(info) << L"Decklink " << get_decklink_version() << (decklink_devices.empty() ? L"" : L"\n\tDevices:\n" + decklink_devices);\r
128         \r
129         std::wstring bluefish_devices;\r
130         BOOST_FOREACH(auto& device, get_bluefish_device_list())\r
131                 bluefish_devices += L"\t" + device;\r
132         CASPAR_LOG(info) << L"Bluefish " << get_bluefish_version() << (bluefish_devices.empty() ? L"" : L"\n\tDevices:\n" + bluefish_devices);\r
133 \r
134         CASPAR_LOG(info) << L"FFMPEG-avcodec " << ((avcodec_version() >> 16) & 0xFF) << L"." << ((avcodec_version() >> 8) & 0xFF) << L"." << ((avcodec_version() >> 0) & 0xFF);\r
135         CASPAR_LOG(info) << L"FFMPEG-swscale " << ((avformat_version() >> 16) & 0xFF) << L"." << ((avformat_version() >> 8) & 0xFF) << L"." << ((avformat_version() >> 0) & 0xFF);\r
136         CASPAR_LOG(info) << L"FFMPEG-avformat " << ((swscale_version() >> 16) & 0xFF) << L"." << ((swscale_version() >> 8) & 0xFF) << L"." << ((swscale_version() >> 0) & 0xFF);\r
137         CASPAR_LOG(info) << L"OpenGL " << ogl_device::create()->invoke([]{return reinterpret_cast<const char*>(glGetString(GL_VERSION));})\r
138                                          << L" "           << ogl_device::create()->invoke([]{return reinterpret_cast<const char*>(glGetString(GL_VENDOR));});\r
139 \r
140         HKEY hkey; \r
141         DWORD dwType, dwSize;\r
142         if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"), 0, KEY_QUERY_VALUE, &hkey) == ERROR_SUCCESS)\r
143         {\r
144                 wchar_t p_name_str[1024];\r
145                 wchar_t csd_ver_str[1024];\r
146                 wchar_t csd_build_str[1024];\r
147 \r
148                 dwType = REG_SZ;\r
149                 dwSize = sizeof(p_name_str);\r
150 \r
151                 RegQueryValueEx(hkey, TEXT("ProductName"), NULL, &dwType, (PBYTE)&p_name_str, &dwSize);\r
152                 RegQueryValueEx(hkey, TEXT("CSDVersion"), NULL, &dwType, (PBYTE)&csd_ver_str, &dwSize);\r
153                 RegQueryValueEx(hkey, TEXT("CSDBuildNumber"), NULL, &dwType, (PBYTE)&csd_build_str, &dwSize);\r
154  \r
155                 RegCloseKey(hkey);\r
156 \r
157                 CASPAR_LOG(info) << p_name_str << L" " << csd_ver_str << L"." << csd_build_str << L"\n";\r
158         }\r
159 }\r
160  \r
161 int main(int argc, wchar_t* argv[])\r
162 {       \r
163         try \r
164         {\r
165                 win32_handler_tbb_installer win32_handler_tbb_installer;\r
166                 win32_exception::install_handler();\r
167 \r
168                 env::initialize("caspar.config");\r
169 \r
170                 // Init FFMPEG\r
171                 av_register_all();\r
172                 avcodec_init();\r
173 \r
174                 // Increase time precision\r
175                 timeBeginPeriod(1);\r
176 \r
177                 // Start caspar\r
178 \r
179                 setup_console_window();\r
180 \r
181         #ifdef _DEBUG\r
182                 _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF | _CRTDBG_CHECK_ALWAYS_DF );\r
183                 _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_DEBUG );\r
184                 _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_DEBUG );\r
185                 _CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_DEBUG );\r
186 \r
187                 MessageBox(nullptr, TEXT("Now is the time to connect for remote debugging..."), TEXT("Debug"), MB_OK | MB_TOPMOST);\r
188         #endif\r
189                                          \r
190                 log::add_file_sink(env::log_folder());\r
191 \r
192                 print_version();\r
193                                 \r
194                 bootstrapper caspar_device;\r
195                                 \r
196                 auto dummy = std::make_shared<IO::ConsoleClientInfo>();\r
197                 amcp::AMCPProtocolStrategy amcp(caspar_device.get_channels());\r
198                 bool is_running = true;\r
199                 while(is_running)\r
200                 {\r
201                         std::wstring wcmd;\r
202                         std::getline(std::wcin, wcmd); // TODO: It's blocking...\r
203                         is_running = wcmd != L"exit" && wcmd != L"q";\r
204                         if(wcmd.substr(0, 2) == L"12")\r
205                         {\r
206                                 wcmd = L"LOADBG 1-1 A LOOP AUTOPLAY\r\n";\r
207                                 amcp.Parse(wcmd.c_str(), wcmd.length(), dummy);\r
208                                 wcmd = L"LOADBG 1-2 DV LOOP AUTOPLAY\r\n";\r
209                                 amcp.Parse(wcmd.c_str(), wcmd.length(), dummy);\r
210                                 wcmd = L"MIXER 1-1 VIDEO FIX_RECT 0.0 0.0 0.5 0.5\r\n";\r
211                                 amcp.Parse(wcmd.c_str(), wcmd.length(), dummy);\r
212                                 wcmd = L"MIXER 1-2 VIDEO FIX_RECT 0.5 0.0 0.5 0.5\r\n";\r
213                                 amcp.Parse(wcmd.c_str(), wcmd.length(), dummy);\r
214                         }\r
215                         else if(wcmd.substr(0, 2) == L"10")\r
216                                 wcmd = L"MIXER 1-1 VIDEO CLIP_RECT 0.4 0.4 0.5 0.5";\r
217                         if(wcmd.substr(0, 2) == L"11")\r
218                                 wcmd = L"MIXER 1-1 VIDEO FIX_RECT 0.4 0.4 0.5 0.5";\r
219                         else if(wcmd.substr(0, 1) == L"1")\r
220                                 wcmd = L"LOADBG 1-1 " + wcmd.substr(1, wcmd.length()-1) + L" SLIDE 100 LOOP AUTOPLAY";\r
221                         else if(wcmd.substr(0, 1) == L"2")\r
222                                 wcmd = L"LOADBG 1-1 " + wcmd.substr(1, wcmd.length()-1) + L" PUSH 100 LOOP AUTOPLAY";\r
223                         else if(wcmd.substr(0, 1) == L"3")\r
224                                 wcmd = L"LOADBG 1-1 " + wcmd.substr(1, wcmd.length()-1) + L" MIX 100 LOOP AUTOPLAY";\r
225                         else if(wcmd.substr(0, 1) == L"4")\r
226                                 wcmd = L"LOADBG 1-1 " + wcmd.substr(1, wcmd.length()-1) + L" WIPE 100 LOOP AUTOPLAY";\r
227                         else if(wcmd.substr(0, 1) == L"5")\r
228                                 wcmd = L"LOADBG 1-2 " + wcmd.substr(1, wcmd.length()-1) + L" LOOP AUTOPLAY";\r
229                         else if(wcmd.substr(0, 1) == L"6")\r
230                                 wcmd = L"CG 1-2 ADD 1 BBTELEFONARE 1";\r
231                         else if(wcmd.substr(0, 1) == L"7")\r
232                                 wcmd = L"LOAD 1-1 720p2500";\r
233                         else if(wcmd.substr(0, 1) == L"8")\r
234                                 wcmd = L"LOAD 1-1 #FFFFFFFF AUTOPLAY";\r
235                         else if(wcmd.substr(0, 1) == L"9")\r
236                                 wcmd = L"LOADBG 1-2 " + wcmd.substr(1, wcmd.length()-1) + L" [1.0-2.0] LOOP AUTOPLAY";\r
237 \r
238                         wcmd += L"\r\n";\r
239                         amcp.Parse(wcmd.c_str(), wcmd.length(), dummy);\r
240                 }\r
241         }\r
242         catch(const std::exception&)\r
243         {\r
244                 CASPAR_LOG(fatal) << "UNHANDLED EXCEPTION in main thread.";\r
245                 CASPAR_LOG_CURRENT_EXCEPTION();\r
246                 std::wcout << L"Press Any Key To Exit\n";\r
247                 _getwch();\r
248         }       \r
249 \r
250         timeEndPeriod(1);\r
251 \r
252         CASPAR_LOG(info) << "Successfully shutdown CasparCG Server";\r
253         \r
254         return 0;\r
255 }