]> git.sesse.net Git - casparcg/blob - modules/decklink/decklink.cpp
[README] Updated for 2.1.0 Beta 1
[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 "decklink_api.h"
37
38 namespace caspar { namespace decklink {
39
40 std::wstring get_version()
41 {
42     std::wstring ver = L"Not found";
43
44     struct co_init init;
45
46         try
47         {
48         ver = decklink::version(create_iterator());
49         }
50         catch (...){}
51
52     return ver;
53 }
54
55 std::vector<std::wstring> device_list()
56 {
57         std::vector<std::wstring> devices;
58
59     struct co_init init;
60
61         try
62         {
63         auto pDecklinkIterator = create_iterator();
64         IDeckLink* decklink;
65         for (int n = 1; pDecklinkIterator->Next(&decklink) == S_OK; ++n)
66         {
67             String m_name;
68             bool success = SUCCEEDED(decklink->GetModelName(&m_name));
69             decklink->Release();
70             std::wstring model_name = L"Unknown";
71
72             if (success)
73                 model_name = u16(m_name);
74
75             devices.push_back(model_name + L" [" + boost::lexical_cast<std::wstring>(n)+L"]");
76         }
77         }
78         catch (...){}
79
80         return devices;
81 }
82
83 void init(core::module_dependencies dependencies)
84 {
85         dependencies.consumer_registry->register_consumer_factory(L"Decklink Consumer", create_consumer, describe_consumer);
86         dependencies.consumer_registry->register_preconfigured_consumer_factory(L"decklink", create_preconfigured_consumer);
87         dependencies.producer_registry->register_producer_factory(L"Decklink Producer", create_producer, describe_producer);
88         dependencies.system_info_provider_repo->register_system_info_provider([](boost::property_tree::wptree& info)
89         {
90                 info.add(L"system.decklink.version", get_version());
91
92                 for (auto device : device_list())
93                         info.add(L"system.decklink.device", device);
94         });
95 }
96
97 }}