You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

560 lines
21KB

  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. } else {
  70. IDeckLinkAPIInformation *api;
  71. int64_t version;
  72. #ifdef _WIN32
  73. if (CoCreateInstance(CLSID_CDeckLinkAPIInformation, NULL, CLSCTX_ALL,
  74. IID_IDeckLinkAPIInformation, (void**) &api) != S_OK) {
  75. api = NULL;
  76. }
  77. #else
  78. api = CreateDeckLinkAPIInformationInstance();
  79. #endif
  80. if (api && api->GetInt(BMDDeckLinkAPIVersion, &version) == S_OK) {
  81. if (version < BLACKMAGIC_DECKLINK_API_VERSION)
  82. av_log(avctx, AV_LOG_WARNING, "Installed DeckLink drivers are too old and may be incompatible with the SDK this module was built against. "
  83. "Make sure you have DeckLink drivers " BLACKMAGIC_DECKLINK_API_VERSION_STRING " or newer installed.\n");
  84. } else {
  85. av_log(avctx, AV_LOG_ERROR, "Failed to check installed DeckLink API version.\n");
  86. }
  87. if (api)
  88. api->Release();
  89. }
  90. return iter;
  91. }
  92. static int decklink_get_attr_string(IDeckLink *dl, BMDDeckLinkAttributeID cfg_id, const char **s)
  93. {
  94. DECKLINK_STR tmp;
  95. HRESULT hr;
  96. IDeckLinkProfileAttributes *attr;
  97. *s = NULL;
  98. if (dl->QueryInterface(IID_IDeckLinkProfileAttributes, (void **)&attr) != S_OK)
  99. return AVERROR_EXTERNAL;
  100. hr = attr->GetString(cfg_id, &tmp);
  101. attr->Release();
  102. if (hr == S_OK) {
  103. *s = DECKLINK_STRDUP(tmp);
  104. DECKLINK_FREE(tmp);
  105. if (!*s)
  106. return AVERROR(ENOMEM);
  107. } else if (hr == E_FAIL) {
  108. return AVERROR_EXTERNAL;
  109. }
  110. return 0;
  111. }
  112. static int decklink_select_input(AVFormatContext *avctx, BMDDeckLinkConfigurationID cfg_id)
  113. {
  114. struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data;
  115. struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx;
  116. BMDDeckLinkAttributeID attr_id = (cfg_id == bmdDeckLinkConfigAudioInputConnection) ? BMDDeckLinkAudioInputConnections : BMDDeckLinkVideoInputConnections;
  117. int64_t bmd_input = (cfg_id == bmdDeckLinkConfigAudioInputConnection) ? (int64_t)ctx->audio_input : (int64_t)ctx->video_input;
  118. const char *type_name = (cfg_id == bmdDeckLinkConfigAudioInputConnection) ? "audio" : "video";
  119. int64_t supported_connections = 0;
  120. HRESULT res;
  121. if (bmd_input) {
  122. res = ctx->attr->GetInt(attr_id, &supported_connections);
  123. if (res != S_OK) {
  124. av_log(avctx, AV_LOG_ERROR, "Failed to query supported %s inputs.\n", type_name);
  125. return AVERROR_EXTERNAL;
  126. }
  127. if ((supported_connections & bmd_input) != bmd_input) {
  128. av_log(avctx, AV_LOG_ERROR, "Device does not support selected %s input.\n", type_name);
  129. return AVERROR(ENOSYS);
  130. }
  131. res = ctx->cfg->SetInt(cfg_id, bmd_input);
  132. if (res != S_OK) {
  133. av_log(avctx, AV_LOG_ERROR, "Failed to select %s input.\n", type_name);
  134. return AVERROR_EXTERNAL;
  135. }
  136. }
  137. return 0;
  138. }
  139. static DECKLINK_BOOL field_order_eq(enum AVFieldOrder field_order, BMDFieldDominance bmd_field_order)
  140. {
  141. if (field_order == AV_FIELD_UNKNOWN)
  142. return true;
  143. if ((field_order == AV_FIELD_TT || field_order == AV_FIELD_TB) && bmd_field_order == bmdUpperFieldFirst)
  144. return true;
  145. if ((field_order == AV_FIELD_BB || field_order == AV_FIELD_BT) && bmd_field_order == bmdLowerFieldFirst)
  146. return true;
  147. if (field_order == AV_FIELD_PROGRESSIVE && (bmd_field_order == bmdProgressiveFrame || bmd_field_order == bmdProgressiveSegmentedFrame))
  148. return true;
  149. return false;
  150. }
  151. int ff_decklink_set_configs(AVFormatContext *avctx,
  152. decklink_direction_t direction) {
  153. struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data;
  154. struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx;
  155. HRESULT res;
  156. if (ctx->duplex_mode) {
  157. DECKLINK_BOOL duplex_supported = false;
  158. #if BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b000000
  159. IDeckLinkProfileManager *manager = NULL;
  160. if (ctx->dl->QueryInterface(IID_IDeckLinkProfileManager, (void **)&manager) == S_OK)
  161. duplex_supported = true;
  162. #else
  163. if (ctx->attr->GetFlag(BMDDeckLinkSupportsDuplexModeConfiguration, &duplex_supported) != S_OK)
  164. duplex_supported = false;
  165. #endif
  166. if (duplex_supported) {
  167. #if BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b000000
  168. IDeckLinkProfile *profile = NULL;
  169. BMDProfileID bmd_profile_id = ctx->duplex_mode == 2 ? bmdProfileOneSubDeviceFullDuplex : bmdProfileTwoSubDevicesHalfDuplex;
  170. res = manager->GetProfile(bmd_profile_id, &profile);
  171. if (res == S_OK) {
  172. res = profile->SetActive();
  173. profile->Release();
  174. }
  175. manager->Release();
  176. #else
  177. res = ctx->cfg->SetInt(bmdDeckLinkConfigDuplexMode, ctx->duplex_mode == 2 ? bmdDuplexModeFull : bmdDuplexModeHalf);
  178. #endif
  179. if (res != S_OK)
  180. av_log(avctx, AV_LOG_WARNING, "Setting duplex mode failed.\n");
  181. else
  182. av_log(avctx, AV_LOG_VERBOSE, "Successfully set duplex mode to %s duplex.\n", ctx->duplex_mode == 2 ? "full" : "half");
  183. } else {
  184. av_log(avctx, AV_LOG_WARNING, "Unable to set duplex mode, because it is not supported.\n");
  185. }
  186. }
  187. if (direction == DIRECTION_IN) {
  188. int ret;
  189. ret = decklink_select_input(avctx, bmdDeckLinkConfigAudioInputConnection);
  190. if (ret < 0)
  191. return ret;
  192. ret = decklink_select_input(avctx, bmdDeckLinkConfigVideoInputConnection);
  193. if (ret < 0)
  194. return ret;
  195. }
  196. if (direction == DIRECTION_OUT && cctx->timing_offset != INT_MIN) {
  197. res = ctx->cfg->SetInt(bmdDeckLinkConfigReferenceInputTimingOffset, cctx->timing_offset);
  198. if (res != S_OK)
  199. av_log(avctx, AV_LOG_WARNING, "Setting timing offset failed.\n");
  200. }
  201. return 0;
  202. }
  203. int ff_decklink_set_format(AVFormatContext *avctx,
  204. int width, int height,
  205. int tb_num, int tb_den,
  206. enum AVFieldOrder field_order,
  207. decklink_direction_t direction)
  208. {
  209. struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data;
  210. struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx;
  211. #if BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b000000
  212. DECKLINK_BOOL support;
  213. #else
  214. BMDDisplayModeSupport support;
  215. #endif
  216. IDeckLinkDisplayModeIterator *itermode;
  217. IDeckLinkDisplayMode *mode;
  218. int i = 1;
  219. HRESULT res;
  220. 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",
  221. width, height, tb_num, tb_den, field_order, direction, cctx->format_code ? cctx->format_code : "(unset)");
  222. if (direction == DIRECTION_IN) {
  223. res = ctx->dli->GetDisplayModeIterator (&itermode);
  224. } else {
  225. res = ctx->dlo->GetDisplayModeIterator (&itermode);
  226. }
  227. if (res!= S_OK) {
  228. av_log(avctx, AV_LOG_ERROR, "Could not get Display Mode Iterator\n");
  229. return AVERROR(EIO);
  230. }
  231. char format_buf[] = " ";
  232. if (cctx->format_code)
  233. memcpy(format_buf, cctx->format_code, FFMIN(strlen(cctx->format_code), sizeof(format_buf)));
  234. BMDDisplayMode target_mode = (BMDDisplayMode)AV_RB32(format_buf);
  235. AVRational target_tb = av_make_q(tb_num, tb_den);
  236. ctx->bmd_mode = bmdModeUnknown;
  237. while ((ctx->bmd_mode == bmdModeUnknown) && itermode->Next(&mode) == S_OK) {
  238. BMDTimeValue bmd_tb_num, bmd_tb_den;
  239. int bmd_width = mode->GetWidth();
  240. int bmd_height = mode->GetHeight();
  241. BMDDisplayMode bmd_mode = mode->GetDisplayMode();
  242. BMDFieldDominance bmd_field_dominance = mode->GetFieldDominance();
  243. mode->GetFrameRate(&bmd_tb_num, &bmd_tb_den);
  244. AVRational mode_tb = av_make_q(bmd_tb_num, bmd_tb_den);
  245. if ((bmd_width == width &&
  246. bmd_height == height &&
  247. !av_cmp_q(mode_tb, target_tb) &&
  248. field_order_eq(field_order, bmd_field_dominance))
  249. || target_mode == bmd_mode) {
  250. ctx->bmd_mode = bmd_mode;
  251. ctx->bmd_width = bmd_width;
  252. ctx->bmd_height = bmd_height;
  253. ctx->bmd_tb_den = bmd_tb_den;
  254. ctx->bmd_tb_num = bmd_tb_num;
  255. ctx->bmd_field_dominance = bmd_field_dominance;
  256. av_log(avctx, AV_LOG_INFO, "Found Decklink mode %d x %d with rate %.2f%s\n",
  257. bmd_width, bmd_height, 1/av_q2d(mode_tb),
  258. (ctx->bmd_field_dominance==bmdLowerFieldFirst || ctx->bmd_field_dominance==bmdUpperFieldFirst)?"(i)":"");
  259. }
  260. mode->Release();
  261. i++;
  262. }
  263. itermode->Release();
  264. if (ctx->bmd_mode == bmdModeUnknown)
  265. return -1;
  266. #if BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b050000
  267. if (direction == DIRECTION_IN) {
  268. BMDDisplayMode actualMode = ctx->bmd_mode;
  269. if (ctx->dli->DoesSupportVideoMode(ctx->video_input, ctx->bmd_mode, ctx->raw_format,
  270. bmdNoVideoInputConversion, bmdSupportedVideoModeDefault,
  271. &actualMode, &support) != S_OK || !support || ctx->bmd_mode != actualMode)
  272. return -1;
  273. } else {
  274. BMDDisplayMode actualMode = ctx->bmd_mode;
  275. if (ctx->dlo->DoesSupportVideoMode(bmdVideoConnectionUnspecified, ctx->bmd_mode, ctx->raw_format,
  276. bmdNoVideoOutputConversion, bmdSupportedVideoModeDefault,
  277. &actualMode, &support) != S_OK || !support || ctx->bmd_mode != actualMode)
  278. return -1;
  279. }
  280. return 0;
  281. #elif BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b000000
  282. if (direction == DIRECTION_IN) {
  283. if (ctx->dli->DoesSupportVideoMode(ctx->video_input, ctx->bmd_mode, ctx->raw_format,
  284. bmdSupportedVideoModeDefault,
  285. &support) != S_OK)
  286. return -1;
  287. } else {
  288. BMDDisplayMode actualMode = ctx->bmd_mode;
  289. if (ctx->dlo->DoesSupportVideoMode(bmdVideoConnectionUnspecified, ctx->bmd_mode, ctx->raw_format,
  290. bmdSupportedVideoModeDefault,
  291. &actualMode, &support) != S_OK || !support || ctx->bmd_mode != actualMode) {
  292. return -1;
  293. }
  294. }
  295. if (support)
  296. return 0;
  297. #else
  298. if (direction == DIRECTION_IN) {
  299. if (ctx->dli->DoesSupportVideoMode(ctx->bmd_mode, ctx->raw_format,
  300. bmdVideoOutputFlagDefault,
  301. &support, NULL) != S_OK)
  302. return -1;
  303. } else {
  304. if (!ctx->supports_vanc || ctx->dlo->DoesSupportVideoMode(ctx->bmd_mode, ctx->raw_format,
  305. bmdVideoOutputVANC,
  306. &support, NULL) != S_OK || support != bmdDisplayModeSupported) {
  307. /* Try without VANC enabled */
  308. if (ctx->dlo->DoesSupportVideoMode(ctx->bmd_mode, ctx->raw_format,
  309. bmdVideoOutputFlagDefault,
  310. &support, NULL) != S_OK) {
  311. return -1;
  312. }
  313. ctx->supports_vanc = 0;
  314. }
  315. }
  316. if (support == bmdDisplayModeSupported)
  317. return 0;
  318. #endif
  319. return -1;
  320. }
  321. int ff_decklink_set_format(AVFormatContext *avctx, decklink_direction_t direction) {
  322. return ff_decklink_set_format(avctx, 0, 0, 0, 0, AV_FIELD_UNKNOWN, direction);
  323. }
  324. int ff_decklink_list_devices(AVFormatContext *avctx,
  325. struct AVDeviceInfoList *device_list,
  326. int show_inputs, int show_outputs)
  327. {
  328. IDeckLink *dl = NULL;
  329. IDeckLinkIterator *iter = decklink_create_iterator(avctx);
  330. int ret = 0;
  331. if (!iter)
  332. return AVERROR(EIO);
  333. while (ret == 0 && iter->Next(&dl) == S_OK) {
  334. IDeckLinkOutput *output_config;
  335. IDeckLinkInput *input_config;
  336. const char *display_name = NULL;
  337. const char *unique_name = NULL;
  338. AVDeviceInfo *new_device = NULL;
  339. int add = 0;
  340. ret = decklink_get_attr_string(dl, BMDDeckLinkDisplayName, &display_name);
  341. if (ret < 0)
  342. goto next;
  343. ret = decklink_get_attr_string(dl, BMDDeckLinkDeviceHandle, &unique_name);
  344. if (ret < 0)
  345. goto next;
  346. if (show_outputs) {
  347. if (dl->QueryInterface(IID_IDeckLinkOutput, (void **)&output_config) == S_OK) {
  348. output_config->Release();
  349. add = 1;
  350. }
  351. }
  352. if (show_inputs) {
  353. if (dl->QueryInterface(IID_IDeckLinkInput, (void **)&input_config) == S_OK) {
  354. input_config->Release();
  355. add = 1;
  356. }
  357. }
  358. if (add == 1) {
  359. new_device = (AVDeviceInfo *) av_mallocz(sizeof(AVDeviceInfo));
  360. if (!new_device) {
  361. ret = AVERROR(ENOMEM);
  362. goto next;
  363. }
  364. new_device->device_name = av_strdup(unique_name ? unique_name : display_name);
  365. new_device->device_description = av_strdup(display_name);
  366. if (!new_device->device_name ||
  367. !new_device->device_description ||
  368. av_dynarray_add_nofree(&device_list->devices, &device_list->nb_devices, new_device) < 0) {
  369. ret = AVERROR(ENOMEM);
  370. av_freep(&new_device->device_name);
  371. av_freep(&new_device->device_description);
  372. av_freep(&new_device);
  373. goto next;
  374. }
  375. }
  376. next:
  377. av_freep(&display_name);
  378. av_freep(&unique_name);
  379. dl->Release();
  380. }
  381. iter->Release();
  382. return ret;
  383. }
  384. /* This is a wrapper around the ff_decklink_list_devices() which dumps the
  385. output to av_log() and exits (for backward compatibility with the
  386. "-list_devices" argument). */
  387. void ff_decklink_list_devices_legacy(AVFormatContext *avctx,
  388. int show_inputs, int show_outputs)
  389. {
  390. struct AVDeviceInfoList *device_list = NULL;
  391. int ret;
  392. device_list = (struct AVDeviceInfoList *) av_mallocz(sizeof(AVDeviceInfoList));
  393. if (!device_list)
  394. return;
  395. ret = ff_decklink_list_devices(avctx, device_list, show_inputs, show_outputs);
  396. if (ret == 0) {
  397. av_log(avctx, AV_LOG_INFO, "Blackmagic DeckLink %s devices:\n",
  398. show_inputs ? "input" : "output");
  399. for (int i = 0; i < device_list->nb_devices; i++) {
  400. av_log(avctx, AV_LOG_INFO, "\t'%s'\n", device_list->devices[i]->device_description);
  401. }
  402. }
  403. avdevice_free_list_devices(&device_list);
  404. }
  405. int ff_decklink_list_formats(AVFormatContext *avctx, decklink_direction_t direction)
  406. {
  407. struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data;
  408. struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx;
  409. IDeckLinkDisplayModeIterator *itermode;
  410. IDeckLinkDisplayMode *mode;
  411. uint32_t format_code;
  412. HRESULT res;
  413. if (direction == DIRECTION_IN) {
  414. int ret;
  415. ret = decklink_select_input(avctx, bmdDeckLinkConfigAudioInputConnection);
  416. if (ret < 0)
  417. return ret;
  418. ret = decklink_select_input(avctx, bmdDeckLinkConfigVideoInputConnection);
  419. if (ret < 0)
  420. return ret;
  421. res = ctx->dli->GetDisplayModeIterator (&itermode);
  422. } else {
  423. res = ctx->dlo->GetDisplayModeIterator (&itermode);
  424. }
  425. if (res!= S_OK) {
  426. av_log(avctx, AV_LOG_ERROR, "Could not get Display Mode Iterator\n");
  427. return AVERROR(EIO);
  428. }
  429. av_log(avctx, AV_LOG_INFO, "Supported formats for '%s':\n\tformat_code\tdescription",
  430. avctx->url);
  431. while (itermode->Next(&mode) == S_OK) {
  432. BMDTimeValue tb_num, tb_den;
  433. mode->GetFrameRate(&tb_num, &tb_den);
  434. format_code = av_bswap32(mode->GetDisplayMode());
  435. av_log(avctx, AV_LOG_INFO, "\n\t%.4s\t\t%ldx%ld at %d/%d fps",
  436. (char*) &format_code, mode->GetWidth(), mode->GetHeight(),
  437. (int) tb_den, (int) tb_num);
  438. switch (mode->GetFieldDominance()) {
  439. case bmdLowerFieldFirst:
  440. av_log(avctx, AV_LOG_INFO, " (interlaced, lower field first)"); break;
  441. case bmdUpperFieldFirst:
  442. av_log(avctx, AV_LOG_INFO, " (interlaced, upper field first)"); break;
  443. }
  444. mode->Release();
  445. }
  446. av_log(avctx, AV_LOG_INFO, "\n");
  447. itermode->Release();
  448. return 0;
  449. }
  450. void ff_decklink_cleanup(AVFormatContext *avctx)
  451. {
  452. struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data;
  453. struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx;
  454. if (ctx->dli)
  455. ctx->dli->Release();
  456. if (ctx->dlo)
  457. ctx->dlo->Release();
  458. if (ctx->attr)
  459. ctx->attr->Release();
  460. if (ctx->cfg)
  461. ctx->cfg->Release();
  462. if (ctx->dl)
  463. ctx->dl->Release();
  464. }
  465. int ff_decklink_init_device(AVFormatContext *avctx, const char* name)
  466. {
  467. struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data;
  468. struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx;
  469. IDeckLink *dl = NULL;
  470. IDeckLinkIterator *iter = decklink_create_iterator(avctx);
  471. if (!iter)
  472. return AVERROR_EXTERNAL;
  473. while (iter->Next(&dl) == S_OK) {
  474. const char *display_name = NULL;
  475. const char *unique_name = NULL;
  476. decklink_get_attr_string(dl, BMDDeckLinkDisplayName, &display_name);
  477. decklink_get_attr_string(dl, BMDDeckLinkDeviceHandle, &unique_name);
  478. if (display_name && !strcmp(name, display_name) || unique_name && !strcmp(name, unique_name)) {
  479. av_free((void *)unique_name);
  480. av_free((void *)display_name);
  481. ctx->dl = dl;
  482. break;
  483. }
  484. av_free((void *)display_name);
  485. av_free((void *)unique_name);
  486. dl->Release();
  487. }
  488. iter->Release();
  489. if (!ctx->dl)
  490. return AVERROR(ENXIO);
  491. if (ctx->dl->QueryInterface(IID_IDeckLinkConfiguration, (void **)&ctx->cfg) != S_OK) {
  492. av_log(avctx, AV_LOG_ERROR, "Could not get configuration interface for '%s'\n", name);
  493. ff_decklink_cleanup(avctx);
  494. return AVERROR_EXTERNAL;
  495. }
  496. if (ctx->dl->QueryInterface(IID_IDeckLinkProfileAttributes, (void **)&ctx->attr) != S_OK) {
  497. av_log(avctx, AV_LOG_ERROR, "Could not get attributes interface for '%s'\n", name);
  498. ff_decklink_cleanup(avctx);
  499. return AVERROR_EXTERNAL;
  500. }
  501. return 0;
  502. }