diff mbox series

[FFmpeg-devel,v3,7/9] lavc/libopenh264enc: add profile high option support

Message ID 1586599419-21122-8-git-send-email-linjie.fu@intel.com
State Superseded
Headers show
Series patchset for the enhancement of libopenh264 encoder | expand

Checks

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

Commit Message

Fu, Linjie April 11, 2020, 10:03 a.m. UTC
Add support for PRO_HIGH/PRO_BASELINE in SVC Encoding extention mode,
which determined by iEntropyCodingModeFlag in ParamTranscode().

<https://github.com/cisco/openh264/blob/master/codec/encoder/core/inc/param_svc.h#L394>

Signed-off-by: Linjie Fu <linjie.fu@intel.com>
---
 libavcodec/libopenh264enc.c | 32 ++++++++++++++++++++++++++------
 1 file changed, 26 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
index c85ae0e..3a205b7 100644
--- a/libavcodec/libopenh264enc.c
+++ b/libavcodec/libopenh264enc.c
@@ -48,7 +48,7 @@  typedef struct SVCContext {
     int slice_mode;                 // deprecated
 #endif
     int loopfilter;
-    char *profile;
+    int profile;
     int max_nal_size;
     int skip_frames;
     int skipped;
@@ -79,7 +79,11 @@  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("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 },
@@ -115,12 +119,28 @@  static av_cold int svc_encode_init_profile(AVCodecContext *avctx, SEncParamExt *
 {
     SVCContext *s = avctx->priv_data;
 
-    if (s->profile && !strcmp(s->profile, "main"))
-        param->iEntropyCodingModeFlag = 1; //< 0:CAVLC  1:CABAC
-    else if (!s->profile && s->cabac)
+    if (s->profile == FF_PROFILE_UNKNOWN)
+        s->profile = s->cabac ? FF_PROFILE_H264_HIGH :
+                                FF_PROFILE_H264_CONSTRAINED_BASELINE;
+
+    switch (s->profile) {
+    case FF_PROFILE_H264_HIGH:
         param->iEntropyCodingModeFlag = 1;
-    else
+        av_log(avctx, AV_LOG_VERBOSE, "Using CABAC, "
+               "select EProfileIdc PRO_HIGH in libopenh264.\n");
+        break;
+    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;
+    }
 
     return 0;
 }