]> git.sesse.net Git - casparcg/blob - modules/decklink/decklink.cpp
2.1.0: Fully ported (apart from legacy protocol proect) to UTF8, instead of a big...
[casparcg] / modules / decklink / decklink.cpp
1 /*\r
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>\r
3 *\r
4 * This file is part of CasparCG (www.casparcg.com).\r
5 *\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
10 *\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
15 *\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
18 *\r
19 * Author: Robert Nagy, ronag89@gmail.com\r
20 */\r
21 \r
22 #include "stdafx.h"\r
23 \r
24 #include "decklink.h"\r
25 #include "util/util.h"\r
26 \r
27 #include "consumer/decklink_consumer.h"\r
28 #include "producer/decklink_producer.h"\r
29 \r
30 #include <core/consumer/frame_consumer.h>\r
31 #include <core/producer/frame_producer.h>\r
32 \r
33 #include "interop/DeckLinkAPI_h.h"\r
34 \r
35 #pragma warning(push)\r
36 #pragma warning(disable : 4996)\r
37 \r
38         #include <atlbase.h>\r
39 \r
40         #include <atlcom.h>\r
41         #include <atlhost.h>\r
42 \r
43 #pragma warning(push)\r
44 \r
45 namespace caspar { namespace decklink {\r
46 \r
47 void init()\r
48 {\r
49         struct co_init\r
50         {\r
51                 co_init(){::CoInitialize(nullptr);}\r
52                 ~co_init(){::CoUninitialize();}\r
53         } init;\r
54         \r
55         CComPtr<IDeckLinkIterator> pDecklinkIterator;\r
56         if(FAILED(pDecklinkIterator.CoCreateInstance(CLSID_CDeckLinkIterator)))         \r
57                 return;\r
58                 \r
59         core::register_consumer_factory([](const std::vector<std::string>& params){return create_consumer(params);});\r
60         core::register_producer_factory(create_producer);\r
61 }\r
62 \r
63 std::string get_version() \r
64 {\r
65         std::string version = "Not found";\r
66         \r
67         struct co_init\r
68         {\r
69                 co_init(){::CoInitialize(nullptr);}\r
70                 ~co_init(){::CoUninitialize();}\r
71         } init;\r
72 \r
73         try\r
74         {\r
75                 CComPtr<IDeckLinkIterator> pDecklinkIterator;\r
76                 if(SUCCEEDED(pDecklinkIterator.CoCreateInstance(CLSID_CDeckLinkIterator)))              \r
77                         version = get_version(pDecklinkIterator);\r
78         }\r
79         catch(...){}\r
80 \r
81         return version;\r
82 }\r
83 \r
84 std::vector<std::string> get_device_list()\r
85 {\r
86         std::vector<std::string> devices;\r
87         \r
88         struct co_init\r
89         {\r
90                 co_init(){::CoInitialize(nullptr);}\r
91                 ~co_init(){::CoUninitialize();}\r
92         } init;\r
93 \r
94         try\r
95         {\r
96                 CComPtr<IDeckLinkIterator> pDecklinkIterator;\r
97                 if(SUCCEEDED(pDecklinkIterator.CoCreateInstance(CLSID_CDeckLinkIterator)))\r
98                 {               \r
99                         CComPtr<IDeckLink> decklink;\r
100                         for(int n = 1; pDecklinkIterator->Next(&decklink) == S_OK; ++n) \r
101                         {\r
102                                 BSTR model_name = L"Unknown";\r
103                                 decklink->GetModelName(&model_name);\r
104                                 devices.push_back(u8(model_name) + " [" + boost::lexical_cast<std::string>(n) + "]");   \r
105                         }\r
106                 }\r
107         }\r
108         catch(...){}\r
109 \r
110         return devices;\r
111 }\r
112 \r
113 }}