summaryrefslogtreecommitdiff
path: root/libavformat/libsrt.c
diff options
context:
space:
mode:
authorJun Zhao <barryjzhao@tencent.com>2019-12-01 14:03:37 +0800
committerJun Zhao <barryjzhao@tencent.com>2019-12-11 14:23:26 +0800
commit8d823e6005febef23ca10ccd9d8725e708167aeb (patch)
tree66eaf9703346064377a8ce6875dd32f58688a3d8 /libavformat/libsrt.c
parent1ea44178f5fff7eb600026a09a0ce7d477ed0240 (diff)
lavf/libsrt: add linger parameter to libsrt
add linger parameter to libsrt, it's setting the number of seconds that the socket waits for unsent data when closing. Reviewed-by: Andriy Gelman <andriy.gelman@gmail.com> Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
Diffstat (limited to 'libavformat/libsrt.c')
-rw-r--r--libavformat/libsrt.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c
index 825ad9d1a3..b6dd2750ca 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;
}
@@ -592,6 +602,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: