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 vdr = VDR::getInstance();
26 video = Video::getInstance();
27 timers = Timers::getInstance();
29 // TODO Work out if is a radio stream
31 player = new Player(Command::getInstance(), this, true, false);
34 videoMode = video->getMode();
41 char* cstartMargin = vdr->configLoad("Timers", "Start margin");
42 char* cendMargin = vdr->configLoad("Timers", "End margin");
45 startMargin = 300; // 5 mins default
49 startMargin = atoi(cstartMargin) * 60;
50 delete[] cstartMargin;
55 endMargin = 300; // 5 mins default
59 endMargin = atoi(cendMargin) * 60;
63 Log::getInstance()->log("VVideoRec", Log::DEBUG, "SM: %u EM: %u", startMargin, endMargin);
65 create(video->getScreenWidth(), video->getScreenHeight());
66 transparent.set(0, 0, 0, 0);
67 setBackgroundColour(transparent);
70 barRegion.y = video->getScreenHeight() - 58; // FIXME, need to be - 1? and below?
71 barRegion.w = video->getScreenWidth();
74 clocksRegion.x = barRegion.x + 140;
75 clocksRegion.y = barRegion.y + 12;
77 clocksRegion.h = surface->getFontHeight();
80 barBlue.set(0, 0, 150, 150);
85 wss.setSurface(surface);
90 wssRegion.w = video->getScreenWidth();
94 VVideoRec::~VVideoRec()
96 if (playing) stopPlay();
97 video->setDefaultAspect();
99 timers->cancelTimer(this, 1);
100 timers->cancelTimer(this, 2);
102 // kill recInfo in case resumePoint has changed (likely)
103 myRec->dropRecInfo();
104 // FIXME - do this properly - save the resume point back to the server manually and update
105 // rec->recInfo->resumePoint - this will fix the ~10s offset problem as well
108 void VVideoRec::draw()
113 void VVideoRec::go(ULONG startFrameNum)
115 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Starting stream: %s at frame: %lu", myRec->getFileName(), startFrameNum);
116 ULONG lengthFrames = 0;
117 ULLONG lengthBytes = vdr->streamRecording(myRec->getFileName(), &lengthFrames);
121 player->setLengthBytes(lengthBytes);
122 player->setLengthFrames(lengthFrames);
123 player->setStartFrame(startFrameNum);
129 stopPlay(); // clean up
131 if (!vdr->isConnected())
133 Command::getInstance()->connectionLost();
137 ViewMan* viewman = ViewMan::getInstance();
139 Message* m = new Message();
140 m->message = Message::CLOSE_ME;
143 Command::getInstance()->postMessageNoLock(m);
145 VInfo* vi = new VInfo();
146 vi->create(400, 150);
147 if (video->getFormat() == Video::PAL)
148 vi->setScreenPos(170, 200);
150 vi->setScreenPos(160, 150);
153 vi->setTitleBarOn(0);
154 vi->setOneLiner(tr("Error playing recording"));
158 m->message = Message::ADD_VIEW;
160 m->parameter = (ULONG)vi;
161 Command::getInstance()->postMessageNoLock(m);
165 int VVideoRec::handleCommand(int command)
180 if (playing) stopPlay();
189 case Remote::SKIPFORWARD:
192 player->skipForward(60);
195 case Remote::SKIPBACK:
198 player->skipBackward(60);
201 case Remote::FORWARD:
203 player->fastForward();
207 case Remote::REVERSE:
209 player->fastBackward();
216 player->skipBackward(10);
222 player->skipForward(10);
234 if (barShowing) removeBar();
239 case Remote::ZERO: player->jumpToPercent(0); doBar(0); return 2;
240 case Remote::ONE: player->jumpToPercent(10); doBar(0); return 2;
241 case Remote::TWO: player->jumpToPercent(20); doBar(0); return 2;
242 case Remote::THREE: player->jumpToPercent(30); doBar(0); return 2;
243 case Remote::FOUR: player->jumpToPercent(40); doBar(0); return 2;
244 case Remote::FIVE: player->jumpToPercent(50); doBar(0); return 2;
245 case Remote::SIX: player->jumpToPercent(60); doBar(0); return 2;
246 case Remote::SEVEN: player->jumpToPercent(70); doBar(0); return 2;
247 case Remote::EIGHT: player->jumpToPercent(80); doBar(0); return 2;
248 case Remote::NINE: player->jumpToPercent(90); doBar(0); return 2;
257 // for testing EPG in NTSC with a NTSC test video
258 Video::getInstance()->setMode(Video::QUARTER);
259 Video::getInstance()->setPosition(170, 5);
260 VEpg* vepg = new VEpg(NULL, 0);
262 ViewMan::getInstance()->add(vepg);
263 ViewMan::getInstance()->updateView(vepg);
280 void VVideoRec::processMessage(Message* m)
282 if (m->from != player) return;
283 if (m->message != Message::PLAYER_EVENT) return;
285 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Message received");
289 case Player::CONNECTION_LOST: // connection lost detected
291 // I can't handle this, send it to command
292 Message* m = new Message();
293 m->to = Command::getInstance();
294 m->message = Message::CONNECTION_LOST;
295 Command::getInstance()->postMessageNoLock(m);
298 case Player::STOP_PLAYBACK:
300 // FIXME Obselete ish - improve this
301 Message* m = new Message(); // Must be done after this thread finishes, and must break into master mutex
302 m->to = Command::getInstance();
303 m->message = Message::STOP_PLAYBACK;
304 Command::getInstance()->postMessageNoLock(m);
307 case Player::ASPECT43:
309 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 43");
312 ViewMan::getInstance()->updateView(this, &wssRegion);
315 case Player::ASPECT169:
317 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 169");
320 ViewMan::getInstance()->updateView(this, &wssRegion);
326 void VVideoRec::stopPlay()
328 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Pre stopPlay");
330 // FIXME work out a better soln for this
331 // Fix a problem to do with thread sync here
332 // because the bar gets a timer every 0.2s and it seems to take up to 0.1s,
333 // (or maybe just the wrong thread being selected?) for the main loop to lock and process
334 // the video stop message it is possible for a bar message to stack up after a stop message
335 // when the bar message is finally processed the prog crashes because this is deleted by then
340 vdr->stopStreaming();
345 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
346 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Post stopPlay");
349 void VVideoRec::toggleChopSides()
351 if (video->getTVsize() == Video::ASPECT16X9) return; // Means nothing for 16:9 TVs
353 if (videoMode == Video::NORMAL)
355 videoMode = Video::LETTERBOX;
356 video->setMode(Video::LETTERBOX);
360 videoMode = Video::NORMAL;
361 video->setMode(Video::NORMAL);
365 void VVideoRec::doBar(int action)
369 rectangle(barRegion, barBlue);
371 /* Work out what to display - choices:
378 Specials, informed by parameter
388 w.setSurface(surface);
390 w.setSurfaceOffset(barRegion.x + 66, barRegion.y + 16);
392 UCHAR playerState = 0;
396 if (action == 1) w.nextSymbol = WSymbol::SKIPFORWARD;
397 else if (action == 2) w.nextSymbol = WSymbol::SKIPBACK;
398 else if (action == 3) w.nextSymbol = WSymbol::SKIPFORWARD2;
399 else if (action == 4) w.nextSymbol = WSymbol::SKIPBACK2;
403 playerState = player->getState();
404 if (playerState == Player::S_PAUSE_P) w.nextSymbol = WSymbol::PAUSE;
405 else if (playerState == Player::S_PAUSE_I) w.nextSymbol = WSymbol::PAUSE;
406 else if (playerState == Player::S_FFWD) w.nextSymbol = WSymbol::FFWD;
407 else if (playerState == Player::S_FBWD) w.nextSymbol = WSymbol::FBWD;
408 else w.nextSymbol = WSymbol::PLAY;
413 if ((playerState == Player::S_FFWD) || (playerState == Player::S_FBWD))
415 // draw blips to show how fast the scan is
416 UCHAR scanrate = player->getIScanRate();
419 char* text = new char[5];
420 SNPRINTF(text, 5, "%ux", scanrate);
421 drawText(text, barRegion.x + 102, barRegion.y + 12, Colour::LIGHTTEXT);
427 ViewMan::getInstance()->updateView(this, &barRegion);
429 if ((playerState == Player::S_FFWD) || (playerState == Player::S_FBWD))
431 timers->cancelTimer(this, 1);
436 timers->setTimerD(this, 1, 4); // only set the getridofbar timer if not ffwd/fbwd
439 timers->setTimerD(this, 2, 0, 200000000);
442 void VVideoRec::timercall(int clientReference)
444 switch(clientReference)
455 if (!barShowing) break;
457 ViewMan::getInstance()->updateView(this, &barRegion);
458 timers->setTimerD(this, 2, 0, 200000000);
464 void VVideoRec::drawBarClocks()
468 UCHAR playerState = player->getState();
469 // sticky bar is set if we are in ffwd/fbwd mode
470 // if player has gone to S_PLAY then kill stickyBar, and run doBar(0) which
471 // will repaint all the bar (it will call this function again, but
472 // this section won't run because stickyBar will then == false)
474 if ((playerState != Player::S_FFWD) && (playerState != Player::S_FBWD))
478 return; // doBar will call this function and do the rest
482 Log* logger = Log::getInstance();
483 logger->log("VVideoRec", Log::DEBUG, "Draw bar clocks");
486 // Blank the area first
487 rectangle(barRegion.x + 624, barRegion.y + 12, 60, 30, barBlue);
491 struct tm* tms = localtime(&t);
492 strftime(timeString, 19, "%H:%M", tms);
493 drawText(timeString, barRegion.x + 624, barRegion.y + 12, Colour::LIGHTTEXT);
497 rectangle(clocksRegion, barBlue);
499 ULONG currentFrameNum = player->getCurrentFrameNum();
501 if (myRec->recInfo->timerEnd > time(NULL))
504 // Work out an approximate length in frames (good to 1s...)
505 lengthFrames = (myRec->recInfo->timerEnd - myRec->recInfo->timerStart) * video->getFPS();
509 lengthFrames = player->getLengthFrames();
512 hmsf currentFrameHMSF = video->framesToHMSF(currentFrameNum);
513 hmsf lengthHMSF = video->framesToHMSF(lengthFrames);
516 if (currentFrameNum >= lengthFrames)
518 strcpy(buffer, "-:--:-- / -:--:--");
522 SNPRINTF(buffer, 99, "%01i:%02i:%02i / %01i:%02i:%02i", currentFrameHMSF.hours, currentFrameHMSF.minutes, currentFrameHMSF.seconds, lengthHMSF.hours, lengthHMSF.minutes, lengthHMSF.seconds);
523 logger->log("VVideoRec", Log::DEBUG, buffer);
526 drawText(buffer, clocksRegion.x, clocksRegion.y, Colour::LIGHTTEXT);
535 int progBarXbase = barRegion.x + 300;
537 rectangle(barRegion.x + progBarXbase, barRegion.y + 12, 310, 24, Colour::LIGHTTEXT);
538 rectangle(barRegion.x + progBarXbase + 2, barRegion.y + 14, 306, 20, barBlue);
540 if (currentFrameNum > lengthFrames) return;
543 // Draw yellow portion
544 int progressWidth = 302 * currentFrameNum / lengthFrames;
545 rectangle(barRegion.x + progBarXbase + 4, barRegion.y + 16, progressWidth, 16, Colour::SELECTHIGHLIGHT);
547 if (myRec->recInfo->timerEnd > time(NULL)) // if chasing
549 int nrWidth = (int)(302 * ((double)(lengthFrames - player->getLengthFrames()) / lengthFrames));
551 Log::getInstance()->log("GVASDF", Log::DEBUG, "Length Frames: %lu", lengthFrames);
552 Log::getInstance()->log("GVASDF", Log::DEBUG, "Player lf: %lu", player->getLengthFrames());
553 Log::getInstance()->log("GVASDF", Log::DEBUG, "NR WDITH: %i", nrWidth);
554 rectangle(barRegion.x + progBarXbase + 4 + 302 - nrWidth, barRegion.y + 16, nrWidth, 16, Colour::RED);
557 // Now calc position for start margin blips
560 posPix = 302 * startMargin * video->getFPS() / lengthFrames;
562 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 2, 2, Colour::LIGHTTEXT);
563 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 + 24, 2, 2, Colour::LIGHTTEXT);
565 posPix = 302 * (lengthFrames - endMargin * video->getFPS()) / lengthFrames;
567 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 2, 2, Colour::LIGHTTEXT);
568 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 + 24, 2, 2, Colour::LIGHTTEXT);
571 void VVideoRec::removeBar()
573 if (!barShowing) return;
574 timers->cancelTimer(this, 2);
577 rectangle(barRegion, transparent);
578 ViewMan::getInstance()->updateView(this, &barRegion);