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(), 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();
79 barBlue.set(0, 0, 150, 150);
85 VVideoRec::~VVideoRec()
87 if (playing) stopPlay();
88 video->setDefaultAspect();
90 timers->cancelTimer(this, 1);
91 timers->cancelTimer(this, 2);
93 // kill recInfo in case resumePoint has changed (likely)
95 // FIXME - do this properly - save the resume point back to the server manually and update
96 // rec->recInfo->resumePoint - this will fix the ~10s offset problem as well
99 void VVideoRec::draw()
104 void VVideoRec::go(ULONG startFrameNum)
106 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Starting stream: %s at frame: %lu", myRec->getFileName(), startFrameNum);
107 ULONG lengthFrames = 0;
108 ULLONG lengthBytes = vdr->streamRecording(myRec->getFileName(), &lengthFrames);
112 player->setLengthBytes(lengthBytes);
113 player->setLengthFrames(lengthFrames);
114 player->setStartFrame(startFrameNum);
120 stopPlay(); // clean up
122 if (!vdr->isConnected())
124 Command::getInstance()->connectionLost();
128 ViewMan* viewman = ViewMan::getInstance();
130 Message* m = new Message();
131 m->message = Message::CLOSE_ME;
134 viewman->postMessage(m);
136 VInfo* vi = new VInfo();
137 vi->create(400, 150);
138 if (video->getFormat() == Video::PAL)
139 vi->setScreenPos(170, 200);
141 vi->setScreenPos(160, 150);
144 vi->setTitleBarOn(0);
145 vi->setOneLiner(tr("Error playing recording"));
149 m->message = Message::ADD_VIEW;
151 m->parameter = (ULONG)vi;
152 viewman->postMessage(m);
156 int VVideoRec::handleCommand(int command)
171 if (playing) stopPlay();
180 case Remote::SKIPFORWARD:
183 player->skipForward(60);
186 case Remote::SKIPBACK:
189 player->skipBackward(60);
192 case Remote::FORWARD:
194 player->fastForward();
198 case Remote::REVERSE:
200 player->fastBackward();
207 player->skipBackward(10);
213 player->skipForward(10);
225 if (barShowing) removeBar();
230 case Remote::ZERO: player->jumpToPercent(0); doBar(0); return 2;
231 case Remote::ONE: player->jumpToPercent(10); doBar(0); return 2;
232 case Remote::TWO: player->jumpToPercent(20); doBar(0); return 2;
233 case Remote::THREE: player->jumpToPercent(30); doBar(0); return 2;
234 case Remote::FOUR: player->jumpToPercent(40); doBar(0); return 2;
235 case Remote::FIVE: player->jumpToPercent(50); doBar(0); return 2;
236 case Remote::SIX: player->jumpToPercent(60); doBar(0); return 2;
237 case Remote::SEVEN: player->jumpToPercent(70); doBar(0); return 2;
238 case Remote::EIGHT: player->jumpToPercent(80); doBar(0); return 2;
239 case Remote::NINE: player->jumpToPercent(90); doBar(0); return 2;
247 // for testing EPG in NTSC with a NTSC test video
248 Video::getInstance()->setMode(Video::QUARTER);
249 Video::getInstance()->setPosition(170, 5);
250 VEpg* vepg = new VEpg(NULL, 0);
252 ViewMan::getInstance()->add(vepg);
253 ViewMan::getInstance()->updateView(vepg);
270 void VVideoRec::stopPlay()
272 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Pre stopPlay");
274 // FIXME work out a better soln for this
275 // Fix a problem to do with thread sync here
276 // because the bar gets a timer every 0.2s and it seems to take up to 0.1s,
277 // (or maybe just the wrong thread being selected?) for the main loop to lock and process
278 // the video stop message it is possible for a bar message to stack up after a stop message
279 // when the bar message is finally processed the prog crashes because this is deleted by then
284 vdr->stopStreaming();
289 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
290 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Post stopPlay");
293 void VVideoRec::toggleChopSides()
295 if (video->getTVsize() == Video::ASPECT16X9) return; // Means nothing for 16:9 TVs
297 if (videoMode == Video::NORMAL)
299 videoMode = Video::LETTERBOX;
300 video->setMode(Video::LETTERBOX);
304 videoMode = Video::NORMAL;
305 video->setMode(Video::NORMAL);
309 void VVideoRec::doBar(int action)
313 rectangle(barRegion, barBlue);
315 /* Work out what to display - choices:
322 Specials, informed by parameter
332 w.setSurface(surface);
334 w.setSurfaceOffset(barRegion.x + 66, barRegion.y + 16);
336 UCHAR playerState = 0;
340 if (action == 1) w.nextSymbol = WSymbol::SKIPFORWARD;
341 else if (action == 2) w.nextSymbol = WSymbol::SKIPBACK;
342 else if (action == 3) w.nextSymbol = WSymbol::SKIPFORWARD2;
343 else if (action == 4) w.nextSymbol = WSymbol::SKIPBACK2;
347 playerState = player->getState();
348 if (playerState == Player::S_PAUSE_P) w.nextSymbol = WSymbol::PAUSE;
349 else if (playerState == Player::S_PAUSE_I) w.nextSymbol = WSymbol::PAUSE;
350 else if (playerState == Player::S_FFWD) w.nextSymbol = WSymbol::FFWD;
351 else if (playerState == Player::S_FBWD) w.nextSymbol = WSymbol::FBWD;
352 else w.nextSymbol = WSymbol::PLAY;
357 if ((playerState == Player::S_FFWD) || (playerState == Player::S_FBWD))
359 // draw blips to show how fast the scan is
360 UCHAR scanrate = player->getIScanRate();
363 char* text = new char[5];
364 SNPRINTF(text, 5, "%ux", scanrate);
365 drawText(text, barRegion.x + 102, barRegion.y + 12, Colour::LIGHTTEXT);
371 ViewMan::getInstance()->updateView(this, &barRegion);
373 if ((playerState == Player::S_FFWD) || (playerState == Player::S_FBWD))
375 timers->cancelTimer(this, 1);
380 timers->setTimerD(this, 1, 4); // only set the getridofbar timer if not ffwd/fbwd
383 timers->setTimerD(this, 2, 0, 200000000);
386 void VVideoRec::timercall(int clientReference)
388 switch(clientReference)
399 if (!barShowing) break;
401 ViewMan::getInstance()->updateView(this, &barRegion);
402 timers->setTimerD(this, 2, 0, 200000000);
408 void VVideoRec::drawBarClocks()
412 UCHAR playerState = player->getState();
413 // sticky bar is set if we are in ffwd/fbwd mode
414 // if player has gone to S_PLAY then kill stickyBar, and run doBar(0) which
415 // will repaint all the bar (it will call this function again, but
416 // this section won't run because stickyBar will then == false)
418 if ((playerState != Player::S_FFWD) && (playerState != Player::S_FBWD))
422 return; // doBar will call this function and do the rest
426 Log* logger = Log::getInstance();
427 logger->log("VVideoRec", Log::DEBUG, "Draw bar clocks");
430 // Blank the area first
431 rectangle(barRegion.x + 624, barRegion.y + 12, 60, 30, barBlue);
435 struct tm* tms = localtime(&t);
436 strftime(timeString, 19, "%H:%M", tms);
437 drawText(timeString, barRegion.x + 624, barRegion.y + 12, Colour::LIGHTTEXT);
441 rectangle(clocksRegion, barBlue);
443 ULONG currentFrameNum = player->getCurrentFrameNum();
444 ULONG lengthFrames = player->getLengthFrames();
446 hmsf currentFrameHMSF = video->framesToHMSF(currentFrameNum);
447 hmsf lengthHMSF = video->framesToHMSF(lengthFrames);
450 if (currentFrameNum >= lengthFrames)
452 strcpy(buffer, "-:--:-- / -:--:--");
456 SNPRINTF(buffer, 99, "%01i:%02i:%02i / %01i:%02i:%02i", currentFrameHMSF.hours, currentFrameHMSF.minutes, currentFrameHMSF.seconds, lengthHMSF.hours, lengthHMSF.minutes, lengthHMSF.seconds);
457 logger->log("VVideoRec", Log::DEBUG, buffer);
460 drawText(buffer, clocksRegion.x, clocksRegion.y, Colour::LIGHTTEXT);
469 int progBarXbase = barRegion.x + 300;
471 rectangle(barRegion.x + progBarXbase, barRegion.y + 12, 310, 24, Colour::LIGHTTEXT);
472 rectangle(barRegion.x + progBarXbase + 2, barRegion.y + 14, 306, 20, barBlue);
474 if (currentFrameNum < lengthFrames)
477 int progressWidth = 302 * currentFrameNum / lengthFrames;
479 rectangle(barRegion.x + progBarXbase + 4, barRegion.y + 16, progressWidth, 16, Colour::SELECTHIGHLIGHT);
481 // Now calc position for start margin blips
484 posPix = 302 * startMargin * video->getFPS() / lengthFrames;
486 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 2, 2, Colour::LIGHTTEXT);
487 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 + 24, 2, 2, Colour::LIGHTTEXT);
489 posPix = 302 * (lengthFrames - endMargin * video->getFPS()) / lengthFrames;
491 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 2, 2, Colour::LIGHTTEXT);
492 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 + 24, 2, 2, Colour::LIGHTTEXT);
496 void VVideoRec::removeBar()
498 if (!barShowing) return;
499 timers->cancelTimer(this, 2);
502 rectangle(barRegion, transparent);
503 ViewMan::getInstance()->updateView(this, &barRegion);