diff mbox series

[FFmpeg-devel,v5,3/3] lavc/libopenh264enc: Add coder option to replace cabac

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

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
Set DEPRECATED flag to option cabac, replace with coder. The
priority logic is:
1. s->coder; then
2. avctx->coder_type; then
3. s->cabac.

Change the default option to -1 and allow the default cabac to be
determined by profile.

Add FF_API_OPENH264_CABAC macro for cabac to remove this option after
LIBAVCODEC_VERSION_MAJOR = 59.

Signed-off-by: Linjie Fu <linjie.fu@intel.com>
---
 libavcodec/libopenh264enc.c | 40 +++++++++++++++++++++++++------------
 libavcodec/version.h        |  3 +++
 2 files changed, 30 insertions(+), 13 deletions(-)

Comments

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

> Set DEPRECATED flag to option cabac, replace with coder. The
> priority logic is:
> 1. s->coder; then
> 2. avctx->coder_type; then
> 3. s->cabac.
>
> Change the default option to -1 and allow the default cabac to be
> determined by profile.
>
> Add FF_API_OPENH264_CABAC macro for cabac to remove this option after
> LIBAVCODEC_VERSION_MAJOR = 59.
>
> Signed-off-by: Linjie Fu <linjie.fu@intel.com>
> ---
> libavcodec/libopenh264enc.c | 40 +++++++++++++++++++++++++------------
> libavcodec/version.h        |  3 +++
> 2 files changed, 30 insertions(+), 13 deletions(-)

I guess this looks ok - thanks!

// Martin
diff mbox series

Patch

diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
index 4c57fa1c89..f63aa52348 100644
--- a/libavcodec/libopenh264enc.c
+++ b/libavcodec/libopenh264enc.c
@@ -48,7 +48,10 @@  typedef struct SVCContext {
     int max_nal_size;
     int skip_frames;
     int skipped;
-    int cabac;
+#if FF_API_OPENH264_CABAC
+    int cabac;                      // deprecated
+#endif
+    int coder;
 
     // rate control mode
     int rc_mode;
@@ -83,7 +86,15 @@  static const AVOption options[] = {
 #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 },
+#if FF_API_OPENH264_CABAC
+    { "cabac", "Enable cabac(deprecated, use coder)", OFFSET(cabac), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE|DEPRECATED },
+#endif
+    { "coder", "Coder type",  OFFSET(coder), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE, "coder" },
+        { "default",          NULL, 0, AV_OPT_TYPE_CONST, { .i64 = -1 }, INT_MIN, INT_MAX, VE, "coder" },
+        { "cavlc",            NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 },  INT_MIN, INT_MAX, VE, "coder" },
+        { "cabac",            NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 },  INT_MIN, INT_MAX, VE, "coder" },
+        { "vlc",              NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 },  INT_MIN, INT_MAX, VE, "coder" },
+        { "ac",               NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 },  INT_MIN, INT_MAX, VE, "coder" },
 
     { "rc_mode", "Select rate control mode", OFFSET(rc_mode), AV_OPT_TYPE_INT, { .i64 = RC_QUALITY_MODE }, RC_OFF_MODE, RC_TIMESTAMP_MODE, VE, "rc_mode" },
         { "off",       "bit rate control off",                                                 0, AV_OPT_TYPE_CONST, { .i64 = RC_OFF_MODE },         0, 0, VE, "rc_mode" },
@@ -145,13 +156,6 @@  static av_cold int svc_encode_init(AVCodecContext *avctx)
 
     (*s->encoder)->GetDefaultParams(s->encoder, &param);
 
-#if FF_API_CODER_TYPE
-FF_DISABLE_DEPRECATION_WARNINGS
-    if (!s->cabac)
-        s->cabac = avctx->coder_type == FF_CODER_TYPE_AC;
-FF_ENABLE_DEPRECATION_WARNINGS
-#endif
-
     param.fMaxFrameRate              = 1/av_q2d(avctx->time_base);
     param.iPicWidth                  = avctx->width;
     param.iPicHeight                 = avctx->height;
@@ -197,12 +201,22 @@  FF_ENABLE_DEPRECATION_WARNINGS
             break;
         }
 
-    if (s->profile == FF_PROFILE_UNKNOWN)
-        s->profile = !s->cabac ? FF_PROFILE_H264_CONSTRAINED_BASELINE :
+#if FF_API_CODER_TYPE && FF_API_OPENH264_CABAC
+FF_DISABLE_DEPRECATION_WARNINGS
+    if (s->coder < 0 && avctx->coder_type == FF_CODER_TYPE_AC)
+        s->coder = 1;
+
+    if (s->coder < 0)
+        s->coder = s->cabac;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
+    if (s->profile == FF_PROFILE_UNKNOWN && s->coder >= 0)
+        s->profile = s->coder == 0 ? FF_PROFILE_H264_CONSTRAINED_BASELINE :
 #if OPENH264_VER_AT_LEAST(1, 8)
-                                 FF_PROFILE_H264_HIGH;
+                                     FF_PROFILE_H264_HIGH;
 #else
-                                 FF_PROFILE_H264_MAIN;
+                                     FF_PROFILE_H264_MAIN;
 #endif
 
     switch (s->profile) {
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 5ffff21342..622c85d5ff 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -138,6 +138,9 @@ 
 #ifndef FF_API_OPENH264_SLICE_MODE
 #define FF_API_OPENH264_SLICE_MODE (LIBAVCODEC_VERSION_MAJOR < 59)
 #endif
+#ifndef FF_API_OPENH264_CABAC
+#define FF_API_OPENH264_CABAC      (LIBAVCODEC_VERSION_MAJOR < 59)
+#endif
 
 
 #endif /* AVCODEC_VERSION_H */