[Mplayerxp-cvslog] SF.net SVN: mplayerxp:[537] mplayerxp
Brought to you by:
olov
From: <nic...@us...> - 2012-12-11 13:31:04
|
Revision: 537 http://mplayerxp.svn.sourceforge.net/mplayerxp/?rev=537&view=rev Author: nickols_k Date: 2012-12-11 13:30:51 +0000 (Tue, 11 Dec 2012) Log Message: ----------- supress warning: deleting any_t* is undefined + declare network support more or less safe Modified Paths: -------------- mplayerxp/configure mplayerxp/libmpdemux/asf.h mplayerxp/libmpstream/asf_mmst_streaming.cpp mplayerxp/libmpstream/asf_streaming.cpp mplayerxp/libmpstream/asf_streaming.h mplayerxp/libmpstream/cddb.cpp mplayerxp/libmpstream/librtsp/rtsp.cpp mplayerxp/libmpstream/librtsp/rtsp.h mplayerxp/libmpstream/librtsp/rtsp_session.cpp mplayerxp/libmpstream/librtsp/rtsp_session.h mplayerxp/libmpstream/network.cpp mplayerxp/libmpstream/network.h mplayerxp/libmpstream/pnm.cpp mplayerxp/libmpstream/pnm.h mplayerxp/libmpstream/s_ftp.cpp mplayerxp/libmpstream/s_network.cpp mplayerxp/libmpstream/s_rtsp.cpp mplayerxp/libmpstream/s_udp.cpp mplayerxp/libmpstream/udp.cpp mplayerxp/libmpstream/udp.h mplayerxp/libmpstream/url.cpp mplayerxp/libmpstream/url.h Modified: mplayerxp/configure =================================================================== --- mplayerxp/configure 2012-12-11 11:31:23 UTC (rev 536) +++ mplayerxp/configure 2012-12-11 13:30:51 UTC (rev 537) @@ -91,7 +91,6 @@ "random_name|generates pseudo random suffix of target", "sdl|build with SDL video and audio output|http://www.libsdl.org", "sdl_image|build with SDL_image for screenshots|http://www.libsdl.org/projects/SDL_image", - "im_sure_that_must_have_streaming| the key to unlock streaming" "libvorbis|build with libvorbis support|http://www.vorbis.com", ) @@ -407,7 +406,6 @@ check_func2 execinfo.h backtrace print_config HAVE_ mp_config.h mp_config.mak backtrace -disabled im_sure_that_must_have_streaming && disable streaming disable inet_pton if enabled streaming ; then disable socklib Modified: mplayerxp/libmpdemux/asf.h =================================================================== --- mplayerxp/libmpdemux/asf.h 2012-12-11 11:31:23 UTC (rev 536) +++ mplayerxp/libmpdemux/asf.h 2012-12-11 13:30:51 UTC (rev 537) @@ -123,25 +123,6 @@ }; #endif -// Definition of the differents type of ASF streaming -typedef enum { - ASF_Unknown_e, - ASF_Live_e, - ASF_Prerecorded_e, - ASF_Redirector_e, - ASF_PlainText_e, - ASF_Authenticate_e -} ASF_StreamType_e; - -typedef struct { - ASF_StreamType_e networking_type; - int request; - int packet_size; - int *audio_streams,n_audio,*video_streams,n_video; - int audio_id, video_id; -} asf_http_networking_t; - - /* * Some macros to swap little endian structures read from an ASF file * into machine endian format Modified: mplayerxp/libmpstream/asf_mmst_streaming.cpp =================================================================== --- mplayerxp/libmpstream/asf_mmst_streaming.cpp 2012-12-11 11:31:23 UTC (rev 536) +++ mplayerxp/libmpstream/asf_mmst_streaming.cpp 2012-12-11 13:30:51 UTC (rev 537) @@ -498,7 +498,7 @@ int asf_header_len; int len, i, packet_length; char* path, *unescpath; - URL_t* url1 = networking->url; + URL* url1 = networking->url; tcp.close(); Modified: mplayerxp/libmpstream/asf_streaming.cpp =================================================================== --- mplayerxp/libmpstream/asf_streaming.cpp 2012-12-11 11:31:23 UTC (rev 536) +++ mplayerxp/libmpstream/asf_streaming.cpp 2012-12-11 13:30:51 UTC (rev 537) @@ -564,8 +564,8 @@ static HTTP_Header* asf_http_request(networking_t *networking) { HTTP_Header* http_hdr = new(zeromem) HTTP_Header; - URL_t *url = NULL; - URL_t *server_url = NULL; + URL *url = NULL; + URL *server_url = NULL; asf_http_networking_t *asf_http_ctrl; char str[250]; char *ptr; @@ -595,7 +595,7 @@ } http_hdr->set_uri(server_url->url ); sprintf( str, "Host: %.220s:%d", server_url->hostname, server_url->port ); - url_free( server_url ); + delete server_url; } else { http_hdr->set_uri(url->file ); sprintf( str, "Host: %.220s:%d", url->hostname, url->port ); @@ -719,7 +719,7 @@ static MPXP_Rc asf_http_networking_start(Tcp& tcp, networking_t *networking) { HTTP_Header *http_hdr=NULL; - URL_t *url = networking->url; + URL *url = networking->url; asf_http_networking_t *asf_http_ctrl; char buffer[BUFFER_SIZE]; int i, ret; @@ -735,7 +735,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 = (any_t*)asf_http_ctrl; + networking->data = asf_http_ctrl; do { done = 1; @@ -842,3 +842,5 @@ 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 Modified: mplayerxp/libmpstream/asf_streaming.h =================================================================== --- mplayerxp/libmpstream/asf_streaming.h 2012-12-11 11:31:23 UTC (rev 536) +++ mplayerxp/libmpstream/asf_streaming.h 2012-12-11 13:30:51 UTC (rev 537) @@ -1,10 +1,37 @@ #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" 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); Modified: mplayerxp/libmpstream/cddb.cpp =================================================================== --- mplayerxp/libmpstream/cddb.cpp 2012-12-11 11:31:23 UTC (rev 536) +++ mplayerxp/libmpstream/cddb.cpp 2012-12-11 13:30:51 UTC (rev 537) @@ -145,7 +145,7 @@ char request[4096]; int ret = 0; Tcp tcp(cddb_data->libinput,-1); - URL_t *url; + URL *url; if( reply_parser==NULL || command==NULL || cddb_data==NULL ) return -1; @@ -183,7 +183,7 @@ } delete http_hdr; - url_free( url ); + delete url; return ret; } Modified: mplayerxp/libmpstream/librtsp/rtsp.cpp =================================================================== --- mplayerxp/libmpstream/librtsp/rtsp.cpp 2012-12-11 11:31:23 UTC (rev 536) +++ mplayerxp/libmpstream/librtsp/rtsp.cpp 2012-12-11 13:30:51 UTC (rev 537) @@ -68,7 +68,7 @@ #define HEADER_SIZE 1024 #define MAX_FIELDS 256 -struct rtsp_s { +struct rtsp_t { Tcp* tcp; Modified: mplayerxp/libmpstream/librtsp/rtsp.h =================================================================== --- mplayerxp/libmpstream/librtsp/rtsp.h 2012-12-11 11:31:23 UTC (rev 536) +++ mplayerxp/libmpstream/librtsp/rtsp.h 2012-12-11 13:30:51 UTC (rev 537) @@ -45,7 +45,7 @@ #define RTSP_METHOD_TEARDOWN "TEARDOWN" #define RTSP_METHOD_SET_PARAMETER "SET_PARAMETER" -typedef struct rtsp_s rtsp_t; +struct rtsp_t; rtsp_t* rtsp_connect (Tcp& tcp, char *mrl, char *path, char *host, int port, char *user_agent); Modified: mplayerxp/libmpstream/librtsp/rtsp_session.cpp =================================================================== --- mplayerxp/libmpstream/librtsp/rtsp_session.cpp 2012-12-11 11:31:23 UTC (rev 536) +++ mplayerxp/libmpstream/librtsp/rtsp_session.cpp 2012-12-11 13:30:51 UTC (rev 537) @@ -59,6 +59,7 @@ #include "realrtsp/xbuffer.h" #include "stream_msg.h" +namespace mpxp { /* #define LOG */ @@ -71,22 +72,16 @@ #define RTSP_SERVER_TYPE_HELIX "Helix" #define RTSP_SERVER_TYPE_UNKNOWN "unknown" -struct rtsp_session_s { - rtsp_t *s; - struct real_rtsp_session_t* real_session; - struct rtp_rtsp_session_t* rtp_session; -}; - -//rtsp_session_t *rtsp_session_start(char *mrl) { -rtsp_session_t *rtsp_session_start(Tcp& tcp, char **mrl, char *path, char *host, +//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_t *rtsp_session = NULL; + Rtsp_Session *rtsp_session = NULL; char *server; char *mrl_line = NULL; rmff_header_t *h; - rtsp_session = new rtsp_session_t; + rtsp_session = new Rtsp_Session; rtsp_session->s = NULL; rtsp_session->real_session = NULL; rtsp_session->rtp_session = NULL; @@ -219,75 +214,63 @@ return rtsp_session; } -int rtsp_session_read (Tcp& tcp,rtsp_session_t *self, char *data, int len) { +int Rtsp_Session::read(Tcp& tcp,char *data, int len) { - if (self->real_session) { - int to_copy=len; - char *dest=data; - char *source = - (char *) (self->real_session->recv + self->real_session->recv_read); - int fill = self->real_session->recv_size - self->real_session->recv_read; + if (real_session) { + int to_copy=len; + char *dest=data; + char *source = + (char *) (real_session->recv + real_session->recv_read); + int fill = real_session->recv_size - real_session->recv_read; - if(self->real_session->rdteof) - return -1; - if (len < 0) return 0; - if (self->real_session->recv_size < 0) return -1; - while (to_copy > fill) { - - memcpy(dest, source, fill); - to_copy -= fill; - dest += fill; - self->real_session->recv_read = 0; - self->real_session->recv_size = - real_get_rdt_chunk (self->s, (char **)&(self->real_session->recv), self->real_session->rdt_rawdata); - if (self->real_session->recv_size < 0) { - self->real_session->rdteof = 1; - self->real_session->recv_size = 0; - } - source = (char *) self->real_session->recv; - fill = self->real_session->recv_size; - - if (self->real_session->recv_size == 0) { + if(real_session->rdteof) return -1; + if(len < 0) return 0; + if(real_session->recv_size < 0) return -1; + while (to_copy > fill) { + memcpy(dest, source, fill); + to_copy -= fill; + dest += fill; + real_session->recv_read = 0; + real_session->recv_size = + real_get_rdt_chunk (s, (char **)&(real_session->recv), real_session->rdt_rawdata); + if (real_session->recv_size < 0) { + real_session->rdteof = 1; + real_session->recv_size = 0; + } + source = (char *) real_session->recv; + fill = real_session->recv_size; + if (real_session->recv_size == 0) { #ifdef LOG - MSG_INFO("librtsp: %d of %d bytes provided\n", len-to_copy, len); + MSG_INFO("librtsp: %d of %d bytes provided\n", len-to_copy, len); #endif - return len-to_copy; - } - } - - memcpy(dest, source, to_copy); - self->real_session->recv_read += to_copy; - + return len-to_copy; + } + } + memcpy(dest, source, to_copy); + real_session->recv_read += to_copy; #ifdef LOG - MSG_INFO("librtsp: %d bytes provided\n", len); + MSG_INFO("librtsp: %d bytes provided\n", len); #endif + return len; + } else if (rtp_session) { + int l = 0; + Tcp _tcp(tcp.get_libinput(),rtp_session->rtp_socket); - return len; - } - else if (self->rtp_session) - { - int l = 0; - Tcp _tcp(tcp.get_libinput(),self->rtp_session->rtp_socket); - - l = read_rtp_from_server (_tcp, data, len); - /* send RTSP and RTCP keepalive */ - rtcp_send_rr (self->s, self->rtp_session); - - if (l == 0) - rtsp_session_end (self); - - return l; - } - - return 0; + l = read_rtp_from_server (_tcp, data, len); + /* send RTSP and RTCP keepalive */ + rtcp_send_rr (s, rtp_session); + if (l == 0) end (); + return l; + } + return 0; } -void rtsp_session_end(rtsp_session_t *session) { - - rtsp_close(session->s); - if (session->real_session) - free_real_rtsp_session (session->real_session); - if (session->rtp_session) - rtp_session_free (session->rtp_session); - delete session; +void Rtsp_Session::end() { + rtsp_close(s); + if (real_session) free_real_rtsp_session (real_session); + if (rtp_session) rtp_session_free (rtp_session); } + +Rtsp_Session::Rtsp_Session() {} +Rtsp_Session::~Rtsp_Session() {} +} // namespace mpxp \ No newline at end of file Modified: mplayerxp/libmpstream/librtsp/rtsp_session.h =================================================================== --- mplayerxp/libmpstream/librtsp/rtsp_session.h 2012-12-11 11:31:23 UTC (rev 536) +++ mplayerxp/libmpstream/librtsp/rtsp_session.h 2012-12-11 13:30:51 UTC (rev 537) @@ -1,3 +1,6 @@ +#include "mp_config.h" +#include "osdep/mplib.h" +using namespace mpxp; /* * This file was ported to MPlayer from xine CVS rtsp_session.h,v 1.4 2003/01/31 14:06:18 */ @@ -31,13 +34,24 @@ #ifndef HAVE_RTSP_SESSION_H #define HAVE_RTSP_SESSION_H -typedef struct rtsp_session_s rtsp_session_t; +struct real_rtsp_session_t; +struct rtp_rtsp_session_t; +struct rtsp_t; +namespace mpxp { + struct Rtsp_Session : public Opaque { + public: + Rtsp_Session(); + virtual ~Rtsp_Session(); -rtsp_session_t *rtsp_session_start(Tcp& tcp, char **mrl, char *path, char *host, - int port, int *redir, uint32_t bandwidth, char *user, char *pass); + virtual int read(Tcp& tcp,char *data, int len); + virtual void end(); -int rtsp_session_read(Tcp& tcp,rtsp_session_t *session, char *data, int len); + rtsp_t* s; + real_rtsp_session_t* real_session; + rtp_rtsp_session_t* rtp_session; + }; -void rtsp_session_end(rtsp_session_t *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); +} // namespace mpxp #endif Modified: mplayerxp/libmpstream/network.cpp =================================================================== --- mplayerxp/libmpstream/network.cpp 2012-12-11 11:31:23 UTC (rev 536) +++ mplayerxp/libmpstream/network.cpp 2012-12-11 13:30:51 UTC (rev 537) @@ -111,15 +111,15 @@ void free_networking( networking_t *networking ) { if( networking==NULL ) return; - if( networking->url ) url_free( networking->url ); + if( networking->url ) delete networking->url; if( networking->buffer ) delete networking->buffer ; if( networking->data ) delete networking->data ; delete networking; } -URL_t* -check4proxies( URL_t *url ) { - URL_t *url_out = NULL; +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") ) { @@ -134,8 +134,8 @@ // We got a proxy, build the URL to use it int len; char *new_url; - URL_t *tmp_url; - URL_t *proxy_url = url_new( proxy ); + URL *tmp_url; + URL *proxy_url = url_new( proxy ); if( proxy_url==NULL ) { MSG_WARN("Invalid proxy setting...Trying without proxy.\n"); @@ -162,18 +162,18 @@ if( tmp_url==NULL ) { return url_out; } - url_free( url_out ); + delete url_out; url_out = tmp_url; delete new_url ; - url_free( proxy_url ); + delete proxy_url; } } return url_out; } -MPXP_Rc http_send_request(Tcp& tcp, URL_t *url, off_t pos ) { +MPXP_Rc http_send_request(Tcp& tcp, URL *url, off_t pos ) { HTTP_Header& http_hdr = *new(zeromem) HTTP_Header; - URL_t *server_url; + URL *server_url; char str[256]; int ret; int proxy = 0; // Boolean @@ -219,7 +219,7 @@ if( url->port==0 ) url->port = 8080; // Default port for the proxy server tcp.close(); tcp.open(url->hostname, url->port, Tcp::IP4); - url_free( server_url ); + delete server_url; server_url = NULL; } else { if( server_url->port==0 ) server_url->port = 80; // Default port for the web server @@ -240,8 +240,7 @@ return MPXP_Ok; err_out: delete &http_hdr; - if (proxy && server_url) - url_free(server_url); + if (proxy && server_url) delete server_url; return MPXP_False; } @@ -271,7 +270,7 @@ } int -http_authenticate(HTTP_Header& http_hdr, URL_t *url, int *auth_retry) { +http_authenticate(HTTP_Header& http_hdr, URL *url, int *auth_retry) { const char *aut; if( *auth_retry==1 ) { @@ -368,7 +367,7 @@ const char *content_type; const char *next_url; - URL_t *url = networking->url; + URL *url = networking->url; do { next_url = NULL; @@ -400,7 +399,7 @@ http_hdr = http_read_response(tcp); if( http_hdr==NULL ) goto err_out; if( mp_conf.verbose ) http_hdr->debug_hdr(); - networking->data = (any_t*)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 ) { @@ -558,7 +557,7 @@ MPXP_Rc nop_networking_start(Tcp& tcp,networking_t* networking ) { HTTP_Header *http_hdr = NULL; const char *next_url=NULL; - URL_t *rd_url=NULL; + URL *rd_url=NULL; MPXP_Rc ret; if( !tcp.established() ) { @@ -645,22 +644,23 @@ 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(reinterpret_cast<pnm_t*>(stream_ctrl->data), buffer, size); + return pnm.read(buffer, size); } MPXP_Rc pnm_networking_start(Tcp& tcp,networking_t *networking ) { - pnm_t *pnm; + Pnm* pnm = new(zeromem) Pnm(tcp); tcp.open(networking->url->hostname, networking->url->port ? networking->url->port : 7070); if(!tcp.established()) return MPXP_False; - pnm = pnm_connect(tcp,networking->url->file); - if(!pnm) return MPXP_NA; - + 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; @@ -670,11 +670,12 @@ int realrtsp_networking_read( Tcp& tcp, char *buffer, int size, networking_t *networking ) { - return rtsp_session_read(tcp,reinterpret_cast<rtsp_session_t*>(networking->data), buffer, size); + 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 ) { - rtsp_session_t *rtsp; + Rtsp_Session* rtsp; char *mrl; char *file; int port; @@ -701,7 +702,7 @@ networking->url->password); if ( redirected == 1 ) { - url_free(networking->url); + delete networking->url; networking->url = url_new(mrl); tcp.close(); } @@ -751,7 +752,7 @@ } #endif -MPXP_Rc networking_start(Tcp& tcp,networking_t* networking, URL_t *url) { +MPXP_Rc networking_start(Tcp& tcp,networking_t* networking, URL *url) { MPXP_Rc rc; networking->url = check4proxies( url ); Modified: mplayerxp/libmpstream/network.h =================================================================== --- mplayerxp/libmpstream/network.h 2012-12-11 11:31:23 UTC (rev 536) +++ mplayerxp/libmpstream/network.h 2012-12-11 13:30:51 UTC (rev 537) @@ -58,7 +58,7 @@ }; struct networking_t { - URL_t *url; + URL *url; std::string mime; networking_status status; int buffering; // boolean @@ -69,23 +69,23 @@ 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 ); - any_t*data; + Opaque* data; }; extern void fixup_network_stream_cache(networking_t *s); -extern MPXP_Rc networking_start(Tcp& fd,networking_t *n, URL_t *url); +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_t* check4proxies( URL_t *url ); +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 ); -MPXP_Rc http_send_request(Tcp& tcp,URL_t *url, off_t pos); +MPXP_Rc http_send_request(Tcp& tcp,URL* url, off_t pos); HTTP_Header* http_read_response(Tcp& fd); -int http_authenticate(HTTP_Header& http_hdr, URL_t *url, int *auth_retry); +int http_authenticate(HTTP_Header& http_hdr, URL* url, int *auth_retry); /* * Joey Parrish <jo...@yu...>: Modified: mplayerxp/libmpstream/pnm.cpp =================================================================== --- mplayerxp/libmpstream/pnm.cpp 2012-12-11 11:31:23 UTC (rev 536) +++ mplayerxp/libmpstream/pnm.cpp 2012-12-11 13:30:51 UTC (rev 537) @@ -50,6 +50,7 @@ #include "tcp.h" #include "pnm.h" +namespace mpxp { #define FOURCC_TAG( ch0, ch1, ch2, ch3 ) \ (((long)(unsigned char)(ch3) ) | \ ( (long)(unsigned char)(ch2) << 8 ) | \ @@ -69,28 +70,6 @@ #define LOG */ -#define BUF_SIZE 4096 -#define HEADER_SIZE 4096 - -struct pnm_s { - Tcp* tcp; - char* path; - char buffer[BUF_SIZE]; /* scratch buffer */ - /* receive buffer */ - uint8_t recv[BUF_SIZE]; - int recv_size; - int recv_read; - - uint8_t header[HEADER_SIZE]; - int header_len; - int header_read; - unsigned seq_num[4]; /* two streams with two indices */ - unsigned seq_current[2]; /* seqs of last stream chunk read */ - uint32_t ts_current; /* timestamp of current chunk */ - uint32_t ts_last[2]; /* timestamps of last chunks */ - unsigned packet; /* number of last recieved packet */ -}; - /* * utility macros */ @@ -195,6 +174,9 @@ static void hexdump (char *buf, int length); +Pnm::Pnm(Tcp& _tcp):tcp(_tcp) {} +Pnm::~Pnm() {} + static int rm_write(Tcp& tcp, const char *buf, int len) { int total, timeout; @@ -281,10 +263,9 @@ * and returns number of bytes read */ -static unsigned int pnm_get_chunk(pnm_t *p, - unsigned int max, +unsigned int Pnm::get_chunk(unsigned int max, unsigned int *chunk_type, - char *data, int *need_response) { + char *data, int *need_response) const { unsigned int chunk_size; unsigned int n; @@ -294,11 +275,11 @@ return -1; /* get first PREAMBLE_SIZE bytes and ignore checksum */ - rm_read (*p->tcp, data, CHECKSUM_SIZE); + rm_read (tcp, data, CHECKSUM_SIZE); if (data[0] == 0x72) - rm_read (*p->tcp, data, PREAMBLE_SIZE); + rm_read (tcp, data, PREAMBLE_SIZE); else - rm_read (*p->tcp, data+CHECKSUM_SIZE, PREAMBLE_SIZE-CHECKSUM_SIZE); + rm_read (tcp, data+CHECKSUM_SIZE, PREAMBLE_SIZE-CHECKSUM_SIZE); max -= PREAMBLE_SIZE; @@ -311,7 +292,7 @@ ptr=data+PREAMBLE_SIZE; if (max < 1) return -1; - rm_read (*p->tcp, ptr++, 1); + rm_read (tcp, ptr++, 1); max -= 1; while(1) { @@ -319,19 +300,19 @@ if (max < 2) return -1; - rm_read (*p->tcp, ptr, 2); + rm_read (tcp, ptr, 2); max -= 2; if (*ptr == 'X') /* checking for server message */ { printf("input_pnm: got a message from server:\n"); if (max < 1) return -1; - rm_read (*p->tcp, ptr+2, 1); + rm_read (tcp, ptr+2, 1); max = -1; n=BE_16((uint8_t*)(ptr+1)); if (max < n) return -1; - rm_read (*p->tcp, ptr+3, n); + rm_read (tcp, ptr+3, n); max -= n; ptr[3+n]=0; printf("%s\n",ptr+3); @@ -353,14 +334,14 @@ n=ptr[1]; if (max < n) return -1; - rm_read (*p->tcp, ptr+2, n); + rm_read (tcp, ptr+2, n); max -= n; ptr+=(n+2); } /* the checksum of the next chunk is ignored here */ if (max < 1) return -1; - rm_read (*p->tcp, ptr+2, 1); + rm_read (tcp, ptr+2, 1); ptr+=3; chunk_size=ptr-data; break; @@ -372,12 +353,12 @@ if (chunk_size > max || chunk_size < PREAMBLE_SIZE) { printf("error: max chunk size exeeded (max was 0x%04x)\n", max); #ifdef LOG - n=rm_read (*p->tcp, &data[PREAMBLE_SIZE], 0x100 - PREAMBLE_SIZE); + n=rm_read (tcp, &data[PREAMBLE_SIZE], 0x100 - PREAMBLE_SIZE); hexdump(data,n+PREAMBLE_SIZE); #endif return -1; } - rm_read (*p->tcp, &data[PREAMBLE_SIZE], chunk_size-PREAMBLE_SIZE); + rm_read (tcp, &data[PREAMBLE_SIZE], chunk_size-PREAMBLE_SIZE); break; default: *chunk_type = 0; @@ -392,8 +373,8 @@ * writes a chunk to a buffer, returns number of bytes written */ -static int pnm_write_chunk(uint16_t chunk_id, uint16_t length, - const char *chunk, char *data) { +int Pnm::write_chunk(uint16_t chunk_id, uint16_t length, + const char *chunk, char *data) const { data[0]=(chunk_id>>8)%0xff; data[1]=chunk_id%0xff; @@ -408,93 +389,92 @@ * constructs a request and sends it */ -static void pnm_send_request(pnm_t *p, uint32_t bandwidth) { +void Pnm::send_request(uint32_t bandwidth) { UNUSED(bandwidth); uint16_t i16; int c=PNM_HEADER_SIZE; char fixme[]={0,1}; - memcpy(p->buffer,pnm_header,PNM_HEADER_SIZE); - c+=pnm_write_chunk(PNA_CLIENT_CHALLANGE,strlen(pnm_challenge), - pnm_challenge,&p->buffer[c]); - c+=pnm_write_chunk(PNA_CLIENT_CAPS,PNM_CLIENT_CAPS_SIZE, - reinterpret_cast<const char*>(pnm_client_caps),&p->buffer[c]); - c+=pnm_write_chunk(0x0a,0,NULL,&p->buffer[c]); - c+=pnm_write_chunk(0x0c,0,NULL,&p->buffer[c]); - c+=pnm_write_chunk(0x0d,0,NULL,&p->buffer[c]); - c+=pnm_write_chunk(0x16,2,fixme,&p->buffer[c]); - c+=pnm_write_chunk(PNA_TIMESTAMP,strlen(pnm_timestamp), - pnm_timestamp,&p->buffer[c]); - c+=pnm_write_chunk(PNA_BANDWIDTH,4, - (const char *)&pnm_default_bandwidth,&p->buffer[c]); - c+=pnm_write_chunk(0x08,0,NULL,&p->buffer[c]); - c+=pnm_write_chunk(0x0e,0,NULL,&p->buffer[c]); - c+=pnm_write_chunk(0x0f,0,NULL,&p->buffer[c]); - c+=pnm_write_chunk(0x11,0,NULL,&p->buffer[c]); - c+=pnm_write_chunk(0x10,0,NULL,&p->buffer[c]); - c+=pnm_write_chunk(0x15,0,NULL,&p->buffer[c]); - c+=pnm_write_chunk(0x12,0,NULL,&p->buffer[c]); - c+=pnm_write_chunk(PNA_GUID,strlen(pnm_guid), - pnm_guid,&p->buffer[c]); - c+=pnm_write_chunk(PNA_TWENTYFOUR,PNM_TWENTYFOUR_SIZE, - reinterpret_cast<char*>(pnm_twentyfour),&p->buffer[c]); + memcpy(buffer,pnm_header,PNM_HEADER_SIZE); + c+=write_chunk(PNA_CLIENT_CHALLANGE,strlen(pnm_challenge), + pnm_challenge,&buffer[c]); + c+=write_chunk(PNA_CLIENT_CAPS,PNM_CLIENT_CAPS_SIZE, + reinterpret_cast<const char*>(pnm_client_caps),&buffer[c]); + c+=write_chunk(0x0a,0,NULL,&buffer[c]); + c+=write_chunk(0x0c,0,NULL,&buffer[c]); + c+=write_chunk(0x0d,0,NULL,&buffer[c]); + c+=write_chunk(0x16,2,fixme,&buffer[c]); + c+=write_chunk(PNA_TIMESTAMP,strlen(pnm_timestamp), + pnm_timestamp,&buffer[c]); + c+=write_chunk(PNA_BANDWIDTH,4, + (const char *)&pnm_default_bandwidth,&buffer[c]); + c+=write_chunk(0x08,0,NULL,&buffer[c]); + c+=write_chunk(0x0e,0,NULL,&buffer[c]); + c+=write_chunk(0x0f,0,NULL,&buffer[c]); + c+=write_chunk(0x11,0,NULL,&buffer[c]); + c+=write_chunk(0x10,0,NULL,&buffer[c]); + c+=write_chunk(0x15,0,NULL,&buffer[c]); + c+=write_chunk(0x12,0,NULL,&buffer[c]); + c+=write_chunk(PNA_GUID,strlen(pnm_guid), + pnm_guid,&buffer[c]); + c+=write_chunk(PNA_TWENTYFOUR,PNM_TWENTYFOUR_SIZE, + reinterpret_cast<char*>(pnm_twentyfour),&buffer[c]); /* data after chunks */ - memcpy(&p->buffer[c],after_chunks,after_chunks_length); + memcpy(&buffer[c],after_chunks,after_chunks_length); c+=after_chunks_length; /* client id string */ - p->buffer[c]=PNA_CLIENT_STRING; + buffer[c]=PNA_CLIENT_STRING; i16=BE_16D((uint8_t*)((strlen(client_string)-1))); /* dont know why do we have -1 here */ - memcpy(&p->buffer[c+1],&i16,2); - memcpy(&p->buffer[c+3],client_string,strlen(client_string)+1); + memcpy(&buffer[c+1],&i16,2); + memcpy(&buffer[c+3],client_string,strlen(client_string)+1); c=c+3+strlen(client_string)+1; /* file path */ - p->buffer[c]=0; - p->buffer[c+1]=PNA_PATH_REQUEST; - i16=BE_16D((uint8_t*)(strlen(p->path))); - memcpy(&p->buffer[c+2],&i16,2); - memcpy(&p->buffer[c+4],p->path,strlen(p->path)); - c=c+4+strlen(p->path); + buffer[c]=0; + buffer[c+1]=PNA_PATH_REQUEST; + i16=BE_16D((uint8_t*)path.length()); + memcpy(&buffer[c+2],&i16,2); + memcpy(&buffer[c+4],path.c_str(),path.length()); + c=c+4+path.length(); /* some trailing bytes */ - p->buffer[c]='y'; - p->buffer[c+1]='B'; + buffer[c]='y'; + buffer[c+1]='B'; - rm_write(*p->tcp,p->buffer,c+2); + rm_write(tcp,buffer,c+2); } /* * pnm_send_response sends a response of a challenge */ -static void pnm_send_response(pnm_t *p, const char *response) { +void Pnm::send_response(const char *response) { int size=strlen(response); - p->buffer[0]=0x23; - p->buffer[1]=0; - p->buffer[2]=(unsigned char) size; + buffer[0]=0x23; + buffer[1]=0; + buffer[2]=(unsigned char) size; - memcpy(&p->buffer[3], response, size); + memcpy(&buffer[3], response, size); - rm_write (*p->tcp, p->buffer, size+3); + rm_write (tcp, buffer, size+3); } /* * get headers and challenge and fix headers - * write headers to p->header - * write challenge to p->buffer + * write headers to header + * write challenge to buffer * * return 0 on error. != 0 on success */ +int Pnm::get_headers(int *need_response) { -static int pnm_get_headers(pnm_t *p, int *need_response) { - uint32_t chunk_type; - char *ptr=reinterpret_cast<char*>(p->header); + char *ptr=reinterpret_cast<char*>(header); uint8_t *prop_hdr=NULL; int chunk_size,size=0; int nr; @@ -503,12 +483,12 @@ *need_response=0; while(1) { - if (HEADER_SIZE-size<=0) + if (Pnm::HEADER_SIZE-size<=0) { printf("input_pnm: header buffer overflow. exiting\n"); return 0; } - chunk_size=pnm_get_chunk(p,HEADER_SIZE-size,&chunk_type,ptr,&nr); + chunk_size=get_chunk(Pnm::HEADER_SIZE-size,&chunk_type,ptr,&nr); if (chunk_size < 0) return 0; if (chunk_type == 0) break; if (chunk_type == PNA_TAG) @@ -541,19 +521,19 @@ size++; /* read challenge */ - memcpy (p->buffer, ptr, PREAMBLE_SIZE); - rm_read (*p->tcp, &p->buffer[PREAMBLE_SIZE], 64); + memcpy (buffer, ptr, PREAMBLE_SIZE); + rm_read (tcp, &buffer[PREAMBLE_SIZE], 64); /* now write a data header */ memcpy(ptr, pnm_data_header, PNM_DATA_HEADER_SIZE); size+=PNM_DATA_HEADER_SIZE; /* - h=rmff_scan_header(p->header); + h=rmff_scan_header(header); rmff_fix_header(h); - p->header_len=rmff_get_header_size(h); - rmff_dump_header(h, p->header, HEADER_SIZE); + header_len=rmff_get_header_size(h); + rmff_dump_header(h, header, HEADER_SIZE); */ - p->header_len=size; + header_len=size; return 1; } @@ -562,61 +542,61 @@ * determine correct stream number by looking at indices */ -static int pnm_calc_stream(pnm_t *p) { +int Pnm::calc_stream() { char str0=0,str1=0; /* looking at the first index to * find possible stream types */ - if (p->seq_current[0]==p->seq_num[0]) str0=1; - if (p->seq_current[0]==p->seq_num[2]) str1=1; + if (seq_current[0]==seq_num[0]) str0=1; + if (seq_current[0]==seq_num[2]) str1=1; switch (str0+str1) { case 1: /* one is possible, good. */ if (str0) { - p->seq_num[0]++; - p->seq_num[1]=p->seq_current[1]+1; + seq_num[0]++; + seq_num[1]=seq_current[1]+1; return 0; } else { - p->seq_num[2]++; - p->seq_num[3]=p->seq_current[1]+1; + seq_num[2]++; + seq_num[3]=seq_current[1]+1; return 1; } break; case 0: case 2: /* both types or none possible, not so good */ /* try to figure out by second index */ - if ( (p->seq_current[1] == p->seq_num[1]) - &&(p->seq_current[1] != p->seq_num[3])) + if ( (seq_current[1] == seq_num[1]) + &&(seq_current[1] != seq_num[3])) { /* ok, only stream0 matches */ - p->seq_num[0]=p->seq_current[0]+1; - p->seq_num[1]++; + seq_num[0]=seq_current[0]+1; + seq_num[1]++; return 0; } - if ( (p->seq_current[1] == p->seq_num[3]) - &&(p->seq_current[1] != p->seq_num[1])) + if ( (seq_current[1] == seq_num[3]) + &&(seq_current[1] != seq_num[1])) { /* ok, only stream1 matches */ - p->seq_num[2]=p->seq_current[0]+1; - p->seq_num[3]++; + seq_num[2]=seq_current[0]+1; + seq_num[3]++; return 1; } /* wow, both streams match, or not. */ /* now we try to decide by timestamps */ - if (p->ts_current < p->ts_last[1]) + if (ts_current < ts_last[1]) return 0; - if (p->ts_current < p->ts_last[0]) + if (ts_current < ts_last[0]) return 1; /* does not help, we guess type 0 */ #ifdef LOG printf("guessing stream# 0\n"); #endif - p->seq_num[0]=p->seq_current[0]+1; - p->seq_num[1]=p->seq_current[1]+1; + seq_num[0]=seq_current[0]+1; + seq_num[1]=seq_current[1]+1; return 0; break; } @@ -628,7 +608,7 @@ * gets a stream chunk and writes it to a recieve buffer */ -static int pnm_get_stream_chunk(pnm_t *p) { +int Pnm::get_stream_chunk() { int n; char keepalive='!'; @@ -636,9 +616,9 @@ /* send a keepalive */ /* realplayer seems to do that every 43th package */ - if ((p->packet%43) == 42) + if ((packet%43) == 42) { - rm_write(*p->tcp,&keepalive,1); + rm_write(tcp,&keepalive,1); } /* data chunks begin with: 'Z' <o> <o> <i1> 'Z' <i2> @@ -647,13 +627,13 @@ * <i2> is a 8 bit index which counts from 0x10 to somewhere */ - n = rm_read (*p->tcp, p->buffer, 8); + n = rm_read (tcp, buffer, 8); if (n<8) return 0; /* skip 8 bytes if 0x62 is read */ - if (p->buffer[0] == 0x62) + if (buffer[0] == 0x62) { - n = rm_read (*p->tcp, p->buffer, 8); + n = rm_read (tcp, buffer, 8); if (n<8) return 0; #ifdef LOG printf("input_pnm: had to seek 8 bytes on 0x62\n"); @@ -661,16 +641,16 @@ } /* a server message */ - if (p->buffer[0] == 'X') + if (buffer[0] == 'X') { - int size=BE_16((uint8_t*)(&p->buffer[1])); + int size=BE_16((uint8_t*)(&buffer[1])); - rm_read (*p->tcp, &p->buffer[8], size-5); - p->buffer[size+3]=0; - printf("input_pnm: got message from server while reading stream:\n%s\n", &p->buffer[3]); + rm_read (tcp, &buffer[8], size-5); + buffer[size+3]=0; + printf("input_pnm: got message from server while reading stream:\n%s\n", &buffer[3]); return 0; } - if (p->buffer[0] == 'F') + if (buffer[0] == 'F') { printf("input_pnm: server error.\n"); return 0; @@ -681,12 +661,12 @@ * keepalives */ n=0; - while (p->buffer[0] != 0x5a) { + while (buffer[0] != 0x5a) { int i; for (i=1; i<8; i++) { - p->buffer[i-1]=p->buffer[i]; + buffer[i-1]=buffer[i]; } - rm_read (*p->tcp, &p->buffer[7], 1); + rm_read (tcp, &buffer[7], 1); n++; } @@ -695,16 +675,16 @@ #endif /* check for 'Z's */ - if ((p->buffer[0] != 0x5a)||(p->buffer[7] != 0x5a)) + if ((buffer[0] != 0x5a)||(buffer[7] != 0x5a)) { printf("input_pnm: bad boundaries\n"); - hexdump(p->buffer, 8); + hexdump(buffer, 8); return 0; } /* check offsets */ - fof1=BE_16((uint8_t*)(&p->buffer[1])); - fof2=BE_16((uint8_t*)(&p->buffer[3])); + fof1=BE_16((uint8_t*)(&buffer[1])); + fof2=BE_16((uint8_t*)(&buffer[3])); if (fof1 != fof2) { printf("input_pnm: frame offsets are different: 0x%04x 0x%04x\n",fof1,fof2); @@ -712,121 +692,110 @@ } /* get first index */ - p->seq_current[0]=BE_16((uint8_t*)(&p->buffer[5])); + seq_current[0]=BE_16((uint8_t*)(&buffer[5])); /* now read the rest of stream chunk */ - n = rm_read (*p->tcp, &p->recv[5], fof1-5); + n = rm_read (tcp, &recv[5], fof1-5); if (n<(fof1-5)) return 0; /* get second index */ - p->seq_current[1]=p->recv[5]; + seq_current[1]=recv[5]; /* get timestamp */ - p->ts_current=BE_32(&p->recv[6]); + ts_current=BE_32(&recv[6]); /* get stream number */ - stream=pnm_calc_stream(p); + stream=calc_stream(); /* saving timestamp */ - p->ts_last[stream]=p->ts_current; + ts_last[stream]=ts_current; /* constructing a data packet header */ - p->recv[0]=0; /* object version */ - p->recv[1]=0; + recv[0]=0; /* object version */ + recv[1]=0; fof2=BE_16((uint8_t*)(&fof2)); - memcpy(&p->recv[2], &fof2, 2); - /*p->recv[2]=(fof2>>8)%0xff;*/ /* length */ - /*p->recv[3]=(fof2)%0xff;*/ + memcpy(&recv[2], &fof2, 2); + /*recv[2]=(fof2>>8)%0xff;*/ /* length */ + /*recv[3]=(fof2)%0xff;*/ - p->recv[4]=0; /* stream number */ - p->recv[5]=stream; + recv[4]=0; /* stream number */ + recv[5]=stream; - p->recv[10]=p->recv[10] & 0xfe; /* streambox seems to do that... */ + recv[10]=recv[10] & 0xfe; /* streambox seems to do that... */ - p->packet++; + packet++; - p->recv_size=fof1; + recv_size=fof1; return fof1; } -// pnm_t *pnm_connect(const char *mrl) { -pnm_t *pnm_connect(Tcp& tcp,const char *path) { +// Pnm *pnm_connect(const char *mrl) { +MPXP_Rc Pnm::connect(const std::string& _path) { - pnm_t *p=new(zeromem) pnm_t; int need_response=0; - p->path=mp_strdup(path); - p->tcp=&tcp; + path=_path; - pnm_send_request(p,pnm_available_bandwidths[10]); - if (!pnm_get_headers(p, &need_response)) { + send_request(pnm_available_bandwidths[10]); + if (!get_headers(&need_response)) { printf ("input_pnm: failed to set up stream\n"); - delete p->path; - delete p; - return NULL; + return MPXP_False; } - if (need_response) pnm_send_response(p, pnm_response); - p->ts_last[0]=0; - p->ts_last[1]=0; + if (need_response) send_response(pnm_response); + ts_last[0]=0; + ts_last[1]=0; /* copy header to recv */ - memcpy(p->recv, p->header, p->header_len); - p->recv_size = p->header_len; - p->recv_read = 0; + memcpy(recv, header, header_len); + recv_size = header_len; + recv_read = 0; - return p; + return MPXP_Ok; } -int pnm_read (pnm_t *self, char *data, int len) { +int Pnm::read (char *data, int len) { - int to_copy=len; - char *dest=data; - char *source=reinterpret_cast<char*>(self->recv) + self->recv_read; - int fill=self->recv_size - self->recv_read; + int to_copy=len; + char *dest=data; + char *source=reinterpret_cast<char*>(recv) + recv_read; + int fill=recv_size - recv_read; - if (len < 0) return 0; - while (to_copy > fill) { + if (len < 0) return 0; + while (to_copy > fill) { - memcpy(dest, source, fill); - to_copy -= fill; - dest += fill; - self->recv_read=0; + memcpy(dest, source, fill); + to_copy -= fill; + dest += fill; + recv_read=0; - if (!pnm_get_stream_chunk (self)) { + if (!get_stream_chunk ()) { #ifdef LOG - printf ("input_pnm: %d of %d bytes provided\n", len-to_copy, len); + printf ("input_pnm: %d of %d bytes provided\n", len-to_copy, len); #endif - return len-to_copy; + return len-to_copy; + } + source = reinterpret_cast<char*>(recv); + fill = recv_size - recv_read; } - source = reinterpret_cast<char*>(self->recv); - fill = self->recv_size - self->recv_read; - } - - memcpy(dest, source, to_copy); - self->recv_read += to_copy; - + memcpy(dest, source, to_copy); + recv_read += to_copy; #ifdef LOG - printf ("input_pnm: %d bytes provided\n", len); + printf ("input_pnm: %d bytes provided\n", len); #endif - - return len; + return len; } -int pnm_peek_header (pnm_t *self, char *data) { +int Pnm::peek_header (char *data) const { - memcpy (data, self->header, self->header_len); - return self->header_len; + memcpy (data, header, header_len); + return header_len; } -void pnm_close(pnm_t *p) { - - if (p->tcp->established()) p->tcp->close(); - delete p->path; - delete p->tcp; - delete p; +void Pnm::close() { + if (tcp.established()) tcp.close(); } - +} // namespace mpxp Modified: mplayerxp/libmpstream/pnm.h =================================================================== --- mplayerxp/libmpstream/pnm.h 2012-12-11 11:31:23 UTC (rev 536) +++ mplayerxp/libmpstream/pnm.h 2012-12-11 13:30:51 UTC (rev 537) @@ -25,22 +25,55 @@ #ifndef HAVE_PNM_H #define HAVE_PNM_H +#include <string> #ifndef __CYGWIN__ #include <inttypes.h> #endif /*#include "xine_internal.h" */ -typedef struct pnm_s pnm_t; namespace mpxp { class Tcp; -} -pnm_t* pnm_connect (Tcp&,const char *url); + class Pnm : public Opaque { + public: + Pnm(Tcp& tcp); + virtual ~Pnm(); -int pnm_read (pnm_t *self, char *data, int len); -void pnm_close (pnm_t *self); + enum sizes { + BUF_SIZE=4096, + HEADER_SIZE=4096 + }; -int pnm_peek_header (pnm_t *self, char *data); + virtual MPXP_Rc connect(const std::string& path); + virtual int read (char *data, int len); + virtual void close (); + virtual int peek_header(char *data) const; + private: + unsigned int get_chunk(unsigned int max, unsigned int *chunk_type,char *data, int *need_response) const; + int write_chunk(uint16_t chunk_id, uint16_t length, const char *chunk, char *data) const; + void send_request(uint32_t bandwidth); + void send_response(const char *response); + int get_headers(int *need_response); + int calc_stream(); + int get_stream_chunk(); + Tcp& tcp; + std::string path; + char buffer[Pnm::BUF_SIZE]; /* scratch buffer */ + /* receive buffer */ + uint8_t recv[Pnm::BUF_SIZE]; + int recv_size; + int recv_read; + + uint8_t header[Pnm::HEADER_SIZE]; + int header_len; + int header_read; + unsigned seq_num[4]; /* two streams with two indices */ + unsigned seq_current[2]; /* seqs of last stream chunk read */ + uint32_t ts_current; /* timestamp of current chunk */ + uint32_t ts_last[2]; /* timestamps of last chunks */ + unsigned packet; /* number of last recieved packet */ + }; +} // namespace mpxp #endif Modified: mplayerxp/libmpstream/s_ftp.cpp =================================================================== --- mplayerxp/libmpstream/s_ftp.cpp 2012-12-11 11:31:23 UTC (rev 536) +++ mplayerxp/libmpstream/s_ftp.cpp 2012-12-11 13:30:51 UTC (rev 537) @@ -52,7 +52,7 @@ const char* host; int port; const char* filename; - URL_t* url; + URL* url; char* cput,*cget; Tcp tcp; @@ -341,14 +341,14 @@ tcp.open(host,port); if(!tcp.established()) { - url_free(url); + delete url; return MPXP_False; } // We got a connection, let's start serious things buf = new char [BUFSIZE]; if (readresp(NULL) == 0) { close(); - url_free(url); + delete url; return MPXP_False; } // Login @@ -361,13 +361,13 @@ if(resp != 2) { MSG_ERR("[ftp] command '%s' failed: %s\n",str,rsp_txt); close(); - url_free(url); + delete url; return MPXP_False; } } else if(resp != 2) { MSG_ERR("[ftp] command '%s' failed: %s\n",str,rsp_txt); close(); - url_free(url); + delete url; return MPXP_False; } @@ -376,7 +376,7 @@ if(resp != 2) { MSG_ERR("[ftp] command 'TYPE I' failed: %s\n",rsp_txt); close(); - url_free(url); + delete url; return MPXP_False; } @@ -385,7 +385,7 @@ if(resp != 2) { MSG_ERR("[ftp] command 'SYST' failed: %s\n",rsp_txt); close(); - url_free(url); + delete url; return MPXP_False; } MSG_INFO("[ftp] System: %s\n",rsp_txt); @@ -393,7 +393,7 @@ if(resp != 2) { MSG_ERR("[ftp] command 'STAT' failed: %s\n",rsp_txt); close(); - url_free(url); + delete url; return MPXP_False; } @@ -414,7 +414,7 @@ // because the connection would stay open in the main process, // preventing correct abort with many servers. - url_free(url); + delete url; return MPXP_Ok; } Stream::type_e Ftp_Stream_Interface::type() const { return file_len?Stream::Type_Seekable:Stream::Type_Stream; } Modified: mplayerxp/libmpstream/s_network.cpp =================================================================== --- mplayerxp/libmpstream/s_network.cpp 2012-12-11 11:31:23 UTC (rev 536) +++ mplayerxp/libmpstream/s_network.cpp 2012-12-11 13:30:51 UTC (rev 537) @@ -37,7 +37,7 @@ virtual off_t sector_size() const; virtual std::string mime_type() const; private: - URL_t* url; + URL* url; off_t spos; Tcp tcp; networking_t* networking; @@ -47,10 +47,7 @@ :Stream_Interface(libinput), tcp(libinput,-1) {} Network_Stream_Interface::~Network_Stream_Interface() { - if(url) { - url_free(url); - delete url; - } + if(url) delete url; } MPXP_Rc Network_Stream_Interface::open(const std::string& filename,unsigned flags) @@ -61,7 +58,7 @@ networking=new_networking(); if(networking_start(tcp,networking,url)!=MPXP_Ok){ MSG_ERR(MSGTR_UnableOpenURL, filename.c_str()); - url_free(url); + delete url; url=NULL; free_networking(networking); networking=NULL; Modified: mplayerxp/libmpstream/s_rtsp.cpp =================================================================== --- mplayerxp/libmpstream/s_rtsp.cpp 2012-12-11 11:31:23 UTC (rev 536) +++ mplayerxp/libmpstream/s_rtsp.cpp 2012-12-11 13:30:51 UTC (rev 537) @@ -58,7 +58,8 @@ int Rtsp_Stream_Interface::read(stream_packet_t*sp) { - return rtsp_session_read (tcp,reinterpret_cast<rtsp_session_t*>(networking->data), sp->buf, sp->len); + Rtsp_Session& rtsp = *static_cast<Rtsp_Session*>(networking->data); + return rtsp.read (tcp, sp->buf, sp->len); } off_t Rtsp_Stream_Interface::seek(off_t newpos) { return newpos; } @@ -73,19 +74,16 @@ void Rtsp_Stream_Interface::close() { - rtsp_session_t *rtsp = NULL; - - rtsp = reinterpret_cast<rtsp_session_t*>(networking->data); - if (rtsp) - rtsp_session_end (rtsp); - url_free(networking->url); + Rtsp_Session* rtsp = static_cast<Rtsp_Session*>(networking->data); + if (rtsp) rtsp->end (); + delete networking->url; free_networking(networking); networking=NULL; } MPXP_Rc Rtsp_Stream_Interface::start() { - rtsp_session_t *rtsp; + Rtsp_Session *rtsp; char *mrl; char *file; int port; @@ -119,7 +117,7 @@ networking->url->username, networking->url->password); if (redirected == 1) { - url_free (networking->url); + delete networking->url; networking->url = url_new (mrl); tcp.close(); } @@ -141,7 +139,7 @@ extern int index_mode; MPXP_Rc Rtsp_Stream_Interface::open(const std::string& filename,unsigned flags) { - URL_t *url; + URL *url; UNUSED(flags); if(filename.substr(0,7)!="rtsp://") return MPXP_False; Modified: mplayerxp/libmpstream/s_udp.cpp =================================================================== --- mplayerxp/libmpstream/s_udp.cpp 2012-12-11 11:31:23 UTC (rev 536) +++ mplayerxp/libmpstream/s_udp.cpp 2012-12-11 13:30:51 UTC (rev 537) @@ -72,7 +72,6 @@ void Udp_Stream_Interface::close() { - url_free(networking->url); free_networking(networking); networking=NULL; } @@ -94,7 +93,7 @@ MPXP_Rc Udp_Stream_Interface::open(const std::string& filename,unsigned flags) { - URL_t *url; + URL *url; UNUSED(flags); MSG_V("STREAM_UDP, URL: %s\n", filename.c_str()); networking = new_networking(); Modified: mplayerxp/libmpstream/udp.cpp =================================================================== --- mplayerxp/libmpstream/udp.cpp 2012-12-11 11:31:23 UTC (rev 536) +++ mplayerxp/libmpstream/udp.cpp 2012-12-11 13:30:51 UTC (rev 537) @@ -45,7 +45,7 @@ namespace mpxp { /* Start listening on a UDP port. If multicast, join the group. */ -void Udp::open(const URL_t *url,int reuse_socket) +void Udp::open(const URL *url,int reuse_socket) { int socket_server_fd, rxsockbufsz; int err; @@ -175,7 +175,7 @@ return; } } -Udp::Udp(const URL_t *url,int reuse_socket) +Udp::Udp(const URL *url,int reuse_socket) :_fd(-1) ,_error(0) { Modified: mplayerxp/libmpstream/udp.h =================================================================== --- mplayerxp/libmpstream/udp.h 2012-12-11 11:31:23 UTC (rev 536) +++ mplayerxp/libmpstream/udp.h 2012-12-11 13:30:51 UTC (rev 537) @@ -25,10 +25,10 @@ class Udp { public: Udp(net_fd_t fd); - Udp(const URL_t* url,int reuse_socket=0); + Udp(const URL* url,int reuse_socket=0); virtual ~Udp(); - void open(const URL_t* url,int reuse_socket=0); + void open(const URL* url,int reuse_socket=0); net_fd_t socket() const { return _fd; } int established() const; int error() const { return _error; } Modified: mplayerxp/libmpstream/url.cpp =================================================================== --- mplayerxp/libmpstream/url.cpp 2012-12-11 11:31:23 UTC (rev 536) +++ mplayerxp/libmpstream/url.cpp 2012-12-11 13:30:51 UTC (rev 537) @@ -21,33 +21,33 @@ #include "mplayerxp.h" namespace mpxp { -URL_t *url_redirect(URL_t **url, const char *redir) { - URL_t *u = *url; - URL_t *res; - if (!strchr(redir, '/') || *redir == '/') { +URL *url_redirect(URL **url, const std::string& _redir) { + std::string redir=_redir; + URL *u = *url; + URL *res; + if (redir.find('/')==std::string::npos || redir[0] == '/') { char *tmp; - char *newurl = new char [strlen(u->url) + strlen(redir) + 1]; - strcpy(newurl, u->url); - if (*redir == '/') { - redir++; - tmp = strstr(newurl, "://"); + std::string newurl; + newurl=u->url; + if (redir[0] == '/') { + redir=redir.substr(1); + tmp = strstr(const_cast<char*>(newurl.c_str()), "://"); if (tmp) tmp = strchr(tmp + 3, '/'); } else - tmp = strrchr(newurl, '/'); + tmp = strrchr(const_cast<char*>(newurl.c_str()), '/'); if (tmp) tmp[1] = 0; - strcat(newurl, redir); + newurl+=redir; res = url_new(newurl); - delete newurl; } else res = url_new(redir); - url_free(u); + delete u; *url = res; return res; } -URL_t* url_new(const std::string& url) { +URL* url_new(const std::string& url) { int pos1, pos2,v6addr = 0; - URL_t* Curl = NULL; + URL* Curl = NULL; char *escfilename=NULL; char *ptr1=NULL, *ptr2=NULL, *ptr3=NULL, *ptr4=NULL; int jumpSize = 3; @@ -65,15 +65,12 @@ } // Create the URL container - Curl = new(zeromem) URL_t; + Curl = new(zeromem) URL; if( Curl==NULL ) { MSG_FATAL("MemAllocFailed\n"); goto err_out; } - // Initialisation of the URL container members - memset( Curl, 0, sizeof(URL_t) ); - string2url(escfilename,url); // Copy the url in the URL container @@ -220,23 +217,20 @@ return Curl; err_out: if (escfilename) delete escfilename; - if (Curl) url_free(Curl); + if (Curl) delete Curl; return NULL; } -void -url_free(URL_t* url) { - if(!url) return; - if(url->url) delete url->url; - if(url->protocol) delete url->protocol; - if(url->hostname) delete url->hostname; - if(url->file) delete url->file; - if(url->username) delete url->username; - if(url->password) delete url->password; - delete url; +URL::URL() {} +URL::~URL() { + if(url) delete url; + if(protocol) delete protocol; + if(hostname) delete hostname; + if(file) delete file; + if(username) delete username; + if(password) delete password; } - /* Replace escape sequences in an URL (or a part of an URL) */ /* works like strcpy(), but without return argument */ void @@ -373,7 +367,7 @@ #ifdef __URL_DEBUG void -url_debug(const URL_t *url) { +url_debug(const URL *url) { if( url==NULL ) { printf("URL pointer NULL\n"); return; Modified: mplayerxp/libmpstream/url.h =================================================================== --- mplayerxp/libmpstream/url.h 2012-12-11 11:31:23 UTC (rev 536) +++ mplayerxp/libmpstream/url.h 2012-12-11 13:30:51 UTC (rev 537) @@ -10,25 +10,28 @@ //#define __URL_DEBUG namespace mpxp { - typedef struct { - char *url; - char *protocol; - char *hostname; - char *file; - unsigned int port; - char *username; - char *password; - } URL_t; + struct URL : public Opaque { + public: + URL(); + virtual ~URL(); - URL_t* url_new(const std::string& url); - void url_free(URL_t* url); + const char* url; + char* protocol; + char* hostname; + char* file; + unsigned int port; + char* username; + char* password; + }; - URL_t *url_redirect(URL_t **url, const char *redir); + URL* url_new(const std::string& url); + + URL *url_redirect(URL **url, const std::string& redir); void url2string(char *outbuf, const std::string& inbuf); void string2url(char *outbuf, const std::string& inbuf); #ifdef __URL_DEBUG - void url_debug(URL_t* url); + void url_debug(URL* url); #endif // __URL_DEBUG } // namespace #endif // __URL_H This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |