Changeset 72fc2d9c9d87002fb29a508271759397157ad99f
- 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
| r5d6e797 |
r72fc2d9 |
|
| 8 | 8 | SOURCES_stream_out_display = display.c |
|---|
| 9 | 9 | SOURCES_stream_out_gather = gather.c |
|---|
| 10 | | SOURCES_stream_out_rtp = rtp.h rtp.c rtpfmt.c rtcp.c rtsp.c |
|---|
| 11 | 10 | SOURCES_stream_out_switcher = switcher.c |
|---|
| 12 | 11 | SOURCES_stream_out_bridge = bridge.c |
|---|
| … | … | |
| 28 | 27 | libstream_out_autodel_plugin.la \ |
|---|
| 29 | 28 | $(NULL) |
|---|
| | 29 | |
|---|
| | 30 | # RTP plugin |
|---|
| | 31 | libstream_out_rtp_plugin_la_SOURCES = \ |
|---|
| | 32 | rtp.c rtp.h rtpfmt.c rtcp.c rtsp.c |
|---|
| | 33 | libstream_out_rtp_plugin_la_CFLAGS = $(AM_CFLAGS) -I$(top_srcdir)/libs/srtp |
|---|
| | 34 | libstream_out_rtp_plugin_la_LIBADD = $(AM_LIBADD) \ |
|---|
| | 35 | $(top_builddir)/libs/srtp/libvlc_srtp.la |
|---|
| | 36 | libstream_out_rtp_plugin_la_DEPENDENCIES = |
|---|
| r4fa484f |
r72fc2d9 |
|
| 3 | 3 | ***************************************************************************** |
|---|
| 4 | 4 | * Copyright (C) 2003-2004 the VideoLAN team |
|---|
| 5 | | * Copyright © 2007 Rémi Denis-Courmont |
|---|
| 6 | | * $Id$ |
|---|
| | 5 | * Copyright © 2007-2008 Rémi Denis-Courmont |
|---|
| 7 | 6 | * |
|---|
| 8 | 7 | * Authors: Laurent Aimar <fenrir@via.ecp.fr> |
|---|
| … | … | |
| 41 | 40 | #include <vlc_charset.h> |
|---|
| 42 | 41 | #include <vlc_strings.h> |
|---|
| | 42 | #include <srtp.h> |
|---|
| 43 | 43 | |
|---|
| 44 | 44 | #include "rtp.h" |
|---|
| … | … | |
| 131 | 131 | "This selects which transport protocol to use for RTP." ) |
|---|
| 132 | 132 | |
|---|
| | 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 | |
|---|
| 133 | 142 | static const char *const ppsz_protos[] = { |
|---|
| 134 | 143 | "dccp", "sctp", "tcp", "udp", "udplite", |
|---|
| … | … | |
| 193 | 202 | RTCP_MUX_TEXT, RTCP_MUX_LONGTEXT, false ); |
|---|
| 194 | 203 | |
|---|
| | 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 | |
|---|
| 195 | 209 | add_bool( SOUT_CFG_PREFIX "mp4a-latm", 0, NULL, RFC3016_TEXT, |
|---|
| 196 | 210 | RFC3016_LONGTEXT, false ); |
|---|
| … | … | |
| 205 | 219 | "dst", "name", "port", "port-audio", "port-video", "*sdp", "ttl", "mux", |
|---|
| 206 | 220 | "sap", "description", "url", "email", "phone", |
|---|
| 207 | | "proto", "rtcp-mux", |
|---|
| | 221 | "proto", "rtcp-mux", "key", "salt", |
|---|
| 208 | 222 | "mp4a-latm", NULL |
|---|
| 209 | 223 | }; |
|---|
| … | … | |
| 300 | 314 | |
|---|
| 301 | 315 | /* Packetizer specific fields */ |
|---|
| | 316 | int i_mtu; |
|---|
| | 317 | srtp_session_t *srtp; |
|---|
| 302 | 318 | pf_rtp_packetizer_t pf_packetize; |
|---|
| 303 | | int i_mtu; |
|---|
| 304 | 319 | |
|---|
| 305 | 320 | /* Packets sinks */ |
|---|
| … | … | |
| 903 | 918 | } |
|---|
| 904 | 919 | |
|---|
| 905 | | id->pf_packetize = NULL; |
|---|
| 906 | 920 | id->i_mtu = config_GetInt( p_stream, "mtu" ); |
|---|
| 907 | 921 | if( id->i_mtu <= 12 + 16 ) |
|---|
| 908 | 922 | id->i_mtu = 576 - 20 - 8; /* pessimistic */ |
|---|
| 909 | | |
|---|
| 910 | 923 | 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 | } |
|---|
| 911 | 949 | |
|---|
| 912 | 950 | vlc_mutex_init( &id->lock_sink ); |
|---|
| … | … | |
| 1252 | 1290 | if( id->listen_fd != NULL ) |
|---|
| 1253 | 1291 | net_ListenClose( id->listen_fd ); |
|---|
| | 1292 | if( id->srtp != NULL ) |
|---|
| | 1293 | srtp_destroy( id->srtp ); |
|---|
| 1254 | 1294 | |
|---|
| 1255 | 1295 | vlc_mutex_destroy( &id->lock_sink ); |
|---|
| … | … | |
| 1398 | 1438 | continue; /* Forced wakeup */ |
|---|
| 1399 | 1439 | |
|---|
| | 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 | |
|---|
| 1400 | 1463 | mtime_t i_date = out->i_dts + i_caching; |
|---|
| 1401 | 1464 | ssize_t len = out->i_buffer; |
|---|
| … | … | |
| 1409 | 1472 | for( int i = 0; i < id->sinkc; i++ ) |
|---|
| 1410 | 1473 | { |
|---|
| 1411 | | SendRTCP( id->sinkv[i].rtcp, out ); |
|---|
| | 1474 | if( !id->srtp ) /* FIXME: SRTCP support */ |
|---|
| | 1475 | SendRTCP( id->sinkv[i].rtcp, out ); |
|---|
| 1412 | 1476 | |
|---|
| 1413 | 1477 | if( send( id->sinkv[i].rtp_fd, out->p_buffer, len, 0 ) >= 0 ) |
|---|