[FFmpeg-devel] [PATCH 2/3] decklink: new option 'format' to set video format by fourCC

Matthias Hunstock atze at fem.tu-ilmenau.de
Thu Mar 16 16:06:00 EET 2017


---
 libavdevice/decklink_common.cpp | 22 ++++++++++++++++++----
 libavdevice/decklink_common_c.h |  1 +
 libavdevice/decklink_dec.cpp    |  2 +-
 libavdevice/decklink_dec_c.c    |  1 +
 4 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/libavdevice/decklink_common.cpp b/libavdevice/decklink_common.cpp
index 131d186..548bf3b 100644
--- a/libavdevice/decklink_common.cpp
+++ b/libavdevice/decklink_common.cpp
@@ -143,6 +143,18 @@ static DECKLINK_BOOL field_order_eq(enum AVFieldOrder field_order, BMDFieldDomin
     return false;
 }
 
+static DECKLINK_BOOL fourcc_eq(char *fourcc_string, BMDDisplayMode fourcc)
+{
+    BMDDisplayMode fourcc_converted = 0;
+    if (!fourcc_string) return false;
+    if (!strcmp(fourcc_string, "pal") && fourcc == 0x70616C20) return true;
+    if (strlen(fourcc_string) < 4) return false;
+    fourcc_converted = ((uint8_t) fourcc_string[0] << 24) | ((uint8_t) fourcc_string[1] << 16) |
+        ((uint8_t) fourcc_string[2] << 8) | ((uint8_t) fourcc_string[3]);
+    if (fourcc_converted == fourcc) return true;
+    return false;
+}
+
 int ff_decklink_set_format(AVFormatContext *avctx,
                                int width, int height,
                                int tb_num, int tb_den,
@@ -157,8 +169,8 @@ int ff_decklink_set_format(AVFormatContext *avctx,
     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\n",
-        width, height, tb_num, tb_den, field_order, direction, num);
+    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, mode fourCC %s\n",
+        width, height, tb_num, tb_den, field_order, direction, num, cctx->format);
 
     if (ctx->duplex_mode) {
         DECKLINK_BOOL duplex_supported = false;
@@ -202,6 +214,7 @@ int ff_decklink_set_format(AVFormatContext *avctx,
         int bmd_width  = mode->GetWidth();
         int bmd_height = mode->GetHeight();
         BMDFieldDominance bmd_field_dominance = mode->GetFieldDominance();
+        BMDDisplayMode bmd_mode = mode->GetDisplayMode();
 
         mode->GetFrameRate(&bmd_tb_num, &bmd_tb_den);
         AVRational mode_tb = av_make_q(bmd_tb_num, bmd_tb_den);
@@ -209,8 +222,9 @@ int ff_decklink_set_format(AVFormatContext *avctx,
         if ((bmd_width == width &&
              bmd_height == height &&
              !av_cmp_q(mode_tb, target_tb) &&
-             field_order_eq(field_order, bmd_field_dominance)) || i == num) {
-            ctx->bmd_mode   = mode->GetDisplayMode();
+             field_order_eq(field_order, bmd_field_dominance))
+             || i == num || fourcc_eq(cctx->format, bmd_mode)) {
+            ctx->bmd_mode   = bmd_mode;
             ctx->bmd_width  = bmd_width;
             ctx->bmd_height = bmd_height;
             ctx->bmd_tb_den = bmd_tb_den;
diff --git a/libavdevice/decklink_common_c.h b/libavdevice/decklink_common_c.h
index d565631..161a48a 100644
--- a/libavdevice/decklink_common_c.h
+++ b/libavdevice/decklink_common_c.h
@@ -47,6 +47,7 @@ struct decklink_cctx {
     int audio_input;
     int video_input;
     int draw_bars;
+    char *format;
 };
 
 #endif /* AVDEVICE_DECKLINK_COMMON_C_H */
diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp
index 7df841b..5948888 100644
--- a/libavdevice/decklink_dec.cpp
+++ b/libavdevice/decklink_dec.cpp
@@ -539,7 +539,7 @@ av_cold int ff_decklink_read_header(AVFormatContext *avctx)
         goto error;
     }
 
-    if (mode_num > 0) {
+    if (mode_num > 0 || cctx->format) {
         if (ff_decklink_set_format(avctx, DIRECTION_IN, mode_num) < 0) {
             av_log(avctx, AV_LOG_ERROR, "Could not set mode %d for %s\n", mode_num, fname);
             ret = AVERROR(EIO);
diff --git a/libavdevice/decklink_dec_c.c b/libavdevice/decklink_dec_c.c
index 31818d2..07da7cc 100644
--- a/libavdevice/decklink_dec_c.c
+++ b/libavdevice/decklink_dec_c.c
@@ -31,6 +31,7 @@
 static const AVOption options[] = {
     { "list_devices", "list available devices"  , OFFSET(list_devices), AV_OPT_TYPE_INT   , { .i64 = 0   }, 0, 1, DEC },
     { "list_formats", "list supported formats"  , OFFSET(list_formats), AV_OPT_TYPE_INT   , { .i64 = 0   }, 0, 1, DEC },
+    { "format",       "set format by fourcc"    , OFFSET(format),       AV_OPT_TYPE_STRING, { .str = NULL}, 3, 4, DEC },
     { "bm_v210",      "v210 10 bit per channel" , OFFSET(v210),         AV_OPT_TYPE_INT   , { .i64 = 0   }, 0, 1, DEC },
     { "teletext_lines", "teletext lines bitmask", OFFSET(teletext_lines), AV_OPT_TYPE_INT64, { .i64 = 0   }, 0, 0x7ffffffffLL, DEC, "teletext_lines"},
     { "standard",     NULL,                                           0,  AV_OPT_TYPE_CONST, { .i64 = 0x7fff9fffeLL}, 0, 0,    DEC, "teletext_lines"},
-- 
2.1.4



More information about the ffmpeg-devel mailing list