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()
114 void VVideoRec::go(ULONG startFrameNum)
116 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Starting stream: %s at frame: %lu", myRec->getFileName(), startFrameNum);
117 ULONG lengthFrames = 0;
118 ULLONG lengthBytes = vdr->streamRecording(myRec->getFileName(), &lengthFrames);
122 player->setLengthBytes(lengthBytes);
123 player->setLengthFrames(lengthFrames);
124 player->setStartFrame(startFrameNum);
130 stopPlay(); // clean up
132 if (!vdr->isConnected())
134 Command::getInstance()->connectionLost();
138 ViewMan* viewman = ViewMan::getInstance();
140 Message* m = new Message();
141 m->message = Message::CLOSE_ME;
144 Command::getInstance()->postMessageNoLock(m);
146 VInfo* vi = new VInfo();
147 vi->create(400, 150);
148 if (video->getFormat() == Video::PAL)
149 vi->setScreenPos(170, 200);
151 vi->setScreenPos(160, 150);
154 vi->setTitleBarOn(0);
155 vi->setOneLiner(tr("Error playing recording"));
159 m->message = Message::ADD_VIEW;
161 m->parameter = (ULONG)vi;
162 Command::getInstance()->postMessageNoLock(m);
166 int VVideoRec::handleCommand(int command)
181 if (playing) stopPlay();
190 case Remote::SKIPFORWARD:
193 player->skipForward(60);
196 case Remote::SKIPBACK:
199 player->skipBackward(60);
202 case Remote::FORWARD:
204 player->fastForward();
208 case Remote::REVERSE:
210 player->fastBackward();
217 player->skipBackward(10);
223 player->skipForward(10);
235 if (barShowing) removeBar();
240 case Remote::ZERO: player->jumpToPercent(0); doBar(0); return 2;
241 case Remote::ONE: player->jumpToPercent(10); doBar(0); return 2;
242 case Remote::TWO: player->jumpToPercent(20); doBar(0); return 2;
243 case Remote::THREE: player->jumpToPercent(30); doBar(0); return 2;
244 case Remote::FOUR: player->jumpToPercent(40); doBar(0); return 2;
245 case Remote::FIVE: player->jumpToPercent(50); doBar(0); return 2;
246 case Remote::SIX: player->jumpToPercent(60); doBar(0); return 2;
247 case Remote::SEVEN: player->jumpToPercent(70); doBar(0); return 2;
248 case Remote::EIGHT: player->jumpToPercent(80); doBar(0); return 2;
249 case Remote::NINE: player->jumpToPercent(90); doBar(0); return 2;
255 Video::getInstance()->setAspectRatio(Video::ASPECT4X3);
259 // for testing EPG in NTSC with a NTSC test video
260 Video::getInstance()->setMode(Video::QUARTER);
261 Video::getInstance()->setPosition(170, 5);
262 VEpg* vepg = new VEpg(NULL, 0);
264 ViewMan::getInstance()->add(vepg);
265 ViewMan::getInstance()->updateView(vepg);
272 Video::getInstance()->setAspectRatio(Video::ASPECT16X9);
283 void VVideoRec::processMessage(Message* m)
285 if (m->from != player) return;
286 if (m->message != Message::PLAYER_EVENT) return;
288 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Message received");
292 case Player::CONNECTION_LOST: // connection lost detected
294 // I can't handle this, send it to command
295 Message* m = new Message();
296 m->to = Command::getInstance();
297 m->message = Message::CONNECTION_LOST;
298 Command::getInstance()->postMessageNoLock(m);
301 case Player::STOP_PLAYBACK:
303 // Obselete ish - improve this
304 Message* m = new Message(); // Must be done after this thread finishes, and must break into master mutex
305 m->to = Command::getInstance();
306 m->message = Message::STOP_PLAYBACK;
307 Command::getInstance()->postMessageNoLock(m);
310 case Player::ASPECT43:
312 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 43");
315 ViewMan::getInstance()->updateView(this, &wssRegion);
316 Log::getInstance()->log("VVideoRec", Log::DEBUG, "WSS done");
319 case Player::ASPECT169:
321 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 169");
324 ViewMan::getInstance()->updateView(this, &wssRegion);
325 Log::getInstance()->log("VVideoRec", Log::DEBUG, "WSS done");
331 void VVideoRec::stopPlay()
333 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Pre stopPlay");
335 // FIXME work out a better soln for this
336 // Fix a problem to do with thread sync here
337 // because the bar gets a timer every 0.2s and it seems to take up to 0.1s,
338 // (or maybe just the wrong thread being selected?) for the main loop to lock and process
339 // the video stop message it is possible for a bar message to stack up after a stop message
340 // when the bar message is finally processed the prog crashes because this is deleted by then
345 vdr->stopStreaming();
350 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
351 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Post stopPlay");
354 void VVideoRec::toggleChopSides()
356 if (video->getTVsize() == Video::ASPECT16X9) return; // Means nothing for 16:9 TVs
358 if (videoMode == Video::NORMAL)
360 videoMode = Video::LETTERBOX;
361 video->setMode(Video::LETTERBOX);
365 videoMode = Video::NORMAL;
366 video->setMode(Video::NORMAL);
370 void VVideoRec::doBar(int action)
374 rectangle(barRegion, barBlue);
376 /* Work out what to display - choices:
383 Specials, informed by parameter
393 w.setSurface(surface);
395 w.setSurfaceOffset(barRegion.x + 66, barRegion.y + 16);
397 UCHAR playerState = 0;
401 if (action == 1) w.nextSymbol = WSymbol::SKIPFORWARD;
402 else if (action == 2) w.nextSymbol = WSymbol::SKIPBACK;
403 else if (action == 3) w.nextSymbol = WSymbol::SKIPFORWARD2;
404 else if (action == 4) w.nextSymbol = WSymbol::SKIPBACK2;
408 playerState = player->getState();
409 if (playerState == Player::S_PAUSE_P) w.nextSymbol = WSymbol::PAUSE;
410 else if (playerState == Player::S_PAUSE_I) w.nextSymbol = WSymbol::PAUSE;
411 else if (playerState == Player::S_FFWD) w.nextSymbol = WSymbol::FFWD;
412 else if (playerState == Player::S_FBWD) w.nextSymbol = WSymbol::FBWD;
413 else w.nextSymbol = WSymbol::PLAY;
418 if ((playerState == Player::S_FFWD) || (playerState == Player::S_FBWD))
420 // draw blips to show how fast the scan is
421 UCHAR scanrate = player->getIScanRate();
424 char* text = new char[5];
425 SNPRINTF(text, 5, "%ux", scanrate);
426 drawText(text, barRegion.x + 102, barRegion.y + 12, Colour::LIGHTTEXT);
432 ViewMan::getInstance()->updateView(this, &barRegion);
434 if ((playerState == Player::S_FFWD) || (playerState == Player::S_FBWD))
436 timers->cancelTimer(this, 1);
441 timers->setTimerD(this, 1, 4); // only set the getridofbar timer if not ffwd/fbwd
444 timers->setTimerD(this, 2, 0, 200000000);
447 void VVideoRec::timercall(int clientReference)
449 switch(clientReference)
460 if (!barShowing) break;
462 ViewMan::getInstance()->updateView(this, &barRegion);
463 timers->setTimerD(this, 2, 0, 200000000);
469 void VVideoRec::drawBarClocks()
473 UCHAR playerState = player->getState();
474 // sticky bar is set if we are in ffwd/fbwd mode
475 // if player has gone to S_PLAY then kill stickyBar, and run doBar(0) which
476 // will repaint all the bar (it will call this function again, but
477 // this section won't run because stickyBar will then == false)
479 if ((playerState != Player::S_FFWD) && (playerState != Player::S_FBWD))
483 return; // doBar will call this function and do the rest
487 Log* logger = Log::getInstance();
488 logger->log("VVideoRec", Log::DEBUG, "Draw bar clocks");
491 // Blank the area first
492 rectangle(barRegion.x + 624, barRegion.y + 12, 60, 30, barBlue);
496 struct tm* tms = localtime(&t);
497 strftime(timeString, 19, "%H:%M", tms);
498 drawText(timeString, barRegion.x + 624, barRegion.y + 12, Colour::LIGHTTEXT);
502 rectangle(clocksRegion, barBlue);
504 ULONG currentFrameNum = player->getCurrentFrameNum();
506 if (myRec->recInfo->timerEnd > time(NULL))
509 // Work out an approximate length in frames (good to 1s...)
510 lengthFrames = (myRec->recInfo->timerEnd - myRec->recInfo->timerStart) * video->getFPS();
514 lengthFrames = player->getLengthFrames();
517 hmsf currentFrameHMSF = video->framesToHMSF(currentFrameNum);
518 hmsf lengthHMSF = video->framesToHMSF(lengthFrames);
521 if (currentFrameNum >= lengthFrames)
523 strcpy(buffer, "-:--:-- / -:--:--");
527 SNPRINTF(buffer, 99, "%01i:%02i:%02i / %01i:%02i:%02i", currentFrameHMSF.hours, currentFrameHMSF.minutes, currentFrameHMSF.seconds, lengthHMSF.hours, lengthHMSF.minutes, lengthHMSF.seconds);
528 logger->log("VVideoRec", Log::DEBUG, buffer);
531 drawText(buffer, clocksRegion.x, clocksRegion.y, Colour::LIGHTTEXT);
540 int progBarXbase = barRegion.x + 300;
542 rectangle(barRegion.x + progBarXbase, barRegion.y + 12, 310, 24, Colour::LIGHTTEXT);
543 rectangle(barRegion.x + progBarXbase + 2, barRegion.y + 14, 306, 20, barBlue);
545 if (currentFrameNum > lengthFrames) return;
548 // Draw yellow portion
549 int progressWidth = 302 * currentFrameNum / lengthFrames;
550 rectangle(barRegion.x + progBarXbase + 4, barRegion.y + 16, progressWidth, 16, Colour::SELECTHIGHLIGHT);
552 if (myRec->recInfo->timerEnd > time(NULL)) // if chasing
554 int nrWidth = (int)(302 * ((double)(lengthFrames - player->getLengthFrames()) / lengthFrames));
556 Log::getInstance()->log("GVASDF", Log::DEBUG, "Length Frames: %lu", lengthFrames);
557 Log::getInstance()->log("GVASDF", Log::DEBUG, "Player lf: %lu", player->getLengthFrames());
558 Log::getInstance()->log("GVASDF", Log::DEBUG, "NR WDITH: %i", nrWidth);
559 rectangle(barRegion.x + progBarXbase + 4 + 302 - nrWidth, barRegion.y + 16, nrWidth, 16, Colour::RED);
562 // Now calc position for start margin blips
565 posPix = 302 * startMargin * 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);
570 posPix = 302 * (lengthFrames - endMargin * video->getFPS()) / lengthFrames;
572 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 2, 2, Colour::LIGHTTEXT);
573 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 + 24, 2, 2, Colour::LIGHTTEXT);
576 void VVideoRec::removeBar()
578 if (!barShowing) return;
579 timers->cancelTimer(this, 2);
582 rectangle(barRegion, transparent);
583 ViewMan::getInstance()->updateView(this, &barRegion);