UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
blackmagic_common.hpp
Go to the documentation of this file.
1
5/*
6 * Copyright (c) 2014-2023 CESNET, z. s. p. o.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, is permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * 3. Neither the name of CESNET nor the names of its contributors may be
21 * used to endorse or promote products derived from this software without
22 * specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
26 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
27 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
28 * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
34 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
35 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#ifndef BLACKMAGIC_COMMON_HPP
39#define BLACKMAGIC_COMMON_HPP
40
41#ifdef _WIN32
42#include <winsock2.h> // needs to be included prior to windows.h which will be
43 // included by foolowing include; wsock2.h needed for
44 // htonl used by vcap/vdisp
45#include "DeckLinkAPI_h.h" /* From DeckLink SDK */
46#else
47#include "DeckLinkAPI.h" /* From DeckLink SDK */
48#endif
49
50#include <cctype>
51#include <cstdbool>
52#include <cstdint>
53#include <map>
54#include <memory>
55#include <tuple>
56#include <vector>
57#include <string>
58#include <type_traits>
59#include <utility>
60
61#include "utils/macros.h"
62#include "video.h"
63
64std::string bmd_hresult_to_string(HRESULT res);
65
66// Order of codecs is important because it is used as a preference list (upper
67// codecs are favored) returned by DISPLAY_PROPERTY_CODECS property (display)
68static std::vector<std::pair<codec_t, BMDPixelFormat>> uv_to_bmd_codec_map = {
69 { R12L, bmdFormat12BitRGBLE },
70 { R10k, bmdFormat10BitRGBX },
71 { v210, bmdFormat10BitYUV },
72 { RGBA, bmdFormat8BitBGRA },
73 { UYVY, bmdFormat8BitYUV },
74};
75
76#ifdef _WIN32
77#define BMD_BOOL BOOL
78#define BMD_TRUE TRUE
79#define BMD_FALSE FALSE
80#else
81#define BMD_BOOL bool
82#define BMD_TRUE true
83#define BMD_FALSE false
84#endif
85
86enum {
88};
89
90struct bmd_option {
91private:
93 union {
94 bool b;
95 int64_t i;
96 double f;
97 char s[128];
98 } m_val{};
99 bool m_user_specified = true;
100 friend std::ostream &operator<<(std::ostream &output, const bmd_option &b);
101public:
102 bmd_option() = default;
103 explicit bmd_option(int64_t val, bool user_spec = true);
104 explicit bmd_option(bool val, bool user_spec = true);
105 bool is_default() const;
106 [[nodiscard]] bool is_help() const;
107 bool is_user_set() const;
108 void set_keep();
109 bool keep() const;
110 bool get_flag() const;
111 int64_t get_int() const;
112 [[nodiscard]] const char *get_string() const;
113 void parse(const char *);
114 void set_flag(bool val_);
115 void set_int(int64_t val_);
116 void set_float(double val_);
117 void set_string(const char *val_);
118 bool device_write(IDeckLinkConfiguration *deckLinkConfiguration, BMDDeckLinkConfigurationID opt, std::string const &log_prefix = "[DeckLink] ") const;
119};
120
121std::ostream &operator<<(std::ostream &output, const bmd_option &b);
122
123#ifdef __APPLE__
124#define BMD_STR CFStringRef
125#elif defined _WIN32
126#define BMD_STR BSTR
127#else
128#define BMD_STR const char *
129#endif
131BMD_STR get_bmd_api_str_from_cstr(const char *cstr);
132void release_bmd_api_str(BMD_STR string);
133#ifdef __cplusplus
134#include <string>
135std::string get_str_from_bmd_api_str(BMD_STR string);
136std::string bmd_get_flags_str(BMDDisplayModeFlags flags);
137#endif
138
139IDeckLinkIterator *create_decklink_iterator(bool *com_initialized, bool verbose = true);
141void decklink_uninitialize(bool *com_initialized);
143void print_decklink_version(void);
144
145bool bmd_check_stereo_profile(IDeckLink *deckLink);
146bool decklink_set_profile(IDeckLink *deckLink, bmd_option const &req_profile, bool stereo);
147std::string bmd_get_device_name(IDeckLink *decklink);
148std::string bmd_get_audio_connection_name(BMDAudioOutputAnalogAESSwitch audioConnection);
149uint32_t bmd_read_fourcc(const char *);
150void r10k_limited_to_full(const char *in, char *out, size_t len);
151void r10k_full_to_limited(const char *in, char *out, size_t len);
152void print_bmd_device_profiles(const char *line_prefix);
153const std::map<BMDVideoConnection, std::string> &get_connection_string_map();
154
155std::ostream &operator<<(std::ostream &output, REFIID iid);
156
157#define BMD_CHECK(cmd, name, action) \
158 do {\
159 HRESULT result = cmd;\
160 if (FAILED(result)) {;\
161 LOG(LOG_LEVEL_ERROR) << MOD_NAME << name << ": " << bmd_hresult_to_string(result) << "\n";\
162 action;\
163 }\
164 } while (0)
165
166
167#define R10K_FULL_OPT "bmd-r10k-full-range"
168#define BMD_NAT_SORT "bmd-sort-natural"
169
170template <typename T>
171bool decklink_supports_codec(T *deckLink, BMDPixelFormat pf);
172extern template bool
173decklink_supports_codec<IDeckLinkOutput>(IDeckLinkOutput *deckLink,
174 BMDPixelFormat pf);
175extern template bool
176decklink_supports_codec<IDeckLinkInput>(IDeckLinkInput *deckLink,
177 BMDPixelFormat pf);
178bool bmd_parse_audio_levels(const char *opt) noexcept(false);
179void print_bmd_attribute(IDeckLinkProfileAttributes *deckLinkAttributes,
180 const char *query_prop_fcc);
181
189using bmd_dev = std::tuple<std::unique_ptr<IDeckLink, void (*)(IDeckLink *)>,
190 unsigned, int, char>;
191std::vector<bmd_dev> bmd_get_sorted_devices(bool *com_initialized,
192 bool verbose = true,
193 bool natural_sort = false);
194
195#endif // defined BLACKMAGIC_COMMON_HPP
196
int void * val
int void size_t * len
const char unsigned int flags
std::string bmd_get_audio_connection_name(BMDAudioOutputAnalogAESSwitch audioConnection)
bool bmd_parse_audio_levels(const char *opt) noexcept(false)
TOREMOVE (implicit "aacl" option is preferred)
BMD_STR get_bmd_api_str_from_cstr(const char *cstr)
template bool decklink_supports_codec< IDeckLinkOutput >(IDeckLinkOutput *deckLink, BMDPixelFormat pf)
bool blackmagic_api_version_check()
@ BMD_MAX_AUD_CH
IDeckLinkIterator * create_decklink_iterator(bool *com_initialized, bool verbose=true)
#define BMD_STR
const std::map< BMDVideoConnection, std::string > & get_connection_string_map()
void print_bmd_device_profiles(const char *line_prefix)
std::ostream & operator<<(std::ostream &output, const bmd_option &b)
std::string bmd_hresult_to_string(HRESULT res)
static std::vector< std::pair< codec_t, BMDPixelFormat > > uv_to_bmd_codec_map
void release_bmd_api_str(BMD_STR string)
void print_bmd_attribute(IDeckLinkProfileAttributes *deckLinkAttributes, const char *query_prop_fcc)
std::tuple< std::unique_ptr< IDeckLink, void(*)(IDeckLink *)>, unsigned, int, char > bmd_dev
std::string bmd_get_device_name(IDeckLink *decklink)
void print_decklink_version(void)
std::vector< bmd_dev > bmd_get_sorted_devices(bool *com_initialized, bool verbose=true, bool natural_sort=false)
void decklink_uninitialize(bool *com_initialized)
bool decklink_set_profile(IDeckLink *deckLink, bmd_option const &req_profile, bool stereo)
std::string get_str_from_bmd_api_str(BMD_STR string)
void r10k_full_to_limited(const char *in, char *out, size_t len)
bool bmd_check_stereo_profile(IDeckLink *deckLink)
template bool decklink_supports_codec< IDeckLinkInput >(IDeckLinkInput *deckLink, BMDPixelFormat pf)
char * get_cstr_from_bmd_api_str(BMD_STR string)
std::string bmd_get_flags_str(BMDDisplayModeFlags flags)
bool decklink_supports_codec(T *deckLink, BMDPixelFormat pf)
uint32_t bmd_read_fourcc(const char *)
void r10k_limited_to_full(const char *in, char *out, size_t len)
int64_t get_int() const
bmd_option()=default
const char * get_string() const
bool is_user_set() const
void set_string(const char *val_)
enum bmd_option::type_tag m_type
bool m_user_specified
ignore errors if set to false
void set_int(int64_t val_)
friend std::ostream & operator<<(std::ostream &output, const bmd_option &b)
void parse(const char *)
bool keep() const
bool is_help() const
bool get_flag() const
bool is_default() const
bool device_write(IDeckLinkConfiguration *deckLinkConfiguration, BMDDeckLinkConfigurationID opt, std::string const &log_prefix="[DeckLink] ") const
void set_flag(bool val_)
union bmd_option::@11 m_val
void set_float(double val_)
@ R10k
RGB 10-bit packed - RGBX, big-endian (2 bit padding)
Definition types.h:73
@ UYVY
YCbCr 422 8-bit - Cb Y0 Cr Y1.
Definition types.h:71
@ R12L
RGB 12-bit packed, little-endian.
Definition types.h:74
@ RGBA
RGBA 8-bit, big-endian.
Definition types.h:70
@ v210
YCbCr 422 10-bit - xVY0U|xY2UY1|xUY3V|xY5VY4, little-endian (2 bit padding /'x'/),...
Definition types.h:75
This is an umbrella header for video functions.