X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=shell%2Fmain.cpp;h=6843c9d225033b51802ccbc9b47d102461f6cd04;hb=09362ec89302304408ed6d39494b102cb694b0e4;hp=a3648b7612ef2ca2780d0f173833c72f93cc02cb;hpb=59d477e3cc496d72dd54396ce097e3797ad60ad3;p=casparcg diff --git a/shell/main.cpp b/shell/main.cpp index a3648b761..6843c9d22 100644 --- a/shell/main.cpp +++ b/shell/main.cpp @@ -18,11 +18,14 @@ * */ -#include -#include - +// tbbmalloc_proxy: +// Replace the standard memory allocation routines in Microsoft* C/C++ RTL +// (malloc/free, global new/delete, etc.) with the TBB memory allocator. #include -#include + +#include "resource.h" + +#include "server.h" #ifdef _DEBUG #define _CRTDBG_MAP_ALLOC @@ -30,10 +33,17 @@ #include #endif -#include "bootstrapper.h" +#define NOMINMAX +#define WIN32_LEAN_AND_MEAN -#include +#include +#include +#include +#include + +#include +#include #include #include #include @@ -43,48 +53,41 @@ #include #include #include -#include - -#include +#include +#include +#include -#include +#include -#include +#include +#include -#include +#include -using namespace caspar; -using namespace caspar::core; -using namespace caspar::protocol; - -#include +#include // NOTE: This is needed in order to make CComObject work since this is not a real ATL project. CComModule _AtlModule; extern __declspec(selectany) CAtlModule* _pAtlModule = &_AtlModule; -class win32_handler_tbb_installer : public tbb::task_scheduler_observer +void change_icon( const HICON hNewIcon ) { -public: - win32_handler_tbb_installer() {observe(true);} - void on_scheduler_entry(bool is_worker) - { - //CASPAR_LOG(debug) << L"Started TBB Worker Thread."; - win32_exception::install_handler(); - } - void on_scheduler_exit() - { - //CASPAR_LOG(debug) << L"Stopped TBB Worker Thread."; - } -}; + auto hMod = ::LoadLibrary(L"Kernel32.dll"); + typedef DWORD(__stdcall *SCI)(HICON); + auto pfnSetConsoleIcon = reinterpret_cast(::GetProcAddress(hMod, "SetConsoleIcon")); + pfnSetConsoleIcon(hNewIcon); + ::FreeLibrary(hMod); +} void setup_console_window() -{ +{ auto hOut = GetStdHandle(STD_OUTPUT_HANDLE); + // Disable close button in console to avoid shutdown without cleanup. EnableMenuItem(GetSystemMenu(GetConsoleWindow(), FALSE), SC_CLOSE , MF_GRAYED); DrawMenuBar(GetConsoleWindow()); + // Configure console size and position. auto coord = GetLargestConsoleWindowSize(hOut); coord.X /= 2; @@ -92,145 +95,222 @@ void setup_console_window() SMALL_RECT DisplayArea = {0, 0, 0, 0}; DisplayArea.Right = coord.X-1; - DisplayArea.Bottom = coord.Y-1; + DisplayArea.Bottom = (coord.Y-1)/2; SetConsoleWindowInfo(hOut, TRUE, &DisplayArea); - + + change_icon(::LoadIcon(GetModuleHandle(0), MAKEINTRESOURCE(101))); + + // Set console title. std::wstringstream str; - str << "CasparCG Server " << env::version(); + str << "CasparCG Server " << caspar::env::version(); +#ifdef COMPILE_RELEASE + str << " Release"; +#elif COMPILE_PROFILE + str << " Profile"; +#elif COMPILE_DEVELOP + str << " Develop"; +#elif COMPILE_DEBUG + str << " Debug"; +#endif SetConsoleTitle(str.str().c_str()); } -void print_version() +void print_info() { CASPAR_LOG(info) << L"Copyright (c) 2010 Sveriges Television AB, www.casparcg.com, "; - CASPAR_LOG(info) << L"Starting CasparCG Video and Graphics Playout Server " << env::version(); - CASPAR_LOG(info) << L"Flash " << get_flash_version(); - CASPAR_LOG(info) << L"Flash-Template-Host " << get_cg_version(); - CASPAR_LOG(info) << L"FreeImage " << get_image_version(); - - std::wstring decklink_devices; - BOOST_FOREACH(auto& device, get_decklink_device_list()) - decklink_devices += L"\t" + device; - CASPAR_LOG(info) << L"Decklink " << get_decklink_version() << (decklink_devices.empty() ? L"" : L"\n\tDevices:\n" + decklink_devices); + CASPAR_LOG(info) << L"Starting CasparCG Video and Graphics Playout Server " << caspar::env::version(); + CASPAR_LOG(info) << L"on " << caspar::get_win_product_name() << L" " << caspar::get_win_sp_version(); + CASPAR_LOG(info) << caspar::get_cpu_info(); + CASPAR_LOG(info) << caspar::get_system_product_name(); + CASPAR_LOG(info) << L"Flash " << caspar::get_flash_version(); + CASPAR_LOG(info) << L"Flash-Template-Host " << caspar::get_cg_version(); + CASPAR_LOG(info) << L"FreeImage " << caspar::get_image_version(); - std::wstring bluefish_devices; - BOOST_FOREACH(auto& device, get_bluefish_device_list()) - bluefish_devices += L"\t" + device; - CASPAR_LOG(info) << L"Bluefish " << get_bluefish_version() << (bluefish_devices.empty() ? L"" : L"\n\tDevices:\n" + bluefish_devices); - - CASPAR_LOG(info) << L"FFMPEG-avcodec " << get_avcodec_version(); - CASPAR_LOG(info) << L"FFMPEG-swscale " << get_avformat_version(); - CASPAR_LOG(info) << L"FFMPEG-avformat " << get_swscale_version(); - CASPAR_LOG(info) << L"OpenGL " << mixer::ogl_device::create()->invoke([]{return reinterpret_cast(glGetString(GL_VERSION));}) - << L" " << mixer::ogl_device::create()->invoke([]{return reinterpret_cast(glGetString(GL_VENDOR));}); - - HKEY hkey; - DWORD dwType, dwSize; - if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"), 0, KEY_QUERY_VALUE, &hkey) == ERROR_SUCCESS) + CASPAR_LOG(info) << L"Decklink " << caspar::get_decklink_version(); + auto deck = caspar::get_decklink_device_list(); + std::for_each(deck.begin(), deck.end(), [](const std::wstring& device) { - wchar_t p_name_str[1024]; - wchar_t csd_ver_str[1024]; - - dwType = REG_SZ; - dwSize = sizeof(p_name_str); + CASPAR_LOG(info) << device; + }); + + auto blue = caspar::get_bluefish_device_list(); + std::for_each(blue.begin(), blue.end(), [](const std::wstring& device) + { + CASPAR_LOG(info) << device; + }); + + CASPAR_LOG(info) << L"FFMPEG-avcodec " << caspar::get_avcodec_version(); + CASPAR_LOG(info) << L"FFMPEG-avformat " << caspar::get_avformat_version(); + CASPAR_LOG(info) << L"FFMPEG-avfilter " << caspar::get_avfilter_version(); + CASPAR_LOG(info) << L"FFMPEG-avutil " << caspar::get_avutil_version(); + CASPAR_LOG(info) << L"FFMPEG-swscale " << caspar::get_swscale_version(); + CASPAR_LOG(info) << L"OpenGL " << caspar::core::ogl_device::get_version() << "\n\n"; +} - if(RegQueryValueEx(hkey, TEXT("ProductName"), NULL, &dwType, (PBYTE)&p_name_str, &dwSize) == ERROR_SUCCESS && - RegQueryValueEx(hkey, TEXT("CSDVersion"), NULL, &dwType, (PBYTE)&csd_ver_str, &dwSize) == ERROR_SUCCESS) - { - CASPAR_LOG(info) << p_name_str << L" " << csd_ver_str << L"." << L"\n"; - } - else - CASPAR_LOG(warning) << "Could not read OS info." << L"\n"; - - RegCloseKey(hkey); +LONG WINAPI UserUnhandledExceptionFilter(EXCEPTION_POINTERS* info) +{ + try + { + CASPAR_LOG(fatal) << L"#######################\n UNHANDLED EXCEPTION: \n" + << L"Adress:" << info->ExceptionRecord->ExceptionAddress << L"\n" + << L"Code:" << info->ExceptionRecord->ExceptionCode << L"\n" + << L"Flag:" << info->ExceptionRecord->ExceptionFlags << L"\n" + << L"Info:" << info->ExceptionRecord->ExceptionInformation << L"\n" + << L"Continuing execution. \n#######################"; } + catch(...){} + + return EXCEPTION_CONTINUE_EXECUTION; } - + int main(int argc, wchar_t* argv[]) -{ +{ + static_assert(sizeof(void*) == 4, "64-bit code generation is not supported."); + + SetUnhandledExceptionFilter(UserUnhandledExceptionFilter); + + CASPAR_LOG(info) << L"Type \"q\" to close application"; + + CASPAR_LOG(info) << L"THIS IS AN ALPHA BUILD"; + + // Set debug mode. #ifdef _DEBUG _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF | _CRTDBG_CHECK_ALWAYS_DF ); _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_DEBUG ); _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_DEBUG ); _CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_DEBUG ); - - if(env::properties().get("configuration.debugging.remote", false)) - MessageBox(nullptr, TEXT("Now is the time to connect for remote debugging..."), TEXT("Debug"), MB_OK | MB_TOPMOST); #endif - - // Increase time precision - timeBeginPeriod(1); - win32_handler_tbb_installer win32_handler_tbb_installer; - win32_exception::install_handler(); + // Increase process priotity. + SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS); + + // Install structured exception handler. + caspar::win32_exception::install_handler(); + + // Increase time precision. This will increase accuracy of function like Sleep(1) from 10 ms to 1 ms. + struct inc_prec + { + inc_prec(){timeBeginPeriod(1);} + ~inc_prec(){timeEndPeriod(1);} + } inc_prec; + + // Install unstructured exception handlers into all tbb threads. + struct tbb_thread_installer : public tbb::task_scheduler_observer + { + tbb_thread_installer(){observe(true);} + void on_scheduler_entry(bool is_worker) + { + //caspar::detail::SetThreadName(GetCurrentThreadId(), "tbb-worker-thread"); + caspar::win32_exception::install_handler(); + } + } tbb_thread_installer; + + tbb::task_scheduler_init init; + try { - env::initialize("caspar.config"); + // Configure environment properties from configuration. + caspar::env::configure("casparcg.config"); + + #ifdef _DEBUG + if(caspar::env::properties().get("configuration.debugging.remote", false)) + MessageBox(nullptr, TEXT("Now is the time to connect for remote debugging..."), TEXT("Debug"), MB_OK | MB_TOPMOST); + #endif + + // Start logging to file. + caspar::log::add_file_sink(caspar::env::log_folder()); - setup_console_window(); - log::add_file_sink(env::log_folder()); + // Setup console window. + setup_console_window(); - print_version(); + // Print environment information. + print_info(); - bootstrapper caspar_device; + // Create server object which initializes channels, protocols and controllers. + caspar::server caspar_server; - auto dummy = std::make_shared(); - amcp::AMCPProtocolStrategy amcp(caspar_device.get_channels()); + // Create a amcp parser for console commands. + caspar::protocol::amcp::AMCPProtocolStrategy amcp(caspar_server.get_channels()); + + // Create a dummy client which prints amcp responses to console. + auto dummy = std::make_shared(); + bool is_running = true; while(is_running) { std::wstring wcmd; std::getline(std::wcin, wcmd); // TODO: It's blocking... + is_running = wcmd != L"exit" && wcmd != L"q"; - if(wcmd.substr(0, 2) == L"12") - { - wcmd = L"LOADBG 1-1 A LOOP \r\nPLAY 1-1\r\n"; - amcp.Parse(wcmd.c_str(), wcmd.length(), dummy); - wcmd = L"LOADBG 1-2 DV LOOP AUTOPLAY\r\nnPLAY 1-1\r\n"; - amcp.Parse(wcmd.c_str(), wcmd.length(), dummy); - wcmd = L"MIXER 1-1 VIDEO FIX_RECT 0.0 0.0 0.5 0.5\r\n"; - amcp.Parse(wcmd.c_str(), wcmd.length(), dummy); - wcmd = L"MIXER 1-2 VIDEO FIX_RECT 0.5 0.0 0.5 0.5\r\n"; - amcp.Parse(wcmd.c_str(), wcmd.length(), dummy); - } - else if(wcmd.substr(0, 2) == L"10") - wcmd = L"MIXER 1-1 VIDEO CLIP_RECT 0.4 0.4 0.5 0.5"; - if(wcmd.substr(0, 2) == L"11") - wcmd = L"MIXER 1-1 VIDEO FIX_RECT 0.4 0.4 0.5 0.5"; - else if(wcmd.substr(0, 1) == L"1") + if(wcmd.substr(0, 1) == L"1") wcmd = L"LOADBG 1-1 " + wcmd.substr(1, wcmd.length()-1) + L" SLIDE 100 LOOP \r\nPLAY 1-1"; else if(wcmd.substr(0, 1) == L"2") - wcmd = L"LOADBG 1-1 " + wcmd.substr(1, wcmd.length()-1) + L" PUSH 100 LOOP \r\nPLAY 1-1"; + wcmd = L"MIXER 1-0 VIDEO IS_KEY 1"; else if(wcmd.substr(0, 1) == L"3") - wcmd = L"LOADBG 1-1 " + wcmd.substr(1, wcmd.length()-1) + L" MIX 100 LOOP \r\nPLAY 1-1"; + wcmd = L"CG 1-2 ADD 1 BBTELEFONARE 1"; else if(wcmd.substr(0, 1) == L"4") - wcmd = L"LOADBG 1-1 " + wcmd.substr(1, wcmd.length()-1) + L" WIPE 100 LOOP \r\nPLAY 1-1"; + wcmd = L"PLAY 1-1 DV FILTER yadif=1:-1 LOOP"; else if(wcmd.substr(0, 1) == L"5") - wcmd = L"LOADBG 1-2 " + wcmd.substr(1, wcmd.length()-1) + L" LOOP \r\nPLAY 1-2"; - else if(wcmd.substr(0, 1) == L"6") - wcmd = L"CG 1-2 ADD 1 THING 1"; - else if(wcmd.substr(0, 1) == L"7") - wcmd = L"LOAD 1-1 720p2500"; - else if(wcmd.substr(0, 1) == L"8") - wcmd = L"LOAD 1-1 #FFFFFFFF AUTOPLAY"; - else if(wcmd.substr(0, 1) == L"9") - wcmd = L"LOADBG 1-2 " + wcmd.substr(1, wcmd.length()-1) + L" [1.0-2.0] LOOP AUTOPLAY"; + { + auto file = wcmd.substr(2, wcmd.length()-1); + wcmd = L"PLAY 1-1 " + file + L" LOOP\r\n" + L"PLAY 1-2 " + file + L" LOOP\r\n" + L"PLAY 1-3 " + file + L" LOOP\r\n" + L"PLAY 2-1 " + file + L" LOOP\r\n" + L"PLAY 2-2 " + file + L" LOOP\r\n" + L"PLAY 2-3 " + file + L" LOOP\r\n"; + } + else if(wcmd.substr(0, 1) == L"X") + { + int num = 0; + std::wstring file; + try + { + num = boost::lexical_cast(wcmd.substr(1, 2)); + file = wcmd.substr(4, wcmd.length()-1); + } + catch(...) + { + num = boost::lexical_cast(wcmd.substr(1, 1)); + file = wcmd.substr(3, wcmd.length()-1); + } + + int n = 0; + int num2 = num; + while(num2 > 0) + { + num2 >>= 1; + n++; + } + + wcmd = L"MIXER 1 GRID " + boost::lexical_cast(n); + + for(int i = 1; i <= num; ++i) + wcmd += L"\r\nPLAY 1-" + boost::lexical_cast(i) + L" " + file + L" LOOP";// + L" SLIDE 100 LOOP"; + } wcmd += L"\r\n"; amcp.Parse(wcmd.c_str(), wcmd.length(), dummy); } } - catch(const std::exception&) + catch(boost::property_tree::file_parser_error&) { - CASPAR_LOG(fatal) << "UNHANDLED EXCEPTION in main thread."; CASPAR_LOG_CURRENT_EXCEPTION(); - std::wcout << L"Press Any Key To Exit\n"; - _getwch(); + CASPAR_LOG(fatal) << L"Unhandled configuration error in main thread. Please check the configuration file (casparcg.config) for errors."; + } + catch(caspar::gl::ogl_exception&) + { + CASPAR_LOG_CURRENT_EXCEPTION(); + CASPAR_LOG(fatal) << L"Unhandled OpenGL Error in main thread. Please try to update graphics drivers in order to receive full OpenGL 3.1+ Support."; + } + catch(...) + { + CASPAR_LOG_CURRENT_EXCEPTION(); + CASPAR_LOG(fatal) << L"Unhandled exception in main thread. Please report this error on the CasparCG forums (www.casparcg.com/forum)."; } - - timeEndPeriod(1); - - CASPAR_LOG(info) << "Successfully shutdown CasparCG Server"; + CASPAR_LOG(info) << "Successfully shutdown CasparCG Server."; + Sleep(100); // CAPSAR_LOG is asynchronous. Try to get text in correct order. + system("pause"); return 0; } \ No newline at end of file