[FFmpeg-devel] [PATCH v2] avformat/libsrt: add mininputbw option

Zhao Zhili quinkblack at foxmail.com
Wed Jul 14 12:07:40 EEST 2021


---
v2: add doc

It's useful when tlpktdrop=0&maxbw=0 and network bandwidth is smaller
than input stream rate. Without this option, the estimated input rate
can drop to near zero.
https://github.com/Haivision/srt/issues/2057

 doc/protocols.texi   |  4 ++++
 libavformat/libsrt.c | 16 ++++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/doc/protocols.texi b/doc/protocols.texi
index 726e5f1c44..f431c15fe4 100644
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@ -1414,6 +1414,10 @@ if @option{inputbw} is not set while @option{maxbw} is set to
 relative (0), the actual input rate is evaluated inside
 the library. Default value is 0.
 
+ at item mininputbw=@var{bytes/seconds}
+This option is effective only if both @option{maxbw} and @option{inputbw}
+are set to 0. It's the minimum value of the estimated input stream rate.
+
 @item iptos=@var{tos}
 IP Type of Service. Applies to sender only. Default value is 0xB8.
 
diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c
index 8dee6aa3f3..5113858d97 100644
--- a/libavformat/libsrt.c
+++ b/libavformat/libsrt.c
@@ -72,6 +72,9 @@ typedef struct SRTContext {
     int ipttl;
     int iptos;
     int64_t inputbw;
+#if SRT_VERSION_VALUE >= 0x010403
+    int64_t mininputbw;
+#endif
     int oheadbw;
     int64_t latency;
     int tlpktdrop;
@@ -118,6 +121,9 @@ static const AVOption libsrt_options[] = {
     { "ipttl",          "IP Time To Live",                                                      OFFSET(ipttl),            AV_OPT_TYPE_INT,      { .i64 = -1 }, -1, 255,       .flags = D|E },
     { "iptos",          "IP Type of Service",                                                   OFFSET(iptos),            AV_OPT_TYPE_INT,      { .i64 = -1 }, -1, 255,       .flags = D|E },
     { "inputbw",        "Estimated input stream rate",                                          OFFSET(inputbw),          AV_OPT_TYPE_INT64,    { .i64 = -1 }, -1, INT64_MAX, .flags = D|E },
+#if SRT_VERSION_VALUE >= 0x010403
+    { "mininputbw",     "Minimum value of the estimated input stream rate",                     OFFSET(mininputbw),       AV_OPT_TYPE_INT64,    { .i64 = -1 }, -1, INT64_MAX, .flags = D|E },
+#endif
     { "oheadbw",        "MaxBW ceiling based on % over input stream rate",                      OFFSET(oheadbw),          AV_OPT_TYPE_INT,      { .i64 = -1 }, -1, 100,       .flags = D|E },
     { "latency",        "receiver delay (in microseconds) to absorb bursts of missed packet retransmissions",                     OFFSET(latency),          AV_OPT_TYPE_INT64, { .i64 = -1 }, -1, INT64_MAX, .flags = D|E },
     { "tsbpddelay",     "deprecated, same effect as latency option",                            OFFSET(latency),          AV_OPT_TYPE_INT64, { .i64 = -1 }, -1, INT64_MAX, .flags = D|E },
@@ -297,6 +303,9 @@ static int libsrt_set_options_post(URLContext *h, int fd)
     SRTContext *s = h->priv_data;
 
     if ((s->inputbw >= 0 && libsrt_setsockopt(h, fd, SRTO_INPUTBW, "SRTO_INPUTBW", &s->inputbw, sizeof(s->inputbw)) < 0) ||
+#if SRT_VERSION_VALUE >= 0x010403
+        (s->mininputbw >= 0 && libsrt_setsockopt(h, fd, SRTO_MININPUTBW, "SRTO_MININPUTBW", &s->mininputbw, sizeof(s->mininputbw)) < 0) ||
+#endif
         (s->oheadbw >= 0 && libsrt_setsockopt(h, fd, SRTO_OHEADBW, "SRTO_OHEADBW", &s->oheadbw, sizeof(s->oheadbw)) < 0)) {
         return AVERROR(EIO);
     }
@@ -560,6 +569,13 @@ static int libsrt_open(URLContext *h, const char *uri, int flags)
         if (av_find_info_tag(buf, sizeof(buf), "inputbw", p)) {
             s->inputbw = strtoll(buf, NULL, 10);
         }
+        if (av_find_info_tag(buf, sizeof(buf), "mininputbw", p)) {
+#if SRT_VERSION_VALUE >= 0x010403
+            s->mininputbw = strtoll(buf, NULL, 10);
+#else
+            av_log(h, AV_LOG_WARNING, "mininputbw unsupported for libsrt version %s\n", SRT_VERSION_STRING);
+#endif
+        }
         if (av_find_info_tag(buf, sizeof(buf), "oheadbw", p)) {
             s->oheadbw = strtoll(buf, NULL, 10);
         }
-- 
2.31.1



More information about the ffmpeg-devel mailing list