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 VRadioRec::VRadioRec(Recording* rec)
40 boxstack = BoxStack::getInstance();
41 vdr = VDR::getInstance();
42 video = Video::getInstance();
43 timers = Timers::getInstance();
49 player = new PlayerRadioRec(Control::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());
77 setBackgroundColour(DrawStyle::TRANSPARENT);
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 = getFontHeight();
91 barBlue.set(0, 0, 0, 128);
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(DrawStyle::TRANSPARENT);
118 void VRadioRec::go(bool resume)
122 startFrameNum = myRec->recInfo->resumePoint;
126 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Starting stream: %s", myRec->getFileName());
127 ULONG lengthFrames = 0;
129 ULLONG lengthBytes = vdr->streamRecording(myRec->getFileName(), &lengthFrames, &isPesRecording);
130 myRec->IsPesRecording = isPesRecording;
132 bool cantStart = false;
134 if (!lengthBytes) cantStart = true;
135 else if (!player->init(lengthBytes, lengthFrames, myRec->IsPesRecording)) cantStart = true;
139 player->setCurrentFrameNumber(startFrameNum);
146 stopPlay(); // clean up
148 if (!vdr->isConnected())
150 Control::getInstance()->connectionLost();
154 Message* m = new Message();
155 m->message = Message::CLOSE_ME;
157 m->p_to = Message::BOXSTACK;
158 MessageQueue::getInstance()->postMessage(m);
160 VInfo* vi = new VInfo();
161 vi->setSize(400, 150);
163 if (video->getFormat() == Video::PAL)
164 vi->setPosition(170, 200);
166 vi->setPosition(160, 150);
169 vi->setTitleBarOn(0);
170 vi->setOneLiner(tr("Error playing recording"));
174 m->message = Message::ADD_VIEW;
175 m->p_to = Message::BOXSTACK;
176 m->data = reinterpret_cast<void*>(vi);
177 MessageQueue::getInstance()->postMessage(m);
181 int VRadioRec::handleCommand(int command)
191 case Input::PLAYPAUSE:
202 if (playing) stopPlay();
211 case Input::SKIPFORWARD:
214 player->skipForward(60);
217 case Input::SKIPBACK:
220 player->skipBackward(60);
226 player->skipBackward(10);
232 player->skipForward(10);
237 if (barShowing) removeBar();
242 case Input::ZERO: player->jumpToPercent(0); doBar(0); return 2;
243 case Input::ONE: player->jumpToPercent(10); doBar(0); return 2;
244 case Input::TWO: player->jumpToPercent(20); doBar(0); return 2;
245 case Input::THREE: player->jumpToPercent(30); doBar(0); return 2;
246 case Input::FOUR: player->jumpToPercent(40); doBar(0); return 2;
247 case Input::FIVE: player->jumpToPercent(50); doBar(0); return 2;
248 case Input::SIX: player->jumpToPercent(60); doBar(0); return 2;
249 case Input::SEVEN: player->jumpToPercent(70); doBar(0); return 2;
250 case Input::EIGHT: player->jumpToPercent(80); doBar(0); return 2;
251 case Input::NINE: player->jumpToPercent(90); doBar(0); return 2;
272 void VRadioRec::processMessage(Message* m)
274 if (m->message == Message::MOUSE_LBDOWN)
276 UINT x = m->parameter - getScreenX();
277 UINT y = m->tag - getScreenY();
280 boxstack->handleCommand(Input::OK); //simulate rok press
282 else if ( (barRegion.x <= x) // If the click happened within the bar region...
283 && (barRegion.y <= y)
284 && ((barRegion.x + barRegion.w) >= x)
285 && ((barRegion.y + barRegion.h) >= y))
287 UINT progBarXbase = barRegion.x + 300;
288 if ( x >= barRegion.x + progBarXbase + 24
289 && x <= barRegion.x + progBarXbase + 4 + 302
290 && y >= barRegion.y + 12 - 2
291 && y <= barRegion.y + 12 - 2+28)
293 int cx = x - (barRegion.x + progBarXbase + 4);
294 double percent = 100 * cx / 302.;
295 player->jumpToPercent(percent); // FIXME check this still works
298 // int progressWidth = 302 * currentFrameNum / lengthFrames;
299 // rectangle(barRegion.x + progBarXbase + 4, barRegion.y + 16, progressWidth, 16, DrawStyle::SELECTHIGHLIGHT);
304 boxstack->handleCommand(Input::OK); //simulate rok press
307 else if (m->message == Message::PLAYER_EVENT)
309 if (m->from != player) return;
311 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Message received");
315 case PlayerRadioRec::CONNECTION_LOST: // connection lost detected
317 // I can't handle this, send it to control
318 Message* m2 = new Message();
319 m2->p_to = Message::CONTROL;
320 m2->message = Message::CONNECTION_LOST;
321 MessageQueue::getInstance()->postMessage(m2);
324 case PlayerRadioRec::STOP_PLAYBACK:
326 // FIXME Obselete ish - improve this
327 Message* m2 = new Message(); // Must be done after this thread finishes, and must break into master mutex
328 m2->p_to = Message::CONTROL;
329 m2->message = Message::STOP_PLAYBACK;
330 MessageQueue::getInstance()->postMessage(m2);
337 void VRadioRec::stopPlay()
339 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Pre stopPlay");
343 vdr->stopStreaming();
348 if (!vdr->isConnected()) { Control::getInstance()->connectionLost(); return; }
349 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Post stopPlay");
352 void VRadioRec::doBar(int action)
356 rectangle(barRegion, barBlue);
358 /* Work out what to display - choices:
363 Specials, informed by parameter
375 w.setPosition(barRegion.x + 66, barRegion.y + 16);
377 UCHAR playerState = 0;
381 if (action == 1) w.nextSymbol = WSymbol::SKIPFORWARD;
382 else if (action == 2) w.nextSymbol = WSymbol::SKIPBACK;
383 else if (action == 3) w.nextSymbol = WSymbol::SKIPFORWARD2;
384 else if (action == 4) w.nextSymbol = WSymbol::SKIPBACK2;
388 playerState = player->getState();
389 if (playerState == PlayerRadioRec::S_PAUSE_P) w.nextSymbol = WSymbol::PAUSE;
390 else if (playerState == PlayerRadioRec::S_PAUSE_I) w.nextSymbol = WSymbol::PAUSE;
391 else w.nextSymbol = WSymbol::PLAY;
398 BoxStack::getInstance()->update(this, &barRegion);
400 timers->setTimerD(this, 1, 4); // only set the getridofbar timer if not ffwd/fbwd
401 timers->setTimerD(this, 2, 0, 200000000);
404 void VRadioRec::timercall(int clientReference)
406 switch(clientReference)
417 if (!barShowing) break;
419 boxstack->update(this, &barRegion);
421 timers->setTimerD(this, 2, 0, 200000000);
427 void VRadioRec::drawBarClocks()
429 Log* logger = Log::getInstance();
430 logger->log("VRadioRec", Log::DEBUG, "Draw bar clocks");
433 // Blank the area first
434 rectangle(barRegion.x + 624, barRegion.y + 12, 60, 30, barBlue);
439 LOCALTIME_R(&t, &tms);
440 strftime(timeString, 19, "%H:%M", &tms);
441 drawText(timeString, barRegion.x + 624, barRegion.y + 12, DrawStyle::LIGHTTEXT);
445 rectangle(clocksRegion, barBlue);
447 ULONG currentSeconds = player->getCurrentSeconds();
448 ULONG lengthSeconds = player->getLengthSeconds();
451 if (lengthSeconds && (currentSeconds < lengthSeconds))
453 ULONG dcurrentSeconds = currentSeconds;
454 ULONG dlengthSeconds = lengthSeconds;
456 ULONG currentHours = dcurrentSeconds / 3600;
457 dcurrentSeconds %= 3600;
458 ULONG currentMinutes = dcurrentSeconds / 60;
459 dcurrentSeconds %= 60;
461 ULONG lengthHours = dlengthSeconds / 3600;
462 dlengthSeconds %= 3600;
463 ULONG lengthMinutes = dlengthSeconds / 60;
464 dlengthSeconds %= 60;
466 SNPRINTF(buffer, 99, "%01lu:%02lu:%02lu / %01lu:%02lu:%02lu", currentHours, currentMinutes, dcurrentSeconds, lengthHours, lengthMinutes, dlengthSeconds);
467 logger->log("VRadioRec", Log::DEBUG, buffer);
471 strcpy(buffer, "-:--:-- / -:--:--");
474 drawText(buffer, clocksRegion.x, clocksRegion.y, DrawStyle::LIGHTTEXT);
477 int progBarXbase = barRegion.x + 300;
479 rectangle(barRegion.x + progBarXbase, barRegion.y + 12, 310, 24, DrawStyle::LIGHTTEXT);
480 rectangle(barRegion.x + progBarXbase + 2, barRegion.y + 14, 306, 20, barBlue);
482 if (currentSeconds > lengthSeconds) return;
483 if (lengthSeconds == 0) return;
485 // Draw yellow portion
486 int progressWidth = 302 * currentSeconds / lengthSeconds;
487 rectangle(barRegion.x + progBarXbase + 4, barRegion.y + 16, progressWidth, 16, DrawStyle::SELECTHIGHLIGHT);
490 if (myRec->recInfo->timerEnd > time(NULL)) // if chasing
492 int nrWidth = (int)(302 * ((double)(lengthFrames - 0) / lengthFrames)); // 0 inserted instead of getlengthframes
494 Log::getInstance()->log("GVASDF", Log::DEBUG, "Length Frames: %lu", lengthFrames);
495 // Log::getInstance()->log("GVASDF", Log::DEBUG, "Player lf: %lu", player->getLengthFrames());
496 Log::getInstance()->log("GVASDF", Log::DEBUG, "NR WDITH: %i", nrWidth);
497 rectangle(barRegion.x + progBarXbase + 4 + 302 - nrWidth, barRegion.y + 16, nrWidth, 16, DrawStyle::RED);
501 logger->log("VRadioRec", Log::DEBUG, "blips");
503 // Now calc position for start margin blips
506 posPix = 302 * startMargin / lengthSeconds;
507 logger->log("VRadioRec", Log::DEBUG, "posPix %i", posPix);
509 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 2, 2, DrawStyle::LIGHTTEXT);
510 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 + 24, 2, 2, DrawStyle::LIGHTTEXT);
512 posPix = 302 * (lengthSeconds - endMargin) / lengthSeconds;
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);
518 void VRadioRec::removeBar()
520 if (!barShowing) return;
521 timers->cancelTimer(this, 2);
523 rectangle(barRegion, DrawStyle::TRANSPARENT);
524 boxstack->update(this, &barRegion);