2 Copyright 2004-2005 Chris Tallon, Andreas Vogel
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP 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 VOMP; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include "vmediaview.h"
25 #include "vpicturebanner.h"
26 #include "vcolourtuner.h"
27 #include "audioplayer.h"
30 #include "wselectlist.h"
41 #include "mediaoptions.h"
42 #include "mediaplayer.h"
45 const int VMediaView::EVENT_SLIDESHOW=100;
46 const int VMediaView::EVENT_DRAWINGDONE=101;
47 const int VMediaView::EVENT_DRAWINGERROR=102;
48 const int VMediaView::EVENT_DIRECTORYDONE=103;
52 * the combined user interface for pictures and audio
53 * has 2 surfaces to enable drawing in a separate thread
54 * the info display can either show a picture info or and audio info
55 * if the audio player comes on top it disables the picture info display
56 * basically we have 3 modes:
57 * - HIDDEN viewer is hidden (pictureEnabled=false, audioEnabled=false)
58 * if justPlaying=true the audioplayer is still running
59 * - PICTURE picture viewer on top ("slide show") - pictureEnabled=true, audioEnabled=false
60 * no AudioBanner visible
61 * if justPlaying=true the audio player runs in bg
62 * - AUDIO audioPlayer on top ("playlist mode") - pictureEnabled=true, audioEnabled=true
63 * the picture viewer is currently halted (should be able to continue if no AudioInfo)
64 * no picture banner (we should have an audio banner to indicate the audio player on top!)
65 * state transitions (via setPictureMode, setAudioMode)
66 * - show Picture -> pictureEnabled=true,
67 * only called from command handler if audioEnabled=false
68 * call from mediaList only possible if audioEnabled=false
69 * *** TODO: would be better to have separate function for external call/internal call
70 * - play [Audio] -> if activate is set -> audioEnabled=true (-> Mode AUDIO)
71 * used for calls from medialist
72 * internal calls do not set activate!
73 * - YELLOW key - toggle
74 * if audioActive==true -> audioActive=false (new mode depends on pictureEnabled - either HIDDEN or PICTURE)
75 * if audioActive==false -> audioActive=true (new mode AUDIO)
76 * *** open handling if no audio file there (ignore key???) - currently empty player
77 * - BACK if mode AUDIO -> audioEnabled=false, justPlaying=false
78 * - BACK if mode PICTURE -> pictureEnabled=false;
79 * - player StreamEnd -> audioEnabled=false (new mode depends on pciture - either HIDDEN or PICTURE)
80 * info/banner handling:
81 * - AudioInfo - alternativ to pictureInfo
82 * off when disabling audio or after timer or with OK in AUDIO mode
83 * on currently any command or player event (end/new song) when audioEnabled==true and retriggerAudioInfo=true
84 * on on OK in AUDIO mode
86 * off when disabling Picture or after timer, OK, green
87 * on only on green when pictureEnabled==true
89 * 2 modes: loading/normal
91 * off when disabling picture, OK, after timer
92 * on when enabling picture, with OK
94 * off when disabling picture and when loading done
96 * *** open: do not show when audio enabled and slide show running (currently slideshow is paused)
98 * always shown when audioEnabled=true
99 * on when enabling Audio
100 * off when disabling audio
102 * timers: 1 - slide show
105 * 4 - audio short update
108 #define DRAWING_THREAD
110 DrawStyle VMediaView::pictureBack=DrawStyle(140,140,140);
111 DrawStyle VMediaView::infoBack=DrawStyle(110,110,110);
112 DrawStyle VMediaView::audioBannerBack=DrawStyle(110,110,110,20);
115 //how long do we wait for a single picture chunk
116 //the unit is 100ms (the timeout on the server side)
118 class VPreader : public JpegReader {
125 VPreader(VMediaView *p,ImageReader *r){
131 virtual ULONG readChunk(ULONG offset,ULONG len,char ** buf) {
132 Log::getInstance()->log("VMediaView::jpegReader", Log::DEBUG, "read chunk o=%d,len=%d,buf=%p",
136 for (int trycount=0;trycount < MAXTRY && ! dobreak && numrec == 0 && rt == 0;trycount++) {
142 rt=reader->getImageChunk((ULLONG)offset,(UINT)len,&numrec,(UCHAR **)buf);
145 Log::getInstance()->log("VMediaView::jpegReader", Log::DEBUG, "got n=%d,buf=%p,rt=%d",
149 virtual int initRead(const MediaURI *uri,ULLONG *sz,ULONG factor=100) {
150 Log::getInstance()->log("VMediaView::jpegReader", Log::DEBUG, "load image %s",uri->getDisplayName());
151 Video* video = Video::getInstance();
153 int rt=MediaPlayer::getInstance()->openMedium(1,uri,sz,video->getScreenWidth()*factor/100, video->getScreenHeight()*factor/100);
156 Log::getInstance()->log("VMediaView::jpegReader", Log::DEBUG, "load image %s returned %llu",uri->getDisplayName(),size);
159 virtual ULONG getSize() {return size;}
160 //seems to be thread safe (more or less...)
167 * a separate thread for drawing pictures
168 * will be started with the sfc and the draw control
169 * will send a player event when done
171 class DrawingThread : public Thread_TYPE {
175 WJpegComplex::JpegControl *_ctl;
180 DrawingThread(VMediaView *parent) {
187 virtual ~DrawingThread(){}
189 return (threadIsActive()!=0);
191 bool start(WJpegComplex::JpegControl *ctl,Surface *sfc,VPreader *reader,DrawStyle &c) {
200 return (threadStart() == 1);
203 Log::getInstance()->log("DrawingThread",Log::DEBUG,"stop initiated");
204 if (threadIsActive()) {
206 if (_reader) _reader->setBreak();
209 Log::getInstance()->log("DrawingThread",Log::DEBUG,"stop done");
214 virtual void threadMethod() {
215 Log::getInstance()->log("DrawingThread",Log::DEBUG,"started");
216 bool rt=WJpegComplex::drawJpeg(_ctl,_sfc,_reader,_colour);
218 if (! _interrupted) {
219 Message* m = new Message();
220 //we misuse PLAYER_EVENT here
221 m->message = Message::PLAYER_EVENT;
224 m->parameter.num = rt?VMediaView::EVENT_DRAWINGDONE:VMediaView::EVENT_DRAWINGERROR;
225 Command::getInstance()->postMessageFromOuterSpace(m);
227 Log::getInstance()->log("DrawingThread",Log::DEBUG,"finishing interrupt=%d",(int)_interrupted);
229 virtual void threadPostStopCleanup() {}
234 VMediaView::VMediaView(VMediaList *p)
236 Log::getInstance()->log("VMediaView::VMediaView", Log::DEBUG, "p=%p", this);
238 pictureEnabled=false;
240 ireader=new ImageReader(1,MediaPlayer::getInstance());
241 reader=new VPreader(this,ireader);
242 //the surface handling
243 Video* video = Video::getInstance();
244 setSize(video->getScreenWidth(), video->getScreenHeight());
248 //create the second surface
253 //disable the surface
262 pictureLoading=false;
265 showtime=INITIAL_SHOWTIME;
266 rotate=WJpegComplex::ROT_0;
268 options=MediaOptions::getInstance();
269 VColourTuner::initFactors();
270 int st=options->getIntOption("SlideShowInterval");
271 if (st > 0) showtime=st;
272 ctl.area.w=originalw;
273 ctl.area.h=originalh;
275 ctl.scaleafter=options->getIntOption("ScaleFactor");
276 const char * mode=options->getStringOption("PictureMode");
277 if (strcmp(mode,"clip") == 0) ctl.mode=WJpegComplex::CROP;
278 else if (strcmp(mode,"letter") == 0) ctl.mode=WJpegComplex::LETTER;
279 else if (strcmp(mode,"clipfactor") == 0) ctl.mode=WJpegComplex::CROPPERCENT;
280 ctl.scaleAmount=options->getIntOption("PictureSize");
281 if (ctl.scaleAmount < 10) ctl.scaleAmount=10;
282 if (ctl.scaleAmount > 200) ctl.scaleAmount=200;
285 //current control is the one used for DISPLAY (not the one for drawing - this is the other one)
286 //this is closely coupled to the surface - i.e. ctl is for sfc1, ctl2 for sfc2
289 pictureShowing=false;
293 barBlue.set(0, 0, 150, 150);
298 retriggerAudioInfo=false;
300 drawingThread=new DrawingThread(this);
303 VMediaView::~VMediaView()
305 Log::getInstance()->log("VMediaView::~VMediaView", Log::DEBUG, "p=%p,secondSfc=%s", this,(secondSurface()?"true":"false"));
306 destroyPictureBanner();
307 if (currentPicture) delete currentPicture;
308 Timers::getInstance()->cancelTimer(this,1);
309 Timers::getInstance()->cancelTimer(this,2);
310 Timers::getInstance()->cancelTimer(this,3);
311 Timers::getInstance()->cancelTimer(this,4);
312 Timers::getInstance()->cancelTimer(this,5);
314 destroyAudioBanner();
315 if (getPlayer(false)) {
316 AudioPlayer::getInstance(NULL,false)->shutdown();
318 if (currentAudio) delete currentAudio;
319 drawingThread->stop();
323 if (secondSurface()) {
331 MediaPlayer::getInstance()->closeMediaChannel(1);
332 MediaPlayer::getInstance()->closeMediaChannel(2);
333 Log::getInstance()->log("VMediaView::~VMediaView", Log::DEBUG, "done p=%p", this);
336 void VMediaView::setPictureMode(bool act) {
337 Log::getInstance()->log("VMediaView", Log::DEBUG, "set pictureMode %d p=%d, a=%d", (int)act,(int)pictureEnabled,(int)audioEnabled);
339 if ( ! pictureEnabled && ! audioEnabled) {
345 if (! pictureEnabled) {
346 //we newly enable the picture - so clear the screen
348 BoxStack::getInstance()->update(this);
349 if (slideshow) startSlideshow();
354 if ( pictureEnabled) {
355 destroyPictureBanner();
356 stopSlideshow(false);
357 #ifdef DRAWING_THREAD
358 drawingThread->stop();
360 if (! audioEnabled) {
368 pictureShowing=false;
373 //we can disable audio without automatically hiding us
374 //this will become strange - we are visible but do not handle
375 //keys - so if you call setAudioMode(false,false) be sure
376 //to call setAudioMode(false,true) afterwards
377 //it is only here to give the list a chance to start a new play
378 //when we call directoryDone
379 void VMediaView::setAudioMode(bool act,bool doHiding) {
380 Log::getInstance()->log("VMediaView", Log::DEBUG, "setAudioMode %d p=%d, a=%d", (int)act,(int)pictureEnabled,(int)audioEnabled);
382 if (! audioEnabled) {
383 if (! pictureEnabled) {
386 draw(); //empty screen if no picture
389 destroyPictureBanner();
401 destroyAudioBanner();
403 if (! pictureEnabled && doHiding) {
411 if (havePictureBanner && ! pictureBanner) showPictureBanner();
418 void VMediaView::draw()
420 Log::getInstance()->log("VMediaView::draw", Log::DEBUG, "pictureError=%s,p=%p", pictureError,this);
422 if (pictureShowing ) fillColour(pictureBack);
423 else fillColour(DrawStyle::BLACK);
425 drawText(pictureError,100,area.h/2,DrawStyle::LIGHTTEXT);
431 int VMediaView::handleCommand(int command)
433 Log::getInstance()->log("VMediaView::handleCommand", Log::DEBUG, "cmd=%d,p=%p", command,this);
434 if ( !audioEnabled && ! pictureEnabled ) {
436 if (command == Remote::YELLOW) {
442 if ( ! audioEnabled) {
443 //------------------------- command in mode PICTURE (i.e. picture is on top) ----------------
450 case Remote::SKIPBACK:
451 rotate=WJpegComplex::ROT_0;
452 showPicture(VMediaList::MV_PREV,slideshow,true);
455 case Remote::FORWARD:
456 if (showtime > 1) showtime--;
457 updatePictureBanner(true);
459 case Remote::DF_DOWN:
461 case Remote::SKIPFORWARD:
462 rotate=WJpegComplex::ROT_0;
463 showPicture(VMediaList::MV_NEXT,slideshow,true);
466 case Remote::REVERSE:
467 if (showtime < 50 ) showtime++;
468 updatePictureBanner(true);
473 destroyPictureBanner();
475 havePictureBanner=false;
478 havePictureBanner=true;
479 showPictureBanner(pictureLoading);
487 rotate=WJpegComplex::ROT_0;
488 showPicture(VMediaList::MV_NEXT,slideshow,true);
495 updatePictureBanner();
499 rotate=WJpegComplex::ROT_0;
500 showPicture(VMediaList::MV_NEXT,slideshow,true);
506 showtime=INITIAL_SHOWTIME;
507 updatePictureBanner();
512 case WJpegComplex::ROT_0:
513 rotate=WJpegComplex::ROT_90;
515 case WJpegComplex::ROT_90:
516 rotate=WJpegComplex::ROT_180;
518 case WJpegComplex::ROT_180:
519 rotate=WJpegComplex::ROT_270;
521 case WJpegComplex::ROT_270:
522 rotate=WJpegComplex::ROT_0;
525 showPicture(VMediaList::MV_NONE,slideshow,true);
529 if (info) destroyInfo();
530 else showPictureInfo();
535 case WJpegComplex::CROP:
536 cropmode=WJpegComplex::LETTER;
538 case WJpegComplex::LETTER:
539 cropmode=WJpegComplex::CROPPERCENT;
542 cropmode=WJpegComplex::CROP;
545 showPicture(VMediaList::MV_NONE,slideshow,true);
550 destroyPictureBanner();
552 VColourTuner *ct=new VColourTuner();
553 BoxStack::getInstance()->add(ct);
555 BoxStack::getInstance()->update(ct);
561 setPictureMode(false);
575 bool updateInfo=false;
576 //------------------------- command in mode AUDIO (i.e. audio is on top) ----------------
585 play(playall,false,VMediaList::MV_PREV);
588 case Remote::FORWARD:
589 if (! audioError) getPlayer()->fastForward();
593 case Remote::DF_DOWN:
595 play(playall,false,VMediaList::MV_NEXT);
598 case Remote::SKIPFORWARD:
599 if (! audioError) getPlayer()->skipForward(10);
602 case Remote::SKIPBACK:
603 if (! audioError) getPlayer()->skipBackward(10);
606 case Remote::REVERSE:
610 if (! audioError) getPlayer()->jumpToPercent(0);
614 if (! audioError) getPlayer()->jumpToPercent(10);
618 if (! audioError) getPlayer()->jumpToPercent(20);
622 if (! audioError) getPlayer()->jumpToPercent(30);
626 if (! audioError) getPlayer()->jumpToPercent(40);
630 if (! audioError) getPlayer()->jumpToPercent(50);
634 if (! audioError) getPlayer()->jumpToPercent(60);
638 if (! audioError) getPlayer()->jumpToPercent(70);
642 if (! audioError) getPlayer()->jumpToPercent(80);
646 if (! audioError) getPlayer()->jumpToPercent(90);
654 retriggerAudioInfo=false;
657 retriggerAudioInfo=true;
660 if (getPlayer()->getState() == AudioPlayer::S_ERROR) {
661 if (playall) play(playall,false,VMediaList::MV_NEXT);
668 if (! audioError) getPlayer()->unpause();
670 if (getPlayer()->getState() != AudioPlayer::S_ERROR) ;
671 else if (playall) play(playall,false,VMediaList::MV_NEXT);
676 if (! audioError) getPlayer()->pause();
690 retriggerAudioInfo=false;
693 if (! pictureShowing) setPictureMode(false); //could have been delayed
698 if (audioEnabled && updateInfo) updateAudioInfo();
703 void VMediaView::processMessage(Message* m)
705 Log::getInstance()->log("VMediaView::processMessage", Log::DEBUG, "cmd=%lu,p=%lu", m->message,m->parameter);
706 if (m->message == Message::MOUSE_MOVE)
710 else if (m->message == Message::MOUSE_LBDOWN)
713 //check if press is outside this view! then simulate cancel
714 int x=(m->parameter.num>>16)-getScreenX();
715 int y=(m->parameter.num&0xFFFF)-getScreenY();
716 if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
718 BoxStack::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
721 else if (m->message = Message::PLAYER_EVENT) {
722 switch (m->parameter.num) {
723 case EVENT_SLIDESHOW:
724 if (! pictureEnabled) break; //old timer msg...
725 //if (! audioEnabled) {
728 rotate=WJpegComplex::ROT_0;
729 showPicture(VMediaList::MV_NEXT,true,false);
734 case EVENT_DRAWINGERROR:
737 case EVENT_DRAWINGDONE:
740 case EVENT_DIRECTORYDONE:
741 //just disable audio without (poetntially) hiding us
742 //this gives the list a chance to decide whether audio
743 //should be on top afterwards without showing the list
745 setAudioMode(false,false);
746 parent->directoryDone();
747 if (! pictureShowing) setPictureMode(false);
748 if (! justPlaying) setAudioMode(false);
750 case AudioPlayer::STREAM_ERR:
751 case AudioPlayer::STREAM_END:
752 if (playall) play(playall,false,VMediaList::MV_NEXT);
758 case AudioPlayer::SHORT_UPDATE:
759 if (info && audioEnabled ) {
761 BoxStack::getInstance()->update(info,&clocksRegion);
762 BoxStack::getInstance()->update(info,&barRegion);
763 Timers::getInstance()->setTimerD(this, 4, 1);
766 case AudioPlayer::NEW_SONG:
767 if (audioEnabled) updateAudioInfo();
769 case AudioPlayer::CONNECTION_LOST:
770 if (audioEnabled) destroyInfo();
771 if (AudioPlayer *player=getPlayer(false)) {
775 Command::getInstance()->connectionLost();
782 VMediaView * VMediaView::createViewer(VMediaList * mparent) {
783 Log::getInstance()->log("VMediaView::createViewer", Log::DEBUG, "p=%p",
785 VMediaView *vmn=new VMediaView(mparent);
786 BoxStack::getInstance()->add(vmn);
788 BoxStack::getInstance()->update(vmn);
792 void VMediaView::startSlideshow() {
794 if (! pictureLoading) Timers::getInstance()->setTimerD(this,1,showtime);
797 void VMediaView::stopSlideshow(bool hard) {
798 if (hard) slideshow=false;
799 Timers::getInstance()->cancelTimer(this,1);
803 void VMediaView::showPicture(ULONG move,bool bslideshow,bool activateBanner) {
805 setPictureMode(true);
807 #ifdef DRAWING_THREAD
808 drawingThread->stop();
810 slideshow=bslideshow;
811 Media *newPicture=parent->getMedia(MEDIA_TYPE_PICTURE,move);
813 pictureShowing=false;
815 //within the event handler first directoryDone is called
816 //and afterwards everything is stopped if nothing new
817 sendCommandMsg(EVENT_DIRECTORYDONE);
824 if (currentPicture) {
825 delete currentPicture;
828 currentPicture=newPicture;
829 loadPicture(currentPicture,activateBanner);
833 //the real picture drawing method
834 //will start drawing on a new surface and will switch it wehn done
836 int VMediaView::loadPicture(Media *md,bool activateBanner) {
839 if (! md->getURI()) {
840 pictureError=tr("No media found");
841 Log::getInstance()->log("VMediaView::load",Log::ERR,"no URI in media");
844 Log::getInstance()->log("VMediaView::load", Log::DEBUG, "filename=%s,p=%p",
845 md->getURI()->getName(),this);
846 //do we have a pictureBanner?
847 havePictureBanner=pictureBanner!=NULL || activateBanner;
849 #ifdef DRAWING_THREAD
850 if (!audioEnabled && havePictureBanner ) showPictureBanner(true);
851 drawingThread->stop();
853 showPictureBanner(true);
857 int rtok=reader->initRead(md->getURI(),&size,ctl.scaleAmount); //scaleAmount is the same for both...
859 //now we can really draw
860 //get the surface for drawing
861 Surface * drawSurface=NULL;
862 WJpegComplex::JpegControl *drawCtl=NULL;
863 getDrawingParam(drawSurface,drawCtl);
865 drawCtl->rotation=rotate;
866 drawCtl->mode=cropmode;
867 drawCtl->compressedSize=size;
868 #ifdef DRAWING_THREAD
869 bool ok=drawingThread->start(drawCtl,drawSurface,reader,pictureBack);
871 Log::getInstance()->log("VMediaView::load", Log::ERR, "unable to start drawing thread");
872 pictureError=tr("JpegError");
873 pictureLoading=false;
874 destroyPictureBanner();
879 //here we could hand this over to the drawing thread
880 bool ok=WJpegComplex::drawJpeg(drawCtl,drawSurface,reader,pictureBack);
885 pictureLoading=false;
889 void VMediaView::drawingDone(bool hasError) {
890 pictureLoading=false;
891 destroyPictureBanner(); //disable loading indication (or real banner)
894 Log::getInstance()->log("VMediaView::drawingDone", Log::DEBUG, "success: sfc now=%p",surface);
896 //only show the pictureBanner if it was there before
897 if (havePictureBanner && ! audioEnabled) showPictureBanner();
898 Log::getInstance()->log("VMediaView::load", Log::DEBUG, "success" );
899 updatePictureInfo(); //will only do somethng if pictureEnabled
903 pictureError=tr("JpegError");
904 if (pictureEnabled) {
909 MediaPlayer::getInstance()->closeMediaChannel(1);
910 #ifndef DRAWING_THREAD
911 if (audioEnabled) showAudioBanner();
913 if (slideshow) startSlideshow();
914 BoxStack::getInstance()->update(this);
917 void VMediaView::showPictureBanner(bool loading) {
918 //we are in the main thread - so we can (and must) safely hard destroy/create the banner
919 Timers::getInstance()->cancelTimer(this,2);
920 if (! currentPicture) {
922 destroyPictureBanner(false);
925 if (pictureBanner) destroyPictureBanner(false);
926 if (! pictureEnabled || ! bannerEnabled) return;
927 pictureBanner= new VPictureBanner(loading, slideshow);
928 pictureBanner->fillColour(infoBack);
930 int len=strlen(currentPicture->getFileName())+Media::TIMEBUFLEN+20;
931 char *buf=new char[len];
932 char tbuf[Media::TIMEBUFLEN];
933 SNPRINTF(buf,len,"%c%02ds%c %s %s " ,
937 currentPicture->getTimeString(tbuf),
938 currentPicture->getFileName()
940 pictureBanner->setText(buf);
944 char *buf=new char[strlen(currentPicture->getDisplayName())+50];
945 SNPRINTF(buf,50,"%s %s",tr("Loading"), currentPicture->getDisplayName());
946 pictureBanner->setText(buf);
949 pictureBanner->draw();
950 if (! loading ) Timers::getInstance()->setTimerD(this,2,8);
951 BoxStack::getInstance()->add(pictureBanner);
952 BoxStack::getInstance()->update(pictureBanner);
955 void VMediaView::destroyPictureBanner(bool fromTimer) {
957 if (fromTimer) sendViewMsg(pictureBanner);
958 else BoxStack::getInstance()->remove(pictureBanner);
960 if (! fromTimer) Timers::getInstance()->cancelTimer(this,2);
963 void VMediaView::updatePictureBanner(bool loading) {
964 if (pictureBanner ) {
965 showPictureBanner(loading);
968 void VMediaView::timercall(int clientref) {
969 Log::getInstance()->log("VMediaView::timercall", Log::DEBUG, "id=%d",clientref);
974 sendCommandMsg(AudioPlayer::SHORT_UPDATE);
979 Log::getInstance()->log("VMediaView::timercall", Log::DEBUG, "infoEnd");
982 //we only did show the audio error info if audio is enabled
983 bool stillError=false;
984 if (AudioPlayer * player=getPlayer(false)) {
985 stillError=player->getState()==AudioPlayer::S_ERROR;
988 sendCommandMsg(AudioPlayer::STREAM_END);
994 if (! slideshow) return;
995 Log::getInstance()->log("VMediaView::timercall", Log::DEBUG, "slideshow");
996 sendCommandMsg(EVENT_SLIDESHOW);
999 Log::getInstance()->log("VMediaView::timercall", Log::DEBUG, "pictureBannerEnd");
1000 destroyPictureBanner(true);
1006 #define INFOBUF 2000
1007 void VMediaView::showPictureInfo(){
1008 if (! pictureEnabled || audioEnabled) return;
1009 if (info) destroyInfo();
1010 if (! currentPicture) return;
1013 info->setTitleText(currentPicture->getFileName());
1014 info->setDropThrough();
1015 info->setSize(500, 300);
1016 info->createBuffer();
1017 info->setBorderOn(1);
1018 info->setTitleBarOn(1);
1020 if (Video::getInstance()->getFormat() == Video::PAL)
1021 info->setPosition(100, 180);
1023 info->setPosition(100, 150);
1025 char tbuf[Media::TIMEBUFLEN];
1026 //modes should come from mediaoptions...
1027 const char *mode=NULL;
1028 switch (currentControl->mode) {
1029 case WJpegComplex::CROPPERCENT:
1032 case WJpegComplex::LETTER:
1039 const char *dirname=parent->getDirname(MEDIA_TYPE_PICTURE);
1041 const char *prfx="";
1042 if (dirname) ldir=strlen(dirname);
1044 dirname=dirname+ldir-35;
1047 SNPRINTF(buf,INFOBUF,"%s= %s%s\n%s= %u x %u\n%s= %lu kBytes\n%s= %s\n%s= %u\n%s= %u%%\n%s= %s",
1048 tr("Directory"), prfx,dirname,
1049 tr("Format(px)"),currentControl->picw,currentControl->pich,
1050 tr("Filesize"),currentControl->compressedSize/1000,
1051 tr("Time"),currentPicture->getTimeString(tbuf),
1052 tr("Rotation"),90*currentControl->finalRotation,
1053 tr("Scale"),currentControl->scale,
1054 tr("Picture Mode"),mode );
1055 info->setMainText(buf);
1057 BoxStack::getInstance()->add(info);
1058 BoxStack::getInstance()->update(info);
1059 Timers::getInstance()->setTimerD(this,3,8);
1061 void VMediaView::updatePictureInfo(){
1066 void VMediaView::destroyInfo(bool fromTimer){
1069 Log::getInstance()->log("VMediaView",Log::DEBUG,"remove info %p",info);
1070 BoxStack::getInstance()->remove(info);
1073 Log::getInstance()->log("VMediaView",Log::DEBUG,"trigger remove info %p",info);
1078 if (! fromTimer) Timers::getInstance()->cancelTimer(this,3);
1079 if (! fromTimer) Timers::getInstance()->cancelTimer(this,4);
1082 void VMediaView::sendViewMsg(Boxx *v) {
1083 Message* m = new Message();
1084 m->message = Message::CLOSE_ME;
1085 m->to = BoxStack::getInstance();
1087 m->parameter.num=(ULONG)v;
1088 Command::getInstance()->postMessageFromOuterSpace(m);
1090 void VMediaView::sendCommandMsg(int command) {
1091 Message* m = new Message();
1092 //we misuse PLAYER_EVENT here
1093 m->message = Message::PLAYER_EVENT;
1096 m->parameter.num = command;
1097 Command::getInstance()->postMessageFromOuterSpace(m);
1100 void VMediaView::enableBanner(bool enable) {
1101 bannerEnabled=false;
1102 updatePictureBanner();
1105 void VMediaView::getDrawingParam(Surface *&sfc,WJpegComplex::JpegControl *&c){
1106 if (secondSurface()) {
1107 //we currently display on sfc2
1116 void VMediaView::switchSurface(){
1117 if (secondSurface()) {
1118 //now we switch to sfc1
1120 currentControl=&ctl;
1124 currentControl=&ctl2;
1128 AudioPlayer * VMediaView::getPlayer(bool createIfNeeded)
1130 AudioPlayer* rt=AudioPlayer::getInstance(this,false);
1131 if (! createIfNeeded && rt == NULL) return NULL;
1133 rt=AudioPlayer::getInstance(this);
1139 bool VMediaView::isAudioPlaying() {
1140 Log::getInstance()->log("VMediaView::isPlaying", Log::DEBUG, "rt=%s", justPlaying?"true":"false");
1149 int VMediaView::play(bool all,bool activate,ULONG move,bool showInfo) {
1151 if (getPlayer(false)) getPlayer(false)->stop();
1153 if (currentAudio) delete currentAudio;
1156 currentAudio=parent->getMedia(MEDIA_TYPE_AUDIO,move);
1158 if ( ! currentAudio || ! currentAudio->getURI()) {
1159 Log::getInstance()->log("VMediaView::load", Log::ERR, "no URI in media");
1160 audioError=tr("no audio file");
1161 if (audioEnabled) sendCommandMsg(EVENT_DIRECTORYDONE);
1165 Log::getInstance()->log("VMediaView::load", Log::DEBUG, "filename=%s,p=%p",
1166 currentAudio->getURI()->getName(),this);
1167 int wseq=getPlayer()->play(currentAudio->getURI());
1168 if (getPlayer()->waitForSequence(5,wseq)<0) {
1169 audioError=tr("unable to open audio file");
1176 Log::getInstance()->log("VMediaView", Log::DEBUG, "player started for %s",currentAudio->getURI()->getName());
1178 if (activate && ! audioEnabled){
1179 if (showInfo) retriggerAudioInfo=true;
1183 //avoid duplicate creation of banner and info
1187 if (activate && (! currentPicture || ! pictureShowing)) draw();
1188 BoxStack::getInstance()->update(this);
1192 void VMediaView::showAudioInfo() {
1193 if (! audioEnabled) return;
1194 Timers::getInstance()->cancelTimer(this,4);
1195 Timers::getInstance()->cancelTimer(this,3);
1196 if (info) destroyInfo();
1197 if (! retriggerAudioInfo) return;
1199 bool playerError=getPlayer()->getState()==AudioPlayer::S_ERROR || audioError;
1200 if (! playerError) Timers::getInstance()->setTimerD(this,3,AUDIOBANNER_TIME);
1201 else Timers::getInstance()->setTimerD(this,3,AUDIOERROR_TIME);
1202 if (! playerError) Timers::getInstance()->setTimerD(this,4, 1);
1203 BoxStack::getInstance()->update(info);
1206 void VMediaView::updateAudioInfo() {
1212 void VMediaView::drawAudioInfo(){
1213 Log::getInstance()->log("VMediaView",Log::DEBUG, "draw banner for %p",info);
1214 const char *title=NULL;
1215 char *playerTitle=NULL;
1216 bool playerError=false;
1220 const char *pl=tr("Playlist");
1221 const char *first=NULL;
1222 char *playerInfo=NULL;
1224 if (getPlayer()->getState() == AudioPlayer::S_PLAY) audioError=NULL;
1226 if (! currentAudio && ! audioError) audioError=tr("no audio file");
1228 title=tr("MediaError");
1231 playerTitle=getPlayer()->getTitle();
1232 if (playerTitle) title=playerTitle;
1233 else title=currentAudio->getDisplayName();
1234 num=parent->getNumEntries(MEDIA_TYPE_AUDIO,currentAudio->index);
1235 playerError=getPlayer()->getState() == AudioPlayer::S_ERROR;
1236 //1more line for long dirs
1237 numlines=playall?5:4;
1241 first=tr("Unable to play audio file");
1242 len=strlen(first)+3;
1244 else if (audioError) {
1247 len=strlen(first)+3;
1250 playerInfo=getPlayer()->getID3Info();drawText(tr("Loading"),5,3,DrawStyle::LIGHTTEXT);
1251 len=strlen(currentAudio->getDisplayName())+strlen(pl)+30+strlen(parent->getDirname(MEDIA_TYPE_AUDIO))+Media::TIMEBUFLEN+110;
1253 for (UINT i=0;i<strlen(playerInfo);i++)
1254 if (playerInfo[i] == '\n') numlines++;
1255 len+=strlen(playerInfo);
1264 UINT height=numlines*30+60;
1265 UINT vheight=Video::getInstance()->getScreenHeight();
1266 UINT vwidth=Video::getInstance()->getScreenWidth();
1267 if (height > vheight-2*AUDIOBANNER_BOTTOM_MARGIN)
1268 height=vheight-2*AUDIOBANNER_BOTTOM_MARGIN;
1269 info->setSize(vwidth -2*AUDIOBANNER_X_MARGIN, height);
1270 info->createBuffer();
1271 if (Video::getInstance()->getFormat() == Video::PAL)
1273 info->setPosition(AUDIOBANNER_X_MARGIN, vheight-height-AUDIOBANNER_BOTTOM_MARGIN);
1277 info->setPosition(AUDIOBANNER_X_MARGIN, vheight-height-AUDIOBANNER_BOTTOM_MARGIN);
1280 info->setTitleBarOn(0);
1281 info->setDropThrough();
1283 //set the regions for the closcks and bars on banner
1284 barRegion.x = info->getWidth()-AUDIOBARLEN-20;
1285 barRegion.y = info->getHeight() - 30; // FIXME, need to be - 1? and below?
1286 barRegion.w = info->getWidth()-AUDIOBARLEN+10;
1289 clocksRegion.x = 130;
1290 clocksRegion.y = barRegion.y + 3;
1291 clocksRegion.w = 190;
1292 clocksRegion.h = getFontHeight();
1293 Log::getInstance()->log("VMediaView",Log::DEBUG,"created AudioInfo %p",info);
1294 BoxStack::getInstance()->add(info);
1295 char *buf=new char [len];
1296 if (playerError || audioError) {
1297 SNPRINTF(buf,len,"%s",first);
1300 char tbuf[Media::TIMEBUFLEN];
1302 SNPRINTF(buf,len,"%s\n"
1308 tr("FileName"),currentAudio->getDisplayName(),
1309 pl,num,parent->getNumEntries(MEDIA_TYPE_AUDIO),
1310 tr("Directory"),parent->getDirname(MEDIA_TYPE_AUDIO),
1311 tr("Time"),currentAudio->getTimeString(tbuf));
1314 SNPRINTF(buf,len,"%s\n"
1319 tr("FileName"),currentAudio->getDisplayName(),
1320 tr("Directory"),parent->getDirname(MEDIA_TYPE_AUDIO),
1321 tr("Time"),currentAudio->getTimeString(tbuf));
1324 Log::getInstance()->log("VMediaView",Log::DEBUG,"info: (%d)%s",strlen(buf),buf);
1325 //now the real drawing functions
1328 info->rectangle(0, 0, info->getWidth(), 30, DrawStyle::TITLEBARBACKGROUND);
1329 info->drawText(title, 5, 5, DrawStyle::LIGHTTEXT);
1330 info->drawPara(buf,5,32,DrawStyle::LIGHTTEXT);
1336 int ybottom=info->getHeight();
1337 info->rectangle(0, ybottom - barRegion.h, info->getWidth(), barRegion.h, DrawStyle::TITLEBARBACKGROUND);
1338 bool drawSymbol=true;
1339 switch(getPlayer()->getState()) {
1340 case AudioPlayer::S_PAUSE:
1341 w.nextSymbol = WSymbol::PAUSE;
1343 case AudioPlayer::S_PLAY:
1344 w.nextSymbol = WSymbol::PLAY;
1346 case AudioPlayer::S_DONE:
1348 w.nextSymbol = WSymbol::PLAY;
1352 case AudioPlayer::S_BACK:
1353 w.nextSymbol = WSymbol::FBWD ;
1355 case AudioPlayer::S_FF:
1356 w.nextSymbol = WSymbol::FFWD ;
1363 w.setPosition(x, ybottom-24);
1368 info->rectangle(x, ybottom - 23, 18, 16, DrawStyle::LIGHTTEXT);
1373 if (playerInfo) delete playerInfo;
1374 if (playerTitle) delete playerTitle;
1377 void VMediaView::drawAudioClocks() {
1378 if (! info || ! audioEnabled) return;
1379 Log::getInstance()->log("VMediaView::drawAudioClocks", Log::DEBUG, "");
1380 //draw clocks and bar
1381 info->rectangle(clocksRegion, DrawStyle::TITLEBARBACKGROUND);
1383 time_t currentSec = (time_t)(getPlayer()->getCurrentTimes());
1384 time_t lengthSec=(time_t)(getPlayer()->getSonglen());
1387 /* gmtime_r(¤tSec,&cpos);
1388 gmtime_r(&lengthSec,&slen);*/
1389 cpos.tm_hour=currentSec/3600;
1390 cpos.tm_min=(currentSec-cpos.tm_hour*3600)/60;
1391 cpos.tm_sec=(currentSec-cpos.tm_hour*3600-cpos.tm_min*60);
1392 slen.tm_hour=lengthSec/3600;;
1393 slen.tm_min=(lengthSec-slen.tm_hour*3600)/60;
1394 slen.tm_sec=(lengthSec-slen.tm_hour*3600-slen.tm_min*60);
1397 if (currentSec >= lengthSec)
1399 SNPRINTF(buffer,99, "-:--:-- / -:--:-- %03dk",getPlayer()->getCurrentBitrate()/1000);
1403 SNPRINTF(buffer, 99, "%01i:%02i:%02i / %01i:%02i:%02i %03dk", cpos.tm_hour, cpos.tm_min, cpos.tm_sec, slen.tm_hour, slen.tm_min, slen.tm_sec,
1404 getPlayer()->getCurrentBitrate()/1000);
1405 //Log::getInstance()->log("VMediaView", Log::DEBUG, buffer);
1408 info->drawText(buffer, clocksRegion.x, clocksRegion.y, DrawStyle::LIGHTTEXT);
1410 // Draw progress bar
1411 int progBarXbase = 0;
1414 info->rectangle(barRegion.x + progBarXbase, barRegion.y + 3, barlen+10, 24, DrawStyle::LIGHTTEXT);
1415 info->rectangle(barRegion.x + progBarXbase + 2, barRegion.y + 5, barlen+6, 20, barBlue);
1417 if (currentSec > lengthSec) currentSec=lengthSec;
1418 if (lengthSec == 0) return;
1420 // Draw yellow portion
1421 int progressWidth = (barlen+2) * currentSec / lengthSec;
1422 info->rectangle(barRegion.x + progBarXbase + 4, barRegion.y + 7, progressWidth, 16, DrawStyle::SELECTHIGHLIGHT);
1426 void VMediaView::showAudioBanner() {
1427 destroyAudioBanner();
1428 if (! audioEnabled) return;
1429 audioBanner=new VInfo();
1430 Log::getInstance()->log("VMediaView",Log::DEBUG,"creating AudioBanner %p", audioBanner);
1431 Video *v=Video::getInstance();
1432 audioBanner->setSize(v->getScreenWidth()-100, 36);
1433 audioBanner->createBuffer();
1434 audioBanner->setPosition(50, v->getScreenHeight()-50);
1435 audioBanner->fillColour(audioBannerBack);
1436 audioBanner->setTitleBarOn(0);
1437 audioBanner->setDropThrough();
1438 if ( ! currentAudio || ! currentAudio->getDisplayName() || audioError) {
1439 audioBanner->drawText(tr("AudioPlayer - not playing"),5,3,DrawStyle::LIGHTTEXT);
1442 char * buf=new char[strlen(currentAudio->getDisplayName())+50];
1443 SNPRINTF(buf,50,"%s %s",tr("AudioPlayer"),currentAudio->getDisplayName());
1444 audioBanner->drawText(buf,5,3,DrawStyle::LIGHTTEXT);
1447 BoxStack::getInstance()->add(audioBanner);
1448 BoxStack::getInstance()->update(audioBanner);
1451 void VMediaView::destroyAudioBanner() {
1453 Log::getInstance()->log("VMediaView",Log::DEBUG,"deleting AudioBanner %p",audioBanner);
1454 BoxStack::getInstance()->remove(audioBanner);