Reviewed-by: Deti Fliegl <deti@fliegl.de> Signed-off-by: Marton Balint <cus@passwd.hu>tags/n3.2
@@ -252,3 +252,32 @@ void ff_decklink_cleanup(AVFormatContext *avctx) | |||||
if (ctx->dl) | if (ctx->dl) | ||||
ctx->dl->Release(); | ctx->dl->Release(); | ||||
} | } | ||||
int ff_decklink_init_device(AVFormatContext *avctx, const char* name) | |||||
{ | |||||
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"); | |||||
return AVERROR_EXTERNAL; | |||||
} | |||||
while (iter->Next(&dl) == S_OK) { | |||||
const char *displayName; | |||||
ff_decklink_get_display_name(dl, &displayName); | |||||
if (!strcmp(name, displayName)) { | |||||
av_free((void *)displayName); | |||||
ctx->dl = dl; | |||||
break; | |||||
} | |||||
av_free((void *)displayName); | |||||
dl->Release(); | |||||
} | |||||
iter->Release(); | |||||
if (!ctx->dl) | |||||
return AVERROR(ENXIO); | |||||
return 0; | |||||
} |
@@ -106,5 +106,6 @@ int ff_decklink_set_format(AVFormatContext *avctx, decklink_direction_t directio | |||||
int ff_decklink_list_devices(AVFormatContext *avctx); | int ff_decklink_list_devices(AVFormatContext *avctx); | ||||
int ff_decklink_list_formats(AVFormatContext *avctx, decklink_direction_t direction = DIRECTION_OUT); | int ff_decklink_list_formats(AVFormatContext *avctx, decklink_direction_t direction = DIRECTION_OUT); | ||||
void ff_decklink_cleanup(AVFormatContext *avctx); | void ff_decklink_cleanup(AVFormatContext *avctx); | ||||
int ff_decklink_init_device(AVFormatContext *avctx, const char* name); | |||||
#endif /* AVDEVICE_DECKLINK_COMMON_H */ | #endif /* AVDEVICE_DECKLINK_COMMON_H */ |
@@ -431,13 +431,12 @@ av_cold int ff_decklink_read_header(AVFormatContext *avctx) | |||||
{ | { | ||||
struct decklink_cctx *cctx = (struct decklink_cctx *) avctx->priv_data; | struct decklink_cctx *cctx = (struct decklink_cctx *) avctx->priv_data; | ||||
struct decklink_ctx *ctx; | struct decklink_ctx *ctx; | ||||
IDeckLinkIterator *iter; | |||||
IDeckLink *dl = NULL; | |||||
AVStream *st; | AVStream *st; | ||||
HRESULT result; | HRESULT result; | ||||
char fname[1024]; | char fname[1024]; | ||||
char *tmp; | char *tmp; | ||||
int mode_num = 0; | int mode_num = 0; | ||||
int ret; | |||||
ctx = (struct decklink_ctx *) av_mallocz(sizeof(struct decklink_ctx)); | ctx = (struct decklink_ctx *) av_mallocz(sizeof(struct decklink_ctx)); | ||||
if (!ctx) | if (!ctx) | ||||
@@ -466,12 +465,6 @@ av_cold int ff_decklink_read_header(AVFormatContext *avctx) | |||||
return AVERROR(EINVAL); | return AVERROR(EINVAL); | ||||
} | } | ||||
iter = CreateDeckLinkIteratorInstance(); | |||||
if (!iter) { | |||||
av_log(avctx, AV_LOG_ERROR, "Could not create DeckLink iterator\n"); | |||||
return AVERROR(EIO); | |||||
} | |||||
/* List available devices. */ | /* List available devices. */ | ||||
if (ctx->list_devices) { | if (ctx->list_devices) { | ||||
ff_decklink_list_devices(avctx); | ff_decklink_list_devices(avctx); | ||||
@@ -485,23 +478,9 @@ av_cold int ff_decklink_read_header(AVFormatContext *avctx) | |||||
*tmp = 0; | *tmp = 0; | ||||
} | } | ||||
/* Open device. */ | |||||
while (iter->Next(&dl) == S_OK) { | |||||
const char *displayName; | |||||
ff_decklink_get_display_name(dl, &displayName); | |||||
if (!strcmp(fname, displayName)) { | |||||
av_free((void *) displayName); | |||||
ctx->dl = dl; | |||||
break; | |||||
} | |||||
av_free((void *) displayName); | |||||
dl->Release(); | |||||
} | |||||
iter->Release(); | |||||
if (!ctx->dl) { | |||||
av_log(avctx, AV_LOG_ERROR, "Could not open '%s'\n", fname); | |||||
return AVERROR(EIO); | |||||
} | |||||
ret = ff_decklink_init_device(avctx, fname); | |||||
if (ret < 0) | |||||
return ret; | |||||
/* Get input device. */ | /* Get input device. */ | ||||
if (ctx->dl->QueryInterface(IID_IDeckLinkInput, (void **) &ctx->dli) != S_OK) { | if (ctx->dl->QueryInterface(IID_IDeckLinkInput, (void **) &ctx->dli) != S_OK) { | ||||
@@ -312,9 +312,8 @@ av_cold int ff_decklink_write_header(AVFormatContext *avctx) | |||||
{ | { | ||||
struct decklink_cctx *cctx = (struct decklink_cctx *) avctx->priv_data; | struct decklink_cctx *cctx = (struct decklink_cctx *) avctx->priv_data; | ||||
struct decklink_ctx *ctx; | struct decklink_ctx *ctx; | ||||
IDeckLinkIterator *iter; | |||||
IDeckLink *dl = NULL; | |||||
unsigned int n; | unsigned int n; | ||||
int ret; | |||||
ctx = (struct decklink_ctx *) av_mallocz(sizeof(struct decklink_ctx)); | ctx = (struct decklink_ctx *) av_mallocz(sizeof(struct decklink_ctx)); | ||||
if (!ctx) | if (!ctx) | ||||
@@ -324,35 +323,15 @@ av_cold int ff_decklink_write_header(AVFormatContext *avctx) | |||||
ctx->preroll = cctx->preroll; | ctx->preroll = cctx->preroll; | ||||
cctx->ctx = ctx; | cctx->ctx = ctx; | ||||
iter = CreateDeckLinkIteratorInstance(); | |||||
if (!iter) { | |||||
av_log(avctx, AV_LOG_ERROR, "Could not create DeckLink iterator\n"); | |||||
return AVERROR(EIO); | |||||
} | |||||
/* List available devices. */ | /* List available devices. */ | ||||
if (ctx->list_devices) { | if (ctx->list_devices) { | ||||
ff_decklink_list_devices(avctx); | ff_decklink_list_devices(avctx); | ||||
return AVERROR_EXIT; | return AVERROR_EXIT; | ||||
} | } | ||||
/* Open device. */ | |||||
while (iter->Next(&dl) == S_OK) { | |||||
const char *displayName; | |||||
ff_decklink_get_display_name(dl, &displayName); | |||||
if (!strcmp(avctx->filename, displayName)) { | |||||
av_free((void *) displayName); | |||||
ctx->dl = dl; | |||||
break; | |||||
} | |||||
av_free((void *) displayName); | |||||
dl->Release(); | |||||
} | |||||
iter->Release(); | |||||
if (!ctx->dl) { | |||||
av_log(avctx, AV_LOG_ERROR, "Could not open '%s'\n", avctx->filename); | |||||
return AVERROR(EIO); | |||||
} | |||||
ret = ff_decklink_init_device(avctx, avctx->filename); | |||||
if (ret < 0) | |||||
return ret; | |||||
/* Get output device. */ | /* Get output device. */ | ||||
if (ctx->dl->QueryInterface(IID_IDeckLinkOutput, (void **) &ctx->dlo) != S_OK) { | if (ctx->dl->QueryInterface(IID_IDeckLinkOutput, (void **) &ctx->dlo) != S_OK) { | ||||