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;
122 ULLONG lengthBytes = vdr->streamRecording(myRec->getFileName(), &lengthFrames);
124 bool cantStart = false;
126 if (!lengthBytes) cantStart = true;
127 else if (!player->init(lengthBytes, lengthFrames)) cantStart = true;
131 // player->setStartBytes(startBytes);
138 stopPlay(); // clean up
140 if (!vdr->isConnected())
142 Command::getInstance()->connectionLost();
146 Message* m = new Message();
147 m->message = Message::CLOSE_ME;
150 Command::getInstance()->postMessageNoLock(m);
152 VInfo* vi = new VInfo();
153 vi->setSize(400, 150);
155 if (video->getFormat() == Video::PAL)
156 vi->setPosition(170, 200);
158 vi->setPosition(160, 150);
161 vi->setTitleBarOn(0);
162 vi->setOneLiner(tr("Error playing recording"));
166 m->message = Message::ADD_VIEW;
168 m->parameter = (ULONG)vi;
169 Command::getInstance()->postMessageNoLock(m);
173 int VRadioRec::handleCommand(int command)
188 if (playing) stopPlay();
197 case Remote::SKIPFORWARD:
200 player->skipForward(60);
203 case Remote::SKIPBACK:
206 player->skipBackward(60);
212 player->skipBackward(10);
218 player->skipForward(10);
223 if (barShowing) removeBar();
228 case Remote::ZERO: player->jumpToPercent(0); doBar(0); return 2;
229 case Remote::ONE: player->jumpToPercent(10); doBar(0); return 2;
230 case Remote::TWO: player->jumpToPercent(20); doBar(0); return 2;
231 case Remote::THREE: player->jumpToPercent(30); doBar(0); return 2;
232 case Remote::FOUR: player->jumpToPercent(40); doBar(0); return 2;
233 case Remote::FIVE: player->jumpToPercent(50); doBar(0); return 2;
234 case Remote::SIX: player->jumpToPercent(60); doBar(0); return 2;
235 case Remote::SEVEN: player->jumpToPercent(70); doBar(0); return 2;
236 case Remote::EIGHT: player->jumpToPercent(80); doBar(0); return 2;
237 case Remote::NINE: player->jumpToPercent(90); doBar(0); return 2;
258 void VRadioRec::processMessage(Message* m)
260 if (m->message == Message::MOUSE_LBDOWN)
262 int x=(m->parameter>>16)-(int)getScreenX();
263 int y=(m->parameter&0xFFFF)-(int)getScreenY();
266 boxstack->handleCommand(Remote::OK); //simulate rok press
268 else if ((int)barRegion.x<=x && (int)barRegion.y<=y && ((int)barRegion.x+(int)barRegion.w)>=x
269 && ((int)barRegion.y+(int)barRegion.h)>=y)
271 int progBarXbase = barRegion.x + 300;
272 if (x>=(int)barRegion.x + progBarXbase + 24
273 && x<=(int)barRegion.x + progBarXbase + 4 + 302
274 && y>=(int)barRegion.y + 12 - 2
275 && y<=(int)barRegion.y + 12 - 2+28)
277 int cx=x-(barRegion.x + progBarXbase + 4);
278 double percent=((double)cx)/302.*100.;
279 player->jumpToPercent(percent);
282 // int progressWidth = 302 * currentFrameNum / lengthFrames;
283 // rectangle(barRegion.x + progBarXbase + 4, barRegion.y + 16, progressWidth, 16, Colour::SELECTHIGHLIGHT);
288 boxstack->handleCommand(Remote::OK); //simulate rok press
291 else if (m->message == Message::PLAYER_EVENT)
293 if (m->from != player) return;
295 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Message received");
299 case Player::CONNECTION_LOST: // connection lost detected
301 // I can't handle this, send it to command
302 Message* m2 = new Message();
303 m2->to = Command::getInstance();
304 m2->message = Message::CONNECTION_LOST;
305 Command::getInstance()->postMessageNoLock(m2);
308 case Player::STOP_PLAYBACK:
310 // FIXME Obselete ish - improve this
311 Message* m2 = new Message(); // Must be done after this thread finishes, and must break into master mutex
312 m2->to = Command::getInstance();
313 m2->message = Message::STOP_PLAYBACK;
314 Command::getInstance()->postMessageNoLock(m2);
321 void VRadioRec::stopPlay()
323 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Pre stopPlay");
327 vdr->stopStreaming();
332 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
333 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Post stopPlay");
336 void VRadioRec::doBar(int action)
340 rectangle(barRegion, barBlue);
342 /* Work out what to display - choices:
347 Specials, informed by parameter
359 w.setPosition(barRegion.x + 66, barRegion.y + 16);
361 UCHAR playerState = 0;
365 if (action == 1) w.nextSymbol = WSymbol::SKIPFORWARD;
366 else if (action == 2) w.nextSymbol = WSymbol::SKIPBACK;
367 else if (action == 3) w.nextSymbol = WSymbol::SKIPFORWARD2;
368 else if (action == 4) w.nextSymbol = WSymbol::SKIPBACK2;
372 playerState = player->getState();
373 if (playerState == Player::S_PAUSE_P) w.nextSymbol = WSymbol::PAUSE;
374 else if (playerState == Player::S_PAUSE_I) w.nextSymbol = WSymbol::PAUSE;
375 else w.nextSymbol = WSymbol::PLAY;
382 BoxStack::getInstance()->update(this, &barRegion);
384 timers->setTimerD(this, 1, 4); // only set the getridofbar timer if not ffwd/fbwd
385 timers->setTimerD(this, 2, 0, 200000000);
388 void VRadioRec::timercall(int clientReference)
390 switch(clientReference)
401 if (!barShowing) break;
403 boxstack->update(this, &barRegion);
405 timers->setTimerD(this, 2, 0, 200000000);
411 void VRadioRec::drawBarClocks()
413 Log* logger = Log::getInstance();
414 logger->log("VRadioRec", Log::DEBUG, "Draw bar clocks");
417 // Blank the area first
418 rectangle(barRegion.x + 624, barRegion.y + 12, 60, 30, barBlue);
422 struct tm* tms = localtime(&t);
423 strftime(timeString, 19, "%H:%M", tms);
424 drawText(timeString, barRegion.x + 624, barRegion.y + 12, Colour::LIGHTTEXT);
428 rectangle(clocksRegion, barBlue);
431 ULONG currentFrameNum = player->getCurrentFrameNum();
433 if (myRec->recInfo->timerEnd > time(NULL))
436 // Work out an approximate length in frames (good to 1s...)
437 lengthFrames = (myRec->recInfo->timerEnd - myRec->recInfo->timerStart) * video->getFPS();
441 // lengthFrames = player->getLengthFrames();
445 hmsf currentFrameHMSF = video->framesToHMSF(currentFrameNum);
446 hmsf lengthHMSF = video->framesToHMSF(lengthFrames);
449 if (currentFrameNum >= lengthFrames)
451 strcpy(buffer, "-:--:-- / -:--:--");
455 SNPRINTF(buffer, 99, "%01i:%02i:%02i / %01i:%02i:%02i", currentFrameHMSF.hours, currentFrameHMSF.minutes, currentFrameHMSF.seconds, lengthHMSF.hours, lengthHMSF.minutes, lengthHMSF.seconds);
456 logger->log("VRadioRec", Log::DEBUG, buffer);
460 ULONG currentSeconds = player->getCurrentSeconds();
461 ULONG lengthSeconds = player->getLengthSeconds();
464 if (lengthSeconds && (currentSeconds < lengthSeconds))
466 ULONG dcurrentSeconds = currentSeconds;
467 ULONG dlengthSeconds = lengthSeconds;
469 ULONG currentHours = dcurrentSeconds / 3600;
470 dcurrentSeconds %= 3600;
471 ULONG currentMinutes = dcurrentSeconds / 60;
472 dcurrentSeconds %= 60;
474 ULONG lengthHours = dlengthSeconds / 3600;
475 dlengthSeconds %= 3600;
476 ULONG lengthMinutes = dlengthSeconds / 60;
477 dlengthSeconds %= 60;
479 SNPRINTF(buffer, 99, "%01lu:%02lu:%02lu / %01lu:%02lu:%02lu", currentHours, currentMinutes, dcurrentSeconds, lengthHours, lengthMinutes, dlengthSeconds);
480 logger->log("VRadioRec", Log::DEBUG, buffer);
484 strcpy(buffer, "-:--:-- / -:--:--");
487 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 boxstack->update(this, &barRegion);