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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "vradiorec.h"
27 #include "recording.h"
32 #include "playerradio.h"
39 VRadioRec::VRadioRec(Recording* rec)
41 boxstack = BoxStack::getInstance();
42 vdr = VDR::getInstance();
43 video = Video::getInstance();
44 timers = Timers::getInstance();
50 player = new PlayerRadio(Command::getInstance(), this);
52 char* cstartMargin = vdr->configLoad("Timers", "Start margin");
53 char* cendMargin = vdr->configLoad("Timers", "End margin");
56 startMargin = 300; // 5 mins default
60 startMargin = atoi(cstartMargin) * 60;
61 delete[] cstartMargin;
66 endMargin = 300; // 5 mins default
70 endMargin = atoi(cendMargin) * 60;
74 Log::getInstance()->log("VRadioRec", Log::DEBUG, "SM: %u EM: %u", startMargin, endMargin);
76 setSize(video->getScreenWidth(), video->getScreenHeight());
81 barRegion.y = video->getScreenHeight() - 58; // FIXME, need to be - 1? and below?
82 barRegion.w = video->getScreenWidth();
85 clocksRegion.x = barRegion.x + 140;
86 clocksRegion.y = barRegion.y + 12;
88 clocksRegion.h = surface->getFontHeight();
91 barBlue.set(0, 0, 150, 150);
96 void VRadioRec::preDelete()
98 timers->cancelTimer(this, 1);
99 timers->cancelTimer(this, 2);
102 VRadioRec::~VRadioRec()
104 if (playing) stopPlay();
107 // kill recInfo in case resumePoint has changed (likely)
108 myRec->dropRecInfo();
109 // FIXME - do this properly - save the resume point back to the server manually and update
110 // rec->recInfo->resumePoint - this will fix the ~10s offset problem as well
113 void VRadioRec::draw()
115 fillColour(Colour::BLACK);
120 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Starting stream: %s", myRec->getFileName());
121 ULONG lengthFrames = 0;
123 ULLONG lengthBytes = vdr->streamRecording(myRec->getFileName(), &lengthFrames, &isPesRecording);
124 myRec->IsPesRecording = isPesRecording;
126 bool cantStart = false;
128 if (!lengthBytes) cantStart = true;
129 else if (!player->init(lengthBytes, lengthFrames, myRec->IsPesRecording)) cantStart = true;
133 // player->setStartBytes(startBytes);
140 stopPlay(); // clean up
142 if (!vdr->isConnected())
144 Command::getInstance()->connectionLost();
148 Message* m = new Message();
149 m->message = Message::CLOSE_ME;
152 Command::getInstance()->postMessageNoLock(m);
154 VInfo* vi = new VInfo();
155 vi->setSize(400, 150);
157 if (video->getFormat() == Video::PAL)
158 vi->setPosition(170, 200);
160 vi->setPosition(160, 150);
163 vi->setTitleBarOn(0);
164 vi->setOneLiner(tr("Error playing recording"));
168 m->message = Message::ADD_VIEW;
170 m->parameter = (ULONG)vi;
171 Command::getInstance()->postMessageNoLock(m);
175 int VRadioRec::handleCommand(int command)
190 if (playing) stopPlay();
199 case Remote::SKIPFORWARD:
202 player->skipForward(60);
205 case Remote::SKIPBACK:
208 player->skipBackward(60);
214 player->skipBackward(10);
220 player->skipForward(10);
225 if (barShowing) removeBar();
230 case Remote::ZERO: player->jumpToPercent(0); doBar(0); return 2;
231 case Remote::ONE: player->jumpToPercent(10); doBar(0); return 2;
232 case Remote::TWO: player->jumpToPercent(20); doBar(0); return 2;
233 case Remote::THREE: player->jumpToPercent(30); doBar(0); return 2;
234 case Remote::FOUR: player->jumpToPercent(40); doBar(0); return 2;
235 case Remote::FIVE: player->jumpToPercent(50); doBar(0); return 2;
236 case Remote::SIX: player->jumpToPercent(60); doBar(0); return 2;
237 case Remote::SEVEN: player->jumpToPercent(70); doBar(0); return 2;
238 case Remote::EIGHT: player->jumpToPercent(80); doBar(0); return 2;
239 case Remote::NINE: player->jumpToPercent(90); doBar(0); return 2;
260 void VRadioRec::processMessage(Message* m)
262 if (m->message == Message::MOUSE_LBDOWN)
264 int x=(m->parameter>>16)-(int)getScreenX();
265 int y=(m->parameter&0xFFFF)-(int)getScreenY();
268 boxstack->handleCommand(Remote::OK); //simulate rok press
270 else if ((int)barRegion.x<=x && (int)barRegion.y<=y && ((int)barRegion.x+(int)barRegion.w)>=x
271 && ((int)barRegion.y+(int)barRegion.h)>=y)
273 int progBarXbase = barRegion.x + 300;
274 if (x>=(int)barRegion.x + progBarXbase + 24
275 && x<=(int)barRegion.x + progBarXbase + 4 + 302
276 && y>=(int)barRegion.y + 12 - 2
277 && y<=(int)barRegion.y + 12 - 2+28)
279 int cx=x-(barRegion.x + progBarXbase + 4);
280 double percent=((double)cx)/302.*100.;
281 player->jumpToPercent(percent);
284 // int progressWidth = 302 * currentFrameNum / lengthFrames;
285 // rectangle(barRegion.x + progBarXbase + 4, barRegion.y + 16, progressWidth, 16, Colour::SELECTHIGHLIGHT);
290 boxstack->handleCommand(Remote::OK); //simulate rok press
293 else if (m->message == Message::PLAYER_EVENT)
295 if (m->from != player) return;
297 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Message received");
301 case Player::CONNECTION_LOST: // connection lost detected
303 // I can't handle this, send it to command
304 Message* m2 = new Message();
305 m2->to = Command::getInstance();
306 m2->message = Message::CONNECTION_LOST;
307 Command::getInstance()->postMessageNoLock(m2);
310 case Player::STOP_PLAYBACK:
312 // FIXME Obselete ish - improve this
313 Message* m2 = new Message(); // Must be done after this thread finishes, and must break into master mutex
314 m2->to = Command::getInstance();
315 m2->message = Message::STOP_PLAYBACK;
316 Command::getInstance()->postMessageNoLock(m2);
323 void VRadioRec::stopPlay()
325 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Pre stopPlay");
329 vdr->stopStreaming();
334 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
335 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Post stopPlay");
338 void VRadioRec::doBar(int action)
342 rectangle(barRegion, barBlue);
344 /* Work out what to display - choices:
349 Specials, informed by parameter
361 w.setPosition(barRegion.x + 66, barRegion.y + 16);
363 UCHAR playerState = 0;
367 if (action == 1) w.nextSymbol = WSymbol::SKIPFORWARD;
368 else if (action == 2) w.nextSymbol = WSymbol::SKIPBACK;
369 else if (action == 3) w.nextSymbol = WSymbol::SKIPFORWARD2;
370 else if (action == 4) w.nextSymbol = WSymbol::SKIPBACK2;
374 playerState = player->getState();
375 if (playerState == Player::S_PAUSE_P) w.nextSymbol = WSymbol::PAUSE;
376 else if (playerState == Player::S_PAUSE_I) w.nextSymbol = WSymbol::PAUSE;
377 else w.nextSymbol = WSymbol::PLAY;
384 BoxStack::getInstance()->update(this, &barRegion);
386 timers->setTimerD(this, 1, 4); // only set the getridofbar timer if not ffwd/fbwd
387 timers->setTimerD(this, 2, 0, 200000000);
390 void VRadioRec::timercall(int clientReference)
392 switch(clientReference)
403 if (!barShowing) break;
405 boxstack->update(this, &barRegion);
407 timers->setTimerD(this, 2, 0, 200000000);
413 void VRadioRec::drawBarClocks()
415 Log* logger = Log::getInstance();
416 logger->log("VRadioRec", Log::DEBUG, "Draw bar clocks");
419 // Blank the area first
420 rectangle(barRegion.x + 624, barRegion.y + 12, 60, 30, barBlue);
424 struct tm* tms = localtime(&t);
425 strftime(timeString, 19, "%H:%M", tms);
426 drawText(timeString, barRegion.x + 624, barRegion.y + 12, Colour::LIGHTTEXT);
430 rectangle(clocksRegion, barBlue);
433 ULONG currentFrameNum = player->getCurrentFrameNum();
435 if (myRec->recInfo->timerEnd > time(NULL))
438 // Work out an approximate length in frames (good to 1s...)
439 lengthFrames = (myRec->recInfo->timerEnd - myRec->recInfo->timerStart) * video->getFPS();
443 // lengthFrames = player->getLengthFrames();
447 hmsf currentFrameHMSF = video->framesToHMSF(currentFrameNum);
448 hmsf lengthHMSF = video->framesToHMSF(lengthFrames);
451 if (currentFrameNum >= lengthFrames)
453 strcpy(buffer, "-:--:-- / -:--:--");
457 SNPRINTF(buffer, 99, "%01i:%02i:%02i / %01i:%02i:%02i", currentFrameHMSF.hours, currentFrameHMSF.minutes, currentFrameHMSF.seconds, lengthHMSF.hours, lengthHMSF.minutes, lengthHMSF.seconds);
458 logger->log("VRadioRec", Log::DEBUG, buffer);
462 ULONG currentSeconds = player->getCurrentSeconds();
463 ULONG lengthSeconds = player->getLengthSeconds();
466 if (lengthSeconds && (currentSeconds < lengthSeconds))
468 ULONG dcurrentSeconds = currentSeconds;
469 ULONG dlengthSeconds = lengthSeconds;
471 ULONG currentHours = dcurrentSeconds / 3600;
472 dcurrentSeconds %= 3600;
473 ULONG currentMinutes = dcurrentSeconds / 60;
474 dcurrentSeconds %= 60;
476 ULONG lengthHours = dlengthSeconds / 3600;
477 dlengthSeconds %= 3600;
478 ULONG lengthMinutes = dlengthSeconds / 60;
479 dlengthSeconds %= 60;
481 SNPRINTF(buffer, 99, "%01lu:%02lu:%02lu / %01lu:%02lu:%02lu", currentHours, currentMinutes, dcurrentSeconds, lengthHours, lengthMinutes, dlengthSeconds);
482 logger->log("VRadioRec", Log::DEBUG, buffer);
486 strcpy(buffer, "-:--:-- / -:--:--");
489 drawText(buffer, clocksRegion.x, clocksRegion.y, Colour::LIGHTTEXT);
492 int progBarXbase = barRegion.x + 300;
494 rectangle(barRegion.x + progBarXbase, barRegion.y + 12, 310, 24, Colour::LIGHTTEXT);
495 rectangle(barRegion.x + progBarXbase + 2, barRegion.y + 14, 306, 20, barBlue);
497 if (currentSeconds > lengthSeconds) return;
498 if (lengthSeconds == 0) return;
500 // Draw yellow portion
501 int progressWidth = 302 * currentSeconds / lengthSeconds;
502 rectangle(barRegion.x + progBarXbase + 4, barRegion.y + 16, progressWidth, 16, Colour::SELECTHIGHLIGHT);
505 if (myRec->recInfo->timerEnd > time(NULL)) // if chasing
507 int nrWidth = (int)(302 * ((double)(lengthFrames - 0) / lengthFrames)); // 0 inserted instead of getlengthframes
509 Log::getInstance()->log("GVASDF", Log::DEBUG, "Length Frames: %lu", lengthFrames);
510 // Log::getInstance()->log("GVASDF", Log::DEBUG, "Player lf: %lu", player->getLengthFrames());
511 Log::getInstance()->log("GVASDF", Log::DEBUG, "NR WDITH: %i", nrWidth);
512 rectangle(barRegion.x + progBarXbase + 4 + 302 - nrWidth, barRegion.y + 16, nrWidth, 16, Colour::RED);
516 logger->log("VRadioRec", Log::DEBUG, "blips");
518 // Now calc position for start margin blips
521 posPix = 302 * startMargin / lengthSeconds;
522 logger->log("VRadioRec", Log::DEBUG, "posPix %i", posPix);
524 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 2, 2, Colour::LIGHTTEXT);
525 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 + 24, 2, 2, Colour::LIGHTTEXT);
527 posPix = 302 * (lengthSeconds - endMargin) / lengthSeconds;
529 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 2, 2, Colour::LIGHTTEXT);
530 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 + 24, 2, 2, Colour::LIGHTTEXT);
533 void VRadioRec::removeBar()
535 if (!barShowing) return;
536 timers->cancelTimer(this, 2);
538 rectangle(barRegion, Colour::BLACK);
539 boxstack->update(this, &barRegion);