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());
78 transparent.set(0, 0, 0, 0);
79 setBackgroundColour(transparent);
83 barRegion.y = video->getScreenHeight() - 58; // FIXME, need to be - 1? and below?
84 barRegion.w = video->getScreenWidth();
87 clocksRegion.x = barRegion.x + 140;
88 clocksRegion.y = barRegion.y + 12;
90 clocksRegion.h = getFontHeight();
93 barBlue.set(0, 0, 0, 128);
98 void VRadioRec::preDelete()
100 timers->cancelTimer(this, 1);
101 timers->cancelTimer(this, 2);
104 VRadioRec::~VRadioRec()
106 if (playing) stopPlay();
109 // kill recInfo in case resumePoint has changed (likely)
110 myRec->dropRecInfo();
111 // FIXME - do this properly - save the resume point back to the server manually and update
112 // rec->recInfo->resumePoint - this will fix the ~10s offset problem as well
115 void VRadioRec::draw()
117 fillColour(transparent);
122 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Starting stream: %s", myRec->getFileName());
123 ULONG lengthFrames = 0;
125 ULLONG lengthBytes = vdr->streamRecording(myRec->getFileName(), &lengthFrames, &isPesRecording);
126 myRec->IsPesRecording = isPesRecording;
128 bool cantStart = false;
130 if (!lengthBytes) cantStart = true;
131 else if (!player->init(lengthBytes, lengthFrames, myRec->IsPesRecording)) cantStart = true;
135 // player->setStartBytes(startBytes);
142 stopPlay(); // clean up
144 if (!vdr->isConnected())
146 Command::getInstance()->connectionLost();
150 Message* m = new Message();
151 m->message = Message::CLOSE_ME;
154 Command::getInstance()->postMessageNoLock(m);
156 VInfo* vi = new VInfo();
157 vi->setSize(400, 150);
159 if (video->getFormat() == Video::PAL)
160 vi->setPosition(170, 200);
162 vi->setPosition(160, 150);
165 vi->setTitleBarOn(0);
166 vi->setOneLiner(tr("Error playing recording"));
170 m->message = Message::ADD_VIEW;
172 m->parameter.num = (ULONG)vi;
173 Command::getInstance()->postMessageNoLock(m);
177 int VRadioRec::handleCommand(int command)
187 case Remote::PLAYPAUSE:
198 if (playing) stopPlay();
207 case Remote::SKIPFORWARD:
210 player->skipForward(60);
213 case Remote::SKIPBACK:
216 player->skipBackward(60);
222 player->skipBackward(10);
228 player->skipForward(10);
233 if (barShowing) removeBar();
238 case Remote::ZERO: player->jumpToPercent(0); doBar(0); return 2;
239 case Remote::ONE: player->jumpToPercent(10); doBar(0); return 2;
240 case Remote::TWO: player->jumpToPercent(20); doBar(0); return 2;
241 case Remote::THREE: player->jumpToPercent(30); doBar(0); return 2;
242 case Remote::FOUR: player->jumpToPercent(40); doBar(0); return 2;
243 case Remote::FIVE: player->jumpToPercent(50); doBar(0); return 2;
244 case Remote::SIX: player->jumpToPercent(60); doBar(0); return 2;
245 case Remote::SEVEN: player->jumpToPercent(70); doBar(0); return 2;
246 case Remote::EIGHT: player->jumpToPercent(80); doBar(0); return 2;
247 case Remote::NINE: player->jumpToPercent(90); doBar(0); return 2;
268 void VRadioRec::processMessage(Message* m)
270 if (m->message == Message::MOUSE_LBDOWN)
272 int x=(m->parameter.num>>16)-(int)getScreenX();
273 int y=(m->parameter.num&0xFFFF)-(int)getScreenY();
276 boxstack->handleCommand(Remote::OK); //simulate rok press
278 else if ((int)barRegion.x<=x && (int)barRegion.y<=y && ((int)barRegion.x+(int)barRegion.w)>=x
279 && ((int)barRegion.y+(int)barRegion.h)>=y)
281 int progBarXbase = barRegion.x + 300;
282 if (x>=(int)barRegion.x + progBarXbase + 24
283 && x<=(int)barRegion.x + progBarXbase + 4 + 302
284 && y>=(int)barRegion.y + 12 - 2
285 && y<=(int)barRegion.y + 12 - 2+28)
287 int cx=x-(barRegion.x + progBarXbase + 4);
288 double percent=((double)cx)/302.*100.;
289 player->jumpToPercent(percent);
292 // int progressWidth = 302 * currentFrameNum / lengthFrames;
293 // rectangle(barRegion.x + progBarXbase + 4, barRegion.y + 16, progressWidth, 16, DrawStyle::SELECTHIGHLIGHT);
298 boxstack->handleCommand(Remote::OK); //simulate rok press
301 else if (m->message == Message::PLAYER_EVENT)
303 if (m->from != player) return;
305 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Message received");
307 switch(m->parameter.num)
309 case Player::CONNECTION_LOST: // connection lost detected
311 // I can't handle this, send it to command
312 Message* m2 = new Message();
313 m2->to = Command::getInstance();
314 m2->message = Message::CONNECTION_LOST;
315 Command::getInstance()->postMessageNoLock(m2);
318 case Player::STOP_PLAYBACK:
320 // FIXME Obselete ish - improve this
321 Message* m2 = new Message(); // Must be done after this thread finishes, and must break into master mutex
322 m2->to = Command::getInstance();
323 m2->message = Message::STOP_PLAYBACK;
324 Command::getInstance()->postMessageNoLock(m2);
331 void VRadioRec::stopPlay()
333 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Pre stopPlay");
337 vdr->stopStreaming();
342 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
343 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Post stopPlay");
346 void VRadioRec::doBar(int action)
350 rectangle(barRegion, barBlue);
352 /* Work out what to display - choices:
357 Specials, informed by parameter
369 w.setPosition(barRegion.x + 66, barRegion.y + 16);
371 UCHAR playerState = 0;
375 if (action == 1) w.nextSymbol = WSymbol::SKIPFORWARD;
376 else if (action == 2) w.nextSymbol = WSymbol::SKIPBACK;
377 else if (action == 3) w.nextSymbol = WSymbol::SKIPFORWARD2;
378 else if (action == 4) w.nextSymbol = WSymbol::SKIPBACK2;
382 playerState = player->getState();
383 if (playerState == Player::S_PAUSE_P) w.nextSymbol = WSymbol::PAUSE;
384 else if (playerState == Player::S_PAUSE_I) w.nextSymbol = WSymbol::PAUSE;
385 else w.nextSymbol = WSymbol::PLAY;
392 BoxStack::getInstance()->update(this, &barRegion);
394 timers->setTimerD(this, 1, 4); // only set the getridofbar timer if not ffwd/fbwd
395 timers->setTimerD(this, 2, 0, 200000000);
398 void VRadioRec::timercall(int clientReference)
400 switch(clientReference)
411 if (!barShowing) break;
413 boxstack->update(this, &barRegion);
415 timers->setTimerD(this, 2, 0, 200000000);
421 void VRadioRec::drawBarClocks()
423 Log* logger = Log::getInstance();
424 logger->log("VRadioRec", Log::DEBUG, "Draw bar clocks");
427 // Blank the area first
428 rectangle(barRegion.x + 624, barRegion.y + 12, 60, 30, barBlue);
433 LOCALTIME_R(&t, &tms);
434 strftime(timeString, 19, "%H:%M", &tms);
435 drawText(timeString, barRegion.x + 624, barRegion.y + 12, DrawStyle::LIGHTTEXT);
439 rectangle(clocksRegion, barBlue);
442 ULONG currentFrameNum = player->getCurrentFrameNum();
444 if (myRec->recInfo->timerEnd > time(NULL))
447 // Work out an approximate length in frames (good to 1s...)
448 lengthFrames = (myRec->recInfo->timerEnd - myRec->recInfo->timerStart) * video->getFPS();
452 // lengthFrames = player->getLengthFrames();
456 hmsf currentFrameHMSF = video->framesToHMSF(currentFrameNum);
457 hmsf lengthHMSF = video->framesToHMSF(lengthFrames);
460 if (currentFrameNum >= lengthFrames)
462 strcpy(buffer, "-:--:-- / -:--:--");
466 SNPRINTF(buffer, 99, "%01i:%02i:%02i / %01i:%02i:%02i", currentFrameHMSF.hours, currentFrameHMSF.minutes, currentFrameHMSF.seconds, lengthHMSF.hours, lengthHMSF.minutes, lengthHMSF.seconds);
467 logger->log("VRadioRec", Log::DEBUG, buffer);
471 ULONG currentSeconds = player->getCurrentSeconds();
472 ULONG lengthSeconds = player->getLengthSeconds();
475 if (lengthSeconds && (currentSeconds < lengthSeconds))
477 ULONG dcurrentSeconds = currentSeconds;
478 ULONG dlengthSeconds = lengthSeconds;
480 ULONG currentHours = dcurrentSeconds / 3600;
481 dcurrentSeconds %= 3600;
482 ULONG currentMinutes = dcurrentSeconds / 60;
483 dcurrentSeconds %= 60;
485 ULONG lengthHours = dlengthSeconds / 3600;
486 dlengthSeconds %= 3600;
487 ULONG lengthMinutes = dlengthSeconds / 60;
488 dlengthSeconds %= 60;
490 SNPRINTF(buffer, 99, "%01lu:%02lu:%02lu / %01lu:%02lu:%02lu", currentHours, currentMinutes, dcurrentSeconds, lengthHours, lengthMinutes, dlengthSeconds);
491 logger->log("VRadioRec", Log::DEBUG, buffer);
495 strcpy(buffer, "-:--:-- / -:--:--");
498 drawText(buffer, clocksRegion.x, clocksRegion.y, DrawStyle::LIGHTTEXT);
501 int progBarXbase = barRegion.x + 300;
503 rectangle(barRegion.x + progBarXbase, barRegion.y + 12, 310, 24, DrawStyle::LIGHTTEXT);
504 rectangle(barRegion.x + progBarXbase + 2, barRegion.y + 14, 306, 20, barBlue);
506 if (currentSeconds > lengthSeconds) return;
507 if (lengthSeconds == 0) return;
509 // Draw yellow portion
510 int progressWidth = 302 * currentSeconds / lengthSeconds;
511 rectangle(barRegion.x + progBarXbase + 4, barRegion.y + 16, progressWidth, 16, DrawStyle::SELECTHIGHLIGHT);
514 if (myRec->recInfo->timerEnd > time(NULL)) // if chasing
516 int nrWidth = (int)(302 * ((double)(lengthFrames - 0) / lengthFrames)); // 0 inserted instead of getlengthframes
518 Log::getInstance()->log("GVASDF", Log::DEBUG, "Length Frames: %lu", lengthFrames);
519 // Log::getInstance()->log("GVASDF", Log::DEBUG, "Player lf: %lu", player->getLengthFrames());
520 Log::getInstance()->log("GVASDF", Log::DEBUG, "NR WDITH: %i", nrWidth);
521 rectangle(barRegion.x + progBarXbase + 4 + 302 - nrWidth, barRegion.y + 16, nrWidth, 16, DrawStyle::RED);
525 logger->log("VRadioRec", Log::DEBUG, "blips");
527 // Now calc position for start margin blips
530 posPix = 302 * startMargin / lengthSeconds;
531 logger->log("VRadioRec", Log::DEBUG, "posPix %i", posPix);
533 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 2, 2, DrawStyle::LIGHTTEXT);
534 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 + 24, 2, 2, DrawStyle::LIGHTTEXT);
536 posPix = 302 * (lengthSeconds - endMargin) / lengthSeconds;
538 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 2, 2, DrawStyle::LIGHTTEXT);
539 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 + 24, 2, 2, DrawStyle::LIGHTTEXT);
542 void VRadioRec::removeBar()
544 if (!barShowing) return;
545 timers->cancelTimer(this, 2);
547 rectangle(barRegion, transparent);
548 boxstack->update(this, &barRegion);