Changeset 72fc2d9c9d87002fb29a508271759397157ad99f

Show
Ignore:
Timestamp:
06/15/08 21:06:54 (2 months ago)
Author:
Rémi Denis-Courmont <rdenis@simphalempin.com>
git-committer:
Rémi Denis-Courmont <rdenis@simphalempin.com> 1213556814 +0300
git-parent:

[fa14c0922728246fe6353042ce4ae052fa4f75d8]

git-author:
Rémi Denis-Courmont <rdenis@simphalempin.com> 1213555728 +0300
Message:

RTP sout: rudimentary SRTP support

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/stream_out/Modules.am

    r5d6e797 r72fc2d9  
    88SOURCES_stream_out_display = display.c 
    99SOURCES_stream_out_gather = gather.c 
    10 SOURCES_stream_out_rtp = rtp.h rtp.c rtpfmt.c rtcp.c rtsp.c 
    1110SOURCES_stream_out_switcher = switcher.c 
    1211SOURCES_stream_out_bridge = bridge.c 
     
    2827    libstream_out_autodel_plugin.la \ 
    2928    $(NULL) 
     29 
     30# RTP plugin 
     31libstream_out_rtp_plugin_la_SOURCES = \ 
     32    rtp.c rtp.h rtpfmt.c rtcp.c rtsp.c 
     33libstream_out_rtp_plugin_la_CFLAGS = $(AM_CFLAGS) -I$(top_srcdir)/libs/srtp 
     34libstream_out_rtp_plugin_la_LIBADD = $(AM_LIBADD) \ 
     35    $(top_builddir)/libs/srtp/libvlc_srtp.la 
     36libstream_out_rtp_plugin_la_DEPENDENCIES = 
  • modules/stream_out/rtp.c

    r4fa484f r72fc2d9  
    33 ***************************************************************************** 
    44 * Copyright (C) 2003-2004 the VideoLAN team 
    5  * Copyright © 2007 Rémi Denis-Courmont 
    6  * $Id$ 
     5 * Copyright © 2007-2008 Rémi Denis-Courmont 
    76 * 
    87 * Authors: Laurent Aimar <fenrir@via.ecp.fr> 
     
    4140#include <vlc_charset.h> 
    4241#include <vlc_strings.h> 
     42#include <srtp.h> 
    4343 
    4444#include "rtp.h" 
     
    131131    "This selects which transport protocol to use for RTP." ) 
    132132 
     133#define SRTP_KEY_TEXT N_("SRTP key (hexadecimal)") 
     134#define SRTP_KEY_LONGTEXT N_( \ 
     135    "RTP packets will be integrity-protected and ciphered "\ 
     136    "with this Secure RTP master shared secret key.") 
     137 
     138#define SRTP_SALT_TEXT N_("SRTP salt (hexadecimal)") 
     139#define SRTP_SALT_LONGTEXT N_( \ 
     140    "Secure RTP requires a (non-secret) master salt value.") 
     141 
    133142static const char *const ppsz_protos[] = { 
    134143    "dccp", "sctp", "tcp", "udp", "udplite", 
     
    193202              RTCP_MUX_TEXT, RTCP_MUX_LONGTEXT, false ); 
    194203 
     204    add_string( SOUT_CFG_PREFIX "key", "", NULL, 
     205                SRTP_KEY_TEXT, SRTP_KEY_LONGTEXT, false ); 
     206    add_string( SOUT_CFG_PREFIX "salt", "", NULL, 
     207                SRTP_SALT_TEXT, SRTP_SALT_LONGTEXT, false ); 
     208 
    195209    add_bool( SOUT_CFG_PREFIX "mp4a-latm", 0, NULL, RFC3016_TEXT, 
    196210                 RFC3016_LONGTEXT, false ); 
     
    205219    "dst", "name", "port", "port-audio", "port-video", "*sdp", "ttl", "mux", 
    206220    "sap", "description", "url", "email", "phone", 
    207     "proto", "rtcp-mux", 
     221    "proto", "rtcp-mux", "key", "salt", 
    208222    "mp4a-latm", NULL 
    209223}; 
     
    300314 
    301315    /* Packetizer specific fields */ 
     316    int                 i_mtu; 
     317    srtp_session_t     *srtp; 
    302318    pf_rtp_packetizer_t pf_packetize; 
    303     int          i_mtu; 
    304319 
    305320    /* Packets sinks */ 
     
    903918    } 
    904919 
    905     id->pf_packetize = NULL; 
    906920    id->i_mtu = config_GetInt( p_stream, "mtu" ); 
    907921    if( id->i_mtu <= 12 + 16 ) 
    908922        id->i_mtu = 576 - 20 - 8; /* pessimistic */ 
    909  
    910923    msg_Dbg( p_stream, "maximum RTP packet size: %d bytes", id->i_mtu ); 
     924 
     925    id->srtp = NULL; 
     926    id->pf_packetize = NULL; 
     927 
     928    char *key = var_CreateGetNonEmptyString (p_stream, SOUT_CFG_PREFIX"key"); 
     929    if (key) 
     930    { 
     931        id->srtp = srtp_create (SRTP_ENCR_AES_CM, SRTP_AUTH_HMAC_SHA1, 10, 
     932                                   SRTP_PRF_AES_CM, SRTP_RCC_MODE1); 
     933        if (id->srtp == NULL) 
     934        { 
     935            free (key); 
     936            goto error; 
     937        } 
     938 
     939        char *salt = var_CreateGetNonEmptyString (p_stream, SOUT_CFG_PREFIX"salt"); 
     940        errno = srtp_setkeystring (id->srtp, key, salt ? salt : ""); 
     941        free (salt); 
     942        free (key); 
     943        if (errno) 
     944        { 
     945            msg_Err (p_stream, "bad SRTP key/salt combination (%m)"); 
     946            goto error; 
     947        } 
     948    } 
    911949 
    912950    vlc_mutex_init( &id->lock_sink ); 
     
    12521290    if( id->listen_fd != NULL ) 
    12531291        net_ListenClose( id->listen_fd ); 
     1292    if( id->srtp != NULL ) 
     1293        srtp_destroy( id->srtp ); 
    12541294 
    12551295    vlc_mutex_destroy( &id->lock_sink ); 
     
    13981438            continue; /* Forced wakeup */ 
    13991439 
     1440        if( id->srtp ) 
     1441        {   /* FIXME: this is awfully inefficient */ 
     1442            size_t len = out->i_buffer; 
     1443            int val = srtp_send( id->srtp, out->p_buffer, &len, 
     1444                                out->i_buffer ); 
     1445            if( val == ENOSPC ) 
     1446            { 
     1447                out = block_Realloc( out, 0, len ); 
     1448                if( out == NULL ) 
     1449                    continue; 
     1450                val = srtp_send( id->srtp, out->p_buffer, &len, 
     1451                                 out->i_buffer ); 
     1452            } 
     1453            if( val ) 
     1454            { 
     1455                errno = val; 
     1456                msg_Dbg( id, "SRTP sending error: %m" ); 
     1457                block_Release( out ); 
     1458                continue; 
     1459            } 
     1460            out->i_buffer = len; 
     1461        } 
     1462 
    14001463        mtime_t  i_date = out->i_dts + i_caching; 
    14011464        ssize_t  len = out->i_buffer; 
     
    14091472        for( int i = 0; i < id->sinkc; i++ ) 
    14101473        { 
    1411             SendRTCP( id->sinkv[i].rtcp, out ); 
     1474            if( !id->srtp ) /* FIXME: SRTCP support */ 
     1475                SendRTCP( id->sinkv[i].rtcp, out ); 
    14121476 
    14131477            if( send( id->sinkv[i].rtp_fd, out->p_buffer, len, 0 ) >= 0 )