22 #include <DeckLinkAPI.h>
24 #include <DeckLinkAPI_i.c>
26 #include <DeckLinkAPIDispatch.cpp>
43 IDeckLinkIterator *CreateDeckLinkIteratorInstance(
void)
45 IDeckLinkIterator *iter;
47 if (CoInitialize(
NULL) < 0) {
52 if (CoCreateInstance(CLSID_CDeckLinkIterator,
NULL, CLSCTX_ALL,
53 IID_IDeckLinkIterator, (
void**) &iter) !=
S_OK) {
66 int l = WideCharToMultiByte(CP_UTF8, 0, w, -1, 0, 0, 0, 0);
69 WideCharToMultiByte(CP_UTF8, 0, w, -1, s, l, 0, 0);
72 #define DECKLINK_STR OLECHAR *
73 #define DECKLINK_STRDUP dup_wchar_to_utf8
74 #define DECKLINK_FREE(s) SysFreeString(s)
75 #define DECKLINK_BOOL BOOL
76 #elif defined(__APPLE__)
77 static char *dup_cfstring_to_utf8(CFStringRef w)
80 CFStringGetCString(w, s, 255, kCFStringEncodingUTF8);
83 #define DECKLINK_STR const __CFString *
84 #define DECKLINK_STRDUP dup_cfstring_to_utf8
85 #define DECKLINK_FREE(s) free((void *) s)
86 #define DECKLINK_BOOL bool
88 #define DECKLINK_STR const char *
89 #define DECKLINK_STRDUP av_strdup
91 #define DECKLINK_FREE(s) free((void *) s)
92 #define DECKLINK_BOOL bool
98 HRESULT hr = This->GetDisplayName(&tmpDisplayName);
110 BMDDeckLinkAttributeID attr_id = (cfg_id == bmdDeckLinkConfigAudioInputConnection) ? BMDDeckLinkAudioInputConnections : BMDDeckLinkVideoInputConnections;
111 int64_t bmd_input = (cfg_id == bmdDeckLinkConfigAudioInputConnection) ? (int64_t)
ctx->audio_input : (int64_t)
ctx->video_input;
112 const char *type_name = (cfg_id == bmdDeckLinkConfigAudioInputConnection) ?
"audio" :
"video";
113 int64_t supported_connections = 0;
117 res =
ctx->attr->GetInt(attr_id, &supported_connections);
122 if ((supported_connections & bmd_input) != bmd_input) {
123 av_log(avctx,
AV_LOG_ERROR,
"Device does not support selected %s input.\n", type_name);
126 res =
ctx->cfg->SetInt(cfg_id, bmd_input);
143 if (field_order ==
AV_FIELD_PROGRESSIVE && (bmd_field_order == bmdProgressiveFrame || bmd_field_order == bmdProgressiveSegmentedFrame))
150 int tb_num,
int tb_den,
156 BMDDisplayModeSupport support;
157 IDeckLinkDisplayModeIterator *itermode;
158 IDeckLinkDisplayMode *
mode;
162 av_log(avctx,
AV_LOG_DEBUG,
"Trying to find mode for frame size %dx%d, frame timing %d/%d, field order %d, direction %d, mode number %d, format code %s\n",
163 width, height, tb_num, tb_den, field_order, direction, num, (cctx->
format_code) ? cctx->
format_code :
"(unset)");
165 if (
ctx->duplex_mode) {
168 if (
ctx->attr->GetFlag(BMDDeckLinkSupportsDuplexModeConfiguration, &duplex_supported) !=
S_OK)
169 duplex_supported =
false;
171 if (duplex_supported) {
172 res =
ctx->cfg->SetInt(bmdDeckLinkConfigDuplexMode,
ctx->duplex_mode == 2 ? bmdDuplexModeFull : bmdDuplexModeHalf);
176 av_log(avctx,
AV_LOG_VERBOSE,
"Successfully set duplex mode to %s duplex.\n",
ctx->duplex_mode == 2 ?
"full" :
"half");
190 res =
ctx->dli->GetDisplayModeIterator (&itermode);
192 res =
ctx->dlo->GetDisplayModeIterator (&itermode);
200 char format_buf[] =
" ";
203 BMDDisplayMode target_mode = (BMDDisplayMode)
AV_RB32(format_buf);
205 ctx->bmd_mode = bmdModeUnknown;
206 while ((
ctx->bmd_mode == bmdModeUnknown) && itermode->Next(&mode) ==
S_OK) {
207 BMDTimeValue bmd_tb_num, bmd_tb_den;
208 int bmd_width = mode->GetWidth();
209 int bmd_height = mode->GetHeight();
210 BMDDisplayMode bmd_mode = mode->GetDisplayMode();
211 BMDFieldDominance bmd_field_dominance = mode->GetFieldDominance();
213 mode->GetFrameRate(&bmd_tb_num, &bmd_tb_den);
216 if ((bmd_width == width &&
217 bmd_height == height &&
221 || target_mode == bmd_mode) {
222 ctx->bmd_mode = bmd_mode;
223 ctx->bmd_width = bmd_width;
224 ctx->bmd_height = bmd_height;
225 ctx->bmd_tb_den = bmd_tb_den;
226 ctx->bmd_tb_num = bmd_tb_num;
227 ctx->bmd_field_dominance = bmd_field_dominance;
229 bmd_width, bmd_height, 1/
av_q2d(mode_tb),
230 (
ctx->bmd_field_dominance==bmdLowerFieldFirst ||
ctx->bmd_field_dominance==bmdUpperFieldFirst)?
"(i)":
"");
239 if (
ctx->bmd_mode == bmdModeUnknown)
242 if (
ctx->dli->DoesSupportVideoMode(
ctx->bmd_mode, bmdFormat8BitYUV,
243 bmdVideoOutputFlagDefault,
247 if (
ctx->dlo->DoesSupportVideoMode(
ctx->bmd_mode, bmdFormat8BitYUV,
248 bmdVideoOutputFlagDefault,
252 if (support == bmdDisplayModeSupported)
264 IDeckLink *dl =
NULL;
265 IDeckLinkIterator *iter = CreateDeckLinkIteratorInstance();
271 while (iter->Next(&dl) ==
S_OK) {
272 const char *displayName;
286 IDeckLinkDisplayModeIterator *itermode;
287 IDeckLinkDisplayMode *
mode;
299 res =
ctx->dli->GetDisplayModeIterator (&itermode);
301 res =
ctx->dlo->GetDisplayModeIterator (&itermode);
309 av_log(avctx,
AV_LOG_INFO,
"Supported formats for '%s':\n\tformat_code\tdescription",
311 while (itermode->Next(&mode) ==
S_OK) {
312 BMDTimeValue tb_num, tb_den;
313 mode->GetFrameRate(&tb_num, &tb_den);
314 format_code =
av_bswap32(mode->GetDisplayMode());
316 (
char*) &format_code, mode->GetWidth(), mode->GetHeight(),
317 (
int) tb_den, (
int) tb_num);
318 switch (mode->GetFieldDominance()) {
319 case bmdLowerFieldFirst:
321 case bmdUpperFieldFirst:
343 ctx->attr->Release();
354 IDeckLink *dl =
NULL;
355 IDeckLinkIterator *iter = CreateDeckLinkIteratorInstance();
361 while (iter->Next(&dl) ==
S_OK) {
362 const char *displayName;
364 if (!strcmp(name, displayName)) {
376 if (
ctx->dl->QueryInterface(IID_IDeckLinkConfiguration, (
void **)&
ctx->cfg) !=
S_OK) {
377 av_log(avctx,
AV_LOG_ERROR,
"Could not get configuration interface for '%s'\n", name);
382 if (
ctx->dl->QueryInterface(IID_IDeckLinkAttributes, (
void **)&
ctx->attr) !=
S_OK) {
#define AV_LOG_WARNING
Something somehow does not look correct.
int ff_decklink_init_device(AVFormatContext *avctx, const char *name)
static DECKLINK_BOOL field_order_eq(enum AVFieldOrder field_order, BMDFieldDominance bmd_field_order)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
int ff_decklink_set_format(AVFormatContext *avctx, int width, int height, int tb_num, int tb_den, enum AVFieldOrder field_order, decklink_direction_t direction, int num)
static double av_q2d(AVRational a)
Convert an AVRational to a double.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static char * dup_wchar_to_utf8(wchar_t *w)
char filename[1024]
input or output filename
int ff_decklink_list_formats(AVFormatContext *avctx, decklink_direction_t direction)
#define AV_LOG_INFO
Standard information.
char * av_strdup(const char *s)
Duplicate a string.
int ff_decklink_list_devices(AVFormatContext *avctx)
static AVRational av_make_q(int num, int den)
Create an AVRational.
static int decklink_select_input(AVFormatContext *avctx, BMDDeckLinkConfigurationID cfg_id)
HRESULT ff_decklink_get_display_name(IDeckLink *This, const char **displayName)
Rational number (pair of numerator and denominator).
void ff_decklink_cleanup(AVFormatContext *avctx)
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
void * priv_data
Format private data.
#define AVERROR_EXTERNAL
Generic error in an external library.
mode
Use these values in ebur128_init (or'ed).