<!DOCTYPE html><html><head><title></title><style type="text/css">p.MsoNormal,p.MsoNoSpacing{margin:0}</style></head><body><div><br></div><div>On Mon, Mar 18, 2019, at 14:18, Aaron Boxer wrote:<br></div><blockquote type="cite" id="fastmail-quoted"><div dir="ltr"><div dir="ltr"><div>1. code can be shared between access/srt.c and access_output/srt.c<br></div><div>2. created a URL parser for SRT parameters stored in URL<br></div><div>---<br></div><div> modules/access/Makefile.am | 2 +-<br></div><div> modules/access/srt_common.c | 179 ++++++++++++++++++++++++++++++<br></div><div> modules/access/srt_common.h | 103 +++++++++++++++++<br></div><div> modules/access_output/Makefile.am | 2 +-<br></div><div> 4 files changed, 284 insertions(+), 2 deletions(-)<br></div><div> create mode 100644 modules/access/srt_common.c<br></div><div> create mode 100644 modules/access/srt_common.h<br></div><div><br></div><div>diff --git a/modules/access/Makefile.am b/modules/access/Makefile.am<br></div><div>index c56cb8fe3a..9cdf98e0a1 100644<br></div><div>--- a/modules/access/Makefile.am<br></div><div>+++ b/modules/access/Makefile.am<br></div><div>@@ -423,7 +423,7 @@ EXTRA_LTLIBRARIES += <a href="http://libaccess_mtp_plugin.la">libaccess_mtp_plugin.la</a><br></div><div> <br></div><div> ### SRT ###<br></div><div> <br></div><div>-libaccess_srt_plugin_la_SOURCES = access/srt.c dummy.cpp<br></div><div>+libaccess_srt_plugin_la_SOURCES = access/srt.c access/srt_common.c access/srt_common.h dummy.cpp<br></div><div> libaccess_srt_plugin_la_CFLAGS = $(AM_CFLAGS) $(SRT_CFLAGS)<br></div><div> libaccess_srt_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) $(SRT_CPPFLAGS)<br></div><div> libaccess_srt_plugin_la_LIBADD = $(SRT_LIBS)<br></div><div>diff --git a/modules/access/srt_common.c b/modules/access/srt_common.c<br></div><div>new file mode 100644<br></div><div>index 0000000000..2f205c762a<br></div><div>--- /dev/null<br></div><div>+++ b/modules/access/srt_common.c<br></div><div>@@ -0,0 +1,179 @@<br></div><div>+/*****************************************************************************<br></div><div>+ * srt_common.c: SRT (Secure Reliable Transport) access module<br></div><div>+ *****************************************************************************<br></div><div>+ *<br></div><div>+ * Copyright (C) 2019, Haivision Systems Inc.<br></div><div>+ *<br></div><div>+ * Author: Aaron Boxer <<a href="mailto:aaron.boxer@collabora.com">aaron.boxer@collabora.com</a>><br></div><div>+ *<br></div><div>+ * This program is free software; you can redistribute it and/or modify it<br></div><div>+ * under the terms of the GNU Lesser General Public License as published by<br></div><div>+ * the Free Software Foundation; either version 2.1 of the License, or<br></div><div>+ * (at your option) any later version.<br></div><div>+ *<br></div><div>+ * This program is distributed in the hope that it will be useful,<br></div><div>+ * but WITHOUT ANY WARRANTY; without even the implied warranty of<br></div><div>+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br></div><div>+ * GNU Lesser General Public License for more details.<br></div><div>+ *<br></div><div>+ * You should have received a copy of the GNU Lesser General Public License<br></div><div>+ * along with this program; if not, write to the Free Software Foundation,<br></div><div>+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.<br></div><div>+ *****************************************************************************/<br></div><div>+<br></div><div>+#include "srt_common.h"<br></div><div>+<br></div><div>+const char * const srt_key_length_names[] = { N_( "16 bytes" ), N_(<br></div><div>+ "24 bytes" ), N_( "32 bytes" ), };<br></div><div>+<br></div><div>+typedef struct parsed_param {<br></div><div>+ char *key;<br></div><div>+ char *val;<br></div><div>+} parsed_param_t;<br></div><div>+<br></div><div>+static inline char*<br></div><div>+find(char *str, char find)<br></div><div>+{<br></div><div>+ str = strchr( str, find );<br></div><div>+ return str != NULL ? str + 1 : NULL;<br></div><div>+}<br></div><div>+<br></div><div>+/**<br></div><div>+ * Parse a query string into an array of key/value structs.<br></div><div>+ *<br></div><div>+ * The query string should be a null terminated string of parameters separated<br></div><div>+ * by a delimiter. Each parameter are checked for the equal sign character.<br></div><div>+ * If it appears in the parameter, it will be used as a null terminator<br></div><div>+ * and the part that comes after it will be the value of the parameter.<br></div><div>+ *<br></div><div>+ *<br></div><div>+ * param: query: the query string to parse. The string will be modified.<br></div><div>+ * param: delimiter: the character that separates the key/value pairs<br></div><div>+ * from each other.<br></div><div>+ * param: params: an array of parsed_param structs to hold the result.<br></div><div>+ * param: max_params: maximum number of parameters to parse.<br></div><div>+ *<br></div><div>+ * Return: the number of parsed items. -1 if there was an error.<br></div><div>+ */<br></div><div>+static int srt_url_parse_query(char *query, const char* delimiter,<br></div><div>+ parsed_param_t *params, int max_params)<br></div><div>+{<br></div><div>+ int i = 0;<br></div><div>+ char *token = NULL;<br></div><div>+<br></div><div>+ if (!query || *query == '\0')<br></div><div>+ return -1;<br></div><div>+ if (!params || max_params == 0)<br></div><div>+ return 0;<br></div><div>+<br></div><div>+ token = strtok( query, delimiter );<br></div><div>+ while (token != NULL && i < max_params) {<br></div><div>+ params[i].key = token;<br></div><div>+ params[i].val = NULL;<br></div><div>+ if ((params[i].val = strchr( params[i].key, '=' )) != NULL) {<br></div><div>+ size_t val_len = strlen( params[i].val );<br></div><div>+<br></div><div>+ /* make key into a zero-delimited string */<br></div><div>+ *(params[i].val) = '\0';<br></div><div>+<br></div><div>+ /* make sure val is not empty */<br></div><div>+ if (val_len > 1) {<br></div><div>+ params[i].val++;<br></div><div>+<br></div><div>+ /* make sure key is not empty */<br></div><div>+ if (params[i].key[0])<br></div><div>+ i++;<br></div><div>+ };<br></div><div>+ }<br></div><div>+ token = strtok( NULL, delimiter );<br></div><div>+ }<br></div><div>+ return i;<br></div><div>+}<br></div><div>+<br></div><div>+bool srt_parse_url(char* url, srt_params_t* params)<br></div><div>+{<br></div><div>+ char* query = NULL;<br></div><div>+ struct parsed_param local_params[32];<br></div><div>+ int num_params = 0;<br></div><div>+ int i = 0;<br></div><div>+ bool rc = false;<br></div><div>+<br></div><div>+ if (!url || !url[0] || !params)<br></div><div>+ return false;<br></div><div>+<br></div><div>+ /* initialize params */<br></div><div>+ params->mode = NULL;<br></div><div>+ params->latency = -1;<br></div><div>+ params->passphrase = NULL;<br></div><div>+ params->payload_size = -1;<br></div><div>+ params->encryption = NULL;<br></div><div>+ params->bandwidth_overhead_limit = -1;<br></div><div>+<br></div><div>+ /* Parse URL parameters */<br></div><div>+ query = find( url, '?' );<br></div><div>+ if (query) {<br></div><div>+ num_params = srt_url_parse_query( query, "&", local_params,<br></div><div>+ sizeof(local_params) / sizeof(struct parsed_param) );<br></div><div>+ if (num_params > 0) {<br></div><div>+ rc = true;<br></div><div>+ for (i = 0; i < num_params; ++i) {<br></div><div>+ char* val = local_params[i].val;<br></div><div>+ if (!val)<br></div><div>+ continue;<br></div><div>+<br></div><div>+ if (strcmp( local_params[i].key, SRT_PARAM_LATENCY ) == 0) {<br></div><div>+ int temp = atoi( val );<br></div><div>+ if (temp >= 0)<br></div><div>+ params->latency = temp;<br></div><div>+ } else if (strcmp( local_params[i].key, SRT_PARAM_MODE ) == 0) {<br></div><div>+ if (strcmp( val, SRT_MODE_LISTENER ) == 0) {<br></div><div>+ params->mode = SRT_MODE_LISTENER;<br></div><div>+ } else if (strcmp( val, SRT_MODE_CALLER ) == 0) {<br></div><div>+ params->mode = SRT_MODE_CALLER;<br></div><div>+ } else if (strcmp( val, SRT_MODE_RENDEZVOUS ) == 0) {<br></div><div>+ params->mode = SRT_MODE_RENDEZVOUS;<br></div><div>+ }<br></div><div>+ } else if (strcmp( local_params[i].key, SRT_PARAM_PASSPHRASE )<br></div><div>+ == 0) {<br></div><div>+ params->passphrase = val;<br></div><div>+ } else if (strcmp( local_params[i].key, SRT_PARAM_PAYLOAD_SIZE )<br></div><div>+ == 0) {<br></div><div>+ int temp = atoi( val );<br></div><div>+ if (temp >= 0)<br></div><div>+ params->payload_size = temp;<br></div><div>+ } else if (strcmp( local_params[i].key, SRT_PARAM_ENCRYPTION )<br></div><div>+ == 0) {<br></div><div>+ if (strcmp( val, SRT_ENCRYPTION_AES128 ) == 0) {<br></div><div>+ params->mode = SRT_ENCRYPTION_AES128;<br></div><div>+ } else if (strcmp( val, SRT_ENCRYPTION_AES198 ) == 0) {<br></div><div>+ params->mode = SRT_ENCRYPTION_AES198;<br></div><div>+ } else if (strcmp( val, SRT_ENCRYPTION_AES256 ) == 0) {<br></div><div>+ params->mode = SRT_ENCRYPTION_AES256;<br></div><div>+ }<br></div><div>+ } else if (strcmp( local_params[i].key,<br></div><div>+ SRT_PARAM_BANDWIDTH_OVERHEAD_LIMIT ) == 0) {<br></div><div>+ int temp = atoi( val );<br></div><div>+ if (temp >= 0)<br></div><div>+ params->bandwidth_overhead_limit = temp;<br></div><div>+<br></div><div>+ }<br></div><div>+ }<br></div><div>+ }<br></div><div>+ }<br></div><div>+<br></div><div>+ return rc;<br></div><div>+}<br></div><div>+<br></div><div>+int srt_set_socket_option(vlc_object_t *this, const char *srt_param,<br></div><div>+ SRTSOCKET u, SRT_SOCKOPT opt, const void *optval, int optlen)<br></div><div>+{<br></div><div>+ int stat = 0;<br></div><div>+<br></div><div>+ stat = srt_setsockopt( u, 0, opt, optval, optlen );<br></div><div>+ if (stat)<br></div><div>+ msg_Err( this, "Failed to set socket option %s (reason: %s)", srt_param,<br></div><div>+ srt_getlasterror_str() );<br></div><div>+<br></div><div>+ return stat;<br></div><div>+}<br></div><div>+<br></div><div>diff --git a/modules/access/srt_common.h b/modules/access/srt_common.h<br></div><div>new file mode 100644<br></div><div>index 0000000000..f0728faf1c<br></div><div>--- /dev/null<br></div><div>+++ b/modules/access/srt_common.h<br></div><div>@@ -0,0 +1,103 @@<br></div><div>+/*****************************************************************************<br></div><div>+ * srt_common.h: SRT (Secure Reliable Transport) access module<br></div><div>+ *****************************************************************************<br></div><div>+ *<br></div><div>+ * Copyright (C) 2019, Haivision Systems Inc.<br></div><div>+ *<br></div><div>+ * Author: Aaron Boxer <<a href="mailto:aaron.boxer@collabora.com">aaron.boxer@collabora.com</a>><br></div><div>+ *<br></div><div>+ * This program is free software; you can redistribute it and/or modify it<br></div><div>+ * under the terms of the GNU Lesser General Public License as published by<br></div><div>+ * the Free Software Foundation; either version 2.1 of the License, or<br></div><div>+ * (at your option) any later version.<br></div><div>+ *<br></div><div>+ * This program is distributed in the hope that it will be useful,<br></div><div>+ * but WITHOUT ANY WARRANTY; without even the implied warranty of<br></div><div>+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br></div><div>+ * GNU Lesser General Public License for more details.<br></div><div>+ *<br></div><div>+ * You should have received a copy of the GNU Lesser General Public License<br></div><div>+ * along with this program; if not, write to the Free Software Foundation,<br></div><div>+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.<br></div><div>+ *****************************************************************************/<br></div><div>+#ifndef SRT_COMMON_H<br></div><div>+#define SRT_COMMON_H 1<br></div><div>+<br></div><div>+#ifdef HAVE_CONFIG_H<br></div><div>+# include "config.h"<br></div><div>+#endif<br></div><div>+<br></div><div>+#include <vlc_common.h><br></div><div>+#include <srt/srt.h><br></div><div>+<br></div><div>+/*<br></div><div>+ SRT Parameters<br></div><div>+<br></div><div>+ Mode: Listener, Caller, Rendezvous (Caller by default)<br></div><div>+ Latency in Milliseconds (default as SRT default)<br></div><div>+ Passphrase (optional)<br></div><div>+ PayloadSize in Bytes (1316/"7 TS frames" by default)<br></div><div>+ Encryption: None, AES128, AES192, AES256<br></div><div>+ Bandwidth Overhead Limit/Headroom (default as sRT default)<br></div><div>+<br></div><div>+ */<br></div><div>+<br></div><div>+/* SRT parameter names */<br></div><div>+#define SRT_PARAM_MODE "mode"<br></div><div>+#define SRT_PARAM_LATENCY "latency"<br></div><div>+#define SRT_PARAM_PASSPHRASE "passphrase"<br></div><div>+#define SRT_PARAM_PAYLOAD_SIZE "payload-size"<br></div><div>+#define SRT_PARAM_ENCRYPTION "encryption"<br></div><div>+#define SRT_PARAM_BANDWIDTH_OVERHEAD_LIMIT "bandwidth-overhead-limit"<br></div><div>+#define SRT_PARAM_CHUNK_SIZE "chunk-size"<br></div><div>+#define SRT_PARAM_POLL_TIMEOUT "poll-timeout"<br></div><div>+#define SRT_PARAM_KEY_LENGTH "key-length"<br></div><div>+<br></div><div>+/* SRT Modes */<br></div><div>+#define SRT_MODE_LISTENER "listener"<br></div><div>+#define SRT_MODE_CALLER "caller"<br></div><div>+#define SRT_MODE_RENDEZVOUS "rendezvous"<br></div><div>+<br></div><div>+/* SRT Encryption */<br></div><div>+#define SRT_ENCRYPTION_NONE "none"<br></div><div>+#define SRT_ENCRYPTION_AES128 "aes128"<br></div><div>+#define SRT_ENCRYPTION_AES198 "aes198"<br></div><div>+#define SRT_ENCRYPTION_AES256 "aes256"<br></div><div>+<br></div><div>+#define SRT_DEFAULT_BANDWIDTH_OVERHEAD_LIMIT 25<br></div><div>+/* libsrt defines default packet size as 1316 internally<br></div><div>+ * so srt module takes same value. */<br></div><div>+#define SRT_DEFAULT_CHUNK_SIZE SRT_LIVE_DEF_PLSIZE<br></div><div>+/* libsrt tutorial uses 9000 as a default binding port */<br></div><div>+#define SRT_DEFAULT_PORT 9000<br></div><div>+/* Minimum/Maximum chunks to allow reading at a time from libsrt */<br></div><div>+#define SRT_MIN_CHUNKS_TRYREAD 10<br></div><div>+#define SRT_MAX_CHUNKS_TRYREAD 100<br></div><div>+/* The default timeout is -1 (infinite) */<br></div><div>+#define SRT_DEFAULT_POLL_TIMEOUT -1<br></div><div>+/* The default latency which srt library uses internally */<br></div><div>+#define SRT_DEFAULT_LATENCY SRT_LIVE_DEF_LATENCY_MS<br></div><div>+#define SRT_DEFAULT_PAYLOAD_SIZE SRT_LIVE_DEF_PLSIZE<br></div><div>+/* Crypto key length in bytes. */<br></div><div>+#define SRT_KEY_LENGTH_TEXT N_("Crypto key length in bytes")<br></div></div></div></blockquote><div><br></div><div>Hello,<br></div><div>If your new code use translations ("N_"), you need to add your file in po/POTFILES.in<br></div><div><br></div><blockquote type="cite" id="fastmail-quoted"><div dir="ltr"><div dir="ltr"><div>+#define SRT_DEFAULT_KEY_LENGTH 16<br></div><div>+static const int srt_key_lengths[] = { 16, 24, 32, };<br></div><div>+<br></div><div>+extern const char * const srt_key_length_names[];<br></div><div>+<br></div><div>+typedef struct srt_params {<br></div><div>+ const char* mode;<br></div><div>+ int latency;<br></div><div>+ const char* passphrase;<br></div><div>+ int payload_size;<br></div><div>+ const char* encryption;<br></div><div>+ int bandwidth_overhead_limit;<br></div><div>+<br></div><div>+} srt_params_t;<br></div><div>+<br></div><div>+bool srt_parse_url(char* url, srt_params_t* params);<br></div><div>+<br></div><div>+int srt_set_socket_option(vlc_object_t *this, const char *srt_param,<br></div><div>+ SRTSOCKET u, SRT_SOCKOPT opt, const void *optval, int optlen);<br></div><div>+<br></div><div>+#endif<br></div><div>diff --git a/modules/access_output/Makefile.am b/modules/access_output/Makefile.am<br></div><div>index 646bc46ee0..224e93eee0 100644<br></div><div>--- a/modules/access_output/Makefile.am<br></div><div>+++ b/modules/access_output/Makefile.am<br></div><div>@@ -27,7 +27,7 @@ access_out_LTLIBRARIES += $(LTLIBaccess_output_shout)<br></div><div> EXTRA_LTLIBRARIES += <a href="http://libaccess_output_shout_plugin.la">libaccess_output_shout_plugin.la</a><br></div><div> <br></div><div> ### SRT ###<br></div><div>-libaccess_output_srt_plugin_la_SOURCES = access_output/srt.c dummy.cpp<br></div><div>+libaccess_output_srt_plugin_la_SOURCES = access_output/srt.c access/srt_common.c access/srt_common.h dummy.cpp<br></div><div> libaccess_output_srt_plugin_la_CFLAGS = $(AM_CFLAGS) $(SRT_CFLAGS)<br></div><div> libaccess_output_srt_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) $(SRT_CPPFLAGS)<br></div><div> libaccess_output_srt_plugin_la_LIBADD = $(SRT_LIBS)<br></div><div>-- <br></div><div>2.17.1<br></div></div></div><div>_______________________________________________<br></div><div>vlc-devel mailing list<br></div><div>To unsubscribe or modify your subscription options:<br></div><div>https://mailman.videolan.org/listinfo/vlc-devel<br></div></blockquote><div><br></div></body></html>