<div dir="ltr"><div dir="ltr">1. code can be shared between access/srt.c and access_output/srt.c<br>2. created a URL parser for SRT parameters stored in URL<br>---<br> modules/access/Makefile.am        |   2 +-<br> modules/access/srt_common.c       | 168 ++++++++++++++++++++++++++++++<br> modules/access/srt_common.h       |  78 ++++++++++++++<br> modules/access_output/Makefile.am |   2 +-<br> po/POTFILES.in                    |   1 +<br> 5 files changed, 249 insertions(+), 2 deletions(-)<br> create mode 100644 modules/access/srt_common.c<br> create mode 100644 modules/access/srt_common.h<br><br>diff --git a/modules/access/Makefile.am b/modules/access/Makefile.am<br>index c56cb8fe3a..9cdf98e0a1 100644<br>--- a/modules/access/Makefile.am<br>+++ b/modules/access/Makefile.am<br>@@ -423,7 +423,7 @@ EXTRA_LTLIBRARIES += <a href="http://libaccess_mtp_plugin.la">libaccess_mtp_plugin.la</a><br> <br> ### SRT ###<br> <br>-libaccess_srt_plugin_la_SOURCES = access/srt.c dummy.cpp<br>+libaccess_srt_plugin_la_SOURCES = access/srt.c access/srt_common.c access/srt_common.h dummy.cpp<br> libaccess_srt_plugin_la_CFLAGS = $(AM_CFLAGS) $(SRT_CFLAGS)<br> libaccess_srt_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) $(SRT_CPPFLAGS)<br> libaccess_srt_plugin_la_LIBADD = $(SRT_LIBS)<br>diff --git a/modules/access/srt_common.c b/modules/access/srt_common.c<br>new file mode 100644<br>index 0000000000..91dcfe0988<br>--- /dev/null<br>+++ b/modules/access/srt_common.c<br>@@ -0,0 +1,168 @@<br>+/*****************************************************************************<br>+ * srt_common.c: SRT (Secure Reliable Transport) access module<br>+ *****************************************************************************<br>+ *<br>+ * Copyright (C) 2019, Haivision Systems Inc.<br>+ *<br>+ * Author: Aaron Boxer <<a href="mailto:aaron.boxer@collabora.com">aaron.boxer@collabora.com</a>><br>+ *<br>+ * This program is free software; you can redistribute it and/or modify it<br>+ * under the terms of the GNU Lesser General Public License as published by<br>+ * the Free Software Foundation; either version 2.1 of the License, or<br>+ * (at your option) any later version.<br>+ *<br>+ * This program is distributed in the hope that it will be useful,<br>+ * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>+ * GNU Lesser General Public License for more details.<br>+ *<br>+ * You should have received a copy of the GNU Lesser General Public License<br>+ * along with this program; if not, write to the Free Software Foundation,<br>+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.<br>+ *****************************************************************************/<br>+<br>+#include "srt_common.h"<br>+<br>+const char * const srt_key_length_names[] = { N_( "16 bytes" ), N_(<br>+        "24 bytes" ), N_( "32 bytes" ), };<br>+<br>+typedef struct parsed_param {<br>+    char *key;<br>+    char *val;<br>+} parsed_param_t;<br>+<br>+static inline char*<br>+find(char *str, char find)<br>+{<br>+    str = strchr( str, find );<br>+    return str != NULL ? str + 1 : NULL;<br>+}<br>+<br>+/**<br>+ * Parse a query string into an array of key/value structs.<br>+ *<br>+ * The query string should be a null terminated string of parameters separated<br>+ * by a delimiter. Each parameter are checked for the equal sign character.<br>+ * If it appears in the parameter, it will be used as a null terminator<br>+ * and the part that comes after it will be the value of the parameter.<br>+ *<br>+ *<br>+ * param: query:         the query string to parse. The string will be modified.<br>+ * param: delimiter:      the character that separates the key/value pairs<br>+ *                      from each other.<br>+ * param: params:       an array of parsed_param structs to hold the result.<br>+ * param: max_params:     maximum number of parameters to parse.<br>+ *<br>+ * Return:                the number of parsed items. -1 if there was an error.<br>+ */<br>+static int srt_url_parse_query(char *query, const char* delimiter,<br>+        parsed_param_t *params, int max_params)<br>+{<br>+    int i = 0;<br>+    char *token = NULL;<br>+<br>+    if (!query || *query == '\0')<br>+        return -1;<br>+    if (!params || max_params == 0)<br>+        return 0;<br>+<br>+    token = strtok( query, delimiter );<br>+    while (token != NULL && i < max_params) {<br>+        params[i].key = token;<br>+        params[i].val = NULL;<br>+        if ((params[i].val = strchr( params[i].key, '=' )) != NULL) {<br>+            size_t val_len = strlen( params[i].val );<br>+<br>+            /* make key into a zero-delimited string */<br>+            *(params[i].val) = '\0';<br>+<br>+            /* make sure val is not empty */<br>+            if (val_len > 1) {<br>+                params[i].val++;<br>+<br>+                /* make sure key is not empty */<br>+                if (params[i].key[0])<br>+                    i++;<br>+            };<br>+        }<br>+        token = strtok( NULL, delimiter );<br>+    }<br>+    return i;<br>+}<br>+<br>+bool srt_parse_url(char* url, srt_params_t* params)<br>+{<br>+    char* query = NULL;<br>+    struct parsed_param local_params[32];<br>+    int num_params = 0;<br>+    int i = 0;<br>+    bool rc = false;<br>+<br>+    if (!url || !url[0] || !params)<br>+        return false;<br>+<br>+    /* initialize params */<br>+    params->latency = -1;<br>+    params->passphrase = NULL;<br>+    params->key_length = -1;<br>+    params->payload_size = -1;<br>+    params->bandwidth_overhead_limit = -1;<br>+<br>+    /* Parse URL parameters */<br>+    query = find( url, '?' );<br>+    if (query) {<br>+        num_params = srt_url_parse_query( query, "&", local_params,<br>+                sizeof(local_params) / sizeof(struct parsed_param) );<br>+        if (num_params > 0) {<br>+            rc = true;<br>+            for (i = 0; i < num_params; ++i) {<br>+                char* val = local_params[i].val;<br>+                if (!val)<br>+                    continue;<br>+<br>+                if (strcmp( local_params[i].key, SRT_PARAM_LATENCY ) == 0) {<br>+                    int temp = atoi( val );<br>+                    if (temp >= 0)<br>+                        params->latency = temp;<br>+                } else if (strcmp( local_params[i].key, SRT_PARAM_PASSPHRASE )<br>+                        == 0) {<br>+                    params->passphrase = val;<br>+                } else if (strcmp( local_params[i].key, SRT_PARAM_PAYLOAD_SIZE )<br>+                        == 0) {<br>+                    int temp = atoi( val );<br>+                    if (temp >= 0)<br>+                        params->payload_size = temp;<br>+                } else if (strcmp( local_params[i].key, SRT_PARAM_KEY_LENGTH )<br>+                        == 0) {<br>+                    int temp = atoi( val );<br>+                    if (temp == srt_key_lengths[0] || temp == srt_key_lengths[1]<br>+                            || temp == srt_key_lengths[2]) {<br>+                        params->key_length = temp;<br>+                    }<br>+                } else if (strcmp( local_params[i].key,<br>+                SRT_PARAM_BANDWIDTH_OVERHEAD_LIMIT ) == 0) {<br>+                    int temp = atoi( val );<br>+                    if (temp >= 0)<br>+                        params->bandwidth_overhead_limit = temp;<br>+<br>+                }<br>+            }<br>+        }<br>+    }<br>+<br>+    return rc;<br>+}<br>+<br>+int srt_set_socket_option(vlc_object_t *this, const char *srt_param,<br>+        SRTSOCKET u, SRT_SOCKOPT opt, const void *optval, int optlen)<br>+{<br>+    int stat = 0;<br>+<br>+    stat = srt_setsockopt( u, 0, opt, optval, optlen );<br>+    if (stat)<br>+    msg_Err( this, "Failed to set socket option %s (reason: %s)", srt_param,<br>+            srt_getlasterror_str() );<br>+<br>+    return stat;<br>+}<br>+<br>diff --git a/modules/access/srt_common.h b/modules/access/srt_common.h<br>new file mode 100644<br>index 0000000000..c2322d5755<br>--- /dev/null<br>+++ b/modules/access/srt_common.h<br>@@ -0,0 +1,78 @@<br>+/*****************************************************************************<br>+ * srt_common.h: SRT (Secure Reliable Transport) access module<br>+ *****************************************************************************<br>+ *<br>+ * Copyright (C) 2019, Haivision Systems Inc.<br>+ *<br>+ * Author: Aaron Boxer <<a href="mailto:aaron.boxer@collabora.com">aaron.boxer@collabora.com</a>><br>+ *<br>+ * This program is free software; you can redistribute it and/or modify it<br>+ * under the terms of the GNU Lesser General Public License as published by<br>+ * the Free Software Foundation; either version 2.1 of the License, or<br>+ * (at your option) any later version.<br>+ *<br>+ * This program is distributed in the hope that it will be useful,<br>+ * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>+ * GNU Lesser General Public License for more details.<br>+ *<br>+ * You should have received a copy of the GNU Lesser General Public License<br>+ * along with this program; if not, write to the Free Software Foundation,<br>+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.<br>+ *****************************************************************************/<br>+#ifndef SRT_COMMON_H<br>+#define SRT_COMMON_H 1<br>+<br>+#ifdef HAVE_CONFIG_H<br>+# include "config.h"<br>+#endif<br>+<br>+#include <vlc_common.h><br>+#include <srt/srt.h><br>+<br>+<br>+/* SRT parameter names */<br>+#define SRT_PARAM_LATENCY                     "latency"<br>+#define SRT_PARAM_PASSPHRASE                  "passphrase"<br>+#define SRT_PARAM_PAYLOAD_SIZE                "payload-size"<br>+#define SRT_PARAM_BANDWIDTH_OVERHEAD_LIMIT    "bandwidth-overhead-limit"<br>+#define SRT_PARAM_CHUNK_SIZE                  "chunk-size"<br>+#define SRT_PARAM_POLL_TIMEOUT                "poll-timeout"<br>+#define SRT_PARAM_KEY_LENGTH                  "key-length"<br>+<br>+<br>+#define SRT_DEFAULT_BANDWIDTH_OVERHEAD_LIMIT 25<br>+/* libsrt defines default packet size as 1316 internally<br>+ * so srt module takes same value. */<br>+#define SRT_DEFAULT_CHUNK_SIZE SRT_LIVE_DEF_PLSIZE<br>+/* libsrt tutorial uses 9000 as a default binding port */<br>+#define SRT_DEFAULT_PORT 9000<br>+/* Minimum/Maximum chunks to allow reading at a time from libsrt */<br>+#define SRT_MIN_CHUNKS_TRYREAD 10<br>+#define SRT_MAX_CHUNKS_TRYREAD 100<br>+/* The default timeout is -1 (infinite) */<br>+#define SRT_DEFAULT_POLL_TIMEOUT -1<br>+/* The default latency which srt library uses internally */<br>+#define SRT_DEFAULT_LATENCY       SRT_LIVE_DEF_LATENCY_MS<br>+#define SRT_DEFAULT_PAYLOAD_SIZE  SRT_LIVE_DEF_PLSIZE<br>+/* Crypto key length in bytes. */<br>+#define SRT_KEY_LENGTH_TEXT N_("Crypto key length in bytes")<br>+#define SRT_DEFAULT_KEY_LENGTH 16<br>+static const int srt_key_lengths[] = { 16, 24, 32, };<br>+<br>+extern const char * const srt_key_length_names[];<br>+<br>+typedef struct srt_params {<br>+    int latency;<br>+    const char* passphrase;<br>+    int key_length;<br>+    int payload_size;<br>+    int bandwidth_overhead_limit;<br>+} srt_params_t;<br>+<br>+bool srt_parse_url(char* url, srt_params_t* params);<br>+<br>+int srt_set_socket_option(vlc_object_t *this, const char *srt_param,<br>+        SRTSOCKET u, SRT_SOCKOPT opt, const void *optval, int optlen);<br>+<br>+#endif<br>diff --git a/modules/access_output/Makefile.am b/modules/access_output/Makefile.am<br>index 646bc46ee0..224e93eee0 100644<br>--- a/modules/access_output/Makefile.am<br>+++ b/modules/access_output/Makefile.am<br>@@ -27,7 +27,7 @@ access_out_LTLIBRARIES += $(LTLIBaccess_output_shout)<br> EXTRA_LTLIBRARIES += <a href="http://libaccess_output_shout_plugin.la">libaccess_output_shout_plugin.la</a><br> <br> ### SRT ###<br>-libaccess_output_srt_plugin_la_SOURCES = access_output/srt.c dummy.cpp<br>+libaccess_output_srt_plugin_la_SOURCES = access_output/srt.c access/srt_common.c access/srt_common.h dummy.cpp<br> libaccess_output_srt_plugin_la_CFLAGS = $(AM_CFLAGS) $(SRT_CFLAGS)<br> libaccess_output_srt_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) $(SRT_CPPFLAGS)<br> libaccess_output_srt_plugin_la_LIBADD = $(SRT_LIBS)<br>diff --git a/po/POTFILES.in b/po/POTFILES.in<br>index c0d73027ab..2436469829 100644<br>--- a/po/POTFILES.in<br>+++ b/po/POTFILES.in<br>@@ -213,6 +213,7 @@ modules/access/shm.c<br> modules/access/smb_common.h<br> modules/access/smb2.c<br> modules/access/srt.c<br>+modules/access/srt_common.c<br> modules/access/tcp.c<br> modules/access/timecode.c<br> modules/access/udp.c<br>-- <br>2.17.1<br><br><br></div></div>