diff mbox series

[FFmpeg-devel,v4] avdevice/decklink_dec: map the raw_format instead of hardcode

Message ID 1605834998-6138-1-git-send-email-lance.lmwang@gmail.com
State Accepted
Commit 09f1d15ae8bd1d7f597aec9ced4f8ebe8762a4bd
Headers show
Series [FFmpeg-devel,v4] avdevice/decklink_dec: map the raw_format instead of hardcode
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Limin Wang Nov. 20, 2020, 1:16 a.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

The patch will change the numerical values for the string constants so bump
micro version.

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavdevice/decklink_common.h |  9 +++++++++
 libavdevice/decklink_dec.cpp  |  3 ++-
 libavdevice/decklink_dec_c.c  | 14 +++++++-------
 libavdevice/version.h         |  2 +-
 4 files changed, 19 insertions(+), 9 deletions(-)

Comments

Marton Balint Nov. 20, 2020, 8:39 p.m. UTC | #1
On Fri, 20 Nov 2020, lance.lmwang@gmail.com wrote:

> From: Limin Wang <lance.lmwang@gmail.com>
>
> The patch will change the numerical values for the string constants so bump
> micro version.
>
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
> libavdevice/decklink_common.h |  9 +++++++++
> libavdevice/decklink_dec.cpp  |  3 ++-
> libavdevice/decklink_dec_c.c  | 14 +++++++-------
> libavdevice/version.h         |  2 +-
> 4 files changed, 19 insertions(+), 9 deletions(-)
>
> diff --git a/libavdevice/decklink_common.h b/libavdevice/decklink_common.h
> index f35bd9a..05380ef 100644
> --- a/libavdevice/decklink_common.h
> +++ b/libavdevice/decklink_common.h
> @@ -162,6 +162,15 @@ IDeckLinkIterator *CreateDeckLinkIteratorInstance(void);
> typedef uint32_t buffercount_type;
> #endif
> 
> +static const BMDPixelFormat decklink_raw_format_map[] = {
> +    (BMDPixelFormat)0,
> +    bmdFormat8BitYUV,
> +    bmdFormat10BitYUV,
> +    bmdFormat8BitARGB,
> +    bmdFormat8BitBGRA,
> +    bmdFormat10BitRGB,
> +};
> +
> static const BMDAudioConnection decklink_audio_connection_map[] = {
>     (BMDAudioConnection)0,
>     bmdAudioConnectionEmbedded,
> diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp
> index 6517b9d..049e133 100644
> --- a/libavdevice/decklink_dec.cpp
> +++ b/libavdevice/decklink_dec.cpp
> @@ -1152,7 +1152,8 @@ av_cold int ff_decklink_read_header(AVFormatContext *avctx)
>     ctx->video_pts_source = cctx->video_pts_source;
>     ctx->draw_bars = cctx->draw_bars;
>     ctx->audio_depth = cctx->audio_depth;
> -    ctx->raw_format = (BMDPixelFormat)cctx->raw_format;
> +    if (cctx->raw_format > 0 && (unsigned int)cctx->raw_format < FF_ARRAY_ELEMS(decklink_raw_format_map))
> +        ctx->raw_format = decklink_raw_format_map[cctx->raw_format];
>     cctx->ctx = ctx;
>
>     /* Check audio channel option for valid values: 2, 8 or 16 */
> diff --git a/libavdevice/decklink_dec_c.c b/libavdevice/decklink_dec_c.c
> index f3fdcd3..5997440 100644
> --- a/libavdevice/decklink_dec_c.c
> +++ b/libavdevice/decklink_dec_c.c
> @@ -33,13 +33,13 @@ 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_code",  "set format by fourcc"    , OFFSET(format_code),  AV_OPT_TYPE_STRING, { .str = NULL}, 0, 0, DEC },
> -    { "raw_format",   "pixel format to be returned by the card when capturing" , OFFSET(raw_format),  AV_OPT_TYPE_INT, { .i64 = 0}, 0, UINT_MAX, DEC, "raw_format" },
> -    { "auto",          NULL,   0,  AV_OPT_TYPE_CONST, { .i64 = 0                        }, 0, 0, DEC, "raw_format"},
> -    { "uyvy422",       NULL,   0,  AV_OPT_TYPE_CONST, { .i64 = MKBETAG('2','v','u','y') }, 0, 0, DEC, "raw_format"},
> -    { "yuv422p10",     NULL,   0,  AV_OPT_TYPE_CONST, { .i64 = MKBETAG('v','2','1','0') }, 0, 0, DEC, "raw_format"},
> -    { "argb",          NULL,   0,  AV_OPT_TYPE_CONST, { .i64 = 32                       }, 0, 0, DEC, "raw_format"},
> -    { "bgra",          NULL,   0,  AV_OPT_TYPE_CONST, { .i64 = MKBETAG('B','G','R','A') }, 0, 0, DEC, "raw_format"},
> -    { "rgb10",         NULL,   0,  AV_OPT_TYPE_CONST, { .i64 = MKBETAG('r','2','1','0') }, 0, 0, DEC, "raw_format"},
> +    { "raw_format",   "pixel format to be returned by the card when capturing" , OFFSET(raw_format),  AV_OPT_TYPE_INT, { .i64 = 0}, 0, 5, DEC, "raw_format" },
> +    { "auto",          NULL,   0,  AV_OPT_TYPE_CONST, { .i64 = 0 }, 0, 0, DEC, "raw_format"},
> +    { "uyvy422",       NULL,   0,  AV_OPT_TYPE_CONST, { .i64 = 1 }, 0, 0, DEC, "raw_format"},
> +    { "yuv422p10",     NULL,   0,  AV_OPT_TYPE_CONST, { .i64 = 2 }, 0, 0, DEC, "raw_format"},
> +    { "argb",          NULL,   0,  AV_OPT_TYPE_CONST, { .i64 = 3 }, 0, 0, DEC, "raw_format"},
> +    { "bgra",          NULL,   0,  AV_OPT_TYPE_CONST, { .i64 = 4 }, 0, 0, DEC, "raw_format"},
> +    { "rgb10",         NULL,   0,  AV_OPT_TYPE_CONST, { .i64 = 5 }, 0, 0, DEC, "raw_format"},
>     { "enable_klv",    "output klv if present in vanc", OFFSET(enable_klv), AV_OPT_TYPE_BOOL, { .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"},
> diff --git a/libavdevice/version.h b/libavdevice/version.h
> index e3aca9e..7022fdb 100644
> --- a/libavdevice/version.h
> +++ b/libavdevice/version.h
> @@ -29,7 +29,7 @@
> 
> #define LIBAVDEVICE_VERSION_MAJOR  58
> #define LIBAVDEVICE_VERSION_MINOR  11
> -#define LIBAVDEVICE_VERSION_MICRO 102
> +#define LIBAVDEVICE_VERSION_MICRO 103
> 
> #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \
>                                                LIBAVDEVICE_VERSION_MINOR, \
> -- 
> 1.8.3.1

LGTM, thanks.

Marton
diff mbox series

Patch

diff --git a/libavdevice/decklink_common.h b/libavdevice/decklink_common.h
index f35bd9a..05380ef 100644
--- a/libavdevice/decklink_common.h
+++ b/libavdevice/decklink_common.h
@@ -162,6 +162,15 @@  IDeckLinkIterator *CreateDeckLinkIteratorInstance(void);
 typedef uint32_t buffercount_type;
 #endif
 
+static const BMDPixelFormat decklink_raw_format_map[] = {
+    (BMDPixelFormat)0,
+    bmdFormat8BitYUV,
+    bmdFormat10BitYUV,
+    bmdFormat8BitARGB,
+    bmdFormat8BitBGRA,
+    bmdFormat10BitRGB,
+};
+
 static const BMDAudioConnection decklink_audio_connection_map[] = {
     (BMDAudioConnection)0,
     bmdAudioConnectionEmbedded,
diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp
index 6517b9d..049e133 100644
--- a/libavdevice/decklink_dec.cpp
+++ b/libavdevice/decklink_dec.cpp
@@ -1152,7 +1152,8 @@  av_cold int ff_decklink_read_header(AVFormatContext *avctx)
     ctx->video_pts_source = cctx->video_pts_source;
     ctx->draw_bars = cctx->draw_bars;
     ctx->audio_depth = cctx->audio_depth;
-    ctx->raw_format = (BMDPixelFormat)cctx->raw_format;
+    if (cctx->raw_format > 0 && (unsigned int)cctx->raw_format < FF_ARRAY_ELEMS(decklink_raw_format_map))
+        ctx->raw_format = decklink_raw_format_map[cctx->raw_format];
     cctx->ctx = ctx;
 
     /* Check audio channel option for valid values: 2, 8 or 16 */
diff --git a/libavdevice/decklink_dec_c.c b/libavdevice/decklink_dec_c.c
index f3fdcd3..5997440 100644
--- a/libavdevice/decklink_dec_c.c
+++ b/libavdevice/decklink_dec_c.c
@@ -33,13 +33,13 @@  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_code",  "set format by fourcc"    , OFFSET(format_code),  AV_OPT_TYPE_STRING, { .str = NULL}, 0, 0, DEC },
-    { "raw_format",   "pixel format to be returned by the card when capturing" , OFFSET(raw_format),  AV_OPT_TYPE_INT, { .i64 = 0}, 0, UINT_MAX, DEC, "raw_format" },
-    { "auto",          NULL,   0,  AV_OPT_TYPE_CONST, { .i64 = 0                        }, 0, 0, DEC, "raw_format"},
-    { "uyvy422",       NULL,   0,  AV_OPT_TYPE_CONST, { .i64 = MKBETAG('2','v','u','y') }, 0, 0, DEC, "raw_format"},
-    { "yuv422p10",     NULL,   0,  AV_OPT_TYPE_CONST, { .i64 = MKBETAG('v','2','1','0') }, 0, 0, DEC, "raw_format"},
-    { "argb",          NULL,   0,  AV_OPT_TYPE_CONST, { .i64 = 32                       }, 0, 0, DEC, "raw_format"},
-    { "bgra",          NULL,   0,  AV_OPT_TYPE_CONST, { .i64 = MKBETAG('B','G','R','A') }, 0, 0, DEC, "raw_format"},
-    { "rgb10",         NULL,   0,  AV_OPT_TYPE_CONST, { .i64 = MKBETAG('r','2','1','0') }, 0, 0, DEC, "raw_format"},
+    { "raw_format",   "pixel format to be returned by the card when capturing" , OFFSET(raw_format),  AV_OPT_TYPE_INT, { .i64 = 0}, 0, 5, DEC, "raw_format" },
+    { "auto",          NULL,   0,  AV_OPT_TYPE_CONST, { .i64 = 0 }, 0, 0, DEC, "raw_format"},
+    { "uyvy422",       NULL,   0,  AV_OPT_TYPE_CONST, { .i64 = 1 }, 0, 0, DEC, "raw_format"},
+    { "yuv422p10",     NULL,   0,  AV_OPT_TYPE_CONST, { .i64 = 2 }, 0, 0, DEC, "raw_format"},
+    { "argb",          NULL,   0,  AV_OPT_TYPE_CONST, { .i64 = 3 }, 0, 0, DEC, "raw_format"},
+    { "bgra",          NULL,   0,  AV_OPT_TYPE_CONST, { .i64 = 4 }, 0, 0, DEC, "raw_format"},
+    { "rgb10",         NULL,   0,  AV_OPT_TYPE_CONST, { .i64 = 5 }, 0, 0, DEC, "raw_format"},
     { "enable_klv",    "output klv if present in vanc", OFFSET(enable_klv), AV_OPT_TYPE_BOOL, { .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"},
diff --git a/libavdevice/version.h b/libavdevice/version.h
index e3aca9e..7022fdb 100644
--- a/libavdevice/version.h
+++ b/libavdevice/version.h
@@ -29,7 +29,7 @@ 
 
 #define LIBAVDEVICE_VERSION_MAJOR  58
 #define LIBAVDEVICE_VERSION_MINOR  11
-#define LIBAVDEVICE_VERSION_MICRO 102
+#define LIBAVDEVICE_VERSION_MICRO 103
 
 #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \
                                                LIBAVDEVICE_VERSION_MINOR, \