]> git.sesse.net Git - ffmpeg/commitdiff
avdevice/decklink: refactor ff_decklink_set_format function
authorKarthick J <kjeyapal@akamai.com>
Tue, 7 Nov 2017 04:02:23 +0000 (09:32 +0530)
committerMarton Balint <cus@passwd.hu>
Tue, 21 Nov 2017 21:55:49 +0000 (22:55 +0100)
This is done to enable input format autodetection in decklink_dec.

Signed-off-by: Marton Balint <cus@passwd.hu>
libavdevice/decklink_common.cpp
libavdevice/decklink_common.h
libavdevice/decklink_dec.cpp
libavdevice/decklink_enc.cpp

index 2bd63ac820c751588a42317e0e5a89de95a677f5..b952e749550f622ddbcc563545f2e655848c404c 100644 (file)
@@ -148,23 +148,12 @@ static DECKLINK_BOOL field_order_eq(enum AVFieldOrder field_order, BMDFieldDomin
     return false;
 }
 
-int ff_decklink_set_format(AVFormatContext *avctx,
-                               int width, int height,
-                               int tb_num, int tb_den,
-                               enum AVFieldOrder field_order,
-                               decklink_direction_t direction, int num)
-{
+int ff_decklink_set_configs(AVFormatContext *avctx,
+                            decklink_direction_t direction) {
     struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data;
     struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx;
-    BMDDisplayModeSupport support;
-    IDeckLinkDisplayModeIterator *itermode;
-    IDeckLinkDisplayMode *mode;
-    int i = 1;
     HRESULT res;
 
-    av_log(avctx, AV_LOG_DEBUG, "Trying to find mode for frame size %dx%d, frame timing %d/%d, field order %d, direction %d, mode number %d, format code %s\n",
-        width, height, tb_num, tb_den, field_order, direction, num, (cctx->format_code) ? cctx->format_code : "(unset)");
-
     if (ctx->duplex_mode) {
         DECKLINK_BOOL duplex_supported = false;
 
@@ -181,7 +170,6 @@ int ff_decklink_set_format(AVFormatContext *avctx,
             av_log(avctx, AV_LOG_WARNING, "Unable to set duplex mode, because it is not supported.\n");
         }
     }
-
     if (direction == DIRECTION_IN) {
         int ret;
         ret = decklink_select_input(avctx, bmdDeckLinkConfigAudioInputConnection);
@@ -190,6 +178,28 @@ int ff_decklink_set_format(AVFormatContext *avctx,
         ret = decklink_select_input(avctx, bmdDeckLinkConfigVideoInputConnection);
         if (ret < 0)
             return ret;
+    }
+    return 0;
+}
+
+int ff_decklink_set_format(AVFormatContext *avctx,
+                               int width, int height,
+                               int tb_num, int tb_den,
+                               enum AVFieldOrder field_order,
+                               decklink_direction_t direction, int num)
+{
+    struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data;
+    struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx;
+    BMDDisplayModeSupport support;
+    IDeckLinkDisplayModeIterator *itermode;
+    IDeckLinkDisplayMode *mode;
+    int i = 1;
+    HRESULT res;
+
+    av_log(avctx, AV_LOG_DEBUG, "Trying to find mode for frame size %dx%d, frame timing %d/%d, field order %d, direction %d, mode number %d, format code %s\n",
+        width, height, tb_num, tb_den, field_order, direction, num, (cctx->format_code) ? cctx->format_code : "(unset)");
+
+    if (direction == DIRECTION_IN) {
         res = ctx->dli->GetDisplayModeIterator (&itermode);
     } else {
         res = ctx->dlo->GetDisplayModeIterator (&itermode);
index b6acb01bb92ca91271fe40a8e4f4d6bd70874c97..4345156d8e53504f549c8d86b583a4897d96aae2 100644 (file)
@@ -134,6 +134,7 @@ static const BMDVideoConnection decklink_video_connection_map[] = {
 };
 
 HRESULT ff_decklink_get_display_name(IDeckLink *This, const char **displayName);
+int ff_decklink_set_configs(AVFormatContext *avctx, decklink_direction_t direction);
 int ff_decklink_set_format(AVFormatContext *avctx, int width, int height, int tb_num, int tb_den, enum AVFieldOrder field_order, decklink_direction_t direction = DIRECTION_OUT, int num = 0);
 int ff_decklink_set_format(AVFormatContext *avctx, decklink_direction_t direction, int num);
 int ff_decklink_list_devices(AVFormatContext *avctx, struct AVDeviceInfoList *device_list, int show_inputs, int show_outputs);
index e90b42811a9044f68928e2121824bfb6dc62c506..03a049a21e43eaae9f33682b574f2bce7fe5e4e8 100644 (file)
@@ -916,6 +916,12 @@ av_cold int ff_decklink_read_header(AVFormatContext *avctx)
         goto error;
     }
 
+    if (ff_decklink_set_configs(avctx, DIRECTION_IN) < 0) {
+        av_log(avctx, AV_LOG_ERROR, "Could not set input configuration\n");
+        ret = AVERROR(EIO);
+        goto error;
+    }
+
     if (mode_num > 0 || cctx->format_code) {
         if (ff_decklink_set_format(avctx, DIRECTION_IN, mode_num) < 0) {
             av_log(avctx, AV_LOG_ERROR, "Could not set mode number %d or format code %s for %s\n",
index 81df563b3bf6671b7327484210b7ea399844c7aa..c06ca4668f02568e4c08dc8c6e1533c6320b8ca0 100644 (file)
@@ -162,6 +162,10 @@ static int decklink_setup_video(AVFormatContext *avctx, AVStream *st)
         return -1;
     }
 
+    if (ff_decklink_set_configs(avctx, DIRECTION_OUT) < 0) {
+        av_log(avctx, AV_LOG_ERROR, "Could not set output configuration\n");
+        return -1;
+    }
     if (ff_decklink_set_format(avctx, c->width, c->height,
                             st->time_base.num, st->time_base.den, c->field_order)) {
         av_log(avctx, AV_LOG_ERROR, "Unsupported video size, framerate or field order!"