2 Copyright 2004-2005 Chris Tallon
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "vvideorec.h"
22 #include "vteletextview.h"
32 #include "recording.h"
33 #include "vaudioselector.h"
43 VVideoRec::VVideoRec(Recording* rec)
45 boxstack = BoxStack::getInstance();
46 vdr = VDR::getInstance();
47 video = Video::getInstance();
48 timers = Timers::getInstance();
52 player = new Player(Command::getInstance(), this, this);
55 videoMode = video->getMode();
62 char* cstartMargin = vdr->configLoad("Timers", "Start margin");
63 char* cendMargin = vdr->configLoad("Timers", "End margin");
66 startMargin = 300; // 5 mins default
70 startMargin = atoi(cstartMargin) * 60;
71 delete[] cstartMargin;
76 endMargin = 300; // 5 mins default
80 endMargin = atoi(cendMargin) * 60;
84 Log::getInstance()->log("VVideoRec", Log::DEBUG, "SM: %u EM: %u", startMargin, endMargin);
86 setSize(video->getScreenWidth(), video->getScreenHeight());
88 transparent.set(0, 0, 0, 0);
89 setBackgroundColour(transparent);
92 barRegion.y = video->getScreenHeight() - 58; // FIXME, need to be - 1? and below?
93 barRegion.w = video->getScreenWidth();
96 clocksRegion.x = barRegion.x + 140;
97 clocksRegion.y = barRegion.y + 12;
99 clocksRegion.h = surface->getFontHeight();
100 // barBlue.set(0, 0, 150, 150);
101 barBlue.set(0, 0, 0, 128);
109 char* optionWSS = vdr->configLoad("General", "WSS");
112 if (strstr(optionWSS, "Yes")) dowss = true;
115 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Do WSS: %u", dowss);
119 wss.setFormat(video->getFormat());
125 wssRegion.w = video->getScreenWidth();
130 void VVideoRec::preDelete()
132 timers->cancelTimer(this, 1);
133 timers->cancelTimer(this, 2);
137 boxstack->remove(vas);
141 if (vsummary) delete vsummary;
143 if (playing) stopPlay();
146 VVideoRec::~VVideoRec()
148 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Entering vvideorec destructor");
150 video->setDefaultAspect();
152 // kill recInfo in case resumePoint has changed (likely)
153 myRec->dropRecInfo();
154 // FIXME - do this properly - save the resume point back to the server manually and update
155 // rec->recInfo->resumePoint - this will fix the ~10s offset problem as well
158 void VVideoRec::go(bool resume)
162 startFrameNum = myRec->recInfo->resumePoint;
166 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Starting stream: %s at frame: %lu", myRec->getFileName(), startFrameNum);
167 ULONG lengthFrames = 0;
168 ULLONG lengthBytes = vdr->streamRecording(myRec->getFileName(), &lengthFrames);
171 player->setLengthBytes(lengthBytes);
172 player->setLengthFrames(lengthFrames);
173 player->setStartFrame(startFrameNum);
180 stopPlay(); // clean up
182 if (!vdr->isConnected())
184 Command::getInstance()->connectionLost();
188 Message* m = new Message();
189 m->message = Message::CLOSE_ME;
192 Command::getInstance()->postMessageNoLock(m);
194 VInfo* vi = new VInfo();
195 vi->setSize(400, 150);
197 if (video->getFormat() == Video::PAL)
198 vi->setPosition(170, 200);
200 vi->setPosition(160, 150);
203 vi->setTitleBarOn(0);
204 vi->setOneLiner(tr("Error playing recording"));
208 m->message = Message::ADD_VIEW;
210 m->parameter = (ULONG)vi;
211 Command::getInstance()->postMessageNoLock(m);
215 int VVideoRec::handleCommand(int command)
237 if (playing) stopPlay();
247 case Remote::SKIPFORWARD:
250 player->skipForward(60);
253 case Remote::SKIPBACK:
256 player->skipBackward(60);
259 case Remote::FORWARD:
261 player->fastForward();
265 case Remote::REVERSE:
267 player->fastBackward();
273 if (vsummary) removeSummary();
284 if (myRec->hasMarks())
286 // skip to previous mark
287 Log* logger = Log::getInstance();
288 int currentFrame = (player->getCurrentFrameNum()); // get current Frame
289 currentFrame -= 5 * video->getFPS(); // subtrack 5 seconds, else you cannot skip more than once back ..
291 int prevMark = myRec->getPrevMark(currentFrame); // find previous Frame
294 logger->log("VVideoRec", Log::NOTICE, "jump back from pos %i to mark at %i",currentFrame,prevMark);
295 player->jumpToMark(prevMark);
302 player->skipBackward(10);
308 if (myRec->hasMarks())
311 Log* logger = Log::getInstance();
312 int currentFrame = (player->getCurrentFrameNum());
314 int nextMark = myRec->getNextMark(currentFrame);
318 logger->log("VVideoRec", Log::NOTICE, "jump forward from pos %i to mark at %i",currentFrame,nextMark);
319 player->jumpToMark(nextMark);
326 player->skipForward(10);
333 player->skipBackward(10);
339 player->skipForward(10);
357 if (barShowing) removeBar();
362 case Remote::ZERO: player->jumpToPercent(0); doBar(0); return 2;
363 case Remote::ONE: player->jumpToPercent(10); doBar(0); return 2;
364 case Remote::TWO: player->jumpToPercent(20); doBar(0); return 2;
365 case Remote::THREE: player->jumpToPercent(30); doBar(0); return 2;
366 case Remote::FOUR: player->jumpToPercent(40); doBar(0); return 2;
367 case Remote::FIVE: player->jumpToPercent(50); doBar(0); return 2;
368 case Remote::SIX: player->jumpToPercent(60); doBar(0); return 2;
369 case Remote::SEVEN: player->jumpToPercent(70); doBar(0); return 2;
370 case Remote::EIGHT: player->jumpToPercent(80); doBar(0); return 2;
371 case Remote::NINE: player->jumpToPercent(90); doBar(0); return 2;
373 case Remote::RECORD: player->toggleSubtitles(); return 2;
377 //Don't use RED for anything. It will eventually be recording summary
383 // for testing EPG in NTSC with a NTSC test video
384 Video::getInstance()->setMode(Video::QUARTER);
385 Video::getInstance()->setPosition(170, 5);
386 VEpg* vepg = new VEpg(NULL, 0);
388 BoxStack::getInstance()->add(vepg);
389 BoxStack::getInstance()->update(vepg);
402 void VVideoRec::doTeletext()
409 VTeletextView *vtxv=player->getTeletextDecoder()->getTeletxtView();
411 vtxv= new VTeletextView((player)->getTeletextDecoder(),this);
412 (player)->getTeletextDecoder()->registerTeletextView(vtxv);
415 vtxv->setSubtitleMode(true);
420 BoxStack::getInstance()->add(vtxv);
422 BoxStack::getInstance()->update(this);
423 BoxStack::getInstance()->update(vtxv);
426 void VVideoRec::processMessage(Message* m)
428 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Message received");
430 if (m->message == Message::MOUSE_LBDOWN)
432 UINT x = (m->parameter>>16) - getScreenX();
433 UINT y = (m->parameter&0xFFFF) - getScreenY();
437 BoxStack::getInstance()->handleCommand(Remote::OK); //simulate rok press
439 else if (barRegion.x<=x && barRegion.y<=y && (barRegion.x+barRegion.w)>=x && (barRegion.y+barRegion.h)>=y)
441 int progBarXbase = barRegion.x + 300;
442 if (myRec->hasMarks())
444 MarkList* markList = myRec->getMarkList();
445 MarkList::iterator i;
446 Mark* loopMark = NULL;
449 if (myRec->recInfo->timerEnd > time(NULL))
452 // Work out an approximate length in frames (good to 1s...)
453 lengthFrames = (myRec->recInfo->timerEnd - myRec->recInfo->timerStart) * video->getFPS();
457 lengthFrames = player->getLengthFrames();
459 for(i = markList->begin(); i != markList->end(); i++)
464 posPix = 302 * loopMark->pos / lengthFrames;
465 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 3, 28, Colour::DANGER);
466 if (x>=barRegion.x + progBarXbase + 2 + posPix
467 && x<=barRegion.x + progBarXbase + 2 + posPix+3
468 && y>=barRegion.y + 12 - 2
469 && y<=barRegion.y + 12 - 2+28)
471 player->jumpToMark(loopMark->pos);
479 if (x>=barRegion.x + progBarXbase + 24
480 && x<=barRegion.x + progBarXbase + 4 + 302
481 && y>=barRegion.y + 12 - 2
482 && y<=barRegion.y + 12 - 2+28)
484 int cx=x-(barRegion.x + progBarXbase + 4);
485 double percent=((double)cx)/302.*100.;
486 player->jumpToPercent(percent);
489 // int progressWidth = 302 * currentFrameNum / lengthFrames;
490 // rectangle(barRegion.x + progBarXbase + 4, barRegion.y + 16, progressWidth, 16, Colour::SELECTHIGHLIGHT);
495 BoxStack::getInstance()->handleCommand(Remote::OK); //simulate rok press
498 else if (m->from == player)
500 if (m->message != Message::PLAYER_EVENT) return;
503 case Player::CONNECTION_LOST: // connection lost detected
505 // I can't handle this, send it to command
506 Message* m2 = new Message();
507 m2->to = Command::getInstance();
508 m2->message = Message::CONNECTION_LOST;
509 Command::getInstance()->postMessageNoLock(m2);
512 case Player::STOP_PLAYBACK:
514 // FIXME Obselete ish - improve this
515 Message* m2 = new Message(); // Must be done after this thread finishes, and must break into master mutex
516 m2->to = Command::getInstance();
517 m2->message = Message::STOP_PLAYBACK;
518 Command::getInstance()->postMessageNoLock(m2);
521 case Player::ASPECT43:
525 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 43");
528 boxstack->update(this, &wssRegion);
532 case Player::ASPECT169:
536 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 169");
539 boxstack->update(this, &wssRegion);
545 else if (m->message == Message::AUDIO_CHANGE_CHANNEL)
547 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received change audio channel to %i", m->parameter);
548 player->setAudioChannel(m->parameter&0xFFFF,(m->parameter&0xFF0000)>> 16 );
550 else if (m->message == Message::SUBTITLE_CHANGE_CHANNEL)
552 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received change subtitle channel to %i", m->parameter);
553 int type=((m->parameter & 0xFF0000)>>16);
555 case 0x10: { //dvbsubtitle
556 player->setSubtitleChannel((m->parameter & 0xFFFF));
557 player->turnSubtitlesOn(true);
558 VTeletextView *vtxt=((Player*)player)->getTeletextDecoder()->getTeletxtView();
559 if (vtxt && vtxt->isInSubtitleMode()) {
560 BoxStack::getInstance()->remove(vtxt);
563 case 0xFF: { //nosubtitles
565 player->turnSubtitlesOn(false);
566 VTeletextView *vtxt=((Player*)player)->getTeletextDecoder()->getTeletxtView();
567 if (vtxt && vtxt->isInSubtitleMode()) {
568 BoxStack::getInstance()->remove(vtxt);
572 case 0x11: { //videotext
573 player->turnSubtitlesOn(false);
575 ((Player*)player)->getTeletextDecoder()->setPage((m->parameter & 0xFFFF));
579 BoxStack::getInstance()->update(vas);
581 BoxStack::getInstance()->update(this);
585 else if (m->message == Message::CHILD_CLOSE)
591 if (!barGenHold && !barScanHold && !barVasHold) removeBar();
596 void VVideoRec::stopPlay()
598 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Pre stopPlay");
601 Log::getInstance()->log("VVideoRec", Log::DEBUG, "1");
603 Log::getInstance()->log("VVideoRec", Log::DEBUG, "2");
604 vdr->stopStreaming();
605 Log::getInstance()->log("VVideoRec", Log::DEBUG, "3");
610 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
611 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Post stopPlay");
614 void VVideoRec::toggleChopSides()
616 if (video->getTVsize() == Video::ASPECT16X9) return; // Means nothing for 16:9 TVs
618 if (videoMode == Video::NORMAL)
620 videoMode = Video::LETTERBOX;
621 video->setMode(Video::LETTERBOX);
625 videoMode = Video::NORMAL;
626 video->setMode(Video::NORMAL);
630 void VVideoRec::doAudioSelector()
632 bool* availableMpegAudioChannels = player->getDemuxerMpegAudioChannels();
633 bool* availableAc3AudioChannels = NULL;
634 bool* availableSubtitleChannels = player->getDemuxerSubtitleChannels();
635 int *availableTTxtpages = player->getTeletxtSubtitlePages();
636 int currentAudioChannel = player->getCurrentAudioChannel();
637 if (Audio::getInstance()->supportsAc3())
639 availableAc3AudioChannels = player->getDemuxerAc3AudioChannels();
641 int subtitleChannel=player->getCurrentSubtitleChannel();
642 int subtitleType=0x10;
643 if (!(player)->isSubtitlesOn()) {
644 if ((player)->getTeletextDecoder()->getTeletxtView() &&
645 (player)->getTeletextDecoder()->getTeletxtView()->isInSubtitleMode()
647 subtitleChannel=(player)->getTeletextDecoder()->getPage();
651 subtitleType=0xFF; //turnedOff
657 vas = new VAudioSelector(this, availableMpegAudioChannels, availableAc3AudioChannels, currentAudioChannel,availableSubtitleChannels, availableTTxtpages,
658 subtitleChannel, subtitleType, myRec->recInfo);
659 vas->setBackgroundColour(barBlue);
660 vas->setPosition(0, barRegion.y - 120);
669 boxstack->update(vas);
672 void VVideoRec::doBar(int action)
676 rectangle(barRegion, barBlue);
678 /* Work out what to display - choices:
685 Specials, informed by parameter
697 w.setPosition(barRegion.x + 66, barRegion.y + 16);
699 UCHAR playerState = 0;
703 if (action == 1) w.nextSymbol = WSymbol::SKIPFORWARD;
704 else if (action == 2) w.nextSymbol = WSymbol::SKIPBACK;
705 else if (action == 3) w.nextSymbol = WSymbol::SKIPFORWARD2;
706 else if (action == 4) w.nextSymbol = WSymbol::SKIPBACK2;
710 playerState = player->getState();
711 if (playerState == Player::S_PAUSE_P) w.nextSymbol = WSymbol::PAUSE;
712 else if (playerState == Player::S_PAUSE_I) w.nextSymbol = WSymbol::PAUSE;
713 else if (playerState == Player::S_FFWD) w.nextSymbol = WSymbol::FFWD;
714 else if (playerState == Player::S_FBWD) w.nextSymbol = WSymbol::FBWD;
715 else w.nextSymbol = WSymbol::PLAY;
720 if ((playerState == Player::S_FFWD) || (playerState == Player::S_FBWD))
722 // draw blips to show how fast the scan is
723 UCHAR scanrate = player->getIScanRate();
727 SNPRINTF(text, 5, "%ux", scanrate);
728 drawText(text, barRegion.x + 102, barRegion.y + 12, Colour::LIGHTTEXT);
734 boxstack->update(this, &barRegion);
736 timers->cancelTimer(this, 1);
739 if ((playerState == Player::S_FFWD) || (playerState == Player::S_FBWD)) barScanHold = true;
740 else barScanHold = false;
742 if (!barGenHold && !barScanHold && !barVasHold) timers->setTimerD(this, 1, 4);
744 timers->setTimerD(this, 2, 0, 200000000);
747 void VVideoRec::timercall(int clientReference)
749 switch(clientReference)
760 if (!barShowing) break;
762 boxstack->update(this, &barRegion);
764 timers->setTimerD(this, 2, 0, 200000000);
770 void VVideoRec::drawBarClocks()
774 UCHAR playerState = player->getState();
775 // sticky bar is set if we are in ffwd/fbwd mode
776 // if player has gone to S_PLAY then kill stickyBar, and run doBar(0) which
777 // will repaint all the bar (it will call this function again, but
778 // this section won't run because stickyBarF will then == false)
780 if ((playerState != Player::S_FFWD) && (playerState != Player::S_FBWD))
784 return; // doBar will call this function and do the rest
788 Log* logger = Log::getInstance();
789 logger->log("VVideoRec", Log::DEBUG, "Draw bar clocks");
792 // Blank the area first
793 rectangle(barRegion.x + 624, barRegion.y + 12, 60, 30, barBlue);
797 struct tm* tms = localtime(&t);
798 strftime(timeString, 19, "%H:%M", tms);
799 drawText(timeString, barRegion.x + 624, barRegion.y + 12, Colour::LIGHTTEXT);
803 rectangle(clocksRegion, barBlue);
805 ULONG currentFrameNum = player->getCurrentFrameNum();
807 if (myRec->recInfo->timerEnd > time(NULL))
810 // Work out an approximate length in frames (good to 1s...)
811 lengthFrames = (myRec->recInfo->timerEnd - myRec->recInfo->timerStart) * video->getFPS();
815 lengthFrames = player->getLengthFrames();
818 hmsf currentFrameHMSF = video->framesToHMSF(currentFrameNum);
819 hmsf lengthHMSF = video->framesToHMSF(lengthFrames);
822 if (currentFrameNum >= lengthFrames)
824 strcpy(buffer, "-:--:-- / -:--:--");
828 SNPRINTF(buffer, 99, "%01i:%02i:%02i / %01i:%02i:%02i", currentFrameHMSF.hours, currentFrameHMSF.minutes, currentFrameHMSF.seconds, lengthHMSF.hours, lengthHMSF.minutes, lengthHMSF.seconds);
829 logger->log("VVideoRec", Log::DEBUG, buffer);
832 drawText(buffer, clocksRegion.x, clocksRegion.y, Colour::LIGHTTEXT);
841 int progBarXbase = barRegion.x + 300;
843 rectangle(barRegion.x + progBarXbase, barRegion.y + 12, 310, 24, Colour::LIGHTTEXT);
844 rectangle(barRegion.x + progBarXbase + 2, barRegion.y + 14, 306, 20, barBlue);
846 if (currentFrameNum > lengthFrames) return;
847 if (lengthFrames == 0) return;
849 // Draw yellow portion
850 int progressWidth = 302 * currentFrameNum / lengthFrames;
851 rectangle(barRegion.x + progBarXbase + 4, barRegion.y + 16, progressWidth, 16, Colour::SELECTHIGHLIGHT);
853 if (myRec->recInfo->timerEnd > time(NULL)) // if chasing
855 int nrWidth = (int)(302 * ((double)(lengthFrames - player->getLengthFrames()) / lengthFrames));
857 Log::getInstance()->log("GVASDF", Log::DEBUG, "Length Frames: %lu", lengthFrames);
858 Log::getInstance()->log("GVASDF", Log::DEBUG, "Player lf: %lu", player->getLengthFrames());
859 Log::getInstance()->log("GVASDF", Log::DEBUG, "NR WDITH: %i", nrWidth);
860 rectangle(barRegion.x + progBarXbase + 4 + 302 - nrWidth, barRegion.y + 16, nrWidth, 16, Colour::RED);
864 // Now calc position for blips
866 if (myRec->hasMarks())
868 // Draw blips where there are cut marks
869 MarkList* markList = myRec->getMarkList();
870 MarkList::iterator i;
871 Mark* loopMark = NULL;
873 for(i = markList->begin(); i != markList->end(); i++)
878 logger->log("VVideoRec", Log::DEBUG, "Drawing mark at frame %i", loopMark->pos);
879 posPix = 302 * loopMark->pos / lengthFrames;
880 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 3, 28, Colour::DANGER);
886 // Draw blips where start and end margins probably are
888 posPix = 302 * startMargin * video->getFPS() / lengthFrames;
890 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 2, 2, Colour::LIGHTTEXT);
891 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 + 24, 2, 2, Colour::LIGHTTEXT);
893 posPix = 302 * (lengthFrames - endMargin * video->getFPS()) / lengthFrames;
895 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 2, 2, Colour::LIGHTTEXT);
896 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 + 24, 2, 2, Colour::LIGHTTEXT);
900 void VVideoRec::removeBar()
902 if (!barShowing) return;
903 timers->cancelTimer(this, 2);
908 rectangle(barRegion, transparent);
909 boxstack->update(this, &barRegion);
912 void VVideoRec::doSummary()
914 vsummary = new VInfo();
915 vsummary->setTitleText(myRec->getProgName());
916 vsummary->setBorderOn(1);
917 vsummary->setExitable();
918 if (myRec->recInfo->summary) vsummary->setMainText(myRec->recInfo->summary);
919 else vsummary->setMainText(tr("Summary unavailable"));
920 if (Video::getInstance()->getFormat() == Video::PAL)
922 vsummary->setPosition(120, 130);
926 vsummary->setPosition(110, 90);
928 vsummary->setSize(510, 270);
932 BoxStack::getInstance()->update(this);
935 void VVideoRec::removeSummary()
943 BoxStack::getInstance()->update(this);
947 void VVideoRec::drawOSDBitmap(UINT posX, UINT posY, const Bitmap& bm)
949 drawBitmap(posX, posY, bm);
951 r.x = posX; r.y = posY; r.w = bm.getWidth(); r.h = bm.getHeight();
952 boxstack->update(this, &r);
955 void VVideoRec::clearOSD()
957 rectangle(area, transparent);
958 boxstack->update(this, &area);
961 void VVideoRec::clearOSDArea(UINT posX, UINT posY, UINT width, UINT height)
964 r.x = posX; r.y = posY; r.w = width; r.h = height;
965 rectangle(r, transparent);
966 boxstack->update(this, &r);