[FFmpeg-devel] make work (live) libsrt

Submitted by Tudor Suciu on Aug. 25, 2018, 12:24 p.m.

Details

Message ID CANWt731=b142qx3-WQ8Ozrdy0jC1gNJfjmXsV61ZwmmPkTCmkA@mail.gmail.com
State New
Headers show

Commit Message

Tudor Suciu Aug. 25, 2018, 12:24 p.m.
Hello Marton,

The new version takes into account your remarks, modifications.

Regards,

Patch hide | download patch | download mbox

From 11cd8cf4bedecc88700424f1a0782beafe70c9f1 Mon Sep 17 00:00:00 2001
From: Tudor Suciu <tudor.suciu@gmail.com>
Date: Sat, 25 Aug 2018 14:06:57 +0200
Subject: [PATCH] add pkt_length to libsrt

---
 doc/protocols.texi   | 7 +++++++
 libavformat/libsrt.c | 8 ++++++++
 2 files changed, 15 insertions(+)

diff --git a/doc/protocols.texi b/doc/protocols.texi
index e9091e068c..076ec5bc14 100644
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@ -1263,6 +1263,13 @@  Not required on receiver (set to 0),
 key size obtained from sender in HaiCrypt handshake.
 Default value is 0.
 
+@item pkt_size=@var{bytes}
+Set maximum send pkt_size size, expressed in bytes.
+Libsrt expects by default payloads of 1316 bytes.
+Libsrt could be configured up to maximum usefull payload
+size in ethernet packets of 1456. The libsrt documents it
+as MTU(1500) - UDP.hdr(28) - SRT.hdr(16).
+
 @item recv_buffer_size=@var{bytes}
 Set receive buffer size, expressed in bytes.
 
diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c
index 0f9529d263..ca6989f316 100644
--- a/libavformat/libsrt.c
+++ b/libavformat/libsrt.c
@@ -48,6 +48,7 @@  typedef struct SRTContext {
     int64_t listen_timeout;
     int recv_buffer_size;
     int send_buffer_size;
+    int pkt_size;
 
     int64_t maxbw;
     int pbkeylen;
@@ -73,6 +74,7 @@  static const AVOption libsrt_options[] = {
     { "listen_timeout", "Connection awaiting timeout",                                          OFFSET(listen_timeout),   AV_OPT_TYPE_INT64, { .i64 = -1 }, -1, INT64_MAX, .flags = D|E },
     { "send_buffer_size", "Socket send buffer size (in bytes)",                                 OFFSET(send_buffer_size), AV_OPT_TYPE_INT,      { .i64 = -1 }, -1, INT_MAX,   .flags = D|E },
     { "recv_buffer_size", "Socket receive buffer size (in bytes)",                              OFFSET(recv_buffer_size), AV_OPT_TYPE_INT,      { .i64 = -1 }, -1, INT_MAX,   .flags = D|E },
+    { "pkt_size",       "Maximum SRT packet size",                                              OFFSET(pkt_size),         AV_OPT_TYPE_INT,      { .i64 = 1316 }, 1, INT_MAX,  .flags = D|E },
     { "maxbw",          "Maximum bandwidth (bytes per second) that the connection can use",     OFFSET(maxbw),            AV_OPT_TYPE_INT64,    { .i64 = -1 }, -1, INT64_MAX, .flags = D|E },
     { "pbkeylen",       "Crypto key len in bytes {16,24,32} Default: 16 (128-bit)",             OFFSET(pbkeylen),         AV_OPT_TYPE_INT,      { .i64 = -1 }, -1, 32,        .flags = D|E },
     { "passphrase",     "Crypto PBKDF2 Passphrase size[0,10..64] 0:disable crypto",             OFFSET(passphrase),       AV_OPT_TYPE_STRING,   { .str = NULL },              .flags = D|E },
@@ -442,6 +444,9 @@  static int libsrt_open(URLContext *h, const char *uri, int flags)
         if (av_find_info_tag(buf, sizeof(buf), "oheadbw", p)) {
             s->oheadbw = strtoll(buf, NULL, 10);
         }
+        if (av_find_info_tag(buf, sizeof(buf), "pkt_size", p)) {
+            s->pkt_size = strtol(buf, NULL, 10);
+        }
         if (av_find_info_tag(buf, sizeof(buf), "tsbpddelay", p)) {
             s->tsbpddelay = strtol(buf, NULL, 10);
         }
@@ -466,6 +471,9 @@  static int libsrt_open(URLContext *h, const char *uri, int flags)
             }
         }
     }
+    if (flags & AVIO_FLAG_WRITE) {
+        h->max_packet_size = s->pkt_size > 0 ? s->pkt_size : 1316;
+    }
     return libsrt_setup(h, uri, flags);
 }
 
-- 
2.11.0