decoder-snd.c
branchtrunk
changeset 25 887faebaba0a
parent 16 9d034fc2c5ec
child 29 640ce9201139
equal deleted inserted replaced
24:0598c933ccae 25:887faebaba0a
     1 /*
     1 /*
     2  * MP3/MPlayer plugin to VDR (C++)
     2  * MP3/MPlayer plugin to VDR (C++)
     3  *
     3  *
     4  * (C) 2001-2007 Stefan Huelswitt <s.huelswitt@gmx.de>
     4  * (C) 2001-2009 Stefan Huelswitt <s.huelswitt@gmx.de>
     5  *
     5  *
     6  * This code is free software; you can redistribute it and/or
     6  * This code is free software; you can redistribute it and/or
     7  * modify it under the terms of the GNU General Public License
     7  * modify it under the terms of the GNU General Public License
     8  * as published by the Free Software Foundation; either version 2
     8  * as published by the Free Software Foundation; either version 2
     9  * of the License, or (at your option) any later version.
     9  * of the License, or (at your option) any later version.
    56 #define CDFS_MARK_TR   "%*[^[][ %d - %d"
    56 #define CDFS_MARK_TR   "%*[^[][ %d - %d"
    57 #define CDFS_TRACK     "track-"
    57 #define CDFS_TRACK     "track-"
    58 
    58 
    59 #define CDDB_PROTO 5                   // used protocol level
    59 #define CDDB_PROTO 5                   // used protocol level
    60 #define CDDB_TOUT  30*1000             // connection timeout (ms)
    60 #define CDDB_TOUT  30*1000             // connection timeout (ms)
       
    61 #define CDDB_CHARSET "ISO8859-1"       // data charset
    61 
    62 
    62 const char *cddbpath="/var/lib/cddb";  // default local cddb path
    63 const char *cddbpath="/var/lib/cddb";  // default local cddb path
    63 
    64 
    64 #define CDDB_DEBUG  // debug cddb queries
    65 #define CDDB_DEBUG  // debug cddb queries
    65 //#define DEBUG_CDFS  // debug cdfs parsing
    66 //#define DEBUG_CDFS  // debug cdfs parsing
   408   bool isSampler;
   409   bool isSampler;
   409   char *DTitle, *ExtD;
   410   char *DTitle, *ExtD;
   410   //
   411   //
   411   cCDDBSong *GetTrack(const char *name, unsigned int pos);
   412   cCDDBSong *GetTrack(const char *name, unsigned int pos);
   412   cCDDBSong *FindTrack(int tr);
   413   cCDDBSong *FindTrack(int tr);
   413   void Strcat(char * &store, char *value);
   414   void Strcat(char * &store, const char *value);
   414   bool Split(const char *source, char div, char * &first, char * &second, bool only3=false);
   415   bool Split(const char *source, char div, char * &first, char * &second, bool only3=false);
   415   void Put(const char *from, char * &to);
   416   void Put(const char *from, char * &to);
   416   void Clean(void);
   417   void Clean(void);
   417 public:
   418 public:
   418   cCDDBDisc(void);
   419   cCDDBDisc(void);
   470 
   471 
   471   d(printf("cddb: loading discid %08x from %s\n",id->discid,filename))
   472   d(printf("cddb: loading discid %08x from %s\n",id->discid,filename))
   472   DiscID=id->discid;
   473   DiscID=id->discid;
   473   FILE *f=fopen(filename,"r");
   474   FILE *f=fopen(filename,"r");
   474   if(f) {
   475   if(f) {
       
   476     cCharSetConv csc(CDDB_CHARSET);
   475     char buff[1024];
   477     char buff[1024];
   476     while(fgets(buff,sizeof(buff),f)) {
   478     while(fgets(buff,sizeof(buff),f)) {
   477       int i=strlen(buff);
   479       int i=strlen(buff);
   478       while(i && (buff[i-1]=='\n' || buff[i-1]=='\r')) buff[--i]=0;
   480       while(i && (buff[i-1]=='\n' || buff[i-1]=='\r')) buff[--i]=0;
   479 
   481 
   482       else {
   484       else {
   483         p=strchr(buff,'=');
   485         p=strchr(buff,'=');
   484         if(p) {
   486         if(p) {
   485            *p=0;
   487            *p=0;
   486            char *name =compactspace(buff);
   488            char *name =compactspace(buff);
   487            char *value=compactspace(p+1);
   489            const char *value=csc.Convert(compactspace(p+1));
   488            if(*name && *value) {
   490            if(*name && *value) {
   489              if(!strcasecmp(name,"DTITLE")) Strcat(DTitle,value);
   491              if(!strcasecmp(name,"DTITLE")) Strcat(DTitle,value);
   490              else if(!strcasecmp(name,"EXTD")) Strcat(ExtD,value);
   492              else if(!strcasecmp(name,"EXTD")) Strcat(ExtD,value);
   491              else if(!strcasecmp(name,"DYEAR")) Year=atoi(value);
   493              else if(!strcasecmp(name,"DYEAR")) Year=atoi(value);
   492              else if(!strncasecmp(name,"TTITLE",6)) {
   494              else if(!strncasecmp(name,"TTITLE",6)) {
   586     return true;
   588     return true;
   587     }
   589     }
   588   return false;
   590   return false;
   589 }
   591 }
   590 
   592 
   591 void cCDDBDisc::Strcat(char * &store, char *value)
   593 void cCDDBDisc::Strcat(char * &store, const char *value)
   592 {
   594 {
   593   if(store) {
   595   if(store) {
   594     char *n=MALLOC(char,strlen(store)+strlen(value)+1);
   596     char *n=MALLOC(char,strlen(store)+strlen(value)+1);
   595     if(n) {
   597     if(n) {
   596       strcpy(n,store);
   598       strcpy(n,store);
   826 
   828 
   827   // check the infocache
   829   // check the infocache
   828   cCacheData *dat=InfoCache.Search(file);
   830   cCacheData *dat=InfoCache.Search(file);
   829   if(dat) {
   831   if(dat) {
   830     Set(dat); dat->Unlock();
   832     Set(dat); dat->Unlock();
       
   833     ConvertToSys();
   831     if(!DecoderID) {
   834     if(!DecoderID) {
   832       DecoderID=DEC_SND;
   835       DecoderID=DEC_SND;
   833       InfoCache.Cache(this,file);
   836       InfoCache.Cache(this,file);
   834       }
   837       }
   835     return Abort(true);
   838     return Abort(true);
   848   Bitrate=Total ? file->Filesize*8/Total : 0; //XXX SampleFreq*Channels*file->sfi.pcmbitwidth;
   851   Bitrate=Total ? file->Filesize*8/Total : 0; //XXX SampleFreq*Channels*file->sfi.pcmbitwidth;
   849   DecoderID=DEC_SND;
   852   DecoderID=DEC_SND;
   850 
   853 
   851   InfoDone();
   854   InfoDone();
   852   InfoCache.Cache(this,file);
   855   InfoCache.Cache(this,file);
   853   return Abort(true);  
   856   ConvertToSys();
       
   857   return Abort(true);
   854 }
   858 }
   855 
   859 
   856 bool cSndInfo::CDDBLookup(const char *filename)
   860 bool cSndInfo::CDDBLookup(const char *filename)
   857 {
   861 {
   858   if(id->Get()) {
   862   if(id->Get()) {