Message ID | 1575207104-9734-2-git-send-email-mypopydev@gmail.com |
---|---|
State | Superseded |
Headers | show |
On Sun, 01. Dec 21:31, Jun Zhao wrote: > From: Jun Zhao <barryjzhao@tencent.com> > > add linger parameter to libsrt, it's setting he number of seconds > that the socket waits for unsent data when closing. minor spelling > > Signed-off-by: Jun Zhao <barryjzhao@tencent.com> > --- > doc/protocols.texi | 4 ++++ > libavformat/libsrt.c | 13 +++++++++++++ > 2 files changed, 17 insertions(+), 0 deletions(-) > > diff --git a/doc/protocols.texi b/doc/protocols.texi > index 0e18a49..f34f246 100644 > --- a/doc/protocols.texi > +++ b/doc/protocols.texi > @@ -1426,6 +1426,10 @@ the overhead transmission (retransmitted and control packets). > file: Set options as for non-live transmission. See @option{messageapi} > for further explanations > > +@item linger=@var{seconds} > +The number of seconds that the socket waits for unsent data when closing. > +Default is -1. I'd add infinite in brackets. > + > @end table > > For more information see: @url{https://github.com/Haivision/srt}. > diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c > index 1c34ec5..0a748a1 100644 > --- a/libavformat/libsrt.c > +++ b/libavformat/libsrt.c > @@ -84,6 +84,7 @@ typedef struct SRTContext { > char *smoother; > int messageapi; > SRT_TRANSTYPE transtype; > + int linger; > } SRTContext; > > #define D AV_OPT_FLAG_DECODING_PARAM > @@ -128,6 +129,7 @@ static const AVOption libsrt_options[] = { > { "transtype", "The transmission type for the socket", OFFSET(transtype), AV_OPT_TYPE_INT, { .i64 = SRTT_INVALID }, SRTT_LIVE, SRTT_INVALID, .flags = D|E, "transtype" }, > { "live", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = SRTT_LIVE }, INT_MIN, INT_MAX, .flags = D|E, "transtype" }, > { "file", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = SRTT_FILE }, INT_MIN, INT_MAX, .flags = D|E, "transtype" }, > + { "linger", "Number of seconds that the socket waits for unsent data when closing", OFFSET(linger), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E }, > { NULL } > }; > Are some other parameters (latency, rcvlatency, connect_timeout) in milliseconds? (It's not that clear from the docs). If yes, it may be good to set linger to milliseconds as well.
On Mon, Dec 2, 2019 at 12:57 PM Andriy Gelman <andriy.gelman@gmail.com> wrote: > > On Sun, 01. Dec 21:31, Jun Zhao wrote: > > From: Jun Zhao <barryjzhao@tencent.com> > > > > add linger parameter to libsrt, it's setting he number of seconds > > that the socket waits for unsent data when closing. > > minor spelling > Will fix > > > > Signed-off-by: Jun Zhao <barryjzhao@tencent.com> > > --- > > doc/protocols.texi | 4 ++++ > > libavformat/libsrt.c | 13 +++++++++++++ > > 2 files changed, 17 insertions(+), 0 deletions(-) > > > > diff --git a/doc/protocols.texi b/doc/protocols.texi > > index 0e18a49..f34f246 100644 > > --- a/doc/protocols.texi > > +++ b/doc/protocols.texi > > @@ -1426,6 +1426,10 @@ the overhead transmission (retransmitted and control packets). > > file: Set options as for non-live transmission. See @option{messageapi} > > for further explanations > > > > > +@item linger=@var{seconds} > > +The number of seconds that the socket waits for unsent data when closing. > > +Default is -1. > > I'd add infinite in brackets. Can't get your point, more details? > > > + > > @end table > > > > For more information see: @url{https://github.com/Haivision/srt}. > > diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c > > index 1c34ec5..0a748a1 100644 > > --- a/libavformat/libsrt.c > > +++ b/libavformat/libsrt.c > > @@ -84,6 +84,7 @@ typedef struct SRTContext { > > char *smoother; > > int messageapi; > > SRT_TRANSTYPE transtype; > > + int linger; > > } SRTContext; > > > > #define D AV_OPT_FLAG_DECODING_PARAM > > @@ -128,6 +129,7 @@ static const AVOption libsrt_options[] = { > > { "transtype", "The transmission type for the socket", OFFSET(transtype), AV_OPT_TYPE_INT, { .i64 = SRTT_INVALID }, SRTT_LIVE, SRTT_INVALID, .flags = D|E, "transtype" }, > > { "live", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = SRTT_LIVE }, INT_MIN, INT_MAX, .flags = D|E, "transtype" }, > > { "file", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = SRTT_FILE }, INT_MIN, INT_MAX, .flags = D|E, "transtype" }, > > + { "linger", "Number of seconds that the socket waits for unsent data when closing", OFFSET(linger), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E }, > > { NULL } > > }; > > > > Are some other parameters (latency, rcvlatency, connect_timeout) in milliseconds? (It's not that clear from the docs). > If yes, it may be good to set linger to milliseconds as well. > The SRT docs (https://github.com/Haivision/srt/blob/master/docs/API.md) used the seconds, and I think SRT borrow the option from socket SO_LINGER (http://man7.org/linux/man-pages/man7/socket.7.html), we can keep the similar semantics with seconds. > -- > Andriy
On Mon, 02. Dec 14:25, mypopy@gmail.com wrote: > On Mon, Dec 2, 2019 at 12:57 PM Andriy Gelman <andriy.gelman@gmail.com> > wrote: > > > > On Sun, 01. Dec 21:31, Jun Zhao wrote: > > > From: Jun Zhao <barryjzhao@tencent.com> > > > > > > add linger parameter to libsrt, it's setting he number of seconds > > > that the socket waits for unsent data when closing. > > > > minor spelling > > > Will fix > > > > > > Signed-off-by: Jun Zhao <barryjzhao@tencent.com> > > > --- > > > doc/protocols.texi | 4 ++++ > > > libavformat/libsrt.c | 13 +++++++++++++ > > > 2 files changed, 17 insertions(+), 0 deletions(-) > > > > > > diff --git a/doc/protocols.texi b/doc/protocols.texi > > > index 0e18a49..f34f246 100644 > > > --- a/doc/protocols.texi > > > +++ b/doc/protocols.texi > > > @@ -1426,6 +1426,10 @@ the overhead transmission (retransmitted and > control packets). > > > file: Set options as for non-live transmission. See @option{messageapi} > > > for further explanations > > > > > > > > +@item linger=@var{seconds} > > > +The number of seconds that the socket waits for unsent data when > closing. > > > +Default is -1. > > > > I'd add infinite in brackets. > Can't get your point, more details? It would be good to add what -1 means here. I initially thought it's an infinite wait but from the srt docs it looks that SRTO_LINGER defaults to on/180 seconds. > > Are some other parameters (latency, rcvlatency, connect_timeout) in > milliseconds? (It's not that clear from the docs). > > If yes, it may be good to set linger to milliseconds as well. > > > The SRT docs (https://github.com/Haivision/srt/blob/master/docs/API.md) > used the seconds, and I think SRT borrow the option from socket SO_LINGER > (http://man7.org/linux/man-pages/man7/socket.7.html), we can keep the > similar semantics with seconds. ok
diff --git a/doc/protocols.texi b/doc/protocols.texi index 0e18a49..f34f246 100644 --- a/doc/protocols.texi +++ b/doc/protocols.texi @@ -1426,6 +1426,10 @@ the overhead transmission (retransmitted and control packets). file: Set options as for non-live transmission. See @option{messageapi} for further explanations +@item linger=@var{seconds} +The number of seconds that the socket waits for unsent data when closing. +Default is -1. + @end table For more information see: @url{https://github.com/Haivision/srt}. diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c index 1c34ec5..0a748a1 100644 --- a/libavformat/libsrt.c +++ b/libavformat/libsrt.c @@ -84,6 +84,7 @@ typedef struct SRTContext { char *smoother; int messageapi; SRT_TRANSTYPE transtype; + int linger; } SRTContext; #define D AV_OPT_FLAG_DECODING_PARAM @@ -128,6 +129,7 @@ static const AVOption libsrt_options[] = { { "transtype", "The transmission type for the socket", OFFSET(transtype), AV_OPT_TYPE_INT, { .i64 = SRTT_INVALID }, SRTT_LIVE, SRTT_INVALID, .flags = D|E, "transtype" }, { "live", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = SRTT_LIVE }, INT_MIN, INT_MAX, .flags = D|E, "transtype" }, { "file", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = SRTT_FILE }, INT_MIN, INT_MAX, .flags = D|E, "transtype" }, + { "linger", "Number of seconds that the socket waits for unsent data when closing", OFFSET(linger), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E }, { NULL } }; @@ -340,6 +342,14 @@ static int libsrt_set_options_pre(URLContext *h, int fd) ((h->flags & AVIO_FLAG_WRITE) && libsrt_setsockopt(h, fd, SRTO_SENDER, "SRTO_SENDER", &yes, sizeof(yes)) < 0)) { return AVERROR(EIO); } + + if (s->linger >= 0) { + struct linger lin; + lin.l_linger = s->linger; + lin.l_onoff = lin.l_linger > 0 ? 1 : 0; + if (libsrt_setsockopt(h, fd, SRTO_LINGER, "SRTO_LINGER", &lin, sizeof(lin)) < 0) + return AVERROR(EIO); + } return 0; } @@ -591,6 +601,9 @@ static int libsrt_open(URLContext *h, const char *uri, int flags) goto err; } } + if (av_find_info_tag(buf, sizeof(buf), "linger", p)) { + s->linger = strtol(buf, NULL, 10); + } } return libsrt_setup(h, uri, flags); err: