2 * copyright (c) 2010 Sveriges Television AB <info@casparcg.com>
\r
4 * This file is part of CasparCG.
\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
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
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
21 #include <Windows.h>
\r
23 #include <tbb/tbbmalloc_proxy.h>
\r
24 #include <tbb/task_scheduler_observer.h>
\r
27 #define _CRTDBG_MAP_ALLOC
\r
34 #include "bootstrapper.h"
\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
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
48 #include <mixer/gpu/ogl_device.h>
\r
50 #include <protocol/amcp/AMCPProtocolStrategy.h>
\r
54 #include <boost/foreach.hpp>
\r
56 #if defined(_MSC_VER)
\r
57 #pragma warning (disable : 4244)
\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
69 #include <atlbase.h>
\r
71 using namespace caspar;
\r
72 using namespace caspar::core;
\r
73 using namespace caspar::protocol;
\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
79 class win32_handler_tbb_installer : public tbb::task_scheduler_observer
\r
82 win32_handler_tbb_installer() {observe(true);}
\r
83 void on_scheduler_entry(bool is_worker)
\r
85 //CASPAR_LOG(debug) << L"Started TBB Worker Thread.";
\r
86 win32_exception::install_handler();
\r
88 void on_scheduler_exit()
\r
90 //CASPAR_LOG(debug) << L"Stopped TBB Worker Thread.";
\r
94 void setup_console_window()
\r
96 auto hOut = GetStdHandle(STD_OUTPUT_HANDLE);
\r
98 EnableMenuItem(GetSystemMenu(GetConsoleWindow(), FALSE), SC_CLOSE , MF_GRAYED);
\r
99 DrawMenuBar(GetConsoleWindow());
\r
101 auto coord = GetLargestConsoleWindowSize(hOut);
\r
104 SetConsoleScreenBufferSize(hOut, coord);
\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
111 std::wstringstream str;
\r
112 str << "CasparCG Server " << env::version();
\r
113 SetConsoleTitle(str.str().c_str());
\r
116 void print_version()
\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_image_version();
\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
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
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
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
144 wchar_t p_name_str[1024];
\r
145 wchar_t csd_ver_str[1024];
\r
146 wchar_t csd_build_str[1024];
\r
149 dwSize = sizeof(p_name_str);
\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
157 CASPAR_LOG(info) << p_name_str << L" " << csd_ver_str << L"." << csd_build_str << L"\n";
\r
161 int main(int argc, wchar_t* argv[])
\r
165 win32_handler_tbb_installer win32_handler_tbb_installer;
\r
166 win32_exception::install_handler();
\r
168 env::initialize("caspar.config");
\r
174 // Increase time precision
\r
175 timeBeginPeriod(1);
\r
179 setup_console_window();
\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
187 MessageBox(nullptr, TEXT("Now is the time to connect for remote debugging..."), TEXT("Debug"), MB_OK | MB_TOPMOST);
\r
190 log::add_file_sink(env::log_folder());
\r
194 bootstrapper caspar_device;
\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
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
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
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
239 amcp.Parse(wcmd.c_str(), wcmd.length(), dummy);
\r
242 catch(const std::exception&)
\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
252 CASPAR_LOG(info) << "Successfully shutdown CasparCG Server";
\r