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 stopPlay(); // clean up
111 if (!vdr->isConnected())
113 Command::getInstance()->connectionLost();
117 ViewMan* viewman = ViewMan::getInstance();
119 Message* m = new Message();
120 m->message = Message::CLOSE_ME;
123 viewman->postMessage(m);
125 VInfo* vi = new VInfo();
126 vi->create(400, 150);
127 if (Video::getInstance()->getFormat() == Video::PAL)
128 vi->setScreenPos(170, 200);
130 vi->setScreenPos(160, 150);
133 vi->setTitleBarOn(0);
134 vi->setOneLiner(tr("Error playing recording"));
138 m->message = Message::ADD_VIEW;
140 m->parameter = (ULONG)vi;
141 viewman->postMessage(m);
145 int VVideoRec::handleCommand(int command)
160 if (playing) stopPlay();
165 player->togglePause();
169 case Remote::SKIPFORWARD:
172 player->skipForward(60);
175 case Remote::SKIPBACK:
178 player->skipBackward(60);
181 case Remote::FORWARD:
183 player->toggleFastForward();
190 player->skipBackward(10);
196 player->skipForward(10);
208 if (barShowing) removeBar();
214 // case Remote::REVERSE:
216 // player->toggleFastBackward();
220 case Remote::ZERO: player->jumpToPercent(0); doBar(0); return 2;
221 case Remote::ONE: player->jumpToPercent(10); doBar(0); return 2;
222 case Remote::TWO: player->jumpToPercent(20); doBar(0); return 2;
223 case Remote::THREE: player->jumpToPercent(30); doBar(0); return 2;
224 case Remote::FOUR: player->jumpToPercent(40); doBar(0); return 2;
225 case Remote::FIVE: player->jumpToPercent(50); doBar(0); return 2;
226 case Remote::SIX: player->jumpToPercent(60); doBar(0); return 2;
227 case Remote::SEVEN: player->jumpToPercent(70); doBar(0); return 2;
228 case Remote::EIGHT: player->jumpToPercent(80); doBar(0); return 2;
229 case Remote::NINE: player->jumpToPercent(90); doBar(0); return 2;
237 // for testing EPG in NTSC with a NTSC test video
238 Video::getInstance()->setMode(Video::QUARTER);
239 Video::getInstance()->setPosition(170, 5);
240 VEpg* vepg = new VEpg(NULL, 0);
242 ViewMan::getInstance()->add(vepg);
243 ViewMan::getInstance()->updateView(vepg);
260 void VVideoRec::stopPlay()
262 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Pre stopPlay");
264 // FIXME work out a better soln for this
265 // Fix a problem to do with thread sync here
266 // because the bar gets a timer every 0.2s and it seems to take up to 0.1s,
267 // (or maybe just the wrong thread being selected?) for the main loop to lock and process
268 // the video stop message it is possible for a bar message to stack up after a stop message
269 // when the bar message is finally processed the prog crashes because this is deleted by then
274 vdr->stopStreaming();
279 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
280 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Post stopPlay");
283 void VVideoRec::toggleChopSides()
285 if (video->getTVsize() == Video::ASPECT16X9) return; // Means nothing for 16:9 TVs
287 if (videoMode == Video::NORMAL)
289 videoMode = Video::LETTERBOX;
290 video->setMode(Video::LETTERBOX);
294 videoMode = Video::NORMAL;
295 video->setMode(Video::NORMAL);
299 void VVideoRec::doBar(int action)
303 rectangle(barRegion, barBlue);
305 /* Work out what to display - choices:
312 Specials, informed by parameter
322 w.setSurface(surface);
324 w.setSurfaceOffset(76, barRegion.y + 16);
328 if (action == 1) w.nextSymbol = WSymbol::SKIPFORWARD;
329 else if (action == 2) w.nextSymbol = WSymbol::SKIPBACK;
330 else if (action == 3) w.nextSymbol = WSymbol::SKIPFORWARD2;
331 else if (action == 4) w.nextSymbol = WSymbol::SKIPBACK2;
335 if (player->isPaused()) w.nextSymbol = WSymbol::PAUSE;
336 else if (player->isFfwd()) w.nextSymbol = WSymbol::FFWD;
337 else if (player->isFbwd()) w.nextSymbol = WSymbol::FBWD;
338 else w.nextSymbol = WSymbol::PLAY;
345 ViewMan::getInstance()->updateView(this, &barRegion);
346 timers->setTimer(this, 1, (struct timespec){4, 0});
347 timers->setTimer(this, 2, (struct timespec){0, 200000000});
350 void VVideoRec::timercall(int clientReference)
352 switch(clientReference)
363 if (!barShowing) break;
365 ViewMan::getInstance()->updateView(this, &barRegion);
366 timers->setTimer(this, 2, (struct timespec){0, 200000000});
372 void VVideoRec::drawBarClocks()
374 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Draw bar clocks");
376 rectangle(clocksRegion, barBlue);
378 ULONG currentTS = (player->getPositionTS() / 90000);
379 int chours = currentTS / 3600;
380 int cminutes = (currentTS - (chours * 3600)) / 60;
381 int cseconds = currentTS - (chours * 3600) - (cminutes * 60);
383 ULONG endTS = (player->getEndTS() / 90000);
384 int ehours = endTS / 3600;
385 int eminutes = (endTS - (ehours * 3600)) / 60;
386 int eseconds = endTS - (ehours * 3600) - (eminutes * 60);
389 if ((currentTS > 95441) // it's at the 33bit rollover point where the calc doesn't work because of the 1s diff
390 // between demuxer values and video chip return values ... ?
391 || (!endTS)) // No values yet
393 strcpy(buffer, "-:--:-- / -:--:--");
397 snprintf(buffer, 99, "%01i:%02i:%02i / %01i:%02i:%02i", chours, cminutes, cseconds, ehours, eminutes, eseconds);
400 drawText(buffer, clocksRegion.x, clocksRegion.y, Colour::LIGHTTEXT);
404 rectangle(barRegion.x + 350, barRegion.y + 12, 310, 24, Colour::LIGHTTEXT);
405 rectangle(barRegion.x + 352, barRegion.y + 14, 306, 20, barBlue);
407 if ((currentTS > 95441) || (!endTS)) return; // No values yet
409 double progress01 = (double)currentTS / (double)endTS;
410 // total width of bar = 302
411 int progressWidth = (int)(302 * progress01);
413 rectangle(barRegion.x + 354, barRegion.y + 16, progressWidth, 16, Colour::SELECTHIGHLIGHT);
415 // Now calc position for start margin blips
419 pos01 = (double)startMargin / (double)endTS;
420 posPix = (int)(302 * pos01);
422 rectangle(barRegion.x + 352 + posPix, barRegion.y + 12 - 2, 2, 2, Colour::LIGHTTEXT);
423 rectangle(barRegion.x + 352 + posPix, barRegion.y + 12 + 24, 2, 2, Colour::LIGHTTEXT);
425 pos01 = (double)(endTS - endMargin) / (double)endTS;
426 posPix = (int)(302 * pos01);
428 rectangle(barRegion.x + 352 + posPix, barRegion.y + 12 - 2, 2, 2, Colour::LIGHTTEXT);
429 rectangle(barRegion.x + 352 + posPix, barRegion.y + 12 + 24, 2, 2, Colour::LIGHTTEXT);
432 void VVideoRec::removeBar()
434 if (!barShowing) return;
435 timers->cancelTimer(this, 2);
437 rectangle(barRegion, transparent);
438 ViewMan::getInstance()->updateView(this, &barRegion);