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->message == Message::MOUSE_LBDOWN)
252 int x=(m->parameter>>16)-(int)getScreenX();
253 int y=(m->parameter&0xFFFF)-(int)getScreenY();
256 ViewMan::getInstance()->handleCommand(Remote::OK); //simulate rok press
258 else if ((int)barRegion.x<=x && (int)barRegion.y<=y && ((int)barRegion.x+(int)barRegion.w)>=x
259 && ((int)barRegion.y+(int)barRegion.h)>=y)
261 int progBarXbase = barRegion.x + 300;
262 if (x>=(int)barRegion.x + progBarXbase + 24
263 && x<=(int)barRegion.x + progBarXbase + 4 + 302
264 && y>=(int)barRegion.y + 12 - 2
265 && y<=(int)barRegion.y + 12 - 2+28)
267 int cx=x-(barRegion.x + progBarXbase + 4);
268 double percent=((double)cx)/302.*100.;
269 player->jumpToPercent(percent);
272 // int progressWidth = 302 * currentFrameNum / lengthFrames;
273 // rectangle(barRegion.x + progBarXbase + 4, barRegion.y + 16, progressWidth, 16, Colour::SELECTHIGHLIGHT);
278 ViewMan::getInstance()->handleCommand(Remote::OK); //simulate rok press
281 else if (m->message == Message::PLAYER_EVENT)
283 if (m->from != player) return;
285 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Message received");
289 case Player::CONNECTION_LOST: // connection lost detected
291 // I can't handle this, send it to command
292 Message* m2 = new Message();
293 m2->to = Command::getInstance();
294 m2->message = Message::CONNECTION_LOST;
295 Command::getInstance()->postMessageNoLock(m2);
298 case Player::STOP_PLAYBACK:
300 // FIXME Obselete ish - improve this
301 Message* m2 = new Message(); // Must be done after this thread finishes, and must break into master mutex
302 m2->to = Command::getInstance();
303 m2->message = Message::STOP_PLAYBACK;
304 Command::getInstance()->postMessageNoLock(m2);
311 void VRadioRec::stopPlay()
313 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Pre stopPlay");
315 // FIXME work out a better soln for this
316 // Fix a problem to do with thread sync here
317 // because the bar gets a timer every 0.2s and it seems to take up to 0.1s,
318 // (or maybe just the wrong thread being selected?) for the main loop to lock and process
319 // the video stop message it is possible for a bar message to stack up after a stop message
320 // when the bar message is finally processed the prog crashes because this is deleted by then
325 vdr->stopStreaming();
330 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
331 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Post stopPlay");
334 void VRadioRec::doBar(int action)
338 rectangle(barRegion, barBlue);
340 /* Work out what to display - choices:
345 Specials, informed by parameter
355 w.setSurface(surface);
357 w.setSurfaceOffset(barRegion.x + 66, barRegion.y + 16);
359 UCHAR playerState = 0;
363 if (action == 1) w.nextSymbol = WSymbol::SKIPFORWARD;
364 else if (action == 2) w.nextSymbol = WSymbol::SKIPBACK;
365 else if (action == 3) w.nextSymbol = WSymbol::SKIPFORWARD2;
366 else if (action == 4) w.nextSymbol = WSymbol::SKIPBACK2;
370 playerState = player->getState();
371 if (playerState == Player::S_PAUSE_P) w.nextSymbol = WSymbol::PAUSE;
372 else if (playerState == Player::S_PAUSE_I) w.nextSymbol = WSymbol::PAUSE;
373 else w.nextSymbol = WSymbol::PLAY;
380 ViewMan::getInstance()->updateView(this, &barRegion);
382 timers->setTimerD(this, 1, 4); // only set the getridofbar timer if not ffwd/fbwd
383 timers->setTimerD(this, 2, 0, 200000000);
386 void VRadioRec::timercall(int clientReference)
388 switch(clientReference)
399 if (!barShowing) break;
401 ViewMan::getInstance()->updateView(this, &barRegion);
402 timers->setTimerD(this, 2, 0, 200000000);
408 void VRadioRec::drawBarClocks()
410 Log* logger = Log::getInstance();
411 logger->log("VRadioRec", Log::DEBUG, "Draw bar clocks");
414 // Blank the area first
415 rectangle(barRegion.x + 624, barRegion.y + 12, 60, 30, barBlue);
419 struct tm* tms = localtime(&t);
420 strftime(timeString, 19, "%H:%M", tms);
421 drawText(timeString, barRegion.x + 624, barRegion.y + 12, Colour::LIGHTTEXT);
425 rectangle(clocksRegion, barBlue);
428 ULONG currentFrameNum = player->getCurrentFrameNum();
430 if (myRec->recInfo->timerEnd > time(NULL))
433 // Work out an approximate length in frames (good to 1s...)
434 lengthFrames = (myRec->recInfo->timerEnd - myRec->recInfo->timerStart) * video->getFPS();
438 // lengthFrames = player->getLengthFrames();
442 hmsf currentFrameHMSF = video->framesToHMSF(currentFrameNum);
443 hmsf lengthHMSF = video->framesToHMSF(lengthFrames);
446 if (currentFrameNum >= lengthFrames)
448 strcpy(buffer, "-:--:-- / -:--:--");
452 SNPRINTF(buffer, 99, "%01i:%02i:%02i / %01i:%02i:%02i", currentFrameHMSF.hours, currentFrameHMSF.minutes, currentFrameHMSF.seconds, lengthHMSF.hours, lengthHMSF.minutes, lengthHMSF.seconds);
453 logger->log("VRadioRec", Log::DEBUG, buffer);
457 ULONG currentSeconds = player->getCurrentSeconds();
458 ULONG lengthSeconds = player->getLengthSeconds();
461 if (lengthSeconds && (currentSeconds < lengthSeconds))
463 ULONG dcurrentSeconds = currentSeconds;
464 ULONG dlengthSeconds = lengthSeconds;
466 ULONG currentHours = dcurrentSeconds / 3600;
467 dcurrentSeconds %= 3600;
468 ULONG currentMinutes = dcurrentSeconds / 60;
469 dcurrentSeconds %= 60;
471 ULONG lengthHours = dlengthSeconds / 3600;
472 dlengthSeconds %= 3600;
473 ULONG lengthMinutes = dlengthSeconds / 60;
474 dlengthSeconds %= 60;
476 SNPRINTF(buffer, 99, "%01lu:%02lu:%02lu / %01lu:%02lu:%02lu", currentHours, currentMinutes, dcurrentSeconds, lengthHours, lengthMinutes, dlengthSeconds);
477 logger->log("VRadioRec", Log::DEBUG, buffer);
481 strcpy(buffer, "-:--:-- / -:--:--");
484 drawText(buffer, clocksRegion.x, clocksRegion.y, Colour::LIGHTTEXT);
490 int progBarXbase = barRegion.x + 300;
492 rectangle(barRegion.x + progBarXbase, barRegion.y + 12, 310, 24, Colour::LIGHTTEXT);
493 rectangle(barRegion.x + progBarXbase + 2, barRegion.y + 14, 306, 20, barBlue);
495 if (currentSeconds > lengthSeconds) return;
496 if (lengthSeconds == 0) return;
498 // Draw yellow portion
499 int progressWidth = 302 * currentSeconds / lengthSeconds;
500 rectangle(barRegion.x + progBarXbase + 4, barRegion.y + 16, progressWidth, 16, Colour::SELECTHIGHLIGHT);
503 if (myRec->recInfo->timerEnd > time(NULL)) // if chasing
505 int nrWidth = (int)(302 * ((double)(lengthFrames - 0) / lengthFrames)); // 0 inserted instead of getlengthframes
507 Log::getInstance()->log("GVASDF", Log::DEBUG, "Length Frames: %lu", lengthFrames);
508 // Log::getInstance()->log("GVASDF", Log::DEBUG, "Player lf: %lu", player->getLengthFrames());
509 Log::getInstance()->log("GVASDF", Log::DEBUG, "NR WDITH: %i", nrWidth);
510 rectangle(barRegion.x + progBarXbase + 4 + 302 - nrWidth, barRegion.y + 16, nrWidth, 16, Colour::RED);
514 logger->log("VRadioRec", Log::DEBUG, "blips");
516 // Now calc position for start margin blips
519 posPix = 302 * startMargin / lengthSeconds;
520 logger->log("VRadioRec", Log::DEBUG, "posPix %i", posPix);
522 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 2, 2, Colour::LIGHTTEXT);
523 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 + 24, 2, 2, Colour::LIGHTTEXT);
525 posPix = 302 * (lengthSeconds - endMargin) / lengthSeconds;
527 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 2, 2, Colour::LIGHTTEXT);
528 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 + 24, 2, 2, Colour::LIGHTTEXT);
531 void VRadioRec::removeBar()
533 if (!barShowing) return;
534 timers->cancelTimer(this, 2);
536 rectangle(barRegion, Colour::BLACK);
537 ViewMan::getInstance()->updateView(this, &barRegion);