[Mplayerxp-cvslog] SF.net SVN: mplayerxp:[531] mplayerxp
Brought to you by:
olov
From: <nic...@us...> - 2012-12-10 13:18:27
|
Revision: 531 http://mplayerxp.svn.sourceforge.net/mplayerxp/?rev=531&view=rev Author: nickols_k Date: 2012-12-10 13:18:14 +0000 (Mon, 10 Dec 2012) Log Message: ----------- convert cdda_priv_t into class CDD_Interface + using std::string Modified Paths: -------------- mplayerxp/libmpstream/cdd.h mplayerxp/libmpstream/cdda.cpp mplayerxp/libmpstream/cddb.cpp mplayerxp/libmpstream/s_cdd.cpp mplayerxp/libvo/vo_sdl.cpp Modified: mplayerxp/libmpstream/cdd.h =================================================================== --- mplayerxp/libmpstream/cdd.h 2012-12-10 11:27:53 UTC (rev 530) +++ mplayerxp/libmpstream/cdd.h 2012-12-10 13:18:14 UTC (rev 531) @@ -7,18 +7,18 @@ struct libinput_t; struct cddb_data_t { - char cddb_hello[1024]; - unsigned long disc_id; - unsigned int tracks; - char *cache_dir; - char *freedb_server; - int freedb_proto_level; - int anonymous; - char category[100]; - char *xmcd_file; - size_t xmcd_file_size; - any_t*user_data; - libinput_t*libinput; + std::string cddb_hello; + unsigned long disc_id; + unsigned int tracks; + char* cache_dir; + const char* freedb_server; + int freedb_proto_level; + int anonymous; + std::string category; + char* xmcd_file; + size_t xmcd_file_size; + any_t* user_data; + libinput_t* libinput; }; struct cd_toc_t { @@ -26,7 +26,7 @@ }; struct cd_track_t { - char *name; + std::string name; unsigned int track_nb; unsigned int min; unsigned int sec; @@ -37,17 +37,29 @@ cd_track_t *next; }; - struct cd_info_t { - char *artist; - char *album; - char *genre; - unsigned int nb_tracks; - unsigned int min; - unsigned int sec; - unsigned msec; - cd_track_t *first; - cd_track_t *last; - cd_track_t *current; + class CD_Info : public Opaque { + public: + CD_Info(); + virtual ~CD_Info(); + + virtual cd_track_t* add_track(const char *track_name, unsigned int track_nb, unsigned int min, unsigned int sec, unsigned int msec, unsigned long frame_begin, unsigned long frame_length); + virtual cd_track_t* get_track(unsigned int track_nb) const; + + virtual void print() const; + virtual MPXP_Rc parse_xmcd(const char *_xmcd_file); + + std::string artist; + std::string album; + std::string genre; + private: + unsigned int nb_tracks; + unsigned int min; + unsigned int sec; + unsigned msec; + + cd_track_t *first; + cd_track_t *last; + cd_track_t *current; }; struct my_track_t { @@ -56,11 +68,25 @@ lsn_t end_sector; }; - struct cdda_priv : public Opaque { + class CDD_Interface : public Opaque { public: - cdda_priv(); - virtual ~cdda_priv(); + CDD_Interface(); + virtual ~CDD_Interface(); + virtual MPXP_Rc open_cdda(const char* dev,const char* track); + virtual MPXP_Rc open_cddb(libinput_t*,const char* dev,const char* track); + + virtual int read(char *buf,track_t* trackidx); + virtual void seek(off_t pos,track_t *trackidx); + virtual off_t tell() const; + virtual void close(); + virtual off_t start() const; + virtual off_t size() const; + virtual int channels(unsigned track_idx) const; + private: + lsn_t map_sector(lsn_t sector,track_t *tr); + unsigned long psa(unsigned long sector); + cdrom_drive_t* cd; my_track_t tracks[256]; /* hope that's enough */ unsigned min; @@ -71,19 +97,6 @@ lsn_t end_sector; }; - cd_info_t* __FASTCALL__ cd_info_new(); - void __FASTCALL__ cd_info_free(cd_info_t *cd_info); - cd_track_t* __FASTCALL__ cd_info_add_track(cd_info_t *cd_info, char *track_name, unsigned int track_nb, unsigned int min, unsigned int sec, unsigned int msec, unsigned long frame_begin, unsigned long frame_length); - cd_track_t* __FASTCALL__ cd_info_get_track(cd_info_t *cd_info, unsigned int track_nb); - - cdda_priv* __FASTCALL__ open_cdda(const char* dev,const char* track); - cdda_priv* __FASTCALL__ open_cddb(libinput_t*,const char* dev,const char* track); - int __FASTCALL__ read_cdda(cdda_priv* s,char *buf,track_t* trackidx); - void __FASTCALL__ seek_cdda(cdda_priv* s,off_t pos,track_t *trackidx); - off_t __FASTCALL__ tell_cdda(const cdda_priv* s); - void __FASTCALL__ close_cdda(cdda_priv*); - off_t __FASTCALL__ cdda_start(cdda_priv*); - off_t __FASTCALL__ cdda_size(cdda_priv*); void cdda_register_options(m_config_t* cfg); } // namespace mpxp #endif // __CDD_H__ Modified: mplayerxp/libmpstream/cdda.cpp =================================================================== --- mplayerxp/libmpstream/cdda.cpp 2012-12-10 11:27:53 UTC (rev 530) +++ mplayerxp/libmpstream/cdda.cpp 2012-12-10 13:18:14 UTC (rev 531) @@ -75,152 +75,144 @@ return rval; } -cdda_priv* __FASTCALL__ open_cdda(const char* dev,const char* arg) { +MPXP_Rc CDD_Interface::open_cdda(const char* dev,const char* arg) { unsigned cd_tracks; - cdda_priv* priv; unsigned int audiolen=0; unsigned i; unsigned char arr[256]; int st_inited; - priv = new(zeromem) cdda_priv; + cd = cdio_cddap_identify(dev,mp_conf.verbose?1:0,NULL); - priv->cd = cdio_cddap_identify(dev,mp_conf.verbose?1:0,NULL); - - if(!priv->cd) { + if(!cd) { MSG_ERR("Can't open cdda device: %s\n",dev); - delete priv; - return NULL; + return MPXP_False; } - cdio_cddap_verbose_set(priv->cd, mp_conf.verbose?CDDA_MESSAGE_PRINTIT:CDDA_MESSAGE_FORGETIT, mp_conf.verbose?CDDA_MESSAGE_PRINTIT:CDDA_MESSAGE_FORGETIT); + cdio_cddap_verbose_set(cd, mp_conf.verbose?CDDA_MESSAGE_PRINTIT:CDDA_MESSAGE_FORGETIT, mp_conf.verbose?CDDA_MESSAGE_PRINTIT:CDDA_MESSAGE_FORGETIT); - if(cdio_cddap_open(priv->cd) != 0) { + if(cdio_cddap_open(cd) != 0) { MSG_ERR("Can't open disc\n"); - cdda_close(priv->cd); - delete priv; - return NULL; + cdda_close(cd); + return MPXP_False; } - cd_tracks=cdio_cddap_tracks(priv->cd); + cd_tracks=cdio_cddap_tracks(cd); MSG_V("Found %d tracks on disc\n",cd_tracks); if(!arg[0]) - for(i=1;i<=cd_tracks;i++) priv->tracks[i-1].play=1; + for(i=1;i<=cd_tracks;i++) tracks[i-1].play=1; cdda_parse_tracks(arr,sizeof(arr)/sizeof(unsigned),arg); - for(i=1;i<=256;i++) if (arr[i]) priv->tracks[i-1].play=1; + for(i=1;i<=256;i++) if (arr[i]) tracks[i-1].play=1; st_inited=0; MSG_V("[CDDA] Queued tracks:"); for(i=0;i<cd_tracks;i++) { - if(priv->tracks[i].play) { - priv->tracks[i].start_sector=cdio_cddap_track_firstsector(priv->cd,i+1); - priv->tracks[i].end_sector=cdio_cddap_track_lastsector(priv->cd,i+1); - MSG_V(" %d[%d-%d]",i+1,priv->tracks[i].start_sector,priv->tracks[i].end_sector); - if(!st_inited) { priv->start_sector=priv->tracks[i].start_sector; st_inited=1; } - priv->end_sector=priv->tracks[i].end_sector; - audiolen += priv->tracks[i].end_sector-priv->tracks[i].start_sector+1; + if(tracks[i].play) { + tracks[i].start_sector=cdio_cddap_track_firstsector(cd,i+1); + tracks[i].end_sector=cdio_cddap_track_lastsector(cd,i+1); + MSG_V(" %d[%d-%d]",i+1,tracks[i].start_sector,tracks[i].end_sector); + if(!st_inited) { start_sector=tracks[i].start_sector; st_inited=1; } + end_sector=tracks[i].end_sector; + audiolen +=tracks[i].end_sector-tracks[i].start_sector+1; } } - for(;i<256;i++) priv->tracks[i].play=0; + for(;i<256;i++) tracks[i].play=0; MSG_V("\n"); - priv->min = (unsigned int)(audiolen/(60*75)); - priv->sec = (unsigned int)((audiolen/75)%60); - priv->msec = (unsigned int)(audiolen%75); + min = (unsigned int)(audiolen/(60*75)); + sec = (unsigned int)((audiolen/75)%60); + msec = (unsigned int)(audiolen%75); - if(speed) cdio_cddap_speed_set(priv->cd,speed); + if(speed) cdio_cddap_speed_set(cd,speed); - priv->sector = priv->start_sector; - return priv; + sector = start_sector; + return MPXP_Ok; } -off_t __FASTCALL__ cdda_start(cdda_priv* priv) { return priv->start_sector*CDIO_CD_FRAMESIZE_RAW; } -off_t __FASTCALL__ cdda_size(cdda_priv* priv) { return priv->end_sector*CDIO_CD_FRAMESIZE_RAW; } - -static lsn_t map_sector(cdda_priv*p,lsn_t sector,track_t *tr) +off_t CDD_Interface::start() const { return start_sector*CDIO_CD_FRAMESIZE_RAW; } +off_t CDD_Interface::size() const { return end_sector*CDIO_CD_FRAMESIZE_RAW; } +int CDD_Interface::channels(unsigned track_idx) const { return cdio_cddap_track_channels(cd, track_idx); } +lsn_t CDD_Interface::map_sector(lsn_t _sector,track_t *tr) { unsigned i,j; - lsn_t cd_track=sector; + lsn_t cd_track=_sector; for(i=0;i<256;i++){ - if(p->tracks[i].play && p->tracks[i].end_sector==sector) { - cd_track=0; - MSG_V("Found track changing. old track=%u Sector=%u",i,sector); - for(j=i+1;j<256;j++) { - if(p->tracks[j].play && p->tracks[j].start_sector==sector+1) { - cd_track=p->tracks[j].start_sector; - if(tr) *tr=j; - MSG_V("new track=%u Sector=%u",j,cd_track); - } + if(tracks[i].play && tracks[i].end_sector==_sector) { + cd_track=0; + MSG_V("Found track changing. old track=%u Sector=%u",i,_sector); + for(j=i+1;j<256;j++) { + if(tracks[j].play && tracks[j].start_sector==_sector+1) { + cd_track=tracks[j].start_sector; + if(tr) *tr=j; + MSG_V("new track=%u Sector=%u",j,cd_track); } + } } } return cd_track; } /* return physical sector address */ -static unsigned long psa(cdda_priv*p,unsigned long sector) +unsigned long CDD_Interface::psa(unsigned long _sector) { unsigned i; - unsigned long got_sectors=p->start_sector,track_len; + unsigned long got_sectors=start_sector,track_len; for(i=0;i<256;i++){ - if(p->tracks[i].play) { - track_len=p->tracks[i].end_sector-p->tracks[i].start_sector; - if(sector>=got_sectors && sector <= track_len) return sector+p->tracks[i].start_sector; + if(tracks[i].play) { + track_len=tracks[i].end_sector-tracks[i].start_sector; + if(_sector>=got_sectors && _sector <= track_len) return _sector+tracks[i].start_sector; got_sectors+=track_len; } } return 0; } -int __FASTCALL__ read_cdda(cdda_priv* p,char *buf,track_t *tr) { - track_t i=255; +int CDD_Interface::read(char *buf,track_t *tr) { + track_t i=255; - if(cdio_cddap_read(p->cd, buf, p->sector, 1)==0) { - MSG_ERR("[CD-DA]: read error occured\n"); - return -1; /* EOF */ - } - p->sector++; - if(p->sector == p->end_sector) { - MSG_DBG2("EOF was reached\n"); - return -1; /* EOF */ - } + if(cdio_cddap_read(cd, buf, sector, 1)==0) { + MSG_ERR("[CD-DA]: read error occured\n"); + return -1; /* EOF */ + } + sector++; + if(sector == end_sector) { + MSG_DBG2("EOF was reached\n"); + return -1; /* EOF */ + } - p->sector=map_sector(p,p->sector,&i); - if(!p->sector) return -1; - if(i!=255) { - *tr=i+1; - MSG_V("Track %d, sector=%d\n", *tr, p->sector); - } - else MSG_DBG2("Track %d, sector=%d\n", *tr, p->sector); - return CDIO_CD_FRAMESIZE_RAW; + sector=map_sector(sector,&i); + if(!sector) return -1; + if(i!=255) { + *tr=i+1; + MSG_V("Track %d, sector=%d\n", *tr, sector); + } else MSG_DBG2("Track %d, sector=%d\n", *tr, sector); + return CDIO_CD_FRAMESIZE_RAW; } -void __FASTCALL__ seek_cdda(cdda_priv* p,off_t pos,track_t *tr) { - long sec; +void CDD_Interface::seek(off_t pos,track_t *tr) { + long _sec; long seeked_track=0; track_t j=255; - sec = pos/CDIO_CD_FRAMESIZE_RAW; - MSG_DBG2("[CDDA] prepare seek to %ld\n",sec); - seeked_track=sec; + _sec = pos/CDIO_CD_FRAMESIZE_RAW; + MSG_DBG2("[CDDA] prepare seek to %ld\n",_sec); + seeked_track=_sec; *tr=255; - if( p->sector!=seeked_track ) { - seeked_track = map_sector(p,seeked_track,&j); + if( sector!=seeked_track ) { + seeked_track = map_sector(seeked_track,&j); if(seeked_track) *tr=j+1; } - p->sector=seeked_track; + sector=seeked_track; } -off_t __FASTCALL__ tell_cdda(const cdda_priv* p) { - return p->sector*CDIO_CD_FRAMESIZE_RAW; +off_t CDD_Interface::tell() const { + return sector*CDIO_CD_FRAMESIZE_RAW; } -void __FASTCALL__ close_cdda(cdda_priv* p) { - delete p; -} - -cdda_priv::cdda_priv() {} -cdda_priv::~cdda_priv() { +void CDD_Interface::close() { cdio_cddap_close(cd); } + +CDD_Interface::CDD_Interface() {} +CDD_Interface::~CDD_Interface() {} } // namespace mpxp #endif Modified: mplayerxp/libmpstream/cddb.cpp =================================================================== --- mplayerxp/libmpstream/cddb.cpp 2012-12-10 11:27:53 UTC (rev 530) +++ mplayerxp/libmpstream/cddb.cpp 2012-12-10 13:18:14 UTC (rev 531) @@ -57,7 +57,7 @@ static cd_toc_t cdtoc[100]; #if defined(__linux__) -int read_toc(void) { +static int read_toc(void) { int drive = open("/dev/cdrom", O_RDONLY | O_NONBLOCK); struct cdrom_tochdr tochdr; struct cdrom_tocentry tocentry; @@ -87,7 +87,7 @@ } #elif defined(SYS_BSD) -int read_toc(void) { +static int read_toc(void) { int drive = open("/dev/acd0c", O_RDONLY | O_NONBLOCK); struct ioc_toc_header tochdr; struct ioc_read_toc_single_entry tocentry; @@ -117,7 +117,7 @@ } #endif -unsigned int __FASTCALL__ cddb_sum(int n) { +static unsigned int __FASTCALL__ cddb_sum(int n) { unsigned int ret; ret = 0; @@ -128,7 +128,7 @@ return ret; } -unsigned long __FASTCALL__ cddb_discid(int tot_trks) { +static unsigned long __FASTCALL__ cddb_discid(int tot_trks) { unsigned int i, t = 0, n = 0; i = 0; @@ -141,7 +141,7 @@ return ((n % 0xff) << 24 | t << 8 | tot_trks); } -int __FASTCALL__ cddb_http_request(const char *command, int (*reply_parser)(HTTP_header_t*,cddb_data_t*), cddb_data_t *cddb_data) { +static int __FASTCALL__ cddb_http_request(const char *command, int (*reply_parser)(HTTP_header_t*,cddb_data_t*), cddb_data_t *cddb_data) { char request[4096]; int ret = 0; Tcp tcp(cddb_data->libinput,-1); @@ -150,7 +150,7 @@ 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, cddb_data->freedb_proto_level ); + 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); @@ -190,7 +190,7 @@ return ret; } -int __FASTCALL__ cddb_read_cache(cddb_data_t *cddb_data) { +static int __FASTCALL__ cddb_read_cache(cddb_data_t *cddb_data) { char file_name[100]; struct stat stats; int file_fd, ret; @@ -214,7 +214,7 @@ file_size = stats.st_size; } - cddb_data->xmcd_file = (char*)mp_malloc(file_size); + cddb_data->xmcd_file = new char [file_size]; if( cddb_data->xmcd_file==NULL ) { MSG_FATAL("Memory allocation failed\n"); close(file_fd); @@ -232,7 +232,7 @@ return 0; } -int __FASTCALL__ cddb_write_cache(cddb_data_t *cddb_data) { +static int __FASTCALL__ cddb_write_cache(cddb_data_t *cddb_data) { // We have the file, save it for cache. char file_name[100]; int file_fd; @@ -321,80 +321,80 @@ return 0; } -int __FASTCALL__ cddb_request_titles(cddb_data_t *cddb_data) { - char command[1024]; - sprintf( command, "cddb+read+%s+%08lx", cddb_data->category, cddb_data->disc_id); - return cddb_http_request(command, cddb_read_parse, cddb_data); +static int __FASTCALL__ cddb_request_titles(cddb_data_t *cddb_data) { + char command[1024]; + sprintf( command, "cddb+read+%s+%08lx", cddb_data->category.c_str(), cddb_data->disc_id); + return cddb_http_request(command, cddb_read_parse, cddb_data); } static int cddb_query_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) { - char album_title[100]; - char *ptr = NULL; - int ret, status; + char album_title[100]; + char *ptr = NULL; + int ret, status; - ret = sscanf((char*)http_hdr->body, "%d ", &status); - if( ret!=1 ) { + ret = sscanf((char*)http_hdr->body, "%d ", &status); + if( ret!=1 ) { + MSG_ERR("Parse error\n"); + return -1; + } + + switch(status) { + case 200: + // Found exact match + ret = sscanf((char*)http_hdr->body, "%d %s %08lx %s", &status, cddb_data->category.c_str(), &(cddb_data->disc_id), album_title); + if( ret!=4 ) { MSG_ERR("Parse error\n"); return -1; - } - - switch(status) { - case 200: - // Found exact match - ret = sscanf((char*)http_hdr->body, "%d %s %08lx %s", &status, cddb_data->category, &(cddb_data->disc_id), album_title); - if( ret!=4 ) { - MSG_ERR("Parse error\n"); - return -1; - } - ptr = strstr((char*)http_hdr->body, album_title); - if( ptr!=NULL ) { - char *ptr2; - int len; - ptr2 = strstr(ptr, "\n"); - if( ptr2==NULL ) { - len = (http_hdr->body_size)-(ptr-(char*)(http_hdr->body)); - } else { - len = ptr2-ptr+1; - } - strncpy(album_title, ptr, len); - album_title[len-2]='\0'; - } - MSG_V("Parse OK, found: %s\n", album_title); - return cddb_request_titles(cddb_data); - case 202: - // No match found - MSG_ERR("Album not found\n"); - break; - case 210: - // Found exact matches, list follows - ptr = strstr((char*)http_hdr->body, "\n"); - if( ptr==NULL ) { - MSG_ERR("Unable to find end of line\n"); - return -1; - } - ptr++; - // We have a list of exact matches, so which one do - // we use? So let's take the first one. - ret = sscanf(ptr, "%s %08lx %s", cddb_data->category, &(cddb_data->disc_id), album_title); - if( ret!=3 ) { - MSG_ERR("Parse error\n"); - return -1; - } - ptr = strstr((char*)http_hdr->body, album_title); - if( ptr!=NULL ) { - char *ptr2; - int len; - ptr2 = strstr(ptr, "\n"); - if( ptr2==NULL ) { - len = (http_hdr->body_size)-(ptr-(char*)(http_hdr->body)); - } else { - len = ptr2-ptr+1; - } - strncpy(album_title, ptr, len); - album_title[len-2]='\0'; - } - MSG_V("Parse OK, found: %s\n", album_title); - return cddb_request_titles(cddb_data); + } + ptr = strstr((char*)http_hdr->body, album_title); + if( ptr!=NULL ) { + char *ptr2; + int len; + ptr2 = strstr(ptr, "\n"); + if( ptr2==NULL ) { + len = (http_hdr->body_size)-(ptr-(char*)(http_hdr->body)); + } else { + len = ptr2-ptr+1; + } + strncpy(album_title, ptr, len); + album_title[len-2]='\0'; + } + MSG_V("Parse OK, found: %s\n", album_title); + return cddb_request_titles(cddb_data); + case 202: + // No match found + MSG_ERR("Album not found\n"); + break; + case 210: + // Found exact matches, list follows + ptr = strstr((char*)http_hdr->body, "\n"); + if( ptr==NULL ) { + MSG_ERR("Unable to find end of line\n"); + return -1; + } + ptr++; + // We have a list of exact matches, so which one do + // we use? So let's take the first one. + ret = sscanf(ptr, "%s %08lx %s", cddb_data->category.c_str(), &(cddb_data->disc_id), album_title); + if( ret!=3 ) { + MSG_ERR("Parse error\n"); + return -1; + } + ptr = strstr((char*)http_hdr->body, album_title); + if( ptr!=NULL ) { + char *ptr2; + int len; + ptr2 = strstr(ptr, "\n"); + if( ptr2==NULL ) { + len = (http_hdr->body_size)-(ptr-(char*)(http_hdr->body)); + } else { + len = ptr2-ptr+1; + } + strncpy(album_title, ptr, len); + album_title[len-2]='\0'; + } + MSG_V("Parse OK, found: %s\n", album_title); + return cddb_request_titles(cddb_data); /* body=[210 Found exact matches, list follows (until terminating `.') misc c711930d Santana / Supernatural @@ -402,99 +402,99 @@ blues c711930d Santana / Supernatural .] */ - case 211: - // Found inexact matches, list follows - MSG_WARN("No exact matches found, list follows\n"); - break; - default: - MSG_ERR("Unhandled code\n"); - } - return -1; + case 211: + // Found inexact matches, list follows + MSG_WARN("No exact matches found, list follows\n"); + break; + default: + MSG_ERR("Unhandled code\n"); + } + return -1; } static int cddb_proto_level_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) { - int max; - int ret, status; - char *ptr; + int max; + int ret, status; + char *ptr; - ret = sscanf((char*)http_hdr->body, "%d ", &status); - if( ret!=1 ) { + ret = sscanf((char*)http_hdr->body, "%d ", &status); + if( ret!=1 ) { + MSG_ERR("Parse error\n"); + return -1; + } + + switch(status) { + case 210: + ptr = strstr((char*)http_hdr->body, "max proto:"); + if( ptr==NULL ) { MSG_ERR("Parse error\n"); return -1; - } - - switch(status) { - case 210: - ptr = strstr((char*)http_hdr->body, "max proto:"); - if( ptr==NULL ) { - MSG_ERR("Parse error\n"); - return -1; - } - ret = sscanf(ptr, "max proto: %d", &max); - if( ret!=1 ) { - MSG_ERR("Parse error\n"); - return -1; - } - cddb_data->freedb_proto_level = max; - return 0; - default: - MSG_ERR("Unhandled code\n"); - } - return -1; + } + ret = sscanf(ptr, "max proto: %d", &max); + if( ret!=1 ) { + MSG_ERR("Parse error\n"); + return -1; + } + cddb_data->freedb_proto_level = max; + return 0; + default: + MSG_ERR("Unhandled code\n"); + } + return -1; } -int __FASTCALL__ cddb_get_proto_level(cddb_data_t *cddb_data) { - return cddb_http_request("stat", cddb_proto_level_parse, cddb_data); +static int __FASTCALL__ cddb_get_proto_level(cddb_data_t *cddb_data) { + return cddb_http_request("stat", cddb_proto_level_parse, cddb_data); } static int cddb_freedb_sites_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) { - int ret, status; - UNUSED(cddb_data); - ret = sscanf((char*)http_hdr->body, "%d ", &status); - if( ret!=1 ) { - MSG_ERR("Parse error\n"); - return -1; - } - - switch(status) { - case 210: - // Parse the sites - return 0; - case 401: - MSG_ERR("No sites information available\n"); - break; - default: - MSG_ERR("Unhandled code\n"); - } + int ret, status; + UNUSED(cddb_data); + ret = sscanf((char*)http_hdr->body, "%d ", &status); + if( ret!=1 ) { + MSG_ERR("Parse error\n"); return -1; + } + + switch(status) { + case 210: + // Parse the sites + return 0; + case 401: + MSG_ERR("No sites information available\n"); + break; + default: + MSG_ERR("Unhandled code\n"); + } + return -1; } -int __FASTCALL__ cddb_get_freedb_sites(cddb_data_t *cddb_data) { - return cddb_http_request("sites", cddb_freedb_sites_parse, cddb_data); +static int __FASTCALL__ cddb_get_freedb_sites(cddb_data_t *cddb_data) { + return cddb_http_request("sites", cddb_freedb_sites_parse, cddb_data); } -void __FASTCALL__ cddb_create_hello(cddb_data_t *cddb_data) { - char host_name[51]; - const char *user_name; +static void __FASTCALL__ cddb_create_hello(cddb_data_t *cddb_data) { + char host_name[51]; + const char *user_name; - if( cddb_data->anonymous ) { // Default is anonymous - /* Note from Eduardo P\xE9rez Ureta <ep...@it...> : - * We don't send current user/host name in hello to prevent spam. - * Software that sends this is considered spyware - * that most people don't like. - */ - user_name = "anonymous"; - strcpy(host_name, "localhost"); - } else { - if( gethostname(host_name, 50)<0 ) { - strcpy(host_name, "localhost"); - } - user_name = getenv("LOGNAME"); + if( cddb_data->anonymous ) { // Default is anonymous + /* Note from Eduardo P\xE9rez Ureta <ep...@it...> : + * We don't send current user/host name in hello to prevent spam. + * Software that sends this is considered spyware + * that most people don't like. + */ + user_name = "anonymous"; + strcpy(host_name, "localhost"); + } else { + if( gethostname(host_name, 50)<0 ) { + strcpy(host_name, "localhost"); } - sprintf( cddb_data->cddb_hello, "&hello=%s+%s+%s+%s", user_name, host_name, "MPlayerXP", VERSION); + user_name = getenv("LOGNAME"); + } + cddb_data->cddb_hello=std::string("&hello=")+user_name+"+"+host_name+"+"+"MPlayerXP"+"+"+VERSION; } -int __FASTCALL__ cddb_retrieve(cddb_data_t *cddb_data) { +static int __FASTCALL__ cddb_retrieve(cddb_data_t *cddb_data) { char offsets[1024], command[1024]; char *ptr; unsigned idx; @@ -528,7 +528,7 @@ return 0; } -MPXP_Rc __FASTCALL__ cddb_resolve(libinput_t*libinput,char **xmcd_file) { +static MPXP_Rc __FASTCALL__ cddb_resolve(libinput_t*libinput,char **xmcd_file) { char cddb_cache_dir[] = DEFAULT_CACHE_DIR; char *home_dir = NULL; cddb_data_t cddb_data; @@ -571,228 +571,183 @@ * *******************************************************************************************************************/ -cd_info_t* __FASTCALL__ cd_info_new() { - cd_info_t *cd_info = NULL; - - cd_info = (cd_info_t*)mp_mallocz(sizeof(cd_info_t)); - if( cd_info==NULL ) { - MSG_FATAL("Memory allocation failed\n"); - return NULL; +CD_Info::CD_Info() {} +CD_Info::~CD_Info() { + cd_track_t *cd_track, *cd_track_next; + cd_track_next = first; + while( cd_track_next!=NULL ) { + cd_track = cd_track_next; + cd_track_next = cd_track->next; + delete cd_track; } - - return cd_info; } -void __FASTCALL__ cd_info_free(cd_info_t *cd_info) { - cd_track_t *cd_track, *cd_track_next; - if( cd_info==NULL ) return; - if( cd_info->artist!=NULL ) delete cd_info->artist; - if( cd_info->album!=NULL ) delete cd_info->album; - if( cd_info->genre!=NULL ) delete cd_info->genre; +cd_track_t* CD_Info::add_track(const char *track_name, + unsigned int track_nb, + unsigned int _min, + unsigned int _sec, + unsigned int _msec, + unsigned long frame_begin, + unsigned long frame_length) { + cd_track_t *cd_track; - cd_track_next = cd_info->first; - while( cd_track_next!=NULL ) { - cd_track = cd_track_next; - cd_track_next = cd_track->next; - if( cd_track->name!=NULL ) delete cd_track->name; - delete cd_track; - } -} + if( track_name==NULL ) return NULL; -cd_track_t* __FASTCALL__ cd_info_add_track(cd_info_t *cd_info, char *track_name, unsigned int track_nb, unsigned int min, unsigned int sec, unsigned int msec, unsigned long frame_begin, unsigned long frame_length) { - cd_track_t *cd_track; - - if( cd_info==NULL || track_name==NULL ) return NULL; - - cd_track = (cd_track_t*)mp_mallocz(sizeof(cd_track_t)); - if( cd_track==NULL ) { + cd_track = new(zeromem) cd_track_t; + if( cd_track==NULL ) { MSG_FATAL("Memory allocation failed\n"); return NULL; - } - cd_track->name = (char*)mp_malloc(strlen(track_name)+1); - if( cd_track->name==NULL ) { - MSG_FATAL("Memory allocation failed\n"); - delete cd_track; - return NULL; - } - strcpy(cd_track->name, track_name); - cd_track->track_nb = track_nb; - cd_track->min = min; - cd_track->sec = sec; - cd_track->msec = msec; - cd_track->frame_begin = frame_begin; - cd_track->frame_length = frame_length; + } + cd_track->name=track_name; + cd_track->track_nb = track_nb; + cd_track->min = _min; + cd_track->sec = _sec; + cd_track->msec = _msec; + cd_track->frame_begin = frame_begin; + cd_track->frame_length = frame_length; - if( cd_info->first==NULL ) { - cd_info->first = cd_track; - } - if( cd_info->last!=NULL ) { - cd_info->last->next = cd_track; - } + if( first==NULL ) first = cd_track; + if( last!=NULL ) last->next = cd_track; - cd_track->prev = cd_info->last; + cd_track->prev = last; - cd_info->last = cd_track; - cd_info->current = cd_track; + last = cd_track; + current = cd_track; - cd_info->nb_tracks++; + nb_tracks++; - return cd_track; + return cd_track; } -cd_track_t* __FASTCALL__ cd_info_get_track(cd_info_t *cd_info, unsigned int track_nb) { - cd_track_t *cd_track=NULL; +cd_track_t* CD_Info::get_track(unsigned int track_nb) const { + cd_track_t *cd_track=NULL; - if( cd_info==NULL ) return NULL; - - cd_track = cd_info->first; - while( cd_track!=NULL ) { - if( cd_track->track_nb==track_nb ) { - return cd_track; - } - cd_track = cd_track->next; - } - return NULL; + cd_track = first; + while( cd_track!=NULL ) { + if( cd_track->track_nb==track_nb ) return cd_track; + cd_track = cd_track->next; + } + return NULL; } -void __FASTCALL__ cd_info_debug(cd_info_t *cd_info) { - cd_track_t *current_track; - MSG_INFO("================ CD INFO === start =========\n"); - if( cd_info==NULL ) { - MSG_INFO("cd_info is NULL\n"); - return; - } - MSG_INFO(" artist=[%s]\n" - " album=[%s]\n" - " genre=[%s]\n" - " nb_tracks=%d\n" - " length= %2d:%02d.%02d\n" - , cd_info->artist - , cd_info->album - , cd_info->genre - , cd_info->nb_tracks - , cd_info->min, cd_info->sec, cd_info->msec); - current_track = cd_info->first; - while( current_track!=NULL ) { - MSG_V(" #%2d %2d:%02d.%02d @ %7ld\t[%s] \n", current_track->track_nb, current_track->min, current_track->sec, current_track->msec, current_track->frame_begin, current_track->name); - current_track = current_track->next; - } - MSG_INFO("================ CD INFO === end =========\n"); +void CD_Info::print() const { + cd_track_t *current_track; + MSG_INFO("================ CD INFO === start =========\n"); + MSG_INFO(" artist=[%s]\n" + " album=[%s]\n" + " genre=[%s]\n" + " nb_tracks=%d\n" + " length= %2d:%02d.%02d\n" + , artist.c_str() + , album.c_str() + , genre.c_str() + , nb_tracks + , min, sec, msec); + current_track = first; + while( current_track!=NULL ) { + MSG_V(" #%2d %2d:%02d.%02d @ %7ld\t[%s] \n", current_track->track_nb, current_track->min, current_track->sec, current_track->msec, current_track->frame_begin, current_track->name.c_str()); + current_track = current_track->next; + } + MSG_INFO("================ CD INFO === end =========\n"); } -char* __FASTCALL__ xmcd_parse_dtitle(cd_info_t *cd_info, char *line) { - char *ptr, *album; - ptr = strstr(line, "DTITLE="); - if( ptr!=NULL ) { - ptr += 7; - album = strstr(ptr, "/"); - if( album==NULL ) return NULL; - cd_info->album = (char*)mp_malloc(strlen(album+2)+1); - if( cd_info->album==NULL ) { - return NULL; - } - strcpy( cd_info->album, album+2 ); - album--; - album[0] = '\0'; - cd_info->artist = (char*)mp_malloc(strlen(ptr)+1); - if( cd_info->artist==NULL ) { - return NULL; - } - strcpy( cd_info->artist, ptr ); - } - return ptr; +static char* __FASTCALL__ xmcd_parse_dtitle(CD_Info& cd_info,char *line) { + char *ptr, *album; + ptr = strstr(line, "DTITLE="); + if( ptr!=NULL ) { + ptr += 7; + album = strstr(ptr, "/"); + if( album==NULL ) return NULL; + cd_info.album=album+2; + album--; + album[0] = '\0'; + cd_info.artist=ptr; + } + return ptr; } -char* __FASTCALL__ xmcd_parse_dgenre(cd_info_t *cd_info, char *line) { - char *ptr; - ptr = strstr(line, "DGENRE="); - if( ptr!=NULL ) { - ptr += 7; - cd_info->genre = (char*)mp_malloc(strlen(ptr)+1); - if( cd_info->genre==NULL ) { - return NULL; - } - strcpy( cd_info->genre, ptr ); - } - return ptr; +char* __FASTCALL__ xmcd_parse_dgenre(CD_Info& cd_info,char *line) { + char *ptr; + ptr = strstr(line, "DGENRE="); + if( ptr!=NULL ) { + ptr += 7; + cd_info.genre=ptr; + } + return ptr; } -char* __FASTCALL__ xmcd_parse_ttitle(cd_info_t *cd_info, char *line) { - unsigned int track_nb; - unsigned long sec, off; - char *ptr; - ptr = strstr(line, "TTITLE"); - if( ptr!=NULL ) { - ptr += 6; - // Here we point to the track number - track_nb = atoi(ptr); - ptr = strstr(ptr, "="); - if( ptr==NULL ) return NULL; - ptr++; +static char* __FASTCALL__ xmcd_parse_ttitle(CD_Info& cd_info,char *line) { + unsigned int track_nb; + unsigned long sec, off; + char *ptr; + ptr = strstr(line, "TTITLE"); + if( ptr!=NULL ) { + ptr += 6; + // Here we point to the track number + track_nb = atoi(ptr); + ptr = strstr(ptr, "="); + if( ptr==NULL ) return NULL; + ptr++; - sec = cdtoc[track_nb].frame; - off = cdtoc[track_nb+1].frame-sec+1; + sec = cdtoc[track_nb].frame; + off = cdtoc[track_nb+1].frame-sec+1; - cd_info_add_track( cd_info, ptr, track_nb+1, (unsigned int)(off/(60*75)), (unsigned int)((off/75)%60), (unsigned int)(off%75), sec, off ); - } - return ptr; + cd_info.add_track( ptr, track_nb+1, (unsigned int)(off/(60*75)), (unsigned int)((off/75)%60), (unsigned int)(off%75), sec, off ); + } + return ptr; } -cd_info_t* __FASTCALL__ cddb_parse_xmcd(char *xmcd_file) { - cd_info_t *cd_info = NULL; - int length, pos = 0; - char *ptr, *ptr2; - unsigned int audiolen; - if( xmcd_file==NULL ) return NULL; +MPXP_Rc CD_Info::parse_xmcd(const char *_xmcd_file) { + int length, pos = 0; + char *ptr; + char *ptr2; + unsigned int audiolen; + if( _xmcd_file==NULL ) return MPXP_False; + char* xmcd_file = mp_strdup(_xmcd_file); - cd_info = cd_info_new(); - if( cd_info==NULL ) { - return NULL; + length = strlen(xmcd_file); + ptr = xmcd_file; + while( ptr!=NULL && pos<length ) { + // Read a line + ptr2 = ptr; + while( ptr2[0]!='\0' && ptr2[0]!='\r' && ptr2[0]!='\n' ) ptr2++; + if( ptr2[0]=='\0' ) break; + ptr2[0] = '\0'; + // Ignore comments + if( ptr[0]!='#' ) { + // Search for the album title + if( xmcd_parse_dtitle(*this, ptr) ); + // Search for the genre + else if( xmcd_parse_dgenre(*this, ptr) ); + // Search for a track title + else if( xmcd_parse_ttitle(*this, ptr) ){} } + if( ptr2[1]=='\n' ) ptr2++; + pos = (ptr2+1)-ptr; + ptr = ptr2+1; + } - length = strlen(xmcd_file); - ptr = xmcd_file; - while( ptr!=NULL && pos<length ) { - // Read a line - ptr2 = ptr; - while( ptr2[0]!='\0' && ptr2[0]!='\r' && ptr2[0]!='\n' ) ptr2++; - if( ptr2[0]=='\0' ) { - break; - } - ptr2[0] = '\0'; - // Ignore comments - if( ptr[0]!='#' ) { - // Search for the album title - if( xmcd_parse_dtitle(cd_info, ptr) ); - // Search for the genre - else if( xmcd_parse_dgenre(cd_info, ptr) ); - // Search for a track title - else if( xmcd_parse_ttitle(cd_info, ptr) ){} - } - if( ptr2[1]=='\n' ) ptr2++; - pos = (ptr2+1)-ptr; - ptr = ptr2+1; - } + audiolen = cdtoc[nb_tracks].frame-cdtoc[0].frame; + min = (unsigned int)(audiolen/(60*75)); + sec = (unsigned int)((audiolen/75)%60); + msec = (unsigned int)(audiolen%75); + delete xmcd_file; - audiolen = cdtoc[cd_info->nb_tracks].frame-cdtoc[0].frame; - cd_info->min = (unsigned int)(audiolen/(60*75)); - cd_info->sec = (unsigned int)((audiolen/75)%60); - cd_info->msec = (unsigned int)(audiolen%75); - - return cd_info; + return MPXP_Ok; } -cdda_priv* __FASTCALL__ open_cddb(libinput_t *libinput,const char *dev, const char *track) { - cd_info_t *cd_info = NULL; +MPXP_Rc CDD_Interface::open_cddb(libinput_t *libinput,const char *dev, const char *track) { char *xmcd_file = NULL; MPXP_Rc ret; ret = cddb_resolve(libinput,&xmcd_file); if( ret==MPXP_False ) { - cd_info = cddb_parse_xmcd(xmcd_file); + CD_Info& cd_info = *new(zeromem) CD_Info; + if(cd_info.parse_xmcd(xmcd_file)==MPXP_Ok) + cd_info.print(); delete xmcd_file; - cd_info_debug( cd_info ); - return NULL; + delete &cd_info; + return ret; } return open_cdda(dev, track); } Modified: mplayerxp/libmpstream/s_cdd.cpp =================================================================== --- mplayerxp/libmpstream/s_cdd.cpp 2012-12-10 11:27:53 UTC (rev 530) +++ mplayerxp/libmpstream/s_cdd.cpp 2012-12-10 13:18:14 UTC (rev 531) @@ -35,18 +35,20 @@ virtual off_t sector_size() const; virtual std::string mime_type() const; protected: - cdda_priv* priv; + CDD_Interface* priv; private: track_t track_idx; }; Cdda_Stream_Interface::Cdda_Stream_Interface(libinput_t* libinput) :Stream_Interface(libinput), + priv(new(zeromem) CDD_Interface), track_idx(255) {} -Cdda_Stream_Interface::~Cdda_Stream_Interface() {} +Cdda_Stream_Interface::~Cdda_Stream_Interface() { delete priv; } MPXP_Rc Cdda_Stream_Interface::open(const char *filename,unsigned flags) { + MPXP_Rc rc; const char *param; char *device; UNUSED(flags); @@ -55,38 +57,38 @@ return MPXP_False; } param=mrl_parse_line(filename,NULL,NULL,&device,NULL); - priv = open_cdda(device ? device : DEFAULT_CDROM_DEVICE,param); + rc = priv->open_cdda(device ? device : DEFAULT_CDROM_DEVICE,param); if(device) delete device; - return priv?MPXP_Ok:MPXP_False; + return rc; } Stream::type_e Cdda_Stream_Interface::type() const { return Stream::Type_RawAudio|Stream::Type_Seekable; } -off_t Cdda_Stream_Interface::start_pos() const { return cdda_start(priv); } -off_t Cdda_Stream_Interface::size() const { return cdda_size(priv); } +off_t Cdda_Stream_Interface::start_pos() const { return priv->start(); } +off_t Cdda_Stream_Interface::size() const { return priv->size(); } off_t Cdda_Stream_Interface::sector_size() const { return CD_FRAMESIZE_RAW; } std::string Cdda_Stream_Interface::mime_type() const { return "audio/PCMA"; } int Cdda_Stream_Interface::read(stream_packet_t*sp) { sp->type=0; - sp->len=read_cdda(priv,sp->buf,&track_idx); + sp->len=priv->read(sp->buf,&track_idx); return sp->len; } off_t Cdda_Stream_Interface::seek(off_t pos) { - seek_cdda(priv,pos,&track_idx); + priv->seek(pos,&track_idx); return pos; } off_t Cdda_Stream_Interface::tell() const { - return tell_cdda(priv); + return priv->tell(); } void Cdda_Stream_Interface::close() { - close_cdda(priv); + priv->close(); } MPXP_Rc Cdda_Stream_Interface::ctrl(unsigned cmd,any_t*args) @@ -99,7 +101,7 @@ } break; case SCTRL_AUD_GET_CHANNELS: - *(int *)args=cdio_cddap_track_channels(priv->cd, track_idx); + *(int *)args=priv->channels(track_idx); if(*(int *)args<=0) *(int *)args=2; MSG_V("cdda channels: %u\n",*(int *)args); return MPXP_Ok; @@ -152,9 +154,9 @@ return MPXP_False; } param=mrl_parse_line(filename,NULL,NULL,&device,NULL); - priv = open_cddb(libinput,device ? device : DEFAULT_CDROM_DEVICE,param); + retval = priv->open_cddb(libinput,device ? device : DEFAULT_CDROM_DEVICE,param); if(device) delete device; - return priv?MPXP_Ok:MPXP_False; + return retval; #else return MPXP_False; #endif Modified: mplayerxp/libvo/vo_sdl.cpp =================================================================== --- mplayerxp/libvo/vo_sdl.cpp 2012-12-10 11:27:53 UTC (rev 530) +++ mplayerxp/libvo/vo_sdl.cpp 2012-12-10 13:18:14 UTC (rev 531) @@ -200,8 +200,8 @@ const char* parse_sub_device(const char *sd) const; - char sdl_subdevice[100]; - char driver[8]; /* output driver used by sdl */ + std::string sdl_subdevice; + std::string driver; /* output driver used by sdl */ unsigned flags; LocalPtr<Aspect>aspect; SDL_Surface* surface; /* SDL display surface */ @@ -273,8 +273,7 @@ const char* vidix_name=NULL; num_buffs = 1; surface = NULL; - sdl_subdevice[0]='\0'; - if(arg) strcpy(sdl_subdevice,arg); + if(arg) sdl_subdevice=arg; if(arg) vidix_name = parse_sub_device(arg); #ifdef CONFIG_VIDIX if(vidix_name) { @@ -324,9 +323,10 @@ void SDL_VO_Interface::sdl_open( ) { + char drv[8]; const SDL_VideoInfo *vidInfo = NULL; MSG_DBG3("SDL: Opening Plugin\n"); - if(sdl_subdevice[0]) setenv("SDL_VIDEODRIVER", sdl_subdevice, 1); + if(!sdl_subdevice.empty()) setenv("SDL_VIDEODRIVER", sdl_subdevice.c_str(), 1); /* does the user want SDL to try and force Xv */ if(sdl_forcexv) setenv("SDL_VIDEO_X11_NODIRECTCOLOR", "1", 1); @@ -349,10 +349,11 @@ } #ifdef CONFIG_VIDIX - if(memcmp(sdl_subdevice,"vidix",5) != 0) + if(memcmp(sdl_subdevice.c_str(),"vidix",5) != 0) #endif - SDL_VideoDriverName(driver, 8); - MSG_OK("SDL: Using driver: %s\n", driver); + SDL_VideoDriverName(drv, 8); + driver=drv; + MSG_OK("SDL: Using driver: %s\n", driver.c_str()); /* other default values */ #ifdef SDL_NOHWSURFACE MSG_V("SDL: using software-surface\n"); @@ -682,11 +683,10 @@ retval = set_fullmode(fullmode); if(retval!=MPXP_Ok) return retval; } else { - if((strcmp(driver, "x11") == 0) - ||(strcmp(driver, "windib") == 0) - ||(strcmp(driver, "directx") == 0) - ||((strcmp(driver, "aalib") == 0) - && X)) { + if(driver=="x11" + ||driver=="windib" + ||driver=="directx" + ||(driver=="aalib" && X)) { MSG_V("SDL: setting windowed mode\n"); retval = set_video_mode(dstwidth, dstheight, bpp, sdlflags); if(retval!=MPXP_Ok) return retval; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |