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(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());
77 transparent.set(0, 0, 0, 0);
78 setBackgroundColour(transparent);
82 barRegion.y = video->getScreenHeight() - 58; // FIXME, need to be - 1? and below?
83 barRegion.w = video->getScreenWidth();
86 clocksRegion.x = barRegion.x + 140;
87 clocksRegion.y = barRegion.y + 12;
89 clocksRegion.h = getFontHeight();
92 barBlue.set(0, 0, 0, 128);
97 void VRadioRec::preDelete()
99 timers->cancelTimer(this, 1);
100 timers->cancelTimer(this, 2);
103 VRadioRec::~VRadioRec()
105 if (playing) stopPlay();
108 // kill recInfo in case resumePoint has changed (likely)
109 myRec->dropRecInfo();
110 // FIXME - do this properly - save the resume point back to the server manually and update
111 // rec->recInfo->resumePoint - this will fix the ~10s offset problem as well
114 void VRadioRec::draw()
116 fillColour(transparent);
119 void VRadioRec::go(bool resume)
123 startFrameNum = myRec->recInfo->resumePoint;
127 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Starting stream: %s", myRec->getFileName());
128 ULONG lengthFrames = 0;
130 ULLONG lengthBytes = vdr->streamRecording(myRec->getFileName(), &lengthFrames, &isPesRecording);
131 myRec->IsPesRecording = isPesRecording;
133 bool cantStart = false;
135 if (!lengthBytes) cantStart = true;
136 else if (!player->init(lengthBytes, lengthFrames, myRec->IsPesRecording)) cantStart = true;
140 player->setCurrentFrameNumber(startFrameNum);
147 stopPlay(); // clean up
149 if (!vdr->isConnected())
151 Command::getInstance()->connectionLost();
155 Message* m = new Message();
156 m->message = Message::CLOSE_ME;
159 MessageQueue::getInstance()->postMessage(m);
161 VInfo* vi = new VInfo();
162 vi->setSize(400, 150);
164 if (video->getFormat() == Video::PAL)
165 vi->setPosition(170, 200);
167 vi->setPosition(160, 150);
170 vi->setTitleBarOn(0);
171 vi->setOneLiner(tr("Error playing recording"));
175 m->message = Message::ADD_VIEW;
177 m->data = reinterpret_cast<void*>(vi);
178 MessageQueue::getInstance()->postMessage(m);
182 int VRadioRec::handleCommand(int command)
192 case Input::PLAYPAUSE:
203 if (playing) stopPlay();
212 case Input::SKIPFORWARD:
215 player->skipForward(60);
218 case Input::SKIPBACK:
221 player->skipBackward(60);
227 player->skipBackward(10);
233 player->skipForward(10);
238 if (barShowing) removeBar();
243 case Input::ZERO: player->jumpToPercent(0); doBar(0); return 2;
244 case Input::ONE: player->jumpToPercent(10); doBar(0); return 2;
245 case Input::TWO: player->jumpToPercent(20); doBar(0); return 2;
246 case Input::THREE: player->jumpToPercent(30); doBar(0); return 2;
247 case Input::FOUR: player->jumpToPercent(40); doBar(0); return 2;
248 case Input::FIVE: player->jumpToPercent(50); doBar(0); return 2;
249 case Input::SIX: player->jumpToPercent(60); doBar(0); return 2;
250 case Input::SEVEN: player->jumpToPercent(70); doBar(0); return 2;
251 case Input::EIGHT: player->jumpToPercent(80); doBar(0); return 2;
252 case Input::NINE: player->jumpToPercent(90); doBar(0); return 2;
273 void VRadioRec::processMessage(Message* m)
275 if (m->message == Message::MOUSE_LBDOWN)
277 int x=(m->parameter>>16)-(int)getScreenX();
278 int y=(m->parameter&0xFFFF)-(int)getScreenY();
281 boxstack->handleCommand(Input::OK); //simulate rok press
283 else if ((int)barRegion.x<=x && (int)barRegion.y<=y && ((int)barRegion.x+(int)barRegion.w)>=x
284 && ((int)barRegion.y+(int)barRegion.h)>=y)
286 int progBarXbase = barRegion.x + 300;
287 if (x>=(int)barRegion.x + progBarXbase + 24
288 && x<=(int)barRegion.x + progBarXbase + 4 + 302
289 && y>=(int)barRegion.y + 12 - 2
290 && y<=(int)barRegion.y + 12 - 2+28)
292 int cx=x-(barRegion.x + progBarXbase + 4);
293 double percent=((double)cx)/302.*100.;
294 player->jumpToPercent(percent);
297 // int progressWidth = 302 * currentFrameNum / lengthFrames;
298 // rectangle(barRegion.x + progBarXbase + 4, barRegion.y + 16, progressWidth, 16, DrawStyle::SELECTHIGHLIGHT);
303 boxstack->handleCommand(Input::OK); //simulate rok press
306 else if (m->message == Message::PLAYER_EVENT)
308 if (m->from != player) return;
310 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Message received");
314 case PlayerRadioRec::CONNECTION_LOST: // connection lost detected
316 // I can't handle this, send it to command
317 Message* m2 = new Message();
318 m2->to = Command::getInstance();
319 m2->message = Message::CONNECTION_LOST;
320 MessageQueue::getInstance()->postMessage(m2);
323 case PlayerRadioRec::STOP_PLAYBACK:
325 // FIXME Obselete ish - improve this
326 Message* m2 = new Message(); // Must be done after this thread finishes, and must break into master mutex
327 m2->to = Command::getInstance();
328 m2->message = Message::STOP_PLAYBACK;
329 MessageQueue::getInstance()->postMessage(m2);
336 void VRadioRec::stopPlay()
338 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Pre stopPlay");
342 vdr->stopStreaming();
347 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
348 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Post stopPlay");
351 void VRadioRec::doBar(int action)
355 rectangle(barRegion, barBlue);
357 /* Work out what to display - choices:
362 Specials, informed by parameter
374 w.setPosition(barRegion.x + 66, barRegion.y + 16);
376 UCHAR playerState = 0;
380 if (action == 1) w.nextSymbol = WSymbol::SKIPFORWARD;
381 else if (action == 2) w.nextSymbol = WSymbol::SKIPBACK;
382 else if (action == 3) w.nextSymbol = WSymbol::SKIPFORWARD2;
383 else if (action == 4) w.nextSymbol = WSymbol::SKIPBACK2;
387 playerState = player->getState();
388 if (playerState == PlayerRadioRec::S_PAUSE_P) w.nextSymbol = WSymbol::PAUSE;
389 else if (playerState == PlayerRadioRec::S_PAUSE_I) w.nextSymbol = WSymbol::PAUSE;
390 else w.nextSymbol = WSymbol::PLAY;
397 BoxStack::getInstance()->update(this, &barRegion);
399 timers->setTimerD(this, 1, 4); // only set the getridofbar timer if not ffwd/fbwd
400 timers->setTimerD(this, 2, 0, 200000000);
403 void VRadioRec::timercall(int clientReference)
405 switch(clientReference)
416 if (!barShowing) break;
418 boxstack->update(this, &barRegion);
420 timers->setTimerD(this, 2, 0, 200000000);
426 void VRadioRec::drawBarClocks()
428 Log* logger = Log::getInstance();
429 logger->log("VRadioRec", Log::DEBUG, "Draw bar clocks");
432 // Blank the area first
433 rectangle(barRegion.x + 624, barRegion.y + 12, 60, 30, barBlue);
438 LOCALTIME_R(&t, &tms);
439 strftime(timeString, 19, "%H:%M", &tms);
440 drawText(timeString, barRegion.x + 624, barRegion.y + 12, DrawStyle::LIGHTTEXT);
444 rectangle(clocksRegion, barBlue);
446 ULONG currentSeconds = player->getCurrentSeconds();
447 ULONG lengthSeconds = player->getLengthSeconds();
450 if (lengthSeconds && (currentSeconds < lengthSeconds))
452 ULONG dcurrentSeconds = currentSeconds;
453 ULONG dlengthSeconds = lengthSeconds;
455 ULONG currentHours = dcurrentSeconds / 3600;
456 dcurrentSeconds %= 3600;
457 ULONG currentMinutes = dcurrentSeconds / 60;
458 dcurrentSeconds %= 60;
460 ULONG lengthHours = dlengthSeconds / 3600;
461 dlengthSeconds %= 3600;
462 ULONG lengthMinutes = dlengthSeconds / 60;
463 dlengthSeconds %= 60;
465 SNPRINTF(buffer, 99, "%01lu:%02lu:%02lu / %01lu:%02lu:%02lu", currentHours, currentMinutes, dcurrentSeconds, lengthHours, lengthMinutes, dlengthSeconds);
466 logger->log("VRadioRec", Log::DEBUG, buffer);
470 strcpy(buffer, "-:--:-- / -:--:--");
473 drawText(buffer, clocksRegion.x, clocksRegion.y, DrawStyle::LIGHTTEXT);
476 int progBarXbase = barRegion.x + 300;
478 rectangle(barRegion.x + progBarXbase, barRegion.y + 12, 310, 24, DrawStyle::LIGHTTEXT);
479 rectangle(barRegion.x + progBarXbase + 2, barRegion.y + 14, 306, 20, barBlue);
481 if (currentSeconds > lengthSeconds) return;
482 if (lengthSeconds == 0) return;
484 // Draw yellow portion
485 int progressWidth = 302 * currentSeconds / lengthSeconds;
486 rectangle(barRegion.x + progBarXbase + 4, barRegion.y + 16, progressWidth, 16, DrawStyle::SELECTHIGHLIGHT);
489 if (myRec->recInfo->timerEnd > time(NULL)) // if chasing
491 int nrWidth = (int)(302 * ((double)(lengthFrames - 0) / lengthFrames)); // 0 inserted instead of getlengthframes
493 Log::getInstance()->log("GVASDF", Log::DEBUG, "Length Frames: %lu", lengthFrames);
494 // Log::getInstance()->log("GVASDF", Log::DEBUG, "Player lf: %lu", player->getLengthFrames());
495 Log::getInstance()->log("GVASDF", Log::DEBUG, "NR WDITH: %i", nrWidth);
496 rectangle(barRegion.x + progBarXbase + 4 + 302 - nrWidth, barRegion.y + 16, nrWidth, 16, DrawStyle::RED);
500 logger->log("VRadioRec", Log::DEBUG, "blips");
502 // Now calc position for start margin blips
505 posPix = 302 * startMargin / lengthSeconds;
506 logger->log("VRadioRec", Log::DEBUG, "posPix %i", posPix);
508 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 2, 2, DrawStyle::LIGHTTEXT);
509 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 + 24, 2, 2, DrawStyle::LIGHTTEXT);
511 posPix = 302 * (lengthSeconds - endMargin) / lengthSeconds;
513 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 2, 2, DrawStyle::LIGHTTEXT);
514 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 + 24, 2, 2, DrawStyle::LIGHTTEXT);
517 void VRadioRec::removeBar()
519 if (!barShowing) return;
520 timers->cancelTimer(this, 2);
522 rectangle(barRegion, transparent);
523 boxstack->update(this, &barRegion);