diff mbox series

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

Message ID 1605362558-20576-1-git-send-email-lance.lmwang@gmail.com
State Superseded
Headers show
Series [FFmpeg-devel,v2] 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. 14, 2020, 2:02 p.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

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

Comments

Marton Balint Nov. 18, 2020, 6:37 p.m. UTC | #1
On Sat, 14 Nov 2020, lance.lmwang@gmail.com wrote:

> From: Limin Wang <lance.lmwang@gmail.com>

Well, this patch changes the numerical values for the string 
constants. We sometimes do that, and probably it is cleaner if we do 
mapping the same way we do with other options, but a libavdevice micro 
bump is definitely needed for the change.

>
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
> libavdevice/decklink_common.h |  9 +++++++++
> libavdevice/decklink_dec.cpp  |  3 ++-
> libavdevice/decklink_dec_c.c  | 12 ++++++------
> 3 files changed, 17 insertions(+), 7 deletions(-)
>
> diff --git a/libavdevice/decklink_common.h b/libavdevice/decklink_common.h
> index f35bd9a..ac15488 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),

Please follow the C syntax: (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..66786db 100644
> --- a/libavdevice/decklink_dec_c.c
> +++ b/libavdevice/decklink_dec_c.c
> @@ -34,12 +34,12 @@ static const AVOption options[] = {
>     { "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" },

The maximum should also be updated.

> -    { "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"},
> +    { "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"},

Regards,
Marton
Limin Wang Nov. 19, 2020, 4:25 a.m. UTC | #2
On Wed, Nov 18, 2020 at 07:37:40PM +0100, Marton Balint wrote:
> 
> 
> On Sat, 14 Nov 2020, lance.lmwang@gmail.com wrote:
> 
> > From: Limin Wang <lance.lmwang@gmail.com>
> 
> Well, this patch changes the numerical values for the string constants. We
> sometimes do that, and probably it is cleaner if we do mapping the same way
> we do with other options, but a libavdevice micro bump is definitely needed
> for the change.

will bump the 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  | 12 ++++++------
> > 3 files changed, 17 insertions(+), 7 deletions(-)
> > 
> > diff --git a/libavdevice/decklink_common.h b/libavdevice/decklink_common.h
> > index f35bd9a..ac15488 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),
> 
> Please follow the C syntax: (BMDPixelFormat)0

OK, will change it

> 
> > +    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..66786db 100644
> > --- a/libavdevice/decklink_dec_c.c
> > +++ b/libavdevice/decklink_dec_c.c
> > @@ -34,12 +34,12 @@ static const AVOption options[] = {
> >     { "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" },
> 
> The maximum should also be updated.

will update the maximum range

> 
> > -    { "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"},
> > +    { "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"},
> 
> Regards,
> Marton
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox series

Patch

diff --git a/libavdevice/decklink_common.h b/libavdevice/decklink_common.h
index f35bd9a..ac15488 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..66786db 100644
--- a/libavdevice/decklink_dec_c.c
+++ b/libavdevice/decklink_dec_c.c
@@ -34,12 +34,12 @@  static const AVOption options[] = {
     { "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"},
+    { "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"},