/* * send OPTIONS request, this is used as very first trial to server * we will need rtsp_hdr later, so return that. * return value: -1: failure status_code: success, rtsp_hdr_ret(malloc) */ int real_rtsp_options(struct stream_t *stream,struct rtsp_header_t **rtsp_hdr_ret) { int ret = 0; struct rtsp_ctrl_t *rtsp_ctrl = stream->stream_ctrl->rtsp_ctrl; struct rtsp_header_t *rtsp_hdr = NULL; char *options_uri = NULL; int options_uri_len = 0; /* default is rtsp-real (becasue OPTIONS req is supported) */ rtsp_hdr = new_rtsp_header_with_standard_fields(rtsp_ctrl); rtsp_set_field(rtsp_hdr,real_useragent); rtsp_set_field(rtsp_hdr,"GUID: 00000000-0000-0000-0000-000000000000"); rtsp_set_field(rtsp_hdr,real_clientid); rtsp_set_field(rtsp_hdr,"Pragma: initiate-session"); rtsp_set_field(rtsp_hdr,"RegionData: 0"); rtsp_set_field(rtsp_hdr,real_clientchallenge); rtsp_set_field(rtsp_hdr,real_companyid); rtsp_set_field(rtsp_hdr,real_playerstarttime); options_uri_len = strlen(stream->serverinfo->host) + 20; options_uri = (char *)xmalloc(options_uri_len); snprintf(options_uri,options_uri_len,"rtsp://%s:%i", stream->serverinfo->host,stream->serverinfo->port); rtsp_request_options(rtsp_hdr,options_uri); rtsp_send_request_and_free(stream,rtsp_hdr); rtsp_hdr = new_rtsp_header(); ret = rtsp_recv_header(stream,rtsp_hdr); if(ret < 0) { goto failed; } *rtsp_hdr_ret = rtsp_hdr; if(options_uri) free(options_uri); return ret; failed: if(rtsp_hdr) free_rtsp_header(rtsp_hdr); if(options_uri) free(options_uri); *rtsp_hdr_ret = NULL; return -1; }
int rtsp_connect( rtsp_client_t *rtsp, const char *psz_mrl, const char *psz_user_agent ) { rtsp_t *s; char *mrl_ptr; char *slash, *colon; unsigned int hostend, pathbegin, i; if( !psz_mrl ) return -1; s = xmalloc( sizeof(rtsp_t) ); rtsp->p_private = s; if( !strncmp( psz_mrl, "rtsp://", 7 ) ) psz_mrl += 7; mrl_ptr = strdup( psz_mrl ); for( i=0; i<MAX_FIELDS; i++ ) { s->answers[i]=NULL; s->scheduled[i]=NULL; } s->host = NULL; s->port = 554; /* rtsp standard port */ s->path = NULL; s->mrl = strdup(psz_mrl); s->server = NULL; s->server_state = 0; s->server_caps = 0; s->cseq = 0; s->session = NULL; if( psz_user_agent ) s->user_agent = strdup( psz_user_agent ); else s->user_agent = strdup( "User-Agent: RealMedia Player Version " "6.0.9.1235 (linux-2.0-libc6-i386-gcc2.95)" ); slash = strchr( mrl_ptr, '/' ); colon = strchr( mrl_ptr, ':' ); if( !slash ) slash = mrl_ptr + strlen(mrl_ptr) + 1; if( !colon ) colon = slash; if( colon > slash ) colon = slash; pathbegin = slash - mrl_ptr; hostend = colon - mrl_ptr; s->host = xmalloc(hostend+1); strncpy( s->host, mrl_ptr, hostend ); s->host[hostend] = 0; if( pathbegin < strlen(mrl_ptr) ) s->path = strdup(mrl_ptr+pathbegin+1); if( colon != slash ) { char buffer[pathbegin-hostend]; strncpy( buffer, mrl_ptr+hostend+1, pathbegin-hostend-1 ); buffer[pathbegin-hostend-1] = 0; s->port = atoi(buffer); if( s->port < 0 || s->port > 65535 ) s->port = 554; } free( mrl_ptr ); //fprintf( stderr, "got mrl: %s %i %s\n", s->host, s->port, s->path ); s->s = rtsp->pf_connect( rtsp->p_userdata, s->host, s->port ); if( s->s < 0 ) { //fprintf(stderr, "rtsp: failed to connect to '%s'\n", s->host); rtsp_close( rtsp ); return -1; } s->server_state = RTSP_CONNECTED; /* now lets send an options request. */ rtsp_schedule_field( rtsp, "CSeq: 1"); rtsp_schedule_field( rtsp, s->user_agent); rtsp_schedule_field( rtsp, "ClientChallenge: " "9e26d33f2984236010ef6253fb1887f7"); rtsp_schedule_field( rtsp, "PlayerStarttime: [28/03/2003:22:50:23 00:00]"); rtsp_schedule_field( rtsp, "CompanyID: KnKV4M4I/B2FjJ1TToLycw==" ); rtsp_schedule_field( rtsp, "GUID: 00000000-0000-0000-0000-000000000000" ); rtsp_schedule_field( rtsp, "RegionData: 0" ); rtsp_schedule_field( rtsp, "ClientID: " "Linux_2.4_6.0.9.1235_play32_RN01_EN_586" ); /*rtsp_schedule_field( rtsp, "Pragma: initiate-session" );*/ rtsp_request_options( rtsp, NULL ); return 0; }
int rtsp_connect(struct rtsp_client * rtsp, const char * host, unsigned int port, const char * mrl) { struct tcp_pcb * tp; in_addr_t host_addr; if (!inet_aton(host, (struct in_addr *)&host_addr)) { return -1; } if ((tp = tcp_alloc()) == NULL) { ERR("can't allocate socket!"); return -1; } if (port == 0) { port = rtsp->port; if (port == 0) port = 554; } INF("RTSP://%s:%d/%s", host, port, mrl); if (tcp_connect(tp, host_addr, htons(port)) < 0) { ERR("can't connect to host!"); tcp_close(tp); return -1; } rtsp->tcp = tp; rtsp->port = port; rtsp->host_addr = host_addr; rtsp->rtp.faddr = host_addr; rtsp->cseq = 1; strcpy(rtsp->host_name, host); strcpy(rtsp->media_name, mrl); if (rtsp_request_options(rtsp) < 0) { ERR("rtsp_request_options() failed!"); return -1; } if (rtsp_request_describe(rtsp) < 0) { ERR("rtsp_request_describe() failed!"); return -1; } if (rtsp_sdp_decode(rtsp) < 0) { ERR("rtsp_sdp_decode() failed!"); return -1; } INF("Track:\"%s\"", rtsp->track_name); if (rtsp_request_setup(rtsp) < 0) { ERR("rtsp_request_setup() failed!"); return -1; } if (rtsp_request_play(rtsp) < 0) { ERR("rtsp_request_play() failed!"); return -1; } return 0; }
rtsp_t *rtsp_connect(xine_stream_t *stream, const char *mrl, const char *user_agent) { rtsp_t *s = malloc(sizeof(rtsp_t)); char *mrl_ptr=strdup(mrl); char *slash, *colon, *amp; int hostend, i; size_t pathbegin; if (strncmp(mrl,"rtsp://",7)) { xprintf(stream->xine, XINE_VERBOSITY_LOG, _("rtsp: bad mrl: %s\n"), mrl); free(s); return NULL; } mrl_ptr+=7; for (i=0; i<MAX_FIELDS; i++) { s->answers[i]=NULL; s->scheduled[i]=NULL; } s->stream=stream; s->host=NULL; s->port=554; /* rtsp standard port */ s->path=NULL; s->mrl=NULL; s->mrl=strdup(mrl); s->server=NULL; s->server_state=0; s->server_caps=0; s->cseq=0; s->session=NULL; if (user_agent) s->user_agent=strdup(user_agent); else s->user_agent=strdup("User-Agent: RealMedia Player Version 6.0.9.1235 (linux-2.0-libc6-i386-gcc2.95)"); amp =strchr(mrl_ptr,'@'); slash=strchr(mrl_ptr,'/'); colon=strchr(mrl_ptr,':'); if (amp && (!slash || amp < slash)) { char *username = NULL, *password = NULL; /* xxx@host:port/ */ if (colon && colon < amp) { /* xxx:yyy@host:port/ */ username = strndup(mrl_ptr, colon - mrl_ptr); password = strndup(colon + 1, amp - colon - 1); } else { username = strndup(mrl_ptr, amp - mrl_ptr); } mrl_ptr = amp + 1; slash = strchr(mrl_ptr, '/'); colon = strchr(mrl_ptr, ':'); if (username) { char *auth; rtsp_basicauth(username, password, &auth); s->auth = _x_asprintf("Authorization: Basic %s", auth); free(auth); } free(username); free(password); } if(!slash) slash=mrl_ptr+strlen(mrl_ptr)+1; if(!colon) colon=slash; if(colon > slash) colon=slash; pathbegin=slash-mrl_ptr; hostend=colon-mrl_ptr; s->host = strndup(mrl_ptr, hostend); if (pathbegin < strlen(mrl_ptr)) s->path=strdup(mrl_ptr+pathbegin+1); if (colon != slash) { char buffer[pathbegin-hostend]; strncpy(buffer,mrl_ptr+hostend+1, pathbegin-hostend-1); buffer[pathbegin-hostend-1]=0; s->port=atoi(buffer); if (s->port < 0 || s->port > 65535) s->port = 554; /* rtsp standard port */ } lprintf("got mrl: %s %i %s\n",s->host,s->port,s->path); s->s = _x_io_tcp_connect (stream, s->host, s->port); if (s->s < 0) { xprintf (stream->xine, XINE_VERBOSITY_LOG, _("rtsp: failed to connect to '%s'\n"), s->host); rtsp_close(s); return NULL; } s->server_state=RTSP_CONNECTED; /* now lets send an options request. */ rtsp_schedule_field(s, "CSeq: 1"); rtsp_schedule_field(s, s->user_agent); rtsp_schedule_field(s, "ClientChallenge: 9e26d33f2984236010ef6253fb1887f7"); rtsp_schedule_field(s, "PlayerStarttime: [28/03/2003:22:50:23 00:00]"); rtsp_schedule_field(s, "CompanyID: KnKV4M4I/B2FjJ1TToLycw=="); rtsp_schedule_field(s, "GUID: 00000000-0000-0000-0000-000000000000"); rtsp_schedule_field(s, "RegionData: 0"); rtsp_schedule_field(s, "ClientID: Linux_2.4_6.0.9.1235_play32_RN01_EN_586"); /*rtsp_schedule_field(s, "Pragma: initiate-session");*/ rtsp_request_options(s, NULL); return s; }