-#ifdef _WIN32
-static IDeckLinkIterator *CreateDeckLinkIteratorInstance(void)
-{
- IDeckLinkIterator *iter;
-
- if (CoInitialize(NULL) != S_OK) {
- av_log(NULL, AV_LOG_ERROR, "COM initialization failed.\n");
- return NULL;
- }
-
- if (CoCreateInstance(CLSID_CDeckLinkIterator, NULL, CLSCTX_ALL,
- IID_IDeckLinkIterator, (void**) &iter) != S_OK) {
- av_log(NULL, AV_LOG_ERROR, "DeckLink drivers not installed.\n");
- return NULL;
- }
-
- return iter;
-}
-#endif
-
-/* free() is needed for a string returned by the DeckLink SDL. */
-#undef free
-
-#ifdef _WIN32
-static char *dup_wchar_to_utf8(wchar_t *w)
-{
- char *s = NULL;
- int l = WideCharToMultiByte(CP_UTF8, 0, w, -1, 0, 0, 0, 0);
- s = (char *) av_malloc(l);
- if (s)
- WideCharToMultiByte(CP_UTF8, 0, w, -1, s, l, 0, 0);
- return s;
-}
-#define DECKLINK_STR OLECHAR *
-#define DECKLINK_STRDUP dup_wchar_to_utf8
-#else
-#define DECKLINK_STR const char *
-#define DECKLINK_STRDUP av_strdup
-#endif
-
-static HRESULT IDeckLink_GetDisplayName(IDeckLink *This, const char **displayName)
-{
- DECKLINK_STR tmpDisplayName;
- HRESULT hr = This->GetDisplayName(&tmpDisplayName);
- if (hr != S_OK)
- return hr;
- *displayName = DECKLINK_STRDUP(tmpDisplayName);
- free((void *) tmpDisplayName);
- return hr;
-}
-
-static int decklink_set_format(struct decklink_ctx *ctx,
- int width, int height,
- int tb_num, int tb_den)
-{
- BMDDisplayModeSupport support;
- IDeckLinkDisplayMode *mode;
-
- if (tb_num == 1) {
- tb_num *= 1000;
- tb_den *= 1000;
- }
- ctx->bmd_mode = bmdModeUnknown;
- while ((ctx->bmd_mode == bmdModeUnknown) && ctx->itermode->Next(&mode) == S_OK) {
- BMDTimeValue bmd_tb_num, bmd_tb_den;
- int bmd_width = mode->GetWidth();
- int bmd_height = mode->GetHeight();
-
- mode->GetFrameRate(&bmd_tb_num, &bmd_tb_den);
-
- if (bmd_width == width && bmd_height == height &&
- bmd_tb_num == tb_num && bmd_tb_den == tb_den) {
- ctx->bmd_mode = mode->GetDisplayMode();
- ctx->bmd_width = bmd_width;
- ctx->bmd_height = bmd_height;
- ctx->bmd_tb_den = bmd_tb_den;
- ctx->bmd_tb_num = bmd_tb_num;
- }
-
- mode->Release();
- }
- if (ctx->bmd_mode == bmdModeUnknown)
- return -1;
- if (ctx->dlo->DoesSupportVideoMode(ctx->bmd_mode, bmdFormat8BitYUV,
- bmdVideoOutputFlagDefault,
- &support, NULL) != S_OK)
- return -1;
- if (support == bmdDisplayModeSupported)
- return 0;
-
- return -1;
-}
-