📄 live555.cpp
字号:
else if( !strcmp( sub->codecName(), "PCMU" ) ) { tk->fmt.i_codec = VLC_FOURCC( 'u', 'l', 'a', 'w' ); } else if( !strcmp( sub->codecName(), "PCMA" ) ) { tk->fmt.i_codec = VLC_FOURCC( 'a', 'l', 'a', 'w' ); } else if( !strncmp( sub->codecName(), "G726", 4 ) ) { tk->fmt.i_codec = VLC_FOURCC( 'g', '7', '2', '6' ); tk->fmt.audio.i_rate = 8000; tk->fmt.audio.i_channels = 1; if( !strcmp( sub->codecName()+5, "40" ) ) tk->fmt.i_bitrate = 40000; else if( !strcmp( sub->codecName()+5, "32" ) ) tk->fmt.i_bitrate = 32000; else if( !strcmp( sub->codecName()+5, "24" ) ) tk->fmt.i_bitrate = 24000; else if( !strcmp( sub->codecName()+5, "16" ) ) tk->fmt.i_bitrate = 16000; } else if( !strcmp( sub->codecName(), "AMR" ) ) { tk->fmt.i_codec = VLC_FOURCC( 's', 'a', 'm', 'r' ); } else if( !strcmp( sub->codecName(), "AMR-WB" ) ) { tk->fmt.i_codec = VLC_FOURCC( 's', 'a', 'w', 'b' ); } else if( !strcmp( sub->codecName(), "MP4A-LATM" ) ) { unsigned int i_extra; uint8_t *p_extra; tk->fmt.i_codec = VLC_FOURCC( 'm', 'p', '4', 'a' ); if( ( p_extra = parseStreamMuxConfigStr( sub->fmtp_config(), i_extra ) ) ) { tk->fmt.i_extra = i_extra; tk->fmt.p_extra = malloc( i_extra ); memcpy( tk->fmt.p_extra, p_extra, i_extra ); delete[] p_extra; }#if LIVEMEDIA_LIBRARY_VERSION_INT >= 1141257600 /* Because the "faad" decoder does not handle the LATM data length field at the start of each returned LATM frame, tell the RTP source to omit it. */ ((MPEG4LATMAudioRTPSource*)sub->rtpSource())->omitLATMDataLengthField();#endif } else if( !strcmp( sub->codecName(), "MPEG4-GENERIC" ) ) { unsigned int i_extra; uint8_t *p_extra; tk->fmt.i_codec = VLC_FOURCC( 'm', 'p', '4', 'a' ); if( ( p_extra = parseGeneralConfigStr( sub->fmtp_config(), i_extra ) ) ) { tk->fmt.i_extra = i_extra; tk->fmt.p_extra = malloc( i_extra ); memcpy( tk->fmt.p_extra, p_extra, i_extra ); delete[] p_extra; } } else if( !strcmp( sub->codecName(), "X-ASF-PF" ) ) { tk->b_asf = VLC_TRUE; if( p_sys->p_out_asf == NULL ) p_sys->p_out_asf = stream_DemuxNew( p_demux, "asf", p_demux->out ); } } else if( !strcmp( sub->mediumName(), "video" ) ) { es_format_Init( &tk->fmt, VIDEO_ES, VLC_FOURCC('u','n','d','f') ); if( !strcmp( sub->codecName(), "MPV" ) ) { tk->fmt.i_codec = VLC_FOURCC( 'm', 'p', 'g', 'v' ); } else if( !strcmp( sub->codecName(), "H263" ) || !strcmp( sub->codecName(), "H263-1998" ) || !strcmp( sub->codecName(), "H263-2000" ) ) { tk->fmt.i_codec = VLC_FOURCC( 'H', '2', '6', '3' ); } else if( !strcmp( sub->codecName(), "H261" ) ) { tk->fmt.i_codec = VLC_FOURCC( 'H', '2', '6', '1' ); } else if( !strcmp( sub->codecName(), "H264" ) ) {#if LIVEMEDIA_LIBRARY_VERSION_INT >= 1117756800 unsigned int i_extra = 0; uint8_t *p_extra = NULL;#endif tk->fmt.i_codec = VLC_FOURCC( 'h', '2', '6', '4' ); tk->fmt.b_packetized = VLC_FALSE; /* XXX not the right minimal version I fear */#if LIVEMEDIA_LIBRARY_VERSION_INT >= 1117756800 if((p_extra=parseH264ConfigStr( sub->fmtp_spropparametersets(), i_extra ) ) ) { tk->fmt.i_extra = i_extra; tk->fmt.p_extra = malloc( i_extra ); memcpy( tk->fmt.p_extra, p_extra, i_extra ); delete[] p_extra; }#endif } else if( !strcmp( sub->codecName(), "JPEG" ) ) { tk->fmt.i_codec = VLC_FOURCC( 'M', 'J', 'P', 'G' ); } else if( !strcmp( sub->codecName(), "MP4V-ES" ) ) { unsigned int i_extra; uint8_t *p_extra; tk->fmt.i_codec = VLC_FOURCC( 'm', 'p', '4', 'v' ); if( ( p_extra = parseGeneralConfigStr( sub->fmtp_config(), i_extra ) ) ) { tk->fmt.i_extra = i_extra; tk->fmt.p_extra = malloc( i_extra ); memcpy( tk->fmt.p_extra, p_extra, i_extra ); delete[] p_extra; } } else if( !strcmp( sub->codecName(), "X-QT" ) || !strcmp( sub->codecName(), "X-QUICKTIME" ) || !strcmp( sub->codecName(), "X-QDM" ) || !strcmp( sub->codecName(), "X-SV3V-ES" ) || !strcmp( sub->codecName(), "X-SORENSONVIDEO" ) ) { tk->b_quicktime = VLC_TRUE; } else if( !strcmp( sub->codecName(), "MP2T" ) ) { tk->b_muxed = VLC_TRUE; tk->p_out_muxed = stream_DemuxNew( p_demux, "ts", p_demux->out ); } else if( !strcmp( sub->codecName(), "MP2P" ) || !strcmp( sub->codecName(), "MP1S" ) ) { tk->b_muxed = VLC_TRUE; tk->p_out_muxed = stream_DemuxNew( p_demux, "ps", p_demux->out ); } else if( !strcmp( sub->codecName(), "X-ASF-PF" ) ) { tk->b_asf = VLC_TRUE; if( p_sys->p_out_asf == NULL ) p_sys->p_out_asf = stream_DemuxNew( p_demux, "asf", p_demux->out );; } } if( !tk->b_quicktime && !tk->b_muxed && !tk->b_asf ) { tk->p_es = es_out_Add( p_demux->out, &tk->fmt ); } if( sub->rtcpInstance() != NULL ) { sub->rtcpInstance()->setByeHandler( StreamClose, tk ); } if( tk->p_es || tk->b_quicktime || tk->b_muxed || tk->b_asf ) { tk->readSource = sub->readSource(); tk->rtpSource = sub->rtpSource(); /* Append */ p_sys->track = (live_track_t**)realloc( p_sys->track, sizeof( live_track_t ) * ( p_sys->i_track + 1 ) ); p_sys->track[p_sys->i_track++] = tk; } else { /* BUG ??? */ msg_Err( p_demux, "unusable RTSP track. this should not happen" ); free( tk ); } } delete iter; if( p_sys->p_out_asf && ParseASF( p_demux ) ) { msg_Err( p_demux, "cannot find a usable asf header" ); /* TODO Clean tracks */ goto error; } if( p_sys->i_track <= 0 ) goto error; return VLC_SUCCESS;error: if( p_sys->p_out_asf ) stream_DemuxDelete( p_sys->p_out_asf ); if( p_sys->ms ) Medium::close( p_sys->ms ); if( p_sys->rtsp ) RTSPClient::close( p_sys->rtsp ); if( p_sys->env ) RECLAIM_ENV(p_sys->env); if( p_sys->p_timeout ) { p_sys->p_timeout->b_die = VLC_TRUE; vlc_thread_join( p_sys->p_timeout ); vlc_object_detach( p_sys->p_timeout ); vlc_object_destroy( p_sys->p_timeout ); } if( p_sys->scheduler ) delete p_sys->scheduler; if( p_sys->p_sdp ) free( p_sys->p_sdp ); if( p_sys->psz_path ) free( p_sys->psz_path ); free( p_sys ); return VLC_EGENERIC;}/***************************************************************************** * DemuxClose: *****************************************************************************/static void Close( vlc_object_t *p_this ){ demux_t *p_demux = (demux_t*)p_this; demux_sys_t *p_sys = p_demux->p_sys; int i; for( i = 0; i < p_sys->i_track; i++ ) { live_track_t *tk = p_sys->track[i]; if( tk->b_muxed ) stream_DemuxDelete( tk->p_out_muxed ); free( tk->p_buffer ); free( tk ); } if( p_sys->i_track ) free( p_sys->track ); if( p_sys->p_out_asf ) stream_DemuxDelete( p_sys->p_out_asf ); if( p_sys->rtsp && p_sys->ms ) { /* TEARDOWN */ p_sys->rtsp->teardownMediaSession( *p_sys->ms ); } Medium::close( p_sys->ms ); if( p_sys->p_timeout ) { p_sys->p_timeout->b_die = VLC_TRUE; vlc_thread_join( p_sys->p_timeout ); vlc_object_detach( p_sys->p_timeout ); vlc_object_destroy( p_sys->p_timeout ); } if( p_sys->rtsp ) RTSPClient::close( p_sys->rtsp ); if( p_sys->env ) RECLAIM_ENV( p_sys->env ); if( p_sys->scheduler ) delete p_sys->scheduler; if( p_sys->p_sdp ) free( p_sys->p_sdp ); if( p_sys->psz_path ) free( p_sys->psz_path ); free( p_sys );}/***************************************************************************** * Connect: connects to the RTSP server to setup the session DESCRIBE *****************************************************************************/static int Connect( demux_t *p_demux ){ demux_sys_t *p_sys = p_demux->p_sys; Authenticator authenticator; char *psz_user = NULL; char *psz_pwd = NULL; char *psz_url = NULL; char *psz_options = NULL; char *p_sdp = NULL; int i_http_port = 0; int i_ret = VLC_SUCCESS;createnew: if( var_CreateGetBool( p_demux, "rtsp-http" ) ) i_http_port = var_CreateGetInteger( p_demux, "rtsp-http-port" );#if LIVEMEDIA_LIBRARY_VERSION_INT > 1130457500 if( ( p_sys->rtsp = RTSPClient::createNew(*p_sys->env, 1 /*verbose*/, "VLC media player", i_http_port ) ) == NULL )#else if( ( p_sys->rtsp = RTSPClient::createNew(*p_sys->env, 1 /*verbose*/, "VLC media player" ) ) == NULL )#endif { msg_Err( p_demux, "RTSPClient::createNew failed (%s)", p_sys->env->getResultMsg() ); return VLC_EGENERIC; } psz_url = (char*)malloc( strlen( p_sys->psz_path ) + 8 ); sprintf( psz_url, "rtsp://%s", p_sys->psz_path ); psz_options = p_sys->rtsp->sendOptionsCmd( psz_url ); if( psz_options ) delete [] psz_options; psz_user = var_CreateGetString( p_demux, "rtsp-user" ); psz_pwd = var_CreateGetString( p_demux, "rtsp-pwd" ); authenticator.setUsernameAndPassword( (const char*)psz_user, (const char*)psz_pwd ); p_sdp = p_sys->rtsp->describeURL( psz_url, &authenticator, var_CreateGetBool( p_demux, "rtsp-kasenna" ) ); if( psz_user ) free( psz_user ); if( psz_pwd ) free( psz_pwd ); if( p_sdp == NULL ) { /* failure occured */ int i_code = 0; const char *psz_error = p_sys->env->getResultMsg(); msg_Dbg( p_demux, "DESCRIBE failed with %d: %s", i_code, psz_error ); sscanf( psz_error, "%*sRTSP/%*s%3u", &i_code ); if( i_code == 401 ) { msg_Err( p_demux, "RTSP authentication failed" ); } else if( !var_CreateGetBool( p_demux, "rtsp-http" ) ) { /* Perhaps a firewall is being annoying. Try HTTP tunneling mode */ vlc_value_t val; val.b_bool = VLC_TRUE; msg_Dbg( p_demux, "we will now try HTTP tunneling mode" ); var_Set( p_demux, "rtsp-http", val ); if( psz_url ) free( psz_url ); if( p_sys->rtsp ) RTSPClient::close( p_sys->rtsp ); goto createnew; } i_ret = VLC_EGENERIC; } if( psz_url ) free( psz_url ); /* malloc-ated copy */ if( p_sys->p_sdp ) free( p_sys->p_sdp ); if( p_sdp ) p_sys->p_sdp = strdup( (char*)p_sdp ); delete[] p_sdp; return i_ret;}/***************************************************************************** * Connect: prepares the subsessions and does the SETUP *****************************************************************************/static int SessionsSetup( demux_t *p_demux ){ demux_sys_t *p_sys = p_demux->p_sys; MediaSubsessionIterator *iter = NULL; MediaSubsession *sub = NULL; vlc_bool_t b_rtsp_tcp = VLC_FALSE; int i_client_port; int i_active_sessions = 0; int i_return = VLC_SUCCESS; unsigned int i_buffer = 0; unsigned const thresh = 200000; /* RTP reorder threshold .2 second (default .1) */ b_rtsp_tcp = var_CreateGetBool( p_demux, "rtsp-tcp" ); i_client_port = var_CreateGetInteger( p_demux, "rtp-client-port" ); /* Initialise each media subsession */ iter = new MediaSubsessionIterator( *p_sys->ms ); while( ( sub = iter->next() ) != NULL ) { Boolean bInit; /* Value taken from mplayer */ if( !strcmp( sub->mediumName(), "audio" ) ) i_buffer = 100000; else if( !strcmp( sub->mediumName(), "video" ) ) i_buffer = 2000000; else continue; if( i_client_port != -1 ) { sub->setClientPortNum( i_client_port ); i_client_port += 2; } if( strcasestr( sub->codecName(), "REAL" ) ) { msg_Info( p_demux, "real codec detected, using real-RTSP instead" ); i_return = VLC_EGENERIC; break; } if( !strcmp( sub->codecName(), "X-ASF-PF" ) ) bInit = sub->initiate( 4 ); /* Constant ? */ else bInit = sub->initiate(); if( !bInit ) { msg_Warn( p_demux, "RTP subsession '%s/%s' failed (%s)", sub->mediumName(), sub->codecName(), p_sys->env->getResultMsg() ); } else { if( sub->rtpSource() != NULL ) { int fd = sub->rtpSource()->RTPgs()->socketNum(); /* Increase the buffer size */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -