]> git.vomp.tv Git - vompclient.git/blob - vvideorec.cc
Stretch: libcec4 changes
[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 <math.h>
22
23 #include "vvideorec.h"
24 #include "vteletextview.h"
25
26 #include "command.h"
27 #include "osd.h"
28 #include "wsymbol.h"
29 #include "audio.h"
30 #include "vdr.h"
31 #include "video.h"
32 #include "timers.h"
33 #include "player.h"
34 #include "recording.h"
35 #include "vaudioselector.h"
36 #include "message.h"
37 #include "remote.h"
38 #include "boxstack.h"
39 #include "vinfo.h"
40 #include "i18n.h"
41 #include "bitmap.h"
42 #include "recinfo.h"
43 #include "log.h"
44 #include "channel.h"
45  
46 VVideoRec::VVideoRec(Recording* rec, bool ish264)
47 {
48   boxstack = BoxStack::getInstance();
49   vdr = VDR::getInstance();
50   video = Video::getInstance();
51   timers = Timers::getInstance();
52   vas = NULL;
53   vsummary = NULL;
54
55   videoMode = video->getMode();
56   myRec = rec;
57
58   video->seth264mode(ish264);
59
60   player = new Player(Command::getInstance(), this, this);
61   player->init(myRec->IsPesRecording,myRec->recInfo->fps);
62
63   playing = false;
64
65   startMargin = 0;
66   endMargin = 0;
67   char* cstartMargin = vdr->configLoad("Timers", "Start margin");
68   char* cendMargin = vdr->configLoad("Timers", "End margin");
69   if (!cstartMargin)
70   {
71     startMargin = 300; // 5 mins default
72   }
73   else
74   {
75     startMargin = atoi(cstartMargin) * 60;
76     delete[] cstartMargin;
77   }
78
79   if (!cendMargin)
80   {
81     endMargin = 300; // 5 mins default
82   }
83   else
84   {
85     endMargin = atoi(cendMargin) * 60;
86     delete[] cendMargin;
87   }
88
89   Log::getInstance()->log("VVideoRec", Log::DEBUG, "SM: %u EM: %u", startMargin, endMargin);
90
91   setSize(video->getScreenWidth(), video->getScreenHeight());
92   createBuffer();
93   transparent.set(0, 0, 0, 0);
94   setBackgroundColour(transparent);
95
96   OsdVector* osdv=dynamic_cast<OsdVector*>(Osd::getInstance());
97   if (osdv)
98   {
99           osdv->updateBackgroundColor(DrawStyle::BLACK);
100   }
101
102   barRegion.x = 0;
103   barRegion.y = video->getScreenHeight() - 58;   // FIXME, need to be - 1? and below?
104   barRegion.w = video->getScreenWidth();
105   barRegion.h = 58;
106
107   clocksRegion.x = barRegion.x + 140;
108   clocksRegion.y = barRegion.y + 12;
109   clocksRegion.w = 170;
110   clocksRegion.h = getFontHeight();
111 //  barBlue.set(0, 0, 150, 150);
112   barBlue.set(0, 0, 0, 128);
113
114   barShowing = false;
115   barGenHold = false;
116   barScanHold = false;
117   barVasHold = false;
118 #ifdef PAL_WSS
119   dowss = false;
120   char* optionWSS = vdr->configLoad("General", "WSS");
121   if (optionWSS)
122   {
123     if (strstr(optionWSS, "Yes")) dowss = true;
124     delete[] optionWSS;
125   }
126   Log::getInstance()->log("VVideoRec", Log::DEBUG, "Do WSS: %u", dowss);
127
128   if (dowss)
129   {
130     wss.setFormat(video->getFormat());
131     wss.setWide(true);
132     add(&wss);
133
134     wssRegion.x = 0;
135     wssRegion.y = 0;
136     wssRegion.w = video->getScreenWidth();
137     wssRegion.h = 300;
138   }
139 #endif
140   vdisplay.mode=Fullscreen;
141   vdisplay.fallbackMode=Fullscreen;
142   vdisplay.x=0;
143   vdisplay.y=0;
144   vdisplay.width=0;
145   vdisplay.height=0;
146
147   lastbar = -1;
148 }
149
150 void VVideoRec::preDelete()
151 {
152   timers->cancelTimer(this, 1);
153   timers->cancelTimer(this, 2);
154
155   if (vas)
156   {
157     boxstack->remove(vas);
158     vas = NULL;
159   }
160
161   if (vsummary) delete vsummary;
162
163   if (playing) stopPlay();
164 }
165
166 VVideoRec::~VVideoRec()
167 {
168   Log::getInstance()->log("VVideoRec", Log::DEBUG, "Entering vvideorec destructor");
169
170   video->setDefaultAspect();
171
172   // kill recInfo in case resumePoint has changed (likely)
173   myRec->dropRecInfo();
174   // FIXME - do this properly - save the resume point back to the server manually and update
175   // rec->recInfo->resumePoint - this will fix the ~10s offset problem as well
176
177   OsdVector* osdv=dynamic_cast<OsdVector*>(Osd::getInstance());
178   if (osdv)
179   {
180           osdv->updateBackgroundColor(DrawStyle::WALLPAPER);
181   }
182 }
183
184 void VVideoRec::go(bool resume)
185 {
186   ULONG startFrameNum;
187   if (resume)
188     startFrameNum = myRec->recInfo->resumePoint;
189   else
190     startFrameNum = 0;
191
192   Log::getInstance()->log("VVideoRec", Log::DEBUG, "Starting stream: %s at frame: %lu", myRec->getFileName(), startFrameNum);
193   ULONG lengthFrames = 0;
194   bool isPesRecording;
195   ULLONG lengthBytes = vdr->streamRecording(myRec->getFileName(), &lengthFrames, &isPesRecording);
196   myRec->IsPesRecording = isPesRecording;
197   if (lengthBytes)
198   {
199     player->setLengthBytes(lengthBytes);
200     player->setLengthFrames(lengthFrames);
201     player->setStartFrame(startFrameNum);
202     player->play();
203     playing = true;
204     doBar(0);
205   }
206   else
207   {
208     stopPlay(); // clean up
209
210     if (!vdr->isConnected())
211     {
212       Command::getInstance()->connectionLost();
213       return;
214     }
215
216     Message* m = new Message();
217     m->message = Message::CLOSE_ME;
218     m->from = this;
219     m->to = boxstack;
220     Command::getInstance()->postMessageNoLock(m);
221
222     VInfo* vi = new VInfo();
223     vi->setSize(400, 150);
224     vi->createBuffer();
225     if (video->getFormat() == Video::PAL)
226       vi->setPosition(170, 200);
227     else
228       vi->setPosition(160, 150);
229     vi->setExitable();
230     vi->setBorderOn(1);
231     vi->setTitleBarOn(0);
232     vi->setOneLiner(tr("Error playing recording"));
233     vi->draw();
234
235     m = new Message();
236     m->message = Message::ADD_VIEW;
237     m->to = boxstack;
238     m->parameter.num = (ULONG)vi;
239     Command::getInstance()->postMessageNoLock(m);
240   }
241 }
242
243 int VVideoRec::handleCommand(int command)
244 {
245   switch(command)
246   {
247     case Remote::UP:
248     case Remote::PLAY:
249     {
250       player->play();
251       doBar(0);
252       return 2;
253     }
254
255     case Remote::PLAYPAUSE:
256     {
257         player->playpause();
258         doBar(0);
259         return 2;
260     }
261
262     case Remote::BACK:
263     {
264       if (vsummary)
265       {
266         removeSummary();
267         return 2;
268       }
269     } // DROP THROUGH
270     case Remote::STOP:
271     case Remote::MENU:
272     {
273       if (playing) stopPlay();
274
275       return 4;
276     }
277     case Remote::DOWN:
278     case Remote::PAUSE:
279     {
280       player->pause();
281       doBar(0);
282       return 2;
283     }
284     case Remote::SKIPFORWARD:
285     {
286       doBar(3);
287       player->skipForward(60);
288       return 2;
289     }
290     case Remote::SKIPBACK:
291     {
292       doBar(4);
293       player->skipBackward(60);
294       return 2;
295     }
296     case Remote::RIGHT:
297     case Remote::FORWARD:
298     {
299       player->fastForward();
300       doBar(0);
301       return 2;
302     }
303     case Remote::LEFT:
304     case Remote::REVERSE:
305     {
306       player->fastBackward();
307       doBar(0);
308       return 2;
309     }
310     case Remote::RED:
311     {
312       if (vsummary) removeSummary();
313       else doSummary();
314       return 2;
315     }
316     case Remote::GREEN:
317     {
318       doAudioSelector();
319       return 2;
320     }
321     case Remote::YELLOW:
322     {
323       if (myRec->hasMarks())
324       {
325         // skip to previous mark
326         Log* logger = Log::getInstance();
327         int currentFrame = (player->getCurrentFrameNum()); // get current Frame
328         currentFrame -= (int)(5. * myRec->recInfo->fps); // subtrack 5 seconds, else you cannot skip more than once back ..
329
330         int prevMark = myRec->getPrevMark(currentFrame); // find previous Frame
331         if (prevMark)
332         {
333           logger->log("VVideoRec", Log::NOTICE, "jump back from pos %i to mark at %i",currentFrame,prevMark);
334           player->jumpToMark(prevMark);
335         }
336         doBar(4);
337       }
338       else
339       {
340         doBar(2);
341         player->skipBackward(10);
342       }
343       return 2;
344     }
345     case Remote::BLUE:
346     {
347       if (myRec->hasMarks())
348       {
349         // skip to next mark
350         Log* logger = Log::getInstance();
351         int currentFrame = (player->getCurrentFrameNum());
352
353         int nextMark = myRec->getNextMark(currentFrame);
354
355         if (nextMark)
356         {
357           logger->log("VVideoRec", Log::NOTICE, "jump forward from pos %i to mark at %i",currentFrame,nextMark);
358           player->jumpToMark(nextMark);
359         }
360         doBar(3);
361       }
362       else
363       {
364         doBar(1);
365         player->skipForward(10);
366       }
367       return 2;
368     }
369     case Remote::PREVCHANNEL:
370     {
371       player->skipBackward(2);
372       return 2;
373     }
374     case Remote::STAR:
375     {
376       doBar(2);
377       player->skipBackward(10);
378       return 2;
379     }
380     case Remote::HASH:
381     {
382       doBar(1);
383       player->skipForward(10);
384       return 2;
385     }
386     case Remote::FULL:
387     case Remote::TV:
388     {
389       toggleChopSides();
390       return 2;
391     }
392
393     case Remote::OK:
394     {
395       if (vsummary)
396       {
397         removeSummary();
398         return 2;
399       }
400       
401       if (barShowing) removeBar();
402       else doBar(0);
403       return 2;
404     }
405
406     case Remote::ZERO:  player->jumpToPercent(0);  doBar(0);  return 2;
407     case Remote::ONE:   player->jumpToPercent(10); doBar(0);  return 2;
408     case Remote::TWO:   player->jumpToPercent(20); doBar(0);  return 2;
409     case Remote::THREE: player->jumpToPercent(30); doBar(0);  return 2;
410     case Remote::FOUR:  player->jumpToPercent(40); doBar(0);  return 2;
411     case Remote::FIVE:  player->jumpToPercent(50); doBar(0);  return 2;
412     case Remote::SIX:   player->jumpToPercent(60); doBar(0);  return 2;
413     case Remote::SEVEN: player->jumpToPercent(70); doBar(0);  return 2;
414     case Remote::EIGHT: player->jumpToPercent(80); doBar(0);  return 2;
415     case Remote::NINE:  player->jumpToPercent(90); doBar(0);  return 2;
416
417     case Remote::RECORD: player->toggleSubtitles(); return 2;
418 #ifdef DEV
419 //    case Remote::RED:
420 //    {
421       //Don't use RED for anything. It will eventually be recording summary
422
423       //player->test1();
424
425
426       /*
427       // for testing EPG in NTSC with a NTSC test video
428       Video::getInstance()->setMode(Video::QUARTER);
429       Video::getInstance()->setPosition(170, 5);
430       VEpg* vepg = new VEpg(NULL, 0);
431       vepg->draw();
432       BoxStack::getInstance()->add(vepg);
433       BoxStack::getInstance()->update(vepg);
434       */
435
436 //      return 2;
437 //    }
438
439 #endif
440
441   }
442
443   return 1;
444 }
445
446 void VVideoRec::doTeletext()
447 {
448   
449   bool exists=true;
450
451   
452   // Draw the teletxt
453   VTeletextView *vtxv=player->getTeletextDecoder()->getTeletxtView();
454   if (vtxv==NULL) {
455        vtxv= new VTeletextView((player)->getTeletextDecoder(),this,NULL);
456       (player)->getTeletextDecoder()->registerTeletextView(vtxv);
457       exists=false;
458   }
459   vtxv->setSubtitleMode(true);
460   vtxv->draw();
461   draw();
462   
463   if (!exists) {
464       BoxStack::getInstance()->add(vtxv);
465   }
466   BoxStack::getInstance()->update(this);
467   BoxStack::getInstance()->update(vtxv); 
468 }
469
470 void VVideoRec::processMessage(Message* m)
471 {
472   Log::getInstance()->log("VVideoRec", Log::DEBUG, "Message received");
473
474   if (m->message == Message::MOUSE_LBDOWN)
475   {
476     UINT x = (m->parameter.num>>16) - getScreenX();
477     UINT y = (m->parameter.num&0xFFFF) - getScreenY();
478
479     if (!barShowing)
480     {
481       BoxStack::getInstance()->handleCommand(Remote::OK); //simulate rok press
482     }
483     else if (barRegion.x<=x && barRegion.y<=y && (barRegion.x+barRegion.w)>=x && (barRegion.y+barRegion.h)>=y)
484     {
485       int progBarXbase = barRegion.x + 300;
486       if (myRec->hasMarks())
487       {
488         MarkList* markList = myRec->getMarkList();
489         MarkList::iterator i;
490         Mark* loopMark = NULL;
491         int posPix;
492         ULONG lengthFrames;
493         if (myRec->recInfo->timerEnd > time(NULL))
494         {
495           // chasing playback
496           // Work out an approximate length in frames (good to 1s...)
497                         lengthFrames = (ULONG)((double)(myRec->recInfo->timerEnd - myRec->recInfo->timerStart) * myRec->recInfo->fps);
498         }
499         else
500         {
501           lengthFrames = player->getLengthFrames();
502         }
503         for(i = markList->begin(); i != markList->end(); i++)
504         {
505           loopMark = *i;
506           if (loopMark->pos)
507           {
508             posPix = 302 * loopMark->pos / lengthFrames;
509             rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 3, 28, DrawStyle::DANGER);
510             if (x>=barRegion.x + progBarXbase + 2 + posPix
511                 && x<=barRegion.x + progBarXbase + 2 + posPix+3
512                 && y>=barRegion.y + 12 - 2
513                 && y<=barRegion.y + 12 - 2+28)
514             {
515               player->jumpToMark(loopMark->pos);
516               doBar(3);
517               return;
518             }
519           }
520         }
521       }
522
523       if (x>=barRegion.x + progBarXbase + 24
524           && x<=barRegion.x + progBarXbase + 4 + 302
525           && y>=barRegion.y + 12 - 2
526           && y<=barRegion.y + 12 - 2+28)
527       {
528         int cx=x-(barRegion.x + progBarXbase + 4);
529         double percent=((double)cx)/302.*100.;
530         player->jumpToPercent(percent);
531         doBar(3);
532         return;
533         //  int progressWidth = 302 * currentFrameNum / lengthFrames;
534         //  rectangle(barRegion.x + progBarXbase + 4, barRegion.y + 16, progressWidth, 16, DrawStyle::SELECTHIGHLIGHT);
535       }
536     }
537     else
538     {
539       BoxStack::getInstance()->handleCommand(Remote::OK); //simulate rok press
540     }
541   }
542   else if (m->from == player)
543   {
544     if (m->message != Message::PLAYER_EVENT) return;
545     switch(m->parameter.num)
546     {
547       case Player::CONNECTION_LOST: // connection lost detected
548       {
549         // I can't handle this, send it to command
550         Message* m2 = new Message();
551         m2->to = Command::getInstance();
552         m2->message = Message::CONNECTION_LOST;
553         Command::getInstance()->postMessageNoLock(m2);
554         break;
555       }
556       case Player::STOP_PLAYBACK:
557       {
558         // FIXME Obselete ish - improve this
559         Message* m2 = new Message(); // Must be done after this thread finishes, and must break into master mutex
560         m2->to = Command::getInstance();
561         m2->message = Message::STOP_PLAYBACK;
562         Command::getInstance()->postMessageNoLock(m2);
563         break;
564       }
565       case Player::ASPECT43:
566       {
567 #ifdef PAL_WSS
568         if (dowss)
569         {
570           Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 43");
571           wss.setWide(false);
572           wss.draw();
573           boxstack->update(this, &wssRegion);
574         }
575 #endif
576         break;
577       }
578       case Player::ASPECT169:
579       {
580 #ifdef PAL_WSS
581         if (dowss)
582         {
583           Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 169");
584           wss.setWide(true);
585           wss.draw();
586           boxstack->update(this, &wssRegion);
587         }
588 #endif
589         break;
590       }
591     }
592   }
593   else if (m->message == Message::AUDIO_CHANGE_CHANNEL)
594   {
595     Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received change audio channel to %i", m->parameter.num);
596     player->setAudioChannel(m->parameter.num&0xFFFF,(m->parameter.num&0xFF0000)>> 16,(m->parameter.num&0xFF000000)>> 24 );
597   }
598   else if (m->message == Message::SUBTITLE_CHANGE_CHANNEL)
599   {
600       Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received change subtitle channel to %i", m->parameter.num);
601       int type=((m->parameter.num & 0xFF0000)>>16);
602       switch (type) {
603       case 0x10: { //dvbsubtitle
604           player->setSubtitleChannel((m->parameter.num & 0xFFFF));
605           player->turnSubtitlesOn(true);
606           VTeletextView *vtxt=((Player*)player)->getTeletextDecoder()->getTeletxtView();
607           if (vtxt && vtxt->isInSubtitleMode()) {
608               BoxStack::getInstance()->remove(vtxt);
609           }
610                  } break;
611       case 0xFF: { //nosubtitles
612           
613            player->turnSubtitlesOn(false);
614            VTeletextView *vtxt=((Player*)player)->getTeletextDecoder()->getTeletxtView();
615            if (vtxt && vtxt->isInSubtitleMode()) {
616               BoxStack::getInstance()->remove(vtxt);
617            }  
618           
619                  } break;
620       case 0x11: { //videotext
621           player->turnSubtitlesOn(false);
622           doTeletext();
623           ((Player*)player)->getTeletextDecoder()->setPage((m->parameter.num & 0xFFFF));
624                  } break;
625       };
626       if (vas) {
627         BoxStack::getInstance()->update(vas);
628       }
629       BoxStack::getInstance()->update(this);
630
631       
632   } 
633   else if (m->message == Message::CHILD_CLOSE)
634   {
635     if (m->from == vas)
636     {
637       vas = NULL;
638       barVasHold = false;
639       if (!barGenHold && !barScanHold && !barVasHold) removeBar();
640     }
641   }
642 }
643
644 void VVideoRec::stopPlay()
645 {
646   Log::getInstance()->log("VVideoRec", Log::DEBUG, "Pre stopPlay");
647
648   removeBar();
649   Log::getInstance()->log("VVideoRec", Log::DEBUG, "1");
650   player->stop();
651   Log::getInstance()->log("VVideoRec", Log::DEBUG, "2");
652   vdr->stopStreaming();
653   Log::getInstance()->log("VVideoRec", Log::DEBUG, "3");
654   delete player;
655
656   playing = false;
657
658   if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
659   Log::getInstance()->log("VVideoRec", Log::DEBUG, "Post stopPlay");
660 }
661
662 void VVideoRec::toggleChopSides()
663 {
664   if (video->getTVsize() == Video::ASPECT16X9) return; // Means nothing for 16:9 TVs
665
666   if (videoMode == Video::NORMAL)
667   {
668     videoMode = Video::LETTERBOX;
669     video->setMode(Video::LETTERBOX);
670   }
671   else
672   {
673     videoMode = Video::NORMAL;
674     video->setMode(Video::NORMAL);
675   }
676 }
677
678 void VVideoRec::doAudioSelector()
679 {
680     int subtitleChannel=player->getCurrentSubtitleChannel();
681     int subtitleType=0x10;
682     if (!(player)->isSubtitlesOn()) {
683         if ((player)->getTeletextDecoder()->getTeletxtView() &&
684             (player)->getTeletextDecoder()->getTeletxtView()->isInSubtitleMode() 
685             ) {
686                 subtitleChannel=(player)->getTeletextDecoder()->getPage();
687                 subtitleType=0x11;
688       
689            } else {
690                 subtitleType=0xFF; //turnedOff
691                 subtitleChannel=0;
692           }
693     }
694     if (player->isPesRecording()) {
695         bool* availableMpegAudioChannels = player->getDemuxerMpegAudioChannels();
696         bool* availableAc3AudioChannels = NULL;
697         bool* availableSubtitleChannels = player->getDemuxerSubtitleChannels();
698         int *availableTTxtpages = player->getTeletxtSubtitlePages();
699         int currentAudioChannel = player->getCurrentAudioChannel();
700         if (Audio::getInstance()->supportsAc3())
701         {
702             availableAc3AudioChannels = player->getDemuxerAc3AudioChannels();
703         }
704         
705         vas = new VAudioSelector(this, availableMpegAudioChannels, availableAc3AudioChannels, currentAudioChannel,availableSubtitleChannels, availableTTxtpages,
706             subtitleChannel, subtitleType, myRec->recInfo);
707     } else {
708         // Draw the selector
709         Channel *temp_channel=player->getDemuxerChannel();
710        // RecInfo *cur_info= myRec->recInfo;
711      /*   unsigned char numchan_recinfo = cur_info->numComponents;
712         unsigned char numchan_subtitles_siz = temp_channel.numSPids;
713         ULONG mp_audcounter = 0;
714         ULONG ac3_counter = 0;
715         int dvb_subcounter = 1;*/
716         ULONG i;
717         
718         /*unsigned char type;
719         char* lang;
720         char* description;
721         for (i = 0; i < numchan_recinfo; i++)
722         {   
723             apid* ac = NULL;
724             type = cur_info->types[i];
725             lang = cur_info->languages[i];
726             description = cur_info->descriptions[i];
727             
728
729             if (cur_info->streams[i] == 2) {
730                 switch (type)
731                 {
732                 case 1: //mpaudio mono
733                 case 3: //mpaudio stereo
734                     if (mp_audcounter < temp_channel.numAPids) ac = &temp_channel.apids[mp_audcounter];
735                     
736                     mp_audcounter++;
737                     break;
738                 case 5: //ac3
739                     if (ac3_counter < temp_channel.numDPids) ac = &temp_channel.dpids[ac3_counter];
740                     ac3_counter++;
741                     break;
742                 }
743             } else if (cur_info->streams[i] == 3){
744                 if (dvb_subcounter < numchan_subtitles_siz) ac = &temp_channel.spids[dvb_subcounter];
745             } else continue; //neither audio nor subtitle
746             if (ac)
747             {
748                 if (description && (strlen(description) > 0))
749                 {
750                     ac->name = new char[strlen(description) + 1];
751                     strcpy(ac->name, description);
752                     
753                 } else if (lang && strlen(lang) > 0)
754                 {
755                     ac->name = new char[strlen(lang) + 1];
756                     strcpy(ac->name, lang);
757                     
758                 }
759             }
760         }*/
761         for (i=0;i<temp_channel->numAPids;i++) {
762             apid *ac=&temp_channel->apids[i];
763             if (ac->desc[0]==0) {
764                 strncpy(ac->desc, tr("unknown"),9);
765             }
766         }
767         for (i=0;i<temp_channel->numDPids;i++) {
768             apid *ac=&temp_channel->dpids[i];
769             if (ac->desc[0]==0) {
770                 strncpy(ac->desc, tr("unknown"),9);
771             }
772         }
773         for (i=0;i<temp_channel->numSPids;i++) {
774             apid *ac=&temp_channel->spids[i];
775             if (ac->desc[0]==0) {
776                 strncpy(ac->desc, tr("unknown"),9);
777             }
778         }
779
780         vas = new VAudioSelector(this,temp_channel , (player)->getCurrentAudioChannel(),
781             subtitleType,subtitleChannel,player->getTeletxtSubtitlePages());  
782       /*   for (i=0;i<temp_channel.numAPids;i++) {
783             apid *ac=&temp_channel.apids[i];
784             delete[] ac->name;
785             ac->name=NULL;
786         }
787         for (i=0;i<temp_channel.numDPids;i++) {
788             apid *ac=&temp_channel.dpids[i];
789             delete[] ac->name;
790             ac->name=NULL;
791         }
792         for (i=0;i<temp_channel.numSPids;i++) {
793             apid *ac=&temp_channel.spids[i];
794             delete[] ac->name;
795             ac->name=NULL;
796         }*/
797     }
798
799
800   vas->setBackgroundColour(barBlue);
801   vas->setPosition(0, barRegion.y - 120);
802
803 // pal 62, ntsc 57
804
805   barVasHold = true;
806   doBar(0);
807
808   vas->draw();
809   boxstack->add(vas);
810   boxstack->update(vas);
811 }
812
813 void VVideoRec::doBar(int action_in)
814 {
815   if (player->isSubtitlesOn()) clearOSD(); // remove dvbsubtitles
816   player->tellSubtitlesOSDVisible(true);
817   barShowing = true;
818
819   int action = action_in;
820   if (action == -1) {
821           action = lastbar;
822   }
823   else {
824           lastbar = action;
825   }
826
827   rectangle(barRegion, barBlue);
828
829   /* Work out what to display - choices:
830
831   Playing  >
832   Paused   ||
833   FFwd     >>
834   FBwd     <<
835
836   Specials, informed by parameter
837
838   Skip forward 10s    >|
839   Skip backward 10s   |<
840   Skip forward 1m     >>|
841   Skip backward 1m    |<<
842
843   */
844
845   WSymbol w;
846   TEMPADD(&w);
847   w.nextSymbol = 0;
848   w.setPosition(barRegion.x + 66, barRegion.y + 16);
849
850   UCHAR playerState = 0;
851
852   if (action)
853   {
854     if (action == 1)       w.nextSymbol = WSymbol::SKIPFORWARD;
855     else if (action == 2)  w.nextSymbol = WSymbol::SKIPBACK;
856     else if (action == 3)  w.nextSymbol = WSymbol::SKIPFORWARD2;
857     else if (action == 4)  w.nextSymbol = WSymbol::SKIPBACK2;
858   }
859   else
860   {
861     playerState = player->getState();
862     if (playerState == Player::S_PAUSE_P)      w.nextSymbol = WSymbol::PAUSE;
863     else if (playerState == Player::S_PAUSE_I) w.nextSymbol = WSymbol::PAUSE;
864     else if (playerState == Player::S_FFWD)    w.nextSymbol = WSymbol::FFWD;
865     else if (playerState == Player::S_FBWD)    w.nextSymbol = WSymbol::FBWD;
866     else                                       w.nextSymbol = WSymbol::PLAY;
867   }
868
869   w.draw();
870
871   if ((playerState == Player::S_FFWD) || (playerState == Player::S_FBWD))
872   {
873     // draw blips to show how fast the scan is
874     UCHAR scanrate = player->getIScanRate();
875     if (scanrate >= 2)
876     {
877       char text[5];
878       SNPRINTF(text, 5, "%ux", scanrate);
879       drawText(text, barRegion.x + 102, barRegion.y + 12, DrawStyle::LIGHTTEXT);
880     }
881   }
882
883   drawBarClocks();
884
885   boxstack->update(this, &barRegion);
886
887   if (action_in != -1) {
888           timers->cancelTimer(this, 1);
889
890
891           if ((playerState == Player::S_FFWD) || (playerState == Player::S_FBWD)) barScanHold = true;
892           else barScanHold = false;
893
894           if (!barGenHold && !barScanHold && !barVasHold) timers->setTimerD(this, 1, 4);
895
896           timers->setTimerD(this, 2, 0, 200000000);
897   }
898 }
899
900 void VVideoRec::timercall(int clientReference)
901 {
902   switch(clientReference)
903   {
904     case 1:
905     {
906       // Remove bar
907       removeBar();
908       break;
909     }
910     case 2:
911     {
912       // Update clock
913       if (!barShowing) break;
914 #ifndef GRADIENT_DRAWING
915       drawBarClocks();
916       boxstack->update(this, &barRegion);
917 #else 
918           doBar(-1);
919 #endif
920       timers->setTimerD(this, 2, 0, 200000000);
921       break;
922     }
923   }
924 }
925
926 hmsf VVideoRec::framesToHMSF(ULONG frames)
927 {
928   hmsf ret;
929   /* from vdr */
930   double Seconds;
931   double fps=myRec->recInfo->fps;
932   ret.frames= int(modf((frames + 0.5) / fps, &Seconds) * fps + 1);
933   int s = int(Seconds);
934   ret.seconds=s % 60;
935   ret.minutes = s / 60 % 60;
936   ret.hours = s / 3600;
937
938
939   return ret;
940 }
941
942 void VVideoRec::drawBarClocks()
943 {
944   if (barScanHold)
945   {
946     UCHAR playerState = player->getState();
947     // sticky bar is set if we are in ffwd/fbwd mode
948     // if player has gone to S_PLAY then kill stickyBar, and run doBar(0) which
949     // will repaint all the bar (it will call this function again, but
950     // this section won't run because stickyBarF will then == false)
951
952     if ((playerState != Player::S_FFWD) && (playerState != Player::S_FBWD))
953     {
954       barScanHold = false;
955       doBar(0);
956       return; // doBar will call this function and do the rest
957     }
958   }
959
960   Log* logger = Log::getInstance();
961   logger->log("VVideoRec", Log::DEBUG, "Draw bar clocks");
962
963   // Draw RTC
964   // Blank the area first
965 #ifndef GRADIENT_DRAWING
966   rectangle(barRegion.x + 624, barRegion.y + 12, 60, 30, barBlue);
967 #endif
968   char timeString[20];
969   time_t t;
970   time(&t);
971   struct tm tms;
972   LOCALTIME_R(&t, &tms);
973   strftime(timeString, 19, "%H:%M", &tms);
974   drawText(timeString, barRegion.x + 624, barRegion.y + 12, DrawStyle::LIGHTTEXT);
975
976   // Draw clocks
977 #ifndef GRADIENT_DRAWING
978   rectangle(clocksRegion, barBlue);
979 #endif
980
981   ULONG currentFrameNum = player->getCurrentFrameNum();
982   ULONG lengthFrames;
983   if (myRec->recInfo->timerEnd > time(NULL))
984   {
985     // chasing playback
986     // Work out an approximate length in frames (good to 1s...)
987     lengthFrames =(ULONG) ((double)(myRec->recInfo->timerEnd - myRec->recInfo->timerStart) * myRec->recInfo->fps);
988   }
989   else
990   {
991     lengthFrames = player->getLengthFrames();
992   }
993
994   hmsf currentFrameHMSF = framesToHMSF(currentFrameNum);
995   hmsf lengthHMSF = framesToHMSF(lengthFrames);
996
997   char buffer[100];
998   if (currentFrameNum >= lengthFrames)
999   {
1000     strcpy(buffer, "-:--:-- / -:--:--");
1001   }
1002   else
1003   {
1004     SNPRINTF(buffer, 99, "%01i:%02i:%02i / %01i:%02i:%02i", currentFrameHMSF.hours, currentFrameHMSF.minutes, currentFrameHMSF.seconds, lengthHMSF.hours, lengthHMSF.minutes, lengthHMSF.seconds);
1005     logger->log("VVideoRec", Log::DEBUG, buffer);
1006   }
1007
1008   drawText(buffer, clocksRegion.x, clocksRegion.y, DrawStyle::LIGHTTEXT);
1009
1010
1011
1012
1013
1014
1015
1016   // Draw progress bar
1017   int progBarXbase = barRegion.x + 300;
1018
1019   rectangle(barRegion.x + progBarXbase, barRegion.y + 12, 310, 24, DrawStyle::LIGHTTEXT);
1020   rectangle(barRegion.x + progBarXbase + 2, barRegion.y + 14, 306, 20, barBlue);
1021
1022   if (currentFrameNum > lengthFrames) return;
1023   if (lengthFrames == 0) return;
1024
1025   // Draw yellow portion
1026   int progressWidth = 302 * currentFrameNum / lengthFrames;
1027   rectangle(barRegion.x + progBarXbase + 4, barRegion.y + 16, progressWidth, 16, DrawStyle::SELECTHIGHLIGHT);
1028
1029   if (myRec->recInfo->timerEnd > time(NULL)) // if chasing
1030   {
1031     int nrWidth = (int)(302 * ((double)(lengthFrames - player->getLengthFrames()) / lengthFrames));
1032
1033     Log::getInstance()->log("GVASDF", Log::DEBUG, "Length Frames: %lu", lengthFrames);
1034     Log::getInstance()->log("GVASDF", Log::DEBUG, "Player lf: %lu", player->getLengthFrames());
1035     Log::getInstance()->log("GVASDF", Log::DEBUG, "NR WDITH: %i", nrWidth);
1036     rectangle(barRegion.x + progBarXbase + 4 + 302 - nrWidth, barRegion.y + 16, nrWidth, 16, DrawStyle::RED);
1037   }
1038
1039   int posPix;
1040   // Now calc position for blips
1041
1042   if (myRec->hasMarks())
1043   {
1044     // Draw blips where there are cut marks
1045     MarkList* markList = myRec->getMarkList();
1046     MarkList::iterator i;
1047     Mark* loopMark = NULL;
1048
1049     for(i = markList->begin(); i != markList->end(); i++)
1050     {
1051       loopMark = *i;
1052       if (loopMark->pos)
1053       {
1054         logger->log("VVideoRec", Log::DEBUG, "Drawing mark at frame %i", loopMark->pos);
1055         posPix = 302 * loopMark->pos / lengthFrames;
1056         rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 3, 28, DrawStyle::DANGER);
1057       }
1058     }
1059   }
1060   else
1061   {
1062     // Draw blips where start and end margins probably are
1063
1064           posPix =(int) (302. * myRec->recInfo->fps * ((double)startMargin) /((double) lengthFrames));
1065
1066     rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 2, 2, DrawStyle::LIGHTTEXT);
1067     rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 + 24, 2, 2, DrawStyle::LIGHTTEXT);
1068
1069     posPix = (int)(302. * ((double)lengthFrames - ((double)endMargin) * myRec->recInfo->fps) / ((double)lengthFrames));
1070
1071     rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 2, 2, DrawStyle::LIGHTTEXT);
1072     rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 + 24, 2, 2, DrawStyle::LIGHTTEXT);
1073   }
1074 }
1075
1076 void VVideoRec::removeBar()
1077 {
1078   if (!barShowing) return;
1079   timers->cancelTimer(this, 2);
1080   barShowing = false;
1081   barGenHold = false;
1082   barScanHold = false;
1083   barVasHold = false;
1084   rectangle(barRegion, transparent);
1085   boxstack->update(this, &barRegion);
1086   player->tellSubtitlesOSDVisible(false);
1087 }
1088
1089 void VVideoRec::doSummary()
1090 {
1091   clearOSD(); // remove dvbsubtitles
1092   player->tellSubtitlesOSDVisible(true);
1093   vsummary = new VInfo();
1094   vsummary->setTitleText(myRec->getProgName());
1095   vsummary->setBorderOn(1);
1096   vsummary->setExitable();
1097   if (myRec->recInfo->summary) vsummary->setMainText(myRec->recInfo->summary);
1098   else vsummary->setMainText(tr("Summary unavailable"));
1099   if (Video::getInstance()->getFormat() == Video::PAL)
1100   {
1101     vsummary->setPosition(120, 130);
1102   }
1103   else
1104   {
1105     vsummary->setPosition(110, 90);
1106   }
1107   vsummary->setSize(510, 270);
1108   add(vsummary);
1109   vsummary->draw();
1110
1111   BoxStack::getInstance()->update(this);
1112 }
1113
1114 void VVideoRec::removeSummary()
1115 {
1116   if (vsummary)
1117   {
1118     remove(vsummary);
1119     delete vsummary;
1120     vsummary = NULL;
1121     draw();
1122     BoxStack::getInstance()->update(this);
1123     player->tellSubtitlesOSDVisible(false);
1124   }
1125 }
1126
1127 void VVideoRec::drawOSDBitmap(UINT posX, UINT posY, const Bitmap& bm, const DisplayRegion& region)
1128 {
1129   drawBitmap(posX, posY, bm, region);
1130   Region r;
1131   r.x = posX; r.y = posY; r.w = bm.getWidth(); r.h = bm.getHeight();
1132   boxstack->update(this, &r);
1133 }
1134
1135 void VVideoRec::clearOSD()
1136 {
1137   rectangle(area, transparent);
1138   boxstack->update(this, &area);
1139 }
1140
1141 void VVideoRec::clearOSDArea(UINT posX, UINT posY, UINT width, UINT height, const DisplayRegion& region)
1142 {
1143   Region r;
1144   r.x = posX+region.windowx; r.y = posY+region.windowy; r.w = width; r.h = height;
1145   //now convert to our display
1146   float scalex=720.f/((float) (region.framewidth+1));
1147   float scaley=576.f/((float) (region.frameheight+1));
1148   r.x=(UINT)floor(scalex*((float)r.x));
1149   r.y=(UINT)floor(scaley*((float)r.y));
1150   r.w=(UINT)(ceil(scalex*((float)r.w))+1.f);
1151   r.h=(UINT)(ceil(scaley*((float)r.h))+1.f);
1152
1153   rectangle(r, transparent);
1154   boxstack->update(this, &r);
1155 }