[FFmpeg-devel] libavcodec/libopenh264enc: Allow client to enable/disable openh264 load balancing.

Submitted by Gregory J. Wolfe on Dec. 14, 2016, 7:27 p.m.

Details

Message ID 1481743679-4864-1-git-send-email-gregory.wolfe@kodakalaris.com
State New
Headers show

Commit Message

Gregory J. Wolfe Dec. 14, 2016, 7:27 p.m.
The libopenh264 library allows the client to enable or disable
load balancing when running multi-threaded.  When enabled, the
slice sizes are dynamically adjusted in order to use the
multiple threads more efficiently.  However, this can also lead
to valid but slightly different results from run to run.
Disabling load balancing prevents dynamic slice adjustment and
yields repeatable results when running multi-threaded, which can
be important when running test cases.

Signed-off-by: Gregory J. Wolfe <gregory.wolfe@kodakalaris.com>
---
 libavcodec/libopenh264enc.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Patch hide | download patch | download mbox

diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
index 648f59b..e84de27 100644
--- a/libavcodec/libopenh264enc.c
+++ b/libavcodec/libopenh264enc.c
@@ -47,6 +47,7 @@  typedef struct SVCContext {
     int skip_frames;
     int skipped;
     int cabac;
+    int load_balancing;
 } SVCContext;
 
 #define OFFSET(x) offsetof(SVCContext, x)
@@ -71,6 +72,7 @@  static const AVOption options[] = {
     { "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 },
+    { "load_balancing", "enable/disable dynamic slice adjustment for efficient use of multiple threads; if enabled, can produce valid but slightly different results from run to run", OFFSET(load_balancing), AV_OPT_TYPE_BOOL, { .i64 = -1 }, 0, 1, VE },
     { NULL }
 };
 
@@ -150,6 +152,12 @@  FF_ENABLE_DEPRECATION_WARNINGS
     param.iLoopFilterDisableIdc      = !s->loopfilter;
     param.iEntropyCodingModeFlag     = 0;
     param.iMultipleThreadIdc         = avctx->thread_count;
+#if OPENH264_VER_AT_LEAST(1, 6)
+    param.bUseLoadBalancing          = s->load_balancing; // default is enabled; -1 means not specified by client
+#else
+    if  ( s->load_balancing != -1 )
+        av_log(avctx, AV_LOG_WARNING, "load_balancing = %d specified, but not supported prior to libopenh264 v1.6\n", s->load_balancing);
+#endif
     if (s->profile && !strcmp(s->profile, "main"))
         param.iEntropyCodingModeFlag = 1;
     else if (!s->profile && s->cabac)