2 * MP3/MPlayer plugin to VDR (C++)
4 * (C) 2001-2007 Stefan Huelswitt <s.huelswitt@gmx.de>
6 * This code is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This code is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
29 #include <vdr/menuitems.h>
30 #include <vdr/status.h>
31 #include <vdr/plugin.h>
32 #if APIVERSNUM >= 10307
33 #include <vdr/interface.h>
34 #include <vdr/skins.h>
38 #include "setup-mp3.h"
41 #include "player-mp3.h"
43 #include "menu-async.h"
53 const char *sourcesSub=0;
54 cFileSources MP3Sources;
56 static const char *plugin_name=0;
58 // --- cMenuSetupMP3 --------------------------------------------------------
60 class cMenuSetupMP3 : public cMenuSetupPage {
64 const char *cddb[3], *disp[2], *scan[3], *bgr[3];
65 const char *aout[AUDIOOUTMODES];
66 int amode, amodes[AUDIOOUTMODES];
68 virtual void Store(void);
73 cMenuSetupMP3::cMenuSetupMP3(void)
75 static const char allowed[] = { "abcdefghijklmnopqrstuvwxyz0123456789-_" };
77 aout[numModes]=trVDR("DVB"); amodes[numModes]=AUDIOOUTMODE_DVB; numModes++;
79 aout[numModes]=tr("OSS"); amodes[numModes]=AUDIOOUTMODE_OSS; numModes++;
83 for(int i=0; i<numModes; i++)
84 if(amodes[i]==data.AudioOutMode) { amode=i; break; }
86 SetSection(tr("MP3"));
87 Add(new cMenuEditStraItem(tr("Setup.MP3$Audio output mode"), &amode,numModes,aout));
88 Add(new cMenuEditBoolItem(tr("Setup.MP3$Audio mode"), &data.AudioMode, tr("Round"), tr("Dither")));
89 Add(new cMenuEditBoolItem(tr("Setup.MP3$Use 48kHz mode only"), &data.Only48kHz));
90 #if APIVERSNUM >= 10307
91 disp[0]=tr("classic");
92 disp[1]=tr("via skin");
93 Add(new cMenuEditStraItem(tr("Setup.MP3$Replay display"), &data.ReplayDisplay, 2, disp));
95 Add(new cMenuEditIntItem( tr("Setup.MP3$Display mode"), &data.DisplayMode, 1, 3));
99 Add(new cMenuEditStraItem(tr("Setup.MP3$Background mode"), &data.BackgrMode, 3, bgr));
100 Add(new cMenuEditBoolItem(tr("Setup.MP3$Initial loop mode"), &data.InitLoopMode));
101 Add(new cMenuEditBoolItem(tr("Setup.MP3$Initial shuffle mode"), &data.InitShuffleMode));
102 Add(new cMenuEditBoolItem(tr("Setup.MP3$Abort player at end of list"),&data.AbortAtEOL));
103 scan[0]=tr("disabled");
104 scan[1]=tr("ID3 only");
105 scan[2]=tr("ID3 & Level");
106 Add(new cMenuEditStraItem(tr("Setup.MP3$Background scan"), &data.BgrScan, 3, scan));
107 Add(new cMenuEditBoolItem(tr("Setup.MP3$Editor display mode"), &data.EditorMode, tr("Filenames"), tr("ID3 names")));
108 Add(new cMenuEditBoolItem(tr("Setup.MP3$Mainmenu mode"), &data.MenuMode, tr("Playlists"), tr("Browser")));
109 Add(new cMenuEditBoolItem(tr("Setup.MP3$Keep selection menu"), &data.KeepSelect));
110 Add(new cMenuEditBoolItem(tr("Setup.MP3$Title/Artist order"), &data.TitleArtistOrder, tr("Normal"), tr("Reversed")));
111 Add(new cMenuEditBoolItem(tr("Hide mainmenu entry"), &data.HideMainMenu));
112 Add(new cMenuEditIntItem( tr("Setup.MP3$Normalizer level"), &data.TargetLevel, 0, MAX_TARGET_LEVEL));
113 Add(new cMenuEditIntItem( tr("Setup.MP3$Limiter level"), &data.LimiterLevel, MIN_LIMITER_LEVEL, 100));
114 Add(new cMenuEditBoolItem(tr("Setup.MP3$Use HTTP proxy"), &data.UseProxy));
115 Add(new cMenuEditStrItem( tr("Setup.MP3$HTTP proxy host"), data.ProxyHost,MAX_HOSTNAME,allowed));
116 Add(new cMenuEditIntItem( tr("Setup.MP3$HTTP proxy port"), &data.ProxyPort,1,65535));
117 cddb[0]=tr("disabled");
118 cddb[1]=tr("local only");
119 cddb[2]=tr("local&remote");
120 Add(new cMenuEditStraItem(tr("Setup.MP3$CDDB for CD-Audio"), &data.UseCddb,3,cddb));
121 Add(new cMenuEditStrItem( tr("Setup.MP3$CDDB server"), data.CddbHost,MAX_HOSTNAME,allowed));
122 Add(new cMenuEditIntItem( tr("Setup.MP3$CDDB port"), &data.CddbPort,1,65535));
125 void cMenuSetupMP3::Store(void)
127 data.AudioOutMode=amodes[amode];
130 SetupStore("InitLoopMode", MP3Setup.InitLoopMode );
131 SetupStore("InitShuffleMode", MP3Setup.InitShuffleMode);
132 SetupStore("AudioMode", MP3Setup.AudioMode );
133 SetupStore("AudioOutMode", MP3Setup.AudioOutMode );
134 SetupStore("BgrScan", MP3Setup.BgrScan );
135 SetupStore("EditorMode", MP3Setup.EditorMode );
136 SetupStore("DisplayMode", MP3Setup.DisplayMode );
137 SetupStore("BackgrMode", MP3Setup.BackgrMode );
138 SetupStore("MenuMode", MP3Setup.MenuMode );
139 SetupStore("TargetLevel", MP3Setup.TargetLevel );
140 SetupStore("LimiterLevel", MP3Setup.LimiterLevel );
141 SetupStore("Only48kHz", MP3Setup.Only48kHz );
142 SetupStore("UseProxy", MP3Setup.UseProxy );
143 SetupStore("ProxyHost", MP3Setup.ProxyHost );
144 SetupStore("ProxyPort", MP3Setup.ProxyPort );
145 SetupStore("UseCddb", MP3Setup.UseCddb );
146 SetupStore("CddbHost", MP3Setup.CddbHost );
147 SetupStore("CddbPort", MP3Setup.CddbPort );
148 SetupStore("AbortAtEOL", MP3Setup.AbortAtEOL );
149 #if APIVERSNUM >= 10307
150 SetupStore("ReplayDisplay", MP3Setup.ReplayDisplay );
152 SetupStore("HideMainMenu", MP3Setup.HideMainMenu );
153 SetupStore("KeepSelect", MP3Setup.KeepSelect );
154 SetupStore("TitleArtistOrder", MP3Setup.TitleArtistOrder);
157 // --- cAsyncStatus ------------------------------------------------------------
159 cAsyncStatus asyncStatus;
161 cAsyncStatus::cAsyncStatus(void)
167 cAsyncStatus::~cAsyncStatus()
172 void cAsyncStatus::Set(const char *Text)
176 text=Text ? strdup(Text) : 0;
181 const char *cAsyncStatus::Begin(void)
187 void cAsyncStatus::Finish(void)
193 // --- --------------------------------------------------------------------
195 static const char *TitleArtist(const char *title, const char *artist)
197 static char buf[256]; // clearly not multi-thread save!
199 if(artist && artist[0]) {
200 if(MP3Setup.TitleArtistOrder) fmt="%2$s - %1$s";
204 snprintf(buf,sizeof(buf),fmt,title,artist);
208 // --- cMP3Control --------------------------------------------------------
210 #if APIVERSNUM >= 10307
211 #define clrBackground clrGray50
212 #define eDvbColor int
216 #define MAXROWS MAXOSDHEIGHT
217 #define INLINE inline
220 class cMP3Control : public cControl {
222 #if APIVERSNUM >= 10307
225 cSkinDisplayReplay *disp;
227 bool statusInterfaceOpen;
229 int bw, bh, bwc, fw, fh;
232 bool visible, shown, bigwin, statusActive;
233 time_t timeoutShow, greentime, oktime;
234 int lastkeytime, number;
235 bool selecting, selecthide;
237 cMP3PlayInfo *lastMode;
238 time_t fliptime, listtime;
239 int hashlist[MAXROWS];
240 int flip, flipint, top, rows;
241 int lastIndex, lastTotal, lastTop;
244 bool jumpactive, jumphide, jumpsecs;
247 void ShowTimed(int Seconds=0);
248 void ShowProgress(bool open=false, bool bigWin=false);
249 void ShowStatus(bool force);
250 void HideStatus(void);
251 void DisplayInfo(const char *s=0);
252 void JumpDisplay(void);
253 void JumpProcess(eKeys Key);
256 INLINE void Write(int x, int y, int w, const char *text, eDvbColor fg=clrWhite, eDvbColor bg=clrBackground);
257 INLINE void Fill(int x, int y, int w, int h, eDvbColor fg);
258 inline void Flush(void);
261 virtual ~cMP3Control();
262 virtual eOSState ProcessKey(eKeys Key);
263 virtual void Show(void) { ShowTimed(); }
264 virtual void Hide(void);
265 bool Visible(void) { return visible; }
266 static bool SetPlayList(cPlayList *plist);
269 cMP3Control::cMP3Control(void)
270 :cControl(player=new cMP3Player)
272 visible=shown=bigwin=selecting=selecthide=jumpactive=jumphide=statusActive=false;
273 timeoutShow=greentime=oktime=0;
274 lastkeytime=number=0;
276 framesPerSecond=SecondsToFrames(1);
277 #if APIVERSNUM >= 10307
279 font=cFont::GetFont(fontOsd);
281 statusInterfaceOpen=false;
283 #if APIVERSNUM >= 10338
284 cStatus::MsgReplaying(this,"MP3",0,true);
286 cStatus::MsgReplaying(this,"MP3");
290 cMP3Control::~cMP3Control()
297 void cMP3Control::Stop(void)
299 #if APIVERSNUM >= 10338
300 cStatus::MsgReplaying(this,0,0,false);
302 cStatus::MsgReplaying(this,0);
304 delete player; player=0;
306 mgr->Flush(); //XXX remove later
309 bool cMP3Control::SetPlayList(cPlayList *plist)
312 cControl *control=cControl::Control();
313 // is there a running MP3 player?
314 if(control && typeid(*control)==typeid(cMP3Control)) {
315 // add songs to running playlist
322 cControl::Launch(new cMP3Control);
329 void cMP3Control::ShowTimed(int Seconds)
333 if(Seconds>0) timeoutShow=time(0)+Seconds;
337 void cMP3Control::Hide(void)
341 #if APIVERSNUM >= 10307
347 visible=bigwin=false;
348 #if APIVERSNUM >= 10500
349 SetNeedsFastResponse(false);
351 needsFastResponse=false;
356 void cMP3Control::ShowStatus(bool force)
358 if((asyncStatus.Changed() || (force && !statusActive)) && !jumpactive) {
359 const char *text=asyncStatus.Begin();
361 #if APIVERSNUM >= 10307
362 if(MP3Setup.ReplayDisplay || !osd) {
363 if(statusActive) Skins.Message(mtStatus,0);
364 Skins.Message(mtStatus,text);
367 if(!statusActive) osd->SaveRegion(0,bh-2*fh,bw-1,bh-fh-1);
368 osd->DrawText(0,bh-2*fh,text,clrBlack,clrCyan,font,bw,fh,taCenter);
372 if(!Interface->IsOpen()) {
373 Interface->Open(0,-1);
374 statusInterfaceOpen=true;
376 Interface->Status(text);
383 asyncStatus.Finish();
387 void cMP3Control::HideStatus(void)
390 #if APIVERSNUM >= 10307
391 if(MP3Setup.ReplayDisplay || !osd)
392 Skins.Message(mtStatus,0);
394 osd->RestoreRegion();
398 if(statusInterfaceOpen) {
400 statusInterfaceOpen=false;
403 Interface->Status(0);
411 #define CTAB 11 // some tabbing values for the progress display
414 void cMP3Control::Write(int x, int y, int w, const char *text, eDvbColor fg, eDvbColor bg)
416 #if APIVERSNUM >= 10307
418 //d(printf("write x=%d y=%d w=%d ->",x,y,w))
419 x*=fw; if(x<0) x+=bw;
420 y*=fh; if(y<0) y+=bh;
421 osd->DrawText(x,y,text,fg,bg,font,w*fw);
422 //d(printf(" x=%d y=%d w=%d\n",x,y,w*fw))
425 if(w>0) Fill(x,y,w,1,bg);
426 Interface->Write(x,y,text,fg,bg);
430 void cMP3Control::Fill(int x, int y, int w, int h, eDvbColor fg)
432 #if APIVERSNUM >= 10307
434 //d(printf("fill x=%d y=%d w=%d h=%d ->",x,y,w,h))
435 x*=fw; if(x<0) x+=bw;
436 y*=fh; if(y<0) y+=bh;
437 osd->DrawRectangle(x,y,x+w*fw-1,y+h*fh-1,fg);
438 //d(printf(" x=%d y=%d x2=%d y2=%d\n",x,y,x+h*fh-1,y+w*fw-1))
441 Interface->Fill(x,y,w,h,fg);
445 void cMP3Control::Flush(void)
447 #if APIVERSNUM >= 10307
448 if(MP3Setup.ReplayDisplay) Skins.Flush();
449 else if(osd) osd->Flush();
455 void cMP3Control::ShowProgress(bool open, bool bigWin)
459 if(player->GetIndex(index,total) && total>=0) {
460 if(!visible && open) {
462 #if APIVERSNUM >= 10307
463 if(MP3Setup.ReplayDisplay) {
464 disp=Skins.Current()->DisplayReplay(false);
470 fw=font->Width(' ')*2;
477 rows=(bh-bp-fh/3)/fh;
482 bt=Setup.OSDHeight-bh;
486 //d(printf("mp3: bw=%d bh=%d bt=%d bp=%d bwc=%d rows=%d fw=%d fh=%d\n",
487 // bw,bh,bt,bp,bwc,rows,fw,fh))
488 osd=cOsdProvider::NewOsd(Setup.OSDLeft,Setup.OSDTop+bt);
491 tArea Areas[] = { { 0,0,bw-1,bh-bp-1,2 }, { 0,bh-bp,bw-1,bh-1,4 } };
492 osd->SetAreas(Areas,sizeof(Areas)/sizeof(tArea));
495 tArea Areas[] = { { 0,0,bw-1,bh-1,4 } };
496 osd->SetAreas(Areas,sizeof(Areas)/sizeof(tArea));
498 osd->DrawRectangle(0,0,bw-1,bh-1,clrGray50);
502 fw=cOsd::CellWidth();
503 fh=cOsd::LineHeight();
504 bh=bigWin ? Setup.OSDheight : -2;
505 bw=bwc=Setup.OSDwidth;
506 rows=Setup.OSDheight-3;
507 Interface->Open(bw,bh);
513 #if APIVERSNUM >= 10500
514 SetNeedsFastResponse(true);
516 needsFastResponse=true;
518 fliptime=listtime=0; flipint=0; flip=-1; top=lastTop=-1; lastIndex=lastTotal=-1;
519 delete lastMode; lastMode=0;
522 cMP3PlayInfo *mode=new cMP3PlayInfo;
523 bool valid=mgr->Info(-1,mode);
524 bool changed=(!lastMode || mode->Hash!=lastMode->Hash);
526 if(changed) { d(printf("mp3-ctrl: mode change detected\n")) }
528 if(valid) { // send progress to status monitor
529 if(changed || mode->Loop!=lastMode->Loop || mode->Shuffle!=lastMode->Shuffle) {
530 snprintf(buf,sizeof(buf),"[%c%c] (%d/%d) %s",
531 mode->Loop?'L':'.',mode->Shuffle?'S':'.',mode->Num,mode->MaxNum,TitleArtist(mode->Title,mode->Artist));
532 #if APIVERSNUM >= 10338
533 cStatus::MsgReplaying(this,buf,mode->Filename[0]?mode->Filename:0,true);
535 cStatus::MsgReplaying(this,buf);
540 if(visible) { // refresh the OSD progress display
543 #if APIVERSNUM >= 10307
544 if(MP3Setup.ReplayDisplay) {
546 if(total>0) disp->SetProgress(index,total);
547 disp->SetCurrent(IndexToHMSF(index));
548 disp->SetTotal(IndexToHMSF(total));
551 if(GetReplayMode(Play,Forward,Speed))
552 disp->SetMode(Play, Forward, Speed);
558 if(!selecting && changed && !statusActive) {
559 snprintf(buf,sizeof(buf),"(%d/%d)",mode->Num,mode->MaxNum);
560 Write(0,-2,CTAB,buf);
564 if(!lastMode || mode->Loop!=lastMode->Loop) {
565 if(mode->Loop) Write(-4,-1,0,"L",clrBlack,clrYellow);
566 else Fill(-4,-1,2,1,clrBackground);
569 if(!lastMode || mode->Shuffle!=lastMode->Shuffle) {
570 if(mode->Shuffle) Write(-2,-1,0,"S",clrWhite,clrRed);
571 else Fill(-2,-1,2,1,clrBackground);
575 index/=framesPerSecond; total/=framesPerSecond;
576 if(index!=lastIndex || total!=lastTotal) {
578 #if APIVERSNUM >= 10307
579 cProgressBar ProgressBar(bw-(CTAB+CTAB2)*fw,fh,index,total);
580 osd->DrawBitmap(CTAB*fw,bh-fh,ProgressBar);
582 cProgressBar ProgressBar((bw-CTAB-CTAB2)*fw,fh,index,total);
583 Interface->SetBitmap(CTAB*fw,(abs(bh)-1)*fh,ProgressBar);
586 snprintf(buf,sizeof(buf),total?"%02d:%02d/%02d:%02d":"%02d:%02d",index/60,index%60,total/60,total%60);
590 #if APIVERSNUM >= 10307
596 if(MP3Setup.ReplayDisplay && (!lastMode || mode->Loop!=lastMode->Loop || mode->Shuffle!=lastMode->Shuffle))
598 if(!valid || changed) {
599 fliptime=time(0); flip=0;
602 else if(time(0)>fliptime+flipint) {
604 flip++; if(flip>=MP3Setup.DisplayMode) flip=0;
614 snprintf(buf,sizeof(buf),"%s",TitleArtist(mode->Title,mode->Artist));
619 snprintf(buf,sizeof(buf),mode->Year>0?"from: %s (%d)":"from: %s",mode->Album,mode->Year);
625 if(mode->MaxBitrate>0)
626 snprintf(buf,sizeof(buf),"%.1f kHz, %d-%d kbps, %s",mode->SampleFreq/1000.0,mode->Bitrate/1000,mode->MaxBitrate/1000,mode->SMode);
628 snprintf(buf,sizeof(buf),"%.1f kHz, %d kbps, %s",mode->SampleFreq/1000.0,mode->Bitrate/1000,mode->SMode);
633 #if APIVERSNUM >= 10307
634 if(MP3Setup.ReplayDisplay) {
636 snprintf(buf2,sizeof(buf2),"[%c%c] (%d/%d) %s",
637 mode->Loop?'L':'.',mode->Shuffle?'S':'.',mode->Num,mode->MaxNum,buf);
638 disp->SetTitle(buf2);
647 else { d(printf("mp3-ctrl: display info skip due to status active\n")) }
648 #if APIVERSNUM >= 10307
656 bool all=(top!=lastTop || changed);
657 if(all || time(0)>listtime+2) {
658 int num=(top>0 && mode->Num==lastMode->Num) ? top : mode->Num - rows/2;
659 if(num+rows>mode->MaxNum) num=mode->MaxNum-rows+1;
662 for(int i=0 ; i<rows && i<MAXROWS && num<=mode->MaxNum ; i++,num++) {
664 mgr->Info(num,&pi); if(!pi.Title[0]) break;
665 snprintf(buf,sizeof(buf),"%d.\t%s",num,TitleArtist(pi.Title,pi.Artist));
666 eDvbColor fg=clrWhite, bg=clrBackground;
667 int hash=MakeHash(buf);
668 if(num==mode->Num) { fg=clrBlack; bg=clrCyan; hash=(hash^77) + 23; }
669 if(all || hash!=hashlist[i]) {
670 char *s=rindex(buf,'\t');
673 Write(0,i,5,buf,fg,bg);
674 Write(5,i,bwc-5,s,fg,bg);
677 Write(0,i,bwc,buf,fg,bg);
682 listtime=time(0); lastTop=top;
689 lastIndex=index; lastTotal=total;
690 delete lastMode; lastMode=mode;
694 void cMP3Control::DisplayInfo(const char *s)
696 if(s) Write(CTAB,-2,bwc-CTAB,s);
697 else Fill(CTAB,-2,bwc-CTAB,1,clrBackground);
700 void cMP3Control::JumpDisplay(void)
703 const char *j=trVDR("Jump: "), u=jumpsecs?'s':'m';
704 if(!jumpmm) sprintf(buf,"%s- %c", j,u);
705 else sprintf(buf,"%s%d- %c",j,jumpmm,u);
706 #if APIVERSNUM >= 10307
707 if(MP3Setup.ReplayDisplay) {
713 #if APIVERSNUM >= 10307
718 void cMP3Control::JumpProcess(eKeys Key)
720 int n=Key-k0, d=jumpsecs?1:60;
723 if(jumpmm*10+n <= lastTotal/d) jumpmm=jumpmm*10+n;
738 player->SkipSeconds(jumpmm*d * ((Key==kLeft || Key==kFastRew) ? -1:1));
747 #if APIVERSNUM >= 10307
748 else if(MP3Setup.ReplayDisplay) disp->SetJump(0);
753 void cMP3Control::Jump(void)
755 jumpmm=0; jumphide=jumpsecs=false;
757 ShowTimed(); if(!visible) return;
761 jumpactive=true; fliptime=0; flip=-1;
764 eOSState cMP3Control::ProcessKey(eKeys Key)
766 if(!player->Active()) return osEnd;
768 if(visible && timeoutShow && time(0)>timeoutShow) { Hide(); timeoutShow=0; }
770 #if APIVERSNUM >= 10307
771 ShowStatus(Key==kNone && !Skins.IsOpen());
773 ShowStatus(Key==kNone && !Interface->IsOpen());
776 if(jumpactive && Key!=kNone) { JumpProcess(Key); return osContinue; }
781 #if APIVERSNUM >= 10347
785 mgr->Next(); player->Play();
789 #if APIVERSNUM >= 10347
793 if(!player->PrevCheck()) mgr->Prev();
799 if(top>0) { top-=rows; if(top<1) top=1; }
804 case kFastRew|k_Repeat:
805 if(!player->IsStream()) player->SkipSeconds(-JUMPSIZE);
808 case kRight|k_Repeat:
815 case kFastFwd|k_Repeat:
816 if(!player->IsStream()) player->SkipSeconds(JUMPSIZE);
819 if(!player->IsStream()) Jump();
823 if(time(0)>greentime) {
824 if(lastMode->Loop || (!lastMode->Loop && !lastMode->Shuffle)) mgr->ToggleLoop();
825 if(lastMode->Shuffle) mgr->ToggleShuffle();
828 if(!lastMode->Loop) mgr->ToggleLoop();
829 else if(!lastMode->Shuffle) mgr->ToggleShuffle();
830 else mgr->ToggleLoop();
832 greentime=time(0)+MULTI_TIMEOUT;
840 if(!player->IsStream()) player->Pause();
849 #if APIVERSNUM >= 10332
850 cRemote::CallPlugin(plugin_name);
857 number=number*10+Key-k0;
858 if(lastMode && number>0 && number<=lastMode->MaxNum) {
859 if(!visible) { ShowTimed(); selecthide=true; }
860 selecting=true; lastkeytime=time_ms();
862 #if APIVERSNUM >= 10307
863 if(MP3Setup.ReplayDisplay) {
864 snprintf(buf,sizeof(buf),"%s%d-/%d",trVDR("Jump: "),number,lastMode->MaxNum);
869 snprintf(buf,sizeof(buf),"(%d-/%d)",number,lastMode->MaxNum);
870 Write(0,-2,CTAB,buf);
871 #if APIVERSNUM >= 10307
877 number=0; lastkeytime=0;
880 if(selecting && time_ms()-lastkeytime>SELECT_TIMEOUT) {
881 if(number>0) { mgr->Goto(number); player->Play(); }
882 if(selecthide) timeoutShow=time(0)+SELECTHIDE_TIMEOUT;
883 if(lastMode) lastMode->Hash=-1;
884 number=0; selecting=selecthide=false;
885 #if APIVERSNUM >= 10307
886 if(MP3Setup.ReplayDisplay) disp->SetJump(0);
891 if(time(0)>oktime || MP3Setup.ReplayDisplay) {
892 visible ? Hide() : ShowTimed();
895 if(visible && !bigwin) { Hide(); ShowProgress(true,true); }
896 else { Hide(); ShowTimed(); }
898 oktime=time(0)+MULTI_TIMEOUT;
907 // --- cMenuID3Info ------------------------------------------------------------
909 class cMenuID3Info : public cOsdMenu {
911 cOsdItem *Item(const char *name, const char *text);
912 cOsdItem *Item(const char *name, const char *format, const float num);
913 void Build(cSongInfo *info, const char *name);
915 cMenuID3Info(cSong *song);
916 cMenuID3Info(cSongInfo *si, const char *name);
917 virtual eOSState ProcessKey(eKeys Key);
920 cMenuID3Info::cMenuID3Info(cSong *song)
921 :cOsdMenu(tr("ID3 information"),12)
923 Build(song->Info(),song->Name());
926 cMenuID3Info::cMenuID3Info(cSongInfo *si, const char *name)
927 :cOsdMenu(tr("ID3 information"),12)
932 void cMenuID3Info::Build(cSongInfo *si, const char *name)
935 Item(tr("Filename"),name);
936 if(si->HasInfo() && si->Total>0) {
938 asprintf(&buf,"%02d:%02d",si->Total/60,si->Total%60);
939 Item(tr("Length"),buf);
941 Item(tr("Title"),si->Title);
942 Item(tr("Artist"),si->Artist);
943 Item(tr("Album"),si->Album);
944 Item(tr("Year"),0,(float)si->Year);
945 Item(tr("Samplerate"),"%.1f kHz",si->SampleFreq/1000.0);
946 Item(tr("Bitrate"),"%.f kbit/s",si->Bitrate/1000.0);
947 Item(trVDR("Channels"),0,(float)si->Channels);
953 cOsdItem *cMenuID3Info::Item(const char *name, const char *format, const float num)
958 asprintf(&buf,format?format:"%.f",num);
962 else item=Item(name,"");
966 cOsdItem *cMenuID3Info::Item(const char *name, const char *text)
969 asprintf(&buf,"%s:\t%s",name,text?text:"");
970 cOsdItem *item = new cOsdItem(buf,osBack);
971 #if APIVERSNUM >= 10307
972 item->SetSelectable(false);
974 item->SetColor(clrWhite, clrBackground);
977 Add(item); return item;
980 eOSState cMenuID3Info::ProcessKey(eKeys Key)
982 eOSState state = cOsdMenu::ProcessKey(Key);
984 if(state==osUnknown) {
989 case kBlue: return osContinue;
990 case kMenu: return osEnd;
997 // --- cMenuInstantBrowse -------------------------------------------------------
999 class cMenuInstantBrowse : public cMenuBrowse {
1001 const char *selecttext, *alltext;
1002 virtual void SetButtons(void);
1003 virtual eOSState ID3Info(void);
1005 cMenuInstantBrowse(cFileSource *Source, const char *Selecttext, const char *Alltext);
1006 virtual eOSState ProcessKey(eKeys Key);
1009 cMenuInstantBrowse::cMenuInstantBrowse(cFileSource *Source, const char *Selecttext, const char *Alltext)
1010 :cMenuBrowse(Source,true,true,tr("Directory browser"),excl_br)
1012 selecttext=Selecttext; alltext=Alltext;
1016 void cMenuInstantBrowse::SetButtons(void)
1018 SetHelp(selecttext, currentdir?tr("Parent"):0, currentdir?0:alltext, tr("ID3 info"));
1022 eOSState cMenuInstantBrowse::ID3Info(void)
1024 cFileObj *item=CurrentItem();
1025 if(item && item->Type()==otFile) {
1026 cSong *song=new cSong(item);
1028 if(song && (si=song->Info())) {
1029 AddSubMenu(new cMenuID3Info(si,item->Path()));
1036 eOSState cMenuInstantBrowse::ProcessKey(eKeys Key)
1038 eOSState state=cOsdMenu::ProcessKey(Key);
1039 if(state==osUnknown) {
1041 case kYellow: lastselect=new cFileObj(source,0,0,otBase);
1046 if(state==osUnknown) state=cMenuBrowse::ProcessStdKey(Key,state);
1050 // --- cMenuPlayListItem -------------------------------------------------------
1052 class cMenuPlayListItem : public cOsdItem {
1057 cMenuPlayListItem(cSong *Song, bool showid3);
1058 cSong *Song(void) { return song; }
1059 virtual void Set(void);
1060 void Set(bool showid3);
1063 cMenuPlayListItem::cMenuPlayListItem(cSong *Song, bool showid3)
1069 void cMenuPlayListItem::Set(bool showid3)
1075 void cMenuPlayListItem::Set(void)
1078 cSongInfo *si=song->Info(false);
1079 if(showID3 && !si) si=song->Info();
1080 if(showID3 && si && si->Title)
1081 asprintf(&buffer, "%d.\t%s",song->Index()+1,TitleArtist(si->Title,si->Artist));
1083 asprintf(&buffer, "%d.\t<%s>",song->Index()+1,song->Name());
1084 SetText(buffer,false);
1087 // --- cMenuPlayList ------------------------------------------------------
1089 class cMenuPlayList : public cOsdMenu {
1091 cPlayList *playlist;
1092 bool browsing, showid3;
1094 void Refresh(bool all = false);
1096 virtual void Move(int From, int To);
1097 eOSState Remove(void);
1098 eOSState ShowID3(void);
1099 eOSState ID3Info(void);
1101 cMenuPlayList(cPlayList *Playlist);
1102 virtual eOSState ProcessKey(eKeys Key);
1105 cMenuPlayList::cMenuPlayList(cPlayList *Playlist)
1106 :cOsdMenu(tr("Playlist editor"),4)
1108 browsing=showid3=false;
1110 if(MP3Setup.EditorMode) showid3=true;
1112 cSong *mp3 = playlist->First();
1114 cOsdMenu::Add(new cMenuPlayListItem(mp3,showid3));
1115 mp3 = playlist->cList<cSong>::Next(mp3);
1117 Buttons(); Display();
1120 void cMenuPlayList::Buttons(void)
1122 SetHelp(tr("Add"), showid3?tr("Filenames"):tr("ID3 names"), tr("Remove"), trVDR(BUTTON"Mark"));
1125 void cMenuPlayList::Refresh(bool all)
1127 cMenuPlayListItem *cur=(cMenuPlayListItem *)((all || Count()<2) ? First() : Get(Current()));
1130 cur=(cMenuPlayListItem *)Next(cur);
1134 void cMenuPlayList::Add(void)
1136 cFileObj *item=cMenuInstantBrowse::GetSelected();
1138 Status(tr("Scanning directory..."));
1139 cInstantPlayList *newpl=new cInstantPlayList(item);
1141 if(newpl->Count()) {
1142 if(newpl->Count()==1 || Interface->Confirm(tr("Add recursivly?"))) {
1143 cSong *mp3=newpl->First();
1145 cSong *n=new cSong(mp3);
1147 cMenuPlayListItem *current=(cMenuPlayListItem *)Get(Current());
1148 playlist->Add(n,current->Song());
1149 cOsdMenu::Add(new cMenuPlayListItem(n,showid3),true,current);
1153 cOsdMenu::Add(new cMenuPlayListItem(n,showid3),true);
1155 mp3=newpl->cList<cSong>::Next(mp3);
1158 Refresh(); Display();
1161 else Error(tr("Empty directory!"));
1163 else Error(tr("Error scanning directory!"));
1169 void cMenuPlayList::Move(int From, int To)
1171 playlist->Move(From,To); playlist->Save();
1172 cOsdMenu::Move(From,To);
1173 Refresh(true); Display();
1176 eOSState cMenuPlayList::ShowID3(void)
1179 Buttons(); Refresh(true); Display();
1183 eOSState cMenuPlayList::ID3Info(void)
1186 cMenuPlayListItem *current = (cMenuPlayListItem *)Get(Current());
1187 AddSubMenu(new cMenuID3Info(current->Song()));
1192 eOSState cMenuPlayList::Remove(void)
1195 cMenuPlayListItem *current = (cMenuPlayListItem *)Get(Current());
1196 if(Interface->Confirm(tr("Remove entry?"))) {
1197 playlist->Del(current->Song()); playlist->Save();
1198 cOsdMenu::Del(Current());
1199 Refresh(); Display();
1205 eOSState cMenuPlayList::ProcessKey(eKeys Key)
1207 eOSState state = cOsdMenu::ProcessKey(Key);
1209 if(browsing && !HasSubMenu() && state==osContinue) { Add(); browsing=false; }
1211 if(state==osUnknown) {
1213 case kOk: return ID3Info();
1214 case kRed: browsing=true;
1215 return AddSubMenu(new cMenuInstantBrowse(MP3Sources.GetSource(),tr("Add"),tr("Add all")));
1216 case kGreen: return ShowID3();
1217 case kYellow: return Remove();
1218 case kBlue: Mark(); return osContinue;
1219 case kMenu: return osEnd;
1226 // --- cPlaylistRename --------------------------------------------------------
1228 class cPlaylistRename : public cOsdMenu {
1230 static char *newname;
1231 const char *oldname;
1234 cPlaylistRename(const char *Oldname);
1235 virtual eOSState ProcessKey(eKeys Key);
1236 static const char *GetNewname(void) { return newname; }
1239 char *cPlaylistRename::newname = NULL;
1241 cPlaylistRename::cPlaylistRename(const char *Oldname)
1242 :cOsdMenu(tr("Rename playlist"), 15)
1244 free(newname); newname=0;
1248 asprintf(&buf,"%s\t%s",tr("Old name:"),oldname);
1249 cOsdItem *old = new cOsdItem(buf,osContinue);
1250 #if APIVERSNUM >= 10307
1251 old->SetSelectable(false);
1253 old->SetColor(clrWhite, clrBackground);
1259 Add(new cMenuEditStrItem( tr("New name"), data, sizeof(data)-1, tr(FileNameChars)),true);
1262 eOSState cPlaylistRename::ProcessKey(eKeys Key)
1264 eOSState state = cOsdMenu::ProcessKey(Key);
1266 if (state == osUnknown) {
1268 case kOk: if(data[0] && strcmp(data,oldname)) newname=strdup(data);
1273 case kBlue: return osContinue;
1280 // --- cMenuMP3Item -----------------------------------------------------
1282 class cMenuMP3Item : public cOsdItem {
1284 cPlayList *playlist;
1285 virtual void Set(void);
1287 cMenuMP3Item(cPlayList *PlayList);
1288 cPlayList *List(void) { return playlist; }
1291 cMenuMP3Item::cMenuMP3Item(cPlayList *PlayList)
1297 void cMenuMP3Item::Set(void)
1300 asprintf(&buffer," %s",playlist->BaseName());
1301 SetText(buffer,false);
1304 // --- cMenuMP3 --------------------------------------------------------
1306 class cMenuMP3 : public cOsdMenu {
1309 bool renaming, sourcing, instanting;
1311 eOSState Play(void);
1312 eOSState Edit(void);
1314 eOSState Delete(void);
1315 eOSState Rename(bool second);
1316 eOSState Source(bool second);
1317 eOSState Instant(bool second);
1318 void ScanLists(void);
1319 eOSState SetButtons(int num);
1323 virtual eOSState ProcessKey(eKeys Key);
1326 cMenuMP3::cMenuMP3(void)
1327 :cOsdMenu(tr("MP3"))
1329 renaming=sourcing=instanting=false;
1330 lists=new cPlayLists;
1331 ScanLists(); SetButtons(1);
1332 if(MP3Setup.MenuMode) Instant(false);
1335 cMenuMP3::~cMenuMP3(void)
1340 eOSState cMenuMP3::SetButtons(int num)
1344 SetHelp(trVDR(BUTTON"Edit"), tr("Source"), tr("Browse"), ">>");
1347 SetHelp("<<", trVDR(BUTTON"New"), trVDR(BUTTON"Delete"), tr("Rename"));
1350 buttonnum=num; Display();
1354 void cMenuMP3::ScanLists(void)
1357 Status(tr("Scanning playlists..."));
1358 bool res=lists->Load(MP3Sources.GetSource());
1361 cPlayList *plist=lists->First();
1363 Add(new cMenuMP3Item(plist));
1364 plist=lists->Next(plist);
1367 else Error(tr("Error scanning playlists!"));
1370 eOSState cMenuMP3::Delete(void)
1373 if(Interface->Confirm(tr("Delete playlist?")) &&
1374 Interface->Confirm(tr("Are you sure?")) ) {
1375 cPlayList *plist = ((cMenuMP3Item *)Get(Current()))->List();
1376 if(plist->Delete()) {
1378 cOsdMenu::Del(Current());
1381 else Error(tr("Error deleting playlist!"));
1387 eOSState cMenuMP3::New(void)
1389 cPlayList *plist=new cPlayList(MP3Sources.GetSource(),0,0);
1393 if(i) sprintf(name,"%s%d",tr("unnamed"),i++);
1394 else { strcpy(name,tr("unnamed")); i++; }
1395 } while(plist->TestName(name));
1397 if(plist->Create(name)) {
1399 Add(new cMenuMP3Item(plist), true);
1401 isyslog("MP3: playlist %s added", plist->Name());
1402 return AddSubMenu(new cMenuPlayList(plist));
1404 Error(tr("Error creating playlist!"));
1409 eOSState cMenuMP3::Rename(bool second)
1411 if(HasSubMenu() || Count() == 0) return osContinue;
1413 cPlayList *plist = ((cMenuMP3Item *)Get(Current()))->List();
1416 return AddSubMenu(new cPlaylistRename(plist->BaseName()));
1419 const char *newname=cPlaylistRename::GetNewname();
1421 if(plist->Rename(newname)) {
1423 DisplayCurrent(true);
1425 else Error(tr("Error renaming playlist!"));
1430 eOSState cMenuMP3::Edit(void)
1432 if(HasSubMenu() || Count() == 0) return osContinue;
1434 cPlayList *plist = ((cMenuMP3Item *)Get(Current()))->List();
1435 if(!plist->Load()) Error(tr("Error loading playlist!"));
1436 else if(!plist->IsWinAmp()) {
1437 isyslog("MP3: editing playlist %s", plist->Name());
1438 return AddSubMenu(new cMenuPlayList(plist));
1440 else Error(tr("Can't edit a WinAmp playlist!"));
1444 eOSState cMenuMP3::Play(void)
1446 if(HasSubMenu() || Count() == 0) return osContinue;
1448 Status(tr("Loading playlist..."));
1449 cPlayList *newpl=new cPlayList(((cMenuMP3Item *)Get(Current()))->List());
1450 if(newpl->Load() && newpl->Count()) {
1451 isyslog("mp3: playback started with playlist %s", newpl->Name());
1452 cMP3Control::SetPlayList(newpl);
1453 if(MP3Setup.KeepSelect) { Status(0); return osContinue; }
1458 Error(tr("Error loading playlist!"));
1462 eOSState cMenuMP3::Source(bool second)
1464 if(HasSubMenu()) return osContinue;
1468 return AddSubMenu(new cMenuSource(&MP3Sources,tr("MP3 source")));
1471 cFileSource *src=cMenuSource::GetSelected();
1473 MP3Sources.SetSource(src);
1480 eOSState cMenuMP3::Instant(bool second)
1482 if(HasSubMenu()) return osContinue;
1486 return AddSubMenu(new cMenuInstantBrowse(MP3Sources.GetSource(),trVDR(BUTTON"Play"),tr("Play all")));
1489 cFileObj *item=cMenuInstantBrowse::GetSelected();
1491 Status(tr("Building playlist..."));
1492 cInstantPlayList *newpl = new cInstantPlayList(item);
1493 if(newpl->Load() && newpl->Count()) {
1494 isyslog("mp3: playback started with instant playlist %s", newpl->Name());
1495 cMP3Control::SetPlayList(newpl);
1496 if(MP3Setup.KeepSelect) { Status(0); return Instant(false); }
1501 Error(tr("Error building playlist!"));
1506 eOSState cMenuMP3::ProcessKey(eKeys Key)
1508 eOSState state = cOsdMenu::ProcessKey(Key);
1510 if(!HasSubMenu() && state==osContinue) { // eval the return value from submenus
1511 if(renaming) return Rename(true);
1512 if(sourcing) return Source(true);
1513 if(instanting) return Instant(true);
1516 if(state == osUnknown) {
1518 case kOk: return Play();
1519 case kRed: return (buttonnum==1 ? Edit() : SetButtons(1));
1520 case kGreen: return (buttonnum==1 ? Source(false) : New());
1521 case kYellow: return (buttonnum==1 ? Instant(false) : Delete());
1522 case kBlue: return (buttonnum==1 ? SetButtons(2) : Rename(false));
1523 case kMenu: return osEnd;
1530 // --- PropagateImage ----------------------------------------------------------
1532 void PropagateImage(const char *image)
1534 cPlugin *graphtft=cPluginManager::GetPlugin("graphtft");
1535 if(graphtft) graphtft->SetupParse("CoverImage",image ? image:"");
1538 // --- cPluginMP3 --------------------------------------------------------------
1540 static const char *VERSION = PLUGIN_VERSION;
1541 static const char *DESCRIPTION = trNOOP("A versatile audio player");
1542 static const char *MAINMENUENTRY = "MP3";
1544 class cPluginMp3 : public cPlugin {
1546 #if APIVERSNUM >= 10330
1547 bool ExternalPlay(const char *path, bool test);
1551 virtual ~cPluginMp3();
1552 virtual const char *Version(void) { return VERSION; }
1553 virtual const char *Description(void) { return tr(DESCRIPTION); }
1554 virtual const char *CommandLineHelp(void);
1555 virtual bool ProcessArgs(int argc, char *argv[]);
1556 #if APIVERSNUM >= 10131
1557 virtual bool Initialize(void);
1559 virtual bool Start(void);
1561 virtual void Housekeeping(void);
1562 virtual const char *MainMenuEntry(void);
1563 virtual cOsdObject *MainMenuAction(void);
1564 virtual cMenuSetupPage *SetupMenu(void);
1565 virtual bool SetupParse(const char *Name, const char *Value);
1566 #if APIVERSNUM >= 10330
1567 virtual bool Service(const char *Id, void *Data);
1568 #if APIVERSNUM >= 10331
1569 virtual const char **SVDRPHelpPages(void);
1570 virtual cString SVDRPCommand(const char *Command, const char *Option, int &ReplyCode);
1575 cPluginMp3::cPluginMp3(void)
1577 // Initialize any member varaiables here.
1578 // DON'T DO ANYTHING ELSE THAT MAY HAVE SIDE EFFECTS, REQUIRE GLOBAL
1579 // VDR OBJECTS TO EXIST OR PRODUCE ANY OUTPUT!
1582 cPluginMp3::~cPluginMp3()
1584 InfoCache.Shutdown();
1588 const char *cPluginMp3::CommandLineHelp(void)
1590 static char *help_str=0;
1592 free(help_str); // for easier orientation, this is column 80|
1593 asprintf(&help_str," -m CMD, --mount=CMD use CMD to mount/unmount/eject mp3 sources\n"
1595 " -n CMD, --network=CMD execute CMD before & after network access\n"
1597 " -C DIR, --cache=DIR store ID3 cache file in DIR\n"
1599 " -B DIR, --cddb=DIR search CDDB files in DIR\n"
1601 " -D DEV, --dsp=DEV device for OSS output\n"
1603 " -i CMD, --iconv=CMD use CMD to convert background images\n"
1605 " -c DIR, --icache=DIR cache converted images in DIR\n"
1607 " -S SUB, --sources=SUB search sources config in SUB subdirectory\n"
1611 netscript ? netscript:"none",
1612 cachedir ? cachedir:"video dir",
1625 sourcesSub ? sourcesSub:"empty"
1630 bool cPluginMp3::ProcessArgs(int argc, char *argv[])
1632 static struct option long_options[] = {
1633 { "mount", required_argument, NULL, 'm' },
1634 { "network", required_argument, NULL, 'n' },
1635 { "cddb", required_argument, NULL, 'B' },
1636 { "dsp", required_argument, NULL, 'D' },
1637 { "cache", required_argument, NULL, 'C' },
1638 { "icache", required_argument, NULL, 'c' },
1639 { "iconv", required_argument, NULL, 'i' },
1640 { "sources", required_argument, NULL, 'S' },
1644 int c, option_index = 0;
1645 while((c=getopt_long(argc,argv,"c:i:m:n:B:C:D:S:",long_options,&option_index))!=-1) {
1647 case 'i': imageconv=optarg; break;
1648 case 'c': imagecache=optarg; break;
1649 case 'm': mountscript=optarg; break;
1650 case 'n': netscript=optarg; break;
1651 case 'C': cachedir=optarg; break;
1652 case 'S': sourcesSub=optarg; break;
1655 cddbpath=optarg; break;
1657 fprintf(stderr, "mp3: libsndfile support has not been compiled in!\n"); return false;
1661 dspdevice=optarg; break;
1663 fprintf(stderr, "mp3: OSS output has not been compiled in!\n"); return false;
1665 default: return false;
1671 #if APIVERSNUM >= 10131
1672 bool cPluginMp3::Initialize(void)
1674 bool cPluginMp3::Start(void)
1677 if(!CheckVDRVersion(1,1,29,"mp3")) return false;
1679 #if APIVERSNUM < 10507
1682 i18n_name="vdr-mp3";
1684 MP3Sources.Load(AddDirectory(ConfigDirectory(sourcesSub),"mp3sources.conf"));
1685 if(MP3Sources.Count()<1) {
1686 esyslog("ERROR: you should have defined at least one source in mp3sources.conf");
1687 fprintf(stderr,"No source(s) defined in mp3sources.conf\n");
1691 #if APIVERSNUM < 10507
1692 RegisterI18n(Phrases);
1694 mgr=new cPlayManager;
1696 esyslog("ERROR: creating playmanager failed");
1697 fprintf(stderr,"Creating playmanager failed\n");
1700 d(printf("mp3: using %s\n",mad_version))
1701 d(printf("mp3: compiled with %s\n",MAD_VERSION))
1705 void cPluginMp3::Housekeeping(void)
1710 const char *cPluginMp3::MainMenuEntry(void)
1712 return MP3Setup.HideMainMenu ? 0 : tr(MAINMENUENTRY);
1715 cOsdObject *cPluginMp3::MainMenuAction(void)
1717 return new cMenuMP3;
1720 cMenuSetupPage *cPluginMp3::SetupMenu(void)
1722 return new cMenuSetupMP3;
1725 bool cPluginMp3::SetupParse(const char *Name, const char *Value)
1727 if (!strcasecmp(Name, "InitLoopMode")) MP3Setup.InitLoopMode = atoi(Value);
1728 else if (!strcasecmp(Name, "InitShuffleMode")) MP3Setup.InitShuffleMode = atoi(Value);
1729 else if (!strcasecmp(Name, "AudioMode")) MP3Setup.AudioMode = atoi(Value);
1730 else if (!strcasecmp(Name, "BgrScan")) MP3Setup.BgrScan = atoi(Value);
1731 else if (!strcasecmp(Name, "EditorMode")) MP3Setup.EditorMode = atoi(Value);
1732 else if (!strcasecmp(Name, "DisplayMode")) MP3Setup.DisplayMode = atoi(Value);
1733 else if (!strcasecmp(Name, "BackgrMode")) MP3Setup.BackgrMode = atoi(Value);
1734 else if (!strcasecmp(Name, "MenuMode")) MP3Setup.MenuMode = atoi(Value);
1735 else if (!strcasecmp(Name, "TargetLevel")) MP3Setup.TargetLevel = atoi(Value);
1736 else if (!strcasecmp(Name, "LimiterLevel")) MP3Setup.LimiterLevel = atoi(Value);
1737 else if (!strcasecmp(Name, "Only48kHz")) MP3Setup.Only48kHz = atoi(Value);
1738 else if (!strcasecmp(Name, "UseProxy")) MP3Setup.UseProxy = atoi(Value);
1739 else if (!strcasecmp(Name, "ProxyHost")) strn0cpy(MP3Setup.ProxyHost,Value,MAX_HOSTNAME);
1740 else if (!strcasecmp(Name, "ProxyPort")) MP3Setup.ProxyPort = atoi(Value);
1741 else if (!strcasecmp(Name, "UseCddb")) MP3Setup.UseCddb = atoi(Value);
1742 else if (!strcasecmp(Name, "CddbHost")) strn0cpy(MP3Setup.CddbHost,Value,MAX_HOSTNAME);
1743 else if (!strcasecmp(Name, "CddbPort")) MP3Setup.CddbPort = atoi(Value);
1744 else if (!strcasecmp(Name, "AbortAtEOL")) MP3Setup.AbortAtEOL = atoi(Value);
1745 else if (!strcasecmp(Name, "AudioOutMode")) {
1746 MP3Setup.AudioOutMode = atoi(Value);
1748 if(MP3Setup.AudioOutMode==AUDIOOUTMODE_OSS) {
1749 esyslog("WARNING: AudioOutMode OSS not supported, falling back to DVB");
1750 MP3Setup.AudioOutMode=AUDIOOUTMODE_DVB;
1754 #if APIVERSNUM >= 10307
1755 else if (!strcasecmp(Name, "ReplayDisplay")) MP3Setup.ReplayDisplay = atoi(Value);
1757 else if (!strcasecmp(Name, "HideMainMenu")) MP3Setup.HideMainMenu = atoi(Value);
1758 else if (!strcasecmp(Name, "KeepSelect")) MP3Setup.KeepSelect = atoi(Value);
1759 else if (!strcasecmp(Name, "TitleArtistOrder")) MP3Setup.TitleArtistOrder = atoi(Value);
1764 #if APIVERSNUM >= 10330
1766 bool cPluginMp3::ExternalPlay(const char *path, bool test)
1768 char real[PATH_MAX+1];
1769 if(realpath(path,real)) {
1770 cFileSource *src=MP3Sources.FindSource(real);
1772 cFileObj *item=new cFileObj(src,0,0,otFile);
1774 item->SplitAndSet(real);
1775 if(item->GuessType()) {
1776 if(item->Exists()) {
1777 cInstantPlayList *pl=new cInstantPlayList(item);
1778 if(pl && pl->Load() && pl->Count()) {
1779 if(!test) cMP3Control::SetPlayList(pl);
1784 else dsyslog("MP3 service: error building playlist");
1787 else dsyslog("MP3 service: cannot play '%s'",path);
1789 else dsyslog("MP3 service: GuessType() failed for '%s'",path);
1793 else dsyslog("MP3 service: cannot find source for '%s', real '%s'",path,real);
1795 else if(errno!=ENOENT && errno!=ENOTDIR)
1796 esyslog("ERROR: realpath: %s: %s",path,strerror(errno));
1800 bool cPluginMp3::Service(const char *Id, void *Data)
1802 if(!strcasecmp(Id,"MP3-Play-v1")) {
1804 struct MPlayerServiceData *msd=(struct MPlayerServiceData *)Data;
1805 msd->result=ExternalPlay(msd->data.filename,false);
1809 else if(!strcasecmp(Id,"MP3-Test-v1")) {
1811 struct MPlayerServiceData *msd=(struct MPlayerServiceData *)Data;
1812 msd->result=ExternalPlay(msd->data.filename,true);
1819 #if APIVERSNUM >= 10331
1821 const char **cPluginMp3::SVDRPHelpPages(void)
1823 static const char *HelpPages[] = {
1825 " Triggers playback of file 'filename'.",
1827 " Tests is playback of file 'filename' is possible.",
1829 " Returns filename of song currently being replayed.",
1835 cString cPluginMp3::SVDRPCommand(const char *Command, const char *Option, int &ReplyCode)
1837 if(!strcasecmp(Command,"PLAY")) {
1839 if(ExternalPlay(Option,false)) return "Playback triggered";
1840 else { ReplyCode=550; return "Playback failed"; }
1842 else { ReplyCode=501; return "Missing filename"; }
1844 else if(!strcasecmp(Command,"TEST")) {
1846 if(ExternalPlay(Option,true)) return "Playback possible";
1847 else { ReplyCode=550; return "Playback not possible"; }
1849 else { ReplyCode=501; return "Missing filename"; }
1851 else if(!strcasecmp(Command,"CURR")) {
1852 cControl *control=cControl::Control();
1853 if(control && typeid(*control)==typeid(cMP3Control)) {
1855 if(mgr->Info(-1,&mode)) return mode.Filename;
1856 else return "<unknown>";
1858 else { ReplyCode=550; return "No running playback"; }
1866 VDRPLUGINCREATOR(cPluginMp3); // Don't touch this!