diff mbox series

[FFmpeg-devel,v2] avformat/libsrt: add snddropdelay parameter for srt

Message ID 1633835847-16243-1-git-send-email-lance.lmwang@gmail.com
State New
Headers show
Series [FFmpeg-devel,v2] avformat/libsrt: add snddropdelay parameter for srt
Related show

Commit Message

Limin Wang Oct. 10, 2021, 3:17 a.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 doc/protocols.texi   | 9 +++++++++
 libavformat/libsrt.c | 7 +++++++
 2 files changed, 16 insertions(+)

Comments

zhilizhao(赵志立) Oct. 10, 2021, 1:46 p.m. UTC | #1
> On Oct 10, 2021, at 11:17 AM, lance.lmwang@gmail.com wrote:
> 
> From: Limin Wang <lance.lmwang@gmail.com>
> 
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
> doc/protocols.texi   | 9 +++++++++
> libavformat/libsrt.c | 7 +++++++
> 2 files changed, 16 insertions(+)
> 
> diff --git a/doc/protocols.texi b/doc/protocols.texi
> index 726e5f1..7951abb 100644
> --- a/doc/protocols.texi
> +++ b/doc/protocols.texi
> @@ -1496,6 +1496,15 @@ when the old encryption key is decommissioned. Default is -1.
> -1 means auto (0x1000 in srt library). The range for
> this option is integers in the 0 - @code{INT_MAX}.
> 
> +@item snddropdelay=@var{microseconds}
> +The sender's delay before dropping packets. This delay is

snddropdelay is NOT the delay before dropping packets, it’s
an extra delay.

> +added to the default drop delay time interval value.
> +
> +Default is -2 which typically means it's unset and use the
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> +the default by libsrt(Default: 0 in Live mode, -1 in File mode).
     ^^^^^^^^^^
> +

which means using the default.

On the other hand, -2 is an implementation detail and not a real
value for snddropdelay, so it doesn’t need to be mentioned in the
doc.

