]> git.sesse.net Git - casparcg/blobdiff - shell/main.cpp
2.0. Initialize TBB worker threads right away to avoid spikes when playing the first...
[casparcg] / shell / main.cpp
index 9d739a4640a3d326651fa2ec01c78dad9fec2d36..6843c9d225033b51802ccbc9b47d102461f6cd04 100644 (file)
 *    along with CasparCG.  If not, see <http://www.gnu.org/licenses/>.\r
 *\r
 */\r
-#include "resource.h"\r
-\r
-#include "server.h"\r
 \r
 // tbbmalloc_proxy: \r
 // Replace the standard memory allocation routines in Microsoft* C/C++ RTL \r
 // (malloc/free, global new/delete, etc.) with the TBB memory allocator. \r
 #include <tbb/tbbmalloc_proxy.h>\r
 \r
+#include "resource.h"\r
+\r
+#include "server.h"\r
+\r
 #ifdef _DEBUG\r
        #define _CRTDBG_MAP_ALLOC\r
        #include <stdlib.h>\r
 #endif\r
 \r
 #define NOMINMAX\r
+#define WIN32_LEAN_AND_MEAN\r
 \r
 #include <windows.h>\r
+#include <winnt.h>\r
+#include <mmsystem.h>\r
 #include <atlbase.h>\r
 \r
-#include <core/mixer/gpu/ogl_device.h>\r
-\r
 #include <protocol/amcp/AMCPProtocolStrategy.h>\r
 \r
 #include <modules/bluefish/bluefish.h>\r
 #include <common/exception/win32_exception.h>\r
 #include <common/exception/exceptions.h>\r
 #include <common/log/log.h>\r
+#include <common/gl/gl_check.h>\r
 #include <common/os/windows/current_version.h>\r
 #include <common/os/windows/system_info.h>\r
-#include <common/utility/assert.h>\r
 \r
-#include <tbb/task_scheduler_observer.h>\r
+#include <core/mixer/gpu/ogl_device.h>\r
+\r
 #include <tbb/task_scheduler_init.h>\r
+#include <tbb/task_scheduler_observer.h>\r
+\r
+#include <boost/property_tree/detail/file_parser_error.hpp>\r
 \r
-#include <boost/foreach.hpp>\r
+#include <algorithm>\r
 \r
 // NOTE: This is needed in order to make CComObject work since this is not a real ATL project.\r
 CComModule _AtlModule;\r
 extern __declspec(selectany) CAtlModule* _pAtlModule = &_AtlModule;\r
 \r
+void change_icon( const HICON hNewIcon )\r
+{\r
+   auto hMod = ::LoadLibrary(L"Kernel32.dll"); \r
+   typedef DWORD(__stdcall *SCI)(HICON);\r
+   auto pfnSetConsoleIcon = reinterpret_cast<SCI>(::GetProcAddress(hMod, "SetConsoleIcon")); \r
+   pfnSetConsoleIcon(hNewIcon); \r
+   ::FreeLibrary(hMod);\r
+}\r
+\r
 void setup_console_window()\r
 {       \r
        auto hOut = GetStdHandle(STD_OUTPUT_HANDLE);\r
@@ -82,7 +97,9 @@ void setup_console_window()
        DisplayArea.Right = coord.X-1;\r
        DisplayArea.Bottom = (coord.Y-1)/2;\r
        SetConsoleWindowInfo(hOut, TRUE, &DisplayArea);\r
-               \r
+                \r
+       change_icon(::LoadIcon(GetModuleHandle(0), MAKEINTRESOURCE(101)));\r
+\r
        // Set console title.\r
        std::wstringstream str;\r
        str << "CasparCG Server " << caspar::env::version();\r
@@ -110,13 +127,18 @@ void print_info()
        CASPAR_LOG(info) << L"FreeImage " << caspar::get_image_version();\r
        \r
        CASPAR_LOG(info) << L"Decklink " << caspar::get_decklink_version();\r
-       BOOST_FOREACH(auto& device, caspar::get_decklink_device_list())\r
+       auto deck = caspar::get_decklink_device_list();\r
+       std::for_each(deck.begin(), deck.end(), [](const std::wstring& device)\r
+       {\r
                CASPAR_LOG(info) << device;\r
+       });\r
                \r
-       CASPAR_LOG(info) << L"Bluefish " << caspar::get_bluefish_version();\r
-       BOOST_FOREACH(auto& device, caspar::get_bluefish_device_list())\r
+       auto blue = caspar::get_bluefish_device_list();\r
+       std::for_each(blue.begin(), blue.end(), [](const std::wstring& device)\r
+       {\r
                CASPAR_LOG(info) << device;\r
-\r
+       });\r
+       \r
        CASPAR_LOG(info) << L"FFMPEG-avcodec "  << caspar::get_avcodec_version();\r
        CASPAR_LOG(info) << L"FFMPEG-avformat " << caspar::get_avformat_version();\r
        CASPAR_LOG(info) << L"FFMPEG-avfilter " << caspar::get_avfilter_version();\r
@@ -124,12 +146,32 @@ void print_info()
        CASPAR_LOG(info) << L"FFMPEG-swscale "  << caspar::get_swscale_version();\r
        CASPAR_LOG(info) << L"OpenGL " << caspar::core::ogl_device::get_version() << "\n\n";\r
 }\r
