2 Copyright 2004-2020 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, see <https://www.gnu.org/licenses/>.
23 #include "recording.h"
28 #include "playerradiorec.h"
34 #include "messagequeue.h"
36 #include "vradiorec.h"
38 static const char* TAG = "VRadioRec";
40 VRadioRec::VRadioRec(Recording* rec)
42 boxstack = BoxStack::getInstance();
43 vdr = VDR::getInstance();
44 video = Video::getInstance();
45 timers = Timers::getInstance();
51 player = new PlayerRadioRec(Control::getInstance(), this);
53 char* cstartMargin = vdr->configLoad("Timers", "Start margin");
54 char* cendMargin = vdr->configLoad("Timers", "End margin");
57 startMargin = 300; // 5 mins default
61 startMargin = atoi(cstartMargin) * 60;
62 delete[] cstartMargin;
67 endMargin = 300; // 5 mins default
71 endMargin = atoi(cendMargin) * 60;
75 LogNT::getInstance()->debug(TAG, "SM: {} EM: {}", startMargin, endMargin);
77 setSize(video->getScreenWidth(), video->getScreenHeight());
79 setBackgroundColour(DrawStyle::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);
97 MessageQueue::getInstance()->addReceiver(this);
100 void VRadioRec::preDelete()
102 timers->cancelTimer(this, 1);
103 timers->cancelTimer(this, 2);
106 VRadioRec::~VRadioRec()
108 MessageQueue::getInstance()->removeReceiver(this);
110 if (playing) stopPlay();
112 // kill recInfo in case resumePoint has changed (likely)
113 myRec->dropRecInfo();
114 // FIXME - do this properly - save the resume point back to the server manually and update
115 // rec->recInfo->resumePoint - this will fix the ~10s offset problem as well
118 void VRadioRec::draw()
120 fillColour(DrawStyle::TRANSPARENT);
123 void VRadioRec::go(bool resume)
127 startFrameNum = myRec->recInfo->resumePoint;
131 LogNT::getInstance()->debug(TAG, "Starting stream: {}", myRec->getFileName());
134 u8 lengthBytes = vdr->streamRecording(myRec->getFileName(), &lengthFrames, &isPesRecording);
135 myRec->IsPesRecording = isPesRecording;
137 bool cantStart = false;
139 if (!lengthBytes) cantStart = true;
140 else if (!player->init(lengthBytes, lengthFrames, myRec->IsPesRecording)) cantStart = true;
144 player->setCurrentFrameNumber(startFrameNum);
151 stopPlay(); // clean up
153 if (!vdr->isConnected())
155 Control::getInstance()->connectionLost();
159 Message* m = new Message();
160 m->message = Message::CLOSE_ME;
162 m->p_to = Message::BOXSTACK;
163 MessageQueue::getInstance()->postMessage(m);
165 VInfo* vi = new VInfo();
166 vi->setSize(400, 150);
168 if (video->getFormat() == Video::PAL)
169 vi->setPosition(170, 200);
171 vi->setPosition(160, 150);
174 vi->setTitleBarOn(0);
175 vi->setOneLiner(tr("Error playing recording"));
179 m->message = Message::ADD_VIEW;
180 m->p_to = Message::BOXSTACK;
181 m->data = reinterpret_cast<void*>(vi);
182 MessageQueue::getInstance()->postMessage(m);
186 int VRadioRec::handleCommand(int command)
194 return BoxStack::COMMAND_HANDLED;
196 case Input::PLAYPAUSE:
200 return BoxStack::COMMAND_HANDLED;
207 if (playing) stopPlay();
208 return BoxStack::DELETE_ME;
214 return BoxStack::COMMAND_HANDLED;
216 case Input::SKIPFORWARD:
219 player->skipForward(60);
220 return BoxStack::COMMAND_HANDLED;
222 case Input::SKIPBACK:
225 player->skipBackward(60);
226 return BoxStack::COMMAND_HANDLED;
231 player->skipBackward(10);
232 return BoxStack::COMMAND_HANDLED;
237 player->skipForward(10);
238 return BoxStack::COMMAND_HANDLED;
242 if (barShowing) removeBar();
244 return BoxStack::COMMAND_HANDLED;
247 case Input::ZERO: player->jumpToPercent(0); doBar(0); return 2;
248 case Input::ONE: player->jumpToPercent(10); doBar(0); return 2;
249 case Input::TWO: player->jumpToPercent(20); doBar(0); return 2;
250 case Input::THREE: player->jumpToPercent(30); doBar(0); return 2;
251 case Input::FOUR: player->jumpToPercent(40); doBar(0); return 2;
252 case Input::FIVE: player->jumpToPercent(50); doBar(0); return 2;
253 case Input::SIX: player->jumpToPercent(60); doBar(0); return 2;
254 case Input::SEVEN: player->jumpToPercent(70); doBar(0); return 2;
255 case Input::EIGHT: player->jumpToPercent(80); doBar(0); return 2;
256 case Input::NINE: player->jumpToPercent(90); doBar(0); return 2;
263 return BoxStack::COMMAND_HANDLED;
268 return BoxStack::COMMAND_HANDLED;
274 return BoxStack::ABANDON_COMMAND;
277 void VRadioRec::processMessage(Message* m)
279 if (m->message == Message::MOUSE_LBDOWN)
281 u4 x = m->parameter - getScreenX();
282 u4 y = m->tag - getScreenY();
285 boxstack->handleCommand(Input::OK); //simulate rok press
287 else if ( (barRegion.x <= x) // If the click happened within the bar region...
288 && (barRegion.y <= y)
289 && ((barRegion.x + barRegion.w) >= x)
290 && ((barRegion.y + barRegion.h) >= y))
292 u4 progBarXbase = barRegion.x + 300;
293 if ( x >= barRegion.x + progBarXbase + 24
294 && x <= barRegion.x + progBarXbase + 4 + 302
295 && y >= barRegion.y + 12 - 2
296 && y <= barRegion.y + 12 - 2+28)
298 int cx = x - (barRegion.x + progBarXbase + 4);
299 double percent = 100 * cx / 302.;
300 player->jumpToPercent(percent); // FIXME check this still works
303 // int progressWidth = 302 * currentFrameNum / lengthFrames;
304 // rectangle(barRegion.x + progBarXbase + 4, barRegion.y + 16, progressWidth, 16, DrawStyle::SELECTHIGHLIGHT);
309 boxstack->handleCommand(Input::OK); //simulate rok press
312 else if (m->message == Message::PLAYER_EVENT)
314 if (m->from != player) return;
316 LogNT::getInstance()->debug(TAG, "Message received");
320 case PlayerRadioRec::CONNECTION_LOST: // connection lost detected
322 // I can't handle this, send it to control
323 Message* m2 = new Message();
324 m2->p_to = Message::CONTROL;
325 m2->message = Message::CONNECTION_LOST;
326 MessageQueue::getInstance()->postMessage(m2);
329 case PlayerRadioRec::STOP_PLAYBACK:
331 // FIXME Obselete ish - improve this
332 Message* m2 = new Message(); // Must be done after this thread finishes, and must break into master mutex
333 m2->p_to = Message::CONTROL;
334 m2->message = Message::STOP_PLAYBACK;
335 MessageQueue::getInstance()->postMessage(m2);
342 void VRadioRec::stopPlay()
344 LogNT::getInstance()->debug(TAG, "Pre stopPlay");
348 vdr->stopStreaming();
353 if (!vdr->isConnected()) { Control::getInstance()->connectionLost(); return; }
354 LogNT::getInstance()->debug(TAG, "Post stopPlay");
357 void VRadioRec::doBar(int action)
361 rectangle(barRegion, barBlue);
363 /* Work out what to display - choices:
368 Specials, informed by parameter
380 w.setPosition(barRegion.x + 66, barRegion.y + 16);
382 UCHAR playerState = 0;
386 if (action == 1) w.nextSymbol = WSymbol::SKIPFORWARD;
387 else if (action == 2) w.nextSymbol = WSymbol::SKIPBACK;
388 else if (action == 3) w.nextSymbol = WSymbol::SKIPFORWARD2;
389 else if (action == 4) w.nextSymbol = WSymbol::SKIPBACK2;
393 playerState = player->getState();
394 if (playerState == PlayerRadioRec::S_PAUSE_P) w.nextSymbol = WSymbol::PAUSE;
395 else if (playerState == PlayerRadioRec::S_PAUSE_I) w.nextSymbol = WSymbol::PAUSE;
396 else w.nextSymbol = WSymbol::PLAY;
403 BoxStack::getInstance()->update(this, &barRegion);
405 timers->setTimerD(this, 1, 4); // only set the getridofbar timer if not ffwd/fbwd
406 timers->setTimerD(this, 2, 0, 200000000);
409 void VRadioRec::timercall(int clientReference)
411 switch(clientReference)
422 if (!barShowing) break;
424 boxstack->update(this, &barRegion);
426 timers->setTimerD(this, 2, 0, 200000000);
432 void VRadioRec::drawBarClocks()
434 LogNT* logger = LogNT::getInstance();
435 logger->debug(TAG, "Draw bar clocks");
438 // Blank the area first
439 rectangle(barRegion.x + 624, barRegion.y + 12, 60, 30, barBlue);
444 LOCALTIME_R(&t, &tms);
445 strftime(timeString, 19, "%H:%M", &tms);
446 drawText(timeString, barRegion.x + 624, barRegion.y + 12, DrawStyle::LIGHTTEXT);
450 rectangle(clocksRegion, barBlue);
452 u4 currentSeconds = player->getCurrentSeconds();
453 u4 lengthSeconds = player->getLengthSeconds();
456 if (lengthSeconds && (currentSeconds < lengthSeconds))
458 u4 dcurrentSeconds = currentSeconds;
459 u4 dlengthSeconds = lengthSeconds;
461 u4 currentHours = dcurrentSeconds / 3600;
462 dcurrentSeconds %= 3600;
463 u4 currentMinutes = dcurrentSeconds / 60;
464 dcurrentSeconds %= 60;
466 u4 lengthHours = dlengthSeconds / 3600;
467 dlengthSeconds %= 3600;
468 u4 lengthMinutes = dlengthSeconds / 60;
469 dlengthSeconds %= 60;
471 SNPRINTF(buffer, 99, "%01lu:%02lu:%02lu / %01lu:%02lu:%02lu", currentHours, currentMinutes, dcurrentSeconds, lengthHours, lengthMinutes, dlengthSeconds);
472 LogNT::getInstance()->debug(TAG, buffer);
476 strcpy(buffer, "-:--:-- / -:--:--");
479 drawText(buffer, clocksRegion.x, clocksRegion.y, DrawStyle::LIGHTTEXT);
482 int progBarXbase = barRegion.x + 300;
484 rectangle(barRegion.x + progBarXbase, barRegion.y + 12, 310, 24, DrawStyle::LIGHTTEXT);
485 rectangle(barRegion.x + progBarXbase + 2, barRegion.y + 14, 306, 20, barBlue);
487 if (currentSeconds > lengthSeconds) return;
488 if (lengthSeconds == 0) return;
490 // Draw yellow portion
491 int progressWidth = 302 * currentSeconds / lengthSeconds;
492 rectangle(barRegion.x + progBarXbase + 4, barRegion.y + 16, progressWidth, 16, DrawStyle::SELECTHIGHLIGHT);
495 if (myRec->recInfo->timerEnd > time(NULL)) // if chasing
497 int nrWidth = (int)(302 * ((double)(lengthFrames - 0) / lengthFrames)); // 0 inserted instead of getlengthframes
499 Log::getInstance()->log("GVASDF", Log::DEBUG, "Length Frames: %lu", lengthFrames);
500 // Log::getInstance()->log("GVASDF", Log::DEBUG, "Player lf: %lu", player->getLengthFrames());
501 Log::getInstance()->log("GVASDF", Log::DEBUG, "NR WDITH: %i", nrWidth);
502 rectangle(barRegion.x + progBarXbase + 4 + 302 - nrWidth, barRegion.y + 16, nrWidth, 16, DrawStyle::RED);
506 LogNT::getInstance()->debug(TAG, "blips");
508 // Now calc position for start margin blips
511 posPix = 302 * startMargin / lengthSeconds;
512 LogNT::getInstance()->debug(TAG, "posPix {}", posPix);
514 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 2, 2, DrawStyle::LIGHTTEXT);
515 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 + 24, 2, 2, DrawStyle::LIGHTTEXT);
517 posPix = 302 * (lengthSeconds - endMargin) / lengthSeconds;
519 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 2, 2, DrawStyle::LIGHTTEXT);
520 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 + 24, 2, 2, DrawStyle::LIGHTTEXT);
523 void VRadioRec::removeBar()
525 if (!barShowing) return;
526 timers->cancelTimer(this, 2);
528 rectangle(barRegion, DrawStyle::TRANSPARENT);
529 boxstack->update(this, &barRegion);