[FFmpeg-cvslog] avformat/libsrt: add payload size option
Sven Dueking
git at videolan.org
Mon Sep 3 01:17:30 EEST 2018
ffmpeg | branch: master | Sven Dueking <sven.dueking at nablet.com> | Mon May 21 13:55:25 2018 +0700| [ea8ae27a5e112d06fd5625f640e40849e6313f0c] | committer: Luca Barbato
avformat/libsrt: add payload size option
Signed-off-by: Sven Dueking <sven.dueking at nablet.com>
Signed-off-by: Luca Barbato <lu_zero at gentoo.org>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ea8ae27a5e112d06fd5625f640e40849e6313f0c
---
doc/protocols.texi | 11 +++++++++++
libavformat/libsrt.c | 21 ++++++++++++++++++++-
2 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/doc/protocols.texi b/doc/protocols.texi
index e2d06a0675..5b625e571b 100644
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@ -755,6 +755,17 @@ only if @option{pbkeylen} is non-zero. It is used on
the receiver only if the received data is encrypted.
The configured passphrase cannot be recovered (write-only).
+ at item payloadsize=@var{bytes}
+Sets the maximum declared size of a packet transferred
+during the single call to the sending function in Live
+mode. Use 0 if this value isn't used (which is default in
+file mode).
+Default value is for MPEG-TS; if you are going to use SRT
+to send any different kind of payload, such as, for example,
+wrapping a live stream in very small frames, then you can
+use a bigger maximum frame size, though not greater than
+1456 bytes.
+
@item pbkeylen=@var{bytes}
Sender encryption key length, in bytes.
Only can be set to 0, 16, 24 and 32.
diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c
index 3e50dab64f..ec209c236d 100644
--- a/libavformat/libsrt.c
+++ b/libavformat/libsrt.c
@@ -34,6 +34,16 @@
#include "os_support.h"
#include "url.h"
+/* This is for MPEG-TS and it's a default SRTO_PAYLOADSIZE for SRTT_LIVE (8 TS packets) */
+#ifndef SRT_LIVE_DEFAULT_PAYLOAD_SIZE
+#define SRT_LIVE_DEFAULT_PAYLOAD_SIZE 1316
+#endif
+
+/* This is the maximum payload size for Live mode, should you have a different payload type than MPEG-TS */
+#ifndef SRT_LIVE_MAX_PAYLOAD_SIZE
+#define SRT_LIVE_MAX_PAYLOAD_SIZE 1456
+#endif
+
enum SRTMode {
SRT_MODE_CALLER = 0,
SRT_MODE_LISTENER = 1,
@@ -62,6 +72,7 @@ typedef struct SRTContext {
int tlpktdrop;
int nakreport;
int64_t connect_timeout;
+ int payload_size;
enum SRTMode mode;
} SRTContext;
@@ -86,6 +97,9 @@ static const AVOption libsrt_options[] = {
{ "tlpktdrop", "Enable receiver pkt drop", OFFSET(tlpktdrop), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, .flags = D|E },
{ "nakreport", "Enable receiver to send periodic NAK reports", OFFSET(nakreport), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, .flags = D|E },
{ "connect_timeout", "Connect timeout. Caller default: 3000, rendezvous (x 10)", OFFSET(connect_timeout), AV_OPT_TYPE_INT64, { .i64 = -1 }, -1, INT64_MAX, .flags = D|E },
+ { "payload size", "maximum declared size of a packet transferred", OFFSET(payload_size), AV_OPT_TYPE_INT, { .i64 = SRT_LIVE_DEFAULT_PAYLOAD_SIZE }, -1, SRT_LIVE_MAX_PAYLOAD_SIZE, .flags = D|E },
+ { "ts_size", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = SRT_LIVE_DEFAULT_PAYLOAD_SIZE }, INT_MIN, INT_MAX, .flags = D|E, "payload_size" },
+ { "max_size", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = SRT_LIVE_MAX_PAYLOAD_SIZE }, INT_MIN, INT_MAX, .flags = D|E, "payload_size" },
{ "mode", "Connection mode (caller, listener, rendezvous)", OFFSET(mode), AV_OPT_TYPE_INT, { .i64 = SRT_MODE_CALLER }, SRT_MODE_CALLER, SRT_MODE_RENDEZVOUS, .flags = D|E, "mode" },
{ "caller", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = SRT_MODE_CALLER }, INT_MIN, INT_MAX, .flags = D|E, "mode" },
{ "listener", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = SRT_MODE_LISTENER }, INT_MIN, INT_MAX, .flags = D|E, "mode" },
@@ -276,7 +290,8 @@ static int libsrt_set_options_pre(URLContext *h, int fd)
(tsbpddelay >= 0 && libsrt_setsockopt(h, fd, SRTO_TSBPDDELAY, "SRTO_TSBPDELAY", &tsbpddelay, sizeof(tsbpddelay)) < 0) ||
(s->tlpktdrop >= 0 && libsrt_setsockopt(h, fd, SRTO_TLPKTDROP, "SRTO_TLPKDROP", &s->tlpktdrop, sizeof(s->tlpktdrop)) < 0) ||
(s->nakreport >= 0 && libsrt_setsockopt(h, fd, SRTO_NAKREPORT, "SRTO_NAKREPORT", &s->nakreport, sizeof(s->nakreport)) < 0) ||
- (connect_timeout >= 0 && libsrt_setsockopt(h, fd, SRTO_CONNTIMEO, "SRTO_CONNTIMEO", &connect_timeout, sizeof(connect_timeout)) <0 )) {
+ (connect_timeout >= 0 && libsrt_setsockopt(h, fd, SRTO_CONNTIMEO, "SRTO_CONNTIMEO", &connect_timeout, sizeof(connect_timeout)) < 0) ||
+ (s->payload_size >= 0 && libsrt_setsockopt(h, fd, SRTO_PAYLOADSIZE, "SRTO_PAYLOADSIZE", &s->payload_size, sizeof(s->payload_size)) < 0)) {
return AVERROR(EIO);
}
return 0;
@@ -454,6 +469,9 @@ static int libsrt_open(URLContext *h, const char *uri, int flags)
if (av_find_info_tag(buf, sizeof(buf), "connect_timeout", p)) {
s->connect_timeout = strtol(buf, NULL, 10);
}
+ if (av_find_info_tag(buf, sizeof(buf), "payload_size", p)) {
+ s->payload_size = strtol(buf, NULL, 10);
+ }
if (av_find_info_tag(buf, sizeof(buf), "mode", p)) {
if (!strcmp(buf, "caller")) {
s->mode = SRT_MODE_CALLER;
@@ -466,6 +484,7 @@ static int libsrt_open(URLContext *h, const char *uri, int flags)
}
}
}
+ h->max_packet_size = s->payload_size > 0 ? s->payload_size : SRT_LIVE_DEFAULT_PAYLOAD_SIZE;
return libsrt_setup(h, uri, flags);
}
More information about the ffmpeg-cvslog
mailing list