]> git.sesse.net Git - casparcg/blob - modules/decklink/decklink.cpp
4252e99d28fb08706390270ab9708000158b0aa0
[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
33 #include "interop/DeckLinkAPI_h.h"
34
35 #pragma warning(push)
36 #pragma warning(disable : 4996)
37
38         #include <atlbase.h>
39
40         #include <atlcom.h>
41         #include <atlhost.h>
42
43 #pragma warning(push)
44
45 namespace caspar { namespace decklink {
46
47 void init()
48 {
49         struct co_init
50         {
51                 co_init(){::CoInitialize(nullptr);}
52                 ~co_init(){::CoUninitialize();}
53         } init;
54         
55         CComPtr<IDeckLinkIterator> pDecklinkIterator;
56         if(FAILED(pDecklinkIterator.CoCreateInstance(CLSID_CDeckLinkIterator)))         
57                 return;
58                 
59         core::register_consumer_factory([](const std::vector<std::wstring>& params){return create_consumer(params);});
60         core::register_producer_factory(create_producer);
61 }
62
63 std::wstring version() 
64 {
65         std::wstring version = L"Not found";
66         
67         struct co_init
68         {
69                 co_init(){::CoInitialize(nullptr);}
70                 ~co_init(){::CoUninitialize();}
71         } init;
72
73         try
74         {
75                 CComPtr<IDeckLinkIterator> pDecklinkIterator;
76                 if(SUCCEEDED(pDecklinkIterator.CoCreateInstance(CLSID_CDeckLinkIterator)))              
77                         version = decklink::version(pDecklinkIterator);
78         }
79         catch(...){}
80
81         return version;
82 }
83
84 std::vector<std::wstring> device_list()
85 {
86         std::vector<std::wstring> devices;
87         
88         struct co_init
89         {
90                 co_init(){::CoInitialize(nullptr);}
91                 ~co_init(){::CoUninitialize();}
92         } init;
93
94         try
95         {
96                 CComPtr<IDeckLinkIterator> pDecklinkIterator;
97                 if(SUCCEEDED(pDecklinkIterator.CoCreateInstance(CLSID_CDeckLinkIterator)))
98                 {               
99                         IDeckLink* decklink;
100                         for(int n = 1; pDecklinkIterator->Next(&decklink) == S_OK; ++n) 
101                         {
102                                 BSTR model_name = L"Unknown";
103                                 decklink->GetModelName(&model_name);
104                                 decklink->Release();
105                                 devices.push_back(std::wstring(model_name) + L" [" + boost::lexical_cast<std::wstring>(n) + L"]");      
106                         }
107                 }
108         }
109         catch(...){}
110
111         return devices;
112 }
113
114 }}