\r
+\r
+LONG WINAPI UserUnhandledExceptionFilter(EXCEPTION_POINTERS* info)\r
+{\r
+       try\r
+       {\r
+               CASPAR_LOG(fatal) << L"#######################\n UNHANDLED EXCEPTION: \n" \r
+                       << L"Adress:" << info->ExceptionRecord->ExceptionAddress << L"\n"\r
+                       << L"Code:" << info->ExceptionRecord->ExceptionCode << L"\n"\r
+                       << L"Flag:" << info->ExceptionRecord->ExceptionFlags << L"\n"\r
+                       << L"Info:" << info->ExceptionRecord->ExceptionInformation << L"\n"\r
+                       << L"Continuing execution. \n#######################";\r
+       }\r
+       catch(...){}\r
+\r
+    return EXCEPTION_CONTINUE_EXECUTION;\r
+}\r
+\r
 int main(int argc, wchar_t* argv[])\r
 {      \r
        static_assert(sizeof(void*) == 4, "64-bit code generation is not supported.");\r
        \r
-       CASPAR_LOG(info) << L"THIS IS AN UNSTABLE BUILD";\r
+       SetUnhandledExceptionFilter(UserUnhandledExceptionFilter);\r
+\r
+       CASPAR_LOG(info) << L"Type \"q\" to close application";\r
+\r
+       CASPAR_LOG(info) << L"THIS IS AN ALPHA BUILD";\r
 \r
        // Set debug mode.\r
        #ifdef _DEBUG\r
@@ -156,8 +198,14 @@ int main(int argc, wchar_t* argv[])
        struct tbb_thread_installer : public tbb::task_scheduler_observer\r
        {\r
                tbb_thread_installer(){observe(true);}\r
-               void on_scheduler_entry(bool is_worker){caspar::win32_exception::install_handler();}\r
+               void on_scheduler_entry(bool is_worker)\r
+               {\r
+                       //caspar::detail::SetThreadName(GetCurrentThreadId(), "tbb-worker-thread");\r
+                       caspar::win32_exception::install_handler();\r
+               }\r
        } tbb_thread_installer;\r
+\r
+       tbb::task_scheduler_init init;\r
        \r
        try \r
        {\r
@@ -201,7 +249,17 @@ int main(int argc, wchar_t* argv[])
                        else if(wcmd.substr(0, 1) == L"3")\r
                                wcmd = L"CG 1-2 ADD 1 BBTELEFONARE 1";\r
                        else if(wcmd.substr(0, 1) == L"4")\r
-                               wcmd = L"PLAY 1-1 DV SEEK 350 FILTER yadif=1:-1 LOOP";\r
+                               wcmd = L"PLAY 1-1 DV FILTER yadif=1:-1 LOOP";\r
+                       else if(wcmd.substr(0, 1) == L"5")\r
+                       {\r
+                               auto file = wcmd.substr(2, wcmd.length()-1);\r
+                               wcmd = L"PLAY 1-1 " + file + L" LOOP\r\n" \r
+                                          L"PLAY 1-2 " + file + L" LOOP\r\n" \r
+                                          L"PLAY 1-3 " + file + L" LOOP\r\n"\r
+                                          L"PLAY 2-1 " + file + L" LOOP\r\n" \r
+                                          L"PLAY 2-2 " + file + L" LOOP\r\n" \r
+                                          L"PLAY 2-3 " + file + L" LOOP\r\n";\r
+                       }\r
                        else if(wcmd.substr(0, 1) == L"X")\r
                        {\r
                                int num = 0;\r
@@ -225,7 +283,7 @@ int main(int argc, wchar_t* argv[])
                                        n++;\r
                                }\r
 \r
-                               wcmd = L"MIXER 1 VIDEO GRID " + boost::lexical_cast<std::wstring>(n);\r
+                               wcmd = L"MIXER 1 GRID " + boost::lexical_cast<std::wstring>(n);\r
 \r
                                for(int i = 1; i <= num; ++i)\r
                                        wcmd += L"\r\nPLAY 1-" + boost::lexical_cast<std::wstring>(i) + L" " + file + L" LOOP";// + L" SLIDE 100 LOOP";\r
@@ -235,10 +293,20 @@ int main(int argc, wchar_t* argv[])
                        amcp.Parse(wcmd.c_str(), wcmd.length(), dummy);\r
                }\r
        }\r
+       catch(boost::property_tree::file_parser_error&)\r
+       {\r
+               CASPAR_LOG_CURRENT_EXCEPTION();\r
+               CASPAR_LOG(fatal) << L"Unhandled configuration error in main thread. Please check the configuration file (casparcg.config) for errors.";\r
+       }\r
+       catch(caspar::gl::ogl_exception&)\r
+       {\r
+               CASPAR_LOG_CURRENT_EXCEPTION();\r
+               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.";\r
+       }\r
        catch(...)\r
        {\r
-               CASPAR_LOG(fatal) << "UNHANDLED EXCEPTION in main thread.";\r
                CASPAR_LOG_CURRENT_EXCEPTION();\r
+               CASPAR_LOG(fatal) << L"Unhandled exception in main thread. Please report this error on the CasparCG forums (www.casparcg.com/forum).";\r
        }       \r
        \r
        CASPAR_LOG(info) << "Successfully shutdown CasparCG Server.";\r