2 Copyright 2004-2019 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"
33 #include "playerradio.h"
39 #include "messagequeue.h"
41 VRadioRec::VRadioRec(Recording* rec)
43 boxstack = BoxStack::getInstance();
44 vdr = VDR::getInstance();
45 video = Video::getInstance();
46 timers = Timers::getInstance();
52 player = new PlayerRadio(Command::getInstance(), this);
54 char* cstartMargin = vdr->configLoad("Timers", "Start margin");
55 char* cendMargin = vdr->configLoad("Timers", "End margin");
58 startMargin = 300; // 5 mins default
62 startMargin = atoi(cstartMargin) * 60;
63 delete[] cstartMargin;
68 endMargin = 300; // 5 mins default
72 endMargin = atoi(cendMargin) * 60;
76 Log::getInstance()->log("VRadioRec", Log::DEBUG, "SM: %u EM: %u", startMargin, endMargin);
78 setSize(video->getScreenWidth(), video->getScreenHeight());
80 transparent.set(0, 0, 0, 0);
81 setBackgroundColour(transparent);
85 barRegion.y = video->getScreenHeight() - 58; // FIXME, need to be - 1? and below?
86 barRegion.w = video->getScreenWidth();
89 clocksRegion.x = barRegion.x + 140;
90 clocksRegion.y = barRegion.y + 12;
92 clocksRegion.h = getFontHeight();
95 barBlue.set(0, 0, 0, 128);
100 void VRadioRec::preDelete()
102 timers->cancelTimer(this, 1);
103 timers->cancelTimer(this, 2);
106 VRadioRec::~VRadioRec()
108 if (playing) stopPlay();
111 // kill recInfo in case resumePoint has changed (likely)
112 myRec->dropRecInfo();
113 // FIXME - do this properly - save the resume point back to the server manually and update
114 // rec->recInfo->resumePoint - this will fix the ~10s offset problem as well
117 void VRadioRec::draw()
119 fillColour(transparent);
122 void VRadioRec::go(bool resume)
126 startFrameNum = myRec->recInfo->resumePoint;
130 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Starting stream: %s", myRec->getFileName());
131 ULONG lengthFrames = 0;
133 ULLONG lengthBytes = vdr->streamRecording(myRec->getFileName(), &lengthFrames, &isPesRecording);
134 myRec->IsPesRecording = isPesRecording;
136 bool cantStart = false;
138 if (!lengthBytes) cantStart = true;
139 else if (!player->init(lengthBytes, lengthFrames, myRec->IsPesRecording)) cantStart = true;
143 player->setCurrentFrameNumber(startFrameNum);
150 stopPlay(); // clean up
152 if (!vdr->isConnected())
154 Command::getInstance()->connectionLost();
158 Message* m = new Message();
159 m->message = Message::CLOSE_ME;
162 MessageQueue::getInstance()->postMessage(m);
164 VInfo* vi = new VInfo();
165 vi->setSize(400, 150);
167 if (video->getFormat() == Video::PAL)
168 vi->setPosition(170, 200);
170 vi->setPosition(160, 150);
173 vi->setTitleBarOn(0);
174 vi->setOneLiner(tr("Error playing recording"));
178 m->message = Message::ADD_VIEW;
180 m->data = reinterpret_cast<void*>(vi);
181 MessageQueue::getInstance()->postMessage(m);
185 int VRadioRec::handleCommand(int command)
195 case Input::PLAYPAUSE:
206 if (playing) stopPlay();
215 case Input::SKIPFORWARD:
218 player->skipForward(60);
221 case Input::SKIPBACK:
224 player->skipBackward(60);
230 player->skipBackward(10);
236 player->skipForward(10);
241 if (barShowing) removeBar();
246 case Input::ZERO: player->jumpToPercent(0); doBar(0); return 2;
247 case Input::ONE: player->jumpToPercent(10); doBar(0); return 2;
248 case Input::TWO: player->jumpToPercent(20); doBar(0); return 2;
249 case Input::THREE: player->jumpToPercent(30); doBar(0); return 2;
250 case Input::FOUR: player->jumpToPercent(40); doBar(0); return 2;
251 case Input::FIVE: player->jumpToPercent(50); doBar(0); return 2;
252 case Input::SIX: player->jumpToPercent(60); doBar(0); return 2;
253 case Input::SEVEN: player->jumpToPercent(70); doBar(0); return 2;
254 case Input::EIGHT: player->jumpToPercent(80); doBar(0); return 2;
255 case Input::NINE: player->jumpToPercent(90); doBar(0); return 2;
276 void VRadioRec::processMessage(Message* m)
278 if (m->message == Message::MOUSE_LBDOWN)
280 int x=(m->parameter>>16)-(int)getScreenX();
281 int y=(m->parameter&0xFFFF)-(int)getScreenY();
284 boxstack->handleCommand(Input::OK); //simulate rok press
286 else if ((int)barRegion.x<=x && (int)barRegion.y<=y && ((int)barRegion.x+(int)barRegion.w)>=x
287 && ((int)barRegion.y+(int)barRegion.h)>=y)
289 int progBarXbase = barRegion.x + 300;
290 if (x>=(int)barRegion.x + progBarXbase + 24
291 && x<=(int)barRegion.x + progBarXbase + 4 + 302
292 && y>=(int)barRegion.y + 12 - 2
293 && y<=(int)barRegion.y + 12 - 2+28)
295 int cx=x-(barRegion.x + progBarXbase + 4);
296 double percent=((double)cx)/302.*100.;
297 player->jumpToPercent(percent);
300 // int progressWidth = 302 * currentFrameNum / lengthFrames;
301 // rectangle(barRegion.x + progBarXbase + 4, barRegion.y + 16, progressWidth, 16, DrawStyle::SELECTHIGHLIGHT);
306 boxstack->handleCommand(Input::OK); //simulate rok press
309 else if (m->message == Message::PLAYER_EVENT)
311 if (m->from != player) return;
313 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Message received");
317 case Player::CONNECTION_LOST: // connection lost detected
319 // I can't handle this, send it to command
320 Message* m2 = new Message();
321 m2->to = Command::getInstance();
322 m2->message = Message::CONNECTION_LOST;
323 MessageQueue::getInstance()->postMessage(m2);
326 case Player::STOP_PLAYBACK:
328 // FIXME Obselete ish - improve this
329 Message* m2 = new Message(); // Must be done after this thread finishes, and must break into master mutex
330 m2->to = Command::getInstance();
331 m2->message = Message::STOP_PLAYBACK;
332 MessageQueue::getInstance()->postMessage(m2);
339 void VRadioRec::stopPlay()
341 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Pre stopPlay");
345 vdr->stopStreaming();
350 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
351 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Post stopPlay");
354 void VRadioRec::doBar(int action)
358 rectangle(barRegion, barBlue);
360 /* Work out what to display - choices:
365 Specials, informed by parameter
377 w.setPosition(barRegion.x + 66, barRegion.y + 16);
379 UCHAR playerState = 0;
383 if (action == 1) w.nextSymbol = WSymbol::SKIPFORWARD;
384 else if (action == 2) w.nextSymbol = WSymbol::SKIPBACK;
385 else if (action == 3) w.nextSymbol = WSymbol::SKIPFORWARD2;
386 else if (action == 4) w.nextSymbol = WSymbol::SKIPBACK2;
390 playerState = player->getState();
391 if (playerState == Player::S_PAUSE_P) w.nextSymbol = WSymbol::PAUSE;
392 else if (playerState == Player::S_PAUSE_I) w.nextSymbol = WSymbol::PAUSE;
393 else w.nextSymbol = WSymbol::PLAY;
400 BoxStack::getInstance()->update(this, &barRegion);
402 timers->setTimerD(this, 1, 4); // only set the getridofbar timer if not ffwd/fbwd
403 timers->setTimerD(this, 2, 0, 200000000);
406 void VRadioRec::timercall(int clientReference)
408 switch(clientReference)
419 if (!barShowing) break;
421 boxstack->update(this, &barRegion);
423 timers->setTimerD(this, 2, 0, 200000000);
429 void VRadioRec::drawBarClocks()
431 Log* logger = Log::getInstance();
432 logger->log("VRadioRec", Log::DEBUG, "Draw bar clocks");
435 // Blank the area first
436 rectangle(barRegion.x + 624, barRegion.y + 12, 60, 30, barBlue);
441 LOCALTIME_R(&t, &tms);
442 strftime(timeString, 19, "%H:%M", &tms);
443 drawText(timeString, barRegion.x + 624, barRegion.y + 12, DrawStyle::LIGHTTEXT);
447 rectangle(clocksRegion, barBlue);
449 ULONG currentSeconds = player->getCurrentSeconds();
450 ULONG lengthSeconds = player->getLengthSeconds();
453 if (lengthSeconds && (currentSeconds < lengthSeconds))
455 ULONG dcurrentSeconds = currentSeconds;
456 ULONG dlengthSeconds = lengthSeconds;
458 ULONG currentHours = dcurrentSeconds / 3600;
459 dcurrentSeconds %= 3600;
460 ULONG currentMinutes = dcurrentSeconds / 60;
461 dcurrentSeconds %= 60;
463 ULONG lengthHours = dlengthSeconds / 3600;
464 dlengthSeconds %= 3600;
465 ULONG lengthMinutes = dlengthSeconds / 60;
466 dlengthSeconds %= 60;
468 SNPRINTF(buffer, 99, "%01lu:%02lu:%02lu / %01lu:%02lu:%02lu", currentHours, currentMinutes, dcurrentSeconds, lengthHours, lengthMinutes, dlengthSeconds);
469 logger->log("VRadioRec", Log::DEBUG, buffer);
473 strcpy(buffer, "-:--:-- / -:--:--");
476 drawText(buffer, clocksRegion.x, clocksRegion.y, DrawStyle::LIGHTTEXT);
479 int progBarXbase = barRegion.x + 300;
481 rectangle(barRegion.x + progBarXbase, barRegion.y + 12, 310, 24, DrawStyle::LIGHTTEXT);
482 rectangle(barRegion.x + progBarXbase + 2, barRegion.y + 14, 306, 20, barBlue);
484 if (currentSeconds > lengthSeconds) return;
485 if (lengthSeconds == 0) return;
487 // Draw yellow portion
488 int progressWidth = 302 * currentSeconds / lengthSeconds;
489 rectangle(barRegion.x + progBarXbase + 4, barRegion.y + 16, progressWidth, 16, DrawStyle::SELECTHIGHLIGHT);
492 if (myRec->recInfo->timerEnd > time(NULL)) // if chasing
494 int nrWidth = (int)(302 * ((double)(lengthFrames - 0) / lengthFrames)); // 0 inserted instead of getlengthframes
496 Log::getInstance()->log("GVASDF", Log::DEBUG, "Length Frames: %lu", lengthFrames);
497 // Log::getInstance()->log("GVASDF", Log::DEBUG, "Player lf: %lu", player->getLengthFrames());
498 Log::getInstance()->log("GVASDF", Log::DEBUG, "NR WDITH: %i", nrWidth);
499 rectangle(barRegion.x + progBarXbase + 4 + 302 - nrWidth, barRegion.y + 16, nrWidth, 16, DrawStyle::RED);
503 logger->log("VRadioRec", Log::DEBUG, "blips");
505 // Now calc position for start margin blips
508 posPix = 302 * startMargin / lengthSeconds;
509 logger->log("VRadioRec", Log::DEBUG, "posPix %i", posPix);
511 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 2, 2, DrawStyle::LIGHTTEXT);
512 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 + 24, 2, 2, DrawStyle::LIGHTTEXT);
514 posPix = 302 * (lengthSeconds - endMargin) / lengthSeconds;
516 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 2, 2, DrawStyle::LIGHTTEXT);
517 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 + 24, 2, 2, DrawStyle::LIGHTTEXT);
520 void VRadioRec::removeBar()
522 if (!barShowing) return;
523 timers->cancelTimer(this, 2);
525 rectangle(barRegion, transparent);
526 boxstack->update(this, &barRegion);