[vlc-devel] [PATCH 3/3] access_output: srt: add support stream encryption

Justin Kim justin.kim at collabora.com
Wed Nov 15 08:48:00 CET 2017


For encrypted transmitting, `passphrase` and `key-length`
properties are added.

Signed-off-by: Justin Kim <justin.kim at collabora.com>
---
 modules/access_output/srt.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/modules/access_output/srt.c b/modules/access_output/srt.c
index 7de9b9151a..e531e132ff 100644
--- a/modules/access_output/srt.c
+++ b/modules/access_output/srt.c
@@ -47,6 +47,8 @@
 /* The default latency is 125
  * which uses srt library internally */
 #define SRT_DEFAULT_LATENCY 125
+/* Crypto key length in bytes. */
+#define SRT_DEFAULT_KEY_LENGTH 16
 
 struct sout_access_out_sys_t
 {
@@ -56,6 +58,8 @@ struct sout_access_out_sys_t
     int           i_latency;
     size_t        i_chunk_size;
     int           i_event_fd;
+    char         *psz_passphrase;
+    int           i_key_length;
 };
 
 static void srt_wait_interrupted(void *p_data)
@@ -187,6 +191,8 @@ static int Open( vlc_object_t *p_this )
     p_sys->i_chunk_size = var_InheritInteger( p_access, "chunk-size" );
     p_sys->i_poll_timeout = var_InheritInteger( p_access, "poll-timeout" );
     p_sys->i_latency = var_InheritInteger( p_access, "latency" );
+    p_sys->psz_passphrase = var_InheritString( p_access, "passphrase" );
+    p_sys->i_key_length = var_InheritInteger( p_access, "key-length" );
     p_sys->i_poll_id = -1;
     p_sys->i_event_fd = -1;
 
@@ -243,6 +249,14 @@ static int Open( vlc_object_t *p_this )
     /* Set latency */
     srt_setsockopt( p_sys->sock, 0, SRTO_TSBPDDELAY, &p_sys->i_latency, sizeof( int ) );
 
+    if ( p_sys->psz_passphrase != NULL && p_sys->psz_passphrase[0] != '\0')
+    {
+        srt_setsockopt( p_sys->sock, 0, SRTO_PASSPHRASE,
+            p_sys->psz_passphrase, strlen( p_sys->psz_passphrase ) );
+        srt_setsockopt( p_sys->sock, 0, SRTO_PBKEYLEN,
+            &p_sys->i_key_length, sizeof( int ) );
+    }
+
     p_sys->i_poll_id = srt_epoll_create();
     if ( p_sys->i_poll_id == -1 )
     {
@@ -286,6 +300,7 @@ failed:
         if ( p_sys->i_poll_id != -1 ) srt_epoll_release( p_sys->i_poll_id );
         if ( p_sys->sock != -1 ) srt_close( p_sys->sock );
         if ( p_sys->i_event_fd != -1 ) close( p_sys->i_event_fd );
+        if ( p_sys->psz_passphrase != NULL) free (p_sys->psz_passphrase);
 
         free( p_sys );
     }
@@ -307,6 +322,11 @@ static void Close( vlc_object_t * p_this )
         p_sys->i_event_fd = -1;
     }
 
+    if ( p_sys->psz_passphrase != NULL)
+    {
+        free (p_sys->psz_passphrase);
+    }
+
     free( p_sys );
 }
 
@@ -322,6 +342,9 @@ vlc_module_begin()
     add_integer( "poll-timeout", SRT_DEFAULT_POLL_TIMEOUT,
             N_("Return poll wait after timeout miliseconds (-1 = infinite)"), NULL, true )
     add_integer( "latency", SRT_DEFAULT_LATENCY, N_("SRT latency (ms)"), NULL, true )
+    add_string( "passphrase", "", N_("Password for stream encryption"), NULL, false )
+    add_integer( "key-length", SRT_DEFAULT_KEY_LENGTH,
+            N_("Crypto key length in bytes [16, 24, 32]"), NULL, false )
 
     set_capability( "sout access", 0 )
     add_shortcut( "srt" )
-- 
2.15.0



More information about the vlc-devel mailing list