diff mbox series

[FFmpeg-devel,v5,1/3] lavc/libopenh264enc: Rewrite profile handling

Message ID 20200506134752.2055-1-linjie.fu@intel.com
State Accepted
Commit d3a7bdd4ac54349aea9150a234478635d50ebd87
Headers show
Series [FFmpeg-devel,v5,1/3] lavc/libopenh264enc: Rewrite profile handling | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Fu, Linjie May 6, 2020, 1:47 p.m. UTC
Support the profiles "constrained_baseline" and "high" for libopenh264
version >= 1.8, support "constrained_baseline" and "main" for earlier
version.

If option not supported with current version, convert to constrained
baseline with a warning for users.

Signed-off-by: Linjie Fu <linjie.fu@intel.com>
---
 libavcodec/libopenh264enc.c | 44 +++++++++++++++++++++++++++++++++----
 1 file changed, 40 insertions(+), 4 deletions(-)

Comments

Martin Storsjö May 12, 2020, 9:36 a.m. UTC | #1
On Wed, 6 May 2020, Linjie Fu wrote:

> Support the profiles "constrained_baseline" and "high" for libopenh264
> version >= 1.8, support "constrained_baseline" and "main" for earlier
> version.
>
> If option not supported with current version, convert to constrained
> baseline with a warning for users.
>
> Signed-off-by: Linjie Fu <linjie.fu@intel.com>
> ---
> libavcodec/libopenh264enc.c | 44 +++++++++++++++++++++++++++++++++----
> 1 file changed, 40 insertions(+), 4 deletions(-)
>
> diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
> index 3bb3cceb64..12c71ca0e9 100644
> --- a/libavcodec/libopenh264enc.c
> +++ b/libavcodec/libopenh264enc.c
> @@ -44,7 +44,7 @@ typedef struct SVCContext {
>     ISVCEncoder *encoder;
>     int slice_mode;
>     int loopfilter;
> -    char *profile;
> +    int profile;
>     int max_nal_size;
>     int skip_frames;
>     int skipped;
> @@ -75,7 +75,12 @@ static const AVOption options[] = {
> #endif
> #endif
>     { "loopfilter", "enable loop filter", OFFSET(loopfilter), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, VE },
> -    { "profile", "set profile restrictions", OFFSET(profile), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, VE },
> +    { "profile", "set profile restrictions", OFFSET(profile), AV_OPT_TYPE_INT, { .i64 = FF_PROFILE_UNKNOWN }, FF_PROFILE_UNKNOWN, 0xffff, VE, "profile" },
> +#define PROFILE(name, value)  name, NULL, 0, AV_OPT_TYPE_CONST, { .i64 = value }, 0, 0, VE, "profile"
> +        { PROFILE("constrained_baseline", FF_PROFILE_H264_CONSTRAINED_BASELINE) },
> +        { PROFILE("main",                 FF_PROFILE_H264_MAIN) },
> +        { PROFILE("high",                 FF_PROFILE_H264_HIGH) },
> +#undef PROFILE
>     { "max_nal_size", "set maximum NAL size in bytes", OFFSET(max_nal_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
>     { "allow_skip_frames", "allow skipping frames to hit the target bitrate", OFFSET(skip_frames), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
>     { "cabac", "Enable cabac", OFFSET(cabac), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
> @@ -176,10 +181,41 @@ FF_ENABLE_DEPRECATION_WARNINGS
>     param.iLoopFilterDisableIdc      = !s->loopfilter;
>     param.iEntropyCodingModeFlag     = 0;
>     param.iMultipleThreadIdc         = avctx->thread_count;
> -    if (s->profile && !strcmp(s->profile, "main"))
> +
> +    if (s->profile == FF_PROFILE_UNKNOWN)
> +        s->profile = !s->cabac ? FF_PROFILE_H264_CONSTRAINED_BASELINE :
> +#if OPENH264_VER_AT_LEAST(1, 8)
> +                                 FF_PROFILE_H264_HIGH;
> +#else
> +                                 FF_PROFILE_H264_MAIN;
> +#endif
> +
> +    switch (s->profile) {
> +#if OPENH264_VER_AT_LEAST(1, 8)
> +    case FF_PROFILE_H264_HIGH:
>         param.iEntropyCodingModeFlag = 1;
> -    else if (!s->profile && s->cabac)
> +        av_log(avctx, AV_LOG_VERBOSE, "Using CABAC, "
> +                "select EProfileIdc PRO_HIGH in libopenh264.\n");
> +        break;
> +#else
> +    case FF_PROFILE_H264_MAIN:
>         param.iEntropyCodingModeFlag = 1;
> +        av_log(avctx, AV_LOG_VERBOSE, "Using CABAC, "
> +                "select EProfileIdc PRO_MAIN in libopenh264.\n");
> +        break;
> +#endif
> +    case FF_PROFILE_H264_CONSTRAINED_BASELINE:
> +    case FF_PROFILE_UNKNOWN:
> +        param.iEntropyCodingModeFlag = 0;
> +        av_log(avctx, AV_LOG_VERBOSE, "Using CAVLC, "
> +               "select EProfileIdc PRO_BASELINE in libopenh264.\n");
> +        break;
> +    default:
> +        param.iEntropyCodingModeFlag = 0;
> +        av_log(avctx, AV_LOG_WARNING, "Unsupported profile, "
> +               "select EProfileIdc PRO_BASELINE in libopenh264.\n");
> +        break;
> +    }
>
>     param.sSpatialLayers[0].iVideoWidth         = param.iPicWidth;
>     param.sSpatialLayers[0].iVideoHeight        = param.iPicHeight;
> -- 
> 2.17.1

Thanks, this looks ok to me.

// Martin
Fu, Linjie May 12, 2020, 1:57 p.m. UTC | #2
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> Martin Storsjö
> Sent: Tuesday, May 12, 2020 17:36
> To: FFmpeg development discussions and patches <ffmpeg-
> devel@ffmpeg.org>
> Cc: Fu, Linjie <linjie.fu@intel.com>
> Subject: Re: [FFmpeg-devel] [PATCH v5 1/3] lavc/libopenh264enc: Rewrite
> profile handling
> 
> On Wed, 6 May 2020, Linjie Fu wrote:
> 
> > Support the profiles "constrained_baseline" and "high" for libopenh264
> > version >= 1.8, support "constrained_baseline" and "main" for earlier
> > version.
> >
> > If option not supported with current version, convert to constrained
> > baseline with a warning for users.
> >
> > Signed-off-by: Linjie Fu <linjie.fu@intel.com>
> > ---
> > libavcodec/libopenh264enc.c | 44
> +++++++++++++++++++++++++++++++++----
> > 1 file changed, 40 insertions(+), 4 deletions(-)
> >
> > diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
> > index 3bb3cceb64..12c71ca0e9 100644
> > --- a/libavcodec/libopenh264enc.c
> > +++ b/libavcodec/libopenh264enc.c
> > @@ -44,7 +44,7 @@ typedef struct SVCContext {
> >     ISVCEncoder *encoder;
> >     int slice_mode;
> >     int loopfilter;
> > -    char *profile;
> > +    int profile;
> >     int max_nal_size;
> >     int skip_frames;
> >     int skipped;
> > @@ -75,7 +75,12 @@ static const AVOption options[] = {
> > #endif
> > #endif
> >     { "loopfilter", "enable loop filter", OFFSET(loopfilter), AV_OPT_TYPE_INT,
> { .i64 = 1 }, 0, 1, VE },
> > -    { "profile", "set profile restrictions", OFFSET(profile),
> AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, VE },
> > +    { "profile", "set profile restrictions", OFFSET(profile), AV_OPT_TYPE_INT,
> { .i64 = FF_PROFILE_UNKNOWN }, FF_PROFILE_UNKNOWN, 0xffff, VE,
> "profile" },
> > +#define PROFILE(name, value)  name, NULL, 0, AV_OPT_TYPE_CONST,
> { .i64 = value }, 0, 0, VE, "profile"
> > +        { PROFILE("constrained_baseline",
> FF_PROFILE_H264_CONSTRAINED_BASELINE) },
> > +        { PROFILE("main",                 FF_PROFILE_H264_MAIN) },
> > +        { PROFILE("high",                 FF_PROFILE_H264_HIGH) },
> > +#undef PROFILE
> >     { "max_nal_size", "set maximum NAL size in bytes",
> OFFSET(max_nal_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
> >     { "allow_skip_frames", "allow skipping frames to hit the target bitrate",
> OFFSET(skip_frames), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
> >     { "cabac", "Enable cabac", OFFSET(cabac), AV_OPT_TYPE_INT, { .i64 = 0 },
> 0, 1, VE },
> > @@ -176,10 +181,41 @@ FF_ENABLE_DEPRECATION_WARNINGS
> >     param.iLoopFilterDisableIdc      = !s->loopfilter;
> >     param.iEntropyCodingModeFlag     = 0;
> >     param.iMultipleThreadIdc         = avctx->thread_count;
> > -    if (s->profile && !strcmp(s->profile, "main"))
> > +
> > +    if (s->profile == FF_PROFILE_UNKNOWN)
> > +        s->profile = !s->cabac ? FF_PROFILE_H264_CONSTRAINED_BASELINE :
> > +#if OPENH264_VER_AT_LEAST(1, 8)
> > +                                 FF_PROFILE_H264_HIGH;
> > +#else
> > +                                 FF_PROFILE_H264_MAIN;
> > +#endif
> > +
> > +    switch (s->profile) {
> > +#if OPENH264_VER_AT_LEAST(1, 8)
> > +    case FF_PROFILE_H264_HIGH:
> >         param.iEntropyCodingModeFlag = 1;
> > -    else if (!s->profile && s->cabac)
> > +        av_log(avctx, AV_LOG_VERBOSE, "Using CABAC, "
> > +                "select EProfileIdc PRO_HIGH in libopenh264.\n");
> > +        break;
> > +#else
> > +    case FF_PROFILE_H264_MAIN:
> >         param.iEntropyCodingModeFlag = 1;
> > +        av_log(avctx, AV_LOG_VERBOSE, "Using CABAC, "
> > +                "select EProfileIdc PRO_MAIN in libopenh264.\n");
> > +        break;
> > +#endif
> > +    case FF_PROFILE_H264_CONSTRAINED_BASELINE:
> > +    case FF_PROFILE_UNKNOWN:
> > +        param.iEntropyCodingModeFlag = 0;
> > +        av_log(avctx, AV_LOG_VERBOSE, "Using CAVLC, "
> > +               "select EProfileIdc PRO_BASELINE in libopenh264.\n");
> > +        break;
> > +    default:
> > +        param.iEntropyCodingModeFlag = 0;
> > +        av_log(avctx, AV_LOG_WARNING, "Unsupported profile, "
> > +               "select EProfileIdc PRO_BASELINE in libopenh264.\n");
> > +        break;
> > +    }
> >
> >     param.sSpatialLayers[0].iVideoWidth         = param.iPicWidth;
> >     param.sSpatialLayers[0].iVideoHeight        = param.iPicHeight;
> > --
> > 2.17.1
> 
> Thanks, this looks ok to me.
> 
> // Martin
> 
Thanks for the review.

- Linjie
Fu, Linjie May 13, 2020, 7:11 a.m. UTC | #3
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of Fu,
> Linjie
> Sent: Tuesday, May 12, 2020 21:58
> To: FFmpeg development discussions and patches <ffmpeg-
> devel@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH v5 1/3] lavc/libopenh264enc: Rewrite
> profile handling
> 
> > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> > Martin Storsjö
> > Sent: Tuesday, May 12, 2020 17:36
> > To: FFmpeg development discussions and patches <ffmpeg-
> > devel@ffmpeg.org>
> > Cc: Fu, Linjie <linjie.fu@intel.com>
> > Subject: Re: [FFmpeg-devel] [PATCH v5 1/3] lavc/libopenh264enc: Rewrite
> > profile handling
> >
> > On Wed, 6 May 2020, Linjie Fu wrote:
> >
> > > Support the profiles "constrained_baseline" and "high" for libopenh264
> > > version >= 1.8, support "constrained_baseline" and "main" for earlier
> > > version.
> > >
> > > If option not supported with current version, convert to constrained
> > > baseline with a warning for users.
> > >
> > > Signed-off-by: Linjie Fu <linjie.fu@intel.com>
> > > ---
> > > libavcodec/libopenh264enc.c | 44
> > +++++++++++++++++++++++++++++++++----
> > > 1 file changed, 40 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
> > > index 3bb3cceb64..12c71ca0e9 100644
> > > --- a/libavcodec/libopenh264enc.c
> > > +++ b/libavcodec/libopenh264enc.c
> > > @@ -44,7 +44,7 @@ typedef struct SVCContext {
> > >     ISVCEncoder *encoder;
> > >     int slice_mode;
> > >     int loopfilter;
> > > -    char *profile;
> > > +    int profile;
> > >     int max_nal_size;
> > >     int skip_frames;
> > >     int skipped;
> > > @@ -75,7 +75,12 @@ static const AVOption options[] = {
> > > #endif
> > > #endif
> > >     { "loopfilter", "enable loop filter", OFFSET(loopfilter),
> AV_OPT_TYPE_INT,
> > { .i64 = 1 }, 0, 1, VE },
> > > -    { "profile", "set profile restrictions", OFFSET(profile),
> > AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, VE },
> > > +    { "profile", "set profile restrictions", OFFSET(profile),
> AV_OPT_TYPE_INT,
> > { .i64 = FF_PROFILE_UNKNOWN }, FF_PROFILE_UNKNOWN, 0xffff, VE,
> > "profile" },
> > > +#define PROFILE(name, value)  name, NULL, 0, AV_OPT_TYPE_CONST,
> > { .i64 = value }, 0, 0, VE, "profile"
> > > +        { PROFILE("constrained_baseline",
> > FF_PROFILE_H264_CONSTRAINED_BASELINE) },
> > > +        { PROFILE("main",                 FF_PROFILE_H264_MAIN) },
> > > +        { PROFILE("high",                 FF_PROFILE_H264_HIGH) },
> > > +#undef PROFILE
> > >     { "max_nal_size", "set maximum NAL size in bytes",
> > OFFSET(max_nal_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
> > >     { "allow_skip_frames", "allow skipping frames to hit the target bitrate",
> > OFFSET(skip_frames), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
> > >     { "cabac", "Enable cabac", OFFSET(cabac), AV_OPT_TYPE_INT, { .i64 = 0 },
> > 0, 1, VE },
> > > @@ -176,10 +181,41 @@ FF_ENABLE_DEPRECATION_WARNINGS
> > >     param.iLoopFilterDisableIdc      = !s->loopfilter;
> > >     param.iEntropyCodingModeFlag     = 0;
> > >     param.iMultipleThreadIdc         = avctx->thread_count;
> > > -    if (s->profile && !strcmp(s->profile, "main"))
> > > +
> > > +    if (s->profile == FF_PROFILE_UNKNOWN)
> > > +        s->profile = !s->cabac ?
> FF_PROFILE_H264_CONSTRAINED_BASELINE :
> > > +#if OPENH264_VER_AT_LEAST(1, 8)
> > > +                                 FF_PROFILE_H264_HIGH;
> > > +#else
> > > +                                 FF_PROFILE_H264_MAIN;
> > > +#endif
> > > +
> > > +    switch (s->profile) {
> > > +#if OPENH264_VER_AT_LEAST(1, 8)
> > > +    case FF_PROFILE_H264_HIGH:
> > >         param.iEntropyCodingModeFlag = 1;
> > > -    else if (!s->profile && s->cabac)
> > > +        av_log(avctx, AV_LOG_VERBOSE, "Using CABAC, "
> > > +                "select EProfileIdc PRO_HIGH in libopenh264.\n");
> > > +        break;
> > > +#else
> > > +    case FF_PROFILE_H264_MAIN:
> > >         param.iEntropyCodingModeFlag = 1;
> > > +        av_log(avctx, AV_LOG_VERBOSE, "Using CABAC, "
> > > +                "select EProfileIdc PRO_MAIN in libopenh264.\n");
> > > +        break;
> > > +#endif
> > > +    case FF_PROFILE_H264_CONSTRAINED_BASELINE:
> > > +    case FF_PROFILE_UNKNOWN:
> > > +        param.iEntropyCodingModeFlag = 0;
> > > +        av_log(avctx, AV_LOG_VERBOSE, "Using CAVLC, "
> > > +               "select EProfileIdc PRO_BASELINE in libopenh264.\n");
> > > +        break;
> > > +    default:
> > > +        param.iEntropyCodingModeFlag = 0;
> > > +        av_log(avctx, AV_LOG_WARNING, "Unsupported profile, "
> > > +               "select EProfileIdc PRO_BASELINE in libopenh264.\n");
> > > +        break;
> > > +    }
> > >
> > >     param.sSpatialLayers[0].iVideoWidth         = param.iPicWidth;
> > >     param.sSpatialLayers[0].iVideoHeight        = param.iPicHeight;
> > > --
> > > 2.17.1
> >
> > Thanks, this looks ok to me.
> >
> > // Martin
> >
> Thanks for the review.
> 
Applied, thx.

- Linjie
diff mbox series

Patch

diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
index 3bb3cceb64..12c71ca0e9 100644
--- a/libavcodec/libopenh264enc.c
+++ b/libavcodec/libopenh264enc.c
@@ -44,7 +44,7 @@  typedef struct SVCContext {
     ISVCEncoder *encoder;
     int slice_mode;
     int loopfilter;
-    char *profile;
+    int profile;
     int max_nal_size;
     int skip_frames;
     int skipped;
@@ -75,7 +75,12 @@  static const AVOption options[] = {
 #endif
 #endif
     { "loopfilter", "enable loop filter", OFFSET(loopfilter), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, VE },
-    { "profile", "set profile restrictions", OFFSET(profile), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, VE },
+    { "profile", "set profile restrictions", OFFSET(profile), AV_OPT_TYPE_INT, { .i64 = FF_PROFILE_UNKNOWN }, FF_PROFILE_UNKNOWN, 0xffff, VE, "profile" },
+#define PROFILE(name, value)  name, NULL, 0, AV_OPT_TYPE_CONST, { .i64 = value }, 0, 0, VE, "profile"
+        { PROFILE("constrained_baseline", FF_PROFILE_H264_CONSTRAINED_BASELINE) },
+        { PROFILE("main",                 FF_PROFILE_H264_MAIN) },
+        { PROFILE("high",                 FF_PROFILE_H264_HIGH) },
+#undef PROFILE
     { "max_nal_size", "set maximum NAL size in bytes", OFFSET(max_nal_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
     { "allow_skip_frames", "allow skipping frames to hit the target bitrate", OFFSET(skip_frames), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
     { "cabac", "Enable cabac", OFFSET(cabac), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
@@ -176,10 +181,41 @@  FF_ENABLE_DEPRECATION_WARNINGS
     param.iLoopFilterDisableIdc      = !s->loopfilter;
     param.iEntropyCodingModeFlag     = 0;
     param.iMultipleThreadIdc         = avctx->thread_count;
-    if (s->profile && !strcmp(s->profile, "main"))
+
+    if (s->profile == FF_PROFILE_UNKNOWN)
+        s->profile = !s->cabac ? FF_PROFILE_H264_CONSTRAINED_BASELINE :
+#if OPENH264_VER_AT_LEAST(1, 8)
+                                 FF_PROFILE_H264_HIGH;
+#else
+                                 FF_PROFILE_H264_MAIN;
+#endif
+
+    switch (s->profile) {
+#if OPENH264_VER_AT_LEAST(1, 8)
+    case FF_PROFILE_H264_HIGH:
         param.iEntropyCodingModeFlag = 1;
-    else if (!s->profile && s->cabac)
+        av_log(avctx, AV_LOG_VERBOSE, "Using CABAC, "
+                "select EProfileIdc PRO_HIGH in libopenh264.\n");
+        break;
+#else
+    case FF_PROFILE_H264_MAIN:
         param.iEntropyCodingModeFlag = 1;
+        av_log(avctx, AV_LOG_VERBOSE, "Using CABAC, "
+                "select EProfileIdc PRO_MAIN in libopenh264.\n");
+        break;
+#endif
+    case FF_PROFILE_H264_CONSTRAINED_BASELINE:
+    case FF_PROFILE_UNKNOWN:
+        param.iEntropyCodingModeFlag = 0;
+        av_log(avctx, AV_LOG_VERBOSE, "Using CAVLC, "
+               "select EProfileIdc PRO_BASELINE in libopenh264.\n");
+        break;
+    default:
+        param.iEntropyCodingModeFlag = 0;
+        av_log(avctx, AV_LOG_WARNING, "Unsupported profile, "
+               "select EProfileIdc PRO_BASELINE in libopenh264.\n");
+        break;
+    }
 
     param.sSpatialLayers[0].iVideoWidth         = param.iPicWidth;
     param.sSpatialLayers[0].iVideoHeight        = param.iPicHeight;