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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "vvideorec.h"
23 VVideoRec::VVideoRec(Recording* rec)
25 viewman = ViewMan::getInstance();
26 vdr = VDR::getInstance();
27 video = Video::getInstance();
28 timers = Timers::getInstance();
31 isRadio = rec->recInfo->hasNoVideo();
33 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Radio = %i", isRadio);
35 player = new Player(Command::getInstance(), this, true, isRadio);
38 videoMode = video->getMode();
45 char* cstartMargin = vdr->configLoad("Timers", "Start margin");
46 char* cendMargin = vdr->configLoad("Timers", "End margin");
49 startMargin = 300; // 5 mins default
53 startMargin = atoi(cstartMargin) * 60;
54 delete[] cstartMargin;
59 endMargin = 300; // 5 mins default
63 endMargin = atoi(cendMargin) * 60;
67 Log::getInstance()->log("VVideoRec", Log::DEBUG, "SM: %u EM: %u", startMargin, endMargin);
69 create(video->getScreenWidth(), video->getScreenHeight());
70 transparent.set(0, 0, 0, 0);
71 setBackgroundColour(transparent);
74 barRegion.y = video->getScreenHeight() - 58; // FIXME, need to be - 1? and below?
75 barRegion.w = video->getScreenWidth();
78 clocksRegion.x = barRegion.x + 140;
79 clocksRegion.y = barRegion.y + 12;
81 clocksRegion.h = surface->getFontHeight();
84 barBlue.set(0, 0, 150, 150);
92 char* optionWSS = vdr->configLoad("General", "WSS");
95 if (strstr(optionWSS, "Yes")) dowss = true;
98 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Do WSS: %u", dowss);
100 wss.setFormat(video->getFormat());
101 wss.setSurface(surface);
107 wssRegion.w = video->getScreenWidth();
112 wssRegion.w = video->getScreenWidth();
116 VVideoRec::~VVideoRec()
120 viewman->removeView(vas);
124 if (playing) stopPlay();
125 video->setDefaultAspect();
127 timers->cancelTimer(this, 1);
128 timers->cancelTimer(this, 2);
130 // kill recInfo in case resumePoint has changed (likely)
131 myRec->dropRecInfo();
132 // FIXME - do this properly - save the resume point back to the server manually and update
133 // rec->recInfo->resumePoint - this will fix the ~10s offset problem as well
136 void VVideoRec::draw()
141 void VVideoRec::go(bool resume)
145 startFrameNum = myRec->recInfo->resumePoint;
149 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Starting stream: %s at frame: %lu", myRec->getFileName(), startFrameNum);
150 ULONG lengthFrames = 0;
151 ULLONG lengthBytes = vdr->streamRecording(myRec->getFileName(), &lengthFrames);
154 player->setLengthBytes(lengthBytes);
157 Log::getInstance()->log("VVideoRec", Log::DEBUG, "GO is setting length frames = %lu", lengthFrames);
158 player->setLengthFrames(lengthFrames);
162 Log::getInstance()->log("VVideoRec", Log::DEBUG, "GO is NOT setting length frames");
164 player->setStartFrame(startFrameNum); // means bytes if radio (FIXME not done yet!)
171 stopPlay(); // clean up
173 if (!vdr->isConnected())
175 Command::getInstance()->connectionLost();
179 Message* m = new Message();
180 m->message = Message::CLOSE_ME;
183 Command::getInstance()->postMessageNoLock(m);
185 VInfo* vi = new VInfo();
186 vi->create(400, 150);
187 if (video->getFormat() == Video::PAL)
188 vi->setScreenPos(170, 200);
190 vi->setScreenPos(160, 150);
193 vi->setTitleBarOn(0);
194 vi->setOneLiner(tr("Error playing recording"));
198 m->message = Message::ADD_VIEW;
200 m->parameter = (ULONG)vi;
201 Command::getInstance()->postMessageNoLock(m);
205 int VVideoRec::handleCommand(int command)
220 if (playing) stopPlay();
229 case Remote::SKIPFORWARD:
232 player->skipForward(60);
235 case Remote::SKIPBACK:
238 player->skipBackward(60);
241 case Remote::FORWARD:
243 if (isRadio) return 2;
244 player->fastForward();
248 case Remote::REVERSE:
250 if (isRadio) return 2;
251 player->fastBackward();
258 player->skipBackward(10);
264 player->skipForward(10);
275 if (isRadio) return 2;
282 if (barShowing) removeBar();
287 case Remote::ZERO: player->jumpToPercent(0); doBar(0); return 2;
288 case Remote::ONE: player->jumpToPercent(10); doBar(0); return 2;
289 case Remote::TWO: player->jumpToPercent(20); doBar(0); return 2;
290 case Remote::THREE: player->jumpToPercent(30); doBar(0); return 2;
291 case Remote::FOUR: player->jumpToPercent(40); doBar(0); return 2;
292 case Remote::FIVE: player->jumpToPercent(50); doBar(0); return 2;
293 case Remote::SIX: player->jumpToPercent(60); doBar(0); return 2;
294 case Remote::SEVEN: player->jumpToPercent(70); doBar(0); return 2;
295 case Remote::EIGHT: player->jumpToPercent(80); doBar(0); return 2;
296 case Remote::NINE: player->jumpToPercent(90); doBar(0); return 2;
301 //Don't use RED for anything. It will eventually be recording summary
307 // for testing EPG in NTSC with a NTSC test video
308 Video::getInstance()->setMode(Video::QUARTER);
309 Video::getInstance()->setPosition(170, 5);
310 VEpg* vepg = new VEpg(NULL, 0);
312 ViewMan::getInstance()->add(vepg);
313 ViewMan::getInstance()->updateView(vepg);
326 void VVideoRec::processMessage(Message* m)
328 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Message received");
330 if (m->from == player)
332 if (m->message != Message::PLAYER_EVENT) return;
335 case Player::CONNECTION_LOST: // connection lost detected
337 // I can't handle this, send it to command
338 Message* m = new Message();
339 m->to = Command::getInstance();
340 m->message = Message::CONNECTION_LOST;
341 Command::getInstance()->postMessageNoLock(m);
344 case Player::STOP_PLAYBACK:
346 // FIXME Obselete ish - improve this
347 Message* m = new Message(); // Must be done after this thread finishes, and must break into master mutex
348 m->to = Command::getInstance();
349 m->message = Message::STOP_PLAYBACK;
350 Command::getInstance()->postMessageNoLock(m);
353 case Player::ASPECT43:
357 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 43");
360 viewman->updateView(this, &wssRegion);
364 case Player::ASPECT169:
368 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 169");
371 viewman->updateView(this, &wssRegion);
377 else if (m->message == Message::AUDIO_CHANGE_CHANNEL)
379 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received change audio channel to %i", m->parameter);
380 player->setAudioChannel(m->parameter);
382 else if (m->message == Message::CHILD_CLOSE)
388 if (!barGenHold && !barScanHold && !barVasHold) removeBar();
393 void VVideoRec::stopPlay()
395 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Pre stopPlay");
397 // FIXME work out a better soln for this
398 // Fix a problem to do with thread sync here
399 // because the bar gets a timer every 0.2s and it seems to take up to 0.1s,
400 // (or maybe just the wrong thread being selected?) for the main loop to lock and process
401 // the video stop message it is possible for a bar message to stack up after a stop message
402 // when the bar message is finally processed the prog crashes because this is deleted by then
407 vdr->stopStreaming();
412 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
413 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Post stopPlay");
416 void VVideoRec::toggleChopSides()
418 if (video->getTVsize() == Video::ASPECT16X9) return; // Means nothing for 16:9 TVs
420 if (videoMode == Video::NORMAL)
422 videoMode = Video::LETTERBOX;
423 video->setMode(Video::LETTERBOX);
427 videoMode = Video::NORMAL;
428 video->setMode(Video::NORMAL);
432 void VVideoRec::doAudioSelector()
434 bool* availableAudioChannels = player->getDemuxerAudioChannels();
435 int currentAudioChannel = player->getCurrentAudioChannel();
437 vas = new VAudioSelector(this, availableAudioChannels, currentAudioChannel, myRec->recInfo);
438 vas->setBackgroundColour(barBlue);
439 if (video->getFormat() == Video::PAL)
441 // vas->setScreenPos(62, barRegion.y - 120);
442 vas->setScreenPos(0, barRegion.y - 120);
446 // vas->setScreenPos(57, barRegion.y - 120);
447 vas->setScreenPos(0, barRegion.y - 120);
455 viewman->updateView(vas);
458 void VVideoRec::doBar(int action)
462 rectangle(barRegion, barBlue);
464 /* Work out what to display - choices:
471 Specials, informed by parameter
481 w.setSurface(surface);
483 w.setSurfaceOffset(barRegion.x + 66, barRegion.y + 16);
485 UCHAR playerState = 0;
489 if (action == 1) w.nextSymbol = WSymbol::SKIPFORWARD;
490 else if (action == 2) w.nextSymbol = WSymbol::SKIPBACK;
491 else if (action == 3) w.nextSymbol = WSymbol::SKIPFORWARD2;
492 else if (action == 4) w.nextSymbol = WSymbol::SKIPBACK2;
496 playerState = player->getState();
497 if (playerState == Player::S_PAUSE_P) w.nextSymbol = WSymbol::PAUSE;
498 else if (playerState == Player::S_PAUSE_I) w.nextSymbol = WSymbol::PAUSE;
499 else if (playerState == Player::S_FFWD) w.nextSymbol = WSymbol::FFWD;
500 else if (playerState == Player::S_FBWD) w.nextSymbol = WSymbol::FBWD;
501 else w.nextSymbol = WSymbol::PLAY;
506 if ((playerState == Player::S_FFWD) || (playerState == Player::S_FBWD))
508 // draw blips to show how fast the scan is
509 UCHAR scanrate = player->getIScanRate();
512 char* text = new char[5];
513 SNPRINTF(text, 5, "%ux", scanrate);
514 drawText(text, barRegion.x + 102, barRegion.y + 12, Colour::LIGHTTEXT);
520 viewman->updateView(this, &barRegion);
522 timers->cancelTimer(this, 1);
525 if ((playerState == Player::S_FFWD) || (playerState == Player::S_FBWD)) barScanHold = true;
526 else barScanHold = false;
528 if (!barGenHold && !barScanHold && !barVasHold) timers->setTimerD(this, 1, 4);
530 timers->setTimerD(this, 2, 0, 200000000);
533 void VVideoRec::timercall(int clientReference)
535 switch(clientReference)
546 if (!barShowing) break;
548 viewman->updateView(this, &barRegion);
549 timers->setTimerD(this, 2, 0, 200000000);
555 void VVideoRec::drawBarClocks()
559 UCHAR playerState = player->getState();
560 // sticky bar is set if we are in ffwd/fbwd mode
561 // if player has gone to S_PLAY then kill stickyBar, and run doBar(0) which
562 // will repaint all the bar (it will call this function again, but
563 // this section won't run because stickyBarF will then == false)
565 if ((playerState != Player::S_FFWD) && (playerState != Player::S_FBWD))
569 return; // doBar will call this function and do the rest
573 Log* logger = Log::getInstance();
574 logger->log("VVideoRec", Log::DEBUG, "Draw bar clocks");
577 // Blank the area first
578 rectangle(barRegion.x + 624, barRegion.y + 12, 60, 30, barBlue);
582 struct tm* tms = localtime(&t);
583 strftime(timeString, 19, "%H:%M", tms);
584 drawText(timeString, barRegion.x + 624, barRegion.y + 12, Colour::LIGHTTEXT);
588 rectangle(clocksRegion, barBlue);
590 ULONG currentFrameNum = player->getCurrentFrameNum();
592 if (myRec->recInfo->timerEnd > time(NULL))
595 // Work out an approximate length in frames (good to 1s...)
596 lengthFrames = (myRec->recInfo->timerEnd - myRec->recInfo->timerStart) * video->getFPS();
600 lengthFrames = player->getLengthFrames();
603 hmsf currentFrameHMSF = video->framesToHMSF(currentFrameNum);
604 hmsf lengthHMSF = video->framesToHMSF(lengthFrames);
607 if (currentFrameNum >= lengthFrames)
609 strcpy(buffer, "-:--:-- / -:--:--");
613 SNPRINTF(buffer, 99, "%01i:%02i:%02i / %01i:%02i:%02i", currentFrameHMSF.hours, currentFrameHMSF.minutes, currentFrameHMSF.seconds, lengthHMSF.hours, lengthHMSF.minutes, lengthHMSF.seconds);
614 logger->log("VVideoRec", Log::DEBUG, buffer);
617 drawText(buffer, clocksRegion.x, clocksRegion.y, Colour::LIGHTTEXT);
626 int progBarXbase = barRegion.x + 300;
628 rectangle(barRegion.x + progBarXbase, barRegion.y + 12, 310, 24, Colour::LIGHTTEXT);
629 rectangle(barRegion.x + progBarXbase + 2, barRegion.y + 14, 306, 20, barBlue);
631 if (currentFrameNum > lengthFrames) return;
632 if (lengthFrames == 0) return;
634 // Draw yellow portion
635 int progressWidth = 302 * currentFrameNum / lengthFrames;
636 rectangle(barRegion.x + progBarXbase + 4, barRegion.y + 16, progressWidth, 16, Colour::SELECTHIGHLIGHT);
638 if (myRec->recInfo->timerEnd > time(NULL)) // if chasing
640 int nrWidth = (int)(302 * ((double)(lengthFrames - player->getLengthFrames()) / lengthFrames));
642 Log::getInstance()->log("GVASDF", Log::DEBUG, "Length Frames: %lu", lengthFrames);
643 Log::getInstance()->log("GVASDF", Log::DEBUG, "Player lf: %lu", player->getLengthFrames());
644 Log::getInstance()->log("GVASDF", Log::DEBUG, "NR WDITH: %i", nrWidth);
645 rectangle(barRegion.x + progBarXbase + 4 + 302 - nrWidth, barRegion.y + 16, nrWidth, 16, Colour::RED);
648 // Now calc position for start margin blips
651 posPix = 302 * startMargin * video->getFPS() / lengthFrames;
653 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 2, 2, Colour::LIGHTTEXT);
654 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 + 24, 2, 2, Colour::LIGHTTEXT);
656 posPix = 302 * (lengthFrames - endMargin * video->getFPS()) / lengthFrames;
658 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 2, 2, Colour::LIGHTTEXT);
659 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 + 24, 2, 2, Colour::LIGHTTEXT);
662 void VVideoRec::removeBar()
664 if (!barShowing) return;
665 timers->cancelTimer(this, 2);
670 rectangle(barRegion, transparent);
671 viewman->updateView(this, &barRegion);