]> git.sesse.net Git - casparcg/blobdiff - modules/decklink/decklink.cpp
Merge pull request #145 from cambell-prince/ffmpeg-dshowparams
[casparcg] / modules / decklink / decklink.cpp
index 94a8ba5561efc4509e51bae01f05296d535b1a01..13fdbb55364ee1f3814b603414218ee782da2446 100644 (file)
@@ -1,30 +1,34 @@
 /*\r
-* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+* Copyright 2013 Sveriges Television AB http://casparcg.com/\r
 *\r
-*  This file is part of CasparCG.\r
+* This file is part of CasparCG (www.casparcg.com).\r
 *\r
-*    CasparCG is free software: you can redistribute it and/or modify\r
-*    it under the terms of the GNU General Public License as published by\r
-*    the Free Software Foundation, either version 3 of the License, or\r
-*    (at your option) any later version.\r
+* CasparCG is free software: you can redistribute it and/or modify\r
+* it under the terms of the GNU General Public License as published by\r
+* the Free Software Foundation, either version 3 of the License, or\r
+* (at your option) any later version.\r
 *\r
-*    CasparCG is distributed in the hope that it will be useful,\r
-*    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
-*    GNU General Public License for more details.\r
-\r
-*    You should have received a copy of the GNU General Public License\r
-*    along with CasparCG.  If not, see <http://www.gnu.org/licenses/>.\r
+* CasparCG is distributed in the hope that it will be useful,\r
+* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+* GNU General Public License for more details.\r
+*\r
+* You should have received a copy of the GNU General Public License\r
+* along with CasparCG. If not, see <http://www.gnu.org/licenses/>.\r
 *\r
+* Author: Robert Nagy, ronag89@gmail.com\r
 */\r
+\r
 #include "stdafx.h"\r
 \r
 #include "decklink.h"\r
 #include "util/util.h"\r
 \r
 #include "consumer/decklink_consumer.h"\r
+#include "consumer/blocking_decklink_consumer.h"\r
 #include "producer/decklink_producer.h"\r
 \r
+#include <core/parameters/parameters.h>\r
 #include <core/consumer/frame_consumer.h>\r
 #include <core/producer/frame_producer.h>\r
 \r
@@ -44,15 +48,31 @@ namespace caspar { namespace decklink {
 \r
 void init()\r
 {\r
-       core::register_consumer_factory([](const std::vector<std::wstring>& params){return create_consumer(params);});\r
+       struct co_init\r
+       {\r
+               co_init(){::CoInitialize(nullptr);}\r
+               ~co_init(){::CoUninitialize();}\r
+       } init;\r
+       \r
+       CComPtr<IDeckLinkIterator> pDecklinkIterator;\r
+       if(FAILED(pDecklinkIterator.CoCreateInstance(CLSID_CDeckLinkIterator)))         \r
+               return;\r
+               \r
+       core::register_consumer_factory([](const core::parameters& params){return decklink::create_consumer(params);});\r
+       core::register_consumer_factory([](const core::parameters& params){return decklink::create_blocking_consumer(params);});\r
        core::register_producer_factory(create_producer);\r
 }\r
 \r
 std::wstring get_version() \r
 {\r
        std::wstring version = L"Not found";\r
+       \r
+       struct co_init\r
+       {\r
+               co_init(){::CoInitialize(nullptr);}\r
+               ~co_init(){::CoUninitialize();}\r
+       } init;\r
 \r
-       ::CoInitialize(nullptr);\r
        try\r
        {\r
                CComPtr<IDeckLinkIterator> pDecklinkIterator;\r
@@ -60,7 +80,6 @@ std::wstring get_version()
                        version = get_version(pDecklinkIterator);\r
        }\r
        catch(...){}\r
-       ::CoUninitialize();\r
 \r
        return version;\r
 }\r
@@ -68,24 +87,29 @@ std::wstring get_version()
 std::vector<std::wstring> get_device_list()\r
 {\r
        std::vector<std::wstring> devices;\r
+       \r
+       struct co_init\r
+       {\r
+               co_init(){::CoInitialize(nullptr);}\r
+               ~co_init(){::CoUninitialize();}\r
+       } init;\r
 \r
-       ::CoInitialize(nullptr);\r
        try\r
        {\r
                CComPtr<IDeckLinkIterator> pDecklinkIterator;\r
                if(SUCCEEDED(pDecklinkIterator.CoCreateInstance(CLSID_CDeckLinkIterator)))\r
                {               \r
-                       CComPtr<IDeckLink> decklink;\r
+                       IDeckLink* decklink;\r
                        for(int n = 1; pDecklinkIterator->Next(&decklink) == S_OK; ++n) \r
                        {\r
                                BSTR model_name = L"Unknown";\r
                                decklink->GetModelName(&model_name);\r
+                               decklink->Release();\r
                                devices.push_back(std::wstring(model_name) + L" [" + boost::lexical_cast<std::wstring>(n) + L"]");      \r
                        }\r
                }\r
        }\r
        catch(...){}\r
-       ::CoUninitialize();\r
 \r
        return devices;\r
 }\r