rtsp_stream_t *RtspSetup( vlc_object_t *owner, vod_media_t *media, const char *path ) { rtsp_stream_t *rtsp = (rtsp_stream_t *)malloc( sizeof( *rtsp ) ); // sunqueen modify if( rtsp == NULL ) { free( rtsp ); return NULL; } rtsp->owner = owner; rtsp->vod_media = media; rtsp->sessionc = 0; rtsp->sessionv = NULL; rtsp->host = NULL; rtsp->url = NULL; rtsp->psz_path = NULL; rtsp->track_id = 0; vlc_mutex_init( &rtsp->lock ); rtsp->timeout = var_InheritInteger(owner, "rtsp-timeout"); if (rtsp->timeout > 0) { if (vlc_timer_create(&rtsp->timer, RtspTimeOut, rtsp)) goto error; } rtsp->psz_path = strdup( (path != NULL) ? path : "/" ); if( rtsp->psz_path == NULL ) goto error; msg_Dbg( owner, "RTSP stream at %s", rtsp->psz_path ); rtsp->host = vlc_rtsp_HostNew( VLC_OBJECT(owner) ); if( rtsp->host == NULL ) goto error; char *user = var_InheritString(owner, "sout-rtsp-user"); char *pwd = var_InheritString(owner, "sout-rtsp-pwd"); rtsp->url = httpd_UrlNew( rtsp->host, rtsp->psz_path, user, pwd ); free(user); free(pwd); if( rtsp->url == NULL ) goto error; httpd_UrlCatch( rtsp->url, HTTPD_MSG_DESCRIBE, RtspCallback, (httpd_callback_sys_t *)rtsp ); // sunqueen modify httpd_UrlCatch( rtsp->url, HTTPD_MSG_SETUP, RtspCallback, (httpd_callback_sys_t *)rtsp ); // sunqueen modify httpd_UrlCatch( rtsp->url, HTTPD_MSG_PLAY, RtspCallback, (httpd_callback_sys_t *)rtsp ); // sunqueen modify httpd_UrlCatch( rtsp->url, HTTPD_MSG_PAUSE, RtspCallback, (httpd_callback_sys_t *)rtsp ); // sunqueen modify httpd_UrlCatch( rtsp->url, HTTPD_MSG_GETPARAMETER, RtspCallback, (httpd_callback_sys_t *)rtsp ); // sunqueen modify httpd_UrlCatch( rtsp->url, HTTPD_MSG_TEARDOWN, RtspCallback, (httpd_callback_sys_t *)rtsp ); // sunqueen modify return rtsp; error: RtspUnsetup( rtsp ); return NULL; }
rtsp_stream_id_t *RtspAddId( rtsp_stream_t *rtsp, sout_stream_id_t *sid, uint32_t ssrc, unsigned clock_rate, int mcast_fd) { if (rtsp->track_id > 999) { msg_Err(rtsp->owner, "RTSP: too many IDs!"); return NULL; } char *urlbuf; rtsp_stream_id_t *id = (rtsp_stream_id_t *)malloc( sizeof( *id ) ); // sunqueen modify httpd_url_t *url; if( id == NULL ) return NULL; id->stream = rtsp; id->sout_id = sid; id->track_id = rtsp->track_id; id->ssrc = ssrc; id->clock_rate = clock_rate; id->mcast_fd = mcast_fd; urlbuf = RtspAppendTrackPath( id, rtsp->psz_path ); if( urlbuf == NULL ) { free( id ); return NULL; } msg_Dbg( rtsp->owner, "RTSP: adding %s", urlbuf ); char *user = var_InheritString(rtsp->owner, "sout-rtsp-user"); char *pwd = var_InheritString(rtsp->owner, "sout-rtsp-pwd"); url = id->url = httpd_UrlNew( rtsp->host, urlbuf, user, pwd ); free( user ); free( pwd ); free( urlbuf ); if( url == NULL ) { free( id ); return NULL; } httpd_UrlCatch( url, HTTPD_MSG_DESCRIBE, RtspCallbackId, (httpd_callback_sys_t *)id ); // sunqueen modify httpd_UrlCatch( url, HTTPD_MSG_SETUP, RtspCallbackId, (httpd_callback_sys_t *)id ); // sunqueen modify httpd_UrlCatch( url, HTTPD_MSG_PLAY, RtspCallbackId, (httpd_callback_sys_t *)id ); // sunqueen modify httpd_UrlCatch( url, HTTPD_MSG_PAUSE, RtspCallbackId, (httpd_callback_sys_t *)id ); // sunqueen modify httpd_UrlCatch( url, HTTPD_MSG_GETPARAMETER, RtspCallbackId, (httpd_callback_sys_t *)id ); // sunqueen modify httpd_UrlCatch( url, HTTPD_MSG_TEARDOWN, RtspCallbackId, (httpd_callback_sys_t *)id ); // sunqueen modify rtsp->track_id++; return id; }
rtsp_stream_t *RtspSetup( sout_stream_t *p_stream, const vlc_url_t *url ) { rtsp_stream_t *rtsp = malloc( sizeof( *rtsp ) ); if( rtsp == NULL || ( url->i_port > 99999 ) ) { free( rtsp ); return NULL; } rtsp->owner = p_stream; rtsp->sessionc = 0; rtsp->sessionv = NULL; rtsp->host = NULL; rtsp->url = NULL; rtsp->psz_path = NULL; vlc_mutex_init( &rtsp->lock ); rtsp->port = (url->i_port > 0) ? url->i_port : 554; rtsp->psz_path = strdup( ( url->psz_path != NULL ) ? url->psz_path : "/" ); if( rtsp->psz_path == NULL ) goto error; assert( strlen( rtsp->psz_path ) > 0 ); if( rtsp->psz_path[strlen( rtsp->psz_path ) - 1] == '/' ) rtsp->track_fmt = "%strackID=%u"; else rtsp->track_fmt = "%s/trackID=%u"; msg_Dbg( p_stream, "RTSP stream: host %s port %d at %s", url->psz_host, rtsp->port, rtsp->psz_path ); rtsp->host = httpd_HostNew( VLC_OBJECT(p_stream), url->psz_host, rtsp->port ); if( rtsp->host == NULL ) goto error; rtsp->url = httpd_UrlNewUnique( rtsp->host, rtsp->psz_path, NULL, NULL, NULL ); if( rtsp->url == NULL ) goto error; httpd_UrlCatch( rtsp->url, HTTPD_MSG_DESCRIBE, RtspCallback, (void*)rtsp ); httpd_UrlCatch( rtsp->url, HTTPD_MSG_SETUP, RtspCallback, (void*)rtsp ); httpd_UrlCatch( rtsp->url, HTTPD_MSG_PLAY, RtspCallback, (void*)rtsp ); httpd_UrlCatch( rtsp->url, HTTPD_MSG_PAUSE, RtspCallback, (void*)rtsp ); httpd_UrlCatch( rtsp->url, HTTPD_MSG_GETPARAMETER, RtspCallback, (void*)rtsp ); httpd_UrlCatch( rtsp->url, HTTPD_MSG_TEARDOWN, RtspCallback, (void*)rtsp ); return rtsp; error: RtspUnsetup( rtsp ); return NULL; }
rtsp_stream_id_t *RtspAddId( rtsp_stream_t *rtsp, sout_stream_id_t *sid, unsigned num, uint32_t ssrc, /* Multicast stuff - TODO: cleanup */ const char *dst, int ttl, unsigned loport, unsigned hiport ) { char urlbuf[sizeof( "/trackID=123" ) + strlen( rtsp->psz_path )]; rtsp_stream_id_t *id = malloc( sizeof( *id ) ); httpd_url_t *url; if( id == NULL ) return NULL; id->stream = rtsp; id->sout_id = sid; id->ssrc = ssrc; /* TODO: can we assume that this need not be strdup'd? */ id->dst = dst; if( id->dst != NULL ) { id->ttl = ttl; id->loport = loport; id->hiport = hiport; } /* FIXME: num screws up if any ES has been removed and re-added */ snprintf( urlbuf, sizeof( urlbuf ), rtsp->track_fmt, rtsp->psz_path, num ); msg_Dbg( rtsp->owner, "RTSP: adding %s", urlbuf ); url = id->url = httpd_UrlNewUnique( rtsp->host, urlbuf, NULL, NULL, NULL ); if( url == NULL ) { free( id ); return NULL; } httpd_UrlCatch( url, HTTPD_MSG_DESCRIBE, RtspCallbackId, (void *)id ); httpd_UrlCatch( url, HTTPD_MSG_SETUP, RtspCallbackId, (void *)id ); httpd_UrlCatch( url, HTTPD_MSG_PLAY, RtspCallbackId, (void *)id ); httpd_UrlCatch( url, HTTPD_MSG_PAUSE, RtspCallbackId, (void *)id ); httpd_UrlCatch( url, HTTPD_MSG_GETPARAMETER, RtspCallbackId, (void *)id ); httpd_UrlCatch( url, HTTPD_MSG_TEARDOWN, RtspCallbackId, (void *)id ); return id; }