~ubuntu-branches/ubuntu/maverick/vdr-plugin-mp3/maverick

« back to all changes in this revision

Viewing changes to decoder-snd.c

  • Committer: Bazaar Package Importer
  • Author(s): Tobias Grimm
  • Date: 2010-03-28 15:09:21 UTC
  • mfrom: (2.1.6 sid)
  • Revision ID: james.westby@ubuntu.com-20100328150921-3kti802cqh0pe1hl
Tags: 0.10.2-3
* Build-depend on vdr-dev >= 1.6.0-16
* Minor debian/copyright update

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * MP3/MPlayer plugin to VDR (C++)
3
3
 *
4
 
 * (C) 2001-2005 Stefan Huelswitt <s.huelswitt@gmx.de>
 
4
 * (C) 2001-2009 Stefan Huelswitt <s.huelswitt@gmx.de>
5
5
 *
6
6
 * This code is free software; you can redistribute it and/or
7
7
 * modify it under the terms of the GNU General Public License
58
58
 
59
59
#define CDDB_PROTO 5                   // used protocol level
60
60
#define CDDB_TOUT  30*1000             // connection timeout (ms)
 
61
#define CDDB_CHARSET "ISO8859-1"       // data charset
61
62
 
62
63
const char *cddbpath="/var/lib/cddb";  // default local cddb path
63
64
 
410
411
  //
411
412
  cCDDBSong *GetTrack(const char *name, unsigned int pos);
412
413
  cCDDBSong *FindTrack(int tr);
413
 
  void Strcat(char * &store, char *value);
 
414
  void Strcat(char * &store, const char *value);
414
415
  bool Split(const char *source, char div, char * &first, char * &second, bool only3=false);
415
416
  void Put(const char *from, char * &to);
416
417
  void Clean(void);
472
473
  DiscID=id->discid;
473
474
  FILE *f=fopen(filename,"r");
474
475
  if(f) {
 
476
    cCharSetConv csc(CDDB_CHARSET);
475
477
    char buff[1024];
476
478
    while(fgets(buff,sizeof(buff),f)) {
477
479
      int i=strlen(buff);
484
486
        if(p) {
485
487
           *p=0;
486
488
           char *name =compactspace(buff);
487
 
           char *value=compactspace(p+1);
 
489
           const char *value=csc.Convert(compactspace(p+1));
488
490
           if(*name && *value) {
489
491
             if(!strcasecmp(name,"DTITLE")) Strcat(DTitle,value);
490
492
             else if(!strcasecmp(name,"EXTD")) Strcat(ExtD,value);
577
579
bool cCDDBDisc::Split(const char *source, char div, char * &first, char * &second, bool only3)
578
580
{
579
581
  int pos=-1, n=0;
580
 
  char *p, l[4]={ ' ',div,' ',0 };
 
582
  const char *p;
 
583
  char l[4]={ ' ',div,' ',0 };
581
584
  if ((p=strstr(source,l))) { pos=p-source; n=3; }
582
585
  else if(!only3 && (p=strchr(source,div)))  { pos=p-source; n=1; }
583
586
  if(pos>=0) {
588
591
  return false;
589
592
}
590
593
 
591
 
void cCDDBDisc::Strcat(char * &store, char *value)
 
594
void cCDDBDisc::Strcat(char * &store, const char *value)
592
595
{
593
596
  if(store) {
594
597
    char *n=MALLOC(char,strlen(store)+strlen(value)+1);
643
646
  bool RemoteGet(cDiscID *id);
644
647
  bool GetLine(char *buff, int size, bool log=true);
645
648
  int GetCddbResponse(void);
646
 
  int DoCddbCmd(char *format, ...);
 
649
  int DoCddbCmd(const char *format, ...);
647
650
public:
648
651
  cCDDB(void);
649
652
  virtual ~cCDDB();
706
709
  if(net->Connect(MP3Setup.CddbHost,MP3Setup.CddbPort)) {
707
710
    int code=GetCddbResponse();
708
711
    if(code/100==2) {
709
 
      char *host=getenv("HOSTNAME"); if(!host) host="unknown";
710
 
      char *user=getenv("USER"); if(!user) user="nobody";
711
 
      code=DoCddbCmd("cddb hello %s %s %s %s\n",user,host,PLUGIN_NAME,PLUGIN_VERSION);
 
712
      const char *host=getenv("HOSTNAME"); if(!host) host="unknown";
 
713
      const char *user=getenv("USER"); if(!user) user="nobody";
 
714
      code=DoCddbCmd("cddb hello %s %s %s %s\n",user,host,PLUGIN_NAME,PluginVersion);
712
715
      if(code/100==2) {
713
716
        code=DoCddbCmd("proto %d\n",CDDB_PROTO);
714
717
        if(code>0) {
730
733
              char *s=index(cat,' '); if(s) *s=0;
731
734
              code=DoCddbCmd("cddb read %s %08x\n",cat,id->discid);
732
735
              if(code==210) {
733
 
                char *name=0;
734
 
                asprintf(&name,"%s/%s/%08x",cddbpath,cat,id->discid);
 
736
                char *name=aprintf("%s/%s/%08x",cddbpath,cat,id->discid);
735
737
                if(MakeDirs(name,false)) {
736
738
                  FILE *out=fopen(name,"w");
737
739
                  if(out) {
783
785
  return -1;
784
786
}
785
787
 
786
 
int cCDDB::DoCddbCmd(char *format, ...)
 
788
int cCDDB::DoCddbCmd(const char *format, ...)
787
789
{
788
790
  va_list ap;
789
791
  va_start(ap,format);
790
792
  char *buff=0;
791
 
  vasprintf(&buff,format,ap);
 
793
  if(vasprintf(&buff,format,ap)<0);
792
794
  va_end(ap);
793
795
#ifdef CDDB_DEBUG
794
796
  printf("cddb: -> %s",buff);
828
830
  cCacheData *dat=InfoCache.Search(file);
829
831
  if(dat) {
830
832
    Set(dat); dat->Unlock();
 
833
    ConvertToSys();
831
834
    if(!DecoderID) {
832
835
      DecoderID=DEC_SND;
833
836
      InfoCache.Cache(this,file);
845
848
  Channels=file->sfi.channels;
846
849
  ChMode=Channels>1 ? 3:0;
847
850
  Total=Frames/SampleFreq;
848
 
  Bitrate=file->Filesize*8/Total; //XXX SampleFreq*Channels*file->sfi.pcmbitwidth;
 
851
  Bitrate=Total ? file->Filesize*8/Total : 0; //XXX SampleFreq*Channels*file->sfi.pcmbitwidth;
849
852
  DecoderID=DEC_SND;
850
853
 
851
854
  InfoDone();
852
855
  InfoCache.Cache(this,file);
853
 
  return Abort(true);  
 
856
  ConvertToSys();
 
857
  return Abort(true);
854
858
}
855
859
 
856
860
bool cSndInfo::CDDBLookup(const char *filename)
857
861
{
858
862
  if(id->Get()) {
859
863
    int tr;
860
 
    char *s=strstr(filename,CDFS_TRACK);
 
864
    const char *s=strstr(filename,CDFS_TRACK);
861
865
    if(s && sscanf(s+strlen(CDFS_TRACK),"%d",&tr)==1) {
862
866
      d(printf("snd: looking up disc id %08x track %d\n",id->discid,tr))
863
867
      return cddb.Lookup(id,tr-1,this);