[vlc-commits] [Git][videolan/vlc][3.0.x] 27 commits: srt: remove redundant code

Hugo Beauzée-Luyssen (@chouquette) gitlab at videolan.org
Thu Feb 17 14:30:03 UTC 2022



Hugo Beauzée-Luyssen pushed to branch 3.0.x at VideoLAN / VLC


Commits:
aed2108c by Rémi Denis-Courmont at 2022-02-17T13:46:14+00:00
srt: remove redundant code

(cherry picked from commit 198f754d838788a43885b0d30c1092a00747f94f)

Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -
a72f1f8d by Rémi Denis-Courmont at 2022-02-17T13:46:14+00:00
srt out: remove redundant code

(cherry picked from commit ae882e18727ab6f3761c982254b2e61d122fb8ef)

Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -
55dd7e85 by Rémi Denis-Courmont at 2022-02-17T13:46:14+00:00
srt: remove tautology

(cherry picked from commit d36c9ea4d1c0d696375c608d66f017741c40bfe8)

Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -
45246904 by Rémi Denis-Courmont at 2022-02-17T13:46:14+00:00
srt: remove tautology

(cherry picked from commit 90b7919115cf2906e020a215a752d9137321f936)

Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -
6b1c2c45 by Olivier Crête at 2022-02-17T13:46:14+00:00
contrib: Update SRT to 1.3.1

Almost the same as the previous one but squashing two patches which should have been and improving the inet_ntop() removing patch.

Skipping 1.3.0 as it was a bad version. Also removed all
custom patches are they don't seem to be required anymore, but
added new ones to make it build with MingW.

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
(cherry picked from commit e4e95613cc2d7f78acf80072b626d52da575f718) (edited)
edited:
- don't force pthreadGC2 but pthread
- removed non-gnu detection

Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -
85d3a050 by Jean-Baptiste Kempf at 2022-02-17T13:46:14+00:00
Contribs: srt, don't link to pthreadGC2 on Mingw

(cherry picked from commit e9ed3a579bee9aa59c6c71fadedaf4822ca95b1e)

Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -
e5f71103 by Olivier Crête at 2022-02-17T13:46:14+00:00
contribs: srt: Fix pkgconfig file generation

VLC doesn't use pkg-config --static but hacks the .pc files, so do
the same here. Also fix srt to produce valid pc files.

Signed-off-by: Konstantin Pavlov <thresh at videolan.org>
(cherry picked from commit dd597699c3a99b93c0ed9862ebf668315484aaca)

Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -
bcd93056 by Olivier Crête at 2022-02-17T13:46:14+00:00
srt: Remove eof code

It is possible to get an empty read from libsrt and it should not be treated as
EOF.

Signed-off-by: Thomas Guillem <thomas at gllm.fr>
(cherry picked from commit 34048bef8ed5e2b5e7c265bfbd0cee1db4b1159b)

Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -
d1a26ef5 by Roman Diouskine at 2022-02-17T13:46:14+00:00
srt: Read several chunks per blocking read call

libsrt input is asynchonously buffered internally and it makes sense to empty
those receive buffers as much as possible on every signaled receive event from
epoll. Doing so reduces context switching/re-scheduling and improves
performance.

Signed-off-by: Thomas Guillem <thomas at gllm.fr>
(cherry picked from commit ca7b0fcc3376f858f9002f96f0bec42288785d09) (rebased)
rebased:
* master has direct stream_sys_t typedef

Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -
9ef542af by Aaron Boxer at 2022-02-17T13:46:14+00:00
srt: move common code to single file

1. code can be shared between access/srt.c and access_output/srt.c
2. created a URL parser for SRT parameters stored in URL

Signed-off-by: Thomas Guillem <thomas at gllm.fr>
(cherry picked from commit 15dea8ecb86f4ec36467bea381afc16493263d1c) (edited)
edited:
* access out was missing dummy.cpp on 3.0

Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -
d5f59f92 by Aaron Boxer at 2022-02-17T13:46:14+00:00
srt: parse url and set options

for latency, maximum bandwidth, etc.

Signed-off-by: Thomas Guillem <thomas at gllm.fr>
(cherry picked from commit f98585725a2d599bc014dae9af014ac9202a892b) (edited)
edited:
* 4.0 used N_() on removed strings
* 3.0 needs advanced flag for add_password()

Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -
2721173c by David Fuhrmann at 2022-02-17T13:46:14+00:00
configure.ac: Require at least srt 1.3.0

Recent commits use defines like SRT_LIVE_DEF_PLSIZE, which are
only available starting with that srt version.

(cherry picked from commit 80b149ddf92226d12e71d4de6e6233f52b1ea2bb) (edited)
edited:
* 3.0 was restricting to < 1.3.0

Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -
6b7bc6e2 by Thomas Guillem at 2022-02-17T13:46:14+00:00
access_out: srt: fix missing config.h include

(cherry picked from commit e7e608e84e9e218886700a6c90e8788a01f46b4f) (rebased)
rebased:
* 3.0 doesn't have struct typedefs

Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -
b3973675 by Aaron Boxer at 2022-02-17T13:46:14+00:00
srt: fix bug in setting passphrase

Signed-off-by: Thomas Guillem <thomas at gllm.fr>
(cherry picked from commit ce386056d0dd9234bb52e057dbd6435dea74e140)

Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -
9b590f6e by Francois Cartegnie at 2022-02-17T13:46:14+00:00
access: srt: use define for variables

(cherry picked from commit 179579703bd600f3760e3aa61794250cfad96b81)

Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -
8db1f5e9 by Julien Montant at 2022-02-17T13:46:14+00:00
srt: fix build issue with recent SRT library

The deprecated macro `SRTO_TSBPDDELAY` has been deleted from SRT.
This prevents the compilation with SRT versions >= v1.4.2.

See the corresponding SRT commit 0e2201aff6b379979cec43fee5e8f162717f6346..
```
-   SRTO_TSBPDDELAY = 23,     // DEPRECATED. ALIAS: SRTO_LATENCY
```

The (unrecommended) `SRTO_LATENCY` should be used instead, which was
already available back then. See notice next to SRTO_LATENCY in the SRT
library source code for details on why it's not recommended.

Signed-off-by: Alexandre Janniaux <ajanni at videolabs.io>
(edited message)
(cherry picked from commit 6e8d77431127c482196115a6eeb769daf56347b3)

Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -
e19fdb24 by Yohann D'ANELLO at 2022-02-17T13:46:14+00:00
srt: add stream ID option

This patch allows the use of the streamid option when using the SRT
protocol.  For example, we can query the URL
srt://localhost:9710?streamid=demo if a stream server is listening on
localhost:9710 that supports multiple streams on the same server. Like
the others already implemented, this parameter can be overwritten in the
settings of the transport.

In a future patch, it may be good to support the full options.  The
complete list can be found here:
https://github.com/Haivision/srt/blob/master/docs/APISocketOptions.md#list-of-options
A human-friendly version of this list can be found in the ffmpeg
documentation: https://ffmpeg.org/ffmpeg-all.html#srt

Signed-off-by: Thomas Guillem <thomas at gllm.fr>
(cherry picked from commit a55c95a9ccb051066b73f103f1a1e25586a97773)

Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -
5eae57a0 by Francois Cartegnie at 2022-02-17T13:46:14+00:00
contribs: bump srt to 1.4.2

fixes crashes
removes now unused patches

(cherry picked from commit 0e7afc72a24f3a0f2a000fd1c9611f75f1c29172)

Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -
2534aa80 by Zhao Zhili at 2022-02-17T13:46:14+00:00
srt: obsolete SRT_PARAM_CHUNK_SIZE and SRT_PARAM_PAYLOAD_SIZE

Firstly, SRTO_PAYLOADSIZE has no effect for receiver. Secondly,
since there is no negotiation of payload size between sender and
receiver, the receiver should use a buffer at least
SRT_LIVE_MAX_PLSIZE bytes, otherwise the data can be truncated.
So the default value of option SRT_PARAM_CHUNK_SIZE is
inappropriate. User may know exactly the sender's payload size
to set the value for SRT_PARAM_CHUNK_SIZE, but there is no much
gain for doing that.

(cherry picked from commit 0b0cc7ff60b3104f59af305d6de8051807bb2577) (edited)
edited:
* 3.0 had the advanced flag in obsolete parameters

Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -
e010ae8e by Zhao Zhili at 2022-02-17T13:46:14+00:00
srt: Fix missing srt_cleanup on error path

