decklink_common.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. /*
  2. * Blackmagic DeckLink output
  3. * Copyright (c) 2013-2014 Ramiro Polla, Luca Barbato, Deti Fliegl
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /* Include internal.h first to avoid conflict between winsock.h (used by
  22. * DeckLink headers) and winsock2.h (used by libavformat) in MSVC++ builds */
  23. extern "C" {
  24. #include "libavformat/internal.h"
  25. }
  26. #include <DeckLinkAPI.h>
  27. #ifdef _WIN32
  28. #include <DeckLinkAPI_i.c>
  29. #else
  30. /* The file provided by the SDK is known to be missing prototypes, which doesn't
  31. cause issues with GCC since the warning doesn't apply to C++ files. However
  32. Clang does complain (and warnings are treated as errors), so suppress the
  33. warning just for this one file */
  34. #ifdef __clang__
  35. #pragma clang diagnostic push
  36. #pragma clang diagnostic ignored "-Wmissing-prototypes"
  37. #endif
  38. #include <DeckLinkAPIDispatch.cpp>
  39. #ifdef __clang__
  40. #pragma clang diagnostic pop
  41. #endif
  42. #endif
  43. extern "C" {
  44. #include "libavformat/avformat.h"
  45. #include "libavutil/imgutils.h"
  46. #include "libavutil/intreadwrite.h"
  47. #include "libavutil/bswap.h"
  48. #include "avdevice.h"
  49. }
  50. #include "decklink_common.h"
  51. static IDeckLinkIterator *decklink_create_iterator(AVFormatContext *avctx)
  52. {
  53. IDeckLinkIterator *iter;
  54. #ifdef _WIN32
  55. if (CoInitialize(NULL) < 0) {
  56. av_log(avctx, AV_LOG_ERROR, "COM initialization failed.\n");
  57. return NULL;
  58. }
  59. if (CoCreateInstance(CLSID_CDeckLinkIterator, NULL, CLSCTX_ALL,
  60. IID_IDeckLinkIterator, (void**) &iter) != S_OK) {
  61. iter = NULL;
  62. }
  63. #else
  64. iter = CreateDeckLinkIteratorInstance();
  65. #endif
  66. if (!iter)
  67. av_log(avctx, AV_LOG_ERROR, "Could not create DeckLink iterator. "
  68. "Make sure you have DeckLink drivers " BLACKMAGIC_DECKLINK_API_VERSION_STRING " or newer installed.\n");
  69. return iter;
  70. }
  71. static int decklink_get_attr_string(IDeckLink *dl, BMDDeckLinkAttributeID cfg_id, const char **s)
  72. {
  73. DECKLINK_STR tmp;
  74. HRESULT hr;
  75. IDeckLinkProfileAttributes *attr;
  76. *s = NULL;
  77. if (dl->QueryInterface(IID_IDeckLinkProfileAttributes, (void **)&attr) != S_OK)
  78. return AVERROR_EXTERNAL;
  79. hr = attr->GetString(cfg_id, &tmp);
  80. attr->Release();
  81. if (hr == S_OK) {
  82. *s = DECKLINK_STRDUP(tmp);
  83. DECKLINK_FREE(tmp);
  84. if (!*s)
  85. return AVERROR(ENOMEM);
  86. } else if (hr == E_FAIL) {
  87. return AVERROR_EXTERNAL;
  88. }
  89. return 0;
  90. }
  91. static int decklink_select_input(AVFormatContext *avctx, BMDDeckLinkConfigurationID cfg_id)
  92. {
  93. struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data;
  94. struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx;
  95. BMDDeckLinkAttributeID attr_id = (cfg_id == bmdDeckLinkConfigAudioInputConnection) ? BMDDeckLinkAudioInputConnections : BMDDeckLinkVideoInputConnections;
  96. int64_t bmd_input = (cfg_id == bmdDeckLinkConfigAudioInputConnection) ? (int64_t)ctx->audio_input : (int64_t)ctx->video_input;
  97. const char *type_name = (cfg_id == bmdDeckLinkConfigAudioInputConnection) ? "audio" : "video";
  98. int64_t supported_connections = 0;
  99. HRESULT res;
  100. if (bmd_input) {
  101. res = ctx->attr->GetInt(attr_id, &supported_connections);
  102. if (res != S_OK) {
  103. av_log(avctx, AV_LOG_ERROR, "Failed to query supported %s inputs.\n", type_name);
  104. return AVERROR_EXTERNAL;
  105. }
  106. if ((supported_connections & bmd_input) != bmd_input) {
  107. av_log(avctx, AV_LOG_ERROR, "Device does not support selected %s input.\n", type_name);
  108. return AVERROR(ENOSYS);
  109. }
  110. res = ctx->cfg->SetInt(cfg_id, bmd_input);
  111. if (res != S_OK) {
  112. av_log(avctx, AV_LOG_ERROR, "Failed to select %s input.\n", type_name);
  113. return AVERROR_EXTERNAL;
  114. }
  115. }
  116. return 0;
  117. }
  118. static DECKLINK_BOOL field_order_eq(enum AVFieldOrder field_order, BMDFieldDominance bmd_field_order)
  119. {
  120. if (field_order == AV_FIELD_UNKNOWN)
  121. return true;
  122. if ((field_order == AV_FIELD_TT || field_order == AV_FIELD_TB) && bmd_field_order == bmdUpperFieldFirst)
  123. return true;
  124. if ((field_order == AV_FIELD_BB || field_order == AV_FIELD_BT) && bmd_field_order == bmdLowerFieldFirst)
  125. return true;
  126. if (field_order == AV_FIELD_PROGRESSIVE && (bmd_field_order == bmdProgressiveFrame || bmd_field_order == bmdProgressiveSegmentedFrame))
  127. return true;
  128. return false;
  129. }
  130. int ff_decklink_set_configs(AVFormatContext *avctx,
  131. decklink_direction_t direction) {
  132. struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data;
  133. struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx;
  134. HRESULT res;
  135. if (ctx->duplex_mode) {
  136. DECKLINK_BOOL duplex_supported = false;
  137. #if BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b000000
  138. IDeckLinkProfileManager *manager = NULL;
  139. if (ctx->dl->QueryInterface(IID_IDeckLinkProfileManager, (void **)&manager) == S_OK)
  140. duplex_supported = true;
  141. #else
  142. if (ctx->attr->GetFlag(BMDDeckLinkSupportsDuplexModeConfiguration, &duplex_supported) != S_OK)
  143. duplex_supported = false;
  144. #endif
  145. if (duplex_supported) {
  146. #if BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b000000
  147. IDeckLinkProfile *profile = NULL;
  148. BMDProfileID bmd_profile_id = ctx->duplex_mode == 2 ? bmdProfileOneSubDeviceFullDuplex : bmdProfileTwoSubDevicesHalfDuplex;
  149. res = manager->GetProfile(bmd_profile_id, &profile);
  150. if (res == S_OK) {
  151. res = profile->SetActive();
  152. profile->Release();
  153. }
  154. manager->Release();
  155. #else
  156. res = ctx->cfg->SetInt(bmdDeckLinkConfigDuplexMode, ctx->duplex_mode == 2 ? bmdDuplexModeFull : bmdDuplexModeHalf);
  157. #endif
  158. if (res != S_OK)
  159. av_log(avctx, AV_LOG_WARNING, "Setting duplex mode failed.\n");
  160. else
  161. av_log(avctx, AV_LOG_VERBOSE, "Successfully set duplex mode to %s duplex.\n", ctx->duplex_mode == 2 ? "full" : "half");
  162. } else {
  163. av_log(avctx, AV_LOG_WARNING, "Unable to set duplex mode, because it is not supported.\n");
  164. }
  165. }
  166. if (direction == DIRECTION_IN) {
  167. int ret;
  168. ret = decklink_select_input(avctx, bmdDeckLinkConfigAudioInputConnection);
  169. if (ret < 0)
  170. return ret;
  171. ret = decklink_select_input(avctx, bmdDeckLinkConfigVideoInputConnection);
  172. if (ret < 0)
  173. return ret;
  174. }
  175. if (direction == DIRECTION_OUT && cctx->timing_offset != INT_MIN) {
  176. res = ctx->cfg->SetInt(bmdDeckLinkConfigReferenceInputTimingOffset, cctx->timing_offset);
  177. if (res != S_OK)
  178. av_log(avctx, AV_LOG_WARNING, "Setting timing offset failed.\n");
  179. }
  180. return 0;
  181. }
  182. int ff_decklink_set_format(AVFormatContext *avctx,
  183. int width, int height,
  184. int tb_num, int tb_den,
  185. enum AVFieldOrder field_order,
  186. decklink_direction_t direction)
  187. {
  188. struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data;
  189. struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx;
  190. #if BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b000000
  191. DECKLINK_BOOL support;
  192. #else
  193. BMDDisplayModeSupport support;
  194. #endif
  195. IDeckLinkDisplayModeIterator *itermode;
  196. IDeckLinkDisplayMode *mode;
  197. int i = 1;
  198. HRESULT res;
  199. 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",
  200. width, height, tb_num, tb_den, field_order, direction, cctx->format_code ? cctx->format_code : "(unset)");
  201. if (direction == DIRECTION_IN) {
  202. res = ctx->dli->GetDisplayModeIterator (&itermode);
  203. } else {
  204. res = ctx->dlo->GetDisplayModeIterator (&itermode);
  205. }
  206. if (res!= S_OK) {
  207. av_log(avctx, AV_LOG_ERROR, "Could not get Display Mode Iterator\n");
  208. return AVERROR(EIO);
  209. }
  210. char format_buf[] = " ";
  211. if (cctx->format_code)
  212. memcpy(format_buf, cctx->format_code, FFMIN(strlen(cctx->format_code), sizeof(format_buf)));
  213. BMDDisplayMode target_mode = (BMDDisplayMode)AV_RB32(format_buf);
  214. AVRational target_tb = av_make_q(tb_num, tb_den);
  215. ctx->bmd_mode = bmdModeUnknown;
  216. while ((ctx->bmd_mode == bmdModeUnknown) && itermode->Next(&mode) == S_OK) {
  217. BMDTimeValue bmd_tb_num, bmd_tb_den;
  218. int bmd_width = mode->GetWidth();
  219. int bmd_height = mode->GetHeight();
  220. BMDDisplayMode bmd_mode = mode->GetDisplayMode();
  221. BMDFieldDominance bmd_field_dominance = mode->GetFieldDominance();
  222. mode->GetFrameRate(&bmd_tb_num, &bmd_tb_den);
  223. AVRational mode_tb = av_make_q(bmd_tb_num, bmd_tb_den);
  224. if ((bmd_width == width &&
  225. bmd_height == height &&
  226. !av_cmp_q(mode_tb, target_tb) &&
  227. field_order_eq(field_order, bmd_field_dominance))
  228. || target_mode == bmd_mode) {
  229. ctx->bmd_mode = bmd_mode;
  230. ctx->bmd_width = bmd_width;
  231. ctx->bmd_height = bmd_height;
  232. ctx->bmd_tb_den = bmd_tb_den;
  233. ctx->bmd_tb_num = bmd_tb_num;
  234. ctx->bmd_field_dominance = bmd_field_dominance;
  235. av_log(avctx, AV_LOG_INFO, "Found Decklink mode %d x %d with rate %.2f%s\n",
  236. bmd_width, bmd_height, 1/av_q2d(mode_tb),
  237. (ctx->bmd_field_dominance==bmdLowerFieldFirst || ctx->bmd_field_dominance==bmdUpperFieldFirst)?"(i)":"");
  238. }
  239. mode->Release();
  240. i++;
  241. }
  242. itermode->Release();
  243. if (ctx->bmd_mode == bmdModeUnknown)
  244. return -1;
  245. #if BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b050000
  246. if (direction == DIRECTION_IN) {
  247. BMDDisplayMode actualMode = ctx->bmd_mode;
  248. if (ctx->dli->DoesSupportVideoMode(ctx->video_input, ctx->bmd_mode, (BMDPixelFormat) cctx->raw_format,
  249. bmdNoVideoInputConversion, bmdSupportedVideoModeDefault,
  250. &actualMode, &support) != S_OK || !support || ctx->bmd_mode != actualMode)
  251. return -1;
  252. } else {
  253. BMDDisplayMode actualMode = ctx->bmd_mode;
  254. if (ctx->dlo->DoesSupportVideoMode(bmdVideoConnectionUnspecified, ctx->bmd_mode, ctx->raw_format,
  255. bmdNoVideoOutputConversion, bmdSupportedVideoModeDefault,
  256. &actualMode, &support) != S_OK || !support || ctx->bmd_mode != actualMode)
  257. return -1;
  258. }
  259. return 0;
  260. #elif BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b000000
  261. if (direction == DIRECTION_IN) {
  262. if (ctx->dli->DoesSupportVideoMode(ctx->video_input, ctx->bmd_mode, (BMDPixelFormat) cctx->raw_format,
  263. bmdSupportedVideoModeDefault,
  264. &support) != S_OK)
  265. return -1;
  266. } else {
  267. BMDDisplayMode actualMode = ctx->bmd_mode;
  268. if (ctx->dlo->DoesSupportVideoMode(bmdVideoConnectionUnspecified, ctx->bmd_mode, ctx->raw_format,
  269. bmdSupportedVideoModeDefault,
  270. &actualMode, &support) != S_OK || !support || ctx->bmd_mode != actualMode) {
  271. return -1;
  272. }
  273. }
  274. if (support)
  275. return 0;
  276. #else
  277. if (direction == DIRECTION_IN) {
  278. if (ctx->dli->DoesSupportVideoMode(ctx->bmd_mode, (BMDPixelFormat) cctx->raw_format,
  279. bmdVideoOutputFlagDefault,
  280. &support, NULL) != S_OK)
  281. return -1;
  282. } else {
  283. if (!ctx->supports_vanc || ctx->dlo->DoesSupportVideoMode(ctx->bmd_mode, ctx->raw_format,
  284. bmdVideoOutputVANC,
  285. &support, NULL) != S_OK || support != bmdDisplayModeSupported) {
  286. /* Try without VANC enabled */
  287. if (ctx->dlo->DoesSupportVideoMode(ctx->bmd_mode, ctx->raw_format,
  288. bmdVideoOutputFlagDefault,
  289. &support, NULL) != S_OK) {
  290. return -1;
  291. }
  292. ctx->supports_vanc = 0;
  293. }
  294. }
  295. if (support == bmdDisplayModeSupported)
  296. return 0;
  297. #endif
  298. return -1;
  299. }
  300. int ff_decklink_set_format(AVFormatContext *avctx, decklink_direction_t direction) {
  301. return ff_decklink_set_format(avctx, 0, 0, 0, 0, AV_FIELD_UNKNOWN, direction);
  302. }
  303. int ff_decklink_list_devices(AVFormatContext *avctx,
  304. struct AVDeviceInfoList *device_list,
  305. int show_inputs, int show_outputs)
  306. {
  307. IDeckLink *dl = NULL;
  308. IDeckLinkIterator *iter = decklink_create_iterator(avctx);
  309. int ret = 0;
  310. if (!iter)
  311. return AVERROR(EIO);
  312. while (ret == 0 && iter->Next(&dl) == S_OK) {
  313. IDeckLinkOutput *output_config;
  314. IDeckLinkInput *input_config;
  315. const char *display_name = NULL;
  316. const char *unique_name = NULL;
  317. AVDeviceInfo *new_device = NULL;
  318. int add = 0;
  319. ret = decklink_get_attr_string(dl, BMDDeckLinkDisplayName, &display_name);
  320. if (ret < 0)
  321. goto next;
  322. ret = decklink_get_attr_string(dl, BMDDeckLinkDeviceHandle, &unique_name);
  323. if (ret < 0)
  324. goto next;
  325. if (show_outputs) {
  326. if (dl->QueryInterface(IID_IDeckLinkOutput, (void **)&output_config) == S_OK) {
  327. output_config->Release();
  328. add = 1;
  329. }
  330. }
  331. if (show_inputs) {
  332. if (dl->QueryInterface(IID_IDeckLinkInput, (void **)&input_config) == S_OK) {
  333. input_config->Release();
  334. add = 1;
  335. }
  336. }
  337. if (add == 1) {
  338. new_device = (AVDeviceInfo *) av_mallocz(sizeof(AVDeviceInfo));
  339. if (!new_device) {
  340. ret = AVERROR(ENOMEM);
  341. goto next;
  342. }
  343. new_device->device_name = av_strdup(unique_name ? unique_name : display_name);
  344. new_device->device_description = av_strdup(display_name);
  345. if (!new_device->device_name ||
  346. !new_device->device_description ||
  347. av_dynarray_add_nofree(&device_list->devices, &device_list->nb_devices, new_device) < 0) {
  348. ret = AVERROR(ENOMEM);
  349. av_freep(&new_device->device_name);
  350. av_freep(&new_device->device_description);
  351. av_freep(&new_device);
  352. goto next;
  353. }
  354. }
  355. next:
  356. av_freep(&display_name);
  357. av_freep(&unique_name);
  358. dl->Release();
  359. }
  360. iter->Release();
  361. return ret;
  362. }
  363. /* This is a wrapper around the ff_decklink_list_devices() which dumps the
  364. output to av_log() and exits (for backward compatibility with the
  365. "-list_devices" argument). */
  366. void ff_decklink_list_devices_legacy(AVFormatContext *avctx,
  367. int show_inputs, int show_outputs)
  368. {
  369. struct AVDeviceInfoList *device_list = NULL;
  370. int ret;
  371. device_list = (struct AVDeviceInfoList *) av_mallocz(sizeof(AVDeviceInfoList));
  372. if (!device_list)
  373. return;
  374. ret = ff_decklink_list_devices(avctx, device_list, show_inputs, show_outputs);
  375. if (ret == 0) {
  376. av_log(avctx, AV_LOG_INFO, "Blackmagic DeckLink %s devices:\n",
  377. show_inputs ? "input" : "output");
  378. for (int i = 0; i < device_list->nb_devices; i++) {
  379. av_log(avctx, AV_LOG_INFO, "\t'%s'\n", device_list->devices[i]->device_description);
  380. }
  381. }
  382. avdevice_free_list_devices(&device_list);
  383. }
  384. int ff_decklink_list_formats(AVFormatContext *avctx, decklink_direction_t direction)
  385. {
  386. struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data;
  387. struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx;
  388. IDeckLinkDisplayModeIterator *itermode;
  389. IDeckLinkDisplayMode *mode;
  390. uint32_t format_code;
  391. HRESULT res;
  392. if (direction == DIRECTION_IN) {
  393. int ret;
  394. ret = decklink_select_input(avctx, bmdDeckLinkConfigAudioInputConnection);
  395. if (ret < 0)
  396. return ret;
  397. ret = decklink_select_input(avctx, bmdDeckLinkConfigVideoInputConnection);
  398. if (ret < 0)
  399. return ret;
  400. res = ctx->dli->GetDisplayModeIterator (&itermode);
  401. } else {
  402. res = ctx->dlo->GetDisplayModeIterator (&itermode);
  403. }
  404. if (res!= S_OK) {
  405. av_log(avctx, AV_LOG_ERROR, "Could not get Display Mode Iterator\n");
  406. return AVERROR(EIO);
  407. }
  408. av_log(avctx, AV_LOG_INFO, "Supported formats for '%s':\n\tformat_code\tdescription",
  409. avctx->url);
  410. while (itermode->Next(&mode) == S_OK) {
  411. BMDTimeValue tb_num, tb_den;
  412. mode->GetFrameRate(&tb_num, &tb_den);
  413. format_code = av_bswap32(mode->GetDisplayMode());
  414. av_log(avctx, AV_LOG_INFO, "\n\t%.4s\t\t%ldx%ld at %d/%d fps",
  415. (char*) &format_code, mode->GetWidth(), mode->GetHeight(),
  416. (int) tb_den, (int) tb_num);
  417. switch (mode->GetFieldDominance()) {
  418. case bmdLowerFieldFirst:
  419. av_log(avctx, AV_LOG_INFO, " (interlaced, lower field first)"); break;
  420. case bmdUpperFieldFirst:
  421. av_log(avctx, AV_LOG_INFO, " (interlaced, upper field first)"); break;
  422. }
  423. mode->Release();
  424. }
  425. av_log(avctx, AV_LOG_INFO, "\n");
  426. itermode->Release();
  427. return 0;
  428. }
  429. void ff_decklink_cleanup(AVFormatContext *avctx)
  430. {
  431. struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data;
  432. struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx;
  433. if (ctx->dli)
  434. ctx->dli->Release();
  435. if (ctx->dlo)
  436. ctx->dlo->Release();
  437. if (ctx->attr)
  438. ctx->attr->Release();
  439. if (ctx->cfg)
  440. ctx->cfg->Release();
  441. if (ctx->dl)
  442. ctx->dl->Release();
  443. }
  444. int ff_decklink_init_device(AVFormatContext *avctx, const char* name)
  445. {
  446. struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data;
  447. struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx;
  448. IDeckLink *dl = NULL;
  449. IDeckLinkIterator *iter = decklink_create_iterator(avctx);
  450. if (!iter)
  451. return AVERROR_EXTERNAL;
  452. while (iter->Next(&dl) == S_OK) {
  453. const char *display_name = NULL;
  454. const char *unique_name = NULL;
  455. decklink_get_attr_string(dl, BMDDeckLinkDisplayName, &display_name);
  456. decklink_get_attr_string(dl, BMDDeckLinkDeviceHandle, &unique_name);
  457. if (display_name && !strcmp(name, display_name) || unique_name && !strcmp(name, unique_name)) {
  458. av_free((void *)unique_name);
  459. av_free((void *)display_name);
  460. ctx->dl = dl;
  461. break;
  462. }
  463. av_free((void *)display_name);
  464. av_free((void *)unique_name);
  465. dl->Release();
  466. }
  467. iter->Release();
  468. if (!ctx->dl)
  469. return AVERROR(ENXIO);
  470. if (ctx->dl->QueryInterface(IID_IDeckLinkConfiguration, (void **)&ctx->cfg) != S_OK) {
  471. av_log(avctx, AV_LOG_ERROR, "Could not get configuration interface for '%s'\n", name);
  472. ff_decklink_cleanup(avctx);
  473. return AVERROR_EXTERNAL;
  474. }
  475. if (ctx->dl->QueryInterface(IID_IDeckLinkProfileAttributes, (void **)&ctx->attr) != S_OK) {
  476. av_log(avctx, AV_LOG_ERROR, "Could not get attributes interface for '%s'\n", name);
  477. ff_decklink_cleanup(avctx);
  478. return AVERROR_EXTERNAL;
  479. }
  480. return 0;
  481. }