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, see <https://www.gnu.org/licenses/>.
22 #include "vmediaview.h"
24 #include "vpicturebanner.h"
25 #include "vcolourtuner.h"
26 #include "audioplayer.h"
28 #include "wselectlist.h"
39 #include "mediaoptions.h"
40 #include "mediaplayer.h"
42 #include "messagequeue.h"
44 const int VMediaView::EVENT_SLIDESHOW=100;
45 const int VMediaView::EVENT_DRAWINGDONE=101;
46 const int VMediaView::EVENT_DRAWINGERROR=102;
47 const int VMediaView::EVENT_DIRECTORYDONE=103;
51 * the combined user interface for pictures and audio
52 * has 2 surfaces to enable drawing in a separate thread
53 * the info display can either show a picture info or and audio info
54 * if the audio player comes on top it disables the picture info display
55 * basically we have 3 modes:
56 * - HIDDEN viewer is hidden (pictureEnabled=false, audioEnabled=false)
57 * if justPlaying=true the audioplayer is still running
58 * - PICTURE picture viewer on top ("slide show") - pictureEnabled=true, audioEnabled=false
59 * no AudioBanner visible
60 * if justPlaying=true the audio player runs in bg
61 * - AUDIO audioPlayer on top ("playlist mode") - pictureEnabled=true, audioEnabled=true
62 * the picture viewer is currently halted (should be able to continue if no AudioInfo)
63 * no picture banner (we should have an audio banner to indicate the audio player on top!)
64 * state transitions (via setPictureMode, setAudioMode)
65 * - show Picture -> pictureEnabled=true,
66 * only called from command handler if audioEnabled=false
67 * call from mediaList only possible if audioEnabled=false
68 * *** TODO: would be better to have separate function for external call/internal call
69 * - play [Audio] -> if activate is set -> audioEnabled=true (-> Mode AUDIO)
70 * used for calls from medialist
71 * internal calls do not set activate!
72 * - YELLOW key - toggle
73 * if audioActive==true -> audioActive=false (new mode depends on pictureEnabled - either HIDDEN or PICTURE)
74 * if audioActive==false -> audioActive=true (new mode AUDIO)
75 * *** open handling if no audio file there (ignore key???) - currently empty player
76 * - BACK if mode AUDIO -> audioEnabled=false, justPlaying=false
77 * - BACK if mode PICTURE -> pictureEnabled=false;
78 * - player StreamEnd -> audioEnabled=false (new mode depends on pciture - either HIDDEN or PICTURE)
79 * info/banner handling:
80 * - AudioInfo - alternativ to pictureInfo
81 * off when disabling audio or after timer or with OK in AUDIO mode
82 * on currently any command or player event (end/new song) when audioEnabled==true and retriggerAudioInfo=true
83 * on on OK in AUDIO mode
85 * off when disabling Picture or after timer, OK, green
86 * on only on green when pictureEnabled==true
88 * 2 modes: loading/normal
90 * off when disabling picture, OK, after timer
91 * on when enabling picture, with OK
93 * off when disabling picture and when loading done
95 * *** open: do not show when audio enabled and slide show running (currently slideshow is paused)
97 * always shown when audioEnabled=true
98 * on when enabling Audio
99 * off when disabling audio
101 * timers: 1 - slide show
104 * 4 - audio short update
107 #define DRAWING_THREAD
109 DrawStyle VMediaView::pictureBack=DrawStyle(140,140,140);
110 DrawStyle VMediaView::infoBack=DrawStyle(110,110,110);
111 DrawStyle VMediaView::audioBannerBack=DrawStyle(110,110,110,20);
114 //how long do we wait for a single picture chunk
115 //the unit is 100ms (the timeout on the server side)
117 class VPreader : public JpegReader {
124 VPreader(VMediaView *p,ImageReader *r){
130 virtual ULONG readChunk(ULONG offset,ULONG len,char ** buf) {
131 Log::getInstance()->log("VMediaView::jpegReader", Log::DEBUG, "read chunk o=%d,len=%d,buf=%p",
135 for (int trycount=0;trycount < MAXTRY && ! dobreak && numrec == 0 && rt == 0;trycount++) {
141 rt=reader->getImageChunk((ULLONG)offset,(UINT)len,&numrec,(UCHAR **)buf);
144 Log::getInstance()->log("VMediaView::jpegReader", Log::DEBUG, "got n=%d,buf=%p,rt=%d",
148 virtual int initRead(const MediaURI *uri,ULLONG *sz,ULONG factor=100) {
149 Log::getInstance()->log("VMediaView::jpegReader", Log::DEBUG, "load image %s",uri->getDisplayName());
150 Video* video = Video::getInstance();
152 int rt=MediaPlayer::getInstance()->openMedium(1,uri,sz,video->getScreenWidth()*factor/100, video->getScreenHeight()*factor/100);
155 Log::getInstance()->log("VMediaView::jpegReader", Log::DEBUG, "load image %s returned %llu",uri->getDisplayName(),size);
158 virtual ULONG getSize() {return size;}
159 //seems to be thread safe (more or less...)
166 * a separate thread for drawing pictures
167 * will be started with the sfc and the draw control
168 * will send a player event when done
170 class DrawingThread : public Thread_TYPE {
174 WJpegComplex::JpegControl *_ctl;
179 DrawingThread(VMediaView *parent) {
186 virtual ~DrawingThread(){}
188 return (threadIsActive()!=0);
190 bool start(WJpegComplex::JpegControl *ctl,Surface *sfc,VPreader *reader,DrawStyle &c) {
199 return (threadStart() == 1);
202 Log::getInstance()->log("DrawingThread",Log::DEBUG,"stop initiated");
203 if (threadIsActive()) {
205 if (_reader) _reader->setBreak();
208 Log::getInstance()->log("DrawingThread",Log::DEBUG,"stop done");
213 virtual void threadMethod() {
214 Log::getInstance()->log("DrawingThread",Log::DEBUG,"started");
215 bool rt=WJpegComplex::drawJpeg(_ctl,_sfc,_reader,_colour);
217 if (! _interrupted) {
218 Message* m = new Message();
219 //we misuse PLAYER_EVENT here
220 m->message = Message::PLAYER_EVENT;
223 m->parameter = rt?VMediaView::EVENT_DRAWINGDONE:VMediaView::EVENT_DRAWINGERROR;
224 MessageQueue::getInstance()->postMessage(m);
226 Log::getInstance()->log("DrawingThread",Log::DEBUG,"finishing interrupt=%d",(int)_interrupted);
231 VMediaView::VMediaView(VMediaList *p)
233 Log::getInstance()->log("VMediaView::VMediaView", Log::DEBUG, "p=%p", this);
235 pictureEnabled=false;
237 ireader=new ImageReader(1,MediaPlayer::getInstance());
238 reader=new VPreader(this,ireader);
239 //the surface handling
240 Video* video = Video::getInstance();
241 setSize(video->getScreenWidth(), video->getScreenHeight());
245 //create the second surface
250 //disable the surface
259 pictureLoading=false;
262 showtime=INITIAL_SHOWTIME;
263 rotate=WJpegComplex::ROT_0;
265 options=MediaOptions::getInstance();
266 VColourTuner::initFactors();
267 int st=options->getIntOption("SlideShowInterval");
268 if (st > 0) showtime=st;
269 ctl.area.w=originalw;
270 ctl.area.h=originalh;
272 ctl.scaleafter=options->getIntOption("ScaleFactor");
273 const char * mode=options->getStringOption("PictureMode");
274 if (strcmp(mode,"clip") == 0) ctl.mode=WJpegComplex::CROP;
275 else if (strcmp(mode,"letter") == 0) ctl.mode=WJpegComplex::LETTER;
276 else if (strcmp(mode,"clipfactor") == 0) ctl.mode=WJpegComplex::CROPPERCENT;
277 ctl.scaleAmount=options->getIntOption("PictureSize");
278 if (ctl.scaleAmount < 10) ctl.scaleAmount=10;
279 if (ctl.scaleAmount > 200) ctl.scaleAmount=200;
282 //current control is the one used for DISPLAY (not the one for drawing - this is the other one)
283 //this is closely coupled to the surface - i.e. ctl is for sfc1, ctl2 for sfc2
286 pictureShowing=false;
290 barBlue.set(0, 0, 150, 150);
295 retriggerAudioInfo=false;
297 drawingThread=new DrawingThread(this);
300 VMediaView::~VMediaView()
302 Log::getInstance()->log("VMediaView::~VMediaView", Log::DEBUG, "p=%p,secondSfc=%s", this,(secondSurface()?"true":"false"));
303 destroyPictureBanner();
304 if (currentPicture) delete currentPicture;
305 Timers::getInstance()->cancelTimer(this,1);
306 Timers::getInstance()->cancelTimer(this,2);
307 Timers::getInstance()->cancelTimer(this,3);
308 Timers::getInstance()->cancelTimer(this,4);
309 Timers::getInstance()->cancelTimer(this,5);
311 destroyAudioBanner();
312 if (getPlayer(false)) {
313 AudioPlayer::getInstance(NULL,false)->shutdown();
315 if (currentAudio) delete currentAudio;
316 drawingThread->stop();
320 if (secondSurface()) {
328 MediaPlayer::getInstance()->closeMediaChannel(1);
329 MediaPlayer::getInstance()->closeMediaChannel(2);
330 Log::getInstance()->log("VMediaView::~VMediaView", Log::DEBUG, "done p=%p", this);
333 void VMediaView::setPictureMode(bool act) {
334 Log::getInstance()->log("VMediaView", Log::DEBUG, "set pictureMode %d p=%d, a=%d", (int)act,(int)pictureEnabled,(int)audioEnabled);
336 if ( ! pictureEnabled && ! audioEnabled) {
342 if (! pictureEnabled) {
343 //we newly enable the picture - so clear the screen
345 BoxStack::getInstance()->update(this);
346 if (slideshow) startSlideshow();
351 if ( pictureEnabled) {
352 destroyPictureBanner();
353 stopSlideshow(false);
354 #ifdef DRAWING_THREAD
355 drawingThread->stop();
357 if (! audioEnabled) {
365 pictureShowing=false;
370 //we can disable audio without automatically hiding us
371 //this will become strange - we are visible but do not handle
372 //keys - so if you call setAudioMode(false,false) be sure
373 //to call setAudioMode(false,true) afterwards
374 //it is only here to give the list a chance to start a new play
375 //when we call directoryDone
376 void VMediaView::setAudioMode(bool act,bool doHiding) {
377 Log::getInstance()->log("VMediaView", Log::DEBUG, "setAudioMode %d p=%d, a=%d", (int)act,(int)pictureEnabled,(int)audioEnabled);
379 if (! audioEnabled) {
380 if (! pictureEnabled) {
383 draw(); //empty screen if no picture
386 destroyPictureBanner();
398 destroyAudioBanner();
400 if (! pictureEnabled && doHiding) {
408 if (havePictureBanner && ! pictureBanner) showPictureBanner();
415 void VMediaView::draw()
417 Log::getInstance()->log("VMediaView::draw", Log::DEBUG, "pictureError=%s,p=%p", pictureError,this);
419 if (pictureShowing ) fillColour(pictureBack);
420 else fillColour(DrawStyle::BLACK);
422 drawText(pictureError,100,area.h/2,DrawStyle::LIGHTTEXT);
428 int VMediaView::handleCommand(int command)
430 Log::getInstance()->log("VMediaView::handleCommand", Log::DEBUG, "cmd=%d,p=%p", command,this);
431 if ( !audioEnabled && ! pictureEnabled ) {
433 if (command == Input::YELLOW) {
439 if ( ! audioEnabled) {
440 //------------------------- command in mode PICTURE (i.e. picture is on top) ----------------
446 case Input::SKIPBACK:
447 rotate=WJpegComplex::ROT_0;
448 showPicture(VMediaList::MV_PREV,slideshow,true);
452 if (showtime > 1) showtime--;
453 updatePictureBanner(true);
456 case Input::SKIPFORWARD:
457 rotate=WJpegComplex::ROT_0;
458 showPicture(VMediaList::MV_NEXT,slideshow,true);
462 if (showtime < 50 ) showtime++;
463 updatePictureBanner(true);
468 destroyPictureBanner();
470 havePictureBanner=false;
473 havePictureBanner=true;
474 showPictureBanner(pictureLoading);
482 rotate=WJpegComplex::ROT_0;
483 showPicture(VMediaList::MV_NEXT,slideshow,true);
490 updatePictureBanner();
494 rotate=WJpegComplex::ROT_0;
495 showPicture(VMediaList::MV_NEXT,slideshow,true);
501 showtime=INITIAL_SHOWTIME;
502 updatePictureBanner();
507 case WJpegComplex::ROT_0:
508 rotate=WJpegComplex::ROT_90;
510 case WJpegComplex::ROT_90:
511 rotate=WJpegComplex::ROT_180;
513 case WJpegComplex::ROT_180:
514 rotate=WJpegComplex::ROT_270;
516 case WJpegComplex::ROT_270:
517 rotate=WJpegComplex::ROT_0;
520 showPicture(VMediaList::MV_NONE,slideshow,true);
524 if (info) destroyInfo();
525 else showPictureInfo();
530 case WJpegComplex::CROP:
531 cropmode=WJpegComplex::LETTER;
533 case WJpegComplex::LETTER:
534 cropmode=WJpegComplex::CROPPERCENT;
537 cropmode=WJpegComplex::CROP;
540 showPicture(VMediaList::MV_NONE,slideshow,true);
545 destroyPictureBanner();
547 VColourTuner *ct=new VColourTuner();
548 BoxStack::getInstance()->add(ct);
550 BoxStack::getInstance()->update(ct);
556 setPictureMode(false);
570 bool updateInfo=false;
571 //------------------------- command in mode AUDIO (i.e. audio is on top) ----------------
579 play(playall,false,VMediaList::MV_PREV);
583 if (! audioError) getPlayer()->fastForward();
588 play(playall,false,VMediaList::MV_NEXT);
591 case Input::SKIPFORWARD:
592 if (! audioError) getPlayer()->skipForward(10);
595 case Input::SKIPBACK:
596 if (! audioError) getPlayer()->skipBackward(10);
603 if (! audioError) getPlayer()->jumpToPercent(0);
607 if (! audioError) getPlayer()->jumpToPercent(10);
611 if (! audioError) getPlayer()->jumpToPercent(20);
615 if (! audioError) getPlayer()->jumpToPercent(30);
619 if (! audioError) getPlayer()->jumpToPercent(40);
623 if (! audioError) getPlayer()->jumpToPercent(50);
627 if (! audioError) getPlayer()->jumpToPercent(60);
631 if (! audioError) getPlayer()->jumpToPercent(70);
635 if (! audioError) getPlayer()->jumpToPercent(80);
639 if (! audioError) getPlayer()->jumpToPercent(90);
647 retriggerAudioInfo=false;
650 retriggerAudioInfo=true;
653 if (getPlayer()->getState() == AudioPlayer::S_ERROR) {
654 if (playall) play(playall,false,VMediaList::MV_NEXT);
661 if (! audioError) getPlayer()->unpause();
663 if (getPlayer()->getState() != AudioPlayer::S_ERROR) ;
664 else if (playall) play(playall,false,VMediaList::MV_NEXT);
669 if (! audioError) getPlayer()->pause();
683 retriggerAudioInfo=false;
686 if (! pictureShowing) setPictureMode(false); //could have been delayed
691 if (audioEnabled && updateInfo) updateAudioInfo();
696 void VMediaView::processMessage(Message* m)
698 Log::getInstance()->log("VMediaView::processMessage", Log::DEBUG, "cmd=%lu,p=%lu", m->message,m->parameter);
699 if (m->message == Message::MOUSE_MOVE)
703 else if (m->message == Message::MOUSE_LBDOWN)
705 if (coordsOutsideBox(m))
707 BoxStack::getInstance()->handleCommand(Input::BACK); //simulate cancel press
710 else if (m->message = Message::PLAYER_EVENT) {
711 switch (m->parameter) {
712 case EVENT_SLIDESHOW:
713 if (! pictureEnabled) break; //old timer msg...
714 //if (! audioEnabled) {
717 rotate=WJpegComplex::ROT_0;
718 showPicture(VMediaList::MV_NEXT,true,false);
723 case EVENT_DRAWINGERROR:
726 case EVENT_DRAWINGDONE:
729 case EVENT_DIRECTORYDONE:
730 //just disable audio without (poetntially) hiding us
731 //this gives the list a chance to decide whether audio
732 //should be on top afterwards without showing the list
734 setAudioMode(false,false);
735 parent->directoryDone();
736 if (! pictureShowing) setPictureMode(false);
737 if (! justPlaying) setAudioMode(false);
739 case AudioPlayer::STREAM_ERR:
740 case AudioPlayer::STREAM_END:
741 if (playall) play(playall,false,VMediaList::MV_NEXT);
747 case AudioPlayer::SHORT_UPDATE:
748 if (info && audioEnabled ) {
750 BoxStack::getInstance()->update(info,&clocksRegion);
751 BoxStack::getInstance()->update(info,&barRegion);
752 Timers::getInstance()->setTimerD(this, 4, 1);
755 case AudioPlayer::NEW_SONG:
756 if (audioEnabled) updateAudioInfo();
758 case AudioPlayer::CONNECTION_LOST:
759 if (audioEnabled) destroyInfo();
760 if (AudioPlayer *player=getPlayer(false)) {
764 Command::getInstance()->connectionLost();
771 VMediaView * VMediaView::createViewer(VMediaList * mparent) {
772 Log::getInstance()->log("VMediaView::createViewer", Log::DEBUG, "p=%p",
774 VMediaView *vmn=new VMediaView(mparent);
775 BoxStack::getInstance()->add(vmn);
777 BoxStack::getInstance()->update(vmn);
781 void VMediaView::startSlideshow() {
783 if (! pictureLoading) Timers::getInstance()->setTimerD(this,1,showtime);
786 void VMediaView::stopSlideshow(bool hard) {
787 if (hard) slideshow=false;
788 Timers::getInstance()->cancelTimer(this,1);
792 void VMediaView::showPicture(ULONG move,bool bslideshow,bool activateBanner) {
794 setPictureMode(true);
796 #ifdef DRAWING_THREAD
797 drawingThread->stop();
799 slideshow=bslideshow;
800 Media *newPicture=parent->getMedia(MEDIA_TYPE_PICTURE,move);
802 pictureShowing=false;
804 //within the event handler first directoryDone is called
805 //and afterwards everything is stopped if nothing new
806 sendCommandMsg(EVENT_DIRECTORYDONE);
813 if (currentPicture) {
814 delete currentPicture;
817 currentPicture=newPicture;
818 loadPicture(currentPicture,activateBanner);
822 //the real picture drawing method
823 //will start drawing on a new surface and will switch it wehn done
825 int VMediaView::loadPicture(Media *md,bool activateBanner) {
828 if (! md->getURI()) {
829 pictureError=tr("No media found");
830 Log::getInstance()->log("VMediaView::load",Log::ERR,"no URI in media");
833 Log::getInstance()->log("VMediaView::load", Log::DEBUG, "filename=%s,p=%p",
834 md->getURI()->getName(),this);
835 //do we have a pictureBanner?
836 havePictureBanner=pictureBanner!=NULL || activateBanner;
838 #ifdef DRAWING_THREAD
839 if (!audioEnabled && havePictureBanner ) showPictureBanner(true);
840 drawingThread->stop();
842 showPictureBanner(true);
846 int rtok=reader->initRead(md->getURI(),&size,ctl.scaleAmount); //scaleAmount is the same for both...
848 //now we can really draw
849 //get the surface for drawing
850 Surface * drawSurface=NULL;
851 WJpegComplex::JpegControl *drawCtl=NULL;
852 getDrawingParam(drawSurface,drawCtl);
854 drawCtl->rotation=rotate;
855 drawCtl->mode=cropmode;
856 drawCtl->compressedSize=size;
857 #ifdef DRAWING_THREAD
858 bool ok=drawingThread->start(drawCtl,drawSurface,reader,pictureBack);
860 Log::getInstance()->log("VMediaView::load", Log::ERR, "unable to start drawing thread");
861 pictureError=tr("JpegError");
862 pictureLoading=false;
863 destroyPictureBanner();
868 //here we could hand this over to the drawing thread
869 bool ok=WJpegComplex::drawJpeg(drawCtl,drawSurface,reader,pictureBack);
874 pictureLoading=false;
878 void VMediaView::drawingDone(bool hasError) {
879 pictureLoading=false;
880 destroyPictureBanner(); //disable loading indication (or real banner)
883 Log::getInstance()->log("VMediaView::drawingDone", Log::DEBUG, "success: sfc now=%p",surface);
885 //only show the pictureBanner if it was there before
886 if (havePictureBanner && ! audioEnabled) showPictureBanner();
887 Log::getInstance()->log("VMediaView::load", Log::DEBUG, "success" );
888 updatePictureInfo(); //will only do somethng if pictureEnabled
892 pictureError=tr("JpegError");
893 if (pictureEnabled) {
898 MediaPlayer::getInstance()->closeMediaChannel(1);
899 #ifndef DRAWING_THREAD
900 if (audioEnabled) showAudioBanner();
902 if (slideshow) startSlideshow();
903 BoxStack::getInstance()->update(this);
906 void VMediaView::showPictureBanner(bool loading) {
907 //we are in the main thread - so we can (and must) safely hard destroy/create the banner
908 Timers::getInstance()->cancelTimer(this,2);
909 if (! currentPicture) {
911 destroyPictureBanner(false);
914 if (pictureBanner) destroyPictureBanner(false);
915 if (! pictureEnabled || ! bannerEnabled) return;
916 pictureBanner= new VPictureBanner(loading, slideshow);
917 pictureBanner->fillColour(infoBack);
919 int len=strlen(currentPicture->getFileName())+Media::TIMEBUFLEN+20;
920 char *buf=new char[len];
921 char tbuf[Media::TIMEBUFLEN];
922 SNPRINTF(buf,len,"%c%02ds%c %s %s " ,
926 currentPicture->getTimeString(tbuf),
927 currentPicture->getFileName()
929 pictureBanner->setText(buf);
933 char *buf=new char[strlen(currentPicture->getDisplayName())+50];
934 SNPRINTF(buf,50,"%s %s",tr("Loading"), currentPicture->getDisplayName());
935 pictureBanner->setText(buf);
938 pictureBanner->draw();
939 if (! loading ) Timers::getInstance()->setTimerD(this,2,8);
940 BoxStack::getInstance()->add(pictureBanner);
941 BoxStack::getInstance()->update(pictureBanner);
944 void VMediaView::destroyPictureBanner(bool fromTimer) {
946 if (fromTimer) sendViewMsg(pictureBanner);
947 else BoxStack::getInstance()->remove(pictureBanner);
949 if (! fromTimer) Timers::getInstance()->cancelTimer(this,2);
952 void VMediaView::updatePictureBanner(bool loading) {
953 if (pictureBanner ) {
954 showPictureBanner(loading);
957 void VMediaView::timercall(int clientref) {
958 Log::getInstance()->log("VMediaView::timercall", Log::DEBUG, "id=%d",clientref);
963 sendCommandMsg(AudioPlayer::SHORT_UPDATE);
968 Log::getInstance()->log("VMediaView::timercall", Log::DEBUG, "infoEnd");
971 //we only did show the audio error info if audio is enabled
972 bool stillError=false;
973 if (AudioPlayer * player=getPlayer(false)) {
974 stillError=player->getState()==AudioPlayer::S_ERROR;
977 sendCommandMsg(AudioPlayer::STREAM_END);
983 if (! slideshow) return;
984 Log::getInstance()->log("VMediaView::timercall", Log::DEBUG, "slideshow");
985 sendCommandMsg(EVENT_SLIDESHOW);
988 Log::getInstance()->log("VMediaView::timercall", Log::DEBUG, "pictureBannerEnd");
989 destroyPictureBanner(true);
996 void VMediaView::showPictureInfo(){
997 if (! pictureEnabled || audioEnabled) return;
998 if (info) destroyInfo();
999 if (! currentPicture) return;
1002 info->setTitleText(currentPicture->getFileName());
1003 info->setDropThrough();
1004 info->setSize(500, 300);
1005 info->createBuffer();
1006 info->setBorderOn(1);
1007 info->setTitleBarOn(1);
1009 if (Video::getInstance()->getFormat() == Video::PAL)
1010 info->setPosition(100, 180);
1012 info->setPosition(100, 150);
1014 char tbuf[Media::TIMEBUFLEN];
1015 //modes should come from mediaoptions...
1016 const char *mode=NULL;
1017 switch (currentControl->mode) {
1018 case WJpegComplex::CROPPERCENT:
1021 case WJpegComplex::LETTER:
1028 const char *dirname=parent->getDirname(MEDIA_TYPE_PICTURE);
1030 const char *prfx="";
1031 if (dirname) ldir=strlen(dirname);
1033 dirname=dirname+ldir-35;
1036 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",
1037 tr("Directory"), prfx,dirname,
1038 tr("Format(px)"),currentControl->picw,currentControl->pich,
1039 tr("Filesize"),currentControl->compressedSize/1000,
1040 tr("Time"),currentPicture->getTimeString(tbuf),
1041 tr("Rotation"),90*currentControl->finalRotation,
1042 tr("Scale"),currentControl->scale,
1043 tr("Picture Mode"),mode );
1044 info->setMainText(buf);
1046 BoxStack::getInstance()->add(info);
1047 BoxStack::getInstance()->update(info);
1048 Timers::getInstance()->setTimerD(this,3,8);
1050 void VMediaView::updatePictureInfo(){
1055 void VMediaView::destroyInfo(bool fromTimer){
1058 Log::getInstance()->log("VMediaView",Log::DEBUG,"remove info %p",info);
1059 BoxStack::getInstance()->remove(info);
1062 Log::getInstance()->log("VMediaView",Log::DEBUG,"trigger remove info %p",info);
1067 if (! fromTimer) Timers::getInstance()->cancelTimer(this,3);
1068 if (! fromTimer) Timers::getInstance()->cancelTimer(this,4);
1071 void VMediaView::sendViewMsg(Boxx *v) {
1072 Message* m = new Message();
1073 m->message = Message::CLOSE_ME;
1074 m->to = BoxStack::getInstance();
1076 m->parameter=(ULONG)v;
1077 MessageQueue::getInstance()->postMessage(m);
1079 void VMediaView::sendCommandMsg(int command) {
1080 Message* m = new Message();
1081 //we misuse PLAYER_EVENT here
1082 m->message = Message::PLAYER_EVENT;
1085 m->parameter = command;
1086 MessageQueue::getInstance()->postMessage(m);
1089 void VMediaView::enableBanner(bool enable) {
1090 bannerEnabled=false;
1091 updatePictureBanner();
1094 void VMediaView::getDrawingParam(Surface *&sfc,WJpegComplex::JpegControl *&c){
1095 if (secondSurface()) {
1096 //we currently display on sfc2
1105 void VMediaView::switchSurface(){
1106 if (secondSurface()) {
1107 //now we switch to sfc1
1109 currentControl=&ctl;
1113 currentControl=&ctl2;
1117 AudioPlayer * VMediaView::getPlayer(bool createIfNeeded)
1119 AudioPlayer* rt=AudioPlayer::getInstance(this,false);
1120 if (! createIfNeeded && rt == NULL) return NULL;
1122 rt=AudioPlayer::getInstance(this);
1128 bool VMediaView::isAudioPlaying() {
1129 Log::getInstance()->log("VMediaView::isPlaying", Log::DEBUG, "rt=%s", justPlaying?"true":"false");
1138 int VMediaView::play(bool all,bool activate,ULONG move,bool showInfo) {
1140 if (getPlayer(false)) getPlayer(false)->stop();
1142 if (currentAudio) delete currentAudio;
1145 currentAudio=parent->getMedia(MEDIA_TYPE_AUDIO,move);
1147 if ( ! currentAudio || ! currentAudio->getURI()) {
1148 Log::getInstance()->log("VMediaView::load", Log::ERR, "no URI in media");
1149 audioError=tr("no audio file");
1150 if (audioEnabled) sendCommandMsg(EVENT_DIRECTORYDONE);
1154 Log::getInstance()->log("VMediaView::load", Log::DEBUG, "filename=%s,p=%p",
1155 currentAudio->getURI()->getName(),this);
1156 int wseq=getPlayer()->play(currentAudio->getURI());
1157 if (getPlayer()->waitForSequence(5,wseq)<0) {
1158 audioError=tr("unable to open audio file");
1165 Log::getInstance()->log("VMediaView", Log::DEBUG, "player started for %s",currentAudio->getURI()->getName());
1167 if (activate && ! audioEnabled){
1168 if (showInfo) retriggerAudioInfo=true;
1172 //avoid duplicate creation of banner and info
1176 if (activate && (! currentPicture || ! pictureShowing)) draw();
1177 BoxStack::getInstance()->update(this);
1181 void VMediaView::showAudioInfo() {
1182 if (! audioEnabled) return;
1183 Timers::getInstance()->cancelTimer(this,4);
1184 Timers::getInstance()->cancelTimer(this,3);
1185 if (info) destroyInfo();
1186 if (! retriggerAudioInfo) return;
1188 bool playerError=getPlayer()->getState()==AudioPlayer::S_ERROR || audioError;
1189 if (! playerError) Timers::getInstance()->setTimerD(this,3,AUDIOBANNER_TIME);
1190 else Timers::getInstance()->setTimerD(this,3,AUDIOERROR_TIME);
1191 if (! playerError) Timers::getInstance()->setTimerD(this,4, 1);
1192 BoxStack::getInstance()->update(info);
1195 void VMediaView::updateAudioInfo() {
1201 void VMediaView::drawAudioInfo(){
1202 Log::getInstance()->log("VMediaView",Log::DEBUG, "draw banner for %p",info);
1203 const char *title=NULL;
1204 char *playerTitle=NULL;
1205 bool playerError=false;
1209 const char *pl=tr("Playlist");
1210 const char *first=NULL;
1211 char *playerInfo=NULL;
1213 if (getPlayer()->getState() == AudioPlayer::S_PLAY) audioError=NULL;
1215 if (! currentAudio && ! audioError) audioError=tr("no audio file");
1217 title=tr("MediaError");
1220 playerTitle=getPlayer()->getTitle();
1221 if (playerTitle) title=playerTitle;
1222 else title=currentAudio->getDisplayName();
1223 num=parent->getNumEntries(MEDIA_TYPE_AUDIO,currentAudio->index);
1224 playerError=getPlayer()->getState() == AudioPlayer::S_ERROR;
1225 //1more line for long dirs
1226 numlines=playall?5:4;
1230 first=tr("Unable to play audio file");
1231 len=strlen(first)+3;
1233 else if (audioError) {
1236 len=strlen(first)+3;
1239 playerInfo=getPlayer()->getID3Info();drawText(tr("Loading"),5,3,DrawStyle::LIGHTTEXT);
1240 len=strlen(currentAudio->getDisplayName())+strlen(pl)+30+strlen(parent->getDirname(MEDIA_TYPE_AUDIO))+Media::TIMEBUFLEN+110;
1242 for (UINT i=0;i<strlen(playerInfo);i++)
1243 if (playerInfo[i] == '\n') numlines++;
1244 len+=strlen(playerInfo);
1253 UINT height=numlines*30+60;
1254 UINT vheight=Video::getInstance()->getScreenHeight();
1255 UINT vwidth=Video::getInstance()->getScreenWidth();
1256 if (height > vheight-2*AUDIOBANNER_BOTTOM_MARGIN)
1257 height=vheight-2*AUDIOBANNER_BOTTOM_MARGIN;
1258 info->setSize(vwidth -2*AUDIOBANNER_X_MARGIN, height);
1259 info->createBuffer();
1260 if (Video::getInstance()->getFormat() == Video::PAL)
1262 info->setPosition(AUDIOBANNER_X_MARGIN, vheight-height-AUDIOBANNER_BOTTOM_MARGIN);
1266 info->setPosition(AUDIOBANNER_X_MARGIN, vheight-height-AUDIOBANNER_BOTTOM_MARGIN);
1269 info->setTitleBarOn(0);
1270 info->setDropThrough();
1272 //set the regions for the closcks and bars on banner
1273 barRegion.x = info->getWidth()-AUDIOBARLEN-20;
1274 barRegion.y = info->getHeight() - 30; // FIXME, need to be - 1? and below?
1275 barRegion.w = info->getWidth()-AUDIOBARLEN+10;
1278 clocksRegion.x = 130;
1279 clocksRegion.y = barRegion.y + 3;
1280 clocksRegion.w = 190;
1281 clocksRegion.h = getFontHeight();
1282 Log::getInstance()->log("VMediaView",Log::DEBUG,"created AudioInfo %p",info);
1283 BoxStack::getInstance()->add(info);
1284 char *buf=new char [len];
1285 if (playerError || audioError) {
1286 SNPRINTF(buf,len,"%s",first);
1289 char tbuf[Media::TIMEBUFLEN];
1291 SNPRINTF(buf,len,"%s\n"
1297 tr("FileName"),currentAudio->getDisplayName(),
1298 pl,num,parent->getNumEntries(MEDIA_TYPE_AUDIO),
1299 tr("Directory"),parent->getDirname(MEDIA_TYPE_AUDIO),
1300 tr("Time"),currentAudio->getTimeString(tbuf));
1303 SNPRINTF(buf,len,"%s\n"
1308 tr("FileName"),currentAudio->getDisplayName(),
1309 tr("Directory"),parent->getDirname(MEDIA_TYPE_AUDIO),
1310 tr("Time"),currentAudio->getTimeString(tbuf));
1313 Log::getInstance()->log("VMediaView",Log::DEBUG,"info: (%d)%s",strlen(buf),buf);
1314 //now the real drawing functions
1317 info->rectangle(0, 0, info->getWidth(), 30, DrawStyle::TITLEBARBACKGROUND);
1318 info->drawText(title, 5, 5, DrawStyle::LIGHTTEXT);
1319 info->drawPara(buf,5,32,DrawStyle::LIGHTTEXT);
1325 int ybottom=info->getHeight();
1326 info->rectangle(0, ybottom - barRegion.h, info->getWidth(), barRegion.h, DrawStyle::TITLEBARBACKGROUND);
1327 bool drawSymbol=true;
1328 switch(getPlayer()->getState()) {
1329 case AudioPlayer::S_PAUSE:
1330 w.nextSymbol = WSymbol::PAUSE;
1332 case AudioPlayer::S_PLAY:
1333 w.nextSymbol = WSymbol::PLAY;
1335 case AudioPlayer::S_DONE:
1337 w.nextSymbol = WSymbol::PLAY;
1341 case AudioPlayer::S_BACK:
1342 w.nextSymbol = WSymbol::FBWD ;
1344 case AudioPlayer::S_FF:
1345 w.nextSymbol = WSymbol::FFWD ;
1352 w.setPosition(x, ybottom-24);
1357 info->rectangle(x, ybottom - 23, 18, 16, DrawStyle::LIGHTTEXT);
1362 if (playerInfo) delete playerInfo;
1363 if (playerTitle) delete playerTitle;
1366 void VMediaView::drawAudioClocks() {
1367 if (! info || ! audioEnabled) return;
1368 Log::getInstance()->log("VMediaView::drawAudioClocks", Log::DEBUG, "");
1369 //draw clocks and bar
1370 info->rectangle(clocksRegion, DrawStyle::TITLEBARBACKGROUND);
1372 time_t currentSec = (time_t)(getPlayer()->getCurrentTimes());
1373 time_t lengthSec=(time_t)(getPlayer()->getSonglen());
1376 /* gmtime_r(¤tSec,&cpos);
1377 gmtime_r(&lengthSec,&slen);*/
1378 cpos.tm_hour=currentSec/3600;
1379 cpos.tm_min=(currentSec-cpos.tm_hour*3600)/60;
1380 cpos.tm_sec=(currentSec-cpos.tm_hour*3600-cpos.tm_min*60);
1381 slen.tm_hour=lengthSec/3600;;
1382 slen.tm_min=(lengthSec-slen.tm_hour*3600)/60;
1383 slen.tm_sec=(lengthSec-slen.tm_hour*3600-slen.tm_min*60);
1386 if (currentSec >= lengthSec)
1388 SNPRINTF(buffer,99, "-:--:-- / -:--:-- %03dk",getPlayer()->getCurrentBitrate()/1000);
1392 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,
1393 getPlayer()->getCurrentBitrate()/1000);
1394 //Log::getInstance()->log("VMediaView", Log::DEBUG, buffer);
1397 info->drawText(buffer, clocksRegion.x, clocksRegion.y, DrawStyle::LIGHTTEXT);
1399 // Draw progress bar
1400 int progBarXbase = 0;
1403 info->rectangle(barRegion.x + progBarXbase, barRegion.y + 3, barlen+10, 24, DrawStyle::LIGHTTEXT);
1404 info->rectangle(barRegion.x + progBarXbase + 2, barRegion.y + 5, barlen+6, 20, barBlue);
1406 if (currentSec > lengthSec) currentSec=lengthSec;
1407 if (lengthSec == 0) return;
1409 // Draw yellow portion
1410 int progressWidth = (barlen+2) * currentSec / lengthSec;
1411 info->rectangle(barRegion.x + progBarXbase + 4, barRegion.y + 7, progressWidth, 16, DrawStyle::SELECTHIGHLIGHT);
1415 void VMediaView::showAudioBanner() {
1416 destroyAudioBanner();
1417 if (! audioEnabled) return;
1418 audioBanner=new VInfo();
1419 Log::getInstance()->log("VMediaView",Log::DEBUG,"creating AudioBanner %p", audioBanner);
1420 Video *v=Video::getInstance();
1421 audioBanner->setSize(v->getScreenWidth()-100, 36);
1422 audioBanner->createBuffer();
1423 audioBanner->setPosition(50, v->getScreenHeight()-50);
1424 audioBanner->fillColour(audioBannerBack);
1425 audioBanner->setTitleBarOn(0);
1426 audioBanner->setDropThrough();
1427 if ( ! currentAudio || ! currentAudio->getDisplayName() || audioError) {
1428 audioBanner->drawText(tr("AudioPlayer - not playing"),5,3,DrawStyle::LIGHTTEXT);
1431 char * buf=new char[strlen(currentAudio->getDisplayName())+50];
1432 SNPRINTF(buf,50,"%s %s",tr("AudioPlayer"),currentAudio->getDisplayName());
1433 audioBanner->drawText(buf,5,3,DrawStyle::LIGHTTEXT);
1436 BoxStack::getInstance()->add(audioBanner);
1437 BoxStack::getInstance()->update(audioBanner);
1440 void VMediaView::destroyAudioBanner() {
1442 Log::getInstance()->log("VMediaView",Log::DEBUG,"deleting AudioBanner %p",audioBanner);
1443 BoxStack::getInstance()->remove(audioBanner);