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(), 1, 0); // 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 + 160;
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::getInstance()->setDefaultAspect();
87 timers->cancelTimer(this, 1);
88 timers->cancelTimer(this, 2);
91 void VVideoRec::draw()
96 void VVideoRec::go(ULLONG startPosition)
98 ULLONG recLength = vdr->streamRecording(myRec);
102 player->setLength(recLength);
103 player->setPosition(startPosition);
109 ViewMan* viewman = ViewMan::getInstance();
111 Message* m = new Message();
112 m->message = Message::CLOSE_ME;
115 viewman->postMessage(m);
117 VInfo* vi = new VInfo();
118 vi->create(400, 150);
119 if (Video::getInstance()->getFormat() == Video::PAL)
120 vi->setScreenPos(170, 200);
122 vi->setScreenPos(160, 150);
125 vi->setTitleBarOn(0);
126 vi->setOneLiner(tr("Error playing recording"));
130 m->message = Message::ADD_VIEW;
132 m->parameter = (ULONG)vi;
133 viewman->postMessage(m);
137 int VVideoRec::handleCommand(int command)
152 if (playing) stopPlay();
157 player->togglePause();
161 case Remote::SKIPFORWARD:
164 player->skipForward(60);
167 case Remote::SKIPBACK:
170 player->skipBackward(60);
173 case Remote::FORWARD:
175 player->toggleFastForward();
182 player->skipBackward(10);
188 player->skipForward(10);
200 if (barShowing) removeBar();
206 // case Remote::REVERSE:
208 // player->toggleFastBackward();
212 case Remote::ZERO: player->jumpToPercent(0); doBar(0); return 2;
213 case Remote::ONE: player->jumpToPercent(10); doBar(0); return 2;
214 case Remote::TWO: player->jumpToPercent(20); doBar(0); return 2;
215 case Remote::THREE: player->jumpToPercent(30); doBar(0); return 2;
216 case Remote::FOUR: player->jumpToPercent(40); doBar(0); return 2;
217 case Remote::FIVE: player->jumpToPercent(50); doBar(0); return 2;
218 case Remote::SIX: player->jumpToPercent(60); doBar(0); return 2;
219 case Remote::SEVEN: player->jumpToPercent(70); doBar(0); return 2;
220 case Remote::EIGHT: player->jumpToPercent(80); doBar(0); return 2;
221 case Remote::NINE: player->jumpToPercent(90); doBar(0); return 2;
229 // for testing EPG in NTSC with a NTSC test video
230 Video::getInstance()->setMode(Video::QUARTER);
231 Video::getInstance()->setPosition(170, 5);
232 VEpg* vepg = new VEpg(NULL, 0);
234 ViewMan::getInstance()->add(vepg);
235 ViewMan::getInstance()->updateView(vepg);
252 void VVideoRec::stopPlay()
254 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Pre stopPlay");
256 // FIXME work out a better soln for this
257 // Fix a problem to do with thread sync here
258 // because the bar gets a timer every 0.2s and it seems to take up to 0.1s,
259 // (or maybe just the wrong thread being selected?) for the main loop to lock and process
260 // the video stop message it is possible for a bar message to stack up after a stop message
261 // when the bar message is finally processed the prog crashes because this is deleted by then
266 vdr->stopStreaming();
271 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Post stopPlay");
274 void VVideoRec::toggleChopSides()
276 if (video->getTVsize() == Video::ASPECT16X9) return; // Means nothing for 16:9 TVs
278 if (videoMode == Video::NORMAL)
280 videoMode = Video::LETTERBOX;
281 video->setMode(Video::LETTERBOX);
285 videoMode = Video::NORMAL;
286 video->setMode(Video::NORMAL);
290 void VVideoRec::doBar(int action)
294 rectangle(barRegion, barBlue);
296 /* Work out what to display - choices:
303 Specials, informed by parameter
313 w.setSurface(surface);
315 w.setSurfaceOffset(76, barRegion.y + 16);
319 if (action == 1) w.nextSymbol = WSymbol::SKIPFORWARD;
320 else if (action == 2) w.nextSymbol = WSymbol::SKIPBACK;
321 else if (action == 3) w.nextSymbol = WSymbol::SKIPFORWARD2;
322 else if (action == 4) w.nextSymbol = WSymbol::SKIPBACK2;
326 if (player->isPaused()) w.nextSymbol = WSymbol::PAUSE;
327 else if (player->isFfwd()) w.nextSymbol = WSymbol::FFWD;
328 else if (player->isFbwd()) w.nextSymbol = WSymbol::FBWD;
329 else w.nextSymbol = WSymbol::PLAY;
336 ViewMan::getInstance()->updateView(this, &barRegion);
337 timers->setTimer(this, 1, (struct timespec){4, 0});
338 timers->setTimer(this, 2, (struct timespec){0, 200000000});
341 void VVideoRec::timercall(int clientReference)
343 switch(clientReference)
354 if (!barShowing) break;
356 ViewMan::getInstance()->updateView(this, &barRegion);
357 timers->setTimer(this, 2, (struct timespec){0, 200000000});
363 void VVideoRec::drawBarClocks()
365 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Draw bar clocks");
367 rectangle(clocksRegion, barBlue);
369 ULONG currentTS = (player->getPositionTS() / 90000);
370 int chours = currentTS / 3600;
371 int cminutes = (currentTS - (chours * 3600)) / 60;
372 int cseconds = currentTS - (chours * 3600) - (cminutes * 60);
374 ULONG endTS = (player->getEndTS() / 90000);
375 int ehours = endTS / 3600;
376 int eminutes = (endTS - (ehours * 3600)) / 60;
377 int eseconds = endTS - (ehours * 3600) - (eminutes * 60);
380 if ((currentTS > 95441) // it's at the 33bit rollover point where the calc doesn't work because of the 1s diff
381 // between demuxer values and video chip return values ... ?
382 || (!endTS)) // No values yet
384 strcpy(buffer, "-:--:-- / -:--:--");
388 snprintf(buffer, 99, "%01i:%02i:%02i / %01i:%02i:%02i", chours, cminutes, cseconds, ehours, eminutes, eseconds);
391 drawText(buffer, clocksRegion.x, clocksRegion.y, Colour::LIGHTTEXT);
395 rectangle(barRegion.x + 350, barRegion.y + 12, 310, 24, Colour::LIGHTTEXT);
396 rectangle(barRegion.x + 352, barRegion.y + 14, 306, 20, barBlue);
398 if ((currentTS > 95441) || (!endTS)) return; // No values yet
400 double progress01 = (double)currentTS / (double)endTS;
401 // total width of bar = 302
402 int progressWidth = (int)(302 * progress01);
404 rectangle(barRegion.x + 354, barRegion.y + 16, progressWidth, 16, Colour::SELECTHIGHLIGHT);
406 // Now calc position for start margin blips
410 pos01 = (double)startMargin / (double)endTS;
411 posPix = (int)(302 * pos01);
413 rectangle(barRegion.x + 352 + posPix, barRegion.y + 12 - 2, 2, 2, Colour::LIGHTTEXT);
414 rectangle(barRegion.x + 352 + posPix, barRegion.y + 12 + 24, 2, 2, Colour::LIGHTTEXT);
416 pos01 = (double)(endTS - endMargin) / (double)endTS;
417 posPix = (int)(302 * pos01);
419 rectangle(barRegion.x + 352 + posPix, barRegion.y + 12 - 2, 2, 2, Colour::LIGHTTEXT);
420 rectangle(barRegion.x + 352 + posPix, barRegion.y + 12 + 24, 2, 2, Colour::LIGHTTEXT);
423 void VVideoRec::removeBar()
425 if (!barShowing) return;
426 timers->cancelTimer(this, 2);
428 rectangle(barRegion, transparent);
429 ViewMan::getInstance()->updateView(this, &barRegion);