]> git.vomp.tv Git - vompclient.git/blob - vvideorec.cc
Vogel Media Player 2008-11-28
[vompclient.git] / vvideorec.cc
1 /*
2     Copyright 2004-2005 Chris Tallon
3
4     This file is part of VOMP.
5
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.
10
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.
15
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.
19 */
20
21 #include "vvideorec.h"
22
23 #include "command.h"
24 #include "osd.h"
25 #include "wsymbol.h"
26 #include "audio.h"
27 #include "vdr.h"
28 #include "video.h"
29 #include "timers.h"
30 #include "player.h"
31 #include "recording.h"
32 #include "vaudioselector.h"
33 #include "message.h"
34 #include "remote.h"
35 #include "boxstack.h"
36 #include "vinfo.h"
37 #include "i18n.h"
38 #include "bitmap.h"
39 #include "recinfo.h"
40 #include "log.h"
41  
42 VVideoRec::VVideoRec(Recording* rec)
43 {
44   boxstack = BoxStack::getInstance();
45   vdr = VDR::getInstance();
46   video = Video::getInstance();
47   timers = Timers::getInstance();
48   vas = NULL;
49   vsummary = NULL;
50
51   player = new Player(Command::getInstance(), this, this);
52   player->init();
53
54   videoMode = video->getMode();
55   myRec = rec;
56
57   playing = false;
58
59   startMargin = 0;
60   endMargin = 0;
61   char* cstartMargin = vdr->configLoad("Timers", "Start margin");
62   char* cendMargin = vdr->configLoad("Timers", "End margin");
63   if (!cstartMargin)
64   {
65     startMargin = 300; // 5 mins default
66   }
67   else
68   {
69     startMargin = atoi(cstartMargin) * 60;
70     delete[] cstartMargin;
71   }
72
73   if (!cendMargin)
74   {
75     endMargin = 300; // 5 mins default
76   }
77   else
78   {
79     endMargin = atoi(cendMargin) * 60;
80     delete[] cendMargin;
81   }
82
83   Log::getInstance()->log("VVideoRec", Log::DEBUG, "SM: %u EM: %u", startMargin, endMargin);
84
85   setSize(video->getScreenWidth(), video->getScreenHeight());
86   createBuffer();
87   transparent.set(0, 0, 0, 0);
88   setBackgroundColour(transparent);
89
90   barRegion.x = 0;
91   barRegion.y = video->getScreenHeight() - 58;   // FIXME, need to be - 1? and below?
92   barRegion.w = video->getScreenWidth();
93   barRegion.h = 58;
94
95   clocksRegion.x = barRegion.x + 140;
96   clocksRegion.y = barRegion.y + 12;
97   clocksRegion.w = 170;
98   clocksRegion.h = surface->getFontHeight();
99 //  barBlue.set(0, 0, 150, 150);
100   barBlue.set(0, 0, 0, 128);
101
102   barShowing = false;
103   barGenHold = false;
104   barScanHold = false;
105   barVasHold = false;
106
107   dowss = false;
108   char* optionWSS = vdr->configLoad("General", "WSS");
109   if (optionWSS)
110   {
111     if (strstr(optionWSS, "Yes")) dowss = true;
112     delete[] optionWSS;
113   }
114   Log::getInstance()->log("VVideoRec", Log::DEBUG, "Do WSS: %u", dowss);
115
116   if (dowss)
117   {
118     wss.setFormat(video->getFormat());
119     wss.setWide(true);
120     add(&wss);
121
122     wssRegion.x = 0;
123     wssRegion.y = 0;
124     wssRegion.w = video->getScreenWidth();
125     wssRegion.h = 300;
126   }
127 }
128
129 void VVideoRec::preDelete()
130 {
131   timers->cancelTimer(this, 1);
132   timers->cancelTimer(this, 2);
133
134   if (vas)
135   {
136     boxstack->remove(vas);
137     vas = NULL;
138   }
139
140   if (vsummary) delete vsummary;
141
142   if (playing) stopPlay();
143 }
144
145 VVideoRec::~VVideoRec()
146 {
147   Log::getInstance()->log("VVideoRec", Log::DEBUG, "Entering vvideorec destructor");
148
149   video->setDefaultAspect();
150
151   // kill recInfo in case resumePoint has changed (likely)
152   myRec->dropRecInfo();
153   // FIXME - do this properly - save the resume point back to the server manually and update
154   // rec->recInfo->resumePoint - this will fix the ~10s offset problem as well
155 }
156
157 void VVideoRec::go(bool resume)
158 {
159   ULONG startFrameNum;
160   if (resume)
161     startFrameNum = myRec->recInfo->resumePoint;
162   else
163     startFrameNum = 0;
164
165   Log::getInstance()->log("VVideoRec", Log::DEBUG, "Starting stream: %s at frame: %lu", myRec->getFileName(), startFrameNum);
166   ULONG lengthFrames = 0;
167   ULLONG lengthBytes = vdr->streamRecording(myRec->getFileName(), &lengthFrames);
168   if (lengthBytes)
169   {
170     player->setLengthBytes(lengthBytes);
171     player->setLengthFrames(lengthFrames);
172     player->setStartFrame(startFrameNum);
173     player->play();
174     playing = true;
175     doBar(0);
176   }
177   else
178   {
179     stopPlay(); // clean up
180
181     if (!vdr->isConnected())
182     {
183       Command::getInstance()->connectionLost();
184       return;
185     }
186
187     Message* m = new Message();
188     m->message = Message::CLOSE_ME;
189     m->from = this;
190     m->to = boxstack;
191     Command::getInstance()->postMessageNoLock(m);
192
193     VInfo* vi = new VInfo();
194     vi->setSize(400, 150);
195     vi->createBuffer();
196     if (video->getFormat() == Video::PAL)
197       vi->setPosition(170, 200);
198     else
199       vi->setPosition(160, 150);
200     vi->setExitable();
201     vi->setBorderOn(1);
202     vi->setTitleBarOn(0);
203     vi->setOneLiner(tr("Error playing recording"));
204     vi->draw();
205
206     m = new Message();
207     m->message = Message::ADD_VIEW;
208     m->to = boxstack;
209     m->parameter = (ULONG)vi;
210     Command::getInstance()->postMessageNoLock(m);
211   }
212 }
213
214 int VVideoRec::handleCommand(int command)
215 {
216   switch(command)
217   {
218     case Remote::PLAY:
219     {
220       player->play();
221       doBar(0);
222       return 2;
223     }
224
225     case Remote::BACK:
226     {
227       if (vsummary)
228       {
229         removeSummary();
230         return 2;
231       }
232     } // DROP THROUGH
233     case Remote::STOP:
234     case Remote::MENU:
235     {
236       if (playing) stopPlay();
237
238       return 4;
239     }
240     case Remote::PAUSE:
241     {
242       player->pause();
243       doBar(0);
244       return 2;
245     }
246     case Remote::SKIPFORWARD:
247     {
248       doBar(3);
249       player->skipForward(60);
250       return 2;
251     }
252     case Remote::SKIPBACK:
253     {
254       doBar(4);
255       player->skipBackward(60);
256       return 2;
257     }
258     case Remote::FORWARD:
259     {
260       player->fastForward();
261       doBar(0);
262       return 2;
263     }
264     case Remote::REVERSE:
265     {
266       player->fastBackward();
267       doBar(0);
268       return 2;
269     }
270     case Remote::RED:
271     {
272       if (vsummary) removeSummary();
273       else doSummary();
274       return 2;
275     }
276     case Remote::GREEN:
277     {
278       doAudioSelector();
279       return 2;
280     }
281     case Remote::YELLOW:
282     {
283       if (myRec->hasMarks())
284       {
285         // skip to previous mark
286         Log* logger = Log::getInstance();
287         int currentFrame = (player->getCurrentFrameNum()); // get current Frame
288         currentFrame -= 5 * video->getFPS(); // subtrack 5 seconds, else you cannot skip more than once back ..
289
290         int prevMark = myRec->getPrevMark(currentFrame); // find previous Frame
291         if (prevMark)
292         {
293           logger->log("VVideoRec", Log::NOTICE, "jump back from pos %i to mark at %i",currentFrame,prevMark);
294           player->jumpToMark(prevMark);
295         }
296         doBar(4);
297       }
298       else
299       {
300         doBar(2);
301         player->skipBackward(10);
302       }
303       return 2;
304     }
305     case Remote::BLUE:
306     {
307       if (myRec->hasMarks())
308       {
309         // skip to next mark
310         Log* logger = Log::getInstance();
311         int currentFrame = (player->getCurrentFrameNum());
312
313         int nextMark = myRec->getNextMark(currentFrame);
314
315         if (nextMark)
316         {
317           logger->log("VVideoRec", Log::NOTICE, "jump forward from pos %i to mark at %i",currentFrame,nextMark);
318           player->jumpToMark(nextMark);
319         }
320         doBar(3);
321       }
322       else
323       {
324         doBar(1);
325         player->skipForward(10);
326       }
327       return 2;
328     }
329     case Remote::STAR:
330     {
331       doBar(2);
332       player->skipBackward(10);
333       return 2;
334     }
335     case Remote::HASH:
336     {
337       doBar(1);
338       player->skipForward(10);
339       return 2;
340     }
341     case Remote::FULL:
342     case Remote::TV:
343     {
344       toggleChopSides();
345       return 2;
346     }
347
348     case Remote::OK:
349     {
350       if (vsummary)
351       {
352         removeSummary();
353         return 2;
354       }
355       
356       if (barShowing) removeBar();
357       else doBar(0);
358       return 2;
359     }
360
361     case Remote::ZERO:  player->jumpToPercent(0);  doBar(0);  return 2;
362     case Remote::ONE:   player->jumpToPercent(10); doBar(0);  return 2;
363     case Remote::TWO:   player->jumpToPercent(20); doBar(0);  return 2;
364     case Remote::THREE: player->jumpToPercent(30); doBar(0);  return 2;
365     case Remote::FOUR:  player->jumpToPercent(40); doBar(0);  return 2;
366     case Remote::FIVE:  player->jumpToPercent(50); doBar(0);  return 2;
367     case Remote::SIX:   player->jumpToPercent(60); doBar(0);  return 2;
368     case Remote::SEVEN: player->jumpToPercent(70); doBar(0);  return 2;
369     case Remote::EIGHT: player->jumpToPercent(80); doBar(0);  return 2;
370     case Remote::NINE:  player->jumpToPercent(90); doBar(0);  return 2;
371
372     case Remote::RECORD: player->toggleSubtitles(); return 2;
373 #ifdef DEV
374 //    case Remote::RED:
375 //    {
376       //Don't use RED for anything. It will eventually be recording summary
377
378       //player->test1();
379
380
381       /*
382       // for testing EPG in NTSC with a NTSC test video
383       Video::getInstance()->setMode(Video::QUARTER);
384       Video::getInstance()->setPosition(170, 5);
385       VEpg* vepg = new VEpg(NULL, 0);
386       vepg->draw();
387       BoxStack::getInstance()->add(vepg);
388       BoxStack::getInstance()->update(vepg);
389       */
390
391 //      return 2;
392 //    }
393
394 #endif
395
396   }
397
398   return 1;
399 }
400
401 void VVideoRec::processMessage(Message* m)
402 {
403   Log::getInstance()->log("VVideoRec", Log::DEBUG, "Message received");
404
405   if (m->message == Message::MOUSE_LBDOWN)
406   {
407     UINT x = (m->parameter>>16) - getScreenX();
408     UINT y = (m->parameter&0xFFFF) - getScreenY();
409
410     if (!barShowing)
411     {
412       BoxStack::getInstance()->handleCommand(Remote::OK); //simulate rok press
413     }
414     else if (barRegion.x<=x && barRegion.y<=y && (barRegion.x+barRegion.w)>=x && (barRegion.y+barRegion.h)>=y)
415     {
416       int progBarXbase = barRegion.x + 300;
417       if (myRec->hasMarks())
418       {
419         MarkList* markList = myRec->getMarkList();
420         MarkList::iterator i;
421         Mark* loopMark = NULL;
422         int posPix;
423         ULONG lengthFrames;
424         if (myRec->recInfo->timerEnd > time(NULL))
425         {
426           // chasing playback
427           // Work out an approximate length in frames (good to 1s...)
428           lengthFrames = (myRec->recInfo->timerEnd - myRec->recInfo->timerStart) * video->getFPS();
429         }
430         else
431         {
432           lengthFrames = player->getLengthFrames();
433         }
434         for(i = markList->begin(); i != markList->end(); i++)
435         {
436           loopMark = *i;
437           if (loopMark->pos)
438           {
439             posPix = 302 * loopMark->pos / lengthFrames;
440             rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 3, 28, Colour::DANGER);
441             if (x>=barRegion.x + progBarXbase + 2 + posPix
442                 && x<=barRegion.x + progBarXbase + 2 + posPix+3
443                 && y>=barRegion.y + 12 - 2
444                 && y<=barRegion.y + 12 - 2+28)
445             {
446               player->jumpToMark(loopMark->pos);
447               doBar(3);
448               return;
449             }
450           }
451         }
452       }
453
454       if (x>=barRegion.x + progBarXbase + 24
455           && x<=barRegion.x + progBarXbase + 4 + 302
456           && y>=barRegion.y + 12 - 2
457           && y<=barRegion.y + 12 - 2+28)
458       {
459         int cx=x-(barRegion.x + progBarXbase + 4);
460         double percent=((double)cx)/302.*100.;
461         player->jumpToPercent(percent);
462         doBar(3);
463         return;
464         //  int progressWidth = 302 * currentFrameNum / lengthFrames;
465         //  rectangle(barRegion.x + progBarXbase + 4, barRegion.y + 16, progressWidth, 16, Colour::SELECTHIGHLIGHT);
466       }
467     }
468     else
469     {
470       BoxStack::getInstance()->handleCommand(Remote::OK); //simulate rok press
471     }
472   }
473   else if (m->from == player)
474   {
475     if (m->message != Message::PLAYER_EVENT) return;
476     switch(m->parameter)
477     {
478       case Player::CONNECTION_LOST: // connection lost detected
479       {
480         // I can't handle this, send it to command
481         Message* m2 = new Message();
482         m2->to = Command::getInstance();
483         m2->message = Message::CONNECTION_LOST;
484         Command::getInstance()->postMessageNoLock(m2);
485         break;
486       }
487       case Player::STOP_PLAYBACK:
488       {
489         // FIXME Obselete ish - improve this
490         Message* m2 = new Message(); // Must be done after this thread finishes, and must break into master mutex
491         m2->to = Command::getInstance();
492         m2->message = Message::STOP_PLAYBACK;
493         Command::getInstance()->postMessageNoLock(m2);
494         break;
495       }
496       case Player::ASPECT43:
497       {
498         if (dowss)
499         {
500           Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 43");
501           wss.setWide(false);
502           wss.draw();
503           boxstack->update(this, &wssRegion);
504         }
505         break;
506       }
507       case Player::ASPECT169:
508       {
509         if (dowss)
510         {
511           Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 169");
512           wss.setWide(true);
513           wss.draw();
514           boxstack->update(this, &wssRegion);
515         }
516         break;
517       }
518     }
519   }
520   else if (m->message == Message::AUDIO_CHANGE_CHANNEL)
521   {
522     Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received change audio channel to %i", m->parameter);
523     player->setAudioChannel(m->parameter&0xFFFF,(m->parameter&0xFF0000)>> 16 );
524   }
525   else if (m->message == Message::CHILD_CLOSE)
526   {
527     if (m->from == vas)
528     {
529       vas = NULL;
530       barVasHold = false;
531       if (!barGenHold && !barScanHold && !barVasHold) removeBar();
532     }
533   }
534 }
535
536 void VVideoRec::stopPlay()
537 {
538   Log::getInstance()->log("VVideoRec", Log::DEBUG, "Pre stopPlay");
539
540   removeBar();
541   Log::getInstance()->log("VVideoRec", Log::DEBUG, "1");
542   player->stop();
543   Log::getInstance()->log("VVideoRec", Log::DEBUG, "2");
544   vdr->stopStreaming();
545   Log::getInstance()->log("VVideoRec", Log::DEBUG, "3");
546   delete player;
547
548   playing = false;
549
550   if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
551   Log::getInstance()->log("VVideoRec", Log::DEBUG, "Post stopPlay");
552 }
553
554 void VVideoRec::toggleChopSides()
555 {
556   if (video->getTVsize() == Video::ASPECT16X9) return; // Means nothing for 16:9 TVs
557
558   if (videoMode == Video::NORMAL)
559   {
560     videoMode = Video::LETTERBOX;
561     video->setMode(Video::LETTERBOX);
562   }
563   else
564   {
565     videoMode = Video::NORMAL;
566     video->setMode(Video::NORMAL);
567   }
568 }
569
570 void VVideoRec::doAudioSelector()
571 {
572   bool* availableMpegAudioChannels = player->getDemuxerMpegAudioChannels();
573   bool* availableAc3AudioChannels = 0;
574   int currentAudioChannel = player->getCurrentAudioChannel();
575   if (Audio::getInstance()->supportsAc3())
576   {
577       availableAc3AudioChannels = player->getDemuxerAc3AudioChannels();
578   }
579
580   vas = new VAudioSelector(this, availableMpegAudioChannels, availableAc3AudioChannels, currentAudioChannel, myRec->recInfo);
581   vas->setBackgroundColour(barBlue);
582   vas->setPosition(0, barRegion.y - 120);
583
584 // pal 62, ntsc 57
585
586   barVasHold = true;
587   doBar(0);
588
589   vas->draw();
590   boxstack->add(vas);
591   boxstack->update(vas);
592 }
593
594 void VVideoRec::doBar(int action)
595 {
596   barShowing = true;
597
598   rectangle(barRegion, barBlue);
599
600   /* Work out what to display - choices:
601
602   Playing  >
603   Paused   ||
604   FFwd     >>
605   FBwd     <<
606
607   Specials, informed by parameter
608
609   Skip forward 10s    >|
610   Skip backward 10s   |<
611   Skip forward 1m     >>|
612   Skip backward 1m    |<<
613
614   */
615
616   WSymbol w;
617   TEMPADD(&w);
618   w.nextSymbol = 0;
619   w.setPosition(barRegion.x + 66, barRegion.y + 16);
620
621   UCHAR playerState = 0;
622
623   if (action)
624   {
625     if (action == 1)       w.nextSymbol = WSymbol::SKIPFORWARD;
626     else if (action == 2)  w.nextSymbol = WSymbol::SKIPBACK;
627     else if (action == 3)  w.nextSymbol = WSymbol::SKIPFORWARD2;
628     else if (action == 4)  w.nextSymbol = WSymbol::SKIPBACK2;
629   }
630   else
631   {
632     playerState = player->getState();
633     if (playerState == Player::S_PAUSE_P)      w.nextSymbol = WSymbol::PAUSE;
634     else if (playerState == Player::S_PAUSE_I) w.nextSymbol = WSymbol::PAUSE;
635     else if (playerState == Player::S_FFWD)    w.nextSymbol = WSymbol::FFWD;
636     else if (playerState == Player::S_FBWD)    w.nextSymbol = WSymbol::FBWD;
637     else                                       w.nextSymbol = WSymbol::PLAY;
638   }
639
640   w.draw();
641
642   if ((playerState == Player::S_FFWD) || (playerState == Player::S_FBWD))
643   {
644     // draw blips to show how fast the scan is
645     UCHAR scanrate = player->getIScanRate();
646     if (scanrate >= 2)
647     {
648       char text[5];
649       SNPRINTF(text, 5, "%ux", scanrate);
650       drawText(text, barRegion.x + 102, barRegion.y + 12, Colour::LIGHTTEXT);
651     }
652   }
653
654   drawBarClocks();
655
656   boxstack->update(this, &barRegion);
657
658   timers->cancelTimer(this, 1);
659
660
661   if ((playerState == Player::S_FFWD) || (playerState == Player::S_FBWD)) barScanHold = true;
662   else barScanHold = false;
663
664   if (!barGenHold && !barScanHold && !barVasHold) timers->setTimerD(this, 1, 4);
665
666   timers->setTimerD(this, 2, 0, 200000000);
667 }
668
669 void VVideoRec::timercall(int clientReference)
670 {
671   switch(clientReference)
672   {
673     case 1:
674     {
675       // Remove bar
676       removeBar();
677       break;
678     }
679     case 2:
680     {
681       // Update clock
682       if (!barShowing) break;
683       drawBarClocks();
684       boxstack->update(this, &barRegion);
685       
686       timers->setTimerD(this, 2, 0, 200000000);
687       break;
688     }
689   }
690 }
691
692 void VVideoRec::drawBarClocks()
693 {
694   if (barScanHold)
695   {
696     UCHAR playerState = player->getState();
697     // sticky bar is set if we are in ffwd/fbwd mode
698     // if player has gone to S_PLAY then kill stickyBar, and run doBar(0) which
699     // will repaint all the bar (it will call this function again, but
700     // this section won't run because stickyBarF will then == false)
701
702     if ((playerState != Player::S_FFWD) && (playerState != Player::S_FBWD))
703     {
704       barScanHold = false;
705       doBar(0);
706       return; // doBar will call this function and do the rest
707     }
708   }
709
710   Log* logger = Log::getInstance();
711   logger->log("VVideoRec", Log::DEBUG, "Draw bar clocks");
712
713   // Draw RTC
714   // Blank the area first
715   rectangle(barRegion.x + 624, barRegion.y + 12, 60, 30, barBlue);
716   char timeString[20];
717   time_t t;
718   time(&t);
719   struct tm* tms = localtime(&t);
720   strftime(timeString, 19, "%H:%M", tms);
721   drawText(timeString, barRegion.x + 624, barRegion.y + 12, Colour::LIGHTTEXT);
722
723   // Draw clocks
724
725   rectangle(clocksRegion, barBlue);
726
727   ULONG currentFrameNum = player->getCurrentFrameNum();
728   ULONG lengthFrames;
729   if (myRec->recInfo->timerEnd > time(NULL))
730   {
731     // chasing playback
732     // Work out an approximate length in frames (good to 1s...)
733     lengthFrames = (myRec->recInfo->timerEnd - myRec->recInfo->timerStart) * video->getFPS();
734   }
735   else
736   {
737     lengthFrames = player->getLengthFrames();
738   }
739
740   hmsf currentFrameHMSF = video->framesToHMSF(currentFrameNum);
741   hmsf lengthHMSF = video->framesToHMSF(lengthFrames);
742
743   char buffer[100];
744   if (currentFrameNum >= lengthFrames)
745   {
746     strcpy(buffer, "-:--:-- / -:--:--");
747   }
748   else
749   {
750     SNPRINTF(buffer, 99, "%01i:%02i:%02i / %01i:%02i:%02i", currentFrameHMSF.hours, currentFrameHMSF.minutes, currentFrameHMSF.seconds, lengthHMSF.hours, lengthHMSF.minutes, lengthHMSF.seconds);
751     logger->log("VVideoRec", Log::DEBUG, buffer);
752   }
753
754   drawText(buffer, clocksRegion.x, clocksRegion.y, Colour::LIGHTTEXT);
755
756
757
758
759
760
761
762   // Draw progress bar
763   int progBarXbase = barRegion.x + 300;
764
765   rectangle(barRegion.x + progBarXbase, barRegion.y + 12, 310, 24, Colour::LIGHTTEXT);
766   rectangle(barRegion.x + progBarXbase + 2, barRegion.y + 14, 306, 20, barBlue);
767
768   if (currentFrameNum > lengthFrames) return;
769   if (lengthFrames == 0) return;
770
771   // Draw yellow portion
772   int progressWidth = 302 * currentFrameNum / lengthFrames;
773   rectangle(barRegion.x + progBarXbase + 4, barRegion.y + 16, progressWidth, 16, Colour::SELECTHIGHLIGHT);
774
775   if (myRec->recInfo->timerEnd > time(NULL)) // if chasing
776   {
777     int nrWidth = (int)(302 * ((double)(lengthFrames - player->getLengthFrames()) / lengthFrames));
778
779     Log::getInstance()->log("GVASDF", Log::DEBUG, "Length Frames: %lu", lengthFrames);
780     Log::getInstance()->log("GVASDF", Log::DEBUG, "Player lf: %lu", player->getLengthFrames());
781     Log::getInstance()->log("GVASDF", Log::DEBUG, "NR WDITH: %i", nrWidth);
782     rectangle(barRegion.x + progBarXbase + 4 + 302 - nrWidth, barRegion.y + 16, nrWidth, 16, Colour::RED);
783   }
784
785   int posPix;
786   // Now calc position for blips
787
788   if (myRec->hasMarks())
789   {
790     // Draw blips where there are cut marks
791     MarkList* markList = myRec->getMarkList();
792     MarkList::iterator i;
793     Mark* loopMark = NULL;
794
795     for(i = markList->begin(); i != markList->end(); i++)
796     {
797       loopMark = *i;
798       if (loopMark->pos)
799       {
800         logger->log("VVideoRec", Log::DEBUG, "Drawing mark at frame %i", loopMark->pos);
801         posPix = 302 * loopMark->pos / lengthFrames;
802         rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 3, 28, Colour::DANGER);
803       }
804     }
805   }
806   else
807   {
808     // Draw blips where start and end margins probably are
809
810     posPix = 302 * startMargin * video->getFPS() / lengthFrames;
811
812     rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 2, 2, Colour::LIGHTTEXT);
813     rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 + 24, 2, 2, Colour::LIGHTTEXT);
814
815     posPix = 302 * (lengthFrames - endMargin * video->getFPS()) / lengthFrames;
816
817     rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 2, 2, Colour::LIGHTTEXT);
818     rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 + 24, 2, 2, Colour::LIGHTTEXT);
819   }
820 }
821
822 void VVideoRec::removeBar()
823 {
824   if (!barShowing) return;
825   timers->cancelTimer(this, 2);
826   barShowing = false;
827   barGenHold = false;
828   barScanHold = false;
829   barVasHold = false;
830   rectangle(barRegion, transparent);
831   boxstack->update(this, &barRegion);
832 }
833
834 void VVideoRec::doSummary()
835 {
836   vsummary = new VInfo();
837   vsummary->setTitleText(myRec->getProgName());
838   vsummary->setBorderOn(1);
839   vsummary->setExitable();
840   if (myRec->recInfo->summary) vsummary->setMainText(myRec->recInfo->summary);
841   else vsummary->setMainText(tr("Summary unavailable"));
842   if (Video::getInstance()->getFormat() == Video::PAL)
843   {
844     vsummary->setPosition(120, 130);
845   }
846   else
847   {
848     vsummary->setPosition(110, 90);
849   }
850   vsummary->setSize(510, 270);
851   add(vsummary);
852   vsummary->draw();
853
854   BoxStack::getInstance()->update(this);
855 }
856
857 void VVideoRec::removeSummary()
858 {
859   if (vsummary)
860   {
861     remove(vsummary);
862     delete vsummary;
863     vsummary = NULL;
864     draw();
865     BoxStack::getInstance()->update(this);
866   }
867 }
868
869 void VVideoRec::drawOSDBitmap(UINT posX, UINT posY, const Bitmap& bm)
870 {
871   drawBitmap(posX, posY, bm);
872   Region r;
873   r.x = posX; r.y = posY; r.w = bm.getWidth(); r.h = bm.getHeight();
874   boxstack->update(this, &r);
875 }
876
877 void VVideoRec::clearOSD()
878 {
879   rectangle(area, transparent);
880   boxstack->update(this, &area);
881 }
882
883 void VVideoRec::clearOSDArea(UINT posX, UINT posY, UINT width, UINT height)
884 {
885   Region r;
886   r.x = posX; r.y = posY; r.w = width; r.h = height;
887   rectangle(r, transparent);
888   boxstack->update(this, &r);
889 }