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());
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, 150, 150);
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::BLACK);
120 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Starting stream: %s", myRec->getFileName());
121 ULONG lengthFrames = 0;
123 ULLONG lengthBytes = vdr->streamRecording(myRec->getFileName(), &lengthFrames, &isPesRecording);
124 myRec->IsPesRecording = isPesRecording;
126 bool cantStart = false;
128 if (!lengthBytes) cantStart = true;
129 else if (!player->init(lengthBytes, lengthFrames, myRec->IsPesRecording)) cantStart = true;
133 // player->setStartBytes(startBytes);
140 stopPlay(); // clean up
142 if (!vdr->isConnected())
144 Command::getInstance()->connectionLost();
148 Message* m = new Message();
149 m->message = Message::CLOSE_ME;
152 Command::getInstance()->postMessageNoLock(m);
154 VInfo* vi = new VInfo();
155 vi->setSize(400, 150);
157 if (video->getFormat() == Video::PAL)
158 vi->setPosition(170, 200);
160 vi->setPosition(160, 150);
163 vi->setTitleBarOn(0);
164 vi->setOneLiner(tr("Error playing recording"));
168 m->message = Message::ADD_VIEW;
170 m->parameter = (ULONG)vi;
171 Command::getInstance()->postMessageNoLock(m);
175 int VRadioRec::handleCommand(int command)
185 case Remote::PLAYPAUSE:
196 if (playing) stopPlay();
205 case Remote::SKIPFORWARD:
208 player->skipForward(60);
211 case Remote::SKIPBACK:
214 player->skipBackward(60);
220 player->skipBackward(10);
226 player->skipForward(10);
231 if (barShowing) removeBar();
236 case Remote::ZERO: player->jumpToPercent(0); doBar(0); return 2;
237 case Remote::ONE: player->jumpToPercent(10); doBar(0); return 2;
238 case Remote::TWO: player->jumpToPercent(20); doBar(0); return 2;
239 case Remote::THREE: player->jumpToPercent(30); doBar(0); return 2;
240 case Remote::FOUR: player->jumpToPercent(40); doBar(0); return 2;
241 case Remote::FIVE: player->jumpToPercent(50); doBar(0); return 2;
242 case Remote::SIX: player->jumpToPercent(60); doBar(0); return 2;
243 case Remote::SEVEN: player->jumpToPercent(70); doBar(0); return 2;
244 case Remote::EIGHT: player->jumpToPercent(80); doBar(0); return 2;
245 case Remote::NINE: player->jumpToPercent(90); doBar(0); return 2;
266 void VRadioRec::processMessage(Message* m)
268 if (m->message == Message::MOUSE_LBDOWN)
270 int x=(m->parameter>>16)-(int)getScreenX();
271 int y=(m->parameter&0xFFFF)-(int)getScreenY();
274 boxstack->handleCommand(Remote::OK); //simulate rok press
276 else if ((int)barRegion.x<=x && (int)barRegion.y<=y && ((int)barRegion.x+(int)barRegion.w)>=x
277 && ((int)barRegion.y+(int)barRegion.h)>=y)
279 int progBarXbase = barRegion.x + 300;
280 if (x>=(int)barRegion.x + progBarXbase + 24
281 && x<=(int)barRegion.x + progBarXbase + 4 + 302
282 && y>=(int)barRegion.y + 12 - 2
283 && y<=(int)barRegion.y + 12 - 2+28)
285 int cx=x-(barRegion.x + progBarXbase + 4);
286 double percent=((double)cx)/302.*100.;
287 player->jumpToPercent(percent);
290 // int progressWidth = 302 * currentFrameNum / lengthFrames;
291 // rectangle(barRegion.x + progBarXbase + 4, barRegion.y + 16, progressWidth, 16, DrawStyle::SELECTHIGHLIGHT);
296 boxstack->handleCommand(Remote::OK); //simulate rok press
299 else if (m->message == Message::PLAYER_EVENT)
301 if (m->from != player) return;
303 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Message received");
307 case Player::CONNECTION_LOST: // connection lost detected
309 // I can't handle this, send it to command
310 Message* m2 = new Message();
311 m2->to = Command::getInstance();
312 m2->message = Message::CONNECTION_LOST;
313 Command::getInstance()->postMessageNoLock(m2);
316 case Player::STOP_PLAYBACK:
318 // FIXME Obselete ish - improve this
319 Message* m2 = new Message(); // Must be done after this thread finishes, and must break into master mutex
320 m2->to = Command::getInstance();
321 m2->message = Message::STOP_PLAYBACK;
322 Command::getInstance()->postMessageNoLock(m2);
329 void VRadioRec::stopPlay()
331 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Pre stopPlay");
335 vdr->stopStreaming();
340 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
341 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Post stopPlay");
344 void VRadioRec::doBar(int action)
348 rectangle(barRegion, barBlue);
350 /* Work out what to display - choices:
355 Specials, informed by parameter
367 w.setPosition(barRegion.x + 66, barRegion.y + 16);
369 UCHAR playerState = 0;
373 if (action == 1) w.nextSymbol = WSymbol::SKIPFORWARD;
374 else if (action == 2) w.nextSymbol = WSymbol::SKIPBACK;
375 else if (action == 3) w.nextSymbol = WSymbol::SKIPFORWARD2;
376 else if (action == 4) w.nextSymbol = WSymbol::SKIPBACK2;
380 playerState = player->getState();
381 if (playerState == Player::S_PAUSE_P) w.nextSymbol = WSymbol::PAUSE;
382 else if (playerState == Player::S_PAUSE_I) w.nextSymbol = WSymbol::PAUSE;
383 else w.nextSymbol = WSymbol::PLAY;
390 BoxStack::getInstance()->update(this, &barRegion);
392 timers->setTimerD(this, 1, 4); // only set the getridofbar timer if not ffwd/fbwd
393 timers->setTimerD(this, 2, 0, 200000000);
396 void VRadioRec::timercall(int clientReference)
398 switch(clientReference)
409 if (!barShowing) break;
411 boxstack->update(this, &barRegion);
413 timers->setTimerD(this, 2, 0, 200000000);
419 void VRadioRec::drawBarClocks()
421 Log* logger = Log::getInstance();
422 logger->log("VRadioRec", Log::DEBUG, "Draw bar clocks");
425 // Blank the area first
426 rectangle(barRegion.x + 624, barRegion.y + 12, 60, 30, barBlue);
430 struct tm* tms = localtime(&t);
431 strftime(timeString, 19, "%H:%M", tms);
432 drawText(timeString, barRegion.x + 624, barRegion.y + 12, DrawStyle::LIGHTTEXT);
436 rectangle(clocksRegion, barBlue);
439 ULONG currentFrameNum = player->getCurrentFrameNum();
441 if (myRec->recInfo->timerEnd > time(NULL))
444 // Work out an approximate length in frames (good to 1s...)
445 lengthFrames = (myRec->recInfo->timerEnd - myRec->recInfo->timerStart) * video->getFPS();
449 // lengthFrames = player->getLengthFrames();
453 hmsf currentFrameHMSF = video->framesToHMSF(currentFrameNum);
454 hmsf lengthHMSF = video->framesToHMSF(lengthFrames);
457 if (currentFrameNum >= lengthFrames)
459 strcpy(buffer, "-:--:-- / -:--:--");
463 SNPRINTF(buffer, 99, "%01i:%02i:%02i / %01i:%02i:%02i", currentFrameHMSF.hours, currentFrameHMSF.minutes, currentFrameHMSF.seconds, lengthHMSF.hours, lengthHMSF.minutes, lengthHMSF.seconds);
464 logger->log("VRadioRec", Log::DEBUG, buffer);
468 ULONG currentSeconds = player->getCurrentSeconds();
469 ULONG lengthSeconds = player->getLengthSeconds();
472 if (lengthSeconds && (currentSeconds < lengthSeconds))
474 ULONG dcurrentSeconds = currentSeconds;
475 ULONG dlengthSeconds = lengthSeconds;
477 ULONG currentHours = dcurrentSeconds / 3600;
478 dcurrentSeconds %= 3600;
479 ULONG currentMinutes = dcurrentSeconds / 60;
480 dcurrentSeconds %= 60;
482 ULONG lengthHours = dlengthSeconds / 3600;
483 dlengthSeconds %= 3600;
484 ULONG lengthMinutes = dlengthSeconds / 60;
485 dlengthSeconds %= 60;
487 SNPRINTF(buffer, 99, "%01lu:%02lu:%02lu / %01lu:%02lu:%02lu", currentHours, currentMinutes, dcurrentSeconds, lengthHours, lengthMinutes, dlengthSeconds);
488 logger->log("VRadioRec", Log::DEBUG, buffer);
492 strcpy(buffer, "-:--:-- / -:--:--");
495 drawText(buffer, clocksRegion.x, clocksRegion.y, DrawStyle::LIGHTTEXT);
498 int progBarXbase = barRegion.x + 300;
500 rectangle(barRegion.x + progBarXbase, barRegion.y + 12, 310, 24, DrawStyle::LIGHTTEXT);
501 rectangle(barRegion.x + progBarXbase + 2, barRegion.y + 14, 306, 20, barBlue);
503 if (currentSeconds > lengthSeconds) return;
504 if (lengthSeconds == 0) return;
506 // Draw yellow portion
507 int progressWidth = 302 * currentSeconds / lengthSeconds;
508 rectangle(barRegion.x + progBarXbase + 4, barRegion.y + 16, progressWidth, 16, DrawStyle::SELECTHIGHLIGHT);
511 if (myRec->recInfo->timerEnd > time(NULL)) // if chasing
513 int nrWidth = (int)(302 * ((double)(lengthFrames - 0) / lengthFrames)); // 0 inserted instead of getlengthframes
515 Log::getInstance()->log("GVASDF", Log::DEBUG, "Length Frames: %lu", lengthFrames);
516 // Log::getInstance()->log("GVASDF", Log::DEBUG, "Player lf: %lu", player->getLengthFrames());
517 Log::getInstance()->log("GVASDF", Log::DEBUG, "NR WDITH: %i", nrWidth);
518 rectangle(barRegion.x + progBarXbase + 4 + 302 - nrWidth, barRegion.y + 16, nrWidth, 16, DrawStyle::RED);
522 logger->log("VRadioRec", Log::DEBUG, "blips");
524 // Now calc position for start margin blips
527 posPix = 302 * startMargin / lengthSeconds;
528 logger->log("VRadioRec", Log::DEBUG, "posPix %i", posPix);
530 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 2, 2, DrawStyle::LIGHTTEXT);
531 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 + 24, 2, 2, DrawStyle::LIGHTTEXT);
533 posPix = 302 * (lengthSeconds - endMargin) / lengthSeconds;
535 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 2, 2, DrawStyle::LIGHTTEXT);
536 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 + 24, 2, 2, DrawStyle::LIGHTTEXT);
539 void VRadioRec::removeBar()
541 if (!barShowing) return;
542 timers->cancelTimer(this, 2);
544 rectangle(barRegion, DrawStyle::BLACK);
545 boxstack->update(this, &barRegion);