28#include <DeckLinkAPIVersion.h>
29#include <DeckLinkAPI.h>
30#if BLACKMAGIC_DECKLINK_API_VERSION >= 0x0e030000
31#include <DeckLinkAPI_v14_2_1.h>
35#include <DeckLinkAPI_i.c>
42#pragma clang diagnostic push
43#pragma clang diagnostic ignored "-Wmissing-prototypes"
45#include <DeckLinkAPIDispatch.cpp>
47#pragma clang diagnostic pop
63 IDeckLinkIterator *iter;
66 if (CoInitialize(
NULL) < 0) {
71 if (CoCreateInstance(CLSID_CDeckLinkIterator,
NULL, CLSCTX_ALL,
72 IID_IDeckLinkIterator, (
void**) &iter) != S_OK) {
76 iter = CreateDeckLinkIteratorInstance();
80 "Make sure you have DeckLink drivers " BLACKMAGIC_DECKLINK_API_VERSION_STRING
" or newer installed.\n");
82 IDeckLinkAPIInformation *api;
85 if (CoCreateInstance(CLSID_CDeckLinkAPIInformation,
NULL, CLSCTX_ALL,
86 IID_IDeckLinkAPIInformation, (
void**) &api) != S_OK) {
90 api = CreateDeckLinkAPIInformationInstance();
92 if (api && api->GetInt(BMDDeckLinkAPIVersion, &
version) == S_OK) {
93 if (
version < BLACKMAGIC_DECKLINK_API_VERSION)
94 av_log(avctx,
AV_LOG_WARNING,
"Installed DeckLink drivers are too old and may be incompatible with the SDK this module was built against. "
95 "Make sure you have DeckLink drivers " BLACKMAGIC_DECKLINK_API_VERSION_STRING
" or newer installed.\n");
114 hr = attr->GetString(cfg_id, &
tmp);
121 }
else if (hr == E_FAIL) {
131 BMDDeckLinkAttributeID attr_id = (cfg_id == bmdDeckLinkConfigAudioInputConnection) ? BMDDeckLinkAudioInputConnections : BMDDeckLinkVideoInputConnections;
133 const char *type_name = (cfg_id == bmdDeckLinkConfigAudioInputConnection) ?
"audio" :
"video";
134 int64_t supported_connections = 0;
138 res =
ctx->attr->GetInt(attr_id, &supported_connections);
143 if ((supported_connections & bmd_input) != bmd_input) {
144 av_log(avctx,
AV_LOG_ERROR,
"Device does not support selected %s input.\n", type_name);
147 res =
ctx->cfg->SetInt(cfg_id, bmd_input);
164 if (field_order ==
AV_FIELD_PROGRESSIVE && (bmd_field_order == bmdProgressiveFrame || bmd_field_order == bmdProgressiveSegmentedFrame))
175 if (
ctx->duplex_mode) {
178#if BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b000000
179 IDeckLinkProfileManager *manager =
NULL;
180 if (
ctx->dl->QueryInterface(IID_IDeckLinkProfileManager, (
void **)&manager) == S_OK)
181 duplex_supported =
true;
183 if (
ctx->attr->GetFlag(BMDDeckLinkSupportsDuplexModeConfiguration, &duplex_supported) != S_OK)
184 duplex_supported =
false;
187 if (duplex_supported) {
188#if BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b000000
190 BMDProfileID bmd_profile_id;
194 bmd_profile_id = decklink_profile_id_map[
ctx->duplex_mode];
195 res = manager->GetProfile(bmd_profile_id, &
profile);
202 res =
ctx->cfg->SetInt(bmdDeckLinkConfigDuplexMode,
ctx->duplex_mode == 2 ? bmdDuplexModeFull : bmdDuplexModeHalf);
207 av_log(avctx,
AV_LOG_VERBOSE,
"Successfully set duplex mode to %s duplex.\n",
ctx->duplex_mode == 2 ||
ctx->duplex_mode == 4 ?
"full" :
"half");
222 res =
ctx->cfg->SetInt(bmdDeckLinkConfigReferenceInputTimingOffset, cctx->
timing_offset);
228 res =
ctx->cfg->SetInt(bmdDeckLinkConfigSDIOutputLinkConfiguration,
ctx->link);
233 if (
ctx->link == bmdLinkConfigurationQuadLink && cctx->
sqd >= 0) {
234 res =
ctx->cfg->SetFlag(bmdDeckLinkConfigQuadLinkSDIVideoOutputSquareDivisionSplit, cctx->
sqd);
245 if (
ctx->attr->GetFlag(BMDDeckLinkSupportsSMPTELevelAOutput, &level_a_supported) != S_OK)
246 level_a_supported =
false;
248 if (level_a_supported) {
249 res =
ctx->cfg->SetFlag(bmdDeckLinkConfigSMPTELevelAOutput, cctx->
level_a);
255 av_log(avctx,
AV_LOG_WARNING,
"Unable to set SMPTE levelA mode, because it is not supported.\n");
264 int tb_num,
int tb_den,
270#if BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b000000
273 BMDDisplayModeSupport support;
275 IDeckLinkDisplayModeIterator *itermode;
276 IDeckLinkDisplayMode *
mode;
280 av_log(avctx,
AV_LOG_DEBUG,
"Trying to find mode for frame size %dx%d, frame timing %d/%d, field order %d, direction %d, format code %s\n",
284 res =
ctx->dli->GetDisplayModeIterator (&itermode);
286 res =
ctx->dlo->GetDisplayModeIterator (&itermode);
294 char format_buf[] =
" ";
297 BMDDisplayMode target_mode = (BMDDisplayMode)
AV_RB32(format_buf);
299 ctx->bmd_mode = bmdModeUnknown;
300 while ((
ctx->bmd_mode == bmdModeUnknown) && itermode->Next(&
mode) == S_OK) {
323 (
ctx->bmd_field_dominance==bmdLowerFieldFirst ||
ctx->bmd_field_dominance==bmdUpperFieldFirst)?
"(i)":
"");
332 if (
ctx->bmd_mode == bmdModeUnknown)
335#if BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b050000
337 BMDDisplayMode actualMode =
ctx->bmd_mode;
338 if (
ctx->dli->DoesSupportVideoMode(
ctx->video_input,
ctx->bmd_mode,
ctx->raw_format,
339 bmdNoVideoInputConversion, bmdSupportedVideoModeDefault,
340 &actualMode, &support) != S_OK || !support ||
ctx->bmd_mode != actualMode)
343 BMDDisplayMode actualMode =
ctx->bmd_mode;
344 if (
ctx->dlo->DoesSupportVideoMode(bmdVideoConnectionUnspecified,
ctx->bmd_mode,
ctx->raw_format,
345 bmdNoVideoOutputConversion, bmdSupportedVideoModeDefault,
346 &actualMode, &support) != S_OK || !support ||
ctx->bmd_mode != actualMode)
350#elif BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b000000
352 if (
ctx->dli->DoesSupportVideoMode(
ctx->video_input,
ctx->bmd_mode,
ctx->raw_format,
353 bmdSupportedVideoModeDefault,
357 BMDDisplayMode actualMode =
ctx->bmd_mode;
358 if (
ctx->dlo->DoesSupportVideoMode(bmdVideoConnectionUnspecified,
ctx->bmd_mode,
ctx->raw_format,
359 bmdSupportedVideoModeDefault,
360 &actualMode, &support) != S_OK || !support ||
ctx->bmd_mode != actualMode) {
369 if (
ctx->dli->DoesSupportVideoMode(
ctx->bmd_mode,
ctx->raw_format,
370 bmdVideoOutputFlagDefault,
371 &support,
NULL) != S_OK)
374 if (!
ctx->supports_vanc ||
ctx->dlo->DoesSupportVideoMode(
ctx->bmd_mode,
ctx->raw_format,
376 &support,
NULL) != S_OK || support != bmdDisplayModeSupported) {
378 if (
ctx->dlo->DoesSupportVideoMode(
ctx->bmd_mode,
ctx->raw_format,
379 bmdVideoOutputFlagDefault,
380 &support,
NULL) != S_OK) {
383 ctx->supports_vanc = 0;
387 if (support == bmdDisplayModeSupported)
429 unsigned long long size;
438 int pkt_size =
pkt->size;
510 int show_inputs,
int show_outputs)
519 while (ret == 0 && iter->Next(&
dl) == S_OK) {
522 const char *display_name =
NULL;
523 const char *unique_name =
NULL;
536 output_config->Release();
543 input_config->Release();
582 int show_inputs,
int show_outputs)
594 show_inputs ?
"input" :
"output");
606 IDeckLinkDisplayModeIterator *itermode;
607 IDeckLinkDisplayMode *
mode;
608 uint32_t format_code;
619 res =
ctx->dli->GetDisplayModeIterator (&itermode);
621 res =
ctx->dlo->GetDisplayModeIterator (&itermode);
629 av_log(avctx,
AV_LOG_INFO,
"Supported formats for '%s':\n\tformat_code\tdescription",
631 while (itermode->Next(&
mode) == S_OK) {
632 BMDTimeValue tb_num, tb_den;
633 mode->GetFrameRate(&tb_num, &tb_den);
636 (
char*) &format_code,
mode->GetWidth(),
mode->GetHeight(),
637 (
int) tb_den, (
int) tb_num);
638 switch (
mode->GetFieldDominance()) {
639 case bmdLowerFieldFirst:
641 case bmdUpperFieldFirst:
663 ctx->attr->Release();
679 while (iter->Next(&
dl) == S_OK) {
680 const char *display_name =
NULL;
681 const char *unique_name =
NULL;
684 if (display_name && !strcmp(
name, display_name) || unique_name && !strcmp(
name, unique_name)) {
698 if (
ctx->dl->QueryInterface(IID_IDeckLinkConfiguration, (
void **)&
ctx->cfg) != S_OK) {
static AVFormatContext * ctx
Main libavdevice API header.
#define i(width, name, range_min, range_max)
int ff_decklink_set_configs(AVFormatContext *avctx, decklink_direction_t direction)
int ff_decklink_list_formats(AVFormatContext *avctx, decklink_direction_t direction)
unsigned long long ff_decklink_packet_queue_size(DecklinkPacketQueue *q)
void ff_decklink_packet_queue_init(AVFormatContext *avctx, DecklinkPacketQueue *q, int64_t queue_size)
int ff_decklink_init_device(AVFormatContext *avctx, const char *name)
void ff_decklink_packet_queue_end(DecklinkPacketQueue *q)
int ff_decklink_packet_queue_get(DecklinkPacketQueue *q, AVPacket *pkt, int block)
void ff_decklink_list_devices_legacy(AVFormatContext *avctx, int show_inputs, int show_outputs)
static int decklink_get_attr_string(IDeckLink *dl, BMDDeckLinkAttributeID cfg_id, const char **s)
static DECKLINK_BOOL field_order_eq(enum AVFieldOrder field_order, BMDFieldDominance bmd_field_order)
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)
static IDeckLinkIterator * decklink_create_iterator(AVFormatContext *avctx)
int ff_decklink_list_devices(AVFormatContext *avctx, struct AVDeviceInfoList *device_list, int show_inputs, int show_outputs)
static int decklink_select_input(AVFormatContext *avctx, BMDDeckLinkConfigurationID cfg_id)
int ff_decklink_packet_queue_put(DecklinkPacketQueue *q, AVPacket *pkt)
void ff_decklink_packet_queue_flush(DecklinkPacketQueue *q)
void ff_decklink_cleanup(AVFormatContext *avctx)
int64_t ff_decklink_packet_queue_peekpts(DecklinkPacketQueue *q)
#define IID_IDeckLinkOutput_v14_2_1
#define IDeckLinkInput_v14_2_1
#define IID_IDeckLinkInput_v14_2_1
#define IID_IDeckLinkProfileAttributes
#define IDeckLinkOutput_v14_2_1
#define IDeckLinkProfileAttributes
@ AV_FIELD_TT
Top coded_first, top displayed first.
@ AV_FIELD_BB
Bottom coded first, bottom displayed first.
@ AV_FIELD_BT
Bottom coded first, top displayed first.
@ AV_FIELD_TB
Top coded first, bottom displayed first.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
int av_packet_make_refcounted(AVPacket *pkt)
Ensure the data described by a given packet is reference counted.
void avdevice_free_list_devices(AVDeviceInfoList **device_list)
Convenient function to free result of avdevice_list_devices().
#define AVERROR_EXTERNAL
Generic error in an external library.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static AVRational av_make_q(int num, int den)
Create an AVRational.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem)
Add an element to a dynamic array.
static av_always_inline int pthread_cond_signal(pthread_cond_t *cond)
static av_always_inline int pthread_mutex_lock(pthread_mutex_t *mutex)
static av_always_inline int pthread_cond_destroy(pthread_cond_t *cond)
static av_always_inline int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
static av_always_inline int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
static av_always_inline int pthread_mutex_unlock(pthread_mutex_t *mutex)
static av_always_inline int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
static av_always_inline int pthread_mutex_destroy(pthread_mutex_t *mutex)
#define FF_ARRAY_ELEMS(a)
int nb_devices
number of autodetected devices
AVDeviceInfo ** devices
list of autodetected devices
Structure describes basic parameters of the device.
char * device_description
human friendly name
char * device_name
device name, format depends on device
char * url
input or output URL.
void * priv_data
Format private data.
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Rational number (pair of numerator and denominator).