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"
38 VRadioRec::VRadioRec(Recording* rec)
40 boxstack = BoxStack::getInstance();
41 vdr = VDR::getInstance();
42 video = Video::getInstance();
43 timers = Timers::getInstance();
49 player = new PlayerRadio(Command::getInstance(), this);
51 char* cstartMargin = vdr->configLoad("Timers", "Start margin");
52 char* cendMargin = vdr->configLoad("Timers", "End margin");
55 startMargin = 300; // 5 mins default
59 startMargin = atoi(cstartMargin) * 60;
60 delete[] cstartMargin;
65 endMargin = 300; // 5 mins default
69 endMargin = atoi(cendMargin) * 60;
73 Log::getInstance()->log("VRadioRec", Log::DEBUG, "SM: %u EM: %u", startMargin, endMargin);
75 setSize(video->getScreenWidth(), video->getScreenHeight());
80 barRegion.y = video->getScreenHeight() - 58; // FIXME, need to be - 1? and below?
81 barRegion.w = video->getScreenWidth();
84 clocksRegion.x = barRegion.x + 140;
85 clocksRegion.y = barRegion.y + 12;
87 clocksRegion.h = surface->getFontHeight();
90 barBlue.set(0, 0, 150, 150);
95 void VRadioRec::preDelete()
97 timers->cancelTimer(this, 1);
98 timers->cancelTimer(this, 2);
101 VRadioRec::~VRadioRec()
103 if (playing) stopPlay();
106 // kill recInfo in case resumePoint has changed (likely)
107 myRec->dropRecInfo();
108 // FIXME - do this properly - save the resume point back to the server manually and update
109 // rec->recInfo->resumePoint - this will fix the ~10s offset problem as well
112 void VRadioRec::draw()
114 fillColour(Colour::BLACK);
119 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Starting stream: %s", myRec->getFileName());
120 ULONG lengthFrames = 0;
121 ULLONG lengthBytes = vdr->streamRecording(myRec->getFileName(), &lengthFrames);
123 bool cantStart = false;
125 if (!lengthBytes) cantStart = true;
126 else if (!player->init(lengthBytes, lengthFrames)) cantStart = true;
130 // player->setStartBytes(startBytes);
137 stopPlay(); // clean up
139 if (!vdr->isConnected())
141 Command::getInstance()->connectionLost();
145 Message* m = new Message();
146 m->message = Message::CLOSE_ME;
149 Command::getInstance()->postMessageNoLock(m);
151 VInfo* vi = new VInfo();
152 vi->setSize(400, 150);
154 if (video->getFormat() == Video::PAL)
155 vi->setPosition(170, 200);
157 vi->setPosition(160, 150);
160 vi->setTitleBarOn(0);
161 vi->setOneLiner(tr("Error playing recording"));
165 m->message = Message::ADD_VIEW;
167 m->parameter = (ULONG)vi;
168 Command::getInstance()->postMessageNoLock(m);
172 int VRadioRec::handleCommand(int command)
187 if (playing) stopPlay();
196 case Remote::SKIPFORWARD:
199 player->skipForward(60);
202 case Remote::SKIPBACK:
205 player->skipBackward(60);
211 player->skipBackward(10);
217 player->skipForward(10);
222 if (barShowing) removeBar();
227 case Remote::ZERO: player->jumpToPercent(0); doBar(0); return 2;
228 case Remote::ONE: player->jumpToPercent(10); doBar(0); return 2;
229 case Remote::TWO: player->jumpToPercent(20); doBar(0); return 2;
230 case Remote::THREE: player->jumpToPercent(30); doBar(0); return 2;
231 case Remote::FOUR: player->jumpToPercent(40); doBar(0); return 2;
232 case Remote::FIVE: player->jumpToPercent(50); doBar(0); return 2;
233 case Remote::SIX: player->jumpToPercent(60); doBar(0); return 2;
234 case Remote::SEVEN: player->jumpToPercent(70); doBar(0); return 2;
235 case Remote::EIGHT: player->jumpToPercent(80); doBar(0); return 2;
236 case Remote::NINE: player->jumpToPercent(90); doBar(0); return 2;
257 void VRadioRec::processMessage(Message* m)
259 if (m->message == Message::MOUSE_LBDOWN)
261 int x=(m->parameter>>16)-(int)getScreenX();
262 int y=(m->parameter&0xFFFF)-(int)getScreenY();
265 boxstack->handleCommand(Remote::OK); //simulate rok press
267 else if ((int)barRegion.x<=x && (int)barRegion.y<=y && ((int)barRegion.x+(int)barRegion.w)>=x
268 && ((int)barRegion.y+(int)barRegion.h)>=y)
270 int progBarXbase = barRegion.x + 300;
271 if (x>=(int)barRegion.x + progBarXbase + 24
272 && x<=(int)barRegion.x + progBarXbase + 4 + 302
273 && y>=(int)barRegion.y + 12 - 2
274 && y<=(int)barRegion.y + 12 - 2+28)
276 int cx=x-(barRegion.x + progBarXbase + 4);
277 double percent=((double)cx)/302.*100.;
278 player->jumpToPercent(percent);
281 // int progressWidth = 302 * currentFrameNum / lengthFrames;
282 // rectangle(barRegion.x + progBarXbase + 4, barRegion.y + 16, progressWidth, 16, Colour::SELECTHIGHLIGHT);
287 boxstack->handleCommand(Remote::OK); //simulate rok press
290 else if (m->message == Message::PLAYER_EVENT)
292 if (m->from != player) return;
294 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Message received");
298 case Player::CONNECTION_LOST: // connection lost detected
300 // I can't handle this, send it to command
301 Message* m2 = new Message();
302 m2->to = Command::getInstance();
303 m2->message = Message::CONNECTION_LOST;
304 Command::getInstance()->postMessageNoLock(m2);
307 case Player::STOP_PLAYBACK:
309 // FIXME Obselete ish - improve this
310 Message* m2 = new Message(); // Must be done after this thread finishes, and must break into master mutex
311 m2->to = Command::getInstance();
312 m2->message = Message::STOP_PLAYBACK;
313 Command::getInstance()->postMessageNoLock(m2);
320 void VRadioRec::stopPlay()
322 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Pre stopPlay");
326 vdr->stopStreaming();
331 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
332 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Post stopPlay");
335 void VRadioRec::doBar(int action)
339 rectangle(barRegion, barBlue);
341 /* Work out what to display - choices:
346 Specials, informed by parameter
358 w.setPosition(barRegion.x + 66, barRegion.y + 16);
360 UCHAR playerState = 0;
364 if (action == 1) w.nextSymbol = WSymbol::SKIPFORWARD;
365 else if (action == 2) w.nextSymbol = WSymbol::SKIPBACK;
366 else if (action == 3) w.nextSymbol = WSymbol::SKIPFORWARD2;
367 else if (action == 4) w.nextSymbol = WSymbol::SKIPBACK2;
371 playerState = player->getState();
372 if (playerState == Player::S_PAUSE_P) w.nextSymbol = WSymbol::PAUSE;
373 else if (playerState == Player::S_PAUSE_I) w.nextSymbol = WSymbol::PAUSE;
374 else w.nextSymbol = WSymbol::PLAY;
381 BoxStack::getInstance()->update(this, &barRegion);
383 timers->setTimerD(this, 1, 4); // only set the getridofbar timer if not ffwd/fbwd
384 timers->setTimerD(this, 2, 0, 200000000);
387 void VRadioRec::timercall(int clientReference)
389 switch(clientReference)
400 if (!barShowing) break;
402 boxstack->update(this, &barRegion);
404 timers->setTimerD(this, 2, 0, 200000000);
410 void VRadioRec::drawBarClocks()
412 Log* logger = Log::getInstance();
413 logger->log("VRadioRec", Log::DEBUG, "Draw bar clocks");
416 // Blank the area first
417 rectangle(barRegion.x + 624, barRegion.y + 12, 60, 30, barBlue);
421 struct tm* tms = localtime(&t);
422 strftime(timeString, 19, "%H:%M", tms);
423 drawText(timeString, barRegion.x + 624, barRegion.y + 12, Colour::LIGHTTEXT);
427 rectangle(clocksRegion, barBlue);
430 ULONG currentFrameNum = player->getCurrentFrameNum();
432 if (myRec->recInfo->timerEnd > time(NULL))
435 // Work out an approximate length in frames (good to 1s...)
436 lengthFrames = (myRec->recInfo->timerEnd - myRec->recInfo->timerStart) * video->getFPS();
440 // lengthFrames = player->getLengthFrames();
444 hmsf currentFrameHMSF = video->framesToHMSF(currentFrameNum);
445 hmsf lengthHMSF = video->framesToHMSF(lengthFrames);
448 if (currentFrameNum >= lengthFrames)
450 strcpy(buffer, "-:--:-- / -:--:--");
454 SNPRINTF(buffer, 99, "%01i:%02i:%02i / %01i:%02i:%02i", currentFrameHMSF.hours, currentFrameHMSF.minutes, currentFrameHMSF.seconds, lengthHMSF.hours, lengthHMSF.minutes, lengthHMSF.seconds);
455 logger->log("VRadioRec", Log::DEBUG, buffer);
459 ULONG currentSeconds = player->getCurrentSeconds();
460 ULONG lengthSeconds = player->getLengthSeconds();
463 if (lengthSeconds && (currentSeconds < lengthSeconds))
465 ULONG dcurrentSeconds = currentSeconds;
466 ULONG dlengthSeconds = lengthSeconds;
468 ULONG currentHours = dcurrentSeconds / 3600;
469 dcurrentSeconds %= 3600;
470 ULONG currentMinutes = dcurrentSeconds / 60;
471 dcurrentSeconds %= 60;
473 ULONG lengthHours = dlengthSeconds / 3600;
474 dlengthSeconds %= 3600;
475 ULONG lengthMinutes = dlengthSeconds / 60;
476 dlengthSeconds %= 60;
478 SNPRINTF(buffer, 99, "%01lu:%02lu:%02lu / %01lu:%02lu:%02lu", currentHours, currentMinutes, dcurrentSeconds, lengthHours, lengthMinutes, dlengthSeconds);
479 logger->log("VRadioRec", Log::DEBUG, buffer);
483 strcpy(buffer, "-:--:-- / -:--:--");
486 drawText(buffer, clocksRegion.x, clocksRegion.y, Colour::LIGHTTEXT);
489 int progBarXbase = barRegion.x + 300;
491 rectangle(barRegion.x + progBarXbase, barRegion.y + 12, 310, 24, Colour::LIGHTTEXT);
492 rectangle(barRegion.x + progBarXbase + 2, barRegion.y + 14, 306, 20, barBlue);
494 if (currentSeconds > lengthSeconds) return;
495 if (lengthSeconds == 0) return;
497 // Draw yellow portion
498 int progressWidth = 302 * currentSeconds / lengthSeconds;
499 rectangle(barRegion.x + progBarXbase + 4, barRegion.y + 16, progressWidth, 16, Colour::SELECTHIGHLIGHT);
502 if (myRec->recInfo->timerEnd > time(NULL)) // if chasing
504 int nrWidth = (int)(302 * ((double)(lengthFrames - 0) / lengthFrames)); // 0 inserted instead of getlengthframes
506 Log::getInstance()->log("GVASDF", Log::DEBUG, "Length Frames: %lu", lengthFrames);
507 // Log::getInstance()->log("GVASDF", Log::DEBUG, "Player lf: %lu", player->getLengthFrames());
508 Log::getInstance()->log("GVASDF", Log::DEBUG, "NR WDITH: %i", nrWidth);
509 rectangle(barRegion.x + progBarXbase + 4 + 302 - nrWidth, barRegion.y + 16, nrWidth, 16, Colour::RED);
513 logger->log("VRadioRec", Log::DEBUG, "blips");
515 // Now calc position for start margin blips
518 posPix = 302 * startMargin / lengthSeconds;
519 logger->log("VRadioRec", Log::DEBUG, "posPix %i", posPix);
521 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 2, 2, Colour::LIGHTTEXT);
522 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 + 24, 2, 2, Colour::LIGHTTEXT);
524 posPix = 302 * (lengthSeconds - endMargin) / lengthSeconds;
526 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 2, 2, Colour::LIGHTTEXT);
527 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 + 24, 2, 2, Colour::LIGHTTEXT);
530 void VRadioRec::removeBar()
532 if (!barShowing) return;
533 timers->cancelTimer(this, 2);
535 rectangle(barRegion, Colour::BLACK);
536 boxstack->update(this, &barRegion);