]> git.sesse.net Git - casparcg/blob - modules/decklink/decklink.cpp
* Extracted module startup from server.cpp to a generated included_modules.h.
[casparcg] / modules / decklink / decklink.cpp
1 /*
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
3 *
4 * This file is part of CasparCG (www.casparcg.com).
5 *
6 * CasparCG is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * CasparCG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * Author: Robert Nagy, ronag89@gmail.com
20 */
21
22 #include "stdafx.h"
23
24 #include "decklink.h"
25 #include "util/util.h"
26
27 #include "consumer/decklink_consumer.h"
28 #include "producer/decklink_producer.h"
29
30 #include <core/consumer/frame_consumer.h>
31 #include <core/producer/frame_producer.h>
32 #include <core/system_info_provider.h>
33
34 #include <boost/property_tree/ptree.hpp>
35
36 #include "interop/DeckLinkAPI_h.h"
37
38 #pragma warning(push)
39 #pragma warning(disable : 4996)
40
41         #include <atlbase.h>
42
43         #include <atlcom.h>
44         #include <atlhost.h>
45
46 #pragma warning(push)
47
48 namespace caspar { namespace decklink {
49
50 std::wstring version()
51 {
52         std::wstring version = L"Not found";
53
54         struct co_init
55         {
56                 co_init(){ ::CoInitialize(nullptr); }
57                 ~co_init(){ ::CoUninitialize(); }
58         } init;
59
60         try
61         {
62                 CComPtr<IDeckLinkIterator> pDecklinkIterator;
63                 if (SUCCEEDED(pDecklinkIterator.CoCreateInstance(CLSID_CDeckLinkIterator)))
64                         version = decklink::version(pDecklinkIterator);
65         }
66         catch (...){}
67
68         return version;
69 }
70
71 std::vector<std::wstring> device_list()
72 {
73         std::vector<std::wstring> devices;
74
75         struct co_init
76         {
77                 co_init(){ ::CoInitialize(nullptr); }
78                 ~co_init(){ ::CoUninitialize(); }
79         } init;
80
81         try
82         {
83                 CComPtr<IDeckLinkIterator> pDecklinkIterator;
84                 if (SUCCEEDED(pDecklinkIterator.CoCreateInstance(CLSID_CDeckLinkIterator)))
85                 {
86                         IDeckLink* decklink;
87                         for (int n = 1; pDecklinkIterator->Next(&decklink) == S_OK; ++n)
88                         {
89                                 BSTR model_name = L"Unknown";
90                                 decklink->GetModelName(&model_name);
91                                 decklink->Release();
92                                 devices.push_back(std::wstring(model_name) + L" [" + boost::lexical_cast<std::wstring>(n)+L"]");
93                         }
94                 }
95         }
96         catch (...){}
97
98         return devices;
99 }
100
101 void init(core::module_dependencies dependencies)
102 {
103         struct co_init
104         {
105                 co_init(){::CoInitialize(nullptr);}
106                 ~co_init(){::CoUninitialize();}
107         } init;
108         
109         CComPtr<IDeckLinkIterator> pDecklinkIterator;
110         if(FAILED(pDecklinkIterator.CoCreateInstance(CLSID_CDeckLinkIterator)))         
111                 return;
112                 
113         core::register_consumer_factory(create_consumer);
114         core::register_preconfigured_consumer_factory(L"decklink", create_preconfigured_consumer);
115         core::register_producer_factory(create_producer);
116         dependencies.system_info_provider_repo->register_system_info_provider([](boost::property_tree::wptree& info)
117         {
118                 info.add(L"system.decklink.version", version());
119
120                 for (auto device : device_list())
121                         info.add(L"system.decklink.device", device);
122         });
123 }
124
125 }}