Thread: [Mplayerxp-cvslog] SF.net SVN: mplayerxp:[569] mplayerxp/libmpstream2
Brought to you by:
olov
From: <nic...@us...> - 2012-12-17 12:05:54
|
Revision: 569 http://mplayerxp.svn.sourceforge.net/mplayerxp/?rev=569&view=rev Author: nickols_k Date: 2012-12-17 12:05:45 +0000 (Mon, 17 Dec 2012) Log Message: ----------- use references instead of pointers Modified Paths: -------------- mplayerxp/libmpstream2/asf_mmst_streaming.cpp mplayerxp/libmpstream2/asf_streaming.cpp mplayerxp/libmpstream2/asf_streaming.h mplayerxp/libmpstream2/network.cpp mplayerxp/libmpstream2/network.h mplayerxp/libmpstream2/s_network.cpp mplayerxp/libmpstream2/s_rtsp.cpp mplayerxp/libmpstream2/s_udp.cpp mplayerxp/libmpstream2/stream.h Modified: mplayerxp/libmpstream2/asf_mmst_streaming.cpp =================================================================== --- mplayerxp/libmpstream2/asf_mmst_streaming.cpp 2012-12-17 10:31:40 UTC (rev 568) +++ mplayerxp/libmpstream2/asf_mmst_streaming.cpp 2012-12-17 12:05:45 UTC (rev 569) @@ -204,7 +204,7 @@ } -static int get_header (Tcp& tcp, uint8_t *header, networking_t *networking) +static int get_header (Tcp& tcp, uint8_t *header, networking_t& networking) { unsigned char pre_header[8]; int header_len; @@ -362,7 +362,7 @@ } -static int get_media_packet (Tcp& tcp, int padding, networking_t *stream_ctrl) { +static int get_media_packet (Tcp& tcp, int padding, networking_t& stream_ctrl) { unsigned char pre_header[8]; unsigned char data[BUF_SIZE]; @@ -453,11 +453,11 @@ static int packet_length1; -static int asf_mmst_networking_read(Tcp& tcp, char *buffer, int size, networking_t *stream_ctrl ) +static int asf_mmst_networking_read(Tcp& tcp, char *buffer, int size, networking_t& stream_ctrl ) { int len; - while( stream_ctrl->buffer_size==0 ) { + while( stream_ctrl.buffer_size==0 ) { // buffer is empty - fill it! int ret = get_media_packet(tcp, packet_length1, stream_ctrl); if( ret<0 ) { @@ -467,21 +467,21 @@ return ret; } - len = stream_ctrl->buffer_size-stream_ctrl->buffer_pos; + len = stream_ctrl.buffer_size-stream_ctrl.buffer_pos; if(len>size) len=size; - memcpy( buffer, (stream_ctrl->buffer)+(stream_ctrl->buffer_pos), len ); - stream_ctrl->buffer_pos += len; - if( stream_ctrl->buffer_pos>=stream_ctrl->buffer_size ) { - delete stream_ctrl->buffer ; - stream_ctrl->buffer = NULL; - stream_ctrl->buffer_size = 0; - stream_ctrl->buffer_pos = 0; + memcpy( buffer, (stream_ctrl.buffer)+(stream_ctrl.buffer_pos), len ); + stream_ctrl.buffer_pos += len; + if( stream_ctrl.buffer_pos>=stream_ctrl.buffer_size ) { + delete stream_ctrl.buffer ; + stream_ctrl.buffer = NULL; + stream_ctrl.buffer_size = 0; + stream_ctrl.buffer_pos = 0; } return len; } -static int asf_mmst_networking_seek(Tcp& tcp, off_t pos, networking_t *networking ) +static int asf_mmst_networking_seek(Tcp& tcp, off_t pos, networking_t& networking ) { UNUSED(tcp); UNUSED(pos); @@ -489,7 +489,7 @@ return -1; } -MPXP_Rc asf_mmst_networking_start(Tcp& tcp, networking_t *networking) +MPXP_Rc asf_mmst_networking_start(Tcp& tcp, networking_t& networking) { char str[1024]; uint8_t data[BUF_SIZE]; @@ -497,7 +497,7 @@ int asf_header_len; int len, i, packet_length; char* path, *unescpath; - URL* url1 = networking->url; + URL* url1 = networking.url; tcp.close(); @@ -634,10 +634,10 @@ send_command (tcp, 0x07, 1, 0xFFFF | stream_ids[0] << 16, 24, data); - networking->networking_read = asf_mmst_networking_read; - networking->networking_seek = asf_mmst_networking_seek; - networking->buffering = 1; - networking->status = networking_playing_e; + networking.networking_read = asf_mmst_networking_read; + networking.networking_seek = asf_mmst_networking_seek; + networking.buffering = 1; + networking.status = networking_playing_e; packet_length1 = packet_length; MSG_V("mmst packet_length = %d\n",packet_length); Modified: mplayerxp/libmpstream2/asf_streaming.cpp =================================================================== --- mplayerxp/libmpstream2/asf_streaming.cpp 2012-12-17 10:31:40 UTC (rev 568) +++ mplayerxp/libmpstream2/asf_streaming.cpp 2012-12-17 12:05:45 UTC (rev 569) @@ -51,7 +51,7 @@ // WMP sequence is MMSU then MMST and then HTTP. // In MPlayer case since HTTP support is more reliable, // we are doing HTTP first then we try MMST if HTTP fail. -static MPXP_Rc asf_http_networking_start(Tcp& fd, networking_t *networking ); +static MPXP_Rc asf_http_networking_start(Tcp& fd, networking_t& networking ); /* ASF networking support several network protocol. @@ -73,9 +73,9 @@ In MPlayer case since HTTP support is more reliable, we are doing HTTP first then we try MMST if HTTP fail. */ -MPXP_Rc asf_networking_start(Tcp& tcp, networking_t *networking) { - char *proto = networking->url->protocol; - int port = networking->url->port; +MPXP_Rc asf_networking_start(Tcp& tcp,networking_t& networking) { + char *proto = networking.url->protocol; + int port = networking.url->port; MPXP_Rc rc; // Is protocol even valid mms,mmsu,mmst,http,http_proxy? @@ -99,7 +99,7 @@ if (!strncasecmp(proto, "mmst", 4) || !strncasecmp(proto, "mms", 3)) { MSG_V("Trying ASF/TCP...\n"); rc = asf_mmst_networking_start(tcp,networking); - networking->url->port = port; + networking.url->port = port; if( rc==MPXP_Ok ) return MPXP_Ok; MSG_V(" ===> ASF/TCP failed\n"); return MPXP_False; @@ -110,7 +110,7 @@ !strncasecmp(proto, "mms", 3)) { MSG_V("Trying ASF/HTTP...\n"); rc = asf_http_networking_start(tcp,networking); - networking->url->port = port; + networking.url->port = port; if( rc==MPXP_Ok ) return MPXP_Ok; MSG_V(" ===> ASF/HTTP failed\n"); return MPXP_False; @@ -185,16 +185,16 @@ } static MPXP_Rc -asf_networking_parse_header(Tcp& tcp, networking_t* networking) { +asf_networking_parse_header(Tcp& tcp, networking_t& networking) { ASF_header_t asfh; ASF_stream_chunck_t chunk; - asf_http_networking_t* asf_ctrl = (asf_http_networking_t*) networking->data; + asf_http_networking_t* asf_ctrl = (asf_http_networking_t*) networking.data; char* buffer=NULL, *chunk_buffer=NULL; int i,r,size,pos = 0; int start; int buffer_size = 0; int chunk_size2read = 0; - int bw = networking->bandwidth; + int bw = networking.bandwidth; int *v_rates = NULL, *a_rates = NULL; int v_rate = 0, a_rate = 0, a_idx = -1, v_idx = -1; @@ -275,7 +275,7 @@ asf_ctrl->packet_size = fileh->max_packet_size; // before playing. // preroll: time in ms to bufferize before playing - networking->prebuffer_size = (unsigned int)(((double)fileh->preroll/1000.0)*((double)fileh->max_bitrate/8.0)); + networking.prebuffer_size = (unsigned int)(((double)fileh->preroll/1000.0)*((double)fileh->max_bitrate/8.0)); } pos = start; @@ -416,11 +416,11 @@ } static int -asf_http_networking_read( Tcp& tcp, char *buffer, int size, networking_t *networking ) { +asf_http_networking_read( Tcp& tcp, char *buffer, int size, networking_t& networking ) { static ASF_stream_chunck_t chunk; int read,chunk_size = 0; static int rest = 0, drop_chunk = 0, waiting = 0; - asf_http_networking_t *asf_http_ctrl = (asf_http_networking_t*)networking->data; + asf_http_networking_t* asf_http_ctrl = (asf_http_networking_t*)networking.data; while(1) { if (rest == 0 && waiting == 0) { @@ -492,7 +492,7 @@ } static int -asf_http_networking_seek( Tcp& tcp, off_t pos, networking_t *networking ) { +asf_http_networking_seek( Tcp& tcp, off_t pos, networking_t& networking ) { UNUSED(tcp); UNUSED(pos); UNUSED(networking); @@ -562,11 +562,11 @@ return ASF_Unknown_e; } -static HTTP_Header* asf_http_request(networking_t *networking) { +static HTTP_Header* asf_http_request(networking_t& networking) { HTTP_Header* http_hdr = new(zeromem) HTTP_Header; URL *url = NULL; URL *server_url = NULL; - asf_http_networking_t *asf_http_ctrl; + asf_http_networking_t* asf_http_ctrl; char str[250]; char *ptr; int i, enable; @@ -575,9 +575,8 @@ int asf_nb_stream=0, stream_id; // Sanity check - if( networking==NULL ) return NULL; - url = networking->url; - asf_http_ctrl = (asf_http_networking_t*)networking->data; + url = networking.url; + asf_http_ctrl = (asf_http_networking_t*)networking.data; if( url==NULL || asf_http_ctrl==NULL ) return NULL; // Common header for all requests. @@ -660,7 +659,7 @@ } static int -asf_http_parse_response(asf_http_networking_t *asf_http_ctrl, HTTP_Header& http_hdr ) { +asf_http_parse_response(asf_http_networking_t& asf_http_ctrl, HTTP_Header& http_hdr ) { const char *content_type, *pragma; char features[64] = "\0"; size_t len; @@ -713,14 +712,14 @@ } while( comma_ptr!=NULL ); pragma = http_hdr.get_next_field(); } - asf_http_ctrl->networking_type = asf_http_networking_type( content_type, features, http_hdr ); + asf_http_ctrl.networking_type = asf_http_networking_type( content_type, features, http_hdr ); return 0; } -static MPXP_Rc asf_http_networking_start(Tcp& tcp, networking_t *networking) { +static MPXP_Rc asf_http_networking_start(Tcp& tcp, networking_t& networking) { HTTP_Header *http_hdr=NULL; - URL *url = networking->url; - asf_http_networking_t *asf_http_ctrl; + URL *url = networking.url; + asf_http_networking_t* asf_http_ctrl; uint8_t buffer[BUFFER_SIZE]; int i, ret; int done; @@ -735,7 +734,7 @@ asf_http_ctrl->request = 1; asf_http_ctrl->audio_streams = asf_http_ctrl->video_streams = NULL; asf_http_ctrl->n_audio = asf_http_ctrl->n_video = 0; - networking->data = asf_http_ctrl; + networking.data = asf_http_ctrl; do { done = 1; @@ -773,7 +772,7 @@ if( mp_conf.verbose>0 ) { MSG_DBG2("Response [%s]\n", http_hdr->get_buffer() ); } - ret = asf_http_parse_response(asf_http_ctrl, *http_hdr); + ret = asf_http_parse_response(*asf_http_ctrl, *http_hdr); if( ret<0 ) { MSG_ERR("Failed to parse header\n"); delete http_hdr; @@ -829,14 +828,14 @@ } while(!done); if( asf_http_ctrl->networking_type==ASF_PlainText_e || asf_http_ctrl->networking_type==ASF_Redirector_e ) { - networking->networking_read = nop_networking_read; - networking->networking_seek = nop_networking_seek; + networking.networking_read = nop_networking_read; + networking.networking_seek = nop_networking_seek; } else { - networking->networking_read = asf_http_networking_read; - networking->networking_seek = asf_http_networking_seek; - networking->buffering = 1; + networking.networking_read = asf_http_networking_read; + networking.networking_seek = asf_http_networking_seek; + networking.buffering = 1; } - networking->status = networking_playing_e; + networking.status = networking_playing_e; delete http_hdr; return MPXP_Ok; Modified: mplayerxp/libmpstream2/asf_streaming.h =================================================================== --- mplayerxp/libmpstream2/asf_streaming.h 2012-12-17 10:31:40 UTC (rev 568) +++ mplayerxp/libmpstream2/asf_streaming.h 2012-12-17 12:05:45 UTC (rev 569) @@ -6,6 +6,7 @@ #include "stream.h" +struct networking_t; namespace mpxp { class Tcp; } @@ -32,7 +33,7 @@ int audio_id, video_id; }; -extern MPXP_Rc asf_networking_start(Tcp& fd, networking_t *networking); -extern MPXP_Rc asf_mmst_networking_start(Tcp& fd, networking_t *networking); +extern MPXP_Rc asf_networking_start(Tcp& fd, networking_t& networking); +extern MPXP_Rc asf_mmst_networking_start(Tcp& fd, networking_t& networking); #endif Modified: mplayerxp/libmpstream2/network.cpp =================================================================== --- mplayerxp/libmpstream2/network.cpp 2012-12-17 10:31:40 UTC (rev 568) +++ mplayerxp/libmpstream2/network.cpp 2012-12-17 12:05:45 UTC (rev 569) @@ -61,21 +61,16 @@ net_config_t net_conf; networking_t* new_networking() { - networking_t *networking = new(zeromem) networking_t; - if( networking==NULL ) { - MSG_FATAL(MSGTR_OutOfMemory); - return NULL; - } + networking_t* networking = new(zeromem) networking_t; networking->mime="application/octet-stream"; return networking; } -void free_networking( networking_t *networking ) { - if( networking==NULL ) return; - if( networking->url ) delete networking->url; - if( networking->buffer ) delete networking->buffer ; - if( networking->data ) delete networking->data ; - delete networking; +void free_networking( networking_t& networking ) { + if( networking.url ) delete networking.url; + if( networking.buffer ) delete networking.buffer ; + if( networking.data ) delete networking.data ; + delete &networking; } URL* @@ -281,11 +276,11 @@ return 0; } -off_t http_seek(Tcp& tcp, networking_t *networking, off_t pos ) { +off_t http_seek(Tcp& tcp, networking_t& networking, off_t pos ) { HTTP_Header* http_hdr = NULL; tcp.close(); - if(http_send_request(tcp,networking->url, pos)==MPXP_Ok) return 0; + if(http_send_request(tcp,networking.url, pos)==MPXP_Ok) return 0; http_hdr = http_read_response(tcp); @@ -310,7 +305,7 @@ if( http_hdr ) { delete http_hdr; - networking->data = NULL; + networking.data = NULL; } return pos; @@ -318,7 +313,7 @@ // By using the protocol, the extension of the file or the content-type // we might be able to guess the networking type. -static MPXP_Rc autodetectProtocol(networking_t *networking, Tcp& tcp) { +static MPXP_Rc autodetectProtocol(networking_t& networking, Tcp& tcp) { HTTP_Header *http_hdr=NULL; int redirect; int auth_retry=0; @@ -327,7 +322,7 @@ const char *content_type; const char *next_url; - URL *url = networking->url; + URL *url = networking.url; do { next_url = NULL; @@ -359,7 +354,7 @@ http_hdr = http_read_response(tcp); if( http_hdr==NULL ) goto err_out; if( mp_conf.verbose ) http_hdr->debug_hdr(); - networking->data = http_hdr; + networking.data = http_hdr; // Check if we can make partial content requests and thus seek in http-streams if( http_hdr->get_status()==200 ) { @@ -386,7 +381,7 @@ if( (field_data = http_hdr->get_field("icy-br")) != NULL ) MSG_INFO("Bitrate: %skbit/s\n", field_data); field_data = NULL; if ( (field_data = http_hdr->get_field("content-type")) != NULL ) - networking->mime = field_data; + networking.mime = field_data; return MPXP_Ok; } case 400: // Server Full @@ -427,7 +422,7 @@ // TODO: RFC 2616, recommand to detect infinite redirection loops next_url = http_hdr->get_field("Location" ); if( next_url!=NULL ) { - networking->url = url = url_redirect( &url, next_url ); + networking.url = url = url_redirect( &url, next_url ); if (!strcasecmp(url->protocol, "mms")) goto err_out; if (strcasecmp(url->protocol, "http")) { MSG_WARN("Unsupported http %d redirect to %s protocol\n", http_hdr->get_status(), url->protocol); @@ -456,34 +451,34 @@ } int -networking_bufferize( networking_t *networking,unsigned char *buffer, int size) { +networking_bufferize( networking_t& networking,unsigned char *buffer, int size) { //printf("networking_bufferize\n"); - networking->buffer = new char [size]; - if( networking->buffer==NULL ) { + networking.buffer = new char [size]; + if( networking.buffer==NULL ) { MSG_FATAL(MSGTR_OutOfMemory); return -1; } - memcpy( networking->buffer, buffer, size ); - networking->buffer_size = size; + memcpy( networking.buffer, buffer, size ); + networking.buffer_size = size; return size; } int -nop_networking_read(Tcp& tcp, char *buffer, int size, networking_t *stream_ctrl ) { +nop_networking_read(Tcp& tcp, char *buffer, int size, networking_t& stream_ctrl ) { int len=0; //printf("nop_networking_read\n"); - if( stream_ctrl->buffer_size!=0 ) { - int buffer_len = stream_ctrl->buffer_size-stream_ctrl->buffer_pos; -//printf("%d bytes in buffer\n", stream_ctrl->buffer_size); + if( stream_ctrl.buffer_size!=0 ) { + int buffer_len = stream_ctrl.buffer_size-stream_ctrl.buffer_pos; +//printf("%d bytes in buffer\n", stream_ctrl.buffer_size); len = (size<buffer_len)?size:buffer_len; - memcpy( buffer, (stream_ctrl->buffer)+(stream_ctrl->buffer_pos), len ); - stream_ctrl->buffer_pos += len; -//printf("buffer_pos = %d\n", stream_ctrl->buffer_pos ); - if( stream_ctrl->buffer_pos>=stream_ctrl->buffer_size ) { - delete stream_ctrl->buffer ; - stream_ctrl->buffer = NULL; - stream_ctrl->buffer_size = 0; - stream_ctrl->buffer_pos = 0; + memcpy( buffer, (stream_ctrl.buffer)+(stream_ctrl.buffer_pos), len ); + stream_ctrl.buffer_pos += len; +//printf("buffer_pos = %d\n", stream_ctrl.buffer_pos ); + if( stream_ctrl.buffer_pos>=stream_ctrl.buffer_size ) { + delete stream_ctrl.buffer ; + stream_ctrl.buffer = NULL; + stream_ctrl.buffer_size = 0; + stream_ctrl.buffer_pos = 0; //printf("buffer cleaned\n"); } //printf("read %d bytes from buffer\n", len ); @@ -501,21 +496,21 @@ } int -nop_networking_seek(Tcp& tcp, off_t pos, networking_t *n ) { +nop_networking_seek(Tcp& tcp, off_t pos, networking_t& n ) { UNUSED(tcp); UNUSED(pos); UNUSED(n); return -1; } -MPXP_Rc nop_networking_start(Tcp& tcp,networking_t* networking ) { +MPXP_Rc nop_networking_start(Tcp& tcp,networking_t& networking ) { HTTP_Header *http_hdr = NULL; const char *next_url=NULL; URL *rd_url=NULL; MPXP_Rc ret; if( !tcp.established() ) { - http_send_request(tcp, networking->url,0); + http_send_request(tcp, networking.url,0); if( !tcp.established() ) return MPXP_False; http_hdr = http_read_response(tcp); if( http_hdr==NULL ) return MPXP_False; @@ -542,7 +537,7 @@ if (next_url != NULL && rd_url != NULL) { MSG_STATUS("Redirected: Using this url instead %s\n",next_url); - networking->url=check4proxies(rd_url); + networking.url=check4proxies(rd_url); ret=nop_networking_start(tcp,networking); //recursively get networking started } else { MSG_ERR("Redirection failed\n"); @@ -561,11 +556,11 @@ break; } } else { - http_hdr = (HTTP_Header*)networking->data; + http_hdr = (HTTP_Header*)networking.data; if( http_hdr->get_body_size()>0 ) { if( networking_bufferize( networking, (unsigned char*)http_hdr->get_body(), http_hdr->get_body_size() )<0 ) { delete http_hdr; - networking->data = NULL; + networking.data = NULL; return MPXP_False; } } @@ -573,23 +568,23 @@ if( http_hdr ) { delete http_hdr; - networking->data = NULL; + networking.data = NULL; } - networking->networking_read = nop_networking_read; - networking->networking_seek = nop_networking_seek; - networking->prebuffer_size = 64*1024; // KBytes - networking->buffering = 1; - networking->status = networking_playing_e; + networking.networking_read = nop_networking_read; + networking.networking_seek = nop_networking_seek; + networking.prebuffer_size = 64*1024; // KBytes + networking.buffering = 1; + networking.status = networking_playing_e; return MPXP_Ok; } -void fixup_network_stream_cache(networking_t *networking) { - if(networking->buffering) { +void fixup_network_stream_cache(networking_t& networking) { + if(networking.buffering) { if(mp_conf.s_cache_size<0) { // cache option not set, will use our computed value. // buffer in KBytes, *5 because the prefill is 20% of the buffer. - mp_conf.s_cache_size = (networking->prebuffer_size/1024)*5; + mp_conf.s_cache_size = (networking.prebuffer_size/1024)*5; if( mp_conf.s_cache_size<64 ) mp_conf.s_cache_size = 64; // 16KBytes min buffer } MSG_INFO("[network] cache size set to: %i\n", mp_conf.s_cache_size); @@ -597,38 +592,38 @@ } int -pnm_networking_read(Tcp& tcp, char *buffer, int size, networking_t *stream_ctrl ) { - Pnm& pnm=*static_cast<Pnm*>(stream_ctrl->data); +pnm_networking_read(Tcp& tcp, char *buffer, int size, networking_t& stream_ctrl ) { + Pnm& pnm=*static_cast<Pnm*>(stream_ctrl.data); UNUSED(tcp); return pnm.read(buffer, size); } -MPXP_Rc pnm_networking_start(Tcp& tcp,networking_t *networking ) { +MPXP_Rc pnm_networking_start(Tcp& tcp,networking_t& networking ) { Pnm* pnm = new(zeromem) Pnm(tcp); - tcp.open(networking->url->hostname, - networking->url->port ? networking->url->port : 7070); + tcp.open(networking.url->hostname, + networking.url->port ? networking.url->port : 7070); if(!tcp.established()) return MPXP_False; - if(pnm->connect(networking->url->file)!=MPXP_Ok) { + if(pnm->connect(networking.url->file)!=MPXP_Ok) { delete pnm; return MPXP_NA; } - networking->data=pnm; - networking->networking_read = pnm_networking_read; - networking->prebuffer_size = 8*1024; // 8 KBytes - networking->buffering = 1; - networking->status = networking_playing_e; + networking.data=pnm; + networking.networking_read = pnm_networking_read; + networking.prebuffer_size = 8*1024; // 8 KBytes + networking.buffering = 1; + networking.status = networking_playing_e; return MPXP_Ok; } int -realrtsp_networking_read( Tcp& tcp, char *buffer, int size, networking_t *networking ) { - Rtsp_Session& rtsp=*static_cast<Rtsp_Session*>(networking->data); +realrtsp_networking_read( Tcp& tcp, char *buffer, int size, networking_t& networking ) { + Rtsp_Session& rtsp=*static_cast<Rtsp_Session*>(networking.data); return rtsp.read(tcp, buffer, size); } -MPXP_Rc realrtsp_networking_start( Tcp& tcp, networking_t *networking ) { +MPXP_Rc realrtsp_networking_start( Tcp& tcp, networking_t& networking ) { Rtsp_Session* rtsp; char *mrl; char *file; @@ -639,25 +634,25 @@ do { redirected = 0; - port = networking->url->port ? networking->url->port : 554; + port = networking.url->port ? networking.url->port : 554; tcp.close(); - tcp.open( networking->url->hostname, port, Tcp::IP4); - if(!tcp.established() && !networking->url->port) - tcp.open( networking->url->hostname,port = 7070, Tcp::IP4); + tcp.open( networking.url->hostname, port, Tcp::IP4); + if(!tcp.established() && !networking.url->port) + tcp.open( networking.url->hostname,port = 7070, Tcp::IP4); if(!tcp.established()) return MPXP_False; - file = networking->url->file; + file = networking.url->file; if (file[0] == '/') file++; - mrl = new char [strlen(networking->url->hostname)+strlen(file)+16]; - sprintf(mrl,"rtsp://%s:%i/%s",networking->url->hostname,port,file); + mrl = new char [strlen(networking.url->hostname)+strlen(file)+16]; + sprintf(mrl,"rtsp://%s:%i/%s",networking.url->hostname,port,file); rtsp = rtsp_session_start(tcp,&mrl, file, - networking->url->hostname, port, &redirected, - net_conf.bandwidth,networking->url->username, - networking->url->password); + networking.url->hostname, port, &redirected, + net_conf.bandwidth,networking.url->username, + networking.url->password); if ( redirected == 1 ) { - delete networking->url; - networking->url = url_new(mrl); + delete networking.url; + networking.url = url_new(mrl); tcp.close(); } delete mrl; @@ -667,12 +662,12 @@ if(!rtsp) return MPXP_False; - networking->data=rtsp; + networking.data=rtsp; - networking->networking_read = realrtsp_networking_read; - networking->prebuffer_size = 128*1024; // 8 KBytes - networking->buffering = 1; - networking->status = networking_playing_e; + networking.networking_read = realrtsp_networking_read; + networking.prebuffer_size = 128*1024; // 8 KBytes + networking.buffering = 1; + networking.status = networking_playing_e; return MPXP_Ok; } @@ -680,36 +675,36 @@ #ifndef STREAMING_LIVE_DOT_COM static int -rtp_networking_read(Tcp& tcp, char *buffer, int size, networking_t *networking ) { +rtp_networking_read(Tcp& tcp, char *buffer, int size, networking_t& networking ) { UNUSED(networking); return read_rtp_from_server(tcp, buffer, size ); } -static MPXP_Rc rtp_networking_start(Tcp& tcp,networking_t* networking, int raw_udp ) { +static MPXP_Rc rtp_networking_start(Tcp& tcp,networking_t& networking, int raw_udp ) { if( !tcp.established() ) { - Udp* udp(new(zeromem) Udp(networking->url)); + Udp* udp(new(zeromem) Udp(networking.url)); tcp = udp->socket(); if( !tcp.established()) return MPXP_False; } if(raw_udp) - networking->networking_read = nop_networking_read; + networking.networking_read = nop_networking_read; else - networking->networking_read = rtp_networking_read; - networking->networking_read = rtp_networking_read; - networking->networking_seek = nop_networking_seek; - networking->prebuffer_size = 64*1024; // KBytes - networking->buffering = 0; - networking->status = networking_playing_e; + networking.networking_read = rtp_networking_read; + networking.networking_read = rtp_networking_read; + networking.networking_seek = nop_networking_seek; + networking.prebuffer_size = 64*1024; // KBytes + networking.buffering = 0; + networking.status = networking_playing_e; return MPXP_Ok; } #endif -MPXP_Rc networking_start(Tcp& tcp,networking_t* networking, URL *url) { +MPXP_Rc networking_start(Tcp& tcp,networking_t& networking, URL *url) { MPXP_Rc rc; - networking->url = check4proxies( url ); + networking.url = check4proxies( url ); rc = autodetectProtocol( networking, tcp); @@ -717,13 +712,13 @@ rc = MPXP_False; // Get the bandwidth available - networking->bandwidth = net_conf.bandwidth; + networking.bandwidth = net_conf.bandwidth; // For RTP streams, we usually don't know the stream type until we open it. - if( !strcasecmp( networking->url->protocol, "rtp")) { + if( !strcasecmp( networking.url->protocol, "rtp")) { if(tcp.established()) tcp.close(); rc = rtp_networking_start(tcp, networking, 0); - } else if( !strcasecmp( networking->url->protocol, "pnm")) { + } else if( !strcasecmp( networking.url->protocol, "pnm")) { tcp.close(); rc = pnm_networking_start(tcp, networking); if (rc == MPXP_False) { @@ -731,7 +726,7 @@ return MPXP_False; } } - else if( !strcasecmp( networking->url->protocol, "rtsp")) { + else if( !strcasecmp( networking.url->protocol, "rtsp")) { if ((rc = realrtsp_networking_start( tcp, networking )) < 0) { MSG_INFO("Not a Realmedia rtsp url. Trying standard rtsp protocol.\n"); #ifdef STREAMING_LIVE_DOT_COM @@ -744,7 +739,7 @@ #endif } } - else if(!strcasecmp( networking->url->protocol, "udp")) { + else if(!strcasecmp( networking.url->protocol, "udp")) { tcp.close(); rc = rtp_networking_start(tcp, networking, 1); if(rc==MPXP_False) { @@ -761,7 +756,7 @@ if( rc==MPXP_False ) { //sometimes a file is just on a webserver and it is not streamed. //try loading them default method as last resort for http protocol - if ( !strcasecmp(networking->url->protocol, "http") ) { + if ( !strcasecmp(networking.url->protocol, "http") ) { MSG_STATUS("Trying default networking for http protocol\n "); //reset stream tcp.close(); @@ -774,11 +769,11 @@ } } if( rc==MPXP_False ) ; - else if( networking->buffering ) { + else if( networking.buffering ) { if(mp_conf.s_cache_size<0) { // cache option not set, will use our computed value. // buffer in KBytes, *5 because the prefill is 20% of the buffer. - mp_conf.s_cache_size = (networking->prebuffer_size/1024)*5; + mp_conf.s_cache_size = (networking.prebuffer_size/1024)*5; if( mp_conf.s_cache_size<64 ) mp_conf.s_cache_size = 64; // 16KBytes min buffer } MSG_INFO("Cache size set to %d KBytes\n", mp_conf.s_cache_size); @@ -787,7 +782,7 @@ } int -networking_stop( networking_t *networking) { - networking->status = networking_stopped_e; +networking_stop( networking_t& networking) { + networking.status = networking_stopped_e; return 0; } Modified: mplayerxp/libmpstream2/network.h =================================================================== --- mplayerxp/libmpstream2/network.h 2012-12-17 10:31:40 UTC (rev 568) +++ mplayerxp/libmpstream2/network.h 2012-12-17 12:05:45 UTC (rev 569) @@ -67,20 +67,20 @@ unsigned int buffer_size; unsigned int buffer_pos; unsigned int bandwidth; // The downstream available - int (*networking_read)( Tcp& fd, char *buffer, int buffer_size, networking_t *stream_ctrl ); - int (*networking_seek)( Tcp& fd, off_t pos, networking_t *stream_ctrl ); + int (*networking_read)( Tcp& fd, char *buffer, int buffer_size, networking_t& stream_ctrl ); + int (*networking_seek)( Tcp& fd, off_t pos, networking_t& stream_ctrl ); Opaque* data; }; -extern void fixup_network_stream_cache(networking_t *s); -extern MPXP_Rc networking_start(Tcp& fd,networking_t *n, URL *url); -extern int networking_bufferize(networking_t *networking,unsigned char *buffer, int size); -extern networking_t *new_networking(); -extern void free_networking( networking_t *networking ); +extern void fixup_network_stream_cache(networking_t& s); +extern MPXP_Rc networking_start(Tcp& fd,networking_t& n, URL *url); +extern int networking_bufferize(networking_t& networking,unsigned char *buffer, int size); +extern networking_t* new_networking(); +extern void free_networking( networking_t& networking ); extern URL* check4proxies( URL* url ); -int nop_networking_read(Tcp& fd, char *buffer, int size, networking_t *stream_ctrl ); -int nop_networking_seek(Tcp& fd, off_t pos, networking_t *stream_ctrl ); +int nop_networking_read(Tcp& fd, char *buffer, int size, networking_t& stream_ctrl ); +int nop_networking_seek(Tcp& fd, off_t pos, networking_t& stream_ctrl ); MPXP_Rc http_send_request(Tcp& tcp,URL* url, off_t pos); HTTP_Header* http_read_response(Tcp& fd); Modified: mplayerxp/libmpstream2/s_network.cpp =================================================================== --- mplayerxp/libmpstream2/s_network.cpp 2012-12-17 10:31:40 UTC (rev 568) +++ mplayerxp/libmpstream2/s_network.cpp 2012-12-17 12:05:45 UTC (rev 569) @@ -56,11 +56,11 @@ url = url_new(filename); if(url) { networking=new_networking(); - if(networking_start(tcp,networking,url)!=MPXP_Ok){ + if(networking_start(tcp,*networking,url)!=MPXP_Ok){ MSG_ERR(MSGTR_UnableOpenURL, filename.c_str()); delete url; url=NULL; - free_networking(networking); + free_networking(*networking); networking=NULL; return MPXP_False; } @@ -78,7 +78,7 @@ int Network_Stream_Interface::read(stream_packet_t*sp) { sp->type=0; - if(networking!=NULL)sp->len=networking->networking_read(tcp,sp->buf,STREAM_BUFFER_SIZE, networking); + if(networking!=NULL)sp->len=networking->networking_read(tcp,sp->buf,STREAM_BUFFER_SIZE, *networking); else sp->len=TEMP_FAILURE_RETRY(tcp.read((uint8_t*)sp->buf,STREAM_BUFFER_SIZE)); spos += sp->len; return sp->len; @@ -88,7 +88,7 @@ { off_t newpos=0; if(networking!=NULL) { - newpos=networking->networking_seek(tcp, pos, networking ); + newpos=networking->networking_seek(tcp, pos, *networking ); if( newpos<0 ) { MSG_WARN("Stream not seekable!\n"); return 1; Modified: mplayerxp/libmpstream2/s_rtsp.cpp =================================================================== --- mplayerxp/libmpstream2/s_rtsp.cpp 2012-12-17 10:31:40 UTC (rev 568) +++ mplayerxp/libmpstream2/s_rtsp.cpp 2012-12-17 12:05:45 UTC (rev 569) @@ -78,7 +78,7 @@ Rtsp_Session* rtsp = static_cast<Rtsp_Session*>(networking->data); if (rtsp) rtsp->end (); delete networking->url; - free_networking(networking); + free_networking(*networking); networking=NULL; } @@ -155,12 +155,12 @@ tcp.close(); index_mode = -1; /* prevent most RTSP streams from locking due to -idx */ if (start() != MPXP_Ok) { - free_networking(networking); + free_networking(*networking); networking = NULL; return MPXP_False; } - fixup_network_stream_cache (networking); + fixup_network_stream_cache (*networking); return MPXP_Ok; } Stream::type_e Rtsp_Stream_Interface::type() const { return Stream::Type_Stream; } Modified: mplayerxp/libmpstream2/s_udp.cpp =================================================================== --- mplayerxp/libmpstream2/s_udp.cpp 2012-12-17 10:31:40 UTC (rev 568) +++ mplayerxp/libmpstream2/s_udp.cpp 2012-12-17 12:05:45 UTC (rev 569) @@ -58,7 +58,7 @@ int Udp_Stream_Interface::read(stream_packet_t*sp) { - return nop_networking_read(tcp,sp->buf,sp->len,networking); + return nop_networking_read(tcp,sp->buf,sp->len,*networking); } off_t Udp_Stream_Interface::seek(off_t newpos) { return newpos; } @@ -73,7 +73,7 @@ void Udp_Stream_Interface::close() { - free_networking(networking); + free_networking(*networking); networking=NULL; } @@ -105,17 +105,17 @@ networking->url = check4proxies (url); if (url->port == 0) { MSG_ERR("You must enter a port number for UDP streams!\n"); - free_networking (networking); + free_networking (*networking); networking = NULL; return MPXP_False; } if (start () !=MPXP_Ok) { MSG_ERR("udp_networking_start failed\n"); - free_networking (networking); + free_networking (*networking); networking = NULL; return MPXP_False; } - fixup_network_stream_cache (networking); + fixup_network_stream_cache (*networking); return MPXP_Ok; } Stream::type_e Udp_Stream_Interface::type() const { return Stream::Type_Stream; } Modified: mplayerxp/libmpstream2/stream.h =================================================================== --- mplayerxp/libmpstream2/stream.h 2012-12-17 10:31:40 UTC (rev 568) +++ mplayerxp/libmpstream2/stream.h 2012-12-17 12:05:45 UTC (rev 569) @@ -11,7 +11,6 @@ #include "xmpcore/xmp_enums.h" -struct networking_t; namespace mpxp { struct libinput_t; enum { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nic...@us...> - 2012-12-17 17:03:58
|
Revision: 570 http://mplayerxp.svn.sourceforge.net/mplayerxp/?rev=570&view=rev Author: nickols_k Date: 2012-12-17 17:03:47 +0000 (Mon, 17 Dec 2012) Log Message: ----------- on respone.404 segfault--: convert networking into classes Modified Paths: -------------- mplayerxp/libmpstream2/Makefile mplayerxp/libmpstream2/http.cpp mplayerxp/libmpstream2/http.h mplayerxp/libmpstream2/network.cpp mplayerxp/libmpstream2/network.h mplayerxp/libmpstream2/s_network.cpp mplayerxp/libmpstream2/s_rtsp.cpp mplayerxp/libmpstream2/s_udp.cpp mplayerxp/libmpstream2/stream.cpp mplayerxp/libmpstream2/udp.h Added Paths: ----------- mplayerxp/libmpstream2/network_asf.cpp mplayerxp/libmpstream2/network_asf.h mplayerxp/libmpstream2/network_asf_mmst.cpp mplayerxp/libmpstream2/network_asf_mmst.h mplayerxp/libmpstream2/network_nop.cpp mplayerxp/libmpstream2/network_nop.h mplayerxp/libmpstream2/network_pnm.cpp mplayerxp/libmpstream2/network_pnm.h mplayerxp/libmpstream2/network_real_rtsp.cpp mplayerxp/libmpstream2/network_real_rtsp.h mplayerxp/libmpstream2/network_rtp.cpp mplayerxp/libmpstream2/network_rtp.h mplayerxp/libmpstream2/network_rtsp.cpp mplayerxp/libmpstream2/network_rtsp.h Removed Paths: ------------- mplayerxp/libmpstream2/asf_mmst_streaming.cpp mplayerxp/libmpstream2/asf_streaming.cpp mplayerxp/libmpstream2/asf_streaming.h Modified: mplayerxp/libmpstream2/Makefile =================================================================== --- mplayerxp/libmpstream2/Makefile 2012-12-17 12:05:45 UTC (rev 569) +++ mplayerxp/libmpstream2/Makefile 2012-12-17 17:03:47 UTC (rev 570) @@ -31,11 +31,16 @@ SUBDIRS = tvi ifeq ($(HAVE_STREAMING),yes) SUBDIRS += freesdp librtsp realrtsp -CXXSRCS += asf_streaming.cpp \ - asf_mmst_streaming.cpp \ - cookies.cpp \ +CXXSRCS += cookies.cpp \ http.cpp \ network.cpp \ + network_asf.cpp \ + network_asf_mmst.cpp \ + network_nop.cpp \ + network_pnm.cpp \ + network_real_rtsp.cpp \ + network_rtp.cpp \ + network_rtsp.cpp \ pnm.cpp \ rtp.cpp \ tcp.cpp \ Deleted: mplayerxp/libmpstream2/asf_mmst_streaming.cpp =================================================================== --- mplayerxp/libmpstream2/asf_mmst_streaming.cpp 2012-12-17 12:05:45 UTC (rev 569) +++ mplayerxp/libmpstream2/asf_mmst_streaming.cpp 2012-12-17 17:03:47 UTC (rev 570) @@ -1,649 +0,0 @@ -#include "mp_config.h" -#include "osdep/mplib.h" -using namespace mpxp; -// mmst implementation taken from the xine-mms plugin made by majormms (http://geocities.com/majormms/) -// -// ported to mplayer by Abhijeet Phatak <abh...@ya...> -// date : 16 April 2002 -// -// information about the mms protocol can be find at http://get.to/sdp -// - - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <errno.h> -#include <inttypes.h> - -#include "mplayerxp.h" -#include "tcp.h" -#include "url.h" -#include "stream.h" - -#include "network.h" - -#ifndef HAVE_WINSOCK2 -#define closesocket close -#else -#include <winsock2.h> -#endif -#ifndef USE_SETLOCALE -#undef USE_ICONV -#endif - -#ifdef USE_ICONV -#ifdef HAVE_GICONV -#include <giconv.h> -#else -#include <iconv.h> -#endif -#ifdef USE_LANGINFO -#include <langinfo.h> -#endif -#endif -#include "stream_msg.h" - -#define BUF_SIZE 102400 -#define HDR_BUF_SIZE 8192 -#define MAX_STREAMS 20 - -typedef struct -{ - uint8_t buf[BUF_SIZE]; - int num_bytes; - -} command_t; - -static int seq_num; -static int num_stream_ids; -static int stream_ids[MAX_STREAMS]; - -static int get_data (Tcp& s,unsigned char *buf, size_t count); - -static void put_32 (command_t *cmd, uint32_t value) -{ - cmd->buf[cmd->num_bytes ] = value % 256; - value = value >> 8; - cmd->buf[cmd->num_bytes+1] = value % 256 ; - value = value >> 8; - cmd->buf[cmd->num_bytes+2] = value % 256 ; - value = value >> 8; - cmd->buf[cmd->num_bytes+3] = value % 256 ; - - cmd->num_bytes += 4; -} - -static uint32_t get_32 (unsigned char *cmd, int offset) -{ - uint32_t ret; - - ret = cmd[offset] ; - ret |= cmd[offset+1]<<8 ; - ret |= cmd[offset+2]<<16 ; - ret |= cmd[offset+3]<<24 ; - - return ret; -} - -static void send_command (Tcp& tcp, int command, uint32_t switches, - uint32_t extra, int length, - unsigned char *data) -{ - command_t cmd; - int len8; - - len8 = (length + 7) / 8; - - cmd.num_bytes = 0; - - put_32 (&cmd, 0x00000001); /* start sequence */ - put_32 (&cmd, 0xB00BFACE); /* #-)) */ - put_32 (&cmd, len8*8 + 32); - put_32 (&cmd, 0x20534d4d); /* protocol type "MMS " */ - put_32 (&cmd, len8 + 4); - put_32 (&cmd, seq_num); - seq_num++; - put_32 (&cmd, 0x0); /* unknown */ - put_32 (&cmd, 0x0); - put_32 (&cmd, len8+2); - put_32 (&cmd, 0x00030000 | command); /* dir | command */ - put_32 (&cmd, switches); - put_32 (&cmd, extra); - - memcpy (&cmd.buf[48], data, length); - if (length & 7) - memset(&cmd.buf[48 + length], 0, 8 - (length & 7)); - - if (tcp.write (cmd.buf, len8*8+48) != (len8*8+48)) { - MSG_ERR ("write error\n"); - } -} - -#ifdef USE_ICONV -static iconv_t url_conv; -#endif - -static void string_utf16(unsigned char *dest,const char *src, int len) -{ - int i; -#ifdef USE_ICONV - size_t len1, len2; - char *ip, *op; - - if (url_conv != (iconv_t)(-1)) - { - memset(dest, 0, 1000); - len1 = len; len2 = 1000; - ip = src; op = dest; - - iconv(url_conv, &ip, &len1, &op, &len2); - } - else - { -#endif - if (len > 499) len = 499; - for (i=0; i<len; i++) { - dest[i*2] = src[i]; - dest[i*2+1] = 0; - } - /* trailing zeroes */ - dest[i*2] = 0; - dest[i*2+1] = 0; -#ifdef USE_ICONV - } -#endif -} - -static void get_answer (Tcp& tcp) -{ - unsigned char data[BUF_SIZE]; - int command = 0x1b; - - while (command == 0x1b) { - int len; - - len = tcp.read(data, BUF_SIZE); - if (!len) { - MSG_ERR ("\nalert! eof\n"); - return; - } - - command = get_32 (data, 36) & 0xFFFF; - - if (command == 0x1b) - send_command (tcp, 0x1b, 0, 0, 0, data); - } -} - -static int get_data (Tcp& tcp,unsigned char *buf, size_t count) -{ - ssize_t len; - size_t total = 0; - - while (total < count) { - - len = tcp.read(&buf[total], count-total); - - if (len<=0) { - MSG_ERR ("read error:"); - return 0; - } - - total += len; - - if (len != 0) { -// printf ("[%d/%d]", total, count); - fflush (stdout); - } - - } - - return 1; - -} - -static int get_header (Tcp& tcp, uint8_t *header, networking_t& networking) -{ - unsigned char pre_header[8]; - int header_len; - - header_len = 0; - - while (1) { - if (!get_data (tcp, pre_header, 8)) { - MSG_ERR ("pre-header read failed\n"); - return 0; - } - if (pre_header[4] == 0x02) { - - int packet_len; - - packet_len = (pre_header[7] << 8 | pre_header[6]) - 8; - -// printf ("asf header packet detected, len=%d\n", packet_len); - - if (packet_len < 0 || packet_len > HDR_BUF_SIZE - header_len) { - MSG_FATAL("Invalid header size, giving up\n"); - return 0; - } - - if (!get_data (tcp, &header[header_len], packet_len)) { - MSG_ERR("header data read failed\n"); - return 0; - } - - header_len += packet_len; - - if ( (header[header_len-1] == 1) && (header[header_len-2]==1)) { - - - if( networking_bufferize( networking, header, header_len )<0 ) { - return -1; - } - - // printf ("get header packet finished\n"); - - return (header_len); - - } - - } else { - - int32_t packet_len; - int command; - unsigned char data[BUF_SIZE]; - - if (!get_data (tcp, (unsigned char*)&packet_len, 4)) { - MSG_ERR ("packet_len read failed\n"); - return 0; - } - - packet_len = get_32 ((unsigned char*)&packet_len, 0) + 4; - -// printf ("command packet detected, len=%d\n", packet_len); - - if (packet_len < 0 || packet_len > BUF_SIZE) { - MSG_FATAL("Invalid rtsp packet size, giving up\n"); - return 0; - } - - if (!get_data (tcp, data, packet_len)) { - MSG_ERR ("command data read failed\n"); - return 0; - } - - command = get_32 (data, 24) & 0xFFFF; - -// printf ("command: %02x\n", command); - - if (command == 0x1b) - send_command (tcp, 0x1b, 0, 0, 0, data); - - } - -// printf ("get header packet succ\n"); - } -} - -static int interp_header (uint8_t *header, int header_len) -{ - int i; - int packet_length=-1; - - /* - * parse header - */ - - i = 30; - while (i<header_len) { - - uint64_t guid_1, guid_2, length; - - guid_2 = (uint64_t)header[i] | ((uint64_t)header[i+1]<<8) - | ((uint64_t)header[i+2]<<16) | ((uint64_t)header[i+3]<<24) - | ((uint64_t)header[i+4]<<32) | ((uint64_t)header[i+5]<<40) - | ((uint64_t)header[i+6]<<48) | ((uint64_t)header[i+7]<<56); - i += 8; - - guid_1 = (uint64_t)header[i] | ((uint64_t)header[i+1]<<8) - | ((uint64_t)header[i+2]<<16) | ((uint64_t)header[i+3]<<24) - | ((uint64_t)header[i+4]<<32) | ((uint64_t)header[i+5]<<40) - | ((uint64_t)header[i+6]<<48) | ((uint64_t)header[i+7]<<56); - i += 8; - -// printf ("guid found: %016llx%016llx\n", guid_1, guid_2); - - length = (uint64_t)header[i] | ((uint64_t)header[i+1]<<8) - | ((uint64_t)header[i+2]<<16) | ((uint64_t)header[i+3]<<24) - | ((uint64_t)header[i+4]<<32) | ((uint64_t)header[i+5]<<40) - | ((uint64_t)header[i+6]<<48) | ((uint64_t)header[i+7]<<56); - - i += 8; - - if ( (guid_1 == 0x6cce6200aa00d9a6ULL) && (guid_2 == 0x11cf668e75b22630ULL) ) { - MSG_V ("header object\n"); - } else if ((guid_1 == 0x6cce6200aa00d9a6ULL) && (guid_2 == 0x11cf668e75b22636ULL)) { - MSG_V ("data object\n"); - } else if ((guid_1 == 0x6553200cc000e48eULL) && (guid_2 == 0x11cfa9478cabdca1ULL)) { - - packet_length = get_32(header, i+92-24); - - MSG_V ("file object, packet length = %d (%d)\n", - packet_length, get_32(header, i+96-24)); - - - } else if ((guid_1 == 0x6553200cc000e68eULL) && (guid_2 == 0x11cfa9b7b7dc0791ULL)) { - - int stream_id = header[i+48] | header[i+49] << 8; - - MSG_V ("stream object, stream id: %d\n", stream_id); - - if (num_stream_ids < MAX_STREAMS) { - stream_ids[num_stream_ids] = stream_id; - num_stream_ids++; - } else { - MSG_ERR("asf_mmst: too many id, stream skipped"); - } - - } else { - MSG_V ("unknown object\n"); - } - -// printf ("length : %lld\n", length); - - i += length-24; - - } - - return packet_length; - -} - - -static int get_media_packet (Tcp& tcp, int padding, networking_t& stream_ctrl) { - unsigned char pre_header[8]; - unsigned char data[BUF_SIZE]; - - if (!get_data (tcp, pre_header, 8)) { - MSG_ERR ("pre-header read failed\n"); - return 0; - } - -// for (i=0; i<8; i++) -// printf ("pre_header[%d] = %02x (%d)\n", -// i, pre_header[i], pre_header[i]); - - if (pre_header[4] == 0x04) { - - int packet_len; - - packet_len = (pre_header[7] << 8 | pre_header[6]) - 8; - -// printf ("asf media packet detected, len=%d\n", packet_len); - - if (packet_len < 0 || packet_len > BUF_SIZE) { - MSG_FATAL("Invalid rtsp packet size, giving up\n"); - return 0; - } - - if (!get_data (tcp, data, packet_len)) { - MSG_ERR ("media data read failed\n"); - return 0; - } - - networking_bufferize(stream_ctrl, data, padding); - - } else { - - int32_t packet_len; - int command; - - if (!get_data (tcp, (unsigned char*)&packet_len, 4)) { - MSG_ERR ("packet_len read failed\n"); - return 0; - } - - packet_len = get_32 ((unsigned char*)&packet_len, 0) + 4; - - if (packet_len < 0 || packet_len > BUF_SIZE) { - MSG_FATAL("Invalid rtsp packet size, giving up\n"); - return 0; - } - - if (!get_data (tcp, data, packet_len)) { - MSG_ERR ("command data read failed\n"); - return 0; - } - - if ( (pre_header[7] != 0xb0) || (pre_header[6] != 0x0b) - || (pre_header[5] != 0xfa) || (pre_header[4] != 0xce) ) { - - MSG_ERR ("missing signature\n"); - return -1; - } - - command = get_32 (data, 24) & 0xFFFF; - -// printf ("\ncommand packet detected, len=%d cmd=0x%X\n", packet_len, command); - - if (command == 0x1b) - send_command (tcp, 0x1b, 0, 0, 0, data); - else if (command == 0x1e) { - MSG_OK ("everything done. Thank you for downloading a media file containing proprietary and patentend technology.\n"); - return 0; - } - else if (command == 0x21 ) { - // Looks like it's new in WMS9 - // Unknown command, but ignoring it seems to work. - return 0; - } - else if (command != 0x05) { - MSG_ERR ("unknown command %02x\n", command); - return -1; - } - } - -// printf ("get media packet succ\n"); - - return 1; -} - - -static int packet_length1; - -static int asf_mmst_networking_read(Tcp& tcp, char *buffer, int size, networking_t& stream_ctrl ) -{ - int len; - - while( stream_ctrl.buffer_size==0 ) { - // buffer is empty - fill it! - int ret = get_media_packet(tcp, packet_length1, stream_ctrl); - if( ret<0 ) { - MSG_ERR("get_media_packet error : %s\n",strerror(errno)); - return -1; - } else if (ret==0) //EOF? - return ret; - } - - len = stream_ctrl.buffer_size-stream_ctrl.buffer_pos; - if(len>size) len=size; - memcpy( buffer, (stream_ctrl.buffer)+(stream_ctrl.buffer_pos), len ); - stream_ctrl.buffer_pos += len; - if( stream_ctrl.buffer_pos>=stream_ctrl.buffer_size ) { - delete stream_ctrl.buffer ; - stream_ctrl.buffer = NULL; - stream_ctrl.buffer_size = 0; - stream_ctrl.buffer_pos = 0; - } - return len; - -} - -static int asf_mmst_networking_seek(Tcp& tcp, off_t pos, networking_t& networking ) -{ - UNUSED(tcp); - UNUSED(pos); - UNUSED(networking); - return -1; -} - -MPXP_Rc asf_mmst_networking_start(Tcp& tcp, networking_t& networking) -{ - char str[1024]; - uint8_t data[BUF_SIZE]; - uint8_t asf_header[HDR_BUF_SIZE]; - int asf_header_len; - int len, i, packet_length; - char* path, *unescpath; - URL* url1 = networking.url; - - tcp.close(); - - /* parse url */ - path = strchr(url1->file,'/') + 1; - - /* mmst filename are not url_escaped by MS MediaPlayer and are expected as - * "plain text" by the server, so need to decode it here - */ - unescpath=new char [strlen(path)+1]; - if (!unescpath) { - MSG_FATAL("Memory allocation failed!\n"); - return MPXP_False; - } - url2string(unescpath,path); - path=unescpath; - - if( url1->port==0 ) url1->port=1755; - tcp.open(url1->hostname, url1->port, Tcp::IP4); - if( !tcp.established()) { - delete path; - return MPXP_False; - } - MSG_INFO ("connected\n"); - - seq_num=0; - - /* - * Send the initial connect info including player version no. Client GUID (random) and the host address being connected to. - * This command is sent at the very start of protocol initiation. It sends local information to the serve - * cmd 1 0x01 - * */ - - /* prepare for the url encoding conversion */ -#ifdef USE_ICONV -#ifdef USE_LANGINFO - url_conv = iconv_open("UTF-16LE",nl_langinfo(CODESET)); -#else - url_conv = iconv_open("UTF-16LE", NULL); -#endif -#endif - - snprintf (str, 1023, "\034\003NSPlayer/7.0.0.1956; {33715801-BAB3-9D85-24E9-03B90328270A}; Host: %s", url1->hostname); - string_utf16 (data, str, strlen(str)); -// send_command(s, commandno ....) - send_command (tcp, 1, 0, 0x0004000b, strlen(str) * 2+2, data); - - len = tcp.read (data, BUF_SIZE); - - /*This sends details of the local machine IP address to a Funnel system at the server. - * Also, the TCP or UDP transport selection is sent. - * - * here 192.168.0.129 is local ip address TCP/UDP states the tronsport we r using - * and 1037 is the local TCP or UDP socket number - * cmd 2 0x02 - * */ - - string_utf16 (&data[8], "\002\000\\\\192.168.0.1\\TCP\\1037", 24); - memset (data, 0, 8); - send_command (tcp, 2, 0, 0, 24*2+10, data); - - len = tcp.read(data, BUF_SIZE); - - /* This command sends file path (at server) and file name request to the server. - * 0x5 */ - - string_utf16 (&data[8], path, strlen(path)); - memset (data, 0, 8); - send_command (tcp, 5, 0, 0, strlen(path)*2+10, data); - delete path; - - get_answer (tcp); - - /* The ASF header chunk request. Includes ?session' variable for pre header value. - * After this command is sent, - * the server replies with 0x11 command and then the header chunk with header data follows. - * 0x15 */ - - memset (data, 0, 40); - data[32] = 2; - - send_command (tcp, 0x15, 1, 0, 40, data); - - num_stream_ids = 0; - /* get_headers(s, asf_header); */ - - asf_header_len = get_header (tcp, asf_header, networking); -// printf("---------------------------------- asf_header %d\n",asf_header); - if (asf_header_len==0) { //error reading header - tcp.close(); - return MPXP_False; - } - packet_length = interp_header (asf_header, asf_header_len); - - /* - * This command is the media stream MBR selector. Switches are always 6 bytes in length. - * After all switch elements, data ends with bytes [00 00] 00 20 ac 40 [02]. - * Where: - * [00 00] shows 0x61 0x00 (on the first 33 sent) or 0xff 0xff for ASF files, and with no ending data for WMV files. - * It is not yet understood what all this means. - * And the last [02] byte is probably the header ?session' value. - * - * 0x33 */ - - memset (data, 0, 40); - - if (mp_conf.audio_id > 0) { - data[2] = 0xFF; - data[3] = 0xFF; - data[4] = mp_conf.audio_id; - send_command(tcp, 0x33, num_stream_ids, 0xFFFF | mp_conf.audio_id << 16, 8, data); - } else { - for (i=1; i<num_stream_ids; i++) { - data [ (i-1) * 6 + 2 ] = 0xFF; - data [ (i-1) * 6 + 3 ] = 0xFF; - data [ (i-1) * 6 + 4 ] = stream_ids[i]; - data [ (i-1) * 6 + 5 ] = 0x00; - } - send_command (tcp, 0x33, num_stream_ids, 0xFFFF | stream_ids[0] << 16, (num_stream_ids-1)*6+2 , data); - } - - get_answer (tcp); - - /* Start sending file from packet xx. - * This command is also used for resume downloads or requesting a lost packet. - * Also used for seeking by sending a play point value which seeks to the media time point. - * Includes ?session' value in pre header and the maximum media stream time. - * 0x07 */ - - memset (data, 0, 40); - - for (i=8; i<16; i++) data[i] = 0xFF; - data[20] = 0x04; - - send_command (tcp, 0x07, 1, 0xFFFF | stream_ids[0] << 16, 24, data); - - networking.networking_read = asf_mmst_networking_read; - networking.networking_seek = asf_mmst_networking_seek; - networking.buffering = 1; - networking.status = networking_playing_e; - - packet_length1 = packet_length; - MSG_V("mmst packet_length = %d\n",packet_length); - -#ifdef USE_ICONV - if (url_conv != (iconv_t)(-1)) iconv_close(url_conv); -#endif - return MPXP_Ok; -} Deleted: mplayerxp/libmpstream2/asf_streaming.cpp =================================================================== --- mplayerxp/libmpstream2/asf_streaming.cpp 2012-12-17 12:05:45 UTC (rev 569) +++ mplayerxp/libmpstream2/asf_streaming.cpp 2012-12-17 17:03:47 UTC (rev 570) @@ -1,845 +0,0 @@ -#include "mp_config.h" -#include "osdep/mplib.h" -using namespace mpxp; -#include <limits> - -#include <stdio.h> -#include <limits.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <errno.h> - -#include "mplayerxp.h" -#ifndef HAVE_WINSOCK2 -#define closesocket close -#else -#include <winsock2.h> -#endif - -#include "url.h" -#include "tcp.h" -#include "http.h" - -#include "stream.h" -#include "asf_streaming.h" -#include "libmpdemux/asf.h" -#include "network.h" -#include "stream_msg.h" - -#if defined( ARCH_X86 ) || defined(ARCH_X86_64) -static inline uint32_t ASF_LOAD_GUID_PREFIX(uint8_t* guid) { return *(uint32_t*)guid; } -#else -static inline uint32_t ASF_LOAD_GUID_PREFIX(uint8_t* guid) { return bswap_32(*(uint32_t*)guid); } -#endif - -// ASF networking support several network protocol. -// One use UDP, not known, yet! -// Another is HTTP, this one is known. -// So for now, we use the HTTP protocol. -// -// We can try several protocol for asf networking -// * first the UDP protcol, if there is a firewall, UDP -// packets will not come back, so the mmsu will failed. -// * Then we can try TCP, but if there is a proxy for -// internet connection, the TCP connection will not get -// through -// * Then we can try HTTP. -// -// Note: MMS/HTTP support is now a "well known" support protocol, -// it has been tested for while, not like MMST support. -// WMP sequence is MMSU then MMST and then HTTP. -// In MPlayer case since HTTP support is more reliable, -// we are doing HTTP first then we try MMST if HTTP fail. -static MPXP_Rc asf_http_networking_start(Tcp& fd, networking_t& networking ); - -/* - ASF networking support several network protocol. - One use UDP, not known, yet! - Another is HTTP, this one is known. - So for now, we use the HTTP protocol. - - We can try several protocol for asf networking - * first the UDP protcol, if there is a firewall, UDP - packets will not come back, so the mmsu will failed. - * Then we can try TCP, but if there is a proxy for - internet connection, the TCP connection will not get - through - * Then we can try HTTP. - - Note: MMS/HTTP support is now a "well known" support protocol, - it has been tested for while, not like MMST support. - WMP sequence is MMSU then MMST and then HTTP. - In MPlayer case since HTTP support is more reliable, - we are doing HTTP first then we try MMST if HTTP fail. -*/ -MPXP_Rc asf_networking_start(Tcp& tcp,networking_t& networking) { - char *proto = networking.url->protocol; - int port = networking.url->port; - MPXP_Rc rc; - - // Is protocol even valid mms,mmsu,mmst,http,http_proxy? - if (!(!strncasecmp(proto, "mmst", 4) || !strncasecmp(proto, "mmsu", 4) || - !strncasecmp(proto, "http_proxy", 10) || !strncasecmp(proto, "mms", 3) || - !strncasecmp(proto, "http", 4))) { - MSG_ERR("Unknown protocol: %s\n", proto ); - return MPXP_False; - } - - // Is protocol mms or mmsu? - if (!strncasecmp(proto, "mmsu", 4) || !strncasecmp(proto, "mms", 3)) { - MSG_V("Trying ASF/UDP...\n"); - //fd = asf_mmsu_networking_start( stream ); - //mmsu support is not implemented yet - using this code - MSG_V(" ===> ASF/UDP failed\n"); - return MPXP_False; - } - - //Is protocol mms or mmst? - if (!strncasecmp(proto, "mmst", 4) || !strncasecmp(proto, "mms", 3)) { - MSG_V("Trying ASF/TCP...\n"); - rc = asf_mmst_networking_start(tcp,networking); - networking.url->port = port; - if( rc==MPXP_Ok ) return MPXP_Ok; - MSG_V(" ===> ASF/TCP failed\n"); - return MPXP_False; - } - - //Is protocol http, http_proxy, or mms? - if (!strncasecmp(proto, "http_proxy", 10) || !strncasecmp(proto, "http", 4) || - !strncasecmp(proto, "mms", 3)) { - MSG_V("Trying ASF/HTTP...\n"); - rc = asf_http_networking_start(tcp,networking); - networking.url->port = port; - if( rc==MPXP_Ok ) return MPXP_Ok; - MSG_V(" ===> ASF/HTTP failed\n"); - return MPXP_False; - } - //everything failed - return MPXP_False; -} - -static int -asf_networking(ASF_stream_chunck_t *stream_chunck, int *drop_packet ) { - if( drop_packet!=NULL ) *drop_packet = 0; - - if( stream_chunck->size<8 ) { - MSG_ERR("Ahhhh, stream_chunck size is too small: %d\n", stream_chunck->size); - return -1; - } - if( stream_chunck->size!=stream_chunck->size_confirm ) { - MSG_ERR("size_confirm mismatch!: %d %d\n", stream_chunck->size, stream_chunck->size_confirm); - return -1; - } - switch(stream_chunck->type) { - case ASF_STREAMING_CLEAR: // $C Clear ASF configuration - MSG_V("=====> Clearing ASF stream configuration!\n"); - if( drop_packet!=NULL ) *drop_packet = 1; - return stream_chunck->size; - break; - case ASF_STREAMING_DATA: // $D Data follows - break; - case ASF_STREAMING_END_TRANS: // $E Transfer complete - MSG_V("=====> Transfer complete\n"); - if( drop_packet!=NULL ) *drop_packet = 1; - return stream_chunck->size; - break; - case ASF_STREAMING_HEADER: // $H ASF header chunk follows - MSG_V("=====> ASF header chunk follows\n"); - break; - default: - MSG_V("=====> Unknown stream type 0x%x\n", stream_chunck->type ); - } - return stream_chunck->size+4; -} - -static const char asf_stream_header_guid[16] = {0x91, 0x07, 0xdc, 0xb7, - 0xb7, 0xa9, 0xcf, 0x11, 0x8e, 0xe6, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65}; -static const char asf_file_header_guid[16] = {0xa1, 0xdc, 0xab, 0x8c, - 0x47, 0xa9, 0xcf, 0x11, 0x8e, 0xe4, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65}; -static const char asf_content_desc_guid[16] = {0x33, 0x26, 0xb2, 0x75, - 0x8e, 0x66, 0xcf, 0x11, 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c}; -static const char asf_stream_group_guid[16] = {0xce, 0x75, 0xf8, 0x7b, - 0x8d, 0x46, 0xd1, 0x11, 0x8d, 0x82, 0x00, 0x60, 0x97, 0xc9, 0xa2, 0xb2}; -static const char asf_data_chunk_guid[16] = {0x36, 0x26, 0xb2, 0x75, - 0x8e, 0x66, 0xcf, 0x11, 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c}; -static int find_asf_guid(char *buf, const char *guid, int cur_pos, int buf_len) -{ - int i; - for (i = cur_pos; i < buf_len - 19; i++) { - if (memcmp(&buf[i], guid, 16) == 0) - return i + 16 + 8; // point after guid + length - } - return -1; -} - -static int max_idx(int s_count, int *s_rates, int bound) { - int i, best = -1, rate = -1; - for (i = 0; i < s_count; i++) { - if (s_rates[i] > rate && s_rates[i] <= bound) { - rate = s_rates[i]; - best = i; - } - } - return best; -} - -static MPXP_Rc -asf_networking_parse_header(Tcp& tcp, networking_t& networking) { - ASF_header_t asfh; - ASF_stream_chunck_t chunk; - asf_http_networking_t* asf_ctrl = (asf_http_networking_t*) networking.data; - char* buffer=NULL, *chunk_buffer=NULL; - int i,r,size,pos = 0; - int start; - int buffer_size = 0; - int chunk_size2read = 0; - int bw = networking.bandwidth; - int *v_rates = NULL, *a_rates = NULL; - int v_rate = 0, a_rate = 0, a_idx = -1, v_idx = -1; - - if(asf_ctrl == NULL) return MPXP_False; - - // The ASF header can be in several network chunks. For example if the content description - // is big, the ASF header will be split in 2 network chunk. - // So we need to retrieve all the chunk before starting to parse the header. - do { - for( r=0; r < (int)sizeof(ASF_stream_chunck_t) ; ) { - i = nop_networking_read(tcp,((char*)&chunk)+r,sizeof(ASF_stream_chunck_t) - r,networking); - if(i <= 0) return MPXP_False; - r += i; - } - // Endian handling of the stream chunk - le2me_ASF_stream_chunck_t(&chunk); - size = asf_networking( &chunk, &r) - sizeof(ASF_stream_chunck_t); - if(r) MSG_WARN("Warning : drop header ????\n"); - if(size < 0){ - MSG_ERR("Error while parsing chunk header\n"); - return MPXP_False; - } - if (chunk.type != ASF_STREAMING_HEADER) { - MSG_ERR("Don't got a header as first chunk !!!!\n"); - return MPXP_False; - } - // audit: do not overflow buffer_size - if (size > std::numeric_limits<size_t>::max() - buffer_size) return MPXP_False; - buffer = (char*) mp_malloc(size+buffer_size); - if(buffer == NULL) { - MSG_FATAL("Error can't allocate %d bytes buffer\n",size+buffer_size); - return MPXP_False; - } - if( chunk_buffer!=NULL ) { - memcpy( buffer, chunk_buffer, buffer_size ); - delete chunk_buffer ; - } - chunk_buffer = buffer; - buffer += buffer_size; - buffer_size += size; - - for(r = 0; r < size;) { - i = nop_networking_read(tcp,buffer+r,size-r,networking); - if(i < 0) { - MSG_ERR("Error while reading network stream\n"); - return MPXP_False; - } - r += i; - } - - if( chunk_size2read==0 ) { - if(size < (int)sizeof(asfh)) { - MSG_ERR("Error chunk is too small\n"); - return MPXP_False; - } else MSG_DBG2("Got chunk\n"); - memcpy(&asfh,buffer,sizeof(asfh)); - le2me_ASF_header_t(&asfh); - chunk_size2read = asfh.objh.size; - MSG_DBG2("Size 2 read=%d\n", chunk_size2read); - } - } while( buffer_size<chunk_size2read); - buffer = chunk_buffer; - size = buffer_size; - - if(asfh.cno > 256) { - MSG_ERR("Error sub chunks number is invalid\n"); - return MPXP_False; - } - - start = sizeof(asfh); - - pos = find_asf_guid(buffer, asf_file_header_guid, start, size); - if (pos >= 0) { - ASF_file_header_t *fileh = (ASF_file_header_t *) &buffer[pos]; - pos += sizeof(ASF_file_header_t); - if (pos > size) goto len_err_out; - le2me_ASF_file_header_t(fileh); - asf_ctrl->packet_size = fileh->max_packet_size; - // before playing. - // preroll: time in ms to bufferize before playing - networking.prebuffer_size = (unsigned int)(((double)fileh->preroll/1000.0)*((double)fileh->max_bitrate/8.0)); - } - - pos = start; - while ((pos = find_asf_guid(buffer, asf_stream_header_guid, pos, size)) >= 0) { - ASF_stream_header_t *streamh = (ASF_stream_header_t *)&buffer[pos]; - pos += sizeof(ASF_stream_header_t); - if (pos > size) goto len_err_out; - le2me_ASF_stream_header_t(streamh); - switch(ASF_LOAD_GUID_PREFIX(streamh->type)) { - case 0xF8699E40 : // audio stream - if(asf_ctrl->audio_streams == NULL){ - asf_ctrl->audio_streams = (int*)mp_malloc(sizeof(int)); - asf_ctrl->n_audio = 1; - } else { - asf_ctrl->n_audio++; - asf_ctrl->audio_streams = (int*)mp_realloc(asf_ctrl->audio_streams, - asf_ctrl->n_audio*sizeof(int)); - } - asf_ctrl->audio_streams[asf_ctrl->n_audio-1] = streamh->stream_no; - break; - case 0xBC19EFC0 : // video stream - if(asf_ctrl->video_streams == NULL){ - asf_ctrl->video_streams = (int*)mp_malloc(sizeof(int)); - asf_ctrl->n_video = 1; - } else { - asf_ctrl->n_video++; - asf_ctrl->video_streams = (int*)mp_realloc(asf_ctrl->video_streams, - asf_ctrl->n_video*sizeof(int)); - } - asf_ctrl->video_streams[asf_ctrl->n_video-1] = streamh->stream_no; - break; - } - } - - // always allocate to avoid lots of ifs later - v_rates =new(zeromem) int [asf_ctrl->n_video]; - a_rates =new(zeromem) int [asf_ctrl->n_audio]; - - pos = find_asf_guid(buffer, asf_stream_group_guid, start, size); - if (pos >= 0) { - // stream bitrate properties object - int stream_count; - char *ptr = &buffer[pos]; - - MSG_V("Stream bitrate properties object\n"); - stream_count = le2me_16(*(uint16_t*)ptr); - ptr += sizeof(uint16_t); - if (ptr > &buffer[size]) goto len_err_out; - MSG_V(" stream count=[0x%x][%u]\n",stream_count, stream_count ); - for( i=0 ; i<stream_count ; i++ ) { - uint32_t rate; - int id; - int j; - id = le2me_16(*(uint16_t*)ptr); - ptr += sizeof(uint16_t); - if (ptr > &buffer[size]) goto len_err_out; - memcpy(&rate, ptr, sizeof(uint32_t));// workaround unaligment bug on sparc - ptr += sizeof(uint32_t); - if (ptr > &buffer[size]) goto len_err_out; - rate = le2me_32(rate); - MSG_V(" stream id=[0x%x][%u]\n", id, id); - MSG_V(" max bitrate=[0x%x][%u]\n", rate, rate); - for (j = 0; j < asf_ctrl->n_video; j++) { - if (id == asf_ctrl->video_streams[j]) { - MSG_V(" is video stream\n"); - v_rates[j] = rate; - break; - } - } - for (j = 0; j < asf_ctrl->n_audio; j++) { - if (id == asf_ctrl->audio_streams[j]) { - MSG_V( " is audio stream\n"); - a_rates[j] = rate; - break; - } - } - } - } - delete buffer; - - // automatic stream selection based on bandwidth - if (bw == 0) bw = INT_MAX; - MSG_V( "Max bandwidth set to %d\n", bw); - - if (asf_ctrl->n_audio) { - // find lowest-bitrate audio stream - a_rate = a_rates[0]; - a_idx = 0; - for (i = 0; i < asf_ctrl->n_audio; i++) { - if (a_rates[i] < a_rate) { - a_rate = a_rates[i]; - a_idx = i; - } - } - if (max_idx(asf_ctrl->n_video, v_rates, bw - a_rate) < 0) { - // both audio and video are not possible, try video only next - a_idx = -1; - a_rate = 0; - } - } - // find best video stream - v_idx = max_idx(asf_ctrl->n_video, v_rates, bw - a_rate); - if (v_idx >= 0) v_rate = v_rates[v_idx]; - // find best audio stream - a_idx = max_idx(asf_ctrl->n_audio, a_rates, bw - v_rate); - - delete v_rates; - delete a_rates; - - if (a_idx < 0 && v_idx < 0) { - MSG_FATAL( "bandwidth too small, file cannot be played!\n"); - return MPXP_False; - } - - // a audio stream was forced - if (mp_conf.audio_id > 0) asf_ctrl->audio_id = mp_conf.audio_id; - else if (a_idx >= 0) asf_ctrl->audio_id = asf_ctrl->audio_streams[a_idx]; - else if (asf_ctrl->n_audio) { - MSG_WARN( "bandwidth too small, deselected audio stream\n"); - mp_conf.audio_id = -2; - } - - // a video stream was forced - if (mp_conf.video_id > 0) asf_ctrl->video_id = mp_conf.video_id; - else if (v_idx >= 0) asf_ctrl->video_id = asf_ctrl->video_streams[v_idx]; - else if (asf_ctrl->n_video) { - MSG_WARN( "bandwidth too small, deselected video stream\n"); - mp_conf.video_id = -2; - } - return MPXP_Ok; - -len_err_out: - MSG_FATAL( "Invalid length in ASF header!\n"); - if (buffer) delete buffer; - if (v_rates) delete v_rates; - if (a_rates) delete a_rates; - return MPXP_False; -} - -static int -asf_http_networking_read( Tcp& tcp, char *buffer, int size, networking_t& networking ) { - static ASF_stream_chunck_t chunk; - int read,chunk_size = 0; - static int rest = 0, drop_chunk = 0, waiting = 0; - asf_http_networking_t* asf_http_ctrl = (asf_http_networking_t*)networking.data; - - while(1) { - if (rest == 0 && waiting == 0) { - read = 0; - while(read < (int)sizeof(ASF_stream_chunck_t)){ - int r = nop_networking_read( tcp, ((char*)&chunk) + read, - sizeof(ASF_stream_chunck_t)-read, - networking ); - if(r <= 0){ - if( r < 0) - MSG_ERR("Error while reading chunk header\n"); - return -1; - } - read += r; - } - - // Endian handling of the stream chunk - le2me_ASF_stream_chunck_t(&chunk); - chunk_size = asf_networking( &chunk, &drop_chunk ); - if(chunk_size < 0) { - MSG_ERR("Error while parsing chunk header\n"); - return -1; - } - chunk_size -= sizeof(ASF_stream_chunck_t); - - if(chunk.type != ASF_STREAMING_HEADER && (!drop_chunk)) { - if (asf_http_ctrl->packet_size < chunk_size) { - MSG_ERR("Error chunk_size > packet_size\n"); - return -1; - } - waiting = asf_http_ctrl->packet_size; - } else { - waiting = chunk_size; - } - - } else if (rest){ - chunk_size = rest; - rest = 0; - } - - read = 0; - if ( waiting >= chunk_size) { - if (chunk_size > size){ - rest = chunk_size - size; - chunk_size = size; - } - while(read < chunk_size) { - int got = nop_networking_read( tcp,buffer+read,chunk_size-read,networking ); - if(got <= 0) { - if(got < 0) - MSG_ERR("Error while reading chunk\n"); - return -1; - } - read += got; - } - waiting -= read; - if (drop_chunk) continue; - } - if (rest == 0 && waiting > 0 && size-read > 0) { - int s = MIN(waiting,size-read); - memset(buffer+read,0,s); - waiting -= s; - read += s; - } - break; - } - - return read; -} - -static int -asf_http_networking_seek( Tcp& tcp, off_t pos, networking_t& networking ) { - UNUSED(tcp); - UNUSED(pos); - UNUSED(networking); - return -1; -} - -static int -asf_header_check( HTTP_Header& http_hdr ) { - ASF_obj_header_t *objh; - if( http_hdr.get_body()==NULL || http_hdr.get_body_size()<sizeof(ASF_obj_header_t) ) return -1; - - objh = (ASF_obj_header_t*)http_hdr.get_body(); - if( ASF_LOAD_GUID_PREFIX(objh->guid)==0x75B22630 ) return 0; - return -1; -} - -static ASF_StreamType_e -asf_http_networking_type(const char *content_type,const char *features, HTTP_Header& http_hdr ) { - if( content_type==NULL ) return ASF_Unknown_e; - if( !strcasecmp(content_type, "application/octet-stream") || - !strcasecmp(content_type, "application/vnd.ms.wms-hdr.asfv1") || // New in Corona, first request - !strcasecmp(content_type, "application/x-mms-framed") || // New in Corana, second request - !strcasecmp(content_type, "video/x-ms-asf")) { - - if( strstr(features, "broadcast") ) { - MSG_V("=====> ASF Live stream\n"); - return ASF_Live_e; - } else { - MSG_V("=====> ASF Prerecorded\n"); - return ASF_Prerecorded_e; - } - } else { - // Ok in a perfect world, web servers should be well configured - // so we could used mime type to know the stream type, - // but guess what? All of them are not well configured. - // So we have to check for an asf header :(, but it works :p - if( http_hdr.get_body_size()>sizeof(ASF_obj_header_t) ) { - if( asf_header_check( http_hdr )==0 ) { - MSG_V("=====> ASF Plain text\n"); - return ASF_PlainText_e; - } else if( (!strcasecmp(content_type, "text/html")) ) { - MSG_V("=====> HTML, mplayer is not a browser...yet!\n"); - return ASF_Unknown_e; - } else { - MSG_V("=====> ASF Redirector\n"); - return ASF_Redirector_e; - } - } else { - if( (!strcasecmp(content_type, "audio/x-ms-wax")) || - (!strcasecmp(content_type, "audio/x-ms-wma")) || - (!strcasecmp(content_type, "video/x-ms-asf")) || - (!strcasecmp(content_type, "video/x-ms-afs")) || - (!strcasecmp(content_type, "video/x-ms-wvx")) || - (!strcasecmp(content_type, "video/x-ms-wmv")) || - (!strcasecmp(content_type, "video/x-ms-wma")) ) { - MSG_ERR("=====> ASF Redirector\n"); - return ASF_Redirector_e; - } else if( !strcasecmp(content_type, "text/plain") ) { - MSG_V("=====> ASF Plain text\n"); - return ASF_PlainText_e; - } else { - MSG_V("=====> ASF unknown content-type: %s\n", content_type ); - return ASF_Unknown_e; - } - } - } - return ASF_Unknown_e; -} - -static HTTP_Header* asf_http_request(networking_t& networking) { - HTTP_Header* http_hdr = new(zeromem) HTTP_Header; - URL *url = NULL; - URL *server_url = NULL; - asf_http_networking_t* asf_http_ctrl; - char str[250]; - char *ptr; - int i, enable; - - int offset_hi=0, offset_lo=0, length=0; - int asf_nb_stream=0, stream_id; - - // Sanity check - url = networking.url; - asf_http_ctrl = (asf_http_networking_t*)networking.data; - if( url==NULL || asf_http_ctrl==NULL ) return NULL; - - // Common header for all requests. - http_hdr->set_field("Accept: */*" ); - http_hdr->set_field("User-Agent: NSPlayer/4.1.0.3856" ); - http_hdr->add_basic_authentication(url->username?url->username:"", url->password?url->password:"" ); - - // Check if we are using a proxy - if( !strcasecmp( url->protocol, "http_proxy" ) ) { - server_url = url_new( (url->file)+1 ); - if( server_url==NULL ) { - MSG_ERR("Invalid proxy URL\n"); - delete http_hdr; - return NULL; - } - http_hdr->set_uri(server_url->url ); - sprintf( str, "Host: %.220s:%d", server_url->hostname, server_url->port ); - delete server_url; - } else { - http_hdr->set_uri(url->file ); - sprintf( str, "Host: %.220s:%d", url->hostname, url->port ); - } - - http_hdr->set_field(str ); - http_hdr->set_field("Pragma: xClientGUID={c77e7400-738a-11d2-9add-0020af0a3278}" ); - sprintf(str, - "Pragma: no-cache,rate=1.000000,stream-time=0,stream-offset=%u:%u,request-context=%d,max-duration=%u", - offset_hi, offset_lo, asf_http_ctrl->request, length ); - http_hdr->set_field( str ); - - switch( asf_http_ctrl->networking_type ) { - case ASF_Live_e: - case ASF_Prerecorded_e: - http_hdr->set_field("Pragma: xPlayStrm=1" ); - ptr = str; - ptr += sprintf( ptr, "Pragma: stream-switch-entry="); - if(asf_http_ctrl->n_audio > 0) { - for( i=0; i<asf_http_ctrl->n_audio ; i++ ) { - stream_id = asf_http_ctrl->audio_streams[i]; - if(stream_id == asf_http_ctrl->audio_id) { - enable = 0; - } else { - enable = 2; - continue; - } - asf_nb_stream++; - ptr += sprintf(ptr, "ffff:%d:%d ", stream_id, enable); - } - } - if(asf_http_ctrl->n_video > 0) { - for( i=0; i<asf_http_ctrl->n_video ; i++ ) { - stream_id = asf_http_ctrl->video_streams[i]; - if(stream_id == asf_http_ctrl->video_id) { - enable = 0; - } else { - enable = 2; - continue; - } - asf_nb_stream++; - ptr += sprintf(ptr, "ffff:%d:%d ", stream_id, enable); - } - } - http_hdr->set_field(str ); - sprintf( str, "Pragma: stream-switch-count=%d", asf_nb_stream ); - http_hdr->set_field( str ); - break; - case ASF_Redirector_e: - break; - case ASF_Unknown_e: - // First request goes here. - break; - default: - MSG_ERR("Unknown asf stream type\n"); - } - - http_hdr->set_field("Connection: Close" ); - http_hdr->build_request( ); - - return http_hdr; -} - -static int -asf_http_parse_response(asf_http_networking_t& asf_http_ctrl, HTTP_Header& http_hdr ) { - const char *content_type, *pragma; - char features[64] = "\0"; - size_t len; - if( http_hdr.response_parse()<0 ) { - MSG_ERR("Failed to parse HTTP response\n"); - return -1; - } - switch( http_hdr.get_status()) { - case 200: - break; - case 401: // Authentication required - return ASF_Authenticate_e; - default: - MSG_ERR("Server return %d:%s\n", http_hdr.get_status(), http_hdr.get_reason_phrase()); - return -1; - } - - content_type = http_hdr.get_field("Content-Type"); - - pragma = http_hdr.get_field("Pragma"); - while( pragma!=NULL ) { - const char *comma_ptr=NULL; - const char *end; - // The pragma line can get severals attributes - // separeted with a comma ','. - do { - if( !strncasecmp( pragma, "features=", 9) ) { - pragma += 9; - end = strstr( pragma, "," ); - if( end==NULL ) { - size_t s = strlen(pragma); - if(s > sizeof(features)) { - MSG_WARN("ASF HTTP PARSE WARNING : Pragma %s cuted from %d bytes to %d\n",pragma,s,sizeof(features)); - len = sizeof(features); - } else { - len = s; - } - } else { - len = MIN((unsigned int)(end-pragma),sizeof(features)); - } - strncpy( features, pragma, len ); - features[len]='\0'; - break; - } - comma_ptr = strstr( pragma, "," ); - if( comma_ptr!=NULL ) { - pragma = comma_ptr+1; - if( pragma[0]==' ' ) pragma++; - } - } while( comma_ptr!=NULL ); - pragma = http_hdr.get_next_field(); - } - asf_http_ctrl.networking_type = asf_http_networking_type( content_type, features, http_hdr ); - return 0; -} - -static MPXP_Rc asf_http_networking_start(Tcp& tcp, networking_t& networking) { - HTTP_Header *http_hdr=NULL; - URL *url = networking.url; - asf_http_networking_t* asf_http_ctrl; - uint8_t buffer[BUFFER_SIZE]; - int i, ret; - int done; - int auth_retry = 0; - - asf_http_ctrl = new(zeromem) asf_http_networking_t; - if( asf_http_ctrl==NULL ) { - MSG_FATAL("Memory allocation failed\n"); - return MPXP_False; - } - asf_http_ctrl->networking_type = ASF_Unknown_e; - asf_http_ctrl->request = 1; - asf_http_ctrl->audio_streams = asf_http_ctrl->video_streams = NULL; - asf_http_ctrl->n_audio = asf_http_ctrl->n_video = 0; - networking.data = asf_http_ctrl; - - do { - done = 1; - tcp.close(); - - if( !strcasecmp( url->protocol, "http_proxy" ) ) { - if( url->port==0 ) url->port = 8080; - } else { - if( url->port==0 ) url->port = 80; - } - tcp.open(url->hostname, url->port, Tcp::IP4); - if( !tcp.established()) return MPXP_False; - - http_hdr = asf_http_request( networking ); - MSG_DBG2("Request [%s]\n", http_hdr->get_buffer() ); - for(i=0; i < (int)http_hdr->get_buffer_size() ; ) { - int r = tcp.write((uint8_t*)(http_hdr->get_buffer()+i), http_hdr->get_buffer_size()-i); - if(r<0) { - MSG_ERR("Socket write error : %s\n",strerror(errno)); - return MPXP_False; - } - i += r; - } - delete http_hdr; - http_hdr = new(zeromem) HTTP_Header; - do { - i = tcp.read(buffer, BUFFER_SIZE); - if( i<=0 ) { - perror("read"); - delete http_hdr; - return MPXP_False; - } - http_hdr->response_append(buffer,i); - } while( !http_hdr->is_header_entire()); - if( mp_conf.verbose>0 ) { - MSG_DBG2("Response [%s]\n", http_hdr->get_buffer() ); - } - ret = asf_http_parse_response(*asf_http_ctrl, *http_hdr); - if( ret<0 ) { - MSG_ERR("Failed to parse header\n"); - delete http_hdr; - return MPXP_False; - } - switch( asf_http_ctrl->networking_type ) { - case ASF_Live_e: - case ASF_Prerecorded_e: - case ASF_PlainText_e: - if( http_hdr->get_body_size()>0 ) { - if( networking_bufferize( networking, (unsigned char *)(http_hdr->get_body()), http_hdr->get_body_size())<0 ) { - delete http_hdr; - return MPXP_False; - } - } - if( asf_http_ctrl->request==1 ) { - if( asf_http_ctrl->networking_type!=ASF_PlainText_e ) { - // First request, we only got the ASF header. - ret = asf_networking_parse_header(tcp,networking); - if(ret < 0) return MPXP_False; - if(asf_http_ctrl->n_audio == 0 && asf_http_ctrl->n_video == 0) { - MSG_ERR("No stream found\n"); - return MPXP_False; - } - asf_http_ctrl->request++; - done = 0; - } else done = 1; - } - break; - case ASF_Redirector_e: - if( http_hdr->get_body_size()>0 ) { - if( networking_bufferize( networking, (unsigned char*)http_hdr->get_body(), http_hdr->get_body_size())<0 ) { - delete http_hdr; - return MPXP_False; - } - } -// type |= STREAMTYPE_TEXT; - done = 1; - break; - case ASF_Authenticate_e: - if( http_authenticate( *http_hdr, url, &auth_retry)<0 ) return MPXP_False; - asf_http_ctrl->networking_type = ASF_Unknown_e; - done = 0; - break; - case ASF_Unknown_e: - default: - MSG_ERR("Unknown ASF networking type\n"); - tcp.close(); - delete http_hdr; - return MPXP_False; - } - // Check if we got a redirect. - } while(!done); - - if( asf_http_ctrl->networking_type==ASF_PlainText_e || asf_http_ctrl->networking_type==ASF_Redirector_e ) { - networking.networking_read = nop_networking_read; - networking.networking_seek = nop_networking_seek; - } else { - networking.networking_read = asf_http_networking_read; - networking.networking_seek = asf_http_networking_seek; - networking.buffering = 1; - } - networking.status = networking_playing_e; - - delete http_hdr; - return MPXP_Ok; -} - -asf_http_networking_t::asf_http_networking_t() {} -asf_http_networking_t::~asf_http_networking_t() {} \ No newline at end of file Deleted: mplayerxp/libmpstream2/asf_streaming.h =================================================================== --- mplayerxp/libmpstream2/asf_streaming.h 2012-12-17 12:05:45 UTC (rev 569) +++ mplayerxp/libmpstream2/asf_streaming.h 2012-12-17 17:03:47 UTC (rev 570) @@ -1,39 +0,0 @@ -#ifndef __ASF_STEAMING_H_INCLUDED -#define __ASF_STEAMING_H_INCLUDED 1 -#include "mp_config.h" -#include "osdep/mplib.h" -using namespace mpxp; - -#include "stream.h" - -struct networking_t; -namespace mpxp { - class Tcp; -} - -// Definition of the differents type of ASF streaming -enum ASF_StreamType_e { - ASF_Unknown_e, - ASF_Live_e, - ASF_Prerecorded_e, - ASF_Redirector_e, - ASF_PlainText_e, - ASF_Authenticate_e -}; - -struct asf_http_networking_t : public Opaque { - public: - asf_http_networking_t(); - virtual ~asf_http_networking_t(); - - ASF_StreamType_e networking_type; - int request; - int packet_size; - int *audio_streams,n_audio,*video_streams,n_video; - int audio_id, video_id; -}; - -extern MPXP_Rc asf_networking_start(Tcp& fd, networking_t& networking); -extern MPXP_Rc asf_mmst_networking_start(Tcp& fd, networking_t& networking); - -#endif Modified: mplayerxp/libmpstream2/http.cpp =================================================================== --- mplayerxp/libmpstream2/http.cpp 2012-12-17 12:05:45 UTC (rev 569) +++ mplayerxp/libmpstream2/http.cpp 2012-12-17 17:03:47 UTC (rev 570) @@ -16,7 +16,9 @@ #include "http.h" #include "url.h" +#include "help_mp.h" #include "stream_msg.h" +#include "network.h" namespace mpxp { HTTP_Header::HTTP_Header() {} @@ -300,6 +302,57 @@ MSG_V("--- HTTP DEBUG HEADER --- END ---\n"); } +int HTTP_Header::authenticate(URL *url, int *auth_retry) { + const char *aut; + + if( *auth_retry==1 ) { + MSG_ERR(MSGTR_ConnAuthFailed); + return -1; + } + if( *auth_retry>0 ) { + if( url->username ) { + delete url->username ; + url->username = NULL; + } + if( url->password ) { + delete url->password ; + url->password = NULL; + } + } + + aut = get_field("WWW-Authenticate"); + if( aut!=NULL ) { + const char *aut_space; + aut_space = strstr(aut, "realm="); + if( aut_space!=NULL ) aut_space += 6; + MSG_INFO("Authentication required for %s\n", aut_space); + } else { + MSG_INFO("Authentication required\n"); + } + if( net_conf.username ) { + url->username = mp_strdup(net_conf.username); + if( url->username==NULL ) { + MSG_FATAL(MSGTR_OutOfMemory); + return -1; + } + } else { + MSG_ERR(MSGTR_ConnAuthFailed); + return -1; + } + if( net_conf.password ) { + url->password = mp_strdup(net_conf.password); + if( url->password==NULL ) { + MSG_FATAL(MSGTR_OutOfMemory); + return -1; + } + } else { + MSG_INFO("No password provided, trying blank password\n"); + } + (*auth_retry)++; + return 0; +} + + int base64_encode(const any_t*enc, int encLen, char *out, int outMax) { static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; Modified: mplayerxp/libmpstream2/http.h =================================================================== --- mplayerxp/libmpstream2/http.h 2012-12-17 12:05:45 UTC (rev 569) +++ mplayerxp/libmpstream2/http.h 2012-12-17 17:03:47 UTC (rev 570) @@ -12,6 +12,8 @@ #include <vector> #include <stdint.h> +#include "url.h" + namespace mpxp { class HTTP_Header : public Opaque { public: @@ -28,6 +30,7 @@ virtual void set_method(const std::string& method ); virtual void set_uri(const std::string& uri ); virtual int add_basic_authentication(const std::string& username, const std::string& password ); + virtual int authenticate(URL *url, int *auth_retry); virtual void debug_hdr(); virtual void cookies_set(const std::string& hostname, const std::string& url); Modified: mplayerxp/libmpstream2/network.cpp =================================================================== --- mplayerxp/libmpstream2/network.cpp 2012-12-17 12:05:45 UTC (rev 569) +++ mplayerxp/libmpstream2/network.cpp 2012-12-17 17:03:47 UTC (rev 570) @@ -19,7 +19,13 @@ #include <ctype.h> #include "mplayerxp.h" -#include "asf_streaming.h" +#include "network_asf.h" +#include "network_asf_mmst.h" +#include "network_nop.h" +#include "network_pnm.h" +#include "network_real_rtsp.h" +#include "network_rtp.h" +#include "network_rtsp.h" #ifndef HAVE_WINSOCK2 #define closesocket close #else @@ -27,8 +33,8 @@ #include <ws2tcpip.h> #endif -#include "stream.h" #include "libmpconf/cfgparser.h" +#include "stream.h" #include "help_mp.h" #include "tcp.h" @@ -37,14 +43,10 @@ #include "cookies.h" #include "url.h" #include "udp.h" -#include "pnm.h" -#ifndef STREAMING_LIVE_DOT_COM -#include "rtp.h" -#endif -#include "librtsp/rtsp_session.h" #include "version.h" #include "stream_msg.h" +namespace mpxp { /* Variables for the command line option -user, -passwd & -bandwidth */ net_config_t::net_config_t() :username(NULL), @@ -60,19 +62,6 @@ net_config_t::~net_config_t() {} net_config_t net_conf; -networking_t* new_networking() { - networking_t* networking = new(zeromem) networking_t; - networking->mime="application/octet-stream"; - return networking; -} - -void free_networking( networking_t& networking ) { - if( networking.url ) delete networking.url; - if( networking.buffer ) delete networking.buffer ; - if( networking.data ) delete networking.data ; - delete &networking; -} - URL* check4proxies( URL *url ) { URL *url_out = NULL; @@ -225,58 +214,7 @@ return http_hdr; } -int -http_authenticate(HTTP_Header& http_hdr, URL *url, int *auth_retry) { - const char *aut; - - if( *auth_retry==1 ) { - MSG_ERR(MSGTR_ConnAuthFailed); - return -1; - } - if( *auth_retry>0 ) { - if( url->username ) { - delete url->username ; - url->username = NULL; - } - if( url->password ) { - delete url->password ; - url->password = NULL; - } - } - - aut = http_hdr.get_field("WWW-Authenticate"); - if( aut!=NULL ) { - const char *aut_space; - aut_space = strstr(aut, "realm="); - if( aut_space!=NULL ) aut_space += 6; - MSG_INFO("Authentication required for %s\n", aut_space); - } else { - MSG_INFO("Authentication required\n"); - } - if( net_conf.username ) { - url->username = mp_strdup(net_conf.username); - if( url->username==NULL ) { - MSG_FATAL(MSGTR_OutOfMemory); - return -1; - } - } else { - MSG_ERR(MSGTR_ConnAuthFailed); - return -1; - } - if( net_conf.password ) { - url->password = mp_strdup(net_conf.password); - if( url->password==NULL ) { - MSG_FATAL(MSGTR_OutOfMemory); - return -1; - } - } else { - MSG_INFO("No password provided, trying blank password\n"); - } - (*auth_retry)++; - return 0; -} - -off_t http_seek(Tcp& tcp, networking_t& networking, off_t pos ) { +off_t http_seek(Tcp& tcp, Networking& networking, off_t pos ) { HTTP_Header* http_hdr = NULL; tcp.close(); @@ -292,7 +230,7 @@ MSG_V("Content-Type: [%s]\n", http_hdr->get_field("Content-Type") ); MSG_V("Content-Length: [%s]\n", http_hdr->get_field("Content-Length") ); if( http_hdr->get_body_size()>0 ) { - if( networking_bufferize( networking, (unsigned char *)http_hdr->get_body(), http_hdr->get_body_size() )<0 ) { + if( networking.bufferize((unsigned char *)http_hdr->get_body(), http_hdr->get_body_size() )<0 ) { delete http_hdr; return 0; } @@ -311,9 +249,18 @@ return pos; } +Networking::Networking() + :mime("application/octet-stream") {} + +Networking::~Networking() { + if( url ) delete url; + if( buffer ) delete buffer ; + if( data ) delete data ; +} + // By using the protocol, the extension of the file or the content-type // we might be able to guess the networking type. -static MPXP_Rc autodetectProtocol(networking_t& networking, Tcp& tcp) { +MPXP_Rc Networking::autodetectProtocol(network_protocol_t& networking, Tcp& tcp) { HTTP_Header *http_hdr=NULL; int redirect; int auth_retry=0; @@ -432,7 +379,7 @@ } break; case 401: // Authentication required - if( http_authenticate(*http_hdr,url, &auth_retry)<0 ) goto err_out; + if( http_hdr->authenticate(url, &auth_retry)<0 ) goto err_out; redirect = 1; break; default: @@ -450,301 +397,72 @@ return MPXP_False; } -int -networking_bufferize( networking_t& networking,unsigned char *buffer, int size) { +int Networking::bufferize(unsigned char *_buffer, int size) { //printf("networking_bufferize\n"); - networking.buffer = new char [size]; - if( networking.buffer==NULL ) { + buffer = new char [size]; + if( buffer==NULL ) { MSG_FATAL(MSGTR_OutOfMemory); return -1; } - memcpy( networking.buffer, buffer, size ); - networking.buffer_size = size; + memcpy( buffer, _buffer, size ); + buffer_size = size; return size; } -int -nop_networking_read(Tcp& tcp, char *buffer, int size, networking_t& stream_ctrl ) { - int len=0; -//printf("nop_networking_read\n"); - if( stream_ctrl.buffer_size!=0 ) { - int buffer_len = stream_ctrl.buffer_size-stream_ctrl.buffer_pos; -//printf("%d bytes in buffer\n", stream_ctrl.buffer_size); - len = (size<buffer_len)?size:buffer_len; - memcpy( buffer, (stream_ctrl.buffer)+(stream_ctrl.buffer_pos), len ); - stream_ctrl.buffer_pos += len; -//printf("buffer_pos = %d\n", stream_ctrl.buffer_pos ); - if( stream_ctrl.buffer_pos>=stream_ctrl.buffer_size ) { - delete stream_ctrl.buffer ; - stream_ctrl.buffer = NULL; - stream_ctrl.buffer_size = 0; - stream_ctrl.buffer_pos = 0; -//printf("buffer cleaned\n"); - } -//printf("read %d bytes from buffer\n", len ); - } - if( len<size ) { - int ret; - ret = tcp.read((uint8_t*)(buffer+len), size-len); - if( ret<0 ) { - MSG_ERR("nop_networking_read error : %s\n",strerror(errno)); - } - len += ret; -//printf("read %d bytes from network\n", len ); - } - return len; -} - -int -nop_networking_seek(Tcp& tcp, off_t pos, networking_t& n ) { - UNUSED(tcp); - UNUSED(pos); - UNUSED(n); - return -1; -} - -MPXP_Rc nop_networking_start(Tcp& tcp,networking_t& networking ) { - HTTP_Header *http_hdr = NULL; - const char *next_url=NULL; - URL *rd_url=NULL; - MPXP_Rc ret; - - if( !tcp.established() ) { - http_send_request(tcp, networking.url,0); - if( !tcp.established() ) return MPXP_False; - http_hdr = http_read_response(tcp); - if( http_hdr==NULL ) return MPXP_False; - - switch( http_hdr->get_status() ) { - case 200: // OK - MSG_V("Content-Type: [%s]\n", http_hdr->get_field("Content-Type") ); - MSG_V("Content-Length: [%s]\n", http_hdr->get_field("Content-Length") ); - if( http_hdr->get_body_size()>0 ) { - if( networking_bufferize( networking, (unsigned char *)http_hdr->get_body(), http_hdr->get_body_size() )<0 ) { - delete http_hdr; - return MPXP_False; - } - } - break; - // Redirect - case 301: // Permanently - case 302: // Temporarily - ret=MPXP_False; - next_url = http_hdr->get_field("Location" ); - - if (next_url != NULL) - rd_url=url_new(next_url); - - if (next_url != NULL && rd_url != NULL) { - MSG_STATUS("Redirected: Using this url instead %s\n",next_url); - networking.url=check4proxies(rd_url); - ret=nop_networking_start(tcp,networking); //recursively get networking started - } else { - MSG_ERR("Redirection failed\n"); - tcp.close(); - } - return ret; - break; - case 401: //Authorization required - case 403: //Forbidden - case 404: //Not found - case 500: //Server Error - default: - MSG_ERR("Server return %d: %s\n", http_hdr->get_status(), http_hdr->get_reason_phrase()); - tcp.close(); - return MPXP_False; - break; - } - } else { - http_hdr = (HTTP_Header*)networking.data; - if( http_hdr->get_body_size()>0 ) { - if( networking_bufferize( networking, (unsigned char*)http_hdr->get_body(), http_hdr->get_body_size() )<0 ) { - delete http_hdr; - networking.data = NULL; - return MPXP_False; - } - } - } - - if( http_hdr ) { - delete http_hdr; - networking.data = NULL; - } - - networking.networking_read = nop_networking_read; - networking.networking_seek = nop_networking_seek; - networking.prebuffer_size = 64*1024; // KBytes - networking.buffering = 1; - networking.status = networking_playing_e; - return MPXP_Ok; -} - -void fixup_network_stream_cache(networking_t& networking) { - if(networking.buffering) { +void Networking::fixup_cache() { + if(buffering) { if(mp_conf.s_cache_size<0) { // cache option not set, will use our computed value. // buffer in KBytes, *5 because the prefill is 20% of the buffer. - mp_conf.s_cache_size = (networking.prebuffer_size/1024)*5; + mp_conf.s_cache_size = (prebuffer_size/1024)*5; if( mp_conf.s_cache_size<64 ) mp_conf.s_cache_size = 64; // 16KBytes min buffer } MSG_INFO("[network] cache size set to: %i\n", mp_conf.s_cache_size); } } -int -pnm_networking_read(Tcp& tcp, char *buffer, int size, networking_t& stream_ctrl ) { - Pnm& pnm=*static_cast<Pnm*>(stream_ctrl.data); - UNUSED(tcp); - return pnm.read(buffer, size); -} +Networking* Networking::start(Tcp& tcp, URL *_url) { + Networking* rc; + network_protocol_t net_protocol; + URL* url = check4proxies( _url ); -MPXP_Rc pnm_networking_start(Tcp& tcp,networking_t& networking ) { - Pnm* pnm = new(zeromem) Pnm(tcp); + net_protocol.url=url; - tcp.open(networking.url->hostname, - networking.url->port ? networking.url->port : 7070); - if(!tcp.established()) return MPXP_False; + if( autodetectProtocol(net_protocol,tcp)!=MPXP_Ok ) return NULL; + rc = NULL; + url=net_protocol.url; - if(pnm->connect(networking.url->file)!=MPXP_Ok) { - delete pnm; - return MPXP_NA; - } - networking.data=pnm; - networking.networking_read = pnm_networking_read; - networking.prebuffer_size = 8*1024; // 8 KBytes - networking.buffering = 1; - networking.status = networking_playing_e; - return MPXP_Ok; -} - -int -realrts... [truncated message content] |
From: <nic...@us...> - 2012-12-17 17:36:08
|
Revision: 571 http://mplayerxp.svn.sourceforge.net/mplayerxp/?rev=571&view=rev Author: nickols_k Date: 2012-12-17 17:36:01 +0000 (Mon, 17 Dec 2012) Log Message: ----------- add ASF MMST autodetection Modified Paths: -------------- mplayerxp/libmpstream2/network.cpp mplayerxp/libmpstream2/network.h mplayerxp/libmpstream2/network_asf_mmst.cpp mplayerxp/libmpstream2/network_asf_mmst.h mplayerxp/libmpstream2/network_rtsp.cpp mplayerxp/libmpstream2/s_rtsp.cpp mplayerxp/libmpstream2/s_udp.cpp Modified: mplayerxp/libmpstream2/network.cpp =================================================================== --- mplayerxp/libmpstream2/network.cpp 2012-12-17 17:03:47 UTC (rev 570) +++ mplayerxp/libmpstream2/network.cpp 2012-12-17 17:36:01 UTC (rev 571) @@ -241,10 +241,7 @@ tcp.close(); } - if( http_hdr ) { - delete http_hdr; - networking.data = NULL; - } + if( http_hdr ) delete http_hdr; return pos; } @@ -254,8 +251,8 @@ Networking::~Networking() { if( url ) delete url; - if( buffer ) delete buffer ; - if( data ) delete data ; + if( buffer ) delete buffer; + if( data ) delete data; } // By using the protocol, the extension of the file or the content-type @@ -443,8 +440,7 @@ MSG_INFO("Can't connect with pnm, retrying with http.\n"); return NULL; } - } - else if( !strcasecmp( url->protocol, "rtsp")) { + } else if( !strcasecmp( url->protocol, "rtsp")) { if ((rc = RealRtsp_Networking::start( tcp, net_protocol )) == NULL) { MSG_INFO("Not a Realmedia rtsp url. Trying standard rtsp protocol.\n"); #ifdef STREAMING_LIVE_DOT_COM @@ -456,14 +452,21 @@ return NULL; #endif } - } - else if(!strcasecmp( url->protocol, "udp")) { + } else if(!strcasecmp( url->protocol, "udp")) { tcp.close(); rc = Rtp_Networking::start(tcp, net_protocol, 1); if(!rc) { MSG_ERR("rtp_networking_start(udp) failed\n"); return NULL; } + } else if(!strncasecmp(url->protocol, "mms", 3) || + !strncasecmp(url->protocol, "mmst", 4) || + !strncasecmp(url->protocol, "mmsu", 4)) { + rc=Asf_Mmst_Networking::start(tcp,net_protocol); + if(!rc) { + MSG_ERR("asf_mmst_networking_start() failed\n"); + return NULL; + } } else { // Send the appropriate HTTP request // Need to filter the network stream. Modified: mplayerxp/libmpstream2/network.h =================================================================== --- mplayerxp/libmpstream2/network.h 2012-12-17 17:03:47 UTC (rev 570) +++ mplayerxp/libmpstream2/network.h 2012-12-17 17:36:01 UTC (rev 571) @@ -71,22 +71,23 @@ virtual void fixup_cache(); virtual int bufferize(unsigned char *buffer, int size); - URL *url; - std::string mime; - networking_status status; - int buffering; // boolean - unsigned int prebuffer_size; - char *buffer; - unsigned int buffer_size; - unsigned int buffer_pos; - unsigned int bandwidth; // The downstream available virtual int read( Tcp& fd, char *buffer, int buffer_size) = 0; virtual int seek( Tcp& fd, off_t pos) = 0; - Opaque* data; + + std::string mime; + URL* url; + networking_status status; + unsigned int bandwidth; // The downstream available protected: Networking(); + unsigned int prebuffer_size; + int buffering; // boolean + char* buffer; + unsigned int buffer_size; + unsigned int buffer_pos; + Opaque* data; private: - static MPXP_Rc autodetectProtocol(network_protocol_t& protocol,Tcp& tcp); + static MPXP_Rc autodetectProtocol(network_protocol_t& protocol,Tcp& tcp); }; extern URL* check4proxies( URL* url ); Modified: mplayerxp/libmpstream2/network_asf_mmst.cpp =================================================================== --- mplayerxp/libmpstream2/network_asf_mmst.cpp 2012-12-17 17:03:47 UTC (rev 570) +++ mplayerxp/libmpstream2/network_asf_mmst.cpp 2012-12-17 17:36:01 UTC (rev 571) @@ -360,8 +360,7 @@ } - -static int get_media_packet (Tcp& tcp, int padding, Networking& stream_ctrl) { +int Asf_Mmst_Networking::get_media_packet (Tcp& tcp, int padding) { unsigned char pre_header[8]; unsigned char data[BUF_SIZE]; @@ -392,7 +391,7 @@ return 0; } - stream_ctrl.bufferize(data, padding); + bufferize(data, padding); } else { @@ -452,39 +451,35 @@ static int packet_length1; -static int asf_mmst_networking_read(Tcp& tcp, char *buffer, int size, Networking& stream_ctrl ) +int Asf_Mmst_Networking::read(Tcp& tcp, char *_buffer, int size) { - int len; + int len; - while( stream_ctrl.buffer_size==0 ) { - // buffer is empty - fill it! - int ret = get_media_packet(tcp, packet_length1, stream_ctrl); - if( ret<0 ) { - MSG_ERR("get_media_packet error : %s\n",strerror(errno)); - return -1; - } else if (ret==0) //EOF? - return ret; - } - - len = stream_ctrl.buffer_size-stream_ctrl.buffer_pos; - if(len>size) len=size; - memcpy( buffer, (stream_ctrl.buffer)+(stream_ctrl.buffer_pos), len ); - stream_ctrl.buffer_pos += len; - if( stream_ctrl.buffer_pos>=stream_ctrl.buffer_size ) { - delete stream_ctrl.buffer ; - stream_ctrl.buffer = NULL; - stream_ctrl.buffer_size = 0; - stream_ctrl.buffer_pos = 0; - } - return len; - + while( buffer_size==0 ) { + // buffer is empty - fill it! + int ret = get_media_packet(tcp, packet_length1); + if( ret<0 ) { + MSG_ERR("get_media_packet error : %s\n",strerror(errno)); + return -1; + } else if (ret==0) return ret; // EOF? + } + len = buffer_size-buffer_pos; + if(len>size) len=size; + memcpy( _buffer, buffer+buffer_pos, len ); + buffer_pos += len; + if( buffer_pos>=buffer_size ) { + delete buffer ; + buffer = NULL; + buffer_size = 0; + buffer_pos = 0; + } + return len; } -static int asf_mmst_networking_seek(Tcp& tcp, off_t pos, Networking& networking ) +int Asf_Mmst_Networking::seek(Tcp& tcp, off_t pos) { UNUSED(tcp); UNUSED(pos); - UNUSED(networking); return -1; } @@ -664,4 +659,6 @@ #endif return rv; } +Asf_Mmst_Networking::Asf_Mmst_Networking() {} +Asf_Mmst_Networking::~Asf_Mmst_Networking() {} } // namespace mpxp Modified: mplayerxp/libmpstream2/network_asf_mmst.h =================================================================== --- mplayerxp/libmpstream2/network_asf_mmst.h 2012-12-17 17:03:47 UTC (rev 570) +++ mplayerxp/libmpstream2/network_asf_mmst.h 2012-12-17 17:36:01 UTC (rev 571) @@ -14,6 +14,7 @@ private: Asf_Mmst_Networking(); int get_header (Tcp& tcp, uint8_t *header); + int get_media_packet (Tcp& tcp, int padding); }; } // namespace mpxp #endif Modified: mplayerxp/libmpstream2/network_rtsp.cpp =================================================================== --- mplayerxp/libmpstream2/network_rtsp.cpp 2012-12-17 17:03:47 UTC (rev 570) +++ mplayerxp/libmpstream2/network_rtsp.cpp 2012-12-17 17:36:01 UTC (rev 571) @@ -77,5 +77,8 @@ } Rtsp_Networking::Rtsp_Networking() {} -Rtsp_Networking::~Rtsp_Networking() {} +Rtsp_Networking::~Rtsp_Networking() { + Rtsp_Session* rtsp = static_cast<Rtsp_Session*>(data); + if (rtsp) rtsp->end(); +} } // namespace mpxp Modified: mplayerxp/libmpstream2/s_rtsp.cpp =================================================================== --- mplayerxp/libmpstream2/s_rtsp.cpp 2012-12-17 17:03:47 UTC (rev 570) +++ mplayerxp/libmpstream2/s_rtsp.cpp 2012-12-17 17:36:01 UTC (rev 571) @@ -70,8 +70,6 @@ void Rtsp_Stream_Interface::close() { - Rtsp_Session* rtsp = static_cast<Rtsp_Session*>(networking->data); - if (rtsp) rtsp->end (); delete networking; networking=NULL; } Modified: mplayerxp/libmpstream2/s_udp.cpp =================================================================== --- mplayerxp/libmpstream2/s_udp.cpp 2012-12-17 17:03:47 UTC (rev 570) +++ mplayerxp/libmpstream2/s_udp.cpp 2012-12-17 17:36:01 UTC (rev 571) @@ -43,7 +43,7 @@ virtual off_t sector_size() const; virtual std::string mime_type() const; private: - MPXP_Rc start (unsigned); + MPXP_Rc start (URL*,unsigned); Networking* networking; Udp udp; @@ -77,18 +77,19 @@ networking=NULL; } -MPXP_Rc Udp_Stream_Interface::start (unsigned bandwidth) +MPXP_Rc Udp_Stream_Interface::start (URL* url,unsigned bandwidth) { if (!udp.established()) { udp.open(networking->url); if (!udp.established()) return MPXP_False; } tcp=udp.socket(); + network_protocol_t net_protocol; + net_protocol.url=url; + net_protocol.mime="application/octet-stream"; Nop_Networking* rv = new(zeromem) Nop_Networking; + rv->start(tcp,net_protocol); rv->bandwidth = bandwidth; - rv->prebuffer_size = 64 * 1024; /* 64 KBytes */ - rv->buffering = 0; - rv->status = networking_playing_e; return MPXP_Ok; } @@ -104,7 +105,7 @@ MSG_ERR("You must enter a port number for UDP streams!\n"); return MPXP_False; } - if (start(net_conf.bandwidth) != MPXP_Ok) { + if (start(url,net_conf.bandwidth) != MPXP_Ok) { MSG_ERR("udp_networking_start failed\n"); return MPXP_False; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nic...@us...> - 2012-12-18 13:04:39
|
Revision: 572 http://mplayerxp.svn.sourceforge.net/mplayerxp/?rev=572&view=rev Author: nickols_k Date: 2012-12-18 13:04:29 +0000 (Tue, 18 Dec 2012) Log Message: ----------- make class URL full-featured and use references on it + constantization Modified Paths: -------------- mplayerxp/libmpstream2/cddb.cpp mplayerxp/libmpstream2/http.cpp mplayerxp/libmpstream2/http.h mplayerxp/libmpstream2/librtsp/rtsp.cpp mplayerxp/libmpstream2/librtsp/rtsp.h mplayerxp/libmpstream2/librtsp/rtsp_session.cpp mplayerxp/libmpstream2/librtsp/rtsp_session.h mplayerxp/libmpstream2/network.cpp mplayerxp/libmpstream2/network.h mplayerxp/libmpstream2/network_asf.cpp mplayerxp/libmpstream2/network_asf_mmst.cpp mplayerxp/libmpstream2/network_nop.cpp mplayerxp/libmpstream2/network_pnm.cpp mplayerxp/libmpstream2/network_real_rtsp.cpp mplayerxp/libmpstream2/network_rtsp.cpp mplayerxp/libmpstream2/network_rtsp.h mplayerxp/libmpstream2/realrtsp/real.cpp mplayerxp/libmpstream2/realrtsp/real.h mplayerxp/libmpstream2/s_ftp.cpp mplayerxp/libmpstream2/s_network.cpp mplayerxp/libmpstream2/s_rtsp.cpp mplayerxp/libmpstream2/s_udp.cpp mplayerxp/libmpstream2/tcp.cpp mplayerxp/libmpstream2/tcp.h mplayerxp/libmpstream2/udp.cpp mplayerxp/libmpstream2/udp.h mplayerxp/libmpstream2/url.cpp mplayerxp/libmpstream2/url.h Modified: mplayerxp/libmpstream2/cddb.cpp =================================================================== --- mplayerxp/libmpstream2/cddb.cpp 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/cddb.cpp 2012-12-18 13:04:29 UTC (rev 572) @@ -145,16 +145,15 @@ char request[4096]; int ret = 0; Tcp tcp(cddb_data->libinput,-1); - URL *url; + URL& url=*new(zeromem) URL(""); if( reply_parser==NULL || command==NULL || cddb_data==NULL ) return -1; sprintf( request, "http://%s/~cddb/cddb.cgi?cmd=%s%s&proto=%d", cddb_data->freedb_server, command, cddb_data->cddb_hello.c_str(), cddb_data->freedb_proto_level ); MSG_V("Request[%s]\n", request ); - url = url_new(request); - if( url==NULL ) { - MSG_ERR("Not a valid URL\n"); + if(url.redirect(request)!=MPXP_Ok) { + MSG_ERR("Not valid URL: '%s'\n",request); return -1; } @@ -183,7 +182,7 @@ } delete http_hdr; - delete url; + delete &url; return ret; } Modified: mplayerxp/libmpstream2/http.cpp =================================================================== --- mplayerxp/libmpstream2/http.cpp 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/http.cpp 2012-12-18 13:04:29 UTC (rev 572) @@ -302,54 +302,32 @@ MSG_V("--- HTTP DEBUG HEADER --- END ---\n"); } -int HTTP_Header::authenticate(URL *url, int *auth_retry) { +int HTTP_Header::authenticate(URL& url, int *auth_retry) { const char *aut; - if( *auth_retry==1 ) { - MSG_ERR(MSGTR_ConnAuthFailed); - return -1; - } - if( *auth_retry>0 ) { - if( url->username ) { - delete url->username ; - url->username = NULL; - } - if( url->password ) { - delete url->password ; - url->password = NULL; - } - } + if( *auth_retry==1 ) { + MSG_ERR(MSGTR_ConnAuthFailed); + return -1; + } + if( *auth_retry>0 ) url.clear_login(); - aut = get_field("WWW-Authenticate"); - if( aut!=NULL ) { - const char *aut_space; - aut_space = strstr(aut, "realm="); - if( aut_space!=NULL ) aut_space += 6; - MSG_INFO("Authentication required for %s\n", aut_space); - } else { - MSG_INFO("Authentication required\n"); - } - if( net_conf.username ) { - url->username = mp_strdup(net_conf.username); - if( url->username==NULL ) { - MSG_FATAL(MSGTR_OutOfMemory); - return -1; - } - } else { - MSG_ERR(MSGTR_ConnAuthFailed); - return -1; - } - if( net_conf.password ) { - url->password = mp_strdup(net_conf.password); - if( url->password==NULL ) { - MSG_FATAL(MSGTR_OutOfMemory); - return -1; - } - } else { - MSG_INFO("No password provided, trying blank password\n"); - } - (*auth_retry)++; - return 0; + aut = get_field("WWW-Authenticate"); + if( aut!=NULL ) { + const char *aut_space; + aut_space = strstr(aut, "realm="); + if( aut_space!=NULL ) aut_space += 6; + MSG_INFO("Authentication required for %s\n", aut_space); + } else { + MSG_INFO("Authentication required\n"); + } + if( !net_conf.username ) { + MSG_ERR(MSGTR_ConnAuthFailed); + return -1; + } + if( !net_conf.password ) MSG_INFO("No password provided, trying blank password\n"); + url.set_login(net_conf.username,net_conf.password?net_conf.password:""); + (*auth_retry)++; + return 0; } Modified: mplayerxp/libmpstream2/http.h =================================================================== --- mplayerxp/libmpstream2/http.h 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/http.h 2012-12-18 13:04:29 UTC (rev 572) @@ -30,7 +30,7 @@ virtual void set_method(const std::string& method ); virtual void set_uri(const std::string& uri ); virtual int add_basic_authentication(const std::string& username, const std::string& password ); - virtual int authenticate(URL *url, int *auth_retry); + virtual int authenticate(URL& url, int *auth_retry); virtual void debug_hdr(); virtual void cookies_set(const std::string& hostname, const std::string& url); Modified: mplayerxp/libmpstream2/librtsp/rtsp.cpp =================================================================== --- mplayerxp/libmpstream2/librtsp/rtsp.cpp 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/librtsp/rtsp.cpp 2012-12-18 13:04:29 UTC (rev 572) @@ -70,24 +70,24 @@ struct rtsp_t { - Tcp* tcp; + Tcp* tcp; - char *host; - int port; - char *path; - char *param; - char *mrl; - char *user_agent; + const char* host; + int port; + const char* path; + const char* param; + char* mrl; + const char* user_agent; - char *server; - unsigned int server_state; - uint32_t server_caps; + const char* server; + unsigned server_state; + uint32_t server_caps; - unsigned int cseq; - char *session; + unsigned cseq; + const char* session; - char *answers[MAX_FIELDS]; /* data of last message */ - char *scheduled[MAX_FIELDS]; /* will be sent with next message */ + char* answers[MAX_FIELDS]; /* data of last message */ + char* scheduled[MAX_FIELDS]; /* will be sent with next message */ }; /* @@ -558,7 +558,7 @@ */ //rtsp_t *rtsp_connect(const char *mrl, const char *user_agent) { -rtsp_t *rtsp_connect(Tcp& tcp, char* mrl, char *path, char *host, int port, char *user_agent) { +rtsp_t *rtsp_connect(Tcp& tcp, char* mrl,const char *path,const char *host, int port,const char *user_agent) { rtsp_t *s=new rtsp_t; int i; @@ -676,7 +676,7 @@ } -char *rtsp_get_session(rtsp_t *s) { +const char *rtsp_get_session(rtsp_t *s) { return s->session; @@ -688,9 +688,9 @@ } -char *rtsp_get_param(rtsp_t *s, const char *p) { +char *rtsp_get_param(rtsp_t *s,const char *p) { int len; - char *param; + const char *param; if (!s->param) return NULL; if (!p) @@ -698,14 +698,14 @@ len = strlen(p); param = s->param; while (param && *param) { - char *nparam = strchr(param, '&'); + const char *nparam = strchr(param, '&'); if (strncmp(param, p, len) == 0 && param[len] == '=') { param += len + 1; len = nparam ? nparam - param : strlen(param); - nparam = new char [len + 1]; - memcpy(nparam, param, len); - nparam[len] = 0; - return nparam; + char* _nparam = new char [len + 1]; + memcpy(_nparam, param, len); + _nparam[len] = 0; + return _nparam; } param = nparam ? nparam + 1 : NULL; } Modified: mplayerxp/libmpstream2/librtsp/rtsp.h =================================================================== --- mplayerxp/libmpstream2/librtsp/rtsp.h 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/librtsp/rtsp.h 2012-12-18 13:04:29 UTC (rev 572) @@ -47,7 +47,7 @@ struct rtsp_t; -rtsp_t* rtsp_connect (Tcp& tcp, char *mrl, char *path, char *host, int port, char *user_agent); +rtsp_t* rtsp_connect (Tcp& tcp, char *mrl, const char *path, const char *host, int port, const char *user_agent); int rtsp_request_options(rtsp_t *s, const char *what); int rtsp_request_describe(rtsp_t *s, const char *what); @@ -69,10 +69,10 @@ void rtsp_close (rtsp_t *self); void rtsp_set_session(rtsp_t *s, const char *id); -char *rtsp_get_session(rtsp_t *s); +const char *rtsp_get_session(rtsp_t *s); char *rtsp_get_mrl(rtsp_t *s); -char *rtsp_get_param(rtsp_t *s, const char *param); +char *rtsp_get_param(rtsp_t *s,const char *param); /*int rtsp_peek_header (rtsp_t *self, char *data); */ Modified: mplayerxp/libmpstream2/librtsp/rtsp_session.cpp =================================================================== --- mplayerxp/libmpstream2/librtsp/rtsp_session.cpp 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/librtsp/rtsp_session.cpp 2012-12-18 13:04:29 UTC (rev 572) @@ -73,8 +73,10 @@ #define RTSP_SERVER_TYPE_UNKNOWN "unknown" //Rtsp_Session *rtsp_session_start(char *mrl) { -Rtsp_Session *rtsp_session_start(Tcp& tcp, char **mrl, char *path, char *host, - int port, int *redir, uint32_t bandwidth, char *user, char *pass) { +Rtsp_Session *rtsp_session_start(Tcp& tcp, char **mrl, const std::string& path, + const std::string& host, + int port, int *redir, uint32_t bandwidth, + const std::string& user, const std::string& pass) { Rtsp_Session *rtsp_session = NULL; char *server; @@ -90,10 +92,10 @@ *redir = 0; /* connect to server */ - rtsp_session->s=rtsp_connect(tcp,*mrl,path,host,port,NULL); + rtsp_session->s=rtsp_connect(tcp,*mrl,path.c_str(),host.c_str(),port,NULL); if (!rtsp_session->s) { - MSG_ERR("rtsp_session: failed to connect to server %s\n", path); + MSG_ERR("rtsp_session: failed to connect to server %s\n", path.c_str()); delete rtsp_session; return NULL; } @@ -111,7 +113,7 @@ { /* we are talking to a real server ... */ - h=real_setup_and_get_header(rtsp_session->s, bandwidth, user, pass); + h=real_setup_and_get_header(rtsp_session->s, bandwidth, user.c_str(), pass.c_str()); if (!h) { /* got an redirect? */ if (rtsp_search_answers(rtsp_session->s, RTSP_OPTIONS_LOCATION)) Modified: mplayerxp/libmpstream2/librtsp/rtsp_session.h =================================================================== --- mplayerxp/libmpstream2/librtsp/rtsp_session.h 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/librtsp/rtsp_session.h 2012-12-18 13:04:29 UTC (rev 572) @@ -51,7 +51,7 @@ rtp_rtsp_session_t* rtp_session; }; - Rtsp_Session* rtsp_session_start(Tcp& tcp, char **mrl, char *path, char *host, - int port, int *redir, uint32_t bandwidth, char *user, char *pass); + Rtsp_Session* rtsp_session_start(Tcp& tcp, char **mrl, const std::string& path, const std::string& host, + int port, int *redir, uint32_t bandwidth, const std::string& user, const std::string& pass); } // namespace mpxp #endif Modified: mplayerxp/libmpstream2/network.cpp =================================================================== --- mplayerxp/libmpstream2/network.cpp 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/network.cpp 2012-12-18 13:04:29 UTC (rev 572) @@ -62,131 +62,72 @@ net_config_t::~net_config_t() {} net_config_t net_conf; -URL* -check4proxies( URL *url ) { - URL *url_out = NULL; - if( url==NULL ) return NULL; - url_out = url_new( url->url ); - if( !strcasecmp(url->protocol, "http_proxy") ) { - MSG_V("Using HTTP proxy: http://%s:%d\n", url->hostname, url->port ); - return url_out; - } - // Check if the http_proxy environment variable is set. - if( !strcasecmp(url->protocol, "http") ) { - char *proxy; - proxy = getenv("http_proxy"); - if( proxy!=NULL ) { - // We got a proxy, build the URL to use it - int len; - char *new_url; - URL *tmp_url; - URL *proxy_url = url_new( proxy ); +MPXP_Rc http_send_request(Tcp& tcp, URL& url, off_t pos ) { + HTTP_Header& http_hdr = *new(zeromem) HTTP_Header; + URL server_url(""); + char str[256]; + int ret; + int proxy = 0; // Boolean - if( proxy_url==NULL ) { - MSG_WARN("Invalid proxy setting...Trying without proxy.\n"); - return url_out; - } - -#ifdef HAVE_AF_INET6 - if (net_conf.ipv4_only_proxy && (gethostbyname(url->hostname)==NULL)) { - MSG_WARN( - "Could not find resolve remote hostname for AF_INET. Trying without proxy.\n"); - return url_out; - } -#endif - - MSG_V("Using HTTP proxy: %s\n", proxy_url->url ); - len = strlen( proxy_url->hostname ) + strlen( url->url ) + 20; // 20 = http_proxy:// + port - new_url = new char [len+1]; - if( new_url==NULL ) { - MSG_FATAL(MSGTR_OutOfMemory); - return url_out; - } - sprintf(new_url, "http_proxy://%s:%d/%s", proxy_url->hostname, proxy_url->port, url->url ); - tmp_url = url_new( new_url ); - if( tmp_url==NULL ) { - return url_out; - } - delete url_out; - url_out = tmp_url; - delete new_url ; - delete proxy_url; - } - } - return url_out; -} - -MPXP_Rc http_send_request(Tcp& tcp, URL *url, off_t pos ) { - HTTP_Header& http_hdr = *new(zeromem) HTTP_Header; - URL *server_url; - char str[256]; - int ret; - int proxy = 0; // Boolean - - if( !strcasecmp(url->protocol, "http_proxy") ) { - proxy = 1; - server_url = url_new( (url->file)+1 ); - http_hdr.set_uri(server_url->url ); - } else { - server_url = url; - http_hdr.set_uri( server_url->file ); - } - if (server_url->port && server_url->port != 80) - snprintf(str, 256, "Host: %s:%d", server_url->hostname, server_url->port ); - else - snprintf(str, 256, "Host: %s", server_url->hostname ); + if( url.protocol2lower()=="http_proxy") { + proxy = 1; + server_url.redirect(url.file()); + http_hdr.set_uri(server_url.url()); + } else { + server_url = url; + http_hdr.set_uri( server_url.file()); + } + if (server_url.port() && server_url.port() != 80) + snprintf(str, 256, "Host: %s:%d", server_url.host().c_str(), server_url.port()); + else + snprintf(str, 256, "Host: %s", server_url.host().c_str()); + http_hdr.set_field(str); + if (net_conf.useragent) { + snprintf(str, 256, "User-Agent: %s", net_conf.useragent); http_hdr.set_field(str); - if (net_conf.useragent) - { - snprintf(str, 256, "User-Agent: %s", net_conf.useragent); - http_hdr.set_field(str); - } - else - http_hdr.set_field("User-Agent: MPlayerXP/"VERSION); + } + else + http_hdr.set_field("User-Agent: MPlayerXP/"VERSION); - http_hdr.set_field("Icy-MetaData: 1"); + http_hdr.set_field("Icy-MetaData: 1"); - if(pos>0) { + if(pos>0) { // Extend http_send_request with possibility to do partial content retrieval - snprintf(str, 256, "Range: bytes=%d-", (int)pos); - http_hdr.set_field(str); - } + snprintf(str, 256, "Range: bytes=%d-", (int)pos); + http_hdr.set_field(str); + } - if (net_conf.cookies_enabled) http_hdr.cookies_set( server_url->hostname, server_url->url ); + if (net_conf.cookies_enabled) http_hdr.cookies_set( server_url.host(), server_url.url()); - http_hdr.set_field( "Connection: closed"); - http_hdr.add_basic_authentication( url->username?url->username:"", url->password?url->password:""); - if( http_hdr.build_request( )==NULL ) { - goto err_out; - } + http_hdr.set_field( "Connection: closed"); + http_hdr.add_basic_authentication( url.user(), url.password()); + if( http_hdr.build_request( )==NULL ) { + goto err_out; + } - if( proxy ) { - if( url->port==0 ) url->port = 8080; // Default port for the proxy server - tcp.close(); - tcp.open(url->hostname, url->port, Tcp::IP4); - delete server_url; - server_url = NULL; - } else { - if( server_url->port==0 ) server_url->port = 80; // Default port for the web server - tcp.close(); - tcp.open(server_url->hostname, server_url->port, Tcp::IP4); - } - if(!tcp.established()) { MSG_ERR("Cannot establish connection\n"); goto err_out; } - MSG_DBG2("Request: [%s]\n", http_hdr.get_buffer() ); + if( proxy ) { + tcp.close(); + url.assign_port(8080); + tcp.open(url, Tcp::IP4); + } else { + tcp.close(); + server_url.assign_port(80); + tcp.open(server_url, Tcp::IP4); + } + if(!tcp.established()) { MSG_ERR("Cannot establish connection\n"); goto err_out; } + MSG_DBG2("Request: [%s]\n", http_hdr.get_buffer() ); - ret = tcp.write((uint8_t*)(http_hdr.get_buffer()), http_hdr.get_buffer_size()); - if( ret!=(int)http_hdr.get_buffer_size() ) { - MSG_ERR("Error while sending HTTP request: didn't sent all the request\n"); - goto err_out; - } + ret = tcp.write((uint8_t*)(http_hdr.get_buffer()), http_hdr.get_buffer_size()); + if( ret!=(int)http_hdr.get_buffer_size() ) { + MSG_ERR("Error while sending HTTP request: didn't sent all the request\n"); + goto err_out; + } - delete &http_hdr; - - return MPXP_Ok; + delete &http_hdr; + return MPXP_Ok; err_out: - delete &http_hdr; - if (proxy && server_url) delete server_url; - return MPXP_False; + delete &http_hdr; + return MPXP_False; } HTTP_Header* http_read_response( Tcp& tcp ) { @@ -247,10 +188,10 @@ } Networking::Networking() - :mime("application/octet-stream") {} + :mime("application/octet-stream"), + url("") {} Networking::~Networking() { - if( url ) delete url; if( buffer ) delete buffer; if( data ) delete data; } @@ -266,7 +207,7 @@ const char *content_type; const char *next_url; - URL *url = networking.url; + URL& url = networking.url; do { next_url = NULL; @@ -274,16 +215,12 @@ content_type = NULL; redirect = 0; - if( url==NULL ) { - goto err_out; - } - #ifndef STREAMING_LIVE_DOT_COM // Old, hacked RTP support, which works for MPEG Program Streams // RTP streams only: // Checking for RTP - if( !strcasecmp(url->protocol, "rtp") ) { - if( url->port==0 ) { + if( url.protocol2lower()=="rtp") { + if( url.port()==0 ) { MSG_ERR("You must enter a port number for RTP streams!\n"); goto err_out; } @@ -291,7 +228,7 @@ } #endif // HTTP based protocol - if( !strcasecmp(url->protocol, "http") || !strcasecmp(url->protocol, "http_proxy") ) { + if( url.protocol2lower()=="http" || url.protocol2lower()=="http_proxy") { http_send_request(tcp, url, 0 ); if(!tcp.established()) goto err_out; @@ -366,10 +303,10 @@ // TODO: RFC 2616, recommand to detect infinite redirection loops next_url = http_hdr->get_field("Location" ); if( next_url!=NULL ) { - networking.url = url = url_redirect( &url, next_url ); - if (!strcasecmp(url->protocol, "mms")) goto err_out; - if (strcasecmp(url->protocol, "http")) { - MSG_WARN("Unsupported http %d redirect to %s protocol\n", http_hdr->get_status(), url->protocol); + url.redirect(next_url); + if (url.protocol2lower()=="mms") goto err_out; + if (url.protocol2lower()=="http") { + MSG_WARN("Unsupported http %d redirect to %s protocol\n", http_hdr->get_status(), url.protocol().c_str()); goto err_out; } redirect = 1; @@ -384,7 +321,7 @@ goto err_out; } } else { - MSG_ERR("Unknown protocol '%s'\n", url->protocol ); + MSG_ERR("Unknown protocol '%s'\n", url.protocol().c_str()); goto err_out; } } while( redirect ); @@ -418,29 +355,28 @@ } } -Networking* Networking::start(Tcp& tcp, URL *_url) { +Networking* Networking::start(Tcp& tcp, const URL& _url) { Networking* rc; network_protocol_t net_protocol; - URL* url = check4proxies( _url ); + net_protocol.url=_url; + net_protocol.url.check4proxies(); - net_protocol.url=url; - if( autodetectProtocol(net_protocol,tcp)!=MPXP_Ok ) return NULL; rc = NULL; - url=net_protocol.url; + URL url=net_protocol.url; // For RTP streams, we usually don't know the stream type until we open it. - if( !strcasecmp( url->protocol, "rtp")) { + if( url.protocol2lower()=="rtp") { if(tcp.established()) tcp.close(); rc = Rtp_Networking::start(tcp, net_protocol, 0); - } else if( !strcasecmp( url->protocol, "pnm")) { + } else if( url.protocol2lower()=="pnm") { tcp.close(); rc = Pnm_Networking::start(tcp, net_protocol); if (!rc) { MSG_INFO("Can't connect with pnm, retrying with http.\n"); return NULL; } - } else if( !strcasecmp( url->protocol, "rtsp")) { + } else if( url.protocol2lower()=="rtsp") { if ((rc = RealRtsp_Networking::start( tcp, net_protocol )) == NULL) { MSG_INFO("Not a Realmedia rtsp url. Trying standard rtsp protocol.\n"); #ifdef STREAMING_LIVE_DOT_COM @@ -452,16 +388,16 @@ return NULL; #endif } - } else if(!strcasecmp( url->protocol, "udp")) { + } else if(url.protocol2lower()=="udp") { tcp.close(); rc = Rtp_Networking::start(tcp, net_protocol, 1); if(!rc) { MSG_ERR("rtp_networking_start(udp) failed\n"); return NULL; } - } else if(!strncasecmp(url->protocol, "mms", 3) || - !strncasecmp(url->protocol, "mmst", 4) || - !strncasecmp(url->protocol, "mmsu", 4)) { + } else if(url.protocol2lower()=="mms" || + url.protocol2lower()=="mmst" || + url.protocol2lower()=="mmsu") { rc=Asf_Mmst_Networking::start(tcp,net_protocol); if(!rc) { MSG_ERR("asf_mmst_networking_start() failed\n"); @@ -477,7 +413,7 @@ if( !rc ) { //sometimes a file is just on a webserver and it is not streamed. //try loading them default method as last resort for http protocol - if ( !strcasecmp(url->protocol, "http") ) { + if (url.protocol2lower()=="http") { MSG_STATUS("Trying default networking for http protocol\n "); //reset stream tcp.close(); Modified: mplayerxp/libmpstream2/network.h =================================================================== --- mplayerxp/libmpstream2/network.h 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/network.h 2012-12-18 13:04:29 UTC (rev 572) @@ -57,16 +57,16 @@ }; struct network_protocol_t { - URL* url; - Opaque* data; + URL url; std::string mime; + Opaque* data; }; struct Networking : public Opaque { public: virtual ~Networking(); - static Networking* start(Tcp& tcp, URL *url); + static Networking* start(Tcp& tcp,const URL& url); virtual int stop(); virtual void fixup_cache(); virtual int bufferize(unsigned char *buffer, int size); @@ -75,7 +75,7 @@ virtual int seek( Tcp& fd, off_t pos) = 0; std::string mime; - URL* url; + URL url; networking_status status; unsigned int bandwidth; // The downstream available protected: @@ -90,9 +90,7 @@ static MPXP_Rc autodetectProtocol(network_protocol_t& protocol,Tcp& tcp); }; - extern URL* check4proxies( URL* url ); - - MPXP_Rc http_send_request(Tcp& tcp,URL* url, off_t pos); + MPXP_Rc http_send_request(Tcp& tcp,URL& url, off_t pos); HTTP_Header* http_read_response(Tcp& fd); /* Modified: mplayerxp/libmpstream2/network_asf.cpp =================================================================== --- mplayerxp/libmpstream2/network_asf.cpp 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/network_asf.cpp 2012-12-18 13:04:29 UTC (rev 572) @@ -1,6 +1,7 @@ #include "mp_config.h" #include "osdep/mplib.h" using namespace mpxp; +#include <algorithm> #include <limits> #include <stdio.h> @@ -152,7 +153,7 @@ return MPXP_False; } // audit: do not overflow buffer_size - if (size > std::numeric_limits<size_t>::max() - _buffer_size) return MPXP_False; + if (unsigned(size) > std::numeric_limits<size_t>::max() - _buffer_size) return MPXP_False; _buffer = (char*) mp_malloc(size+_buffer_size); if(_buffer == NULL) { MSG_FATAL("Error can't allocate %d bytes buffer\n",size+_buffer_size); @@ -436,219 +437,201 @@ static ASF_StreamType_e asf_http_networking_type(const char *content_type,const char *features, HTTP_Header& http_hdr ) { - if( content_type==NULL ) return ASF_Unknown_e; - if( !strcasecmp(content_type, "application/octet-stream") || - !strcasecmp(content_type, "application/vnd.ms.wms-hdr.asfv1") || // New in Corona, first request - !strcasecmp(content_type, "application/x-mms-framed") || // New in Corana, second request - !strcasecmp(content_type, "video/x-ms-asf")) { + if(content_type==NULL ) return ASF_Unknown_e; + if(!strcasecmp(content_type, "application/octet-stream") || + !strcasecmp(content_type, "application/vnd.ms.wms-hdr.asfv1") || // New in Corona, first request + !strcasecmp(content_type, "application/x-mms-framed") || // New in Corana, second request + !strcasecmp(content_type, "video/x-ms-asf")) { - if( strstr(features, "broadcast") ) { - MSG_V("=====> ASF Live stream\n"); - return ASF_Live_e; - } else { - MSG_V("=====> ASF Prerecorded\n"); - return ASF_Prerecorded_e; - } + if( strstr(features, "broadcast") ) { + MSG_V("=====> ASF Live stream\n"); + return ASF_Live_e; } else { - // Ok in a perfect world, web servers should be well configured - // so we could used mime type to know the stream type, - // but guess what? All of them are not well configured. - // So we have to check for an asf header :(, but it works :p - if( http_hdr.get_body_size()>sizeof(ASF_obj_header_t) ) { - if( asf_header_check( http_hdr )==0 ) { - MSG_V("=====> ASF Plain text\n"); - return ASF_PlainText_e; - } else if( (!strcasecmp(content_type, "text/html")) ) { - MSG_V("=====> HTML, mplayer is not a browser...yet!\n"); - return ASF_Unknown_e; - } else { - MSG_V("=====> ASF Redirector\n"); - return ASF_Redirector_e; - } - } else { - if( (!strcasecmp(content_type, "audio/x-ms-wax")) || - (!strcasecmp(content_type, "audio/x-ms-wma")) || - (!strcasecmp(content_type, "video/x-ms-asf")) || - (!strcasecmp(content_type, "video/x-ms-afs")) || - (!strcasecmp(content_type, "video/x-ms-wvx")) || - (!strcasecmp(content_type, "video/x-ms-wmv")) || - (!strcasecmp(content_type, "video/x-ms-wma")) ) { - MSG_ERR("=====> ASF Redirector\n"); - return ASF_Redirector_e; - } else if( !strcasecmp(content_type, "text/plain") ) { - MSG_V("=====> ASF Plain text\n"); - return ASF_PlainText_e; - } else { - MSG_V("=====> ASF unknown content-type: %s\n", content_type ); - return ASF_Unknown_e; - } - } + MSG_V("=====> ASF Prerecorded\n"); + return ASF_Prerecorded_e; } - return ASF_Unknown_e; + } else { + // Ok in a perfect world, web servers should be well configured + // so we could used mime type to know the stream type, + // but guess what? All of them are not well configured. + // So we have to check for an asf header :(, but it works :p + if( http_hdr.get_body_size()>sizeof(ASF_obj_header_t) ) { + if( asf_header_check( http_hdr )==0 ) { + MSG_V("=====> ASF Plain text\n"); + return ASF_PlainText_e; + } else if( (!strcasecmp(content_type, "text/html")) ) { + MSG_V("=====> HTML, mplayer is not a browser...yet!\n"); + return ASF_Unknown_e; + } else { + MSG_V("=====> ASF Redirector\n"); + return ASF_Redirector_e; + } + } else { + if((!strcasecmp(content_type, "audio/x-ms-wax")) || + (!strcasecmp(content_type, "audio/x-ms-wma")) || + (!strcasecmp(content_type, "video/x-ms-asf")) || + (!strcasecmp(content_type, "video/x-ms-afs")) || + (!strcasecmp(content_type, "video/x-ms-wvx")) || + (!strcasecmp(content_type, "video/x-ms-wmv")) || + (!strcasecmp(content_type, "video/x-ms-wma")) ) { + MSG_ERR("=====> ASF Redirector\n"); + return ASF_Redirector_e; + } else if( !strcasecmp(content_type, "text/plain") ) { + MSG_V("=====> ASF Plain text\n"); + return ASF_PlainText_e; + } else { + MSG_V("=====> ASF unknown content-type: %s\n", content_type ); + return ASF_Unknown_e; + } + } + } + return ASF_Unknown_e; } HTTP_Header* Asf_Networking::http_request() const { - HTTP_Header* http_hdr = new(zeromem) HTTP_Header; + HTTP_Header* http_hdr = new(zeromem) HTTP_Header; // URL *url = NULL; - URL *server_url = NULL; - char str[250]; - char *ptr; - int i, enable; + URL server_url; + char str[250]; + char *ptr; + int i, enable; - int offset_hi=0, offset_lo=0, length=0; - int asf_nb_stream=0, stream_id; + int offset_hi=0, offset_lo=0, length=0; + int asf_nb_stream=0, stream_id; - // Sanity check - if( url==NULL ) return NULL; + // Common header for all requests. + http_hdr->set_field("Accept: */*" ); + http_hdr->set_field("User-Agent: NSPlayer/4.1.0.3856" ); + http_hdr->add_basic_authentication(url.user(), url.password()); - // Common header for all requests. - http_hdr->set_field("Accept: */*" ); - http_hdr->set_field("User-Agent: NSPlayer/4.1.0.3856" ); - http_hdr->add_basic_authentication(url->username?url->username:"", url->password?url->password:"" ); + // Check if we are using a proxy + if( url.protocol2lower()=="http_proxy") { + server_url.redirect(url.file()); + http_hdr->set_uri(server_url.url()); + sprintf( str, "Host: %.220s:%d", server_url.host().c_str(), server_url.port()); + } else { + http_hdr->set_uri(url.file()); + sprintf( str, "Host: %.220s:%d", url.host().c_str(), url.port()); + } - // Check if we are using a proxy - if( !strcasecmp( url->protocol, "http_proxy" ) ) { - server_url = url_new( (url->file)+1 ); - if( server_url==NULL ) { - MSG_ERR("Invalid proxy URL\n"); - delete http_hdr; - return NULL; - } - http_hdr->set_uri(server_url->url ); - sprintf( str, "Host: %.220s:%d", server_url->hostname, server_url->port ); - delete server_url; - } else { - http_hdr->set_uri(url->file ); - sprintf( str, "Host: %.220s:%d", url->hostname, url->port ); - } - - http_hdr->set_field(str ); - http_hdr->set_field("Pragma: xClientGUID={c77e7400-738a-11d2-9add-0020af0a3278}" ); - sprintf(str, - "Pragma: no-cache,rate=1.000000,stream-time=0,stream-offset=%u:%u,request-context=%d,max-duration=%u", + http_hdr->set_field(str ); + http_hdr->set_field("Pragma: xClientGUID={c77e7400-738a-11d2-9add-0020af0a3278}" ); + sprintf(str,"Pragma: no-cache,rate=1.000000,stream-time=0,stream-offset=%u:%u,request-context=%d,max-duration=%u", offset_hi, offset_lo, request, length ); - http_hdr->set_field( str ); + http_hdr->set_field( str ); - switch( networking_type ) { - case ASF_Live_e: - case ASF_Prerecorded_e: - http_hdr->set_field("Pragma: xPlayStrm=1" ); - ptr = str; - ptr += sprintf( ptr, "Pragma: stream-switch-entry="); - if(n_audio > 0) { - for( i=0; i<n_audio ; i++ ) { - stream_id = audio_streams[i]; - if(stream_id == audio_id) { - enable = 0; - } else { - enable = 2; - continue; - } - asf_nb_stream++; - ptr += sprintf(ptr, "ffff:%d:%d ", stream_id, enable); - } - } - if(n_video > 0) { - for( i=0; i<n_video ; i++ ) { - stream_id = video_streams[i]; - if(stream_id == video_id) { - enable = 0; - } else { - enable = 2; - continue; - } - asf_nb_stream++; - ptr += sprintf(ptr, "ffff:%d:%d ", stream_id, enable); - } - } - http_hdr->set_field(str ); - sprintf( str, "Pragma: stream-switch-count=%d", asf_nb_stream ); - http_hdr->set_field( str ); - break; - case ASF_Redirector_e: - break; - case ASF_Unknown_e: - // First request goes here. - break; - default: - MSG_ERR("Unknown asf stream type\n"); - } + switch( networking_type ) { + case ASF_Live_e: + case ASF_Prerecorded_e: + http_hdr->set_field("Pragma: xPlayStrm=1" ); + ptr = str; + ptr += sprintf( ptr, "Pragma: stream-switch-entry="); + if(n_audio > 0) { + for( i=0; i<n_audio ; i++ ) { + stream_id = audio_streams[i]; + if(stream_id == audio_id) enable = 0; + else { + enable = 2; + continue; + } + asf_nb_stream++; + ptr += sprintf(ptr, "ffff:%d:%d ", stream_id, enable); + } + } + if(n_video > 0) { + for( i=0; i<n_video ; i++ ) { + stream_id = video_streams[i]; + if(stream_id == video_id) enable = 0; + else { + enable = 2; + continue; + } + asf_nb_stream++; + ptr += sprintf(ptr, "ffff:%d:%d ", stream_id, enable); + } + } + http_hdr->set_field(str ); + sprintf( str, "Pragma: stream-switch-count=%d", asf_nb_stream ); + http_hdr->set_field( str ); + break; + case ASF_Redirector_e: break; + case ASF_Unknown_e: // First request goes here. + break; + default: + MSG_ERR("Unknown asf stream type\n"); + } - http_hdr->set_field("Connection: Close" ); - http_hdr->build_request( ); + http_hdr->set_field("Connection: Close" ); + http_hdr->build_request( ); - return http_hdr; + return http_hdr; } int Asf_Networking::parse_response(HTTP_Header& http_hdr ) { - const char *content_type, *pragma; - char features[64] = "\0"; - size_t len; - if( http_hdr.response_parse()<0 ) { - MSG_ERR("Failed to parse HTTP response\n"); - return -1; - } - switch( http_hdr.get_status()) { - case 200: - break; - case 401: // Authentication required - return ASF_Authenticate_e; - default: - MSG_ERR("Server return %d:%s\n", http_hdr.get_status(), http_hdr.get_reason_phrase()); - return -1; - } + const char *content_type, *pragma; + char features[64] = "\0"; + size_t len; + if( http_hdr.response_parse()<0 ) { + MSG_ERR("Failed to parse HTTP response\n"); + return -1; + } + switch( http_hdr.get_status()) { + case 200: + break; + case 401: // Authentication required + return ASF_Authenticate_e; + default: + MSG_ERR("Server return %d:%s\n", http_hdr.get_status(), http_hdr.get_reason_phrase()); + return -1; + } - content_type = http_hdr.get_field("Content-Type"); + content_type = http_hdr.get_field("Content-Type"); - pragma = http_hdr.get_field("Pragma"); - while( pragma!=NULL ) { - const char *comma_ptr=NULL; - const char *end; - // The pragma line can get severals attributes - // separeted with a comma ','. - do { - if( !strncasecmp( pragma, "features=", 9) ) { - pragma += 9; - end = strstr( pragma, "," ); - if( end==NULL ) { - size_t s = strlen(pragma); - if(s > sizeof(features)) { - MSG_WARN("ASF HTTP PARSE WARNING : Pragma %s cuted from %d bytes to %d\n",pragma,s,sizeof(features)); - len = sizeof(features); - } else { - len = s; - } - } else { - len = MIN((unsigned int)(end-pragma),sizeof(features)); - } - strncpy( features, pragma, len ); - features[len]='\0'; - break; - } - comma_ptr = strstr( pragma, "," ); - if( comma_ptr!=NULL ) { - pragma = comma_ptr+1; - if( pragma[0]==' ' ) pragma++; - } - } while( comma_ptr!=NULL ); - pragma = http_hdr.get_next_field(); - } - networking_type = asf_http_networking_type( content_type, features, http_hdr ); - return 0; + pragma = http_hdr.get_field("Pragma"); + while( pragma!=NULL ) { + const char *comma_ptr=NULL; + const char *end; + // The pragma line can get severals attributes + // separeted with a comma ','. + do { + if( !strncasecmp( pragma, "features=", 9) ) { + pragma += 9; + end = strstr( pragma, "," ); + if( end==NULL ) { + size_t s = strlen(pragma); + if(s > sizeof(features)) { + MSG_WARN("ASF HTTP PARSE WARNING : Pragma %s cuted from %d bytes to %d\n",pragma,s,sizeof(features)); + len = sizeof(features); + } else len = s; + } else len = std::min((unsigned long)(end-pragma),sizeof(features)); + strncpy( features, pragma, len ); + features[len]='\0'; + break; + } + comma_ptr = strstr( pragma, "," ); + if( comma_ptr!=NULL ) { + pragma = comma_ptr+1; + if( pragma[0]==' ' ) pragma++; + } + } while( comma_ptr!=NULL ); + pragma = http_hdr.get_next_field(); + } + networking_type = asf_http_networking_type( content_type, features, http_hdr ); + return 0; } Networking* Asf_Networking::start(Tcp& tcp, network_protocol_t& protocol) { HTTP_Header *http_hdr=NULL; - URL *url = protocol.url; + URL& url = protocol.url; uint8_t buffer[BUFFER_SIZE]; int i, ret; int done; int auth_retry = 0; - const char *proto = protocol.url->protocol; + const char *proto = protocol.url.protocol().c_str(); // sanity check - if (!(!strncasecmp(proto, "http_proxy", 10) || - !strncasecmp(proto, "http", 4))) { + if (!(protocol.url.protocol2lower()=="http_proxy" || + protocol.url.protocol2lower()=="http")) { MSG_ERR("Unknown protocol: %s\n", proto ); return NULL; } @@ -668,12 +651,9 @@ done = 1; tcp.close(); - if( !strcasecmp( url->protocol, "http_proxy" ) ) { - if( url->port==0 ) url->port = 8080; - } else { - if( url->port==0 ) url->port = 80; - } - tcp.open(url->hostname, url->port, Tcp::IP4); + if( url.protocol2lower()=="http_proxy") url.assign_port(8080); + else url.assign_port(80); + tcp.open(url, Tcp::IP4); if( !tcp.established()) { delete rv; return NULL; @@ -778,7 +758,6 @@ return Nop_Networking::start(tcp,protocol); } else rv->buffering = 1; rv->status = networking_playing_e; - rv->url->port=protocol.url->port; delete http_hdr; return rv; Modified: mplayerxp/libmpstream2/network_asf_mmst.cpp =================================================================== --- mplayerxp/libmpstream2/network_asf_mmst.cpp 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/network_asf_mmst.cpp 2012-12-18 13:04:29 UTC (rev 572) @@ -362,7 +362,7 @@ int Asf_Mmst_Networking::get_media_packet (Tcp& tcp, int padding) { unsigned char pre_header[8]; - unsigned char data[BUF_SIZE]; + unsigned char _data[BUF_SIZE]; if (!get_data (tcp, pre_header, 8)) { MSG_ERR ("pre-header read failed\n"); @@ -386,12 +386,12 @@ return 0; } - if (!get_data (tcp, data, packet_len)) { + if (!get_data (tcp, _data, packet_len)) { MSG_ERR ("media data read failed\n"); return 0; } - bufferize(data, padding); + bufferize(_data, padding); } else { @@ -410,7 +410,7 @@ return 0; } - if (!get_data (tcp, data, packet_len)) { + if (!get_data (tcp, _data, packet_len)) { MSG_ERR ("command data read failed\n"); return 0; } @@ -422,12 +422,12 @@ return -1; } - command = get_32 (data, 24) & 0xFFFF; + command = get_32 (_data, 24) & 0xFFFF; // printf ("\ncommand packet detected, len=%d cmd=0x%X\n", packet_len, command); if (command == 0x1b) - send_command (tcp, 0x1b, 0, 0, 0, data); + send_command (tcp, 0x1b, 0, 0, 0, _data); else if (command == 0x1e) { MSG_OK ("everything done. Thank you for downloading a media file containing proprietary and patentend technology.\n"); return 0; @@ -490,19 +490,20 @@ uint8_t asf_header[HDR_BUF_SIZE]; int asf_header_len; int len, i, packet_length; - char* path, *unescpath; - URL* url1 = protocol.url; - const char *proto = protocol.url->protocol; + const char* path; + char* unescpath; + URL url1 = protocol.url; // Is protocol even valid mms,mmsu,mmst,http,http_proxy? - if (!(!strncasecmp(proto, "mmst", 4) || !strncasecmp(proto, "mmsu", 4) || - !strncasecmp(proto, "mms", 3))) { - MSG_ERR("Unknown protocol: %s\n", proto ); + if (!(protocol.url.protocol2lower()=="mmst" || + protocol.url.protocol2lower()=="mmsu" || + protocol.url.protocol2lower()=="mms")) { + MSG_ERR("Unknown protocol: %s\n", protocol.url.protocol().c_str() ); return NULL; } // Is protocol mms or mmsu? - if (!strncasecmp(proto, "mmsu", 4) || !strncasecmp(proto, "mms", 3)) { + if (protocol.url.protocol2lower()=="mmsu" || protocol.url.protocol2lower()=="mms") { MSG_V("Trying ASF/UDP...\n"); //fd = asf_mmsu_networking_start( stream ); //mmsu support is not implemented yet - using this code @@ -513,7 +514,7 @@ tcp.close(); /* parse url */ - path = strchr(url1->file,'/') + 1; + path = strchr(url1.file().c_str(),'/') + 1; /* mmst filename are not url_escaped by MS MediaPlayer and are expected as * "plain text" by the server, so need to decode it here @@ -526,8 +527,8 @@ url2string(unescpath,path); path=unescpath; - if( url1->port==0 ) url1->port=1755; - tcp.open(url1->hostname, url1->port, Tcp::IP4); + url1.assign_port(1755); + tcp.open(url1, Tcp::IP4); if( !tcp.established()) { delete path; return NULL; @@ -551,7 +552,7 @@ #endif #endif - snprintf (str, 1023, "\034\003NSPlayer/7.0.0.1956; {33715801-BAB3-9D85-24E9-03B90328270A}; Host: %s", url1->hostname); + snprintf (str, 1023, "\034\003NSPlayer/7.0.0.1956; {33715801-BAB3-9D85-24E9-03B90328270A}; Host: %s", url1.host().c_str()); string_utf16 (data, str, strlen(str)); // send_command(s, commandno ....) send_command (tcp, 1, 0, 0x0004000b, strlen(str) * 2+2, data); @@ -649,7 +650,6 @@ rv->buffering = 1; rv->status = networking_playing_e; - rv->url->port=protocol.url->port; packet_length1 = packet_length; MSG_V("mmst packet_length = %d\n",packet_length); Modified: mplayerxp/libmpstream2/network_nop.cpp =================================================================== --- mplayerxp/libmpstream2/network_nop.cpp 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/network_nop.cpp 2012-12-18 13:04:29 UTC (rev 572) @@ -50,7 +50,7 @@ Networking* Nop_Networking::start(Tcp& tcp,network_protocol_t& protocol) { HTTP_Header *http_hdr = NULL; const char *next_url=NULL; - URL *rd_url=NULL; + URL& rd_url=protocol.url; Nop_Networking* rv = new(zeromem) Nop_Networking; if( !tcp.established() ) { @@ -82,12 +82,9 @@ case 302: // Temporarily next_url = http_hdr->get_field("Location" ); - if (next_url != NULL) - rd_url=url_new(next_url); - - if (next_url != NULL && rd_url != NULL) { + if (next_url != NULL && rd_url.redirect(next_url)==MPXP_Ok) { MSG_STATUS("Redirected: Using this url instead %s\n",next_url); - protocol.url=check4proxies(rd_url); + rd_url.check4proxies(); delete rv; rv=static_cast<Nop_Networking*>(Nop_Networking::start(tcp,protocol)); //recursively get networking started } else { Modified: mplayerxp/libmpstream2/network_pnm.cpp =================================================================== --- mplayerxp/libmpstream2/network_pnm.cpp 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/network_pnm.cpp 2012-12-18 13:04:29 UTC (rev 572) @@ -22,11 +22,11 @@ Networking* Pnm_Networking::start(Tcp& tcp,network_protocol_t& protocol ) { Pnm* pnm = new(zeromem) Pnm(tcp); - tcp.open(protocol.url->hostname, - protocol.url->port ? protocol.url->port : 7070); + protocol.url.assign_port(7070); + tcp.open(protocol.url); if(!tcp.established()) return NULL; - if(pnm->connect(protocol.url->file)!=MPXP_Ok) { + if(pnm->connect(protocol.url.file())!=MPXP_Ok) { delete pnm; return NULL; } Modified: mplayerxp/libmpstream2/network_real_rtsp.cpp =================================================================== --- mplayerxp/libmpstream2/network_real_rtsp.cpp 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/network_real_rtsp.cpp 2012-12-18 13:04:29 UTC (rev 572) @@ -21,33 +21,33 @@ Networking* RealRtsp_Networking::start( Tcp& tcp, network_protocol_t& protocol ) { Rtsp_Session* rtsp; char *mrl; - char *file; - int port; + const char *file; int redirected, temp; temp = 5; // counter so we don't get caught in infinite redirections (you never know) do { redirected = 0; - port = protocol.url->port ? protocol.url->port : 554; + protocol.url.assign_port(554); tcp.close(); - tcp.open( protocol.url->hostname, port, Tcp::IP4); - if(!tcp.established() && !protocol.url->port) - tcp.open( protocol.url->hostname,port = 7070, Tcp::IP4); + tcp.open( protocol.url, Tcp::IP4); + if(!tcp.established() && !protocol.url.port()) { + protocol.url.assign_port(7070); + tcp.open( protocol.url, Tcp::IP4); + } if(!tcp.established()) return NULL; - file = protocol.url->file; + file = protocol.url.file().c_str(); if (file[0] == '/') file++; - mrl = new char [strlen(protocol.url->hostname)+strlen(file)+16]; - sprintf(mrl,"rtsp://%s:%i/%s",protocol.url->hostname,port,file); + mrl = new char [protocol.url.host().length()+strlen(file)+16]; + sprintf(mrl,"rtsp://%s:%i/%s",protocol.url.host().c_str(),protocol.url.port(),file); rtsp = rtsp_session_start(tcp,&mrl, file, - protocol.url->hostname, port, &redirected, - net_conf.bandwidth,protocol.url->username, - protocol.url->password); + protocol.url.host(), protocol.url.port(), &redirected, + net_conf.bandwidth,protocol.url.user(), + protocol.url.password()); if ( redirected == 1 ) { - delete protocol.url; - protocol.url = url_new(mrl); + protocol.url.redirect(mrl); tcp.close(); } delete mrl; Modified: mplayerxp/libmpstream2/network_rtsp.cpp =================================================================== --- mplayerxp/libmpstream2/network_rtsp.cpp 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/network_rtsp.cpp 2012-12-18 13:04:29 UTC (rev 572) @@ -7,13 +7,11 @@ #include "librtsp/rtsp_session.h" namespace mpxp { -#define RTSP_DEFAULT_PORT 554 -Networking* Rtsp_Networking::start(Tcp& tcp, URL* url,unsigned bandwidth) +Networking* Rtsp_Networking::start(Tcp& tcp, URL& url,unsigned bandwidth) { Rtsp_Session *rtsp; char *mrl; - char *file; - int port; + const char *file; int redirected, temp; /* counter so we don't get caught in infinite redirections */ @@ -22,30 +20,28 @@ do { redirected = 0; - tcp.open(url->hostname, - port = (url->port ? - url->port : - RTSP_DEFAULT_PORT)); - if (!tcp.established() && !url->port) - tcp.open(url->hostname, - port = 7070); + url.assign_port(554); + tcp.open(url); + if (!tcp.established()) { + url.assign_port(7070); + tcp.open(url); + } if (!tcp.established()) return NULL; - file = url->file; + file = url.file().c_str(); if (file[0] == '/') file++; - mrl = new char [strlen (url->hostname) + strlen (file) + 16]; + mrl = new char [url.host().length() + strlen (file) + 16]; - sprintf (mrl, "rtsp://%s:%i/%s",url->hostname, port, file); + sprintf (mrl, "rtsp://%s:%i/%s",url.host().c_str(), url.port(), file); rtsp = rtsp_session_start (tcp, &mrl, file, - url->hostname, - port, &redirected, + url.host(), + url.port(), &redirected, bandwidth, - url->username, - url->password); + url.user(), + url.password()); if (redirected == 1) { - delete url; - url = url_new (mrl); + url.redirect(mrl); tcp.close(); } delete mrl; Modified: mplayerxp/libmpstream2/network_rtsp.h =================================================================== --- mplayerxp/libmpstream2/network_rtsp.h 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/network_rtsp.h 2012-12-18 13:04:29 UTC (rev 572) @@ -8,7 +8,7 @@ public: virtual ~Rtsp_Networking(); - static Networking* start(Tcp& tcp, URL* url,unsigned bandwidth); + static Networking* start(Tcp& tcp, URL& url,unsigned bandwidth); virtual int read( Tcp& fd, char *buffer, int buffer_size); virtual int seek( Tcp& fd, off_t pos); private: Modified: mplayerxp/libmpstream2/realrtsp/real.cpp =================================================================== --- mplayerxp/libmpstream2/realrtsp/real.cpp 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/realrtsp/real.cpp 2012-12-18 13:04:29 UTC (rev 572) @@ -428,7 +428,7 @@ //! maximum size of the rtsp description, must be < INT_MAX #define MAX_DESC_BUF (20 * 1024 * 1024) rmff_header_t *real_setup_and_get_header(rtsp_t *rtsp_session, uint32_t bandwidth, - char *username, char *password) { + const char *username, const char *password) { char *description=NULL; char *session_id=NULL; Modified: mplayerxp/libmpstream2/realrtsp/real.h =================================================================== --- mplayerxp/libmpstream2/realrtsp/real.h 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/realrtsp/real.h 2012-12-18 13:04:29 UTC (rev 572) @@ -53,7 +53,7 @@ int real_get_rdt_chunk(rtsp_t *rtsp_session, char **buffer, int rdt_rawdata); rmff_header_t *real_setup_and_get_header(rtsp_t *rtsp_session, uint32_t bandwidth, - char *username, char *password); + const char *username, const char *password); struct real_rtsp_session_t *init_real_rtsp_session (void); void free_real_rtsp_session (struct real_rtsp_session_t* real_session); Modified: mplayerxp/libmpstream2/s_ftp.cpp =================================================================== --- mplayerxp/libmpstream2/s_ftp.cpp 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/s_ftp.cpp 2012-12-18 13:04:29 UTC (rev 572) @@ -47,12 +47,7 @@ int OpenData(size_t newpos); int SendCmd(const std::string& cmd,char* rsp); - const char* user; - const char* pass; - const char* host; - int port; - const char* filename; - URL* url; + URL url; char* cput,*cget; Tcp tcp; @@ -196,7 +191,6 @@ int Ftp_Stream_Interface::OpenPort() { int resp; - net_fd_t fd; char rsp_txt[256]; char* par,str[128]; int num[6]; @@ -212,10 +206,11 @@ return 0; } sscanf(par+1,"%u,%u,%u,%u,%u,%u",&num[0],&num[1],&num[2],&num[3],&num[4],&num[5]); - snprintf(str,127,"%d.%d.%d.%d",num[0],num[1],num[2],num[3]); - tcp.open(str,(num[4]<<8)+num[5]); + snprintf(str,127,"ftp://%d.%d.%d.%d:%d",num[0],num[1],num[2],num[3],(num[4]<<8)+num[5]); + url.redirect(str); + tcp.open(url); - if(fd < 0) MSG_ERR("[ftp] failed to create data connection\n"); + if(!tcp.established()) MSG_ERR("[ftp] failed to create data connection\n"); return 1; } @@ -237,7 +232,7 @@ } } // Get the file - snprintf(str,255,"RETR %s",filename); + snprintf(str,255,"RETR %s",url.file().c_str()); resp = SendCmd(str,rsp_txt); if(resp != 1) { @@ -323,51 +318,46 @@ UNUSED(flags); uname=std::string("ftp://")+_filename; - if(!(url=url_new(uname))) goto bad_url; + if(url.redirect(uname)!=MPXP_Ok) goto bad_url; // url = check4proxies (rurl); - if(!(url->hostname && url->file)) { + if(url.host().empty() && !url.file().empty()) { bad_url: MSG_ERR("[ftp] Bad url\n"); return MPXP_False; } - user=url->username?url->username:"anonymous"; - pass=url->password?url->password:"no@spam"; - host=url->hostname; - port=url->port?url->port:21; - filename=url->file; - MSG_V("FTP: Opening ~%s :%s @%s :%i %s\n",user,pass,host,port,filename); + if(url.user().empty()) url.set_login("anonymous","no@spam"); + url.assign_port(21); + MSG_V("FTP: Opening ~%s :%s @%s :%i %s\n" + ,url.user().c_str(),url.password().c_str(),url.host().c_str(), + url.port(),url.file().c_str()); // Open the control connection - tcp.open(host,port); + tcp.open(url); if(!tcp.established()) { - delete url; return MPXP_False; } // We got a connection, let's start serious things buf = new char [BUFSIZE]; if (readresp(NULL) == 0) { close(); - delete url; return MPXP_False; } // Login - snprintf(str,255,"USER %s",user); + snprintf(str,255,"USER %s",url.user().c_str()); resp = SendCmd(str,rsp_txt); // password needed if(resp == 3) { - snprintf(str,255,"PASS %s",pass); + snprintf(str,255,"PASS %s",url.password().c_str()); resp = SendCmd(str,rsp_txt); if(resp != 2) { MSG_ERR("[ftp] command '%s' failed: %s\n",str,rsp_txt); close(); - delete url; return MPXP_False; } } else if(resp != 2) { MSG_ERR("[ftp] command '%s' failed: %s\n",str,rsp_txt); close(); - delete url; return MPXP_False; } @@ -376,7 +366,6 @@ if(resp != 2) { MSG_ERR("[ftp] command 'TYPE I' failed: %s\n",rsp_txt); close(); - delete url; return MPXP_False; } @@ -385,7 +374,6 @@ if(resp != 2) { MSG_ERR("[ftp] command 'SYST' failed: %s\n",rsp_txt); close(); - delete url; return MPXP_False; } MSG_INFO("[ftp] System: %s\n",rsp_txt); @@ -393,13 +381,12 @@ if(resp != 2) { MSG_ERR("[ftp] command 'STAT' failed: %s\n",rsp_txt); close(); - delete url; return MPXP_False; } file_len=0; // Get the filesize - snprintf(str,255,"SIZE %s",filename); + snprintf(str,255,"SIZE %s",url.file().c_str()); resp = SendCmd(str,rsp_txt); if(resp != 2) { MSG_WARN("[ftp] command '%s' failed: %s\n",str,rsp_txt); @@ -414,7 +401,6 @@ // because the connection would stay open in the main process, // preventing correct abort with many servers. - delete url; return MPXP_Ok; } Stream::type_e Ftp_Stream_Interface::type() const { return file_len?Stream::Type_Seekable:Stream::Type_Stream; } Modified: mplayerxp/libmpstream2/s_network.cpp =================================================================== --- mplayerxp/libmpstream2/s_network.cpp 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/s_network.cpp 2012-12-18 13:04:29 UTC (rev 572) @@ -37,7 +37,7 @@ virtual off_t sector_size() const; virtual std::string mime_type() const; private: - URL* url; + URL url; off_t spos; Tcp tcp; Networking* networking; @@ -46,22 +46,17 @@ Network_Stream_Interface::Network_Stream_Interface(libinput_t& libinput) :Stream_Interface(libinput), tcp(libinput,-1) {} -Network_Stream_Interface::~Network_Stream_Interface() { - if(url) delete url; -} +Network_Stream_Interface::~Network_Stream_Interface() {} MPXP_Rc Network_Stream_Interface::open(const std::string& filename,unsigned flags) { UNUSED(flags); - url = url_new(filename); - if(url) { + if(url.redirect(filename)==MPXP_Ok) { if((networking=Networking::start(tcp,url))==NULL){ MSG_ERR(MSGTR_UnableOpenURL, filename.c_str()); - delete url; - url=NULL; return MPXP_False; } - MSG_INFO(MSGTR_ConnToServer, url->hostname); + MSG_INFO(MSGTR_ConnToServer, url.host().c_str()); spos = 0; return MPXP_Ok; } Modified: mplayerxp/libmpstream2/s_rtsp.cpp =================================================================== --- mplayerxp/libmpstream2/s_rtsp.cpp 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/s_rtsp.cpp 2012-12-18 13:04:29 UTC (rev 572) @@ -76,14 +76,14 @@ MPXP_Rc Rtsp_Stream_Interface::open(const std::string& filename,unsigned flags) { - URL *url; + URL url; UNUSED(flags); if(filename.substr(0,7)!="rtsp://") return MPXP_False; MSG_V("STREAM_RTSP, URL: %s\n", filename.c_str()); - url = url_new (filename); - url = check4proxies (url); + url.redirect (filename); + url.check4proxies (); tcp.close(); if ((networking=Rtsp_Networking::start(tcp,url,net_conf.bandwidth)) == NULL) { Modified: mplayerxp/libmpstream2/s_udp.cpp =================================================================== --- mplayerxp/libmpstream2/s_udp.cpp 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/s_udp.cpp 2012-12-18 13:04:29 UTC (rev 572) @@ -43,9 +43,9 @@ virtual off_t sector_size() const; virtual std::string mime_type() const; private: - MPXP_Rc start (URL*,unsigned); + MPXP_Rc start (const URL&,unsigned); - Networking* networking; + Networking* networking; Udp udp; Tcp tcp; }; @@ -77,7 +77,7 @@ networking=NULL; } -MPXP_Rc Udp_Stream_Interface::start (URL* url,unsigned bandwidth) +MPXP_Rc Udp_Stream_Interface::start (const URL& url,unsigned bandwidth) { if (!udp.established()) { udp.open(networking->url); @@ -95,13 +95,13 @@ MPXP_Rc Udp_Stream_Interface::open(const std::string& filename,unsigned flags) { - URL *url; + URL url; UNUSED(flags); MSG_V("STREAM_UDP, URL: %s\n", filename.c_str()); - url = url_new (filename); - url = check4proxies (url); - if (url->port == 0) { + url.redirect(filename); + url.check4proxies (); + if (url.port() == 0) { MSG_ERR("You must enter a port number for UDP streams!\n"); return MPXP_False; } Modified: mplayerxp/libmpstream2/tcp.cpp =================================================================== --- mplayerxp/libmpstream2/tcp.cpp 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/tcp.cpp 2012-12-18 13:04:29 UTC (rev 572) @@ -51,7 +51,7 @@ // return -2 for fatal error, like unable to resolve name, connection timeout... // return -1 is unable to connect to a particular port -void Tcp::open(const std::string& host, int port, tcp_af_e af) { +void Tcp::open(const URL& __url, tcp_af_e af) { socklen_t err_len; int ret,count = 0; fd_set set; @@ -64,6 +64,7 @@ any_t*our_s_addr; // Pointer to sin_addr or sin6_addr struct hostent *hp=NULL; char buf[255]; + _url=__url; #ifdef HAVE_WINSOCK2 u_long val; @@ -73,7 +74,7 @@ #endif buf[0]=0; - MSG_V("[tcp%s] Trying to resolv host '%s'\n", af2String(af), host.c_str()); + MSG_V("[tcp%s] Trying to resolv host '%s'\n", af2String(af), _url.host().c_str()); _fd = ::socket(af==Tcp::IP4?AF_INET:AF_INET6, SOCK_STREAM, 0); if( _fd==-1 ) { @@ -104,26 +105,26 @@ memset(&server_address, 0, sizeof(server_address)); - MSG_V("[tcp%s] PreResolving Host '%s'\n",af2String(af), host.c_str()); + MSG_V("[tcp%s] PreResolving Host '%s'\n",af2String(af), _url.host().c_str()); #ifndef HAVE_WINSOCK2 #ifdef USE_ATON - if (::inet_aton(host.c_str(), our_s_addr)!=1) + if (::inet_aton(_url.host().c_str(), our_s_addr)!=1) #else - if (::inet_pton(af==Tcp::IP4?AF_INET:AF_INET6, host.c_str(), our_s_addr)!=1) + if (::inet_pton(af==Tcp::IP4?AF_INET:AF_INET6, _url.host().c_str(), our_s_addr)!=1) #endif #else - if (::inet_addr(host.c_str())==INADDR_NONE ) + if (::inet_addr(_url.host().c_str())==INADDR_NONE ) #endif { - MSG_V("[tcp%s] Resolving Host '%s'\n",af2String(af), host.c_str()); + MSG_V("[tcp%s] Resolving Host '%s'\n",af2String(af), _url.host().c_str()); #ifdef HAVE_GETHOSTBYNAME2 - hp=(struct hostent*)::gethostbyname2( host.c_str(), af==Tcp::IP4?AF_INET:AF_INET6 ); + hp=(struct hostent*)::gethostbyname2( _url.host().c_str(), af==Tcp::IP4?AF_INET:AF_INET6 ); #else - hp=(struct hostent*)::gethostbyname( host.c_str() ); + hp=(struct hostent*)::gethostbyname( _url.host().c_str() ); #endif if( hp==NULL ) { - MSG_V("[tcp%s] Can't resolv: %s\n",af2String(af), host.c_str()); + MSG_V("[tcp%s] Can't resolv: %s\n",af2String(af), _url.host().c_str()); _error=Tcp::Err_Fatal; return; } @@ -132,7 +133,7 @@ } #ifdef HAVE_WINSOCK2 else { - unsigned long addr = inet_addr(host.c_str()); + unsigned long addr = inet_addr(_url.host().c_str()); memcpy( our_s_addr, (any_t*)&addr, sizeof(addr) ); } #endif @@ -140,12 +141,12 @@ switch (af) { case Tcp::IP4: server_address.four.sin_family=AF_INET; - server_address.four.sin_port=htons(port); + server_address.four.sin_port=htons(_url.port()); server_address_size = sizeof(server_address.four); break; case Tcp::IP6: server_address.six.sin6_family=AF_INET6; - server_address.six.sin6_port=htons(port); + server_address.six.sin6_port=htons(_url.port()); server_address_size = sizeof(server_address.six); break; default: @@ -159,7 +160,7 @@ #else ::inet_ntop(af==Tcp::IP4?AF_INET:AF_INET6, our_s_addr, buf, 255); #endif - MSG_INFO("[tcp%s] Connecting to server: %s (%s:%i)\n",af2String(af),host.c_str(),buf,port); + MSG_INFO("[tcp%s] Connecting to server: %s (%s:%i)\n",af2String(af),_url.host().c_str(),buf,_url.port()); // Turn the socket as non blocking so we can timeout on the connection #ifndef HAVE_WINSOCK2 @@ -174,7 +175,7 @@ #else if( (WSAGetLastError() != WSAEINPROGRESS) && (WSAGetLastError() != WSAEWOULDBLOCK) ) { #endif - MSG_V("[tcp%s] Can't connect to server: %s\n",af2String(af),host.c_str()); + MSG_V("[tcp%s] Can't connect to server: %s\n",af2String(af),_url.host().c_str()); ::closesocket(_fd); _fd=-1; _error=Tcp::Err_Port; @@ -225,12 +226,12 @@ } } -Tcp::Tcp(libinput_t& _libinput,const std::string& host,int port,tcp_af_e af) +Tcp::Tcp(libinput_t... [truncated message content] |
From: <nic...@us...> - 2012-12-18 15:10:04
|
Revision: 573 http://mplayerxp.svn.sourceforge.net/mplayerxp/?rev=573&view=rev Author: nickols_k Date: 2012-12-18 15:09:54 +0000 (Tue, 18 Dec 2012) Log Message: ----------- convert librtsp into classes Modified Paths: -------------- mplayerxp/libmpstream2/librtsp/rtsp.cpp mplayerxp/libmpstream2/librtsp/rtsp.h mplayerxp/libmpstream2/librtsp/rtsp_rtp.cpp mplayerxp/libmpstream2/librtsp/rtsp_rtp.h mplayerxp/libmpstream2/librtsp/rtsp_session.cpp mplayerxp/libmpstream2/librtsp/rtsp_session.h mplayerxp/libmpstream2/network_real_rtsp.cpp mplayerxp/libmpstream2/network_rtsp.cpp mplayerxp/libmpstream2/realrtsp/real.cpp mplayerxp/libmpstream2/realrtsp/real.h Modified: mplayerxp/libmpstream2/librtsp/rtsp.cpp =================================================================== --- mplayerxp/libmpstream2/librtsp/rtsp.cpp 2012-12-18 13:04:29 UTC (rev 572) +++ mplayerxp/libmpstream2/librtsp/rtsp.cpp 2012-12-18 15:09:54 UTC (rev 573) @@ -60,34 +60,14 @@ #include "osdep/timer.h" #include "stream_msg.h" +namespace mpxp { /* #define LOG */ -#define BUF_SIZE 4096 -#define HEADER_SIZE 1024 -#define MAX_FIELDS 256 - -struct rtsp_t { - - Tcp* tcp; - - const char* host; - int port; - const char* path; - const char* param; - char* mrl; - const char* user_agent; - - const char* server; - unsigned server_state; - uint32_t server_caps; - - unsigned cseq; - const char* session; - - char* answers[MAX_FIELDS]; /* data of last message */ - char* scheduled[MAX_FIELDS]; /* will be sent with next message */ +enum { + BUF_SIZE=4096, + HEADER_SIZE=1024 }; /* @@ -97,28 +77,43 @@ #define RTSP_PROTOCOL_VERSION "RTSP/1.0" /* server states */ -#define RTSP_CONNECTED 1 -#define RTSP_INIT 2 -#define RTSP_READY 4 -#define RTSP_PLAYING 8 -#define RTSP_RECORDING 16 +enum { + RTSP_CONNECTED=1, + RTSP_INIT=2, + RTSP_READY=4, + RTSP_PLAYING=8, + RTSP_RECORDING=16 +}; /* server capabilities */ -#define RTSP_OPTIONS 0x001 -#define RTSP_DESCRIBE 0x002 -#define RTSP_ANNOUNCE 0x004 -#define RTSP_SETUP 0x008 -#define RTSP_GET_PARAMETER 0x010 -#define RTSP_SET_PARAMETER 0x020 -#define RTSP_TEARDOWN 0x040 -#define RTSP_PLAY 0x080 -#define RTSP_RECORD 0x100 +enum { + RTSP_OPTIONS=0x001, + RTSP_DESCRIBE=0x002, + RTSP_ANNOUNCE=0x004, + RTSP_SETUP=0x008, + RTSP_GET_PARAMETER=0x010, + RTSP_SET_PARAMETER=0x020, + RTSP_TEARDOWN=0x040, + RTSP_PLAY=0x080, + RTSP_RECORD=0x100 +}; +Rtsp::Rtsp(Tcp& _tcp):tcp(_tcp) {} +Rtsp::~Rtsp() { + if (path) delete path; + if (host) delete host; + if (mrl) delete mrl; + if (session) delete session; + if (user_agent) delete user_agent; + free_answers(); + unschedule_all(); +} + /* * network utilities */ -static int write_stream(Tcp& tcp, const char *buf, int len) { +int Rtsp::write_stream(const char *buf, int len) const { int total, timeout; total = 0; timeout = 30; @@ -144,13 +139,13 @@ return total; } -static ssize_t read_stream(Tcp& tcp, any_t*buf, size_t count) { +ssize_t Rtsp::read_stream(any_t*buf, size_t count) const { ssize_t ret, total; total = 0; - while (total < count) { + while (total < ssize_t(count)) { ret=tcp.read(((uint8_t*)buf)+total, count-total); @@ -171,211 +166,193 @@ * and returns a null terminated string. */ -static char *rtsp_get(rtsp_t *s) { +char* Rtsp::get() const { + int n=1; + char *buffer = new char [BUF_SIZE]; + char *string = NULL; - int n=1; - char *buffer = new char [BUF_SIZE]; - char *string = NULL; + read_stream(buffer, 1); + while (n<BUF_SIZE) { + read_stream(&(buffer[n]), 1); + if ((buffer[n-1]==0x0d)&&(buffer[n]==0x0a)) break; + n++; + } - read_stream(*s->tcp, buffer, 1); - while (n<BUF_SIZE) { - read_stream(*s->tcp, &(buffer[n]), 1); - if ((buffer[n-1]==0x0d)&&(buffer[n]==0x0a)) break; - n++; - } + if (n>=BUF_SIZE) { + MSG_FATAL("librtsp: buffer overflow in rtsp_get\n"); + exit(1); + } + string=new char [n]; + memcpy(string,buffer,n-1); + string[n-1]=0; - if (n>=BUF_SIZE) { - MSG_FATAL("librtsp: buffer overflow in rtsp_get\n"); - exit(1); - } - string=new char [n]; - memcpy(string,buffer,n-1); - string[n-1]=0; - #ifdef LOG - MSG_INFO("librtsp: << '%s'\n", string); + MSG_INFO("librtsp: << '%s'\n", string); #endif - delete buffer; - return string; + delete buffer; + return string; } /* * rtsp_put puts a line on stream */ -static void rtsp_put(rtsp_t *s, const char *string) { +void Rtsp::put(const char *string) const { + int len=strlen(string); + char *buf=new char [len+2]; - int len=strlen(string); - char *buf=new char [len+2]; - #ifdef LOG - MSG_INFO("librtsp: >> '%s'", string); + MSG_INFO("librtsp: >> '%s'", string); #endif - memcpy(buf,string,len); - buf[len]=0x0d; - buf[len+1]=0x0a; + memcpy(buf,string,len); + buf[len]=0x0d; + buf[len+1]=0x0a; - write_stream(*s->tcp, buf, len+2); + write_stream(buf, len+2); #ifdef LOG - MSG_INFO(" done.\n"); + MSG_INFO(" done.\n"); #endif - - delete buf; + delete buf; } /* * extract server status code */ -static int rtsp_get_code(const char *string) { +int Rtsp::get_code(const char *string) const { + char buf[4]; + int code=0; - char buf[4]; - int code=0; - - if (!strncmp(string, RTSP_PROTOCOL_VERSION, strlen(RTSP_PROTOCOL_VERSION))) - { - memcpy(buf, string+strlen(RTSP_PROTOCOL_VERSION)+1, 3); - buf[3]=0; - code=atoi(buf); - } else if (!strncmp(string, RTSP_METHOD_SET_PARAMETER,8)) - { - return RTSP_STATUS_SET_PARAMETER; - } - - if(code != RTSP_STATUS_OK) MSG_INFO("librtsp: server responds: '%s'\n",string); - - return code; + if (!strncmp(string, RTSP_PROTOCOL_VERSION, strlen(RTSP_PROTOCOL_VERSION))) { + memcpy(buf, string+strlen(RTSP_PROTOCOL_VERSION)+1, 3); + buf[3]=0; + code=atoi(buf); + } else if (!strncmp(string, RTSP_METHOD_SET_PARAMETER,8)) { + return RTSP_STATUS_SET_PARAMETER; + } + if(code != RTSP_STATUS_OK) MSG_INFO("librtsp: server responds: '%s'\n",string); + return code; } /* * send a request */ -static void rtsp_send_request(rtsp_t *s, const char *type, const char *what) { +void Rtsp::send_request(const char *type, const char *what) { + char *const *payload=scheduled; + char *buf; - char **payload=s->scheduled; - char *buf; + buf = new char [strlen(type)+strlen(what)+strlen(RTSP_PROTOCOL_VERSION)+3]; - buf = new char [strlen(type)+strlen(what)+strlen(RTSP_PROTOCOL_VERSION)+3]; - - sprintf(buf,"%s %s %s",type, what, RTSP_PROTOCOL_VERSION); - rtsp_put(s,buf); - delete buf; - if (payload) - while (*payload) { - rtsp_put(s,*payload); - payload++; - } - rtsp_put(s,""); - rtsp_unschedule_all(s); + sprintf(buf,"%s %s %s",type, what, RTSP_PROTOCOL_VERSION); + put(buf); + delete buf; + if (payload) + while (*payload) { + put(*payload); + payload++; + } + put(""); + unschedule_all(); } /* * schedule standard fields */ -static void rtsp_schedule_standard(rtsp_t *s) { +void Rtsp::schedule_standard() { + char tmp[17]; - char tmp[17]; + snprintf(tmp, 17, "CSeq: %u", cseq); + schedule_field(tmp); - snprintf(tmp, 17, "CSeq: %u", s->cseq); - rtsp_schedule_field(s, tmp); - - if (s->session) { - char *buf; - buf = new char [strlen(s->session)+15]; - sprintf(buf, "Session: %s", s->session); - rtsp_schedule_field(s, buf); - delete buf; - } + if (session) { + char *buf; + buf = new char [strlen(session)+15]; + sprintf(buf, "Session: %s", session); + schedule_field(buf); + delete buf; + } } /* * get the answers, if server responses with something != 200, return NULL */ -static int rtsp_get_answers(rtsp_t *s) { +int Rtsp::get_answers() { + char *answer=NULL; + unsigned int answer_seq; + char **answer_ptr=answers; + int code; + int ans_count = 0; - char *answer=NULL; - unsigned int answer_seq; - char **answer_ptr=s->answers; - int code; - int ans_count = 0; + answer=get(); + if (!answer) return 0; + code=get_code(answer); + delete answer; - answer=rtsp_get(s); - if (!answer) - return 0; - code=rtsp_get_code(answer); - delete answer; + free_answers(); - rtsp_free_answers(s); + do { /* while we get answer lines */ + answer=get(); + if (!answer) return 0; - do { /* while we get answer lines */ - - answer=rtsp_get(s); - if (!answer) - return 0; - - if (!strncasecmp(answer,"CSeq:",5)) { - sscanf(answer,"%*s %u",&answer_seq); - if (s->cseq != answer_seq) { + if (!strncasecmp(answer,"CSeq:",5)) { + sscanf(answer,"%*s %u",&answer_seq); + if (cseq != answer_seq) { #ifdef LOG - MSG_WARN("librtsp: warning: CSeq mismatch. got %u, assumed %u", answer_seq, s->cseq); + MSG_WARN("librtsp: warning: CSeq mismatch. got %u, assumed %u", answer_seq, s->cseq); #endif - s->cseq=answer_seq; - } - } - if (!strncasecmp(answer,"Server:",7)) { - char *buf = new char [strlen(answer)]; - sscanf(answer,"%*s %s",buf); - if (s->server) delete s->server; - s->server=mp_strdup(buf); - delete buf; - } - if (!strncasecmp(answer,"Session:",8)) { - char *buf = new(zeromem) char [strlen(answer)]; - sscanf(answer,"%*s %s",buf); - if (s->session) { - if (strcmp(buf, s->session)) { - MSG_WARN("rtsp: warning: setting NEW session: %s\n", buf); - delete s->session; - s->session=mp_strdup(buf); + cseq=answer_seq; + } } - } else - { + if (!strncasecmp(answer,"Server:",7)) { + char *buf = new char [strlen(answer)]; + sscanf(answer,"%*s %s",buf); + if (server) delete server; + server=mp_strdup(buf); + delete buf; + } + if (!strncasecmp(answer,"Session:",8)) { + char *buf = new(zeromem) char [strlen(answer)]; + sscanf(answer,"%*s %s",buf); + if (session) { + if (strcmp(buf, session)) { + MSG_WARN("rtsp: warning: setting NEW session: %s\n", buf); + delete session; + session=mp_strdup(buf); + } + } else { #ifdef LOG - MSG_INFO("rtsp: setting session id to: %s\n", buf); + MSG_INFO("rtsp: setting session id to: %s\n", buf); #endif - s->session=mp_strdup(buf); - } - delete buf; - } - *answer_ptr=answer; - answer_ptr++; - } while ((strlen(answer)!=0) && (++ans_count < MAX_FIELDS)); - - s->cseq++; - - *answer_ptr=NULL; - rtsp_schedule_standard(s); - - return code; + session=mp_strdup(buf); + } + delete buf; + } + *answer_ptr=answer; + answer_ptr++; + } while ((strlen(answer)!=0) && (++ans_count < RTSP_MAX_FIELDS)); + cseq++; + *answer_ptr=NULL; + schedule_standard(); + return code; } /* * send an ok message */ -int rtsp_send_ok(rtsp_t *s) { - char cseq[16]; +int Rtsp::send_ok() const { + char _cseq[16]; - rtsp_put(s, "RTSP/1.0 200 OK"); - sprintf(cseq,"CSeq: %u", s->cseq); - rtsp_put(s, cseq); - rtsp_put(s, ""); - return 0; + put("RTSP/1.0 200 OK"); + sprintf(_cseq,"CSeq: %u", cseq); + put(_cseq); + put(""); + return 0; } /* @@ -383,174 +360,140 @@ * server status code. */ -int rtsp_request_options(rtsp_t *s, const char *what) { +int Rtsp::request_options(const char *what) { + char *buf; - char *buf; - - if (what) { - buf=mp_strdup(what); - } else - { - buf=new char [strlen(s->host)+16]; - sprintf(buf,"rtsp://%s:%i", s->host, s->port); - } - rtsp_send_request(s,RTSP_METHOD_OPTIONS,buf); - delete buf; - - return rtsp_get_answers(s); + if (what) buf=mp_strdup(what); + else { + buf=new char [strlen(host)+16]; + sprintf(buf,"rtsp://%s:%i", host, port); + } + send_request(RTSP_METHOD_OPTIONS,buf); + delete buf; + return get_answers(); } -int rtsp_request_describe(rtsp_t *s, const char *what) { +int Rtsp::request_describe(const char *what) { + char *buf; - char *buf; - - if (what) { - buf=mp_strdup(what); - } else - { - buf=new char [strlen(s->host)+strlen(s->path)+16]; - sprintf(buf,"rtsp://%s:%i/%s", s->host, s->port, s->path); - } - rtsp_send_request(s,RTSP_METHOD_DESCRIBE,buf); - delete buf; - - return rtsp_get_answers(s); + if (what) buf=mp_strdup(what); + else { + buf=new char [strlen(host)+strlen(path)+16]; + sprintf(buf,"rtsp://%s:%i/%s", host, port, path); + } + send_request(RTSP_METHOD_DESCRIBE,buf); + delete buf; + return get_answers(); } -int rtsp_request_setup(rtsp_t *s, const char *what, char *control) { +int Rtsp::request_setup(const char *what, char *control) { + char *buf = NULL; - char *buf = NULL; - - if (what) - buf = mp_strdup (what); - else - { - int len = strlen (s->host) + strlen (s->path) + 16; - if (control) - len += strlen (control) + 1; - - buf = new char [len]; - sprintf (buf, "rtsp://%s:%i/%s%s%s", s->host, s->port, s->path, + if (what) buf = mp_strdup (what); + else { + int len = strlen (host) + strlen (path) + 16; + if (control) len += strlen (control) + 1; + buf = new char [len]; + sprintf (buf, "rtsp://%s:%i/%s%s%s", host, port, path, control ? "/" : "", control ? control : ""); - } - - rtsp_send_request (s, RTSP_METHOD_SETUP, buf); - delete buf; - return rtsp_get_answers (s); + } + send_request (RTSP_METHOD_SETUP, buf); + delete buf; + return get_answers (); } -int rtsp_request_setparameter(rtsp_t *s, const char *what) { +int Rtsp::request_setparameter(const char *what) { + char *buf; - char *buf; - - if (what) { - buf=mp_strdup(what); - } else - { - buf=new char [strlen(s->host)+strlen(s->path)+16]; - sprintf(buf,"rtsp://%s:%i/%s", s->host, s->port, s->path); - } - rtsp_send_request(s,RTSP_METHOD_SET_PARAMETER,buf); - delete buf; - - return rtsp_get_answers(s); + if (what) buf=mp_strdup(what); + else { + buf=new char [strlen(host)+strlen(path)+16]; + sprintf(buf,"rtsp://%s:%i/%s", host, port, path); + } + send_request(RTSP_METHOD_SET_PARAMETER,buf); + delete buf; + return get_answers(); } -int rtsp_request_play(rtsp_t *s, const char *what) { +int Rtsp::request_play(const char *what) { + char *buf; + int ret; - char *buf; - int ret; + if (what) buf=mp_strdup(what); + else { + buf=new char [strlen(host)+strlen(path)+16]; + sprintf(buf,"rtsp://%s:%i/%s", host, port, path); + } + send_request(RTSP_METHOD_PLAY,buf); + delete buf; - if (what) { - buf=mp_strdup(what); - } else - { - buf=new char [strlen(s->host)+strlen(s->path)+16]; - sprintf(buf,"rtsp://%s:%i/%s", s->host, s->port, s->path); - } - rtsp_send_request(s,RTSP_METHOD_PLAY,buf); - delete buf; - - ret = rtsp_get_answers (s); - if (ret == RTSP_STATUS_OK) - s->server_state = RTSP_PLAYING; - - return ret; + ret = get_answers (); + if (ret == RTSP_STATUS_OK) server_state = RTSP_PLAYING; + return ret; } -int rtsp_request_teardown(rtsp_t *s, const char *what) { +int Rtsp::request_teardown(const char *what) { + char *buf; - char *buf; + if (what) buf = mp_strdup (what); + else { + buf = new char [strlen (host) + strlen (path) + 16]; + sprintf (buf, "rtsp://%s:%i/%s", host, port, path); + } + send_request (RTSP_METHOD_TEARDOWN, buf); + delete buf; - if (what) - buf = mp_strdup (what); - else - { - buf = new char [strlen (s->host) + strlen (s->path) + 16]; - sprintf (buf, "rtsp://%s:%i/%s", s->host, s->port, s->path); - } - rtsp_send_request (s, RTSP_METHOD_TEARDOWN, buf); - delete buf; - - /* after teardown we're done with RTSP streaming, no need to get answer as - reading more will only result to garbage and buffer overflow */ - return RTSP_STATUS_OK; + /* after teardown we're done with RTSP streaming, no need to get answer as + reading more will only result to garbage and buffer overflow */ + return RTSP_STATUS_OK; } /* * read opaque data from stream */ -int rtsp_read_data(rtsp_t *s, char *buffer, unsigned int size) { +int Rtsp::read_data(char *buffer, unsigned int size) const { + int i,seq; - int i,seq; - - if (size>=4) { - i=read_stream(*s->tcp, buffer, 4); - if (i<4) return i; - if (((buffer[0]=='S')&&(buffer[1]=='E')&&(buffer[2]=='T')&&(buffer[3]=='_')) || - ((buffer[0]=='O')&&(buffer[1]=='P')&&(buffer[2]=='T')&&(buffer[3]=='I'))) // OPTIONS - { - char *rest=rtsp_get(s); - if (!rest) - return -1; - - seq=-1; - do { - delete rest; - rest=rtsp_get(s); - if (!rest) - return -1; - if (!strncasecmp(rest,"CSeq:",5)) - sscanf(rest,"%*s %u",&seq); - } while (strlen(rest)!=0); - delete rest; - if (seq<0) { + if (size>=4) { + i=read_stream(buffer, 4); + if (i<4) return i; + if (((buffer[0]=='S')&&(buffer[1]=='E')&&(buffer[2]=='T')&&(buffer[3]=='_')) || + ((buffer[0]=='O')&&(buffer[1]=='P')&&(buffer[2]=='T')&&(buffer[3]=='I'))) { // OPTIONS + char *rest=get(); + if (!rest) return -1; + seq=-1; + do { + delete rest; + rest=get(); + if (!rest) return -1; + if (!strncasecmp(rest,"CSeq:",5)) + sscanf(rest,"%*s %u",&seq); + } while (strlen(rest)!=0); + delete rest; + if (seq<0) { #ifdef LOG - MSG_WARN("rtsp: warning: CSeq not recognized!\n"); + MSG_WARN("rtsp: warning: CSeq not recognized!\n"); #endif - seq=1; - } - /* let's make the server happy */ - rtsp_put(s, "RTSP/1.0 451 Parameter Not Understood"); - rest=new char [17]; - sprintf(rest,"CSeq: %u", seq); - rtsp_put(s, rest); - delete rest; - rtsp_put(s, ""); - i=read_stream(*s->tcp, buffer, size); - } else - { - i=read_stream(*s->tcp, buffer+4, size-4); - i+=4; - } - } else - i=read_stream(*s->tcp, buffer, size); + seq=1; + } + /* let's make the server happy */ + put("RTSP/1.0 451 Parameter Not Understood"); + rest=new char [17]; + sprintf(rest,"CSeq: %u", seq); + put(rest); + delete rest; + put(""); + i=read_stream(buffer, size); + } else { + i=read_stream(buffer+4, size-4); + i+=4; + } + } else i=read_stream(buffer, size); #ifdef LOG - MSG_INFO("librtsp: << %d of %d bytes\n", i, size); + MSG_INFO("librtsp: << %d of %d bytes\n", i, size); #endif - - return i; + return i; } /* @@ -558,59 +501,59 @@ */ //rtsp_t *rtsp_connect(const char *mrl, const char *user_agent) { -rtsp_t *rtsp_connect(Tcp& tcp, char* mrl,const char *path,const char *host, int port,const char *user_agent) { +Rtsp* Rtsp::connect(Tcp& tcp, char* mrl,const char *path,const char *host, int port,const char *user_agent) { - rtsp_t *s=new rtsp_t; + Rtsp& s=*new(zeromem) Rtsp(tcp); int i; - for (i=0; i<MAX_FIELDS; i++) { - s->answers[i]=NULL; - s->scheduled[i]=NULL; + for (i=0; i<RTSP_MAX_FIELDS; i++) { + s.answers[i]=NULL; + s.scheduled[i]=NULL; } - s->server=NULL; - s->server_state=0; - s->server_caps=0; + s.server=NULL; + s.server_state=0; + s.server_caps=0; - s->cseq=0; - s->session=NULL; + s.cseq=0; + s.session=NULL; if (user_agent) - s->user_agent=mp_strdup(user_agent); + s.user_agent=mp_strdup(user_agent); else - s->user_agent=mp_strdup("User-Agent: RealMedia Player Version 6.0.9.1235 (linux-2.0-libc6-i386-gcc2.95)"); + s.user_agent=mp_strdup("User-Agent: RealMedia Player Version 6.0.9.1235 (linux-2.0-libc6-i386-gcc2.95)"); - s->mrl = mp_strdup(mrl); - s->host = mp_strdup(host); - s->port = port; - s->path = mp_strdup(path); + s.mrl = mp_strdup(mrl); + s.host = mp_strdup(host); + s.port = port; + s.path = mp_strdup(path); while (*path == '/') path++; - if ((s->param = strchr(s->path, '?')) != NULL) - s->param++; - s->tcp = &tcp; + if ((s.param = strchr(s.path, '?')) != NULL) + s.param++; if (!tcp.established()) { - MSG_ERR("rtsp: failed to connect to '%s'\n", s->host); - rtsp_close(s); + MSG_ERR("rtsp: failed to connect to '%s'\n", s.host); + s.close(); + delete &s; return NULL; } - s->server_state=RTSP_CONNECTED; + s.server_state=RTSP_CONNECTED; /* now let's 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"); + s.schedule_field("CSeq: 1"); + s.schedule_field(s.user_agent); + s.schedule_field("ClientChallenge: 9e26d33f2984236010ef6253fb1887f7"); + s.schedule_field("PlayerStarttime: [28/03/2003:22:50:23 00:00]"); + s.schedule_field("CompanyID: KnKV4M4I/B2FjJ1TToLycw=="); + s.schedule_field("GUID: 00000000-0000-0000-0000-000000000000"); + s.schedule_field("RegionData: 0"); + s.schedule_field("ClientID: Linux_2.4_6.0.9.1235_play32_RN01_EN_586"); /*rtsp_schedule_field(s, "Pragma: initiate-session");*/ - rtsp_request_options(s, NULL); + s.request_options(NULL); - return s; + return &s; } @@ -618,23 +561,12 @@ * closes an rtsp connection */ -void rtsp_close(rtsp_t *s) { - - if (s->server_state) - { - if (s->server_state == RTSP_PLAYING) - rtsp_request_teardown (s, NULL); - s->tcp->close(); - } - - if (s->path) delete s->path; - if (s->host) delete s->host; - if (s->mrl) delete s->mrl; - if (s->session) delete s->session; - if (s->user_agent) delete s->user_agent; - rtsp_free_answers(s); - rtsp_unschedule_all(s); - delete s; +void Rtsp::close() { + if (server_state) { + if (server_state == RTSP_PLAYING) + request_teardown (NULL); + tcp.close(); + } } /* @@ -642,146 +574,118 @@ * after the first matched tag. returns NULL if no match found. */ -char *rtsp_search_answers(rtsp_t *s, const char *tag) { +char* Rtsp::search_answers(const char *tag) const { + char *const *answer; + char *ptr; - char **answer; - char *ptr; + if (!answers) return NULL; + answer=answers; - if (!s->answers) return NULL; - answer=s->answers; - - while (*answer) { - if (!strncasecmp(*answer,tag,strlen(tag))) { - ptr=strchr(*answer,':'); - if (!ptr) return NULL; - ptr++; - while(*ptr==' ') ptr++; - return ptr; + while (*answer) { + if (!strncasecmp(*answer,tag,strlen(tag))) { + ptr=strchr(*answer,':'); + if (!ptr) return NULL; + ptr++; + while(*ptr==' ') ptr++; + return ptr; + } + answer++; } - answer++; - } - - return NULL; + return NULL; } /* * session id management */ -void rtsp_set_session(rtsp_t *s, const char *id) { - - if (s->session) delete s->session; - - s->session=mp_strdup(id); - +void Rtsp::set_session(const char *id) { + if (session) delete session; + session=mp_strdup(id); } -const char *rtsp_get_session(rtsp_t *s) { +const char* Rtsp::get_session() const { return session; } +char* Rtsp::get_mrl() const { return mrl; } - return s->session; - -} - -char *rtsp_get_mrl(rtsp_t *s) { - - return s->mrl; - -} - -char *rtsp_get_param(rtsp_t *s,const char *p) { - int len; - const char *param; - if (!s->param) - return NULL; - if (!p) - return mp_strdup(s->param); - len = strlen(p); - param = s->param; - while (param && *param) { - const char *nparam = strchr(param, '&'); - if (strncmp(param, p, len) == 0 && param[len] == '=') { - param += len + 1; - len = nparam ? nparam - param : strlen(param); - char* _nparam = new char [len + 1]; - memcpy(_nparam, param, len); - _nparam[len] = 0; - return _nparam; +char* Rtsp::get_param(const char *p) const { + int len; + const char *_param; + if (!param) return NULL; + if (!p) return mp_strdup(param); + len = strlen(p); + _param = param; + while (_param && *_param) { + const char *nparam = strchr(_param, '&'); + if (strncmp(_param, p, len) == 0 && _param[len] == '=') { + _param += len + 1; + len = nparam ? nparam - _param : strlen(_param); + char* _nparam = new char [len + 1]; + memcpy(_nparam, _param, len); + _nparam[len] = 0; + return _nparam; + } + _param = nparam ? nparam + 1 : NULL; } - param = nparam ? nparam + 1 : NULL; - } - return NULL; + return NULL; } /* * schedules a field for transmission */ -void rtsp_schedule_field(rtsp_t *s, const char *string) { - - int i=0; - - if (!string) return; - - while(s->scheduled[i]) { - i++; - } - s->scheduled[i]=mp_strdup(string); +void Rtsp::schedule_field(const char *string) { + int i=0; + if (!string) return; + while(scheduled[i]) i++; + scheduled[i]=mp_strdup(string); } /* * removes the first scheduled field which prefix matches string. */ -void rtsp_unschedule_field(rtsp_t *s, const char *string) { - - char **ptr=s->scheduled; - - if (!string) return; - - while(*ptr) { - if (!strncmp(*ptr, string, strlen(string))) - break; - else - ptr++; - } - if (*ptr) delete *ptr; - ptr++; - do { - *(ptr-1)=*ptr; - } while(*ptr); +void Rtsp::unschedule_field(const char *string) { + char **ptr=scheduled; + if (!string) return; + while(*ptr) { + if (!strncmp(*ptr, string, strlen(string))) break; + else ptr++; + } + if (*ptr) delete *ptr; + ptr++; + do { + *(ptr-1)=*ptr; + } while(*ptr); } /* * unschedule all fields */ -void rtsp_unschedule_all(rtsp_t *s) { +void Rtsp::unschedule_all() { + char **ptr; - char **ptr; + if (!scheduled) return; + ptr=scheduled; - if (!s->scheduled) return; - ptr=s->scheduled; - - while (*ptr) { - delete *ptr; - *ptr=NULL; - ptr++; - } + while (*ptr) { + delete *ptr; + *ptr=NULL; + ptr++; + } } /* * mp_free answers */ -void rtsp_free_answers(rtsp_t *s) { +void Rtsp::free_answers() { + char **answer; - char **answer; - - if (!s->answers) return; - answer=s->answers; - - while (*answer) { - delete *answer; - *answer=NULL; - answer++; - } + if (!answers) return; + answer=answers; + while (*answer) { + delete *answer; + *answer=NULL; + answer++; + } } +} // namespace mpxp Modified: mplayerxp/libmpstream2/librtsp/rtsp.h =================================================================== --- mplayerxp/libmpstream2/librtsp/rtsp.h 2012-12-18 13:04:29 UTC (rev 572) +++ mplayerxp/libmpstream2/librtsp/rtsp.h 2012-12-18 15:09:54 UTC (rev 573) @@ -33,11 +33,13 @@ #define HAVE_RTSP_H #include "libmpstream2/tcp.h" +namespace mpxp { /* some codes returned by rtsp_request_* functions */ -enum { - RTSP_STATUS_SET_PARAMETER =10, - RTSP_STATUS_OK =200 -}; + enum { + RTSP_STATUS_SET_PARAMETER =10, + RTSP_STATUS_OK =200, + RTSP_MAX_FIELDS =256 + }; #define RTSP_METHOD_OPTIONS "OPTIONS" #define RTSP_METHOD_DESCRIBE "DESCRIBE" #define RTSP_METHOD_SETUP "SETUP" @@ -45,40 +47,67 @@ #define RTSP_METHOD_TEARDOWN "TEARDOWN" #define RTSP_METHOD_SET_PARAMETER "SET_PARAMETER" -struct rtsp_t; + class Rtsp : public Opaque { + public: + Rtsp(Tcp& tcp); + virtual ~Rtsp(); -rtsp_t* rtsp_connect (Tcp& tcp, char *mrl, const char *path, const char *host, int port, const char *user_agent); + static Rtsp* connect (Tcp& tcp, char *mrl, const char *path, const char *host, int port, const char *user_agent); -int rtsp_request_options(rtsp_t *s, const char *what); -int rtsp_request_describe(rtsp_t *s, const char *what); -int rtsp_request_setup(rtsp_t *s, const char *what, char *control); -int rtsp_request_setparameter(rtsp_t *s, const char *what); -int rtsp_request_play(rtsp_t *s, const char *what); -int rtsp_request_teardown(rtsp_t *s, const char *what); + virtual int request_options(const char *what); + virtual int request_describe(const char *what); + virtual int request_setup(const char *what, char *control); + virtual int request_setparameter(const char *what); + virtual int request_play(const char *what); + virtual int request_teardown(const char *what); -int rtsp_send_ok(rtsp_t *s); + virtual int send_ok() const; + virtual int read_data(char *buffer, unsigned int size) const; -int rtsp_read_data(rtsp_t *s, char *buffer, unsigned int size); + virtual char* search_answers(const char *tag) const; -char* rtsp_search_answers(rtsp_t *s, const char *tag); -void rtsp_add_to_payload(char **payload, const char *string); + virtual void free_answers(); -void rtsp_free_answers(rtsp_t *self); + virtual void close (); -int rtsp_read (rtsp_t *self, char *data, int len); -void rtsp_close (rtsp_t *self); + virtual void set_session(const char *id); + virtual const char* get_session() const; -void rtsp_set_session(rtsp_t *s, const char *id); -const char *rtsp_get_session(rtsp_t *s); + virtual char* get_mrl() const; + virtual char* get_param(const char *param) const; -char *rtsp_get_mrl(rtsp_t *s); -char *rtsp_get_param(rtsp_t *s,const char *param); + virtual void schedule_field(const char *string); + virtual void unschedule_field(const char *string); + virtual void unschedule_all(); + private: + char* get() const; + void put(const char *string) const; + int get_code(const char *string) const; + void send_request(const char *type, const char *what); + void schedule_standard(); + int get_answers(); + int write_stream(const char *buf, int len) const; + ssize_t read_stream(any_t*buf, size_t count) const; -/*int rtsp_peek_header (rtsp_t *self, char *data); */ + Tcp& tcp; -void rtsp_schedule_field(rtsp_t *s, const char *string); -void rtsp_unschedule_field(rtsp_t *s, const char *string); -void rtsp_unschedule_all(rtsp_t *s); + const char* host; + int port; + const char* path; + const char* param; + char* mrl; + const char* user_agent; + const char* server; + unsigned server_state; + uint32_t server_caps; + + unsigned cseq; + const char* session; + + char* answers[RTSP_MAX_FIELDS]; /* data of last message */ + char* scheduled[RTSP_MAX_FIELDS]; /* will be sent with next message */ + }; +} // namespace mpxp #endif Modified: mplayerxp/libmpstream2/librtsp/rtsp_rtp.cpp =================================================================== --- mplayerxp/libmpstream2/librtsp/rtsp_rtp.cpp 2012-12-18 13:04:29 UTC (rev 572) +++ mplayerxp/libmpstream2/librtsp/rtsp_rtp.cpp 2012-12-18 15:09:54 UTC (rev 573) @@ -48,6 +48,7 @@ #include "freesdp/parser.h" #include "stream_msg.h" +namespace mpxp { #define RTSP_DEFAULT_PORT 31336 #define MAX_LENGTH 256 @@ -76,596 +77,467 @@ #define RTCP_RR "\201\311\0\7(.JD\31+\306\343\0\0\0\0\0\0/E\0\0\2&\0\0\0\0\0\0\0\0\201" #define RTCP_SEND_FREQUENCY 1024 -int rtsp_port = 0; -char *rtsp_destination = NULL; - -void -rtcp_send_rr (rtsp_t *s, struct rtp_rtsp_session_t *st) -{ - if (st->rtcp_socket == -1) - return; - +void Rtp_Rtsp_Session::rtcp_send_rr (Rtsp& s) { + if (rtcp_socket == -1) return; /* send RTCP RR every RTCP_SEND_FREQUENCY packets * FIXME : NOT CORRECT, HARDCODED, BUT MAKES SOME SERVERS HAPPY * not rfc compliant * http://www.faqs.org/rfcs/rfc1889.html chapter 6 for RTCP */ + if (count == RTCP_SEND_FREQUENCY) { + char rtcp_content[RTCP_RR_SIZE]; + strcpy (rtcp_content, RTCP_RR); + send (rtcp_socket, rtcp_content, RTCP_RR_SIZE, 0); - if (st->count == RTCP_SEND_FREQUENCY) - { - char rtcp_content[RTCP_RR_SIZE]; - strcpy (rtcp_content, RTCP_RR); - send (st->rtcp_socket, rtcp_content, RTCP_RR_SIZE, 0); - - /* ping RTSP server to keep connection alive. - we use OPTIONS instead of PING as not all servers support it */ - rtsp_request_options (s, "*"); - st->count = 0; - } - else - st->count++; + /* ping RTSP server to keep connection alive. + we use OPTIONS instead of PING as not all servers support it */ + s.request_options ("*"); + count = 0; + } else count++; } -static struct rtp_rtsp_session_t * -rtp_session_new (void) -{ - struct rtp_rtsp_session_t *st = NULL; - - st = new struct rtp_rtsp_session_t; - - st->rtp_socket = -1; - st->rtcp_socket = -1; - st->control_url = NULL; - st->count = 0; - - return st; +Rtp_Rtsp_Session::Rtp_Rtsp_Session() { + rtp_socket = -1; + rtcp_socket = -1; } -void -rtp_session_free (struct rtp_rtsp_session_t *st) -{ - if (!st) - return; - - if (st->rtp_socket != -1) - close (st->rtp_socket); - if (st->rtcp_socket != -1) - close (st->rtcp_socket); - - if (st->control_url) - delete st->control_url; - delete st; +Rtp_Rtsp_Session::~Rtp_Rtsp_Session() { + if (rtp_socket != -1) ::close (rtp_socket); + if (rtcp_socket != -1) ::close (rtcp_socket); + if (control_url) delete control_url; } -static void -rtp_session_set_fd (struct rtp_rtsp_session_t *st, - int rtp_sock, int rtcp_sock) -{ - if (!st) - return; - - st->rtp_socket = rtp_sock; - st->rtcp_socket = rtcp_sock; +void Rtp_Rtsp_Session::set_fd (int rtp_sock, int rtcp_sock) { + rtp_socket = rtp_sock; + rtcp_socket = rtcp_sock; } -static int -parse_port (const char *line, const char *param, - int *rtp_port, int *rtcp_port) -{ - char *parse1; - char *parse2; - char *parse3; +int Rtp_Rtsp_Session::parse_port (const char *line, const char *param, int *rtp_port, int *rtcp_port) const { + char *parse1; + char *parse2; + char *parse3; - char *line_copy = mp_strdup (line); + char *line_copy = mp_strdup (line); - parse1 = strstr (line_copy, param); + parse1 = strstr (line_copy, param); - if (parse1) - { - parse2 = strstr (parse1, "-"); - - if (parse2) - { - parse3 = strstr (parse2, ";"); - - if (parse3) - parse3[0] = 0; - - parse2[0] = 0; + if (parse1) { + parse2 = strstr (parse1, "-"); + if (parse2) { + parse3 = strstr (parse2, ";"); + if (parse3) parse3[0] = 0; + parse2[0] = 0; + } else { + delete line_copy; + return 0; + } + } else { + delete line_copy; + return 0; } - else - { - delete line_copy; - return 0; - } - } - else - { + *rtp_port = atoi (parse1 + strlen (param)); + *rtcp_port = atoi (parse2 + 1); delete line_copy; - return 0; - } - - *rtp_port = atoi (parse1 + strlen (param)); - *rtcp_port = atoi (parse2 + 1); - - delete line_copy; - - return 1; + return 1; } -static char * -parse_destination (const char *line) -{ - char *parse1; - char *parse2; +char* Rtp_Rtsp_Session::parse_destination (const char *line) const { + char *parse1; + char *parse2; - char *dest = NULL; - char *line_copy = mp_strdup (line); - int len; + char *dest = NULL; + char *line_copy = mp_strdup (line); + int len; - parse1 = strstr (line_copy, RTSP_SETUP_DESTINATION); - if (!parse1) - { + parse1 = strstr (line_copy, RTSP_SETUP_DESTINATION); + if (!parse1) { + delete line_copy; + return NULL; + } + parse2 = strstr (parse1, ";"); + if (!parse2) { + delete line_copy; + return NULL; + } + len = strlen(parse1)-strlen (parse2)-strlen(RTSP_SETUP_DESTINATION)+1; + dest = new char [len + 1]; + snprintf (dest, len, parse1 + strlen (RTSP_SETUP_DESTINATION)); delete line_copy; - return NULL; - } - - parse2 = strstr (parse1, ";"); - if (!parse2) - { - delete line_copy; - return NULL; - } - - len = strlen (parse1) - strlen (parse2) - - strlen (RTSP_SETUP_DESTINATION) + 1; - dest = (char *) mp_malloc (len + 1); - snprintf (dest, len, parse1 + strlen (RTSP_SETUP_DESTINATION)); - delete line_copy; - - return dest; + return dest; } -static int -rtcp_connect (int client_port, int server_port, const char* server_hostname) -{ - struct sockaddr_in sin; - struct hostent *hp; - int s; +int Rtp_Rtsp_Session::rtcp_connect(int client_port, int server_port, const char* server_hostname) const { + struct sockaddr_in sin; + struct hostent *hp; + int s; - if (client_port <= 1023) - return -1; + if (client_port <= 1023) return -1; - s = socket (PF_INET, SOCK_DGRAM, IPPROTO_UDP); - if (s == -1) - return -1; + s = ::socket (PF_INET, SOCK_DGRAM, IPPROTO_UDP); + if (s == -1) return -1; - hp = gethostbyname (server_hostname); - if (!hp) - { - close (s); - return -1; - } + hp = gethostbyname (server_hostname); + if (!hp) { + ::close (s); + return -1; + } - sin.sin_family = AF_INET; - sin.sin_addr.s_addr = INADDR_ANY; - sin.sin_port = htons (client_port); + sin.sin_family = AF_INET; + sin.sin_addr.s_addr = INADDR_ANY; + sin.sin_port = htons (client_port); - if (bind (s, (struct sockaddr *) &sin, sizeof (sin))) - { + if (::bind (s, (struct sockaddr *) &sin, sizeof (sin))) { #ifndef HAVE_WINSOCK2 - if (errno != EINPROGRESS) + if (errno != EINPROGRESS) #else - if (WSAGetLastError() != WSAEINPROGRESS) + if (WSAGetLastError() != WSAEINPROGRESS) #endif - { - close (s); - return -1; + { + ::close (s); + return -1; + } } - } - sin.sin_family = AF_INET; - memcpy (&(sin.sin_addr.s_addr), hp->h_addr, sizeof (hp->h_addr)); - sin.sin_port = htons (server_port); + sin.sin_family = AF_INET; + memcpy (&(sin.sin_addr.s_addr), hp->h_addr, sizeof (hp->h_addr)); + sin.sin_port = htons (server_port); /* datagram socket */ - if (connect (s, (struct sockaddr *) &sin, sizeof (sin)) < 0) - { - close (s); - return -1; - } - - return s; + if (::connect (s, (struct sockaddr *) &sin, sizeof (sin)) < 0) { + ::close (s); + return -1; + } + return s; } -static int -rtp_connect (char *hostname, int port) -{ - struct sockaddr_in sin; - struct timeval tv; - int err, err_len; - int rxsockbufsz; - int s; - fd_set set; +int Rtp_Rtsp_Session::rtp_connect (const char *hostname, int port) const { + struct sockaddr_in sin; + struct timeval tv; + int err, err_len; + int rxsockbufsz; + int s; + fd_set set; - if (port <= 1023) - return -1; + if (port <= 1023) return -1; - s = socket (PF_INET, SOCK_DGRAM, 0); - if (s == -1) - return -1; + s = ::socket (PF_INET, SOCK_DGRAM, 0); + if (s == -1) return -1; - sin.sin_family = AF_INET; - if (!hostname || !strcmp (hostname, "0.0.0.0")) - sin.sin_addr.s_addr = htonl (INADDR_ANY); - else + sin.sin_family = AF_INET; + if (!hostname || !strcmp (hostname, "0.0.0.0")) + sin.sin_addr.s_addr = htonl (INADDR_ANY); + else #ifndef HAVE_WINSOCK2 #ifdef USE_ATON - inet_aton (hostname, &sin.sin_addr); + ::inet_aton (hostname, &sin.sin_addr); #else - inet_pton (AF_INET, hostname, &sin.sin_addr); + ::inet_pton (AF_INET, hostname, &sin.sin_addr); #endif #else - sin.sin_addr.s_addr = htonl (INADDR_ANY); + sin.sin_addr.s_addr = ::htonl (INADDR_ANY); #endif - sin.sin_port = htons (port); + sin.sin_port = htons (port); - /* Increase the socket rx buffer size to maximum -- this is UDP */ - rxsockbufsz = 240 * 1024; - if (setsockopt (s, SOL_SOCKET, SO_RCVBUF, - &rxsockbufsz, sizeof (rxsockbufsz))) - MSG_ERR("Couldn't set receive socket buffer size\n"); + /* Increase the socket rx buffer size to maximum -- this is UDP */ + rxsockbufsz = 240 * 1024; + if (::setsockopt (s, SOL_SOCKET, SO_RCVBUF, &rxsockbufsz, sizeof (rxsockbufsz))) + MSG_ERR("Couldn't set receive socket buffer size\n"); - /* if multicast address, add membership */ - if ((ntohl (sin.sin_addr.s_addr) >> 28) == 0xe) - { - struct ip_mreq mcast; - mcast.imr_multiaddr.s_addr = sin.sin_addr.s_addr; - mcast.imr_interface.s_addr = 0; + /* if multicast address, add membership */ + if ((::ntohl (sin.sin_addr.s_addr) >> 28) == 0xe) { + struct ip_mreq mcast; + mcast.imr_multiaddr.s_addr = sin.sin_addr.s_addr; + mcast.imr_interface.s_addr = 0; - if (setsockopt (s, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mcast, sizeof (mcast))) - { - MSG_ERR("IP_ADD_MEMBERSHIP failed\n"); - close (s); - return -1; + if (::setsockopt (s, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mcast, sizeof (mcast))) { + MSG_ERR("IP_ADD_MEMBERSHIP failed\n"); + ::close (s); + return -1; + } } - } - /* datagram socket */ - if (bind (s, (struct sockaddr *) &sin, sizeof (sin))) - { + /* datagram socket */ + if (::bind (s, (struct sockaddr *) &sin, sizeof (sin))) { #ifndef HAVE_WINSOCK2 - if (errno != EINPROGRESS) + if (errno != EINPROGRESS) #else - if (WSAGetLastError() != WSAEINPROGRESS) + if (WSAGetLastError() != WSAEINPROGRESS) #endif - { - MSG_ERR("bind: %s\n", strerror (errno)); - close (s); - return -1; + { + MSG_ERR("bind: %s\n", strerror (errno)); + ::close (s); + return -1; + } } - } - tv.tv_sec = 0; - tv.tv_usec = (1 * 1000000); /* 1 second timeout */ + tv.tv_sec = 0; + tv.tv_usec = (1 * 1000000); /* 1 second timeout */ - FD_ZERO (&set); - FD_SET (s, &set); + FD_ZERO (&set); + FD_SET (s, &set); - err = select (s + 1, &set, NULL, NULL, &tv); - if (err < 0) - { - MSG_ERR("Select failed: %s\n", strerror (errno)); - close (s); - return -1; - } - else if (err == 0) - { - MSG_ERR("Timeout! No data from host %s\n", hostname); - close (s); - return -1; - } + err = ::select (s + 1, &set, NULL, NULL, &tv); + if (err < 0) { + MSG_ERR("Select failed: %s\n", strerror (errno)); + ::close (s); + return -1; + } else if (err == 0) { + MSG_ERR("Timeout! No data from host %s\n", hostname); + ::close (s); + return -1; + } - err_len = sizeof (err); - getsockopt (s, SOL_SOCKET, SO_ERROR, &err, (socklen_t *) &err_len); - if (err) - { - MSG_ERR("Socket error: %d\n", err); - close (s); - return -1; - } - - return s; + err_len = sizeof (err); + ::getsockopt (s, SOL_SOCKET, SO_ERROR, &err, (socklen_t *) &err_len); + if (err) { + MSG_ERR("Socket error: %d\n", err); + ::close (s); + return -1; + } + return s; } -static int -is_multicast_address (char *addr) -{ - struct sockaddr_in sin; +int Rtp_Rtsp_Session::is_multicast_address (const char *addr) const { + struct sockaddr_in sin; - if (!addr) - return -1; + if (!addr) return -1; + sin.sin_family = AF_INET; - sin.sin_family = AF_INET; - #ifndef HAVE_WINSOCK2 #ifdef USE_ATON - inet_aton (addr, &sin.sin_addr); + ::inet_aton (addr, &sin.sin_addr); #else - inet_pton (AF_INET, addr, &sin.sin_addr); + ::inet_pton (AF_INET, addr, &sin.sin_addr); #endif #else sin.sin_addr.s_addr = htonl (INADDR_ANY); #endif - - if ((ntohl (sin.sin_addr.s_addr) >> 28) == 0xe) - return 1; - - return 0; + if ((::ntohl (sin.sin_addr.s_addr) >> 28) == 0xe) return 1; + return 0; } -struct rtp_rtsp_session_t * -rtp_setup_and_play (rtsp_t *rtsp_session) -{ - struct rtp_rtsp_session_t* rtp_session = NULL; - const fsdp_media_description_t *med_dsc = NULL; - char temp_buf[MAX_LENGTH + 1]; - char npt[256]; +Rtp_Rtsp_Session* Rtp_Rtsp_Session::setup_and_play (Rtsp& rtsp) { + struct Rtp_Rtsp_Session* rtp_session = NULL; + const fsdp_media_description_t *med_dsc = NULL; + char temp_buf[MAX_LENGTH + 1]; + char npt[256]; - char* answer; - char* sdp; - char *server_addr = NULL; - char *destination = NULL; + char* answer; + char* sdp; + char *server_addr = NULL; + char *destination = NULL; - int statut; - int content_length = 0; - int is_multicast = 0; + int statut; + int content_length = 0; + int is_multicast = 0; - fsdp_description_t *dsc = NULL; - fsdp_error_t result; + fsdp_description_t *dsc = NULL; + fsdp_error_t result; - int client_rtp_port = -1; - int client_rtcp_port = -1; - int server_rtp_port = -1; - int server_rtcp_port = -1; - int rtp_sock = -1; - int rtcp_sock = -1; + int client_rtp_port = -1; + int client_rtcp_port = -1; + int server_rtp_port = -1; + int server_rtcp_port = -1; + int rtp_sock = -1; + int rtcp_sock = -1; /* 1. send a RTSP DESCRIBE request to server */ - rtsp_schedule_field (rtsp_session, RTSP_ACCEPT_SDP); - statut = rtsp_request_describe (rtsp_session, NULL); - if (statut < 200 || statut > 299) - return NULL; + rtsp.schedule_field (RTSP_ACCEPT_SDP); + statut = rtsp.request_describe (NULL); + if (statut < 200 || statut > 299) return NULL; - answer = rtsp_search_answers (rtsp_session, RTSP_CONTENT_LENGTH); - if (answer) - content_length = atoi (answer); - else - return NULL; + answer = rtsp.search_answers (RTSP_CONTENT_LENGTH); + if (answer) content_length = atoi (answer); + else return NULL; - answer = rtsp_search_answers (rtsp_session, RTSP_CONTENT_TYPE); - if (!answer || !strstr (answer, RTSP_APPLICATION_SDP)) - return NULL; + answer = rtsp.search_answers (RTSP_CONTENT_TYPE); + if (!answer || !strstr (answer, RTSP_APPLICATION_SDP)) return NULL; - /* 2. read SDP message from server */ - sdp = (char *) mp_malloc (content_length + 1); - if (rtsp_read_data (rtsp_session, sdp, content_length) <= 0) - { - delete sdp; - return NULL; - } - sdp[content_length] = 0; + /* 2. read SDP message from server */ + sdp = (char *) mp_malloc (content_length + 1); + if (rtsp.read_data (sdp, content_length) <= 0) { + delete sdp; + return NULL; + } + sdp[content_length] = 0; - /* 3. parse SDP message */ - dsc = fsdp_description_new (); - result = fsdp_parse (sdp, dsc); - if (result != FSDPE_OK) - { + /* 3. parse SDP message */ + dsc = fsdp_description_new (); + result = fsdp_parse (sdp, dsc); + if (result != FSDPE_OK) { + delete sdp; + fsdp_description_delete (dsc); + return NULL; + } + MSG_V("SDP:\n%s\n", sdp); delete sdp; - fsdp_description_delete (dsc); - return NULL; - } - MSG_V("SDP:\n%s\n", sdp); - delete sdp; - /* 4. check for number of media streams: only one is supported */ - if (fsdp_get_media_count (dsc) != 1) - { - MSG_ERR("A single media stream only is supported atm.\n"); - fsdp_description_delete (dsc); - return NULL; - } + /* 4. check for number of media streams: only one is supported */ + if (fsdp_get_media_count (dsc) != 1) { + MSG_ERR("A single media stream only is supported atm.\n"); + fsdp_description_delete (dsc); + return NULL; + } - /* 5. set the Normal Play Time parameter - * use range provided by server in SDP or start now if empty */ - sprintf (npt, RTSP_RANGE); - if (fsdp_get_range (dsc)) - strcat (npt, fsdp_get_range (dsc)); - else - strcat (npt, RTSP_NPT_NOW); + /* 5. set the Normal Play Time parameter + * use range provided by server in SDP or start now if empty */ + sprintf (npt, RTSP_RANGE); + if (fsdp_get_range (dsc)) strcat (npt, fsdp_get_range (dsc)); + else strcat (npt, RTSP_NPT_NOW); - /* 5. check for a valid media stream */ - med_dsc = fsdp_get_media (dsc, 0); - if (!med_dsc) - { - fsdp_description_delete (dsc); - return NULL; - } + /* 5. check for a valid media stream */ + med_dsc = fsdp_get_media (dsc, 0); + if (!med_dsc) { + fsdp_description_delete (dsc); + return NULL; + } + /* 6. parse the `m=<media> <port> <transport> <fmt list>' line */ + /* check for an A/V media */ + if (fsdp_get_media_type (med_dsc) != FSDP_MEDIA_VIDEO && + fsdp_get_media_type (med_dsc) != FSDP_MEDIA_AUDIO) { + fsdp_description_delete (dsc); + return NULL; + } - /* 6. parse the `m=<media> <port> <transport> <fmt list>' line */ + /* only RTP/AVP transport method is supported right now */ + if (fsdp_get_media_transport_protocol (med_dsc) != FSDP_TP_RTP_AVP) { + fsdp_description_delete (dsc); + return NULL; + } - /* check for an A/V media */ - if (fsdp_get_media_type (med_dsc) != FSDP_MEDIA_VIDEO && - fsdp_get_media_type (med_dsc) != FSDP_MEDIA_AUDIO) - { - fsdp_description_delete (dsc); - return NULL; - } + /* only MPEG-TS is supported at the moment */ + if (!strstr (fsdp_get_media_format (med_dsc, 0), + RTSP_MEDIA_CONTAINER_MPEG_TS)) { + fsdp_description_delete (dsc); + return NULL; + } - /* only RTP/AVP transport method is supported right now */ - if (fsdp_get_media_transport_protocol (med_dsc) != FSDP_TP_RTP_AVP) - { - fsdp_description_delete (dsc); - return NULL; - } + /* get client port (if any) advised by server */ + client_rtp_port = fsdp_get_media_port (med_dsc); + if (client_rtp_port == -1) { + fsdp_description_delete (dsc); + return NULL; + } - /* only MPEG-TS is supported at the moment */ - if (!strstr (fsdp_get_media_format (med_dsc, 0), - RTSP_MEDIA_CONTAINER_MPEG_TS)) - { - fsdp_description_delete (dsc); - return NULL; - } + /* if client_rtp_port = 0 => let client randomly pick one */ + if (client_rtp_port == 0) { + /* TODO: we should check if the port is in use first */ + if (rtp_session->rtsp_port) client_rtp_port = rtp_session->rtsp_port; + else client_rtp_port = RTSP_DEFAULT_PORT; + } - /* get client port (if any) advised by server */ - client_rtp_port = fsdp_get_media_port (med_dsc); - if (client_rtp_port == -1) - { - fsdp_description_delete (dsc); - return NULL; - } + /* RTCP port generally is RTP port + 1 */ + client_rtcp_port = client_rtp_port + 1; - /* if client_rtp_port = 0 => let client randomly pick one */ - if (client_rtp_port == 0) - { - /* TODO: we should check if the port is in use first */ - if (rtsp_port) - client_rtp_port = rtsp_port; - else - client_rtp_port = RTSP_DEFAULT_PORT; - } + MSG_V("RTP Port from SDP appears to be: %d\n", client_rtp_port); + MSG_V("RTCP Port from SDP appears to be: %d\n", client_rtcp_port); - /* RTCP port generally is RTP port + 1 */ - client_rtcp_port = client_rtp_port + 1; + /* 7. parse the `c=<network type> <addr type> <connection address>' line */ + /* check for a valid media network type (inet) */ + if (fsdp_get_media_network_type (med_dsc) != FSDP_NETWORK_TYPE_INET) { + /* no control for media: try global one instead */ + if (fsdp_get_global_conn_network_type (dsc) != FSDP_NETWORK_TYPE_INET) { + fsdp_description_delete (dsc); + return NULL; + } + } - MSG_V("RTP Port from SDP appears to be: %d\n", client_rtp_port); - MSG_V("RTCP Port from SDP appears to be: %d\n", client_rtcp_port); + /* only IPv4 is supported atm. */ + if (fsdp_get_media_address_type (med_dsc) != FSDP_ADDRESS_TYPE_IPV4) { + /* no control for media: try global one instead */ + if (fsdp_get_global_conn_address_type (dsc) != FSDP_ADDRESS_TYPE_IPV4) { + fsdp_description_delete (dsc); + return NULL; + } + } - /* 7. parse the `c=<network type> <addr type> <connection address>' line */ - - /* check for a valid media network type (inet) */ - if (fsdp_get_media_network_type (med_dsc) != FSDP_NETWORK_TYPE_INET) - { - /* no control for media: try global one instead */ - if (fsdp_get_global_conn_network_type (dsc) != FSDP_NETWORK_TYPE_INET) - { - fsdp_description_delete (dsc); - return NULL; + /* get the media server address to connect to */ + if (fsdp_get_media_address (med_dsc)) server_addr = mp_strdup (fsdp_get_media_address (med_dsc)); + else if (fsdp_get_global_conn_address (dsc)) { + /* no control for media: try global one instead */ + server_addr = mp_strdup (fsdp_get_global_conn_address (dsc)); } - } - /* only IPv4 is supported atm. */ - if (fsdp_get_media_address_type (med_dsc) != FSDP_ADDRESS_TYPE_IPV4) - { - /* no control for media: try global one instead */ - if (fsdp_get_global_conn_address_type (dsc) != FSDP_ADDRESS_TYPE_IPV4) - { - fsdp_description_delete (dsc); - return NULL; + if (!server_addr) { + fsdp_description_delete (dsc); + return NULL; } - } - /* get the media server address to connect to */ - if (fsdp_get_media_address (med_dsc)) - server_addr = mp_strdup (fsdp_get_media_address (med_dsc)); - else if (fsdp_get_global_conn_address (dsc)) - { - /* no control for media: try global one instead */ - server_addr = mp_strdup (fsdp_get_global_conn_address (dsc)); - } + /* check for a UNICAST or MULTICAST address to connect to */ + is_multicast = rtp_session->is_multicast_address (server_addr); - if (!server_addr) - { - fsdp_description_delete (dsc); - return NULL; - } + /* 8. initiate an RTP session */ + rtp_session = new(zeromem) Rtp_Rtsp_Session; + if (!rtp_session) { + delete server_addr; + fsdp_description_delete (dsc); + return NULL; + } - /* check for a UNICAST or MULTICAST address to connect to */ - is_multicast = is_multicast_address (server_addr); - - /* 8. initiate an RTP session */ - rtp_session = rtp_session_new (); - if (!rtp_session) - { - delete server_addr; + /* get the media control URL */ + if (fsdp_get_media_control (med_dsc, 0)) + rtp_session->control_url = mp_strdup (fsdp_get_media_control (med_dsc, 0)); fsdp_description_delete (dsc); - return NULL; - } + if (!rtp_session->control_url) { + delete server_addr; + delete rtp_session; + return NULL; + } - /* get the media control URL */ - if (fsdp_get_media_control (med_dsc, 0)) - rtp_session->control_url = mp_strdup (fsdp_get_media_control (med_dsc, 0)); - fsdp_description_delete (dsc); - if (!rtp_session->control_url) - { - delete server_addr; - rtp_session_free (rtp_session); - return NULL; - } - - /* 9. create the payload for RTSP SETUP request */ - memset (temp_buf, '\0', MAX_LENGTH); - snprintf (temp_buf, MAX_LENGTH, + /* 9. create the payload for RTSP SETUP request */ + memset (temp_buf, '\0', MAX_LENGTH); + snprintf (temp_buf, MAX_LENGTH, RTSP_TRANSPORT_REQUEST, is_multicast ? RTSP_TRANSPORT_MULTICAST : RTSP_TRANSPORT_UNICAST, is_multicast ? RTSP_MULTICAST_PORT : RTSP_UNICAST_CLIENT_PORT, client_rtp_port, client_rtcp_port); - MSG_V("RTSP Transport: %s\n", temp_buf); + MSG_V("RTSP Transport: %s\n", temp_buf); - rtsp_unschedule_field (rtsp_session, RTSP_SESSION); - rtsp_schedule_field (rtsp_session, temp_buf); + rtsp.unschedule_field (RTSP_SESSION); + rtsp.schedule_field (temp_buf); - /* 10. check for the media control URL type and initiate RTSP SETUP */ - if (!strncmp (rtp_session->control_url, "rtsp://", 7)) /* full URL */ - statut = rtsp_request_setup (rtsp_session, - rtp_session->control_url, NULL); - else /* relative URL */ - statut = rtsp_request_setup (rtsp_session, - NULL, rtp_session->control_url); + /* 10. check for the media control URL type and initiate RTSP SETUP */ + if (!strncmp (rtp_session->control_url, "rtsp://", 7)) /* full URL */ + statut = rtsp.request_setup (rtp_session->control_url, NULL); + else /* relative URL */ + statut = rtsp.request_setup (NULL, rtp_session->control_url); - if (statut < 200 || statut > 299) - { - delete server_addr; - rtp_session_free (rtp_session); - return NULL; - } + if (statut < 200 || statut > 299) { + delete server_addr; + delete rtp_session; + return NULL; + } - /* 11. parse RTSP SETUP response: we need it to actually determine - * the real address and port to connect to */ - answer = rtsp_search_answers (rtsp_session, RTSP_TRANSPORT); - if (!answer) - { - delete server_addr; - rtp_session_free (rtp_session); - return NULL; - } + /* 11. parse RTSP SETUP response: we need it to actually determine + * the real address and port to connect to */ + answer = rtsp.search_answers (RTSP_TRANSPORT); + if (!answer) { + delete server_addr; + delete rtp_session; + return NULL; + } - /* check for RTP and RTCP ports to bind according to how request was done */ - is_multicast = 0; - if (strstr (answer, RTSP_TRANSPORT_MULTICAST)) - is_multicast = 1; + /* check for RTP and RTCP ports to bind according to how request was done */ + is_multicast = 0; + if (strstr (answer, RTSP_TRANSPORT_MULTICAST)) is_multicast = 1; - if (is_multicast) - parse_port (answer, RTSP_MULTICAST_PORT, + if (is_multicast) + rtp_session->parse_port (answer, RTSP_MULTICAST_PORT, + &client_rtp_port, &client_rtcp_port); + else { + rtp_session->parse_port (answer, RTSP_UNICAST_CLIENT_PORT, &client_rtp_port, &client_rtcp_port); - else - { - parse_port (answer, RTSP_UNICAST_CLIENT_PORT, - &client_rtp_port, &client_rtcp_port); - parse_port (answer, RTSP_UNICAST_SERVER_PORT, + rtp_session->parse_port (answer, RTSP_UNICAST_SERVER_PORT, &server_rtp_port, &server_rtcp_port); - } + } - /* now check network settings as determined by server */ - if (rtsp_destination) - destination = mp_strdup (rtsp_destination); - else - destination = parse_destination (answer); - if (!destination) - destination = mp_strdup (server_addr); - delete server_addr; + /* now check network settings as determined by server */ + if (rtp_session->rtsp_destination) destination = mp_strdup (rtp_session->rtsp_destination); + else destination = rtp_session->parse_destination (answer); + if (!destination) destination = mp_strdup (server_addr); + delete server_addr; - MSG_V("RTSP Destination: %s\n" + MSG_V("RTSP Destination: %s\n" "Client RTP port : %d\n" "Client RTCP port : %d\n" "Server RTP port : %d\n" @@ -676,29 +548,28 @@ , server_rtp_port , server_rtcp_port); - /* 12. performs RTSP PLAY request */ - rtsp_schedule_field (rtsp_session, npt); - statut = rtsp_request_play (rtsp_session, NULL); - if (statut < 200 || statut > 299) - { + /* 12. performs RTSP PLAY request */ + rtsp.schedule_field (npt); + statut = rtsp.request_play (NULL); + if (statut < 200 || statut > 299) { + delete destination; + delete rtp_session; + return NULL; + } + + /* 13. create RTP and RTCP connections */ + rtp_sock = rtp_session->rtp_connect (destination, client_rtp_port); + rtcp_sock = rtp_session->rtcp_connect (client_rtcp_port, server_rtcp_port, destination); + rtp_session->set_fd (rtp_sock, rtcp_sock); delete destination; - rtp_session_free (rtp_session); - return NULL; - } - /* 13. create RTP and RTCP connections */ - rtp_sock = rtp_connect (destination, client_rtp_port); - rtcp_sock = rtcp_connect (client_rtcp_port, server_rtcp_port, destination); - rtp_session_set_fd (rtp_session, rtp_sock, rtcp_sock); - delete destination; + MSG_V("RTP Sock : %d\nRTCP Sock : %d\n",rtp_session->rtp_socket, rtp_session->rtcp_socket); - MSG_V("RTP Sock : %d\nRTCP Sock : %d\n",rtp_session->rtp_socket, rtp_session->rtcp_socket); - - if (rtp_session->rtp_socket == -1) - { - rtp_session_free (rtp_session); - return NULL; - } - - return rtp_session; + if (rtp_session->rtp_socket == -1) { + delete rtp_session; + return NULL; + } + return rtp_session; } +int Rtp_Rtsp_Session::get_rtp_socket() const { return rtp_socket; } +} // namespace mpxp Modified: mplayerxp/libmpstream2/librtsp/rtsp_rtp.h =================================================================== --- mplayerxp/libmpstream2/librtsp/rtsp_rtp.h 2012-12-18 13:04:29 UTC (rev 572) +++ mplayerxp/libmpstream2/librtsp/rtsp_rtp.h 2012-12-18 15:09:54 UTC (rev 573) @@ -23,19 +23,31 @@ #include "rtsp.h" +namespace mpxp { #define MAX_PREVIEW_SIZE 4096 + class Rtp_Rtsp_Session : public Opaque { + public: + Rtp_Rtsp_Session(); + virtual ~Rtp_Rtsp_Session(); -struct rtp_rtsp_session_t { - int rtp_socket; - int rtcp_socket; - char *control_url; - int count; -}; + static Rtp_Rtsp_Session* setup_and_play(Rtsp& rtsp_session); + virtual void rtcp_send_rr (Rtsp& s); + virtual int get_rtp_socket() const; + private: + void set_fd (int rtp_sock, int rtcp_sock); + int parse_port (const char *line, const char *param, int *rtp_port, int *rtcp_port) const; + char* parse_destination (const char *line) const; + int rtcp_connect (int client_port, int server_port, const char* server_hostname) const; + int rtp_connect (const char *hostname, int port) const; + int is_multicast_address (const char *addr) const; -struct rtp_rtsp_session_t *rtp_setup_and_play (rtsp_t* rtsp_session); -off_t rtp_read (struct rtp_rtsp_session_t* st, char *buf, off_t length); -void rtp_session_free (struct rtp_rtsp_session_t *st); -void rtcp_send_rr (rtsp_t *s, struct rtp_rtsp_session_t *st); - + int rtp_socket; + int rtcp_socket; + char* control_url; + int count; + int rtsp_port; + char* rtsp_destination; + }; +} // names... [truncated message content] |
From: <nic...@us...> - 2012-12-18 16:08:03
|
Revision: 574 http://mplayerxp.svn.sourceforge.net/mplayerxp/?rev=574&view=rev Author: nickols_k Date: 2012-12-18 16:07:55 +0000 (Tue, 18 Dec 2012) Log Message: ----------- convert static struct rtpbuffer rtpbuf into class Rtp Modified Paths: -------------- mplayerxp/libmpstream2/librtsp/rtsp_session.cpp mplayerxp/libmpstream2/librtsp/rtsp_session.h mplayerxp/libmpstream2/network_real_rtsp.cpp mplayerxp/libmpstream2/network_rtp.cpp mplayerxp/libmpstream2/network_rtp.h mplayerxp/libmpstream2/network_rtsp.cpp mplayerxp/libmpstream2/rtp.cpp mplayerxp/libmpstream2/rtp.h Modified: mplayerxp/libmpstream2/librtsp/rtsp_session.cpp =================================================================== --- mplayerxp/libmpstream2/librtsp/rtsp_session.cpp 2012-12-18 15:09:54 UTC (rev 573) +++ mplayerxp/libmpstream2/librtsp/rtsp_session.cpp 2012-12-18 16:07:55 UTC (rev 574) @@ -83,10 +83,7 @@ char *mrl_line = NULL; rmff_header_t *h; - rtsp_session = new Rtsp_Session; - rtsp_session->s = NULL; - rtsp_session->real_session = NULL; - rtsp_session->rtp_session = NULL; + rtsp_session = new(zeromem) Rtsp_Session; //connect: *redir = 0; @@ -199,6 +196,8 @@ } rtsp_session->rtp_session = Rtp_Rtsp_Session::setup_and_play (*rtsp_session->s); + tcp=rtsp_session->rtp_session->get_rtp_socket(); + rtsp_session->rtp = new(zeromem) Rtp(tcp); /* neither a Real or an RTP server */ if (!rtsp_session->rtp_session) @@ -216,7 +215,7 @@ return rtsp_session; } -int Rtsp_Session::read(Tcp& tcp,char *data, int len) { +int Rtsp_Session::read(char *data, int len) { if (real_session) { int to_copy=len; @@ -256,9 +255,7 @@ return len; } else if (rtp_session) { int l = 0; - Tcp _tcp(tcp.get_libinput(),rtp_session->get_rtp_socket()); - - l = read_rtp_from_server (_tcp, data, len); + l = rtp->read_from_server (data, len); /* send RTSP and RTCP keepalive */ rtp_session->rtcp_send_rr (*s); if (l == 0) end (); @@ -270,9 +267,11 @@ void Rtsp_Session::end() { s->close(); if (real_session) free_real_rtsp_session (real_session); + real_session = NULL; if (rtp_session) delete rtp_session; + rtp_session = NULL; } Rtsp_Session::Rtsp_Session() {} -Rtsp_Session::~Rtsp_Session() {} -} // namespace mpxp \ No newline at end of file +Rtsp_Session::~Rtsp_Session() { end(); if(rtp) delete rtp; } +} // namespace mpxp Modified: mplayerxp/libmpstream2/librtsp/rtsp_session.h =================================================================== --- mplayerxp/libmpstream2/librtsp/rtsp_session.h 2012-12-18 15:09:54 UTC (rev 573) +++ mplayerxp/libmpstream2/librtsp/rtsp_session.h 2012-12-18 16:07:55 UTC (rev 574) @@ -33,7 +33,7 @@ #ifndef HAVE_RTSP_SESSION_H #define HAVE_RTSP_SESSION_H - +#include "../rtp.h" struct real_rtsp_session_t; namespace mpxp { class Rtp_Rtsp_Session; @@ -45,12 +45,13 @@ static Rtsp_Session* start(Tcp& tcp, char **mrl, const std::string& path, const std::string& host, int port, int *redir, uint32_t bandwidth, const std::string& user, const std::string& pass); - virtual int read(Tcp& tcp,char *data, int len); + virtual int read(char *data, int len); virtual void end(); private: Rtsp* s; real_rtsp_session_t*real_session; Rtp_Rtsp_Session* rtp_session; + Rtp* rtp; }; } // namespace mpxp #endif Modified: mplayerxp/libmpstream2/network_real_rtsp.cpp =================================================================== --- mplayerxp/libmpstream2/network_real_rtsp.cpp 2012-12-18 15:09:54 UTC (rev 573) +++ mplayerxp/libmpstream2/network_real_rtsp.cpp 2012-12-18 16:07:55 UTC (rev 574) @@ -15,7 +15,7 @@ int RealRtsp_Networking::read( Tcp& tcp, char *_buffer, int size) { Rtsp_Session& rtsp=*static_cast<Rtsp_Session*>(data); - return rtsp.read(tcp, _buffer, size); + return rtsp.read(_buffer, size); } Networking* RealRtsp_Networking::start( Tcp& tcp, network_protocol_t& protocol ) { Modified: mplayerxp/libmpstream2/network_rtp.cpp =================================================================== --- mplayerxp/libmpstream2/network_rtp.cpp 2012-12-18 15:09:54 UTC (rev 573) +++ mplayerxp/libmpstream2/network_rtp.cpp 2012-12-18 16:07:55 UTC (rev 574) @@ -15,7 +15,7 @@ } int Rtp_Networking::read(Tcp& tcp, char *_buffer, int size) { - return read_rtp_from_server(tcp, _buffer, size ); + return rtp->read_from_server(_buffer, size ); } Networking* Rtp_Networking::start(Tcp& tcp,network_protocol_t& protocol, int raw_udp ) { @@ -31,6 +31,7 @@ rv->prebuffer_size = 64*1024; // KBytes rv->buffering = 0; rv->status = networking_playing_e; + rv->rtp = new(zeromem) Rtp(tcp); return rv; } Modified: mplayerxp/libmpstream2/network_rtp.h =================================================================== --- mplayerxp/libmpstream2/network_rtp.h 2012-12-18 15:09:54 UTC (rev 573) +++ mplayerxp/libmpstream2/network_rtp.h 2012-12-18 16:07:55 UTC (rev 574) @@ -2,6 +2,7 @@ #define __NETWORK_RP_H_INCLUDED #include "network_nop.h" +#include "rtp.h" namespace mpxp { struct Rtp_Networking : public Nop_Networking { @@ -13,6 +14,7 @@ virtual int seek( Tcp& fd, off_t pos); private: Rtp_Networking(); + Rtp* rtp; }; } // namespace mpxp #endif Modified: mplayerxp/libmpstream2/network_rtsp.cpp =================================================================== --- mplayerxp/libmpstream2/network_rtsp.cpp 2012-12-18 15:09:54 UTC (rev 573) +++ mplayerxp/libmpstream2/network_rtsp.cpp 2012-12-18 16:07:55 UTC (rev 574) @@ -69,7 +69,7 @@ int Rtsp_Networking::read(Tcp& tcp, char *_buffer, int size) { Rtsp_Session& rtsp = *static_cast<Rtsp_Session*>(data); - return rtsp.read (tcp, buffer, size); + return rtsp.read (buffer, size); } Rtsp_Networking::Rtsp_Networking() {} Modified: mplayerxp/libmpstream2/rtp.cpp =================================================================== --- mplayerxp/libmpstream2/rtp.cpp 2012-12-18 15:09:54 UTC (rev 573) +++ mplayerxp/libmpstream2/rtp.cpp 2012-12-18 16:07:55 UTC (rev 574) @@ -41,6 +41,7 @@ // write rtp packets in cache // get rtp packets reordered +namespace mpxp { #define MAXRTPPACKETSIN 32 // The number of max packets being reordered struct rtpbits { @@ -59,17 +60,6 @@ int ssrc; /* random */ }; -struct rtpbuffer -{ - unsigned char data[MAXRTPPACKETSIN][STREAM_BUFFER_SIZE]; - unsigned short seq[MAXRTPPACKETSIN]; - unsigned short len[MAXRTPPACKETSIN]; - unsigned short first; -}; -static struct rtpbuffer rtpbuf; - -static int getrtp2(Tcp& fd, struct rtpheader *rh, char** data, int* lengthData); - // RTP Reordering functions // Algorithm works as follows: // If next packet is in sequence just copy it to buffer @@ -78,178 +68,167 @@ // and keeps track of expected sequence // Initialize rtp cache -static void rtp_cache_reset(unsigned short seq) -{ - int i; +void Rtp::cache_reset(unsigned short seq) { + int i; - rtpbuf.first = 0; - rtpbuf.seq[0] = ++seq; + rtp_first = 0; + rtp_seq[0] = ++seq; - for (i=0; i<MAXRTPPACKETSIN; i++) { - rtpbuf.len[i] = 0; - } + for (i=0; i<MAXRTPPACKETSIN; i++) rtp_len[i] = 0; } // Write in a cache the rtp packet in right rtp sequence order -static int rtp_cache(Tcp& tcp, char *buffer, int length) -{ - struct rtpheader rh; - int newseq; - char *data; - unsigned short seq; - static int is_first = 1; +int Rtp::cache(char *buffer, int length) { + struct rtpheader rh; + int newseq; + char *data; + unsigned short seq; + static int is_first = 1; - getrtp2(tcp, &rh, &data, &length); - if(!length) - return 0; - seq = rh.b.sequence; + getrtp2(&rh, &data, &length); + if(!length) return 0; + seq = rh.b.sequence; - newseq = seq - rtpbuf.seq[rtpbuf.first]; + newseq = seq - rtp_seq[rtp_first]; - if ((newseq == 0) || is_first) - { - is_first = 0; + if ((newseq == 0) || is_first) { + is_first = 0; - rtpbuf.first = ( 1 + rtpbuf.first ) % MAXRTPPACKETSIN; - rtpbuf.seq[rtpbuf.first] = ++seq; - goto feed; - } + rtp_first = ( 1 + rtp_first ) % MAXRTPPACKETSIN; + rtp_seq[rtp_first] = ++seq; + goto feed; + } - if (newseq > MAXRTPPACKETSIN) - { - MSG_DBG2("Overrun(seq[%d]=%d seq=%d, newseq=%d)\n", rtpbuf.first, rtpbuf.seq[rtpbuf.first], seq, newseq); - rtp_cache_reset(seq); - goto feed; - } + if (newseq > MAXRTPPACKETSIN) { + MSG_DBG2("Overrun(seq[%d]=%d seq=%d, newseq=%d)\n", rtp_first, rtp_seq[rtp_first], seq, newseq); + cache_reset(seq); + goto feed; + } - if (newseq < 0) - { - int i; + if (newseq < 0) { + int i; - // Is it a stray packet re-sent to network? - for (i=0; i<MAXRTPPACKETSIN; i++) { - if (rtpbuf.seq[i] == seq) { - MSG_ERR("Stray packet (seq[%d]=%d seq=%d, newseq=%d found at %d)\n", rtpbuf.first, rtpbuf.seq[rtpbuf.first], seq, newseq, i); - return 0; // Yes, it is! - } - } - // Some heuristic to decide when to drop packet or to restart everything - if (newseq > -(3 * MAXRTPPACKETSIN)) { - MSG_ERR("Too Old packet (seq[%d]=%d seq=%d, newseq=%d)\n", rtpbuf.first, rtpbuf.seq[rtpbuf.first], seq, newseq); - return 0; // Yes, it is! - } + // Is it a stray packet re-sent to network? + for (i=0; i<MAXRTPPACKETSIN; i++) { + if (rtp_seq[i] == seq) { + MSG_ERR("Stray packet (seq[%d]=%d seq=%d, newseq=%d found at %d)\n", rtp_first, rtp_seq[rtp_first], seq, newseq, i); + return 0; // Yes, it is! + } + } + // Some heuristic to decide when to drop packet or to restart everything + if (newseq > -(3 * MAXRTPPACKETSIN)) { + MSG_ERR("Too Old packet (seq[%d]=%d seq=%d, newseq=%d)\n", rtp_first, rtp_seq[rtp_first], seq, newseq); + return 0; // Yes, it is! + } - MSG_ERR("Underrun(seq[%d]=%d seq=%d, newseq=%d)\n", rtpbuf.first, rtpbuf.seq[rtpbuf.first], seq, newseq); + MSG_ERR("Underrun(seq[%d]=%d seq=%d, newseq=%d)\n", rtp_first, rtp_seq[rtp_first], seq, newseq); - rtp_cache_reset(seq); - goto feed; - } + cache_reset(seq); + goto feed; + } - MSG_DBG3("Out of Seq (seq[%d]=%d seq=%d, newseq=%d)\n", rtpbuf.first, rtpbuf.seq[rtpbuf.first], seq, newseq); - newseq = ( newseq + rtpbuf.first ) % MAXRTPPACKETSIN; - memcpy (rtpbuf.data[newseq], data, length); - rtpbuf.len[newseq] = length; - rtpbuf.seq[newseq] = seq; + MSG_DBG3("Out of Seq (seq[%d]=%d seq=%d, newseq=%d)\n", rtp_first, rtp_seq[rtp_first], seq, newseq); + newseq = ( newseq + rtp_first ) % MAXRTPPACKETSIN; + memcpy (rtp_data[newseq], data, length); + rtp_len[newseq] = length; + rtp_seq[newseq] = seq; - return 0; + return 0; feed: - memcpy (buffer, data, length); - return length; + memcpy (buffer, data, length); + return length; } // Get next packet in cache // Look in cache to get first packet in sequence -static int rtp_get_next(Tcp& tcp, char *buffer, int length) -{ - int i; - unsigned short nextseq; +int Rtp::get_next(char *buffer, int length) { + int i; + unsigned short nextseq; - // If we have empty buffer we loop to fill it - for (i=0; i < MAXRTPPACKETSIN -3; i++) { - if (rtpbuf.len[rtpbuf.first] != 0) break; + // If we have empty buffer we loop to fill it + for (i=0; i < MAXRTPPACKETSIN -3; i++) { + if (rtp_len[rtp_first] != 0) break; - length = rtp_cache(tcp, buffer, length) ; + length = cache(buffer, length); - // returns on first packet in sequence - if (length > 0) { - return length; - } else if (length < 0) break; + // returns on first packet in sequence + if (length > 0) return length; + else if (length < 0) break; + // Only if length == 0 loop continues! + } - // Only if length == 0 loop continues! - } + i = rtp_first; + while (rtp_len[i] == 0) { + MSG_ERR("Lost packet %hu\n", rtp_seq[i]); + i = ( 1 + i ) % MAXRTPPACKETSIN; + if (rtp_first == i) break; + } + rtp_first = i; - i = rtpbuf.first; - while (rtpbuf.len[i] == 0) { - MSG_ERR("Lost packet %hu\n", rtpbuf.seq[i]); - i = ( 1 + i ) % MAXRTPPACKETSIN; - if (rtpbuf.first == i) break; - } - rtpbuf.first = i; + // Copy next non empty packet from cache + MSG_DBG3( "Getting rtp from cache [%d] %hu\n", rtp_first, rtp_seq[rtp_first]); + memcpy (buffer, rtp_data[rtp_first], rtp_len[rtp_first]); + length = rtp_len[rtp_first]; // can be zero? - // Copy next non empty packet from cache - MSG_DBG3( "Getting rtp from cache [%d] %hu\n", rtpbuf.first, rtpbuf.seq[rtpbuf.first]); - memcpy (buffer, rtpbuf.data[rtpbuf.first], rtpbuf.len[rtpbuf.first]); - length = rtpbuf.len[rtpbuf.first]; // can be zero? + // Reset fisrt slot and go next in cache + rtp_len[rtp_first] = 0; + nextseq = rtp_seq[rtp_first]; + rtp_first = ( 1 + rtp_first ) % MAXRTPPACKETSIN; + rtp_seq[rtp_first] = nextseq + 1; - // Reset fisrt slot and go next in cache - rtpbuf.len[rtpbuf.first] = 0; - nextseq = rtpbuf.seq[rtpbuf.first]; - rtpbuf.first = ( 1 + rtpbuf.first ) % MAXRTPPACKETSIN; - rtpbuf.seq[rtpbuf.first] = nextseq + 1; - - return length; + return length; } // Read next rtp packet using cache -int read_rtp_from_server(Tcp& tcp, char *buffer, int length) { - // Following test is ASSERT (i.e. uneuseful if code is correct) - if(buffer==NULL || length<STREAM_BUFFER_SIZE) { - MSG_ERR("RTP buffer invalid; no data return from network\n"); - return 0; - } +int Rtp::read_from_server(char *buffer, int length) { + // Following test is ASSERT (i.e. uneuseful if code is correct) + if(buffer==NULL || length<STREAM_BUFFER_SIZE) { + MSG_ERR("RTP buffer invalid; no data return from network\n"); + return 0; + } - // loop just to skip empty packets - while ((length = rtp_get_next(tcp, buffer, length)) == 0) { - MSG_ERR("Got empty packet from RTP cache!?\n"); - } - - return(length); + // loop just to skip empty packets + while ((length = get_next(buffer, length)) == 0) { + MSG_ERR("Got empty packet from RTP cache!?\n"); + } + return(length); } -static int getrtp2(Tcp& tcp, struct rtpheader *rh, char** data, int* lengthData) { - static char buf[1600]; - unsigned int intP; - char* charP = (char*) &intP; - int headerSize; - int lengthPacket; - lengthPacket=tcp.read((uint8_t*)(buf),1590); - if (lengthPacket<0) - MSG_ERR("rtp: socket read error\n"); - else if (lengthPacket<12) - MSG_ERR("rtp: packet too small (%d) to be an rtp frame (>12bytes)\n", lengthPacket); - if(lengthPacket<12) { - *lengthData = 0; - return 0; - } - rh->b.v = (unsigned int) ((buf[0]>>6)&0x03); - rh->b.p = (unsigned int) ((buf[0]>>5)&0x01); - rh->b.x = (unsigned int) ((buf[0]>>4)&0x01); - rh->b.cc = (unsigned int) ((buf[0]>>0)&0x0f); - rh->b.m = (unsigned int) ((buf[1]>>7)&0x01); - rh->b.pt = (unsigned int) ((buf[1]>>0)&0x7f); - intP = 0; - memcpy(charP+2,&buf[2],2); - rh->b.sequence = ntohl(intP); - intP = 0; - memcpy(charP,&buf[4],4); - rh->timestamp = ntohl(intP); +int Rtp::getrtp2(struct rtpheader *rh, char** data, int* lengthData) const { + static char buf[1600]; + unsigned int intP; + char* charP = (char*) &intP; + int headerSize; + int lengthPacket; + lengthPacket=tcp.read((uint8_t*)(buf),1590); + if (lengthPacket<0) MSG_ERR("rtp: socket read error\n"); + else if (lengthPacket<12) MSG_ERR("rtp: packet too small (%d) to be an rtp frame (>12bytes)\n", lengthPacket); + if(lengthPacket<12) { + *lengthData = 0; + return 0; + } + rh->b.v = (unsigned int) ((buf[0]>>6)&0x03); + rh->b.p = (unsigned int) ((buf[0]>>5)&0x01); + rh->b.x = (unsigned int) ((buf[0]>>4)&0x01); + rh->b.cc = (unsigned int) ((buf[0]>>0)&0x0f); + rh->b.m = (unsigned int) ((buf[1]>>7)&0x01); + rh->b.pt = (unsigned int) ((buf[1]>>0)&0x7f); + intP = 0; + memcpy(charP+2,&buf[2],2); + rh->b.sequence = ntohl(intP); + intP = 0; + memcpy(charP,&buf[4],4); + rh->timestamp = ntohl(intP); - headerSize = 12 + 4*rh->b.cc; /* in bytes */ + headerSize = 12 + 4*rh->b.cc; /* in bytes */ - *lengthData = lengthPacket - headerSize; - *data = (char*) buf + headerSize; + *lengthData = lengthPacket - headerSize; + *data = (char*) buf + headerSize; - return 0; + return 0; } +Rtp::Rtp(Tcp& _tcp):tcp(_tcp) {} +Rtp::~Rtp() {} +} // namespace mpxp Modified: mplayerxp/libmpstream2/rtp.h =================================================================== --- mplayerxp/libmpstream2/rtp.h 2012-12-18 15:09:54 UTC (rev 573) +++ mplayerxp/libmpstream2/rtp.h 2012-12-18 16:07:55 UTC (rev 574) @@ -4,11 +4,38 @@ * http://svn.mplayerhq.hu/mplayer/trunk/ * $Id: rtp.h,v 1.2 2007/11/17 12:43:37 nickols_k Exp $ */ - -#ifndef RTP_H -#define RTP_H +#ifndef __RTP_H_INCLUDED +#define __RTP_H_INCLUDED 1 #include "network.h" +#include "tcp.h" +#include <stdint.h> -int read_rtp_from_server(Tcp& fd, char *buffer, int length); +namespace mpxp { +// RTP reorder routines +// Also handling of repeated UDP packets (a bug of ExtremeNetworks switches firmware) +// rtpreord procedures +// write rtp packets in cache +// get rtp packets reordered +#define MAXRTPPACKETSIN 32 // The number of max packets being reordered + + class Rtp : public Opaque { + public: + Rtp(Tcp& tcp); + virtual ~Rtp(); + + virtual int read_from_server(char *buffer, int length); + private: + void cache_reset(unsigned short seq); + int cache(char *buffer, int length); + int get_next(char *buffer, int length); + int getrtp2(struct rtpheader *rh, char** data, int* lengthData) const; + + Tcp& tcp; + uint8_t rtp_data[MAXRTPPACKETSIN][STREAM_BUFFER_SIZE]; + uint16_t rtp_seq[MAXRTPPACKETSIN]; + uint16_t rtp_len[MAXRTPPACKETSIN]; + uint16_t rtp_first; + }; +} // namespace mpxp #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nic...@us...> - 2012-12-18 16:22:49
|
Revision: 575 http://mplayerxp.svn.sourceforge.net/mplayerxp/?rev=575&view=rev Author: nickols_k Date: 2012-12-18 16:22:42 +0000 (Tue, 18 Dec 2012) Log Message: ----------- rename Rtp -> Rtp_Cache Modified Paths: -------------- mplayerxp/libmpstream2/Makefile mplayerxp/libmpstream2/librtsp/rtsp_session.cpp mplayerxp/libmpstream2/librtsp/rtsp_session.h mplayerxp/libmpstream2/network_rtp.cpp mplayerxp/libmpstream2/network_rtp.h Added Paths: ----------- mplayerxp/libmpstream2/rtp_cache.cpp mplayerxp/libmpstream2/rtp_cache.h Removed Paths: ------------- mplayerxp/libmpstream2/rtp.cpp mplayerxp/libmpstream2/rtp.h Modified: mplayerxp/libmpstream2/Makefile =================================================================== --- mplayerxp/libmpstream2/Makefile 2012-12-18 16:07:55 UTC (rev 574) +++ mplayerxp/libmpstream2/Makefile 2012-12-18 16:22:42 UTC (rev 575) @@ -42,7 +42,7 @@ network_rtp.cpp \ network_rtsp.cpp \ pnm.cpp \ - rtp.cpp \ + rtp_cache.cpp \ tcp.cpp \ udp.cpp CXXSRCS += s_ftp.cpp \ Modified: mplayerxp/libmpstream2/librtsp/rtsp_session.cpp =================================================================== --- mplayerxp/libmpstream2/librtsp/rtsp_session.cpp 2012-12-18 16:07:55 UTC (rev 574) +++ mplayerxp/libmpstream2/librtsp/rtsp_session.cpp 2012-12-18 16:22:42 UTC (rev 575) @@ -49,7 +49,6 @@ #include "tcp.h" #include "url.h" -#include "rtp.h" #include "rtsp.h" #include "rtsp_rtp.h" #include "rtsp_session.h" @@ -197,7 +196,7 @@ rtsp_session->rtp_session = Rtp_Rtsp_Session::setup_and_play (*rtsp_session->s); tcp=rtsp_session->rtp_session->get_rtp_socket(); - rtsp_session->rtp = new(zeromem) Rtp(tcp); + rtsp_session->rtp = new(zeromem) Rtp_Cache(tcp); /* neither a Real or an RTP server */ if (!rtsp_session->rtp_session) Modified: mplayerxp/libmpstream2/librtsp/rtsp_session.h =================================================================== --- mplayerxp/libmpstream2/librtsp/rtsp_session.h 2012-12-18 16:07:55 UTC (rev 574) +++ mplayerxp/libmpstream2/librtsp/rtsp_session.h 2012-12-18 16:22:42 UTC (rev 575) @@ -33,7 +33,7 @@ #ifndef HAVE_RTSP_SESSION_H #define HAVE_RTSP_SESSION_H -#include "../rtp.h" +#include "../rtp_cache.h" struct real_rtsp_session_t; namespace mpxp { class Rtp_Rtsp_Session; @@ -51,7 +51,7 @@ Rtsp* s; real_rtsp_session_t*real_session; Rtp_Rtsp_Session* rtp_session; - Rtp* rtp; + Rtp_Cache* rtp; }; } // namespace mpxp #endif Modified: mplayerxp/libmpstream2/network_rtp.cpp =================================================================== --- mplayerxp/libmpstream2/network_rtp.cpp 2012-12-18 16:07:55 UTC (rev 574) +++ mplayerxp/libmpstream2/network_rtp.cpp 2012-12-18 16:22:42 UTC (rev 575) @@ -5,7 +5,6 @@ #include "udp.h" #include "tcp.h" #include "network_rtp.h" -#include "rtp.h" namespace mpxp { int Rtp_Networking::seek(Tcp& tcp, off_t pos) { @@ -31,7 +30,7 @@ rv->prebuffer_size = 64*1024; // KBytes rv->buffering = 0; rv->status = networking_playing_e; - rv->rtp = new(zeromem) Rtp(tcp); + rv->rtp = new(zeromem) Rtp_Cache(tcp); return rv; } Modified: mplayerxp/libmpstream2/network_rtp.h =================================================================== --- mplayerxp/libmpstream2/network_rtp.h 2012-12-18 16:07:55 UTC (rev 574) +++ mplayerxp/libmpstream2/network_rtp.h 2012-12-18 16:22:42 UTC (rev 575) @@ -2,7 +2,7 @@ #define __NETWORK_RP_H_INCLUDED #include "network_nop.h" -#include "rtp.h" +#include "rtp_cache.h" namespace mpxp { struct Rtp_Networking : public Nop_Networking { @@ -14,7 +14,7 @@ virtual int seek( Tcp& fd, off_t pos); private: Rtp_Networking(); - Rtp* rtp; + Rtp_Cache* rtp; }; } // namespace mpxp #endif Deleted: mplayerxp/libmpstream2/rtp.cpp =================================================================== --- mplayerxp/libmpstream2/rtp.cpp 2012-12-18 16:07:55 UTC (rev 574) +++ mplayerxp/libmpstream2/rtp.cpp 2012-12-18 16:22:42 UTC (rev 575) @@ -1,234 +0,0 @@ -#include "mp_config.h" -#include "osdep/mplib.h" -using namespace mpxp; -/* Imported from the dvbstream-0.2 project - * - * Modified for use with MPlayer, for details see the changelog at - * http://svn.mplayerhq.hu/mplayer/trunk/ - * $Id: rtp.c,v 1.4 2007/11/17 12:43:37 nickols_k Exp $ - */ - -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <stdlib.h> -#include <stdio.h> -#include <sys/types.h> -#include <ctype.h> - -#ifndef HAVE_WINSOCK2 -#include <netinet/in.h> -#include <sys/socket.h> -#include <arpa/inet.h> -#define closesocket close -#else -#include <winsock2.h> -#include <ws2tcpip.h> -#endif -#include <errno.h> -#include "stream.h" - -/* MPEG-2 TS RTP stack */ - -#define DEBUG 1 -#include "tcp.h" -#include "rtp.h" -#include "stream_msg.h" - -// RTP reorder routines -// Also handling of repeated UDP packets (a bug of ExtremeNetworks switches firmware) -// rtpreord procedures -// write rtp packets in cache -// get rtp packets reordered - -namespace mpxp { -#define MAXRTPPACKETSIN 32 // The number of max packets being reordered - -struct rtpbits { - unsigned int v:2; /* version: 2 */ - unsigned int p:1; /* is there padding appended: 0 */ - unsigned int x:1; /* number of extension headers: 0 */ - unsigned int cc:4; /* number of CSRC identifiers: 0 */ - unsigned int m:1; /* marker: 0 */ - unsigned int pt:7; /* payload type: 33 for MPEG2 TS - RFC 1890 */ - unsigned int sequence:16; /* sequence number: random */ -}; - -struct rtpheader { /* in network byte order */ - struct rtpbits b; - int timestamp; /* start: random */ - int ssrc; /* random */ -}; - -// RTP Reordering functions -// Algorithm works as follows: -// If next packet is in sequence just copy it to buffer -// Otherwise copy it in cache according to its sequence number -// Cache is a circular array where "rtpbuf.first" points to next sequence slot -// and keeps track of expected sequence - -// Initialize rtp cache -void Rtp::cache_reset(unsigned short seq) { - int i; - - rtp_first = 0; - rtp_seq[0] = ++seq; - - for (i=0; i<MAXRTPPACKETSIN; i++) rtp_len[i] = 0; -} - -// Write in a cache the rtp packet in right rtp sequence order -int Rtp::cache(char *buffer, int length) { - struct rtpheader rh; - int newseq; - char *data; - unsigned short seq; - static int is_first = 1; - - getrtp2(&rh, &data, &length); - if(!length) return 0; - seq = rh.b.sequence; - - newseq = seq - rtp_seq[rtp_first]; - - if ((newseq == 0) || is_first) { - is_first = 0; - - rtp_first = ( 1 + rtp_first ) % MAXRTPPACKETSIN; - rtp_seq[rtp_first] = ++seq; - goto feed; - } - - if (newseq > MAXRTPPACKETSIN) { - MSG_DBG2("Overrun(seq[%d]=%d seq=%d, newseq=%d)\n", rtp_first, rtp_seq[rtp_first], seq, newseq); - cache_reset(seq); - goto feed; - } - - if (newseq < 0) { - int i; - - // Is it a stray packet re-sent to network? - for (i=0; i<MAXRTPPACKETSIN; i++) { - if (rtp_seq[i] == seq) { - MSG_ERR("Stray packet (seq[%d]=%d seq=%d, newseq=%d found at %d)\n", rtp_first, rtp_seq[rtp_first], seq, newseq, i); - return 0; // Yes, it is! - } - } - // Some heuristic to decide when to drop packet or to restart everything - if (newseq > -(3 * MAXRTPPACKETSIN)) { - MSG_ERR("Too Old packet (seq[%d]=%d seq=%d, newseq=%d)\n", rtp_first, rtp_seq[rtp_first], seq, newseq); - return 0; // Yes, it is! - } - - MSG_ERR("Underrun(seq[%d]=%d seq=%d, newseq=%d)\n", rtp_first, rtp_seq[rtp_first], seq, newseq); - - cache_reset(seq); - goto feed; - } - - MSG_DBG3("Out of Seq (seq[%d]=%d seq=%d, newseq=%d)\n", rtp_first, rtp_seq[rtp_first], seq, newseq); - newseq = ( newseq + rtp_first ) % MAXRTPPACKETSIN; - memcpy (rtp_data[newseq], data, length); - rtp_len[newseq] = length; - rtp_seq[newseq] = seq; - - return 0; - -feed: - memcpy (buffer, data, length); - return length; -} - -// Get next packet in cache -// Look in cache to get first packet in sequence -int Rtp::get_next(char *buffer, int length) { - int i; - unsigned short nextseq; - - // If we have empty buffer we loop to fill it - for (i=0; i < MAXRTPPACKETSIN -3; i++) { - if (rtp_len[rtp_first] != 0) break; - - length = cache(buffer, length); - - // returns on first packet in sequence - if (length > 0) return length; - else if (length < 0) break; - // Only if length == 0 loop continues! - } - - i = rtp_first; - while (rtp_len[i] == 0) { - MSG_ERR("Lost packet %hu\n", rtp_seq[i]); - i = ( 1 + i ) % MAXRTPPACKETSIN; - if (rtp_first == i) break; - } - rtp_first = i; - - // Copy next non empty packet from cache - MSG_DBG3( "Getting rtp from cache [%d] %hu\n", rtp_first, rtp_seq[rtp_first]); - memcpy (buffer, rtp_data[rtp_first], rtp_len[rtp_first]); - length = rtp_len[rtp_first]; // can be zero? - - // Reset fisrt slot and go next in cache - rtp_len[rtp_first] = 0; - nextseq = rtp_seq[rtp_first]; - rtp_first = ( 1 + rtp_first ) % MAXRTPPACKETSIN; - rtp_seq[rtp_first] = nextseq + 1; - - return length; -} - - -// Read next rtp packet using cache -int Rtp::read_from_server(char *buffer, int length) { - // Following test is ASSERT (i.e. uneuseful if code is correct) - if(buffer==NULL || length<STREAM_BUFFER_SIZE) { - MSG_ERR("RTP buffer invalid; no data return from network\n"); - return 0; - } - - // loop just to skip empty packets - while ((length = get_next(buffer, length)) == 0) { - MSG_ERR("Got empty packet from RTP cache!?\n"); - } - return(length); -} - -int Rtp::getrtp2(struct rtpheader *rh, char** data, int* lengthData) const { - static char buf[1600]; - unsigned int intP; - char* charP = (char*) &intP; - int headerSize; - int lengthPacket; - lengthPacket=tcp.read((uint8_t*)(buf),1590); - if (lengthPacket<0) MSG_ERR("rtp: socket read error\n"); - else if (lengthPacket<12) MSG_ERR("rtp: packet too small (%d) to be an rtp frame (>12bytes)\n", lengthPacket); - if(lengthPacket<12) { - *lengthData = 0; - return 0; - } - rh->b.v = (unsigned int) ((buf[0]>>6)&0x03); - rh->b.p = (unsigned int) ((buf[0]>>5)&0x01); - rh->b.x = (unsigned int) ((buf[0]>>4)&0x01); - rh->b.cc = (unsigned int) ((buf[0]>>0)&0x0f); - rh->b.m = (unsigned int) ((buf[1]>>7)&0x01); - rh->b.pt = (unsigned int) ((buf[1]>>0)&0x7f); - intP = 0; - memcpy(charP+2,&buf[2],2); - rh->b.sequence = ntohl(intP); - intP = 0; - memcpy(charP,&buf[4],4); - rh->timestamp = ntohl(intP); - - headerSize = 12 + 4*rh->b.cc; /* in bytes */ - - *lengthData = lengthPacket - headerSize; - *data = (char*) buf + headerSize; - - return 0; -} -Rtp::Rtp(Tcp& _tcp):tcp(_tcp) {} -Rtp::~Rtp() {} -} // namespace mpxp Deleted: mplayerxp/libmpstream2/rtp.h =================================================================== --- mplayerxp/libmpstream2/rtp.h 2012-12-18 16:07:55 UTC (rev 574) +++ mplayerxp/libmpstream2/rtp.h 2012-12-18 16:22:42 UTC (rev 575) @@ -1,41 +0,0 @@ -/* Imported from the dvbstream project - * - * Modified for use with MPlayer, for details see the changelog at - * http://svn.mplayerhq.hu/mplayer/trunk/ - * $Id: rtp.h,v 1.2 2007/11/17 12:43:37 nickols_k Exp $ - */ -#ifndef __RTP_H_INCLUDED -#define __RTP_H_INCLUDED 1 -#include "network.h" -#include "tcp.h" -#include <stdint.h> - -namespace mpxp { -// RTP reorder routines -// Also handling of repeated UDP packets (a bug of ExtremeNetworks switches firmware) -// rtpreord procedures -// write rtp packets in cache -// get rtp packets reordered - -#define MAXRTPPACKETSIN 32 // The number of max packets being reordered - - class Rtp : public Opaque { - public: - Rtp(Tcp& tcp); - virtual ~Rtp(); - - virtual int read_from_server(char *buffer, int length); - private: - void cache_reset(unsigned short seq); - int cache(char *buffer, int length); - int get_next(char *buffer, int length); - int getrtp2(struct rtpheader *rh, char** data, int* lengthData) const; - - Tcp& tcp; - uint8_t rtp_data[MAXRTPPACKETSIN][STREAM_BUFFER_SIZE]; - uint16_t rtp_seq[MAXRTPPACKETSIN]; - uint16_t rtp_len[MAXRTPPACKETSIN]; - uint16_t rtp_first; - }; -} // namespace mpxp -#endif Copied: mplayerxp/libmpstream2/rtp_cache.cpp (from rev 574, mplayerxp/libmpstream2/rtp.cpp) =================================================================== --- mplayerxp/libmpstream2/rtp_cache.cpp (rev 0) +++ mplayerxp/libmpstream2/rtp_cache.cpp 2012-12-18 16:22:42 UTC (rev 575) @@ -0,0 +1,234 @@ +#include "mp_config.h" +#include "osdep/mplib.h" +using namespace mpxp; +/* Imported from the dvbstream-0.2 project + * + * Modified for use with MPlayer, for details see the changelog at + * http://svn.mplayerhq.hu/mplayer/trunk/ + * $Id: rtp.c,v 1.4 2007/11/17 12:43:37 nickols_k Exp $ + */ + +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <stdlib.h> +#include <stdio.h> +#include <sys/types.h> +#include <ctype.h> + +#ifndef HAVE_WINSOCK2 +#include <netinet/in.h> +#include <sys/socket.h> +#include <arpa/inet.h> +#define closesocket close +#else +#include <winsock2.h> +#include <ws2tcpip.h> +#endif +#include <errno.h> +#include "stream.h" + +/* MPEG-2 TS RTP stack */ + +#define DEBUG 1 +#include "tcp.h" +#include "rtp_cache.h" +#include "stream_msg.h" + +// RTP reorder routines +// Also handling of repeated UDP packets (a bug of ExtremeNetworks switches firmware) +// rtpreord procedures +// write rtp packets in cache +// get rtp packets reordered + +namespace mpxp { +#define MAXRTPPACKETSIN 32 // The number of max packets being reordered + +struct rtpbits { + unsigned int v:2; /* version: 2 */ + unsigned int p:1; /* is there padding appended: 0 */ + unsigned int x:1; /* number of extension headers: 0 */ + unsigned int cc:4; /* number of CSRC identifiers: 0 */ + unsigned int m:1; /* marker: 0 */ + unsigned int pt:7; /* payload type: 33 for MPEG2 TS - RFC 1890 */ + unsigned int sequence:16; /* sequence number: random */ +}; + +struct rtpheader { /* in network byte order */ + struct rtpbits b; + int timestamp; /* start: random */ + int ssrc; /* random */ +}; + +// RTP Reordering functions +// Algorithm works as follows: +// If next packet is in sequence just copy it to buffer +// Otherwise copy it in cache according to its sequence number +// Cache is a circular array where "rtpbuf.first" points to next sequence slot +// and keeps track of expected sequence + +// Initialize rtp cache +void Rtp_Cache::cache_reset(unsigned short seq) { + int i; + + rtp_first = 0; + rtp_seq[0] = ++seq; + + for (i=0; i<MAXRTPPACKETSIN; i++) rtp_len[i] = 0; +} + +// Write in a cache the rtp packet in right rtp sequence order +int Rtp_Cache::cache(char *buffer, int length) { + struct rtpheader rh; + int newseq; + char *data; + unsigned short seq; + static int is_first = 1; + + getrtp2(&rh, &data, &length); + if(!length) return 0; + seq = rh.b.sequence; + + newseq = seq - rtp_seq[rtp_first]; + + if ((newseq == 0) || is_first) { + is_first = 0; + + rtp_first = ( 1 + rtp_first ) % MAXRTPPACKETSIN; + rtp_seq[rtp_first] = ++seq; + goto feed; + } + + if (newseq > MAXRTPPACKETSIN) { + MSG_DBG2("Overrun(seq[%d]=%d seq=%d, newseq=%d)\n", rtp_first, rtp_seq[rtp_first], seq, newseq); + cache_reset(seq); + goto feed; + } + + if (newseq < 0) { + int i; + + // Is it a stray packet re-sent to network? + for (i=0; i<MAXRTPPACKETSIN; i++) { + if (rtp_seq[i] == seq) { + MSG_ERR("Stray packet (seq[%d]=%d seq=%d, newseq=%d found at %d)\n", rtp_first, rtp_seq[rtp_first], seq, newseq, i); + return 0; // Yes, it is! + } + } + // Some heuristic to decide when to drop packet or to restart everything + if (newseq > -(3 * MAXRTPPACKETSIN)) { + MSG_ERR("Too Old packet (seq[%d]=%d seq=%d, newseq=%d)\n", rtp_first, rtp_seq[rtp_first], seq, newseq); + return 0; // Yes, it is! + } + + MSG_ERR("Underrun(seq[%d]=%d seq=%d, newseq=%d)\n", rtp_first, rtp_seq[rtp_first], seq, newseq); + + cache_reset(seq); + goto feed; + } + + MSG_DBG3("Out of Seq (seq[%d]=%d seq=%d, newseq=%d)\n", rtp_first, rtp_seq[rtp_first], seq, newseq); + newseq = ( newseq + rtp_first ) % MAXRTPPACKETSIN; + memcpy (rtp_data[newseq], data, length); + rtp_len[newseq] = length; + rtp_seq[newseq] = seq; + + return 0; + +feed: + memcpy (buffer, data, length); + return length; +} + +// Get next packet in cache +// Look in cache to get first packet in sequence +int Rtp_Cache::get_next(char *buffer, int length) { + int i; + unsigned short nextseq; + + // If we have empty buffer we loop to fill it + for (i=0; i < MAXRTPPACKETSIN -3; i++) { + if (rtp_len[rtp_first] != 0) break; + + length = cache(buffer, length); + + // returns on first packet in sequence + if (length > 0) return length; + else if (length < 0) break; + // Only if length == 0 loop continues! + } + + i = rtp_first; + while (rtp_len[i] == 0) { + MSG_ERR("Lost packet %hu\n", rtp_seq[i]); + i = ( 1 + i ) % MAXRTPPACKETSIN; + if (rtp_first == i) break; + } + rtp_first = i; + + // Copy next non empty packet from cache + MSG_DBG3( "Getting rtp from cache [%d] %hu\n", rtp_first, rtp_seq[rtp_first]); + memcpy (buffer, rtp_data[rtp_first], rtp_len[rtp_first]); + length = rtp_len[rtp_first]; // can be zero? + + // Reset fisrt slot and go next in cache + rtp_len[rtp_first] = 0; + nextseq = rtp_seq[rtp_first]; + rtp_first = ( 1 + rtp_first ) % MAXRTPPACKETSIN; + rtp_seq[rtp_first] = nextseq + 1; + + return length; +} + + +// Read next rtp packet using cache +int Rtp_Cache::read_from_server(char *buffer, int length) { + // Following test is ASSERT (i.e. uneuseful if code is correct) + if(buffer==NULL || length<STREAM_BUFFER_SIZE) { + MSG_ERR("RTP buffer invalid; no data return from network\n"); + return 0; + } + + // loop just to skip empty packets + while ((length = get_next(buffer, length)) == 0) { + MSG_ERR("Got empty packet from RTP cache!?\n"); + } + return(length); +} + +int Rtp_Cache::getrtp2(struct rtpheader *rh, char** data, int* lengthData) const { + static char buf[1600]; + unsigned int intP; + char* charP = (char*) &intP; + int headerSize; + int lengthPacket; + lengthPacket=tcp.read((uint8_t*)(buf),1590); + if (lengthPacket<0) MSG_ERR("rtp: socket read error\n"); + else if (lengthPacket<12) MSG_ERR("rtp: packet too small (%d) to be an rtp frame (>12bytes)\n", lengthPacket); + if(lengthPacket<12) { + *lengthData = 0; + return 0; + } + rh->b.v = (unsigned int) ((buf[0]>>6)&0x03); + rh->b.p = (unsigned int) ((buf[0]>>5)&0x01); + rh->b.x = (unsigned int) ((buf[0]>>4)&0x01); + rh->b.cc = (unsigned int) ((buf[0]>>0)&0x0f); + rh->b.m = (unsigned int) ((buf[1]>>7)&0x01); + rh->b.pt = (unsigned int) ((buf[1]>>0)&0x7f); + intP = 0; + memcpy(charP+2,&buf[2],2); + rh->b.sequence = ntohl(intP); + intP = 0; + memcpy(charP,&buf[4],4); + rh->timestamp = ntohl(intP); + + headerSize = 12 + 4*rh->b.cc; /* in bytes */ + + *lengthData = lengthPacket - headerSize; + *data = (char*) buf + headerSize; + + return 0; +} +Rtp_Cache::Rtp_Cache(Tcp& _tcp):tcp(_tcp) {} +Rtp_Cache::~Rtp_Cache() {} +} // namespace mpxp Copied: mplayerxp/libmpstream2/rtp_cache.h (from rev 574, mplayerxp/libmpstream2/rtp.h) =================================================================== --- mplayerxp/libmpstream2/rtp_cache.h (rev 0) +++ mplayerxp/libmpstream2/rtp_cache.h 2012-12-18 16:22:42 UTC (rev 575) @@ -0,0 +1,41 @@ +/* Imported from the dvbstream project + * + * Modified for use with MPlayer, for details see the changelog at + * http://svn.mplayerhq.hu/mplayer/trunk/ + * $Id: rtp.h,v 1.2 2007/11/17 12:43:37 nickols_k Exp $ + */ +#ifndef __RTP_CACHE_H_INCLUDED +#define __RTP_CACHE_H_INCLUDED 1 +#include "network.h" +#include "tcp.h" +#include <stdint.h> + +namespace mpxp { +// RTP reorder routines +// Also handling of repeated UDP packets (a bug of ExtremeNetworks switches firmware) +// rtpreord procedures +// write rtp packets in cache +// get rtp packets reordered + +#define MAXRTPPACKETSIN 32 // The number of max packets being reordered + + class Rtp_Cache : public Opaque { + public: + Rtp_Cache(Tcp& tcp); + virtual ~Rtp_Cache(); + + virtual int read_from_server(char *buffer, int length); + private: + void cache_reset(unsigned short seq); + int cache(char *buffer, int length); + int get_next(char *buffer, int length); + int getrtp2(struct rtpheader *rh, char** data, int* lengthData) const; + + Tcp& tcp; + uint8_t rtp_data[MAXRTPPACKETSIN][STREAM_BUFFER_SIZE]; + uint16_t rtp_seq[MAXRTPPACKETSIN]; + uint16_t rtp_len[MAXRTPPACKETSIN]; + uint16_t rtp_first; + }; +} // namespace mpxp +#endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |