#include "decklink_common.h"
-#ifdef _WIN32
-IDeckLinkIterator *CreateDeckLinkIteratorInstance(void)
+static IDeckLinkIterator *decklink_create_iterator(AVFormatContext *avctx)
{
IDeckLinkIterator *iter;
+#ifdef _WIN32
if (CoInitialize(NULL) < 0) {
- av_log(NULL, AV_LOG_ERROR, "COM initialization failed.\n");
+ av_log(avctx, 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;
+ iter = NULL;
}
-
- return iter;
-}
+#else
+ iter = CreateDeckLinkIteratorInstance();
#endif
+ if (!iter)
+ av_log(avctx, AV_LOG_ERROR, "Could not create DeckLink iterator. "
+ "Make sure you have DeckLink drivers " BLACKMAGIC_DECKLINK_API_VERSION_STRING " or newer installed.\n");
-#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
-#define DECKLINK_FREE(s) SysFreeString(s)
-#elif defined(__APPLE__)
-static char *dup_cfstring_to_utf8(CFStringRef w)
-{
- char s[256];
- CFStringGetCString(w, s, 255, kCFStringEncodingUTF8);
- return av_strdup(s);
+ return iter;
}
-#define DECKLINK_STR const __CFString *
-#define DECKLINK_STRDUP dup_cfstring_to_utf8
-#define DECKLINK_FREE(s) CFRelease(s)
-#else
-#define DECKLINK_STR const char *
-#define DECKLINK_STRDUP av_strdup
-/* free() is needed for a string returned by the DeckLink SDL. */
-#define DECKLINK_FREE(s) free((void *) s)
-#endif
HRESULT ff_decklink_get_display_name(IDeckLink *This, const char **displayName)
{
int show_inputs, int show_outputs)
{
IDeckLink *dl = NULL;
- IDeckLinkIterator *iter = CreateDeckLinkIteratorInstance();
+ IDeckLinkIterator *iter = decklink_create_iterator(avctx);
int ret = 0;
- if (!iter) {
- av_log(avctx, AV_LOG_ERROR, "Could not create DeckLink iterator\n");
+ if (!iter)
return AVERROR(EIO);
- }
while (ret == 0 && iter->Next(&dl) == S_OK) {
IDeckLinkOutput *output_config;
struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data;
struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx;
IDeckLink *dl = NULL;
- IDeckLinkIterator *iter = CreateDeckLinkIteratorInstance();
- if (!iter) {
- av_log(avctx, AV_LOG_ERROR, "Could not create DeckLink iterator\n");
+ IDeckLinkIterator *iter = decklink_create_iterator(avctx);
+ if (!iter)
return AVERROR_EXTERNAL;
- }
while (iter->Next(&dl) == S_OK) {
const char *displayName;