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 player = new Player(Command::getInstance(), true, false); // say 0 for radio because buffering will work anyway
32 videoMode = video->getMode();
39 char* cstartMargin = vdr->configLoad("Timers", "Start margin");
40 char* cendMargin = vdr->configLoad("Timers", "End margin");
43 startMargin = 300; // 5 mins default
47 startMargin = atoi(cstartMargin) * 60;
48 delete[] cstartMargin;
53 endMargin = 300; // 5 mins default
57 endMargin = atoi(cendMargin) * 60;
61 Log::getInstance()->log("VVideoRec", Log::DEBUG, "SM: %u EM: %u", startMargin, endMargin);
63 create(video->getScreenWidth(), video->getScreenHeight());
64 transparent.set(0, 0, 0, 0);
65 setBackgroundColour(transparent);
68 barRegion.y = video->getScreenHeight() - 66; // FIXME, need to be - 1? and below?
69 barRegion.w = video->getScreenWidth();
72 clocksRegion.x = barRegion.x + 140;
73 clocksRegion.y = barRegion.y + 12;
75 clocksRegion.h = surface->getFontHeight();
77 barBlue.set(0, 0, 150, 150);
82 VVideoRec::~VVideoRec()
84 if (playing) stopPlay();
85 video->setDefaultAspect();
87 timers->cancelTimer(this, 1);
88 timers->cancelTimer(this, 2);
91 void VVideoRec::draw()
96 void VVideoRec::go(ULONG startFrameNum)
98 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Starting stream: %s at frame: %lu", myRec->getFileName(), startFrameNum);
99 ULONG lengthFrames = 0;
100 ULLONG lengthBytes = vdr->streamRecording(myRec->getFileName(), &lengthFrames);
104 player->setLengthBytes(lengthBytes);
105 player->setLengthFrames(lengthFrames);
106 player->setStartFrame(startFrameNum);
112 stopPlay(); // clean up
114 if (!vdr->isConnected())
116 Command::getInstance()->connectionLost();
120 ViewMan* viewman = ViewMan::getInstance();
122 Message* m = new Message();
123 m->message = Message::CLOSE_ME;
126 viewman->postMessage(m);
128 VInfo* vi = new VInfo();
129 vi->create(400, 150);
130 if (video->getFormat() == Video::PAL)
131 vi->setScreenPos(170, 200);
133 vi->setScreenPos(160, 150);
136 vi->setTitleBarOn(0);
137 vi->setOneLiner(tr("Error playing recording"));
141 m->message = Message::ADD_VIEW;
143 m->parameter = (ULONG)vi;
144 viewman->postMessage(m);
148 int VVideoRec::handleCommand(int command)
163 if (playing) stopPlay();
168 player->togglePause();
172 case Remote::SKIPFORWARD:
175 player->skipForward(60);
178 case Remote::SKIPBACK:
181 player->skipBackward(60);
184 case Remote::FORWARD:
186 player->toggleFastForward();
193 player->skipBackward(10);
199 player->skipForward(10);
211 if (barShowing) removeBar();
217 // case Remote::REVERSE:
219 // player->toggleFastBackward();
223 case Remote::ZERO: player->jumpToPercent(0); doBar(0); return 2;
224 case Remote::ONE: player->jumpToPercent(10); doBar(0); return 2;
225 case Remote::TWO: player->jumpToPercent(20); doBar(0); return 2;
226 case Remote::THREE: player->jumpToPercent(30); doBar(0); return 2;
227 case Remote::FOUR: player->jumpToPercent(40); doBar(0); return 2;
228 case Remote::FIVE: player->jumpToPercent(50); doBar(0); return 2;
229 case Remote::SIX: player->jumpToPercent(60); doBar(0); return 2;
230 case Remote::SEVEN: player->jumpToPercent(70); doBar(0); return 2;
231 case Remote::EIGHT: player->jumpToPercent(80); doBar(0); return 2;
232 case Remote::NINE: player->jumpToPercent(90); doBar(0); return 2;
240 // for testing EPG in NTSC with a NTSC test video
241 Video::getInstance()->setMode(Video::QUARTER);
242 Video::getInstance()->setPosition(170, 5);
243 VEpg* vepg = new VEpg(NULL, 0);
245 ViewMan::getInstance()->add(vepg);
246 ViewMan::getInstance()->updateView(vepg);
263 void VVideoRec::stopPlay()
265 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Pre stopPlay");
267 // FIXME work out a better soln for this
268 // Fix a problem to do with thread sync here
269 // because the bar gets a timer every 0.2s and it seems to take up to 0.1s,
270 // (or maybe just the wrong thread being selected?) for the main loop to lock and process
271 // the video stop message it is possible for a bar message to stack up after a stop message
272 // when the bar message is finally processed the prog crashes because this is deleted by then
277 vdr->stopStreaming();
282 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
283 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Post stopPlay");
286 void VVideoRec::toggleChopSides()
288 if (video->getTVsize() == Video::ASPECT16X9) return; // Means nothing for 16:9 TVs
290 if (videoMode == Video::NORMAL)
292 videoMode = Video::LETTERBOX;
293 video->setMode(Video::LETTERBOX);
297 videoMode = Video::NORMAL;
298 video->setMode(Video::NORMAL);
302 void VVideoRec::doBar(int action)
306 rectangle(barRegion, barBlue);
308 /* Work out what to display - choices:
315 Specials, informed by parameter
325 w.setSurface(surface);
327 w.setSurfaceOffset(76, barRegion.y + 16);
331 if (action == 1) w.nextSymbol = WSymbol::SKIPFORWARD;
332 else if (action == 2) w.nextSymbol = WSymbol::SKIPBACK;
333 else if (action == 3) w.nextSymbol = WSymbol::SKIPFORWARD2;
334 else if (action == 4) w.nextSymbol = WSymbol::SKIPBACK2;
338 if (player->isPaused()) w.nextSymbol = WSymbol::PAUSE;
339 else if (player->isFfwd()) w.nextSymbol = WSymbol::FFWD;
340 else if (player->isFbwd()) w.nextSymbol = WSymbol::FBWD;
341 else w.nextSymbol = WSymbol::PLAY;
348 ViewMan::getInstance()->updateView(this, &barRegion);
349 timers->setTimerD(this, 1, 4);
350 timers->setTimerD(this, 2, 0, 200000000);
353 void VVideoRec::timercall(int clientReference)
355 switch(clientReference)
366 if (!barShowing) break;
368 ViewMan::getInstance()->updateView(this, &barRegion);
369 timers->setTimerD(this, 2, 0, 200000000);
375 void VVideoRec::drawBarClocks()
377 Log* logger = Log::getInstance();
378 logger->log("VVideoRec", Log::DEBUG, "Draw bar clocks");
381 // Blank the area first
382 rectangle(barRegion.x + 624, barRegion.y + 12, 60, 30, barBlue);
386 struct tm* tms = localtime(&t);
387 strftime(timeString, 19, "%H:%M", tms);
388 drawText(timeString, barRegion.x + 624, barRegion.y + 12, Colour::LIGHTTEXT);
392 rectangle(clocksRegion, barBlue);
394 ULONG currentFrameNum = player->getCurrentFrameNum();
395 ULONG lengthFrames = player->getLengthFrames();
397 hmsf currentFrameHMSF = video->framesToHMSF(currentFrameNum);
398 hmsf lengthHMSF = video->framesToHMSF(lengthFrames);
401 if (currentFrameNum >= lengthFrames)
403 strcpy(buffer, "-:--:-- / -:--:--");
407 SNPRINTF(buffer, 99, "%01i:%02i:%02i / %01i:%02i:%02i", currentFrameHMSF.hours, currentFrameHMSF.minutes, currentFrameHMSF.seconds, lengthHMSF.hours, lengthHMSF.minutes, lengthHMSF.seconds);
408 logger->log("VVideoRec", Log::DEBUG, buffer);
411 drawText(buffer, clocksRegion.x, clocksRegion.y, Colour::LIGHTTEXT);
420 int progBarXbase = barRegion.x + 300;
422 rectangle(barRegion.x + progBarXbase, barRegion.y + 12, 310, 24, Colour::LIGHTTEXT);
423 rectangle(barRegion.x + progBarXbase + 2, barRegion.y + 14, 306, 20, barBlue);
425 if (currentFrameNum < lengthFrames)
428 int progressWidth = 302 * currentFrameNum / lengthFrames;
430 rectangle(barRegion.x + progBarXbase + 4, barRegion.y + 16, progressWidth, 16, Colour::SELECTHIGHLIGHT);
432 // Now calc position for start margin blips
435 posPix = 302 * startMargin * video->getFPS() / lengthFrames;
437 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 2, 2, Colour::LIGHTTEXT);
438 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 + 24, 2, 2, Colour::LIGHTTEXT);
440 posPix = 302 * (lengthFrames - endMargin * video->getFPS()) / lengthFrames;
442 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 2, 2, Colour::LIGHTTEXT);
443 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 + 24, 2, 2, Colour::LIGHTTEXT);
447 void VVideoRec::removeBar()
449 if (!barShowing) return;
450 timers->cancelTimer(this, 2);
452 rectangle(barRegion, transparent);
453 ViewMan::getInstance()->updateView(this, &barRegion);