2 Copyright 2004-2006 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 "vradiorec.h"
23 VRadioRec::VRadioRec(Recording* rec)
25 vdr = VDR::getInstance();
26 video = Video::getInstance();
27 timers = Timers::getInstance();
33 player = new PlayerRadio(Command::getInstance(), this, true);
35 char* cstartMargin = vdr->configLoad("Timers", "Start margin");
36 char* cendMargin = vdr->configLoad("Timers", "End margin");
39 startMargin = 300; // 5 mins default
43 startMargin = atoi(cstartMargin) * 60;
44 delete[] cstartMargin;
49 endMargin = 300; // 5 mins default
53 endMargin = atoi(cendMargin) * 60;
57 Log::getInstance()->log("VRadioRec", Log::DEBUG, "SM: %u EM: %u", startMargin, endMargin);
59 create(video->getScreenWidth(), video->getScreenHeight());
60 setBackgroundColour(Colour::BLACK);
63 barRegion.y = video->getScreenHeight() - 58; // FIXME, need to be - 1? and below?
64 barRegion.w = video->getScreenWidth();
67 clocksRegion.x = barRegion.x + 140;
68 clocksRegion.y = barRegion.y + 12;
70 clocksRegion.h = surface->getFontHeight();
73 barBlue.set(0, 0, 150, 150);
78 VRadioRec::~VRadioRec()
80 if (playing) stopPlay();
82 timers->cancelTimer(this, 1);
83 timers->cancelTimer(this, 2);
85 // kill recInfo in case resumePoint has changed (likely)
87 // FIXME - do this properly - save the resume point back to the server manually and update
88 // rec->recInfo->resumePoint - this will fix the ~10s offset problem as well
91 void VRadioRec::draw()
98 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Starting stream: %s", myRec->getFileName());
99 ULONG lengthFrames = 0;
100 ULLONG lengthBytes = vdr->streamRecording(myRec->getFileName(), &lengthFrames);
102 bool cantStart = false;
104 if (!lengthBytes) cantStart = true;
105 else if (!player->init(lengthBytes, lengthFrames)) cantStart = true;
109 // player->setStartBytes(startBytes);
116 stopPlay(); // clean up
118 if (!vdr->isConnected())
120 Command::getInstance()->connectionLost();
124 ViewMan* viewman = ViewMan::getInstance();
126 Message* m = new Message();
127 m->message = Message::CLOSE_ME;
130 Command::getInstance()->postMessageNoLock(m);
132 VInfo* vi = new VInfo();
133 vi->create(400, 150);
134 if (video->getFormat() == Video::PAL)
135 vi->setScreenPos(170, 200);
137 vi->setScreenPos(160, 150);
140 vi->setTitleBarOn(0);
141 vi->setOneLiner(tr("Error playing recording"));
145 m->message = Message::ADD_VIEW;
147 m->parameter = (ULONG)vi;
148 Command::getInstance()->postMessageNoLock(m);
152 int VRadioRec::handleCommand(int command)
167 if (playing) stopPlay();
176 case Remote::SKIPFORWARD:
179 player->skipForward(60);
182 case Remote::SKIPBACK:
185 player->skipBackward(60);
191 player->skipBackward(10);
197 player->skipForward(10);
202 if (barShowing) removeBar();
207 case Remote::ZERO: player->jumpToPercent(0); doBar(0); return 2;
208 case Remote::ONE: player->jumpToPercent(10); doBar(0); return 2;
209 case Remote::TWO: player->jumpToPercent(20); doBar(0); return 2;
210 case Remote::THREE: player->jumpToPercent(30); doBar(0); return 2;
211 case Remote::FOUR: player->jumpToPercent(40); doBar(0); return 2;
212 case Remote::FIVE: player->jumpToPercent(50); doBar(0); return 2;
213 case Remote::SIX: player->jumpToPercent(60); doBar(0); return 2;
214 case Remote::SEVEN: player->jumpToPercent(70); doBar(0); return 2;
215 case Remote::EIGHT: player->jumpToPercent(80); doBar(0); return 2;
216 case Remote::NINE: player->jumpToPercent(90); doBar(0); return 2;
225 // for testing EPG in NTSC with a NTSC test video
226 Video::getInstance()->setMode(Video::QUARTER);
227 Video::getInstance()->setPosition(170, 5);
228 VEpg* vepg = new VEpg(NULL, 0);
230 ViewMan::getInstance()->add(vepg);
231 ViewMan::getInstance()->updateView(vepg);
248 void VRadioRec::processMessage(Message* m)
250 if (m->from != player) return;
251 if (m->message != Message::PLAYER_EVENT) return;
253 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Message received");
257 case Player::CONNECTION_LOST: // connection lost detected
259 // I can't handle this, send it to command
260 Message* m = new Message();
261 m->to = Command::getInstance();
262 m->message = Message::CONNECTION_LOST;
263 Command::getInstance()->postMessageNoLock(m);
266 case Player::STOP_PLAYBACK:
268 // FIXME Obselete ish - improve this
269 Message* m = new Message(); // Must be done after this thread finishes, and must break into master mutex
270 m->to = Command::getInstance();
271 m->message = Message::STOP_PLAYBACK;
272 Command::getInstance()->postMessageNoLock(m);
278 void VRadioRec::stopPlay()
280 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Pre stopPlay");
282 // FIXME work out a better soln for this
283 // Fix a problem to do with thread sync here
284 // because the bar gets a timer every 0.2s and it seems to take up to 0.1s,
285 // (or maybe just the wrong thread being selected?) for the main loop to lock and process
286 // the video stop message it is possible for a bar message to stack up after a stop message
287 // when the bar message is finally processed the prog crashes because this is deleted by then
292 vdr->stopStreaming();
297 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
298 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Post stopPlay");
301 void VRadioRec::doBar(int action)
305 rectangle(barRegion, barBlue);
307 /* Work out what to display - choices:
312 Specials, informed by parameter
322 w.setSurface(surface);
324 w.setSurfaceOffset(barRegion.x + 66, barRegion.y + 16);
326 UCHAR playerState = 0;
330 if (action == 1) w.nextSymbol = WSymbol::SKIPFORWARD;
331 else if (action == 2) w.nextSymbol = WSymbol::SKIPBACK;
332 else if (action == 3) w.nextSymbol = WSymbol::SKIPFORWARD2;
333 else if (action == 4) w.nextSymbol = WSymbol::SKIPBACK2;
337 playerState = player->getState();
338 if (playerState == Player::S_PAUSE_P) w.nextSymbol = WSymbol::PAUSE;
339 else if (playerState == Player::S_PAUSE_I) w.nextSymbol = WSymbol::PAUSE;
340 else w.nextSymbol = WSymbol::PLAY;
347 ViewMan::getInstance()->updateView(this, &barRegion);
349 timers->setTimerD(this, 1, 4); // only set the getridofbar timer if not ffwd/fbwd
350 timers->setTimerD(this, 2, 0, 200000000);
353 void VRadioRec::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 VRadioRec::drawBarClocks()
377 Log* logger = Log::getInstance();
378 logger->log("VRadioRec", 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);
395 ULONG currentFrameNum = player->getCurrentFrameNum();
397 if (myRec->recInfo->timerEnd > time(NULL))
400 // Work out an approximate length in frames (good to 1s...)
401 lengthFrames = (myRec->recInfo->timerEnd - myRec->recInfo->timerStart) * video->getFPS();
405 // lengthFrames = player->getLengthFrames();
409 hmsf currentFrameHMSF = video->framesToHMSF(currentFrameNum);
410 hmsf lengthHMSF = video->framesToHMSF(lengthFrames);
413 if (currentFrameNum >= lengthFrames)
415 strcpy(buffer, "-:--:-- / -:--:--");
419 SNPRINTF(buffer, 99, "%01i:%02i:%02i / %01i:%02i:%02i", currentFrameHMSF.hours, currentFrameHMSF.minutes, currentFrameHMSF.seconds, lengthHMSF.hours, lengthHMSF.minutes, lengthHMSF.seconds);
420 logger->log("VRadioRec", Log::DEBUG, buffer);
424 ULONG currentSeconds = player->getCurrentSeconds();
425 ULONG lengthSeconds = player->getLengthSeconds();
428 if (lengthSeconds && (currentSeconds < lengthSeconds))
430 ULONG dcurrentSeconds = currentSeconds;
431 ULONG dlengthSeconds = lengthSeconds;
433 ULONG currentHours = dcurrentSeconds / 3600;
434 dcurrentSeconds %= 3600;
435 ULONG currentMinutes = dcurrentSeconds / 60;
436 dcurrentSeconds %= 60;
438 ULONG lengthHours = dlengthSeconds / 3600;
439 dlengthSeconds %= 3600;
440 ULONG lengthMinutes = dlengthSeconds / 60;
441 dlengthSeconds %= 60;
443 SNPRINTF(buffer, 99, "%01lu:%02lu:%02lu / %01lu:%02lu:%02lu", currentHours, currentMinutes, dcurrentSeconds, lengthHours, lengthMinutes, dlengthSeconds);
444 logger->log("VRadioRec", Log::DEBUG, buffer);
448 strcpy(buffer, "-:--:-- / -:--:--");
451 drawText(buffer, clocksRegion.x, clocksRegion.y, Colour::LIGHTTEXT);
457 int progBarXbase = barRegion.x + 300;
459 rectangle(barRegion.x + progBarXbase, barRegion.y + 12, 310, 24, Colour::LIGHTTEXT);
460 rectangle(barRegion.x + progBarXbase + 2, barRegion.y + 14, 306, 20, barBlue);
462 if (currentSeconds > lengthSeconds) return;
463 if (lengthSeconds == 0) return;
465 // Draw yellow portion
466 int progressWidth = 302 * currentSeconds / lengthSeconds;
467 rectangle(barRegion.x + progBarXbase + 4, barRegion.y + 16, progressWidth, 16, Colour::SELECTHIGHLIGHT);
470 if (myRec->recInfo->timerEnd > time(NULL)) // if chasing
472 int nrWidth = (int)(302 * ((double)(lengthFrames - 0) / lengthFrames)); // 0 inserted instead of getlengthframes
474 Log::getInstance()->log("GVASDF", Log::DEBUG, "Length Frames: %lu", lengthFrames);
475 // Log::getInstance()->log("GVASDF", Log::DEBUG, "Player lf: %lu", player->getLengthFrames());
476 Log::getInstance()->log("GVASDF", Log::DEBUG, "NR WDITH: %i", nrWidth);
477 rectangle(barRegion.x + progBarXbase + 4 + 302 - nrWidth, barRegion.y + 16, nrWidth, 16, Colour::RED);
481 logger->log("VRadioRec", Log::DEBUG, "blips");
483 // Now calc position for start margin blips
486 posPix = 302 * startMargin / lengthSeconds;
487 logger->log("VRadioRec", Log::DEBUG, "posPix %i", posPix);
489 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 2, 2, Colour::LIGHTTEXT);
490 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 + 24, 2, 2, Colour::LIGHTTEXT);
492 posPix = 302 * (lengthSeconds - endMargin) / lengthSeconds;
494 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 2, 2, Colour::LIGHTTEXT);
495 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 + 24, 2, 2, Colour::LIGHTTEXT);
498 void VRadioRec::removeBar()
500 if (!barShowing) return;
501 timers->cancelTimer(this, 2);
503 rectangle(barRegion, Colour::BLACK);
504 ViewMan::getInstance()->updateView(this, &barRegion);