> +Special value -1: Do not drop packets on the sender at all.
> +
> @item payload_size=@var{bytes}
> Sets the maximum declared size of a packet transferred
> during the single call to the sending function in Live
> diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c
> index c6308d1..c2e633b 100644
> --- a/libavformat/libsrt.c
> +++ b/libavformat/libsrt.c
> @@ -65,6 +65,7 @@ typedef struct SRTContext {
>     int enforced_encryption;
>     int kmrefreshrate;
>     int kmpreannounce;
> +    int64_t snddropdelay;
> #endif
>     int mss;
>     int ffs;
> @@ -111,6 +112,7 @@ static const AVOption libsrt_options[] = {
>     { "enforced_encryption", "Enforces that both connection parties have the same passphrase set",                              OFFSET(enforced_encryption), AV_OPT_TYPE_BOOL,  { .i64 = -1 }, -1, 1,         .flags = D|E },
>     { "kmrefreshrate",       "The number of packets to be transmitted after which the encryption key is switched to a new key", OFFSET(kmrefreshrate),       AV_OPT_TYPE_INT,   { .i64 = -1 }, -1, INT_MAX,   .flags = D|E },
>     { "kmpreannounce",       "The interval between when a new encryption key is sent and when switchover occurs",               OFFSET(kmpreannounce),       AV_OPT_TYPE_INT,   { .i64 = -1 }, -1, INT_MAX,   .flags = D|E },
> +    { "snddropdelay",        "The sender's delay(in microseconds) before dropping packets",                                     OFFSET(snddropdelay),        AV_OPT_TYPE_INT64,   { .i64 = -2 }, -2, INT64_MAX,   .flags = D|E },
> #endif
>     { "mss",            "The Maximum Segment Size",                                             OFFSET(mss),              AV_OPT_TYPE_INT,      { .i64 = -1 }, -1, 1500,      .flags = D|E },
>     { "ffs",            "Flight flag size (window size) (in bytes)",                            OFFSET(ffs),              AV_OPT_TYPE_INT,      { .i64 = -1 }, -1, INT_MAX,   .flags = D|E },
> @@ -318,6 +320,7 @@ static int libsrt_set_options_pre(URLContext *h, int fd)
>     int latency = s->latency / 1000;
>     int rcvlatency = s->rcvlatency / 1000;
>     int peerlatency = s->peerlatency / 1000;
> +    int snddropdelay = s->snddropdelay > 0 ? s->snddropdelay / 1000 : s->snddropdelay;
>     int connect_timeout = s->connect_timeout;
> 
>     if ((s->mode == SRT_MODE_RENDEZVOUS && libsrt_setsockopt(h, fd, SRTO_RENDEZVOUS, "SRTO_RENDEZVOUS", &yes, sizeof(yes)) < 0) ||
> @@ -334,6 +337,7 @@ static int libsrt_set_options_pre(URLContext *h, int fd)
> #endif
>         (s->kmrefreshrate >= 0 && libsrt_setsockopt(h, fd, SRTO_KMREFRESHRATE, "SRTO_KMREFRESHRATE", &s->kmrefreshrate, sizeof(s->kmrefreshrate)) < 0) ||
>         (s->kmpreannounce >= 0 && libsrt_setsockopt(h, fd, SRTO_KMPREANNOUNCE, "SRTO_KMPREANNOUNCE", &s->kmpreannounce, sizeof(s->kmpreannounce)) < 0) ||
> +        (s->snddropdelay  >=-1 && libsrt_setsockopt(h, fd, SRTO_SNDDROPDELAY,  "SRTO_SNDDROPDELAY",  &snddropdelay, sizeof(snddropdelay)) < 0) ||
> #endif
>         (s->mss >= 0 && libsrt_setsockopt(h, fd, SRTO_MSS, "SRTO_MSS", &s->mss, sizeof(s->mss)) < 0) ||
>         (s->ffs >= 0 && libsrt_setsockopt(h, fd, SRTO_FC, "SRTO_FC", &s->ffs, sizeof(s->ffs)) < 0) ||
> @@ -549,6 +553,9 @@ static int libsrt_open(URLContext *h, const char *uri, int flags)
>         if (av_find_info_tag(buf, sizeof(buf), "kmpreannounce", p)) {
>             s->kmpreannounce = strtol(buf, NULL, 10);
>         }
> +        if (av_find_info_tag(buf, sizeof(buf), "snddropdelay", p)) {
> +            s->snddropdelay = strtoll(buf, NULL, 10);
> +        }
> #endif
>         if (av_find_info_tag(buf, sizeof(buf), "mss", p)) {
>             s->mss = strtol(buf, NULL, 10);
> -- 
> 1.8.3.1
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
Limin Wang Oct. 10, 2021, 2:57 p.m. UTC | #2
On Sun, Oct 10, 2021 at 09:46:26PM +0800, "zhilizhao(赵志立)" wrote:
> 
> 
> > On Oct 10, 2021, at 11:17 AM, lance.lmwang@gmail.com wrote:
> > 
> > From: Limin Wang <lance.lmwang@gmail.com>
> > 
> > Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> > ---
> > doc/protocols.texi   | 9 +++++++++
> > libavformat/libsrt.c | 7 +++++++
> > 2 files changed, 16 insertions(+)
> > 
> > diff --git a/doc/protocols.texi b/doc/protocols.texi
> > index 726e5f1..7951abb 100644
> > --- a/doc/protocols.texi
> > +++ b/doc/protocols.texi
> > @@ -1496,6 +1496,15 @@ when the old encryption key is decommissioned. Default is -1.
> > -1 means auto (0x1000 in srt library). The range for
> > this option is integers in the 0 - @code{INT_MAX}.
> > 
> > +@item snddropdelay=@var{microseconds}
> > +The sender's delay before dropping packets. This delay is
> 
> snddropdelay is NOT the delay before dropping packets, it’s
> an extra delay.

If you prefer to add extra before delay, I'm OK with that.

In fact, it's coming the short description of apps/srt-live-transmit.md for snddropdelay.

More description are coming from API/API-socket-options.md:
Sets an extra delay before TLPKTDROP is triggered on the data sender. This delay is added to the default drop delay time interval value. Keep in mind that the longer the delay, the more probable it becomes that packets would be retransmitted uselessly because they will be dropped by the receiver anyway.

For you think it's not good for the "Keep in mind...", so I remove it anyway.

> 
> > +added to the default drop delay time interval value.
> > +
> > +Default is -2 which typically means it's unset and use the
>                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > +the default by libsrt(Default: 0 in Live mode, -1 in File mode).
>      ^^^^^^^^^^
> > +
> 
> which means using the default.
> 
> On the other hand, -2 is an implementation detail and not a real
> value for snddropdelay, so it doesn’t need to be mentioned in the
> doc.

OK, will remove about -2.

> 
> > +Special value -1: Do not drop packets on the sender at all.
> > +
> > @item payload_size=@var{bytes}
> > Sets the maximum declared size of a packet transferred
> > during the single call to the sending function in Live
> > diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c
> > index c6308d1..c2e633b 100644
> > --- a/libavformat/libsrt.c
> > +++ b/libavformat/libsrt.c
> > @@ -65,6 +65,7 @@ typedef struct SRTContext {
> >     int enforced_encryption;
> >     int kmrefreshrate;
> >     int kmpreannounce;
> > +    int64_t snddropdelay;
> > #endif
> >     int mss;
> >     int ffs;
> > @@ -111,6 +112,7 @@ static const AVOption libsrt_options[] = {
> >     { "enforced_encryption", "Enforces that both connection parties have the same passphrase set",                              OFFSET(enforced_encryption), AV_OPT_TYPE_BOOL,  { .i64 = -1 }, -1, 1,         .flags = D|E },
> >     { "kmrefreshrate",       "The number of packets to be transmitted after which the encryption key is switched to a new key", OFFSET(kmrefreshrate),       AV_OPT_TYPE_INT,   { .i64 = -1 }, -1, INT_MAX,   .flags = D|E },
> >     { "kmpreannounce",       "The interval between when a new encryption key is sent and when switchover occurs",               OFFSET(kmpreannounce),       AV_OPT_TYPE_INT,   { .i64 = -1 }, -1, INT_MAX,   .flags = D|E },
> > +    { "snddropdelay",        "The sender's delay(in microseconds) before dropping packets",                                     OFFSET(snddropdelay),        AV_OPT_TYPE_INT64,   { .i64 = -2 }, -2, INT64_MAX,   .flags = D|E },
> > #endif
> >     { "mss",            "The Maximum Segment Size",                                             OFFSET(mss),              AV_OPT_TYPE_INT,      { .i64 = -1 }, -1, 1500,      .flags = D|E },
> >     { "ffs",            "Flight flag size (window size) (in bytes)",                            OFFSET(ffs),              AV_OPT_TYPE_INT,      { .i64 = -1 }, -1, INT_MAX,   .flags = D|E },
> > @@ -318,6 +320,7 @@ static int libsrt_set_options_pre(URLContext *h, int fd)
> >     int latency = s->latency / 1000;
> >     int rcvlatency = s->rcvlatency / 1000;
> >     int peerlatency = s->peerlatency / 1000;
> > +    int snddropdelay = s->snddropdelay > 0 ? s->snddropdelay / 1000 : s->snddropdelay;
> >     int connect_timeout = s->connect_timeout;
> > 
> >     if ((s->mode == SRT_MODE_RENDEZVOUS && libsrt_setsockopt(h, fd, SRTO_RENDEZVOUS, "SRTO_RENDEZVOUS", &yes, sizeof(yes)) < 0) ||
> > @@ -334,6 +337,7 @@ static int libsrt_set_options_pre(URLContext *h, int fd)
> > #endif
> >         (s->kmrefreshrate >= 0 && libsrt_setsockopt(h, fd, SRTO_KMREFRESHRATE, "SRTO_KMREFRESHRATE", &s->kmrefreshrate, sizeof(s->kmrefreshrate)) < 0) ||
> >         (s->kmpreannounce >= 0 && libsrt_setsockopt(h, fd, SRTO_KMPREANNOUNCE, "SRTO_KMPREANNOUNCE", &s->kmpreannounce, sizeof(s->kmpreannounce)) < 0) ||
> > +        (s->snddropdelay  >=-1 && libsrt_setsockopt(h, fd, SRTO_SNDDROPDELAY,  "SRTO_SNDDROPDELAY",  &snddropdelay, sizeof(snddropdelay)) < 0) ||
> > #endif
> >         (s->mss >= 0 && libsrt_setsockopt(h, fd, SRTO_MSS, "SRTO_MSS", &s->mss, sizeof(s->mss)) < 0) ||
> >         (s->ffs >= 0 && libsrt_setsockopt(h, fd, SRTO_FC, "SRTO_FC", &s->ffs, sizeof(s->ffs)) < 0) ||
> > @@ -549,6 +553,9 @@ static int libsrt_open(URLContext *h, const char *uri, int flags)
> >         if (av_find_info_tag(buf, sizeof(buf), "kmpreannounce", p)) {
> >             s->kmpreannounce = strtol(buf, NULL, 10);
> >         }
> > +        if (av_find_info_tag(buf, sizeof(buf), "snddropdelay", p)) {
> > +            s->snddropdelay = strtoll(buf, NULL, 10);
> > +        }
> > #endif
> >         if (av_find_info_tag(buf, sizeof(buf), "mss", p)) {
> >             s->mss = strtol(buf, NULL, 10);
> > -- 
> > 1.8.3.1
> > 
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> > 
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> > 
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox series

Patch

diff --git a/doc/protocols.texi b/doc/protocols.texi
index 726e5f1..7951abb 100644
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@ -1496,6 +1496,15 @@  when the old encryption key is decommissioned. Default is -1.
 -1 means auto (0x1000 in srt library). The range for
 this option is integers in the 0 - @code{INT_MAX}.
 
+@item snddropdelay=@var{microseconds}
+The sender's delay before dropping packets. This delay is
+added to the default drop delay time interval value.
+
+Default is -2 which typically means it's unset and use the
+the default by libsrt(Default: 0 in Live mode, -1 in File mode).
+
+Special value -1: Do not drop packets on the sender at all.
+
 @item payload_size=@var{bytes}
 Sets the maximum declared size of a packet transferred
 during the single call to the sending function in Live
diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c
index c6308d1..c2e633b 100644
--- a/libavformat/libsrt.c
+++ b/libavformat/libsrt.c
@@ -65,6 +65,7 @@  typedef struct SRTContext {
     int enforced_encryption;
     int kmrefreshrate;
     int kmpreannounce;
+    int64_t snddropdelay;
 #endif
     int mss;
     int ffs;
@@ -111,6 +112,7 @@  static const AVOption libsrt_options[] = {
     { "enforced_encryption", "Enforces that both connection parties have the same passphrase set",                              OFFSET(enforced_encryption), AV_OPT_TYPE_BOOL,  { .i64 = -1 }, -1, 1,         .flags = D|E },
     { "kmrefreshrate",       "The number of packets to be transmitted after which the encryption key is switched to a new key", OFFSET(kmrefreshrate),       AV_OPT_TYPE_INT,   { .i64 = -1 }, -1, INT_MAX,   .flags = D|E },
     { "kmpreannounce",       "The interval between when a new encryption key is sent and when switchover occurs",               OFFSET(kmpreannounce),       AV_OPT_TYPE_INT,   { .i64 = -1 }, -1, INT_MAX,   .flags = D|E },
+    { "snddropdelay",        "The sender's delay(in microseconds) before dropping packets",                                     OFFSET(snddropdelay),        AV_OPT_TYPE_INT64,   { .i64 = -2 }, -2, INT64_MAX,   .flags = D|E },
 #endif
     { "mss",            "The Maximum Segment Size",                                             OFFSET(mss),              AV_OPT_TYPE_INT,      { .i64 = -1 }, -1, 1500,      .flags = D|E },
     { "ffs",            "Flight flag size (window size) (in bytes)",                            OFFSET(ffs),              AV_OPT_TYPE_INT,      { .i64 = -1 }, -1, INT_MAX,   .flags = D|E },
@@ -318,6 +320,7 @@  static int libsrt_set_options_pre(URLContext *h, int fd)
     int latency = s->latency / 1000;
     int rcvlatency = s->rcvlatency / 1000;
     int peerlatency = s->peerlatency / 1000;
+    int snddropdelay = s->snddropdelay > 0 ? s->snddropdelay / 1000 : s->snddropdelay;
     int connect_timeout = s->connect_timeout;
 
     if ((s->mode == SRT_MODE_RENDEZVOUS && libsrt_setsockopt(h, fd, SRTO_RENDEZVOUS, "SRTO_RENDEZVOUS", &yes, sizeof(yes)) < 0) ||
@@ -334,6 +337,7 @@  static int libsrt_set_options_pre(URLContext *h, int fd)
 #endif
         (s->kmrefreshrate >= 0 && libsrt_setsockopt(h, fd, SRTO_KMREFRESHRATE, "SRTO_KMREFRESHRATE", &s->kmrefreshrate, sizeof(s->kmrefreshrate)) < 0) ||
         (s->kmpreannounce >= 0 && libsrt_setsockopt(h, fd, SRTO_KMPREANNOUNCE, "SRTO_KMPREANNOUNCE", &s->kmpreannounce, sizeof(s->kmpreannounce)) < 0) ||
+        (s->snddropdelay  >=-1 && libsrt_setsockopt(h, fd, SRTO_SNDDROPDELAY,  "SRTO_SNDDROPDELAY",  &snddropdelay, sizeof(snddropdelay)) < 0) ||
 #endif
         (s->mss >= 0 && libsrt_setsockopt(h, fd, SRTO_MSS, "SRTO_MSS", &s->mss, sizeof(s->mss)) < 0) ||
         (s->ffs >= 0 && libsrt_setsockopt(h, fd, SRTO_FC, "SRTO_FC", &s->ffs, sizeof(s->ffs)) < 0) ||
@@ -549,6 +553,9 @@  static int libsrt_open(URLContext *h, const char *uri, int flags)
         if (av_find_info_tag(buf, sizeof(buf), "kmpreannounce", p)) {
             s->kmpreannounce = strtol(buf, NULL, 10);
         }
+        if (av_find_info_tag(buf, sizeof(buf), "snddropdelay", p)) {
+            s->snddropdelay = strtoll(buf, NULL, 10);
+        }
 #endif
         if (av_find_info_tag(buf, sizeof(buf), "mss", p)) {
             s->mss = strtol(buf, NULL, 10);