(cherry picked from commit 52e3f716bc922664188b7f0dce744b3d92eb24a5) (rebased)
rebased:
* 3.0 is freeing psz_host

Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -
67faec33 by Zhao Zhili at 2022-02-17T13:46:14+00:00
srt: initialize p_sys->sock to SRT_INVALID_SOCK

Otherwise the zero initialized p_sys->sock will be closed in
srt_schedule_reconnect().

(cherry picked from commit e452063d6e25df6b22f0088f1f3edc4b976bfc64) (rebased)
rebased:
* 3.0 has vlc_mutex_destroy()

Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -
d7146aca by Zhao Zhili at 2022-02-17T13:46:14+00:00
srt: comment out too verbose log

(cherry picked from commit e6b547ccdc13c259c8322dcfc5620223640f0859)

Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -
29faf90e by Zhao Zhili at 2022-02-17T13:46:14+00:00
access_output/srt: obsolete SRT_PARAM_CHUNK_SIZE

It's the same thing as SRT_PARAM_PAYLOAD_SIZE.

(cherry picked from commit c90ef66a553d1da90276d09cd2551cd77225904e) (edited)
edited:
* 3.0 doesn't have struct typedefs
* 3.0 has advanced parameter in some settings

Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -
4c7cf49f by Zhao Zhili at 2022-02-17T13:46:14+00:00
access_output/srt: simplify always true condition

(cherry picked from commit 853df2675c619733ab874482847e93e5691a2820)

Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -
d0b91750 by Zhao Zhili at 2022-02-17T13:46:14+00:00
access_output/srt: send data in payload_size chunks

Fix #26048

To avoid sending a lot of small UDP packets.

(cherry picked from commit 84bc80de2334747c29e319bb3695bae1f2d2ade9) (rebased)
rebased:
* 3.0 doesn't have struct typedefs

Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -
fe971a8f by Hugo Beauzée-Luyssen at 2022-02-17T13:46:14+00:00
contribs: srt: Fix build with gcc11

(cherry picked from commit a49c449f1dd344087c4086fc03ecf4a5d69a6bf9)

Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -
a448c959 by Jean-Baptiste Kempf at 2022-02-17T13:46:14+00:00
Contribs: update SRT to 1.4.4

(cherry picked from commit 9a289291d01a393294c62ee7406487f59e25f4ed)

Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -


14 changed files:

- configure.ac
- − contrib/src/srt/0001-CMakeLists.txt-substitute-link-flags-for-package-nam.patch
- + contrib/src/srt/0001-core-ifdef-MSG_TRUNC-nixes-fix.patch
- − contrib/src/srt/0002-CMakeLists.txt-let-cmake-find-pthread.patch
- contrib/src/srt/SHA512SUMS
- − contrib/src/srt/add-implicit-link-libraries.patch
- contrib/src/srt/rules.mak
- modules/access/Makefile.am
- modules/access/srt.c
- + modules/access/srt_common.c
- + modules/access/srt_common.h
- modules/access_output/Makefile.am
- modules/access_output/srt.c
- po/POTFILES.in


Changes:

=====================================
configure.ac
=====================================
@@ -4016,7 +4016,7 @@ AM_CONDITIONAL([HAVE_LIRC], [test "${have_lirc}" = "yes"])
 dnl
 dnl  SRT plugin
 dnl
-PKG_ENABLE_MODULES_VLC([SRT], [access_srt access_output_srt], [srt >= 1.2.2 srt < 1.3.0], [SRT input/output plugin], [auto], [], [], [-DENABLE_SRT])
+PKG_ENABLE_MODULES_VLC([SRT], [access_srt access_output_srt], [srt >= 1.3.0], [SRT input/output plugin], [auto], [], [], [-DENABLE_SRT])
 
 EXTEND_HELP_STRING([Visualisations and Video filter plugins:])
 dnl


=====================================
contrib/src/srt/0001-CMakeLists.txt-substitute-link-flags-for-package-nam.patch deleted
=====================================
@@ -1,33 +0,0 @@
-From 671f9bc81168438d7cbc86f5946f2dbb720fa60e Mon Sep 17 00:00:00 2001
-From: Justin Kim <justin.kim at collabora.com>
-Date: Thu, 19 Apr 2018 20:12:21 +0900
-Subject: [PATCH 1/2] CMakeLists.txt: substitute link flags for package names
-
-Signed-off-by: Justin Kim <justin.kim at collabora.com>
----
- CMakeLists.txt | 2 ++
- 1 file changed, 2 insertions(+)
-
-diff --git a/CMakeLists.txt b/CMakeLists.txt
-index 85eb9c5..77fbfb0 100644
---- a/CMakeLists.txt
-+++ b/CMakeLists.txt
-@@ -90,6 +90,7 @@ if ( USE_GNUTLS )
- 	endif()
-  
- 	pkg_check_modules (SSL REQUIRED ${SSL_REQUIRED_MODULES})
-+	set (SRT_LIBS_PRIVATE ${SSL_LDFLAGS})
- 
- 	add_definitions(
- 		-DUSE_GNUTLS=1
-@@ -103,6 +104,7 @@ else()
- 	find_package(OpenSSL REQUIRED)
- 	set (SSL_INCLUDE_DIRS ${OPENSSL_INCLUDE_DIR})
- 	set (SSL_LIBRARIES ${OPENSSL_LIBRARIES})
-+	set (SRT_LIBS_PRIVATE ${SSL_LIBRARIES})
- 
- 	add_definitions(
- 		-DHAICRYPT_USE_OPENSSL_EVP=1
--- 
-2.17.0
-


=====================================
contrib/src/srt/0001-core-ifdef-MSG_TRUNC-nixes-fix.patch
=====================================
@@ -0,0 +1,32 @@
+From b159a783ac11cb6c2c8ec035deaeb3d8a73e0e2f Mon Sep 17 00:00:00 2001
+From: Francois Cartegnie <fcvlcdev at free.fr>
+Date: Mon, 9 Nov 2020 20:54:14 +0100
+Subject: [PATCH] core: ifdef MSG_TRUNC nixes fix
+
+---
+ srtcore/channel.cpp | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/srtcore/channel.cpp b/srtcore/channel.cpp
+index 3473e75..3af852e 100644
+--- a/srtcore/channel.cpp
++++ b/srtcore/channel.cpp
+@@ -801,6 +801,7 @@ EReadStatus CChannel::recvfrom(sockaddr_any& w_addr, CPacket& w_packet) const
+         goto Return_error;
+     }
+ 
++#ifndef _WIN32
+     // Fix for an issue with Linux Kernel found during tests at Tencent..
+     //
+     // There was a bug in older Linux Kernel which caused that when the internal
+@@ -825,6 +826,7 @@ EReadStatus CChannel::recvfrom(sockaddr_any& w_addr, CPacket& w_packet) const
+         status = RST_AGAIN;
+         goto Return_error;
+     }
++#endif
+ 
+     w_packet.setLength(recv_size - CPacket::HDR_SIZE);
+ 
+-- 
+2.26.2
+


=====================================
contrib/src/srt/0002-CMakeLists.txt-let-cmake-find-pthread.patch deleted
=====================================
@@ -1,51 +0,0 @@
-From 6446d6c9294b63b3b1d363a4e92213a3bb5d4101 Mon Sep 17 00:00:00 2001
-From: Justin Kim <justin.kim at collabora.com>
-Date: Fri, 23 Mar 2018 13:05:29 +0900
-Subject: [PATCH 2/2] CMakeLists.txt: let cmake find pthread
-
----
- CMakeLists.txt | 24 ++++++------------------
- 1 file changed, 6 insertions(+), 18 deletions(-)
-
-diff --git a/CMakeLists.txt b/CMakeLists.txt
-index 77fbfb0..52d6bcd 100644
---- a/CMakeLists.txt
-+++ b/CMakeLists.txt
-@@ -213,28 +213,16 @@ if (${ENABLE_PROFILE} AND HAVE_COMPILER_GNU_COMPAT)
- endif()
- 
- 
--if (NOT MINGW)
- # find pthread
--find_path(PTHREAD_INCLUDE_DIR pthread.h HINTS C:/pthread-win32/include)
--if (PTHREAD_INCLUDE_DIR)
--	message(STATUS "Pthread include dir: ${PTHREAD_INCLUDE_DIR}")
--else()
--	message(FATAL_ERROR "Failed to find pthread.h. Specify PTHREAD_INCLUDE_DIR.")
--endif()
--
--find_library(PTHREAD_LIBRARY NAMES pthread pthread_dll pthread_lib HINTS C:/pthread-win32/lib)
--if (PTHREAD_LIBRARY)
--	message(STATUS "Pthread library: ${PTHREAD_LIBRARY}")
-+set (THREADS_PTHREAD_ARG "2" CACHE STRING "Forcibly set by CMakeLists.txt." FORCE)
-+set (THREADS_PREFER_PTHREAD_FLAG ON)
-+find_package (Threads REQUIRED)
-+if (WIN32)
-+	set (SRT_LIBS_PRIVATE ${SRT_LIBS_PRIVATE} -lpthread)
- else()
--	message(FATAL_ERROR "Failed to find pthread library. Specify PTHREAD_LIBRARY.")
-+	set (SRT_LIBS_PRIVATE ${SRT_LIBS_PRIVATE} ${CMAKE_THREAD_LIBS_INIT})
- endif()
- 
--elseif(THREADS_FOUND)
--	set(PTHREAD_LIBRARY ${CMAKE_THREAD_LIBS_INIT})
--else()
--	find_library(PTHREAD_LIBRARY NAMES pthread pthreadGC2 pthreadGC)
--endif() # if (NOT MINGW)
--
- # This is required in some projects that add some other sources
- # to the SRT library to be compiled together (aka "virtual library").
- if (DEFINED SRT_EXTRA_LIB_INC)
--- 
-2.17.0
-


=====================================
contrib/src/srt/SHA512SUMS
=====================================
@@ -1,2 +1 @@
-30bc7750e1a47d637c57fef9dcf0d1be02ac51831f041f75ea3bd2437f1e1bfd06848fbbdcfb5476267b9165b1a035e5bedfa9ea2f3c88ea536ee93c23e3cd46  srt-1.2.3.tar.gz
-
+0d51e0ef73f4aa7eb284288cdbbd75b1c161969c2c2fed3a6d4e13a931341ca41dfcf2d6c1b9728f72b43454a9fde3764da67a27af9f0c99a6818682e4f4d4ba  srt-1.4.4.tar.gz


=====================================
contrib/src/srt/add-implicit-link-libraries.patch deleted
=====================================
@@ -1,25 +0,0 @@
---- srt.old/CMakeLists.txt	2017-12-09 09:10:02.000000000 +0100
-+++ srt/CMakeLists.txt	2017-12-09 09:18:38.000000000 +0100
-@@ -425,13 +425,15 @@
- # This may cause trouble when you want to compile your app with static libstdc++;
- # if your build requires it, you'd probably remove -lstdc++ from the list
- # obtained by `pkg-config --libs`.
--#
--# Some sensible solution for that is desired. Currently turned on only on demand.
--if (ENABLE_C_DEPS)
--if ( LINUX )
--	set (IFNEEDED_SRT_LDFLAGS "${IFNEEDED_SRT_LDFLAGS} -lstdc++ -lm")
--endif()
--endif()
-+
-+message("Adding the following implicit link libraries: ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES}")
-+foreach(LIB ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES})
-+    if(IS_ABSOLUTE ${LIB} AND EXISTS ${LIB})
-+	    set(SRT_LIBS_PRIVATE ${SRT_LIBS_PRIVATE} ${LIB})
-+    else()
-+        set(SRT_LIBS_PRIVATE ${SRT_LIBS_PRIVATE} "-l${LIB}")
-+    endif()
-+endforeach()
- 
- join_arguments(SRT_LIBS_PRIVATE ${SRT_LIBS_PRIVATE})
- 


=====================================
contrib/src/srt/rules.mak
=====================================
@@ -1,13 +1,13 @@
 # srt
 
-SRT_VERSION := 1.2.3
+SRT_VERSION := 1.4.4
 SRT_URL := $(GITHUB)/Haivision/srt/archive/v$(SRT_VERSION).tar.gz
 
 ifdef BUILD_NETWORK
 PKGS += srt
 endif
 
-ifeq ($(call need_pkg,"srt >= 1.2.2"),)
+ifeq ($(call need_pkg,"srt >= 1.3.1"),)
 PKGS_FOUND += srt
 endif
 
@@ -23,15 +23,12 @@ $(TARBALLS)/srt-$(SRT_VERSION).tar.gz:
 
 srt: srt-$(SRT_VERSION).tar.gz .sum-srt
 	$(UNPACK)
-	$(APPLY) $(SRC)/srt/add-implicit-link-libraries.patch
-	$(APPLY) $(SRC)/srt/0001-CMakeLists.txt-substitute-link-flags-for-package-nam.patch
-	$(APPLY) $(SRC)/srt/0002-CMakeLists.txt-let-cmake-find-pthread.patch
-	$(APPLY) $(SRC)/srt/fix-partial-availability.patch
-	$(call pkg_static,"scripts/haisrt.pc.in")
+	$(APPLY) $(SRC)/srt/0001-core-ifdef-MSG_TRUNC-nixes-fix.patch
+	$(call pkg_static,"scripts/srt.pc.in")
 	mv srt-$(SRT_VERSION) $@ && touch $@
 
 .srt: srt toolchain.cmake
 	cd $< && $(HOSTVARS_PIC) $(CMAKE) \
-		-DENABLE_SHARED=OFF -DUSE_GNUTLS=ON -DENABLE_CXX11=OFF
+		-DENABLE_SHARED=OFF -DUSE_GNUTLS=ON -DENABLE_CXX11=OFF -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_INSTALL_BINDIR=bin -DCMAKE_INSTALL_INCLUDEDIR=include
 	cd $< && $(CMAKEBUILD) . --target install
 	touch $@


=====================================
modules/access/Makefile.am
=====================================
@@ -426,7 +426,7 @@ EXTRA_LTLIBRARIES += libaccess_mtp_plugin.la
 
 ### SRT ###
 
-libaccess_srt_plugin_la_SOURCES = access/srt.c
+libaccess_srt_plugin_la_SOURCES = access/srt.c access/srt_common.c access/srt_common.h dummy.cpp
 libaccess_srt_plugin_la_CFLAGS = $(AM_CFLAGS) $(SRT_CFLAGS)
 libaccess_srt_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) $(SRT_CPPFLAGS)
 libaccess_srt_plugin_la_LIBADD = $(SRT_LIBS)


=====================================
modules/access/srt.c
=====================================
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * srt.c: SRT (Secure Reliable Transport) input module
+ * srt.c: SRT (Secure Reliable Transport) access module
  *****************************************************************************
  * Copyright (C) 2017-2018, Collabora Ltd.
  * Copyright (C) 2018, Haivision Systems Inc.
@@ -21,42 +21,19 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
+#include "srt_common.h"
 
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <vlc_common.h>
-#include <vlc_interrupt.h>
 #include <vlc_fs.h>
 #include <vlc_plugin.h>
 #include <vlc_access.h>
+#include <vlc_interrupt.h>
 
 #include <vlc_network.h>
 #include <vlc_url.h>
 
-#include <srt/srt.h>
-
-/* libsrt defines default packet size as 1316 internally
- * so srt module takes same value. */
-#define SRT_DEFAULT_CHUNK_SIZE 1316
-/* The default timeout is -1 (infinite) */
-#define SRT_DEFAULT_POLL_TIMEOUT -1
-/* The default latency is 125
- * which uses srt library internally */
-#define SRT_DEFAULT_LATENCY 125
-/* Crypto key length in bytes. */
-#define SRT_KEY_LENGTH_TEXT "Crypto key length in bytes"
-#define SRT_DEFAULT_KEY_LENGTH 16
-static const int srt_key_lengths[] = {
-    16, 24, 32,
-};
-
-static const char *const srt_key_length_names[] = {
-    "16 bytes", "24 bytes", "32 bytes",
-};
-
-struct stream_sys_t
+
+
+typedef struct stream_sys_t
 {
     SRTSOCKET   sock;
     int         i_poll_id;
@@ -64,7 +41,10 @@ struct stream_sys_t
     bool        b_interrupted;
     char       *psz_host;
     int         i_port;
-};
+    int         i_chunks; /* Number of chunks to allocate in the next read */
+} stream_sys_t;
+
+
 
 static void srt_wait_interrupted(void *p_data)
 {
@@ -111,10 +91,15 @@ static int Control(stream_t *p_stream, int i_query, va_list args)
 
 static bool srt_schedule_reconnect(stream_t *p_stream)
 {
-    int         i_latency;
-    int         stat;
-    char        *psz_passphrase = NULL;
-
+    vlc_object_t *strm_obj = (vlc_object_t *) p_stream;
+    int i_latency=var_InheritInteger( p_stream, SRT_PARAM_LATENCY );
+    int stat;
+    char *psz_passphrase = var_InheritString( p_stream, SRT_PARAM_PASSPHRASE );
+    bool passphrase_needs_free = true;
+    char *psz_streamid = var_InheritString( p_stream, SRT_PARAM_STREAMID );
+    bool streamid_needs_free = true;
+    char *url = NULL;
+    srt_params_t params;
     struct addrinfo hints = {
         .ai_socktype = SOCK_DGRAM,
     }, *res = NULL;
@@ -149,6 +134,24 @@ static bool srt_schedule_reconnect(stream_t *p_stream)
         goto out;
     }
 
+    if (p_stream->psz_url) {
+        url = strdup( p_stream->psz_url );
+        if (srt_parse_url( url, &params )) {
+            if (params.latency != -1)
+                i_latency = params.latency;
+            if (params.passphrase != NULL) {
+                free( psz_passphrase );
+                passphrase_needs_free = false;
+                psz_passphrase = (char *) params.passphrase;
+            }
+	    if (params.streamid != NULL ) {
+		free( psz_streamid );
+		streamid_needs_free = false;
+		psz_streamid = (char *) params.streamid;
+	    }
+        }
+    }
+
     /* Make SRT non-blocking */
     srt_setsockopt( p_sys->sock, 0, SRTO_SNDSYN,
         &(bool) { false }, sizeof( bool ) );
@@ -164,18 +167,24 @@ static bool srt_schedule_reconnect(stream_t *p_stream)
         &(int) { 0 }, sizeof( int ) );
 
     /* Set latency */
-    i_latency = var_InheritInteger( p_stream, "latency" );
-    srt_setsockopt( p_sys->sock, 0, SRTO_TSBPDDELAY,
-        &i_latency, sizeof( int ) );
+    srt_set_socket_option( strm_obj, SRT_PARAM_LATENCY, p_sys->sock,
+            SRTO_LATENCY, &i_latency, sizeof(i_latency) );
 
-    psz_passphrase = var_InheritString( p_stream, "passphrase" );
-    if ( psz_passphrase != NULL && psz_passphrase[0] != '\0')
-    {
-        int i_key_length = var_InheritInteger( p_stream, "key-length" );
-        srt_setsockopt( p_sys->sock, 0, SRTO_PASSPHRASE,
-            psz_passphrase, strlen( psz_passphrase ) );
-        srt_setsockopt( p_sys->sock, 0, SRTO_PBKEYLEN,
-            &i_key_length, sizeof( int ) );
+    /* set passphrase */
+    if (psz_passphrase != NULL && psz_passphrase[0] != '\0') {
+        int i_key_length = var_InheritInteger( p_stream, SRT_PARAM_KEY_LENGTH );
+
+        srt_set_socket_option( strm_obj, SRT_PARAM_KEY_LENGTH, p_sys->sock,
+                SRTO_PBKEYLEN, &i_key_length, sizeof(i_key_length) );
+
+        srt_set_socket_option( strm_obj, SRT_PARAM_PASSPHRASE, p_sys->sock,
+                SRTO_PASSPHRASE, psz_passphrase, strlen(psz_passphrase) );
+    }
+
+    /* set stream id */
+    if (psz_streamid != NULL && psz_streamid[0] != '\0') {
+        srt_set_socket_option( strm_obj, SRT_PARAM_STREAMID, p_sys->sock,
+                SRTO_STREAMID, psz_streamid, strlen(psz_streamid) );
     }
 
     srt_epoll_add_usock( p_sys->i_poll_id, p_sys->sock,
@@ -185,14 +194,18 @@ static bool srt_schedule_reconnect(stream_t *p_stream)
     msg_Dbg( p_stream, "Schedule SRT connect (dest addresss: %s, port: %d).",
         p_sys->psz_host, p_sys->i_port);
 
-    stat = srt_connect( p_sys->sock, res->ai_addr, res->ai_addrlen);
-    if ( stat == SRT_ERROR )
-    {
+    stat = srt_connect( p_sys->sock, res->ai_addr, res->ai_addrlen );
+    if (stat == SRT_ERROR) {
         msg_Err( p_stream, "Failed to connect to server (reason: %s)",
-                 srt_getlasterror_str() );
+                srt_getlasterror_str() );
         failed = true;
     }
 
+    /* Reset the number of chunks to allocate as the bitrate of
+     * the stream may have changed.
+     */
+    p_sys->i_chunks = SRT_MIN_CHUNKS_TRYREAD;
+
 out:
     if (failed && p_sys->sock != SRT_INVALID_SOCK)
     {
@@ -201,8 +214,12 @@ out:
         p_sys->sock = SRT_INVALID_SOCK;
     }
 
+    if (passphrase_needs_free)
+        free( psz_passphrase );
+    if (streamid_needs_free)
+	free( psz_streamid );
     freeaddrinfo( res );
-    free( psz_passphrase );
+    free( url );
 
     return !failed;
 }
@@ -210,8 +227,9 @@ out:
 static block_t *BlockSRT(stream_t *p_stream, bool *restrict eof)
 {
     stream_sys_t *p_sys = p_stream->p_sys;
-    int i_chunk_size = var_InheritInteger( p_stream, "chunk-size" );
-    int i_poll_timeout = var_InheritInteger( p_stream, "poll-timeout" );
+    int i_poll_timeout = var_InheritInteger( p_stream, SRT_PARAM_POLL_TIMEOUT );
+    /* SRT doesn't have a concept of EOF for live streams. */
+    VLC_UNUSED(eof);
 
     if ( vlc_killed() )
     {
@@ -219,7 +237,12 @@ static block_t *BlockSRT(stream_t *p_stream, bool *restrict eof)
         return NULL;
     }
 
-    block_t *pkt = block_Alloc( i_chunk_size );
+    if ( p_sys->i_chunks == 0 )
+        p_sys->i_chunks = SRT_MIN_CHUNKS_TRYREAD;
+
+    const size_t i_chunk_size = SRT_LIVE_MAX_PLSIZE;
+    const size_t bufsize = i_chunk_size * p_sys->i_chunks;
+    block_t *pkt = block_Alloc( bufsize );
     if ( unlikely( pkt == NULL ) )
     {
         return NULL;
@@ -257,29 +280,59 @@ static block_t *BlockSRT(stream_t *p_stream, bool *restrict eof)
                 continue;
         }
 
-        int stat = srt_recvmsg( p_sys->sock,
-            (char *)pkt->p_buffer, i_chunk_size );
-        if ( stat > 0 )
+        /* Try to get as much data as possible out of the lib, if there
+         * is still some left, increase the number of chunks to read so that
+         * it will read faster on the next iteration. This way the buffer will
+         * grow until it reads fast enough to keep the library empty after
+         * each iteration.
+         */
+        pkt->i_buffer = 0;
+        while ( ( bufsize - pkt->i_buffer ) >= i_chunk_size )
         {
-            pkt->i_buffer = stat;
-            goto out;
+            int stat = srt_recvmsg( p_sys->sock,
+                (char *)( pkt->p_buffer + pkt->i_buffer ),
+                bufsize - pkt->i_buffer );
+            if ( stat <= 0 )
+            {
+                break;
+            }
+            pkt->i_buffer += (size_t)stat;
+        }
+
+#if 0
+        msg_Dbg ( p_stream, "Read %zu bytes out of a max of %zu"
+            " (%d chunks of %zu bytes)", pkt->i_buffer,
+            p_sys->i_chunks * i_chunk_size, p_sys->i_chunks,
+                i_chunk_size );
+#endif
+
+        /* Gradually adjust number of chunks we read at a time
+        * up to a predefined maximum. The actual number we might
+        * settle on depends on stream's bit rate.
+        */
+        size_t rem = bufsize - pkt->i_buffer;
+        if ( rem < i_chunk_size )
+        {
+            if ( p_sys->i_chunks < SRT_MAX_CHUNKS_TRYREAD )
+            {
+                p_sys->i_chunks++;
+            }
         }
 
-        msg_Err( p_stream, "failed to receive packet, set EOS (reason: %s)",
-            srt_getlasterror_str() );
-        *eof = true;
-        break;
+        goto out;
     }
 
-    /* if the poll reports errors for any reason at all
-     * including a timeout, or there is a read error,
-     * we skip the turn.
+    /* if the poll reports errors for any reason at all,
+     * including a timeout, we skip the turn.
      */
-
-    block_Release(pkt);
-    pkt = NULL;
+    pkt->i_buffer = 0;
 
 out:
+    if (pkt->i_buffer == 0) {
+      block_Release(pkt);
+      pkt = NULL;
+    }
+
     vlc_interrupt_unregister();
 
     /* Re-add the socket to the poll if we were interrupted */
@@ -329,6 +382,7 @@ static int Open(vlc_object_t *p_this)
         msg_Err( p_stream, "Failed to create poll id for SRT socket." );
         goto failed;
     }
+    p_sys->sock = SRT_INVALID_SOCK;
 
     if ( !srt_schedule_reconnect( p_stream ) )
     {
@@ -345,16 +399,11 @@ static int Open(vlc_object_t *p_this)
 failed:
     vlc_mutex_destroy( &p_sys->lock );
 
-    if ( p_sys != NULL )
-    {
-        if ( p_sys->sock != -1 ) srt_close( p_sys->sock );
-        if ( p_sys->i_poll_id != -1 ) srt_epoll_release( p_sys->i_poll_id );
-
-        free( p_sys->psz_host );
+    if ( p_sys->sock != SRT_INVALID_SOCK ) srt_close( p_sys->sock );
+    if ( p_sys->i_poll_id != -1 ) srt_epoll_release( p_sys->i_poll_id );
+    srt_cleanup();
 
-        vlc_obj_free( p_this, p_sys );
-        p_stream->p_sys = NULL;
-    }
+    free( p_sys->psz_host );
 
     return VLC_EGENERIC;
 }
@@ -364,42 +413,41 @@ static void Close(vlc_object_t *p_this)
     stream_t     *p_stream = (stream_t*)p_this;
     stream_sys_t *p_sys = p_stream->p_sys;
 
-    if ( p_sys )
-    {
-        vlc_mutex_destroy( &p_sys->lock );
-
-        srt_epoll_remove_usock( p_sys->i_poll_id, p_sys->sock );
-        srt_close( p_sys->sock );
-        srt_epoll_release( p_sys->i_poll_id );
-
-        free( p_sys->psz_host );
+    vlc_mutex_destroy( &p_sys->lock );
 
-        vlc_obj_free( p_this, p_sys );
-        p_stream->p_sys = NULL;
-    }
+    srt_epoll_remove_usock( p_sys->i_poll_id, p_sys->sock );
+    srt_close( p_sys->sock );
+    srt_epoll_release( p_sys->i_poll_id );
 
+    free( p_sys->psz_host );
     srt_cleanup();
 }
 
 /* Module descriptor */
 vlc_module_begin ()
-    set_shortname( N_("SRT") )
-    set_description( N_("SRT input") )
+    set_shortname( N_( "SRT" ) )
+    set_description( N_( "SRT input" ) )
     set_category( CAT_INPUT )
     set_subcategory( SUBCAT_INPUT_ACCESS )
 
-    add_integer( "chunk-size", SRT_DEFAULT_CHUNK_SIZE,
-            N_("SRT chunk size (bytes)"), NULL, true )
-    add_integer( "poll-timeout", SRT_DEFAULT_POLL_TIMEOUT,
-            N_("Return poll wait after timeout milliseconds (-1 = infinite)"), NULL, true )
-    add_integer( "latency", SRT_DEFAULT_LATENCY, N_("SRT latency (ms)"), NULL, true )
-    add_password( "passphrase", "", "Password for stream encryption", NULL, false )
-    add_integer( "key-length", SRT_DEFAULT_KEY_LENGTH,
+    add_obsolete_integer( SRT_PARAM_CHUNK_SIZE )
+    add_integer( SRT_PARAM_POLL_TIMEOUT, SRT_DEFAULT_POLL_TIMEOUT,
+            N_( "Return poll wait after timeout milliseconds (-1 = infinite)" ),
+            NULL, true )
+    add_integer( SRT_PARAM_LATENCY, SRT_DEFAULT_LATENCY,
+            N_( "SRT latency (ms)" ), NULL, true )
+    add_password( SRT_PARAM_PASSPHRASE, "",
+            N_( "Password for stream encryption" ), NULL, false )
+    add_obsolete_integer( SRT_PARAM_PAYLOAD_SIZE )
+    add_integer( SRT_PARAM_KEY_LENGTH, SRT_DEFAULT_KEY_LENGTH,
             SRT_KEY_LENGTH_TEXT, SRT_KEY_LENGTH_TEXT, false )
-        change_integer_list( srt_key_lengths, srt_key_length_names )
+    change_integer_list( srt_key_lengths, srt_key_length_names )
+    add_string(SRT_PARAM_STREAMID, "",
+            N_(" SRT Stream ID"), NULL, false)
+    change_safe()
 
-    set_capability( "access", 0 )
-    add_shortcut( "srt" )
+    set_capability("access", 0)
+    add_shortcut("srt")
 
-    set_callbacks( Open, Close )
+    set_callbacks(Open, Close)
 vlc_module_end ()


=====================================
modules/access/srt_common.c
=====================================
@@ -0,0 +1,172 @@
+/*****************************************************************************
+ * srt_common.c: SRT (Secure Reliable Transport) access module
+ *****************************************************************************
+ *
+ * Copyright (C) 2019, Haivision Systems Inc.
+ *
+ * Author: Aaron Boxer <aaron.boxer at collabora.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#include "srt_common.h"
+
+const char * const srt_key_length_names[] = { N_( "16 bytes" ), N_(
+        "24 bytes" ), N_( "32 bytes" ), };
+
+typedef struct parsed_param {
+    char *key;
+    char *val;
+} parsed_param_t;
+
+static inline char*
+find(char *str, char find)
+{
+    str = strchr( str, find );
+    return str != NULL ? str + 1 : NULL;
+}
+
+/**
+ * Parse a query string into an array of key/value structs.
+ *
+ * The query string should be a null terminated string of parameters separated
+ * by a delimiter. Each parameter are checked for the equal sign character.
+ * If it appears in the parameter, it will be used as a null terminator
+ * and the part that comes after it will be the value of the parameter.
+ *
+ *
+ * param: query:         the query string to parse. The string will be modified.
+ * param: delimiter:      the character that separates the key/value pairs
+ *                      from each other.
+ * param: params:       an array of parsed_param structs to hold the result.
+ * param: max_params:     maximum number of parameters to parse.
+ *
+ * Return:                the number of parsed items. -1 if there was an error.
+ */
+static int srt_url_parse_query(char *query, const char* delimiter,
+        parsed_param_t *params, int max_params)
+{
+    int i = 0;
+    char *token = NULL;
+
+    if (!query || *query == '\0')
+        return -1;
+    if (!params || max_params == 0)
+        return 0;
+
+    token = strtok( query, delimiter );
+    while (token != NULL && i < max_params) {
+        params[i].key = token;
+        params[i].val = NULL;
+        if ((params[i].val = strchr( params[i].key, '=' )) != NULL) {
+            size_t val_len = strlen( params[i].val );
+
+            /* make key into a zero-delimited string */
+            *(params[i].val) = '\0';
+
+            /* make sure val is not empty */
+            if (val_len > 1) {
+                params[i].val++;
+
+                /* make sure key is not empty */
+                if (params[i].key[0])
+                    i++;
+            };
+        }
+        token = strtok( NULL, delimiter );
+    }
+    return i;
+}
+
+bool srt_parse_url(char* url, srt_params_t* params)
+{
+    char* query = NULL;
+    struct parsed_param local_params[32];
+    int num_params = 0;
+    int i = 0;
+    bool rc = false;
+
+    if (!url || !url[0] || !params)
+        return false;
+
+    /* initialize params */
+    params->latency = -1;
+    params->passphrase = NULL;
+    params->key_length = -1;
+    params->payload_size = -1;
+    params->bandwidth_overhead_limit = -1;
+    params->streamid = NULL;
+
+    /* Parse URL parameters */
+    query = find( url, '?' );
+    if (query) {
+        num_params = srt_url_parse_query( query, "&", local_params,
+                sizeof(local_params) / sizeof(struct parsed_param) );
+        if (num_params > 0) {
+            rc = true;
+            for (i = 0; i < num_params; ++i) {
+                char* val = local_params[i].val;
+                if (!val)
+                    continue;
+
+                if (strcmp( local_params[i].key, SRT_PARAM_LATENCY ) == 0) {
+                    int temp = atoi( val );
+                    if (temp >= 0)
+                        params->latency = temp;
+                } else if (strcmp( local_params[i].key, SRT_PARAM_PASSPHRASE )
+                        == 0) {
+                    params->passphrase = val;
+                } else if (strcmp( local_params[i].key, SRT_PARAM_STREAMID )
+                        == 0) {
+                    params->streamid = val;
+                } else if (strcmp( local_params[i].key, SRT_PARAM_PAYLOAD_SIZE )
+                        == 0) {
+                    int temp = atoi( val );
+                    if (temp >= 0)
+                        params->payload_size = temp;
+                } else if (strcmp( local_params[i].key, SRT_PARAM_KEY_LENGTH )
+                        == 0) {
+                    int temp = atoi( val );
+                    if (temp == srt_key_lengths[0] || temp == srt_key_lengths[1]
+                            || temp == srt_key_lengths[2]) {
+                        params->key_length = temp;
+                    }
+                } else if (strcmp( local_params[i].key,
+                SRT_PARAM_BANDWIDTH_OVERHEAD_LIMIT ) == 0) {
+                    int temp = atoi( val );
+                    if (temp >= 0)
+                        params->bandwidth_overhead_limit = temp;
+
+                }
+            }
+        }
+    }
+
+    return rc;
+}
+
+int srt_set_socket_option(vlc_object_t *this, const char *srt_param,
+        SRTSOCKET u, SRT_SOCKOPT opt, const void *optval, int optlen)
+{
+    int stat = 0;
+
+    stat = srt_setsockopt( u, 0, opt, optval, optlen );
+    if (stat)
+    msg_Err( this, "Failed to set socket option %s (reason: %s)", srt_param,
+            srt_getlasterror_str() );
+
+    return stat;
+}
+


=====================================
modules/access/srt_common.h
=====================================
@@ -0,0 +1,80 @@
+/*****************************************************************************
+ * srt_common.h: SRT (Secure Reliable Transport) access module
+ *****************************************************************************
+ *
+ * Copyright (C) 2019, Haivision Systems Inc.
+ *
+ * Author: Aaron Boxer <aaron.boxer at collabora.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+#ifndef SRT_COMMON_H
+#define SRT_COMMON_H 1
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <srt/srt.h>
+
+
+/* SRT parameter names */
+#define SRT_PARAM_LATENCY                     "latency"
+#define SRT_PARAM_PASSPHRASE                  "passphrase"
+#define SRT_PARAM_PAYLOAD_SIZE                "payload-size"
+#define SRT_PARAM_BANDWIDTH_OVERHEAD_LIMIT    "bandwidth-overhead-limit"
+#define SRT_PARAM_CHUNK_SIZE                  "chunk-size"
+#define SRT_PARAM_POLL_TIMEOUT                "poll-timeout"
+#define SRT_PARAM_KEY_LENGTH                  "key-length"
+#define SRT_PARAM_STREAMID                    "streamid"
+
+
+#define SRT_DEFAULT_BANDWIDTH_OVERHEAD_LIMIT 25
+/* libsrt defines default packet size as 1316 internally
+ * so srt module takes same value. */
+#define SRT_DEFAULT_CHUNK_SIZE SRT_LIVE_DEF_PLSIZE
+/* libsrt tutorial uses 9000 as a default binding port */
+#define SRT_DEFAULT_PORT 9000
+/* Minimum/Maximum chunks to allow reading at a time from libsrt */
+#define SRT_MIN_CHUNKS_TRYREAD 10
+#define SRT_MAX_CHUNKS_TRYREAD 100
+/* The default timeout is -1 (infinite) */
+#define SRT_DEFAULT_POLL_TIMEOUT -1
+/* The default latency which srt library uses internally */
+#define SRT_DEFAULT_LATENCY       SRT_LIVE_DEF_LATENCY_MS
+#define SRT_DEFAULT_PAYLOAD_SIZE  SRT_LIVE_DEF_PLSIZE
+/* Crypto key length in bytes. */
+#define SRT_KEY_LENGTH_TEXT N_("Crypto key length in bytes")
+#define SRT_DEFAULT_KEY_LENGTH 16
+static const int srt_key_lengths[] = { 16, 24, 32, };
+
+extern const char * const srt_key_length_names[];
+
+typedef struct srt_params {
+    int latency;
+    const char* passphrase;
+    int key_length;
+    int payload_size;
+    int bandwidth_overhead_limit;
+    const char* streamid;
+} srt_params_t;
+
+bool srt_parse_url(char* url, srt_params_t* params);
+
+int srt_set_socket_option(vlc_object_t *this, const char *srt_param,
+        SRTSOCKET u, SRT_SOCKOPT opt, const void *optval, int optlen);
+
+#endif


=====================================
modules/access_output/Makefile.am
=====================================
@@ -28,7 +28,7 @@ access_out_LTLIBRARIES += $(LTLIBaccess_output_shout)
 EXTRA_LTLIBRARIES += libaccess_output_shout_plugin.la
 
 ### SRT ###
-libaccess_output_srt_plugin_la_SOURCES = access_output/srt.c
+libaccess_output_srt_plugin_la_SOURCES = access_output/srt.c access/srt_common.c access/srt_common.h dummy.cpp
 libaccess_output_srt_plugin_la_CFLAGS = $(AM_CFLAGS) $(SRT_CFLAGS)
 libaccess_output_srt_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) $(SRT_CPPFLAGS)
 libaccess_output_srt_plugin_la_LIBADD = $(SRT_LIBS) $(LIBPTHREAD)


=====================================
modules/access_output/srt.c
=====================================
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * srt.c: SRT (Secure Reliable Transport) output module
+ * srt.c: SRT (Secure Reliable Transport) access_output module
  *****************************************************************************
  * Copyright (C) 2017-2018, Collabora Ltd.
  * Copyright (C) 2018, Haivision Systems Inc.
@@ -22,48 +22,25 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
+#include <srt_common.h>
 
-#include <vlc_common.h>
 #include <vlc_interrupt.h>
 #include <vlc_fs.h>
 #include <vlc_plugin.h>
 #include <vlc_sout.h>
 #include <vlc_block.h>
+#include <vlc_block_helper.h>
 #include <vlc_network.h>
 
-#include <srt/srt.h>
-
-/* libsrt defines default packet size as 1316 internally
- * so srt module takes same value. */
-#define SRT_DEFAULT_CHUNK_SIZE 1316
-/* libsrt tutorial uses 9000 as a default binding port */
-#define SRT_DEFAULT_PORT 9000
-/* The default timeout is -1 (infinite) */
-#define SRT_DEFAULT_POLL_TIMEOUT 100
-/* The default latency is 125
- * which uses srt library internally */
-#define SRT_DEFAULT_LATENCY 125
-/* Crypto key length in bytes. */
-#define SRT_KEY_LENGTH_TEXT N_("Crypto key length in bytes")
-#define SRT_DEFAULT_KEY_LENGTH 16
-static const int srt_key_lengths[] = {
-    16, 24, 32,
-};
-
-static const char *const srt_key_length_names[] = {
-    N_("16 bytes"), N_("24 bytes"), N_("32 bytes"),
-};
-
-struct sout_access_out_sys_t
+typedef struct sout_access_out_sys_t
 {
     SRTSOCKET     sock;
     int           i_poll_id;
     bool          b_interrupted;
     vlc_mutex_t   lock;
-};
+    int           i_payload_size;
+    block_bytestream_t block_stream;
+} sout_access_out_sys_t;
 
 static void srt_wait_interrupted(void *p_data)
 {
@@ -86,12 +63,20 @@ static void srt_wait_interrupted(void *p_data)
 
 static bool srt_schedule_reconnect(sout_access_out_t *p_access)
 {
-    char                    *psz_dst_addr = NULL;
-    int                      i_dst_port;
-    int                      i_latency;
-    int                      stat;
-    char                    *psz_passphrase = NULL;
-
+    vlc_object_t *access_obj = (vlc_object_t *) p_access;
+    int stat;
+    char *psz_dst_addr = NULL;
+    int i_dst_port;
+    int i_latency=var_InheritInteger( p_access, SRT_PARAM_LATENCY );
+    int i_payload_size = var_InheritInteger( p_access, SRT_PARAM_PAYLOAD_SIZE );
+    char *psz_passphrase = var_InheritString( p_access, SRT_PARAM_PASSPHRASE );
+    bool passphrase_needs_free = true;
+    char *psz_streamid = var_InheritString( p_access, SRT_PARAM_STREAMID );
+    bool streamid_needs_free = true;
+    int i_max_bandwidth_limit =
+    var_InheritInteger( p_access, SRT_PARAM_BANDWIDTH_OVERHEAD_LIMIT );
+    char *url = NULL;
+    srt_params_t params;
     struct addrinfo hints = {
         .ai_socktype = SOCK_DGRAM,
     }, *res = NULL;
@@ -99,8 +84,6 @@ static bool srt_schedule_reconnect(sout_access_out_t *p_access)
     sout_access_out_sys_t *p_sys = p_access->p_sys;
     bool failed = false;
 
-    psz_passphrase = var_InheritString( p_access, "passphrase" );
-
     i_dst_port = SRT_DEFAULT_PORT;
     char *psz_parser = psz_dst_addr = strdup( p_access->psz_path );
     if( !psz_dst_addr )
@@ -146,6 +129,26 @@ static bool srt_schedule_reconnect(sout_access_out_t *p_access)
         goto out;
     }
 
+    if (psz_dst_addr) {
+        url = strdup( psz_dst_addr );
+        if (srt_parse_url( url, &params )) {
+            if (params.latency != -1)
+                i_latency = params.latency;
+            if (params.payload_size != -1)
+                i_payload_size = params.payload_size;
+            if (params.passphrase != NULL) {
+                free( psz_passphrase );
+                passphrase_needs_free = false;
+                psz_passphrase = (char *) params.passphrase;
+            }
+	    if (params.streamid != NULL) {
+                free( psz_streamid );
+                streamid_needs_free = false;
+                psz_streamid = (char *) params.streamid;
+            }
+        }
+    }
+
     /* Make SRT non-blocking */
     srt_setsockopt( p_sys->sock, 0, SRTO_SNDSYN,
         &(bool) { false }, sizeof( bool ) );
@@ -161,18 +164,42 @@ static bool srt_schedule_reconnect(sout_access_out_t *p_access)
         &(int) { 1 }, sizeof( int ) );
 
     /* Set latency */
-    i_latency = var_InheritInteger( p_access, "latency" );
-    srt_setsockopt( p_sys->sock, 0, SRTO_TSBPDDELAY,
-        &i_latency, sizeof( int ) );
+    srt_set_socket_option( access_obj, SRT_PARAM_LATENCY, p_sys->sock,
+            SRTO_LATENCY, &i_latency, sizeof(i_latency) );
+
+    /* set passphrase */
+    if (psz_passphrase != NULL && psz_passphrase[0] != '\0') {
+        int i_key_length = var_InheritInteger( access_obj, SRT_PARAM_KEY_LENGTH );
+
+        srt_set_socket_option( access_obj, SRT_PARAM_KEY_LENGTH, p_sys->sock,
+                SRTO_PBKEYLEN, &i_key_length, sizeof(i_key_length) );
 
-    if ( psz_passphrase != NULL && psz_passphrase[0] != '\0')
+        srt_set_socket_option( access_obj, SRT_PARAM_PASSPHRASE, p_sys->sock,
+                SRTO_PASSPHRASE, psz_passphrase, strlen(psz_passphrase) );
+    }
+
+    /* set streamid */
+    if (psz_streamid != NULL && psz_streamid[0] != '\0') {
+        srt_set_socket_option( access_obj, SRT_PARAM_STREAMID, p_sys->sock,
+                SRTO_STREAMID, psz_streamid, strlen(psz_streamid) );
+    }
+
+    /* set maximumu payload size */
+    stat = srt_set_socket_option( access_obj, SRT_PARAM_PAYLOAD_SIZE, p_sys->sock,
+            SRTO_PAYLOADSIZE, &i_payload_size, sizeof(i_payload_size) );
+    if ( stat == SRT_ERROR )
     {
-        int i_key_length = var_InheritInteger( p_access, "key-length" );
-        srt_setsockopt( p_sys->sock, 0, SRTO_PASSPHRASE,
-            psz_passphrase, strlen( psz_passphrase ) );
-        srt_setsockopt( p_sys->sock, 0, SRTO_PBKEYLEN,
-            &i_key_length, sizeof( int ) );
+        msg_Err( p_access, "Failed to config payload size, %s",
+                 srt_getlasterror_str() );
+        failed = true;
+        goto out;
     }
+    p_sys->i_payload_size = i_payload_size;
+
+    /* set maximum bandwidth limit*/
+    srt_set_socket_option( access_obj, SRT_PARAM_BANDWIDTH_OVERHEAD_LIMIT,
+            p_sys->sock, SRTO_OHEADBW, &i_max_bandwidth_limit,
+            sizeof(i_max_bandwidth_limit) );
 
     srt_setsockopt( p_sys->sock, 0, SRTO_SENDER, &(int) { 1 }, sizeof(int) );
 
@@ -199,8 +226,12 @@ out:
         p_sys->sock = SRT_INVALID_SOCK;
     }
 
-    free( psz_passphrase );
+    if (passphrase_needs_free)
+        free( psz_passphrase );
+    if (streamid_needs_free)
+        free( psz_streamid );
     free( psz_dst_addr );
+    free( url );
     freeaddrinfo( res );
 
     return !failed;
@@ -209,20 +240,58 @@ out:
 static ssize_t Write( sout_access_out_t *p_access, block_t *p_buffer )
 {
     sout_access_out_sys_t *p_sys = p_access->p_sys;
-    int i_len = 0;
-    size_t i_chunk_size = var_InheritInteger( p_access, "chunk-size" );
-    int i_poll_timeout = var_InheritInteger( p_access, "poll-timeout" );
+    int i_poll_timeout = var_InheritInteger( p_access, SRT_PARAM_POLL_TIMEOUT );
     bool b_interrupted = false;
+    ssize_t i_len = 0;
+    int chunk_size;
+    uint8_t chunk[SRT_LIVE_MAX_PLSIZE];
+
+    if ( p_buffer == NULL )
+        return 0;
+    block_BytestreamPush( &p_sys->block_stream, p_buffer );
 
     vlc_interrupt_register( srt_wait_interrupted, p_access);
 
-    while( p_buffer )
+    while( true )
     {
-        block_t *p_next;
+        /* We can leave the remaining bytes less than i_payload_size for next
+         * Write() round, but it will add delay.
+         */
+        chunk_size = __MIN( block_BytestreamRemaining( &p_sys->block_stream ),
+                            p_sys->i_payload_size );
+        if ( chunk_size == 0 )
+            break;
+
+        if ( vlc_killed() )
+        {
+            /* We are told to stop. Stop. */
+            i_len = VLC_EGENERIC;
+            goto out;
+        }
 
-        i_len += p_buffer->i_buffer;
+        switch( srt_getsockstate( p_sys->sock ) )
+        {
+            case SRTS_CONNECTED:
+                /* Good to go */
+                break;
+            case SRTS_BROKEN:
+            case SRTS_NONEXIST:
+            case SRTS_CLOSED:
+                /* Failed. Schedule recovery. */
+                if ( !srt_schedule_reconnect( p_access ) )
+                    msg_Err( p_access, "Failed to schedule connect");
+                /* Fall-through */
+            default:
+                /* Not ready */
+                i_len = VLC_EGENERIC;
+                goto out;
+        }
 
-        while( p_buffer->i_buffer )
+        SRTSOCKET ready[1];
+        int readycnt = 1;
+        if ( srt_epoll_wait( p_sys->i_poll_id,
+            0, 0, &ready[0], &readycnt,
+            i_poll_timeout, NULL, 0, NULL, 0 ) < 0)
         {
             if ( vlc_killed() )
             {
@@ -231,90 +300,53 @@ static ssize_t Write( sout_access_out_t *p_access, block_t *p_buffer )
                 goto out;
             }
 
-            switch( srt_getsockstate( p_sys->sock ) )
+            /* if 'srt_epoll_wait' is interrupted, we still need to
+            *  finish sending current block or it may be sent only
+            *  partially. TODO: this delay can be prevented,
+            *  possibly with a FIFO and an additional thread.
+            */
+            vlc_mutex_lock( &p_sys->lock );
+            if ( p_sys->b_interrupted )
             {
-                case SRTS_CONNECTED:
-                    /* Good to go */
-                    break;
-                case SRTS_BROKEN:
-                case SRTS_NONEXIST:
-                case SRTS_CLOSED:
-                    /* Failed. Schedule recovery. */
-                    if ( !srt_schedule_reconnect( p_access ) )
-                        msg_Err( p_access, "Failed to schedule connect");
-                    /* Fall-through */
-                default:
-                    /* Not ready */
-                    i_len = VLC_EGENERIC;
-                    goto out;
+                srt_epoll_add_usock( p_sys->i_poll_id, p_sys->sock,
+                    &(int) { SRT_EPOLL_ERR | SRT_EPOLL_OUT });
+                p_sys->b_interrupted = false;
+                b_interrupted = true;
             }
+            vlc_mutex_unlock( &p_sys->lock );
 
-            SRTSOCKET ready[1];
-            int readycnt = 1;
-            if ( srt_epoll_wait( p_sys->i_poll_id,
-                0, 0, &ready[0], &readycnt,
-                i_poll_timeout, NULL, 0, NULL, 0 ) < 0)
+            if ( !b_interrupted )
             {
-                if ( vlc_killed() )
-                {
-                    /* We are told to stop. Stop. */
-                    i_len = VLC_EGENERIC;
-                    goto out;
-                }
-
-                /* if 'srt_epoll_wait' is interrupted, we still need to
-                *  finish sending current block or it may be sent only
-                *  partially. TODO: this delay can be prevented,
-                *  possibly with a FIFO and an additional thread.
-                */
-                vlc_mutex_lock( &p_sys->lock );
-                if ( p_sys->b_interrupted )
-                {
-                    srt_epoll_add_usock( p_sys->i_poll_id, p_sys->sock,
-                        &(int) { SRT_EPOLL_ERR | SRT_EPOLL_OUT });
-                    p_sys->b_interrupted = false;
-                    b_interrupted = true;
-                }
-                vlc_mutex_unlock( &p_sys->lock );
-
-                if ( !b_interrupted )
-                {
-                    continue;
-                }
-                else if ( (true) )
-                {
-                    msg_Dbg( p_access, "srt_epoll_wait was interrupted");
-                }
+                continue;
             }
-
-            if ( readycnt > 0  && ready[0] == p_sys->sock
-                && srt_getsockstate( p_sys->sock ) == SRTS_CONNECTED)
+            else
             {
-                size_t i_write = __MIN( p_buffer->i_buffer, i_chunk_size );
-                if (srt_sendmsg2( p_sys->sock,
-                    (char *)p_buffer->p_buffer, i_write, 0 ) == SRT_ERROR )
-                {
-                    msg_Warn( p_access, "send error: %s", srt_getlasterror_str() );
-                    i_len = VLC_EGENERIC;
-                    goto out;
-                }
-
-                p_buffer->p_buffer += i_write;
-                p_buffer->i_buffer -= i_write;
+                msg_Dbg( p_access, "srt_epoll_wait was interrupted");
             }
         }
 
-        p_next = p_buffer->p_next;
-        block_Release( p_buffer );
-        p_buffer = p_next;
-
-        if ( b_interrupted )
+        if ( readycnt > 0  && ready[0] == p_sys->sock
+            && srt_getsockstate( p_sys->sock ) == SRTS_CONNECTED)
         {
-            goto out;
+            if ( block_GetBytes( &p_sys->block_stream, chunk,
+                                 chunk_size ) != VLC_SUCCESS )
+                break;
+            if (srt_sendmsg2( p_sys->sock,
+                (char *)chunk, chunk_size, 0 ) == SRT_ERROR )
+            {
+                msg_Warn( p_access, "send error: %s", srt_getlasterror_str() );
+                i_len = VLC_EGENERIC;
+                goto out;
+            }
+            else
+            {
+                i_len += chunk_size;
+            }
         }
     }
 
 out:
+    block_BytestreamEmpty( &p_sys->block_stream );
     vlc_interrupt_unregister();
 
     /* Re-add the socket to the poll if we were interrupted */
@@ -327,7 +359,6 @@ out:
     }
     vlc_mutex_unlock( &p_sys->lock );
 
-    if ( i_len <= 0 ) block_ChainRelease( p_buffer );
     return i_len;
 }
 
@@ -372,6 +403,7 @@ static int Open( vlc_object_t *p_this )
     srt_startup();
 
     vlc_mutex_init( &p_sys->lock );
+    block_BytestreamInit( &p_sys->block_stream );
 
     p_access->p_sys = p_sys;
 
@@ -399,14 +431,8 @@ static int Open( vlc_object_t *p_this )
 failed:
     vlc_mutex_destroy( &p_sys->lock );
 
-    if ( p_sys != NULL )
-    {
-        if ( p_sys->sock != -1 ) srt_close( p_sys->sock );
-        if ( p_sys->i_poll_id != -1 ) srt_epoll_release( p_sys->i_poll_id );
-
-        vlc_obj_free( p_this, p_sys );
-        p_access->p_sys = NULL;
-    }
+    if ( p_sys->sock != -1 ) srt_close( p_sys->sock );
+    if ( p_sys->i_poll_id != -1 ) srt_epoll_release( p_sys->i_poll_id );
 
     return VLC_EGENERIC;
 }
@@ -416,37 +442,43 @@ static void Close( vlc_object_t * p_this )
     sout_access_out_t     *p_access = (sout_access_out_t*)p_this;
     sout_access_out_sys_t *p_sys = p_access->p_sys;
 
-    if ( p_sys )
-    {
-        vlc_mutex_destroy( &p_sys->lock );
-
-        srt_epoll_remove_usock( p_sys->i_poll_id, p_sys->sock );
-        srt_close( p_sys->sock );
-        srt_epoll_release( p_sys->i_poll_id );
+    vlc_mutex_destroy( &p_sys->lock );
 
-        vlc_obj_free( p_this, p_sys );
-        p_access->p_sys = NULL;
-    }
+    srt_epoll_remove_usock( p_sys->i_poll_id, p_sys->sock );
+    srt_close( p_sys->sock );
+    srt_epoll_release( p_sys->i_poll_id );
+    block_BytestreamRelease( &p_sys->block_stream );
 
     srt_cleanup();
 }
 
 /* Module descriptor */
 vlc_module_begin()
-    set_shortname( N_("SRT") )
-    set_description( N_("SRT stream output") )
+    set_shortname( N_( "SRT" ) )
+    set_description( N_( "SRT stream output" ) )
     set_category( CAT_SOUT )
     set_subcategory( SUBCAT_SOUT_ACO )
 
-    add_integer( "chunk-size", SRT_DEFAULT_CHUNK_SIZE,
-            N_("SRT chunk size (bytes)"), NULL, true )
-    add_integer( "poll-timeout", SRT_DEFAULT_POLL_TIMEOUT,
-            N_("Return poll wait after timeout milliseconds (-1 = infinite)"), NULL, true )
-    add_integer( "latency", SRT_DEFAULT_LATENCY, N_("SRT latency (ms)"), NULL, true )
-    add_password( "passphrase", "", N_("Password for stream encryption"), NULL, false )
-    add_integer( "key-length", SRT_DEFAULT_KEY_LENGTH,
-            SRT_KEY_LENGTH_TEXT, SRT_KEY_LENGTH_TEXT, false )
-        change_integer_list( srt_key_lengths, srt_key_length_names )
+    add_obsolete_integer( SRT_PARAM_CHUNK_SIZE )
+    add_integer( SRT_PARAM_POLL_TIMEOUT, SRT_DEFAULT_POLL_TIMEOUT,
+            N_( "Return poll wait after timeout milliseconds (-1 = infinite)" ),
+            NULL, true )
+    add_integer( SRT_PARAM_LATENCY, SRT_DEFAULT_LATENCY, N_( "SRT latency (ms)" ),
+            NULL, true )
+    add_password( SRT_PARAM_PASSPHRASE, "", N_( "Password for stream encryption" ),
+            NULL, false )
+    add_integer( SRT_PARAM_PAYLOAD_SIZE, SRT_DEFAULT_PAYLOAD_SIZE,
+            N_( "SRT maximum payload size (bytes)" ), NULL, true )
+        change_integer_range( 1, SRT_LIVE_MAX_PLSIZE )
+    add_integer( SRT_PARAM_BANDWIDTH_OVERHEAD_LIMIT,
+            SRT_DEFAULT_BANDWIDTH_OVERHEAD_LIMIT,
+            N_( "SRT maximum bandwidth ceiling (bytes)" ), NULL, true )
+    add_integer( SRT_PARAM_KEY_LENGTH, SRT_DEFAULT_KEY_LENGTH, SRT_KEY_LENGTH_TEXT,
+            SRT_KEY_LENGTH_TEXT, false )
+    change_integer_list( srt_key_lengths, srt_key_length_names )
+    add_string(SRT_PARAM_STREAMID, "",
+            N_(" SRT Stream ID"), NULL, false)
+    change_safe()
 
     set_capability( "sout access", 0 )
     add_shortcut( "srt" )


=====================================
po/POTFILES.in
=====================================
@@ -217,6 +217,7 @@ modules/access/shm.c
 modules/access/smb.c
 modules/access/smb_common.h
 modules/access/srt.c
+modules/access/srt_common.c
 modules/access/tcp.c
 modules/access/timecode.c
 modules/access/udp.c



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/08b36ec7e38ace0c7e198f34273e15858450473a...a448c9597124b256b41e8641f1e1073c42f6596c

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/08b36ec7e38ace0c7e198f34273e15858450473a...a448c9597124b256b41e8641f1e1073c42f6596c
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list