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 + 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 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Starting stream: %s", myRec->getFileName());
99 ULLONG recLength = vdr->streamRecording(myRec->getFileName());
103 player->setLength(recLength);
104 player->setPosition(startPosition);
110 stopPlay(); // clean up
112 if (!vdr->isConnected())
114 Command::getInstance()->connectionLost();
118 ViewMan* viewman = ViewMan::getInstance();
120 Message* m = new Message();
121 m->message = Message::CLOSE_ME;
124 viewman->postMessage(m);
126 VInfo* vi = new VInfo();
127 vi->create(400, 150);
128 if (Video::getInstance()->getFormat() == Video::PAL)
129 vi->setScreenPos(170, 200);
131 vi->setScreenPos(160, 150);
134 vi->setTitleBarOn(0);
135 vi->setOneLiner(tr("Error playing recording"));
139 m->message = Message::ADD_VIEW;
141 m->parameter = (ULONG)vi;
142 viewman->postMessage(m);
146 int VVideoRec::handleCommand(int command)
161 if (playing) stopPlay();
166 player->togglePause();
170 case Remote::SKIPFORWARD:
173 player->skipForward(60);
176 case Remote::SKIPBACK:
179 player->skipBackward(60);
182 case Remote::FORWARD:
184 player->toggleFastForward();
191 player->skipBackward(10);
197 player->skipForward(10);
209 if (barShowing) removeBar();
215 // case Remote::REVERSE:
217 // player->toggleFastBackward();
221 case Remote::ZERO: player->jumpToPercent(0); doBar(0); return 2;
222 case Remote::ONE: player->jumpToPercent(10); doBar(0); return 2;
223 case Remote::TWO: player->jumpToPercent(20); doBar(0); return 2;
224 case Remote::THREE: player->jumpToPercent(30); doBar(0); return 2;
225 case Remote::FOUR: player->jumpToPercent(40); doBar(0); return 2;
226 case Remote::FIVE: player->jumpToPercent(50); doBar(0); return 2;
227 case Remote::SIX: player->jumpToPercent(60); doBar(0); return 2;
228 case Remote::SEVEN: player->jumpToPercent(70); doBar(0); return 2;
229 case Remote::EIGHT: player->jumpToPercent(80); doBar(0); return 2;
230 case Remote::NINE: player->jumpToPercent(90); doBar(0); return 2;
238 // for testing EPG in NTSC with a NTSC test video
239 Video::getInstance()->setMode(Video::QUARTER);
240 Video::getInstance()->setPosition(170, 5);
241 VEpg* vepg = new VEpg(NULL, 0);
243 ViewMan::getInstance()->add(vepg);
244 ViewMan::getInstance()->updateView(vepg);
261 void VVideoRec::stopPlay()
263 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Pre stopPlay");
265 // FIXME work out a better soln for this
266 // Fix a problem to do with thread sync here
267 // because the bar gets a timer every 0.2s and it seems to take up to 0.1s,
268 // (or maybe just the wrong thread being selected?) for the main loop to lock and process
269 // the video stop message it is possible for a bar message to stack up after a stop message
270 // when the bar message is finally processed the prog crashes because this is deleted by then
275 vdr->stopStreaming();
280 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
281 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Post stopPlay");
284 void VVideoRec::toggleChopSides()
286 if (video->getTVsize() == Video::ASPECT16X9) return; // Means nothing for 16:9 TVs
288 if (videoMode == Video::NORMAL)
290 videoMode = Video::LETTERBOX;
291 video->setMode(Video::LETTERBOX);
295 videoMode = Video::NORMAL;
296 video->setMode(Video::NORMAL);
300 void VVideoRec::doBar(int action)
304 rectangle(barRegion, barBlue);
306 /* Work out what to display - choices:
313 Specials, informed by parameter
323 w.setSurface(surface);
325 w.setSurfaceOffset(76, barRegion.y + 16);
329 if (action == 1) w.nextSymbol = WSymbol::SKIPFORWARD;
330 else if (action == 2) w.nextSymbol = WSymbol::SKIPBACK;
331 else if (action == 3) w.nextSymbol = WSymbol::SKIPFORWARD2;
332 else if (action == 4) w.nextSymbol = WSymbol::SKIPBACK2;
336 if (player->isPaused()) w.nextSymbol = WSymbol::PAUSE;
337 else if (player->isFfwd()) w.nextSymbol = WSymbol::FFWD;
338 else if (player->isFbwd()) w.nextSymbol = WSymbol::FBWD;
339 else w.nextSymbol = WSymbol::PLAY;
346 ViewMan::getInstance()->updateView(this, &barRegion);
347 timers->setTimerD(this, 1, 4);
348 timers->setTimerD(this, 2, 0, 200000000);
351 void VVideoRec::timercall(int clientReference)
353 switch(clientReference)
364 if (!barShowing) break;
366 ViewMan::getInstance()->updateView(this, &barRegion);
367 timers->setTimerD(this, 2, 0, 200000000);
373 void VVideoRec::drawBarClocks()
375 Log* logger = Log::getInstance();
376 logger->log("VVideoRec", Log::DEBUG, "Draw bar clocks");
378 rectangle(clocksRegion, barBlue);
380 ULONG currentTS = (player->getPositionTS() / 90000);
381 int chours = currentTS / 3600;
382 int cminutes = (currentTS - (chours * 3600)) / 60;
383 int cseconds = currentTS - (chours * 3600) - (cminutes * 60);
385 ULONG endTS = (player->getEndTS() / 90000);
386 int ehours = endTS / 3600;
387 int eminutes = (endTS - (ehours * 3600)) / 60;
388 int eseconds = endTS - (ehours * 3600) - (eminutes * 60);
391 if ((currentTS > 95441) // it's at the 33bit rollover point where the calc doesn't work because of the 1s diff
392 // between demuxer values and video chip return values ... ?
393 || (!endTS)) // No values yet
395 strcpy(buffer, "-:--:-- / -:--:--");
399 SNPRINTF(buffer, 99, "%01i:%02i:%02i / %01i:%02i:%02i", chours, cminutes, cseconds, ehours, eminutes, eseconds);
400 logger->log("VVideoRec", Log::DEBUG, buffer);
402 // if (chours > 0) abort();
405 drawText(buffer, clocksRegion.x, clocksRegion.y, Colour::LIGHTTEXT);
409 rectangle(barRegion.x + 350, barRegion.y + 12, 310, 24, Colour::LIGHTTEXT);
410 rectangle(barRegion.x + 352, barRegion.y + 14, 306, 20, barBlue);
412 if ((currentTS > 95441) || (!endTS)) return; // No values yet
414 double progress01 = (double)currentTS / (double)endTS;
415 // total width of bar = 302
416 int progressWidth = (int)(302 * progress01);
418 rectangle(barRegion.x + 354, barRegion.y + 16, progressWidth, 16, Colour::SELECTHIGHLIGHT);
420 // Now calc position for start margin blips
424 pos01 = (double)startMargin / (double)endTS;
425 posPix = (int)(302 * pos01);
427 rectangle(barRegion.x + 352 + posPix, barRegion.y + 12 - 2, 2, 2, Colour::LIGHTTEXT);
428 rectangle(barRegion.x + 352 + posPix, barRegion.y + 12 + 24, 2, 2, Colour::LIGHTTEXT);
430 pos01 = (double)(endTS - endMargin) / (double)endTS;
431 posPix = (int)(302 * pos01);
433 rectangle(barRegion.x + 352 + posPix, barRegion.y + 12 - 2, 2, 2, Colour::LIGHTTEXT);
434 rectangle(barRegion.x + 352 + posPix, barRegion.y + 12 + 24, 2, 2, Colour::LIGHTTEXT);
437 void VVideoRec::removeBar()
439 if (!barShowing) return;
440 timers->cancelTimer(this, 2);
442 rectangle(barRegion, transparent);
443 ViewMan::getInstance()->updateView(this, &barRegion);