X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Faccess%2Frtp%2Frtp.c;h=c896270c0f09f3ec8e3c65354989c4002c814d22;hb=39349f5c16dbf4d7dc7e474e7b596bd34c380730;hp=056d9408c8e8c3eda744f90757270617ba99d333;hpb=ab36d2f79979987e7ec4c20dd4a90882a0a705de;p=vlc diff --git a/modules/access/rtp/rtp.c b/modules/access/rtp/rtp.c old mode 100644 new mode 100755 index 056d9408c8..c896270c0f --- a/modules/access/rtp/rtp.c +++ b/modules/access/rtp/rtp.c @@ -4,11 +4,11 @@ */ /***************************************************************************** * Copyright (C) 2001-2005 the VideoLAN team - * Copyright © 2007-2008 Rémi Denis-Courmont + * Copyright © 2007-2009 Rémi Denis-Courmont * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2.0 + * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, @@ -16,7 +16,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ****************************************************************************/ @@ -26,6 +26,7 @@ #endif #include #include +#include #include #include @@ -33,15 +34,20 @@ #include #include -#include - #include "rtp.h" -#include +#ifdef HAVE_SRTP +# include +#endif #define RTP_CACHING_TEXT N_("RTP de-jitter buffer length (msec)") #define RTP_CACHING_LONGTEXT N_( \ "How long to wait for late RTP packets (and delay the performance)." ) +#define RTCP_PORT_TEXT N_("RTCP (local) port") +#define RTCP_PORT_LONGTEXT N_( \ + "RTCP packets will be received on this transport protocol port. " \ + "If zero, multiplexed RTP/RTCP is used.") + #define SRTP_KEY_TEXT N_("SRTP key (hexadecimal)") #define SRTP_KEY_LONGTEXT N_( \ "RTP packets will be authenticated and deciphered "\ @@ -76,37 +82,42 @@ static void Close (vlc_object_t *); * Module descriptor */ vlc_module_begin () - set_shortname (_("RTP")) - set_description (_("(Experimental) Real-Time Protocol demuxer")) + set_shortname (N_("RTP")) + set_description (N_("Real-Time Protocol (RTP) input")) set_category (CAT_INPUT) set_subcategory (SUBCAT_INPUT_DEMUX) set_capability ("access_demux", 0) set_callbacks (Open, Close) add_integer ("rtp-caching", 1000, NULL, RTP_CACHING_TEXT, - RTP_CACHING_LONGTEXT, true); + RTP_CACHING_LONGTEXT, true) + change_integer_range (0, 65535) + change_safe () + add_integer ("rtcp-port", 0, NULL, RTCP_PORT_TEXT, + RTCP_PORT_LONGTEXT, false) change_integer_range (0, 65535) + change_safe () +#ifdef HAVE_SRTP add_string ("srtp-key", "", NULL, - SRTP_KEY_TEXT, SRTP_KEY_LONGTEXT, false); + SRTP_KEY_TEXT, SRTP_KEY_LONGTEXT, false) add_string ("srtp-salt", "", NULL, - SRTP_SALT_TEXT, SRTP_SALT_LONGTEXT, false); + SRTP_SALT_TEXT, SRTP_SALT_LONGTEXT, false) +#endif add_integer ("rtp-max-src", 1, NULL, RTP_MAX_SRC_TEXT, - RTP_MAX_SRC_LONGTEXT, true); + RTP_MAX_SRC_LONGTEXT, true) change_integer_range (1, 255) add_integer ("rtp-timeout", 5, NULL, RTP_TIMEOUT_TEXT, - RTP_TIMEOUT_LONGTEXT, true); + RTP_TIMEOUT_LONGTEXT, true) add_integer ("rtp-max-dropout", 3000, NULL, RTP_MAX_DROPOUT_TEXT, - RTP_MAX_DROPOUT_LONGTEXT, true); + RTP_MAX_DROPOUT_LONGTEXT, true) change_integer_range (0, 32767) add_integer ("rtp-max-misorder", 100, NULL, RTP_MAX_MISORDER_TEXT, - RTP_MAX_MISORDER_LONGTEXT, true); + RTP_MAX_MISORDER_LONGTEXT, true) change_integer_range (0, 32767) - add_shortcut ("dccp") /*add_shortcut ("sctp")*/ - add_shortcut ("rtptcp") /* "tcp" is already taken :( */ - add_shortcut ("rtp") - add_shortcut ("udplite") + add_shortcut ("dccp", "rtptcp", /* "tcp" is already taken :( */ + "rtp", "udplite") vlc_module_end () /* @@ -114,7 +125,7 @@ vlc_module_end () * - send RTCP-RR and RTCP-BYE * - dynamic payload types (need SDP parser) * - multiple medias (need SDP parser, and RTCP-SR parser for lip-sync) - * - support for access_filter in case of stream_Demux (MPEG-TS) + * - support for stream_filter in case of stream_Demux (MPEG-TS) */ #ifndef IPPROTO_DCCP @@ -129,7 +140,6 @@ vlc_module_end () /* * Local prototypes */ -static int Demux (demux_t *); static int Control (demux_t *, int i_query, va_list args); static int extract_port (char **phost); @@ -155,23 +165,34 @@ static int Open (vlc_object_t *obj) else return VLC_EGENERIC; - char *tmp = strdup (demux->psz_path); - char *shost = tmp; - if (shost == NULL) + char *tmp = strdup (demux->psz_location); + if (tmp == NULL) return VLC_ENOMEM; - char *dhost = strchr (shost, '@'); - if (dhost) - *dhost++ = '\0'; + char *shost; + char *dhost = strchr (tmp, '@'); + if (dhost != NULL) + { + *(dhost++) = '\0'; + shost = tmp; + } + else + { + dhost = tmp; + shost = NULL; + } /* Parses the port numbers */ int sport = 0, dport = 0; - sport = extract_port (&shost); + if (shost != NULL) + sport = extract_port (&shost); if (dhost != NULL) dport = extract_port (&dhost); if (dport == 0) dport = 5004; /* avt-profile-1 port */ + int rtcp_dport = var_CreateGetInteger (obj, "rtcp-port"); + /* Try to connect */ int fd = -1, rtcp_fd = -1; @@ -179,15 +200,13 @@ static int Open (vlc_object_t *obj) { case IPPROTO_UDP: case IPPROTO_UDPLITE: - if ((dport & 1) != 0 || (sport & 1) != 0) - msg_Err (obj, "Using odd port number is higly discouraged"); - fd = net_OpenDgram (obj, dhost, dport, shost, sport, AF_UNSPEC, tp); if (fd == -1) break; - rtcp_fd = net_OpenDgram (obj, dhost, dport + 1, shost, - sport ? (sport + 1) : 0, AF_UNSPEC, tp); + if (rtcp_dport > 0) /* XXX: source port is unknown */ + rtcp_fd = net_OpenDgram (obj, dhost, rtcp_dport, shost, 0, + AF_UNSPEC, tp); break; case IPPROTO_DCCP: @@ -199,14 +218,14 @@ static int Open (vlc_object_t *obj) #ifdef SOCK_DCCP var_Create (obj, "dccp-service", VLC_VAR_STRING); var_SetString (obj, "dccp-service", "RTPV"); /* FIXME: RTPA? */ - fd = net_Connect (obj, shost, (sport + 1) & ~1, SOCK_DCCP, tp); + fd = net_Connect (obj, dhost, dport, SOCK_DCCP, tp); #else msg_Err (obj, "DCCP support not included"); #endif break; case IPPROTO_TCP: - fd = net_Connect (obj, shost, (sport + 1) & ~1, SOCK_STREAM, tp); + fd = net_Connect (obj, dhost, dport, SOCK_STREAM, tp); break; } @@ -226,20 +245,20 @@ static int Open (vlc_object_t *obj) } vlc_mutex_init (&p_sys->lock); - vlc_cond_init (&p_sys->wait); +#ifdef HAVE_SRTP p_sys->srtp = NULL; +#endif p_sys->fd = fd; p_sys->rtcp_fd = rtcp_fd; p_sys->caching = var_CreateGetInteger (obj, "rtp-caching"); p_sys->max_src = var_CreateGetInteger (obj, "rtp-max-src"); - p_sys->timeout = var_CreateGetInteger (obj, "rtp-timeout"); + p_sys->timeout = var_CreateGetInteger (obj, "rtp-timeout") + * CLOCK_FREQ; p_sys->max_dropout = var_CreateGetInteger (obj, "rtp-max-dropout"); p_sys->max_misorder = var_CreateGetInteger (obj, "rtp-max-misorder"); - p_sys->autodetect = true; p_sys->framed_rtp = (tp == IPPROTO_TCP); - p_sys->dead = false; - demux->pf_demux = Demux; + demux->pf_demux = NULL; demux->pf_control = Control; demux->p_sys = p_sys; @@ -247,6 +266,7 @@ static int Open (vlc_object_t *obj) if (p_sys->session == NULL) goto error; +#ifdef HAVE_SRTP char *key = var_CreateGetNonEmptyString (demux, "srtp-key"); if (key) { @@ -268,6 +288,7 @@ static int Open (vlc_object_t *obj) goto error; } } +#endif if (vlc_clone (&p_sys->thread, rtp_thread, demux, VLC_THREAD_PRIORITY_INPUT)) @@ -294,11 +315,12 @@ static void Close (vlc_object_t *obj) vlc_cancel (p_sys->thread); vlc_join (p_sys->thread, NULL); } - vlc_cond_destroy (&p_sys->wait); vlc_mutex_destroy (&p_sys->lock); +#ifdef HAVE_SRTP if (p_sys->srtp) srtp_destroy (p_sys->srtp); +#endif if (p_sys->session) rtp_session_destroy (demux, p_sys->session); if (p_sys->rtcp_fd != -1) @@ -363,7 +385,7 @@ static int Control (demux_t *demux, int i_query, va_list args) case DEMUX_GET_PTS_DELAY: { int64_t *v = va_arg (args, int64_t *); - *v = p_sys->caching * 1000; + *v = (int64_t)p_sys->caching * 1000; return VLC_SUCCESS; } @@ -409,7 +431,6 @@ static void codec_decode (demux_t *demux, void *data, block_t *block) block_Release (block); } - static void *stream_init (demux_t *demux, const char *name) { return stream_DemuxNew (demux, name, demux->out); @@ -418,7 +439,7 @@ static void *stream_init (demux_t *demux, const char *name) static void stream_destroy (demux_t *demux, void *data) { if (data) - stream_DemuxDelete ((stream_t *)data); + stream_Delete ((stream_t *)data); (void)demux; } @@ -432,6 +453,11 @@ static void stream_decode (demux_t *demux, void *data, block_t *block) (void)demux; } +static void *demux_init (demux_t *demux) +{ + return stream_init (demux, demux->psz_demux); +} + /* * Static payload types handler */ @@ -443,7 +469,20 @@ static void *pcmu_init (demux_t *demux) { es_format_t fmt; - es_format_Init (&fmt, AUDIO_ES, VLC_FOURCC ('u', 'l', 'a', 'w')); + es_format_Init (&fmt, AUDIO_ES, VLC_CODEC_MULAW); + fmt.audio.i_rate = 8000; + fmt.audio.i_channels = 1; + return codec_init (demux, &fmt); +} + +/* PT=3 + * GSM + */ +static void *gsm_init (demux_t *demux) +{ + es_format_t fmt; + + es_format_Init (&fmt, AUDIO_ES, VLC_CODEC_GSM); fmt.audio.i_rate = 8000; fmt.audio.i_channels = 1; return codec_init (demux, &fmt); @@ -456,7 +495,7 @@ static void *pcma_init (demux_t *demux) { es_format_t fmt; - es_format_Init (&fmt, AUDIO_ES, VLC_FOURCC ('a', 'l', 'a', 'w')); + es_format_Init (&fmt, AUDIO_ES, VLC_CODEC_ALAW); fmt.audio.i_rate = 8000; fmt.audio.i_channels = 1; return codec_init (demux, &fmt); @@ -469,7 +508,7 @@ static void *l16s_init (demux_t *demux) { es_format_t fmt; - es_format_Init (&fmt, AUDIO_ES, VLC_FOURCC ('s', '1', '6', 'b')); + es_format_Init (&fmt, AUDIO_ES, VLC_CODEC_S16B); fmt.audio.i_rate = 44100; fmt.audio.i_channels = 2; return codec_init (demux, &fmt); @@ -479,12 +518,25 @@ static void *l16m_init (demux_t *demux) { es_format_t fmt; - es_format_Init (&fmt, AUDIO_ES, VLC_FOURCC ('s', '1', '6', 'b')); + es_format_Init (&fmt, AUDIO_ES, VLC_CODEC_S16B); fmt.audio.i_rate = 44100; fmt.audio.i_channels = 1; return codec_init (demux, &fmt); } +/* PT=12 + * QCELP + */ +static void *qcelp_init (demux_t *demux) +{ + es_format_t fmt; + + es_format_Init (&fmt, AUDIO_ES, VLC_CODEC_QCELP); + fmt.audio.i_rate = 8000; + fmt.audio.i_channels = 1; + return codec_init (demux, &fmt); +} + /* PT=14 * MPA: MPEG Audio (RFC2250, §3.4) */ @@ -492,8 +544,9 @@ static void *mpa_init (demux_t *demux) { es_format_t fmt; - es_format_Init (&fmt, AUDIO_ES, VLC_FOURCC ('m', 'p', 'g', 'a')); + es_format_Init (&fmt, AUDIO_ES, VLC_CODEC_MPGA); fmt.audio.i_channels = 2; + fmt.b_packetized = false; return codec_init (demux, &fmt); } @@ -519,7 +572,8 @@ static void *mpv_init (demux_t *demux) { es_format_t fmt; - es_format_Init (&fmt, VIDEO_ES, VLC_FOURCC ('m', 'p', 'g', 'v')); + es_format_Init (&fmt, VIDEO_ES, VLC_CODEC_MPGV); + fmt.b_packetized = false; return codec_init (demux, &fmt); } @@ -567,6 +621,7 @@ int rtp_autodetect (demux_t *demux, rtp_session_t *session, .number = ptype, }; + /* Remember to keep this in sync with modules/services_discovery/sap.c */ switch (ptype) { case 0: @@ -575,6 +630,12 @@ int rtp_autodetect (demux_t *demux, rtp_session_t *session, pt.frequency = 8000; break; + case 3: + msg_Dbg (demux, "detected GSM"); + pt.init = gsm_init; + pt.frequency = 8000; + break; + case 8: msg_Dbg (demux, "detected G.711 A-law"); pt.init = pcma_init; @@ -593,6 +654,12 @@ int rtp_autodetect (demux_t *demux, rtp_session_t *session, pt.frequency = 44100; break; + case 12: + msg_Dbg (demux, "detected QCELP"); + pt.init = qcelp_init; + pt.frequency = 8000; + break; + case 14: msg_Dbg (demux, "detected MPEG Audio"); pt.init = mpa_init; @@ -616,7 +683,22 @@ int rtp_autodetect (demux_t *demux, rtp_session_t *session, break; default: - return -1; + /* + * If the rtp payload type is unknown then check demux if it is specified + */ + if ((strcmp(demux->psz_demux, "h264") == 0) || (strcmp(demux->psz_demux, "ts") == 0)) + { + msg_Dbg (demux, "rtp autodetect specified demux=%s", demux->psz_demux); + pt.init = demux_init; + pt.destroy = stream_destroy; + pt.decode = stream_decode; + pt.frequency = 90000; + break; + } + else + { + return -1; + } } rtp_add_type (demux, session, &pt); return 0; @@ -626,11 +708,3 @@ int rtp_autodetect (demux_t *demux, rtp_session_t *session, * Dynamic payload type handlers * Hmm, none implemented yet. */ - -/** - * Processing callback - */ -static int Demux (demux_t *demux) -{ - return rtp_process (demux) ? 0 : 1; -}