📄 live555.cpp
字号:
/***************************************************************************** * live555.cpp : LIVE555 Streaming Media support. ***************************************************************************** * Copyright (C) 2003-2007 the VideoLAN team * $Id: aeba245bb46007e454d4ffd763171c6a32151221 $ * * Authors: Laurent Aimar <fenrir@via.ecp.fr> * Derk-Jan Hartman <hartman at videolan. org> * Derk-Jan Hartman <djhartman at m2x .dot. nl> for M2X * * This program 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 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * 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 General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************//* For inttypes.h * Note: config.h may include inttypes.h, so make sure we define this option * early enough. */#define __STDC_CONSTANT_MACROS 1#ifdef HAVE_CONFIG_H# include "config.h"#endif#include <inttypes.h>#include <vlc_common.h>#include <vlc_plugin.h>#include <vlc_demux.h>#include <vlc_interface.h>#include <vlc_network.h>#include <vlc_url.h>#include <iostream>#include <limits.h>#if defined( WIN32 )# include <winsock2.h>#endif#include "UsageEnvironment.hh"#include "BasicUsageEnvironment.hh"#include "GroupsockHelper.hh"#include "liveMedia.hh"extern "C" {#include "../access/mms/asf.h" /* Who said ugly ? */}using namespace std;/***************************************************************************** * Module descriptor *****************************************************************************/static int Open ( vlc_object_t * );static void Close( vlc_object_t * );#define CACHING_TEXT N_("Caching value (ms)")#define CACHING_LONGTEXT N_( \ "Allows you to modify the default caching value for RTSP streams. This " \ "value should be set in millisecond units." )#define KASENNA_TEXT N_( "Kasenna RTSP dialect")#define KASENNA_LONGTEXT N_( "Kasenna servers use an old and unstandard " \ "dialect of RTSP. When you set this parameter, VLC will try this dialect "\ "for communication. In this mode you cannot connect to normal RTSP servers." )#define USER_TEXT N_("RTSP user name")#define USER_LONGTEXT N_("Allows you to modify the user name that will " \ "be used for authenticating the connection.")#define PASS_TEXT N_("RTSP password")#define PASS_LONGTEXT N_("Allows you to modify the password that will be " \ "used for the connection.")vlc_module_begin(); set_description( N_("RTP/RTSP/SDP demuxer (using Live555)" ) ); set_capability( "demux", 50 ); set_shortname( "RTP/RTSP"); set_callbacks( Open, Close ); add_shortcut( "live" ); add_shortcut( "livedotcom" ); set_category( CAT_INPUT ); set_subcategory( SUBCAT_INPUT_DEMUX ); add_submodule(); set_description( N_("RTSP/RTP access and demux") ); add_shortcut( "rtsp" ); add_shortcut( "sdp" ); set_capability( "access_demux", 0 ); set_callbacks( Open, Close ); add_bool( "rtsp-tcp", 0, NULL, N_("Use RTP over RTSP (TCP)"), N_("Use RTP over RTSP (TCP)"), true ); add_integer( "rtp-client-port", -1, NULL, N_("Client port"), N_("Port to use for the RTP source of the session"), true ); add_bool( "rtsp-mcast", false, NULL, N_("Force multicast RTP via RTSP"), N_("Force multicast RTP via RTSP"), true ); add_bool( "rtsp-http", 0, NULL, N_("Tunnel RTSP and RTP over HTTP"), N_("Tunnel RTSP and RTP over HTTP"), true ); add_integer( "rtsp-http-port", 80, NULL, N_("HTTP tunnel port"), N_("Port to use for tunneling the RTSP/RTP over HTTP."), true ); add_integer("rtsp-caching", 4 * DEFAULT_PTS_DELAY / 1000, NULL, CACHING_TEXT, CACHING_LONGTEXT, true ); add_bool( "rtsp-kasenna", false, NULL, KASENNA_TEXT, KASENNA_LONGTEXT, true ); add_string( "rtsp-user", NULL, NULL, USER_TEXT, USER_LONGTEXT, true ); add_string( "rtsp-pwd", NULL, NULL, PASS_TEXT, PASS_LONGTEXT, true );vlc_module_end();/***************************************************************************** * Local prototypes *****************************************************************************/typedef struct{ demux_t *p_demux; MediaSubsession *sub; es_format_t fmt; es_out_id_t *p_es; bool b_muxed; bool b_quicktime; bool b_asf; stream_t *p_out_muxed; /* for muxed stream */ uint8_t *p_buffer; unsigned int i_buffer; bool b_rtcp_sync; char waiting; int64_t i_pts; int64_t i_npt;} live_track_t;struct timeout_thread_t{ VLC_COMMON_MEMBERS int64_t i_remain; bool b_handle_keep_alive; demux_sys_t *p_sys;};struct demux_sys_t{ char *p_sdp; /* XXX mallocated */ char *psz_path; /* URL-encoded path */ vlc_url_t url; MediaSession *ms; TaskScheduler *scheduler; UsageEnvironment *env ; RTSPClient *rtsp; /* */ int i_track; live_track_t **track; /* XXX mallocated */ /* Weird formats */ asf_header_t asfh; stream_t *p_out_asf; bool b_real; /* */ int64_t i_pcr; /* The clock */ int64_t i_npt; int64_t i_npt_length; int64_t i_npt_start; /* timeout thread information */ int i_timeout; /* session timeout value in seconds */ bool b_timeout_call;/* mark to send an RTSP call to prevent server timeout */ timeout_thread_t *p_timeout; /* the actual thread that makes sure we don't timeout */ /* */ bool b_force_mcast; bool b_multicast; /* if one of the tracks is multicasted */ bool b_no_data; /* if we never received any data */ int i_no_data_ti; /* consecutive number of TaskInterrupt */ char event; bool b_get_param; /* Does the server support GET_PARAMETER */};static int Demux ( demux_t * );static int Control( demux_t *, int, va_list );static int Connect ( demux_t * );static int SessionsSetup( demux_t * );static int Play ( demux_t *);static int ParseASF ( demux_t * );static int RollOverTcp ( demux_t * );static void StreamRead ( void *, unsigned int, unsigned int, struct timeval, unsigned int );static void StreamClose ( void * );static void TaskInterrupt( void * );static void* TimeoutPrevention( vlc_object_t * );static unsigned char* parseH264ConfigStr( char const* configStr, unsigned int& configSize );/***************************************************************************** * DemuxOpen: *****************************************************************************/static int Open ( vlc_object_t *p_this ){ demux_t *p_demux = (demux_t*)p_this; demux_sys_t *p_sys = NULL; MediaSubsessionIterator *iter = NULL; MediaSubsession *sub = NULL; int i, i_return; int i_error = VLC_EGENERIC; if( p_demux->s ) { /* See if it looks like a SDP v, o, s fields are mandatory and in this order */ const uint8_t *p_peek; if( stream_Peek( p_demux->s, &p_peek, 7 ) < 7 ) return VLC_EGENERIC; if( memcmp( p_peek, "v=0\r\n", 5 ) && memcmp( p_peek, "v=0\n", 4 ) && ( p_peek[0] < 'a' || p_peek[0] > 'z' || p_peek[1] != '=' ) ) { return VLC_EGENERIC; } } else { var_Create( p_demux, "rtsp-caching", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT ); } p_demux->pf_demux = Demux; p_demux->pf_control= Control; p_demux->p_sys = p_sys = (demux_sys_t*)malloc( sizeof( demux_sys_t ) ); if( !p_sys ) return VLC_ENOMEM; p_sys->p_sdp = NULL; p_sys->scheduler = NULL; p_sys->env = NULL; p_sys->ms = NULL; p_sys->rtsp = NULL; p_sys->i_track = 0; p_sys->track = NULL; p_sys->i_pcr = 0; p_sys->i_npt = 0; p_sys->i_npt_start = 0; p_sys->i_npt_length = 0; p_sys->p_out_asf = NULL; p_sys->b_no_data = true; p_sys->i_no_data_ti = 0; p_sys->p_timeout = NULL; p_sys->i_timeout = 0; p_sys->b_timeout_call = false; p_sys->b_multicast = false; p_sys->b_real = false; p_sys->psz_path = strdup( p_demux->psz_path ); p_sys->b_force_mcast = var_CreateGetBool( p_demux, "rtsp-mcast" ); p_sys->b_get_param = false; /* parse URL for rtsp://[user:[passwd]@]serverip:port/options */ vlc_UrlParse( &p_sys->url, p_sys->psz_path, 0 ); if( ( p_sys->scheduler = BasicTaskScheduler::createNew() ) == NULL ) { msg_Err( p_demux, "BasicTaskScheduler::createNew failed" ); goto error; } if( !( p_sys->env = BasicUsageEnvironment::createNew(*p_sys->scheduler) ) ) { msg_Err( p_demux, "BasicUsageEnvironment::createNew failed" ); goto error; } if( strcasecmp( p_demux->psz_access, "sdp" ) ) { char *p = p_sys->psz_path; while( (p = strchr( p, ' ' )) != NULL ) *p = '+'; } if( p_demux->s != NULL ) { /* Gather the complete sdp file */ int i_sdp = 0; int i_sdp_max = 1000; uint8_t *p_sdp = (uint8_t*) malloc( i_sdp_max ); if( !p_sdp ) { i_error = VLC_ENOMEM; goto error; } for( ;; ) { int i_read = stream_Read( p_demux->s, &p_sdp[i_sdp], i_sdp_max - i_sdp - 1 ); if( !vlc_object_alive (p_demux) || p_demux->b_error ) { free( p_sdp ); goto error; } if( i_read < 0 ) { msg_Err( p_demux, "failed to read SDP" ); free( p_sdp ); goto error; } i_sdp += i_read; if( i_read < i_sdp_max - i_sdp - 1 ) { p_sdp[i_sdp] = '\0'; break; } i_sdp_max += 1000; p_sdp = (uint8_t*)realloc( p_sdp, i_sdp_max ); } p_sys->p_sdp = (char*)p_sdp; } else if( ( p_demux->s == NULL ) && !strcasecmp( p_demux->psz_access, "sdp" ) ) { /* sdp:// link from SAP */ p_sys->p_sdp = strdup( p_sys->psz_path ); } else if( ( i_return = Connect( p_demux ) ) != VLC_SUCCESS ) { msg_Err( p_demux, "Failed to connect with rtsp://%s", p_sys->psz_path ); goto error; } if( p_sys->p_sdp == NULL ) { msg_Err( p_demux, "Failed to retrieve the RTSP Session Description" ); i_error = VLC_ENOMEM; goto error; } if( ( i_return = SessionsSetup( p_demux ) ) != VLC_SUCCESS ) { msg_Err( p_demux, "Nothing to play for rtsp://%s", p_sys->psz_path ); goto error;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -