2 Copyright 2004-2006 Chris Tallon
\r
4 This file is part of VOMP.
\r
6 VOMP is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 VOMP is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with VOMP; if not, write to the Free Software
\r
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
21 #include "vradiorec.h"
\r
23 #include "command.h"
\r
26 #include "wsymbol.h"
\r
27 #include "recording.h"
\r
28 #include "message.h"
\r
32 #include "playerradio.h"
\r
33 #include "boxstack.h"
\r
39 VRadioRec::VRadioRec(Recording* rec)
\r
41 boxstack = BoxStack::getInstance();
\r
42 vdr = VDR::getInstance();
\r
43 video = Video::getInstance();
\r
44 timers = Timers::getInstance();
\r
50 player = new PlayerRadio(Command::getInstance(), this);
\r
52 char* cstartMargin = vdr->configLoad("Timers", "Start margin");
\r
53 char* cendMargin = vdr->configLoad("Timers", "End margin");
\r
56 startMargin = 300; // 5 mins default
\r
60 startMargin = atoi(cstartMargin) * 60;
\r
61 delete[] cstartMargin;
\r
66 endMargin = 300; // 5 mins default
\r
70 endMargin = atoi(cendMargin) * 60;
\r
71 delete[] cendMargin;
\r
74 Log::getInstance()->log("VRadioRec", Log::DEBUG, "SM: %u EM: %u", startMargin, endMargin);
\r
76 setSize(video->getScreenWidth(), video->getScreenHeight());
\r
81 barRegion.y = video->getScreenHeight() - 58; // FIXME, need to be - 1? and below?
\r
82 barRegion.w = video->getScreenWidth();
\r
85 clocksRegion.x = barRegion.x + 140;
\r
86 clocksRegion.y = barRegion.y + 12;
\r
87 clocksRegion.w = 170;
\r
88 clocksRegion.h = getFontHeight();
\r
91 barBlue.set(0, 0, 150, 150);
\r
96 void VRadioRec::preDelete()
\r
98 timers->cancelTimer(this, 1);
\r
99 timers->cancelTimer(this, 2);
\r
102 VRadioRec::~VRadioRec()
\r
104 if (playing) stopPlay();
\r
107 // kill recInfo in case resumePoint has changed (likely)
\r
108 myRec->dropRecInfo();
\r
109 // FIXME - do this properly - save the resume point back to the server manually and update
\r
110 // rec->recInfo->resumePoint - this will fix the ~10s offset problem as well
\r
113 void VRadioRec::draw()
\r
115 fillColour(DrawStyle::BLACK);
\r
118 void VRadioRec::go()
\r
120 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Starting stream: %s", myRec->getFileName());
\r
121 ULONG lengthFrames = 0;
\r
122 bool isPesRecording;
\r
123 ULLONG lengthBytes = vdr->streamRecording(myRec->getFileName(), &lengthFrames, &isPesRecording);
\r
124 myRec->IsPesRecording = isPesRecording;
\r
126 bool cantStart = false;
\r
128 if (!lengthBytes) cantStart = true;
\r
129 else if (!player->init(lengthBytes, lengthFrames, myRec->IsPesRecording)) cantStart = true;
\r
133 // player->setStartBytes(startBytes);
\r
140 stopPlay(); // clean up
\r
142 if (!vdr->isConnected())
\r
144 Command::getInstance()->connectionLost();
\r
148 Message* m = new Message();
\r
149 m->message = Message::CLOSE_ME;
\r
152 Command::getInstance()->postMessageNoLock(m);
\r
154 VInfo* vi = new VInfo();
\r
155 vi->setSize(400, 150);
\r
156 vi->createBuffer();
\r
157 if (video->getFormat() == Video::PAL)
\r
158 vi->setPosition(170, 200);
\r
160 vi->setPosition(160, 150);
\r
162 vi->setBorderOn(1);
\r
163 vi->setTitleBarOn(0);
\r
164 vi->setOneLiner(tr("Error playing recording"));
\r
168 m->message = Message::ADD_VIEW;
\r
170 m->parameter = (ULONG)vi;
\r
171 Command::getInstance()->postMessageNoLock(m);
\r
175 int VRadioRec::handleCommand(int command)
\r
185 case Remote::PLAYPAUSE:
\r
187 player->playpause();
\r
196 if (playing) stopPlay();
\r
199 case Remote::PAUSE:
\r
205 case Remote::SKIPFORWARD:
\r
208 player->skipForward(60);
\r
211 case Remote::SKIPBACK:
\r
214 player->skipBackward(60);
\r
217 case Remote::YELLOW:
\r
220 player->skipBackward(10);
\r
226 player->skipForward(10);
\r
231 if (barShowing) removeBar();
\r
236 case Remote::ZERO: player->jumpToPercent(0); doBar(0); return 2;
\r
237 case Remote::ONE: player->jumpToPercent(10); doBar(0); return 2;
\r
238 case Remote::TWO: player->jumpToPercent(20); doBar(0); return 2;
\r
239 case Remote::THREE: player->jumpToPercent(30); doBar(0); return 2;
\r
240 case Remote::FOUR: player->jumpToPercent(40); doBar(0); return 2;
\r
241 case Remote::FIVE: player->jumpToPercent(50); doBar(0); return 2;
\r
242 case Remote::SIX: player->jumpToPercent(60); doBar(0); return 2;
\r
243 case Remote::SEVEN: player->jumpToPercent(70); doBar(0); return 2;
\r
244 case Remote::EIGHT: player->jumpToPercent(80); doBar(0); return 2;
\r
245 case Remote::NINE: player->jumpToPercent(90); doBar(0); return 2;
\r
254 case Remote::GREEN:
\r
266 void VRadioRec::processMessage(Message* m)
\r
268 if (m->message == Message::MOUSE_LBDOWN)
\r
270 int x=(m->parameter>>16)-(int)getScreenX();
\r
271 int y=(m->parameter&0xFFFF)-(int)getScreenY();
\r
274 boxstack->handleCommand(Remote::OK); //simulate rok press
\r
276 else if ((int)barRegion.x<=x && (int)barRegion.y<=y && ((int)barRegion.x+(int)barRegion.w)>=x
\r
277 && ((int)barRegion.y+(int)barRegion.h)>=y)
\r
279 int progBarXbase = barRegion.x + 300;
\r
280 if (x>=(int)barRegion.x + progBarXbase + 24
\r
281 && x<=(int)barRegion.x + progBarXbase + 4 + 302
\r
282 && y>=(int)barRegion.y + 12 - 2
\r
283 && y<=(int)barRegion.y + 12 - 2+28)
\r
285 int cx=x-(barRegion.x + progBarXbase + 4);
\r
286 double percent=((double)cx)/302.*100.;
\r
287 player->jumpToPercent(percent);
\r
290 // int progressWidth = 302 * currentFrameNum / lengthFrames;
\r
291 // rectangle(barRegion.x + progBarXbase + 4, barRegion.y + 16, progressWidth, 16, DrawStyle::SELECTHIGHLIGHT);
\r
296 boxstack->handleCommand(Remote::OK); //simulate rok press
\r
299 else if (m->message == Message::PLAYER_EVENT)
\r
301 if (m->from != player) return;
\r
303 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Message received");
\r
305 switch(m->parameter)
\r
307 case Player::CONNECTION_LOST: // connection lost detected
\r
309 // I can't handle this, send it to command
\r
310 Message* m2 = new Message();
\r
311 m2->to = Command::getInstance();
\r
312 m2->message = Message::CONNECTION_LOST;
\r
313 Command::getInstance()->postMessageNoLock(m2);
\r
316 case Player::STOP_PLAYBACK:
\r
318 // FIXME Obselete ish - improve this
\r
319 Message* m2 = new Message(); // Must be done after this thread finishes, and must break into master mutex
\r
320 m2->to = Command::getInstance();
\r
321 m2->message = Message::STOP_PLAYBACK;
\r
322 Command::getInstance()->postMessageNoLock(m2);
\r
329 void VRadioRec::stopPlay()
\r
331 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Pre stopPlay");
\r
335 vdr->stopStreaming();
\r
340 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
\r
341 Log::getInstance()->log("VRadioRec", Log::DEBUG, "Post stopPlay");
\r
344 void VRadioRec::doBar(int action)
\r
348 rectangle(barRegion, barBlue);
\r
350 /* Work out what to display - choices:
\r
355 Specials, informed by parameter
\r
357 Skip forward 10s >|
\r
358 Skip backward 10s |<
\r
359 Skip forward 1m >>|
\r
360 Skip backward 1m |<<
\r
367 w.setPosition(barRegion.x + 66, barRegion.y + 16);
\r
369 UCHAR playerState = 0;
\r
373 if (action == 1) w.nextSymbol = WSymbol::SKIPFORWARD;
\r
374 else if (action == 2) w.nextSymbol = WSymbol::SKIPBACK;
\r
375 else if (action == 3) w.nextSymbol = WSymbol::SKIPFORWARD2;
\r
376 else if (action == 4) w.nextSymbol = WSymbol::SKIPBACK2;
\r
380 playerState = player->getState();
\r
381 if (playerState == Player::S_PAUSE_P) w.nextSymbol = WSymbol::PAUSE;
\r
382 else if (playerState == Player::S_PAUSE_I) w.nextSymbol = WSymbol::PAUSE;
\r
383 else w.nextSymbol = WSymbol::PLAY;
\r
390 BoxStack::getInstance()->update(this, &barRegion);
\r
392 timers->setTimerD(this, 1, 4); // only set the getridofbar timer if not ffwd/fbwd
\r
393 timers->setTimerD(this, 2, 0, 200000000);
\r
396 void VRadioRec::timercall(int clientReference)
\r
398 switch(clientReference)
\r
409 if (!barShowing) break;
\r
411 boxstack->update(this, &barRegion);
\r
413 timers->setTimerD(this, 2, 0, 200000000);
\r
419 void VRadioRec::drawBarClocks()
\r
421 Log* logger = Log::getInstance();
\r
422 logger->log("VRadioRec", Log::DEBUG, "Draw bar clocks");
\r
425 // Blank the area first
\r
426 rectangle(barRegion.x + 624, barRegion.y + 12, 60, 30, barBlue);
\r
427 char timeString[20];
\r
430 struct tm* tms = localtime(&t);
\r
431 strftime(timeString, 19, "%H:%M", tms);
\r
432 drawText(timeString, barRegion.x + 624, barRegion.y + 12, DrawStyle::LIGHTTEXT);
\r
436 rectangle(clocksRegion, barBlue);
\r
439 ULONG currentFrameNum = player->getCurrentFrameNum();
\r
440 ULONG lengthFrames;
\r
441 if (myRec->recInfo->timerEnd > time(NULL))
\r
443 // chasing playback
\r
444 // Work out an approximate length in frames (good to 1s...)
\r
445 lengthFrames = (myRec->recInfo->timerEnd - myRec->recInfo->timerStart) * video->getFPS();
\r
449 // lengthFrames = player->getLengthFrames();
\r
453 hmsf currentFrameHMSF = video->framesToHMSF(currentFrameNum);
\r
454 hmsf lengthHMSF = video->framesToHMSF(lengthFrames);
\r
457 if (currentFrameNum >= lengthFrames)
\r
459 strcpy(buffer, "-:--:-- / -:--:--");
\r
463 SNPRINTF(buffer, 99, "%01i:%02i:%02i / %01i:%02i:%02i", currentFrameHMSF.hours, currentFrameHMSF.minutes, currentFrameHMSF.seconds, lengthHMSF.hours, lengthHMSF.minutes, lengthHMSF.seconds);
\r
464 logger->log("VRadioRec", Log::DEBUG, buffer);
\r
468 ULONG currentSeconds = player->getCurrentSeconds();
\r
469 ULONG lengthSeconds = player->getLengthSeconds();
\r
472 if (lengthSeconds && (currentSeconds < lengthSeconds))
\r
474 ULONG dcurrentSeconds = currentSeconds;
\r
475 ULONG dlengthSeconds = lengthSeconds;
\r
477 ULONG currentHours = dcurrentSeconds / 3600;
\r
478 dcurrentSeconds %= 3600;
\r
479 ULONG currentMinutes = dcurrentSeconds / 60;
\r
480 dcurrentSeconds %= 60;
\r
482 ULONG lengthHours = dlengthSeconds / 3600;
\r
483 dlengthSeconds %= 3600;
\r
484 ULONG lengthMinutes = dlengthSeconds / 60;
\r
485 dlengthSeconds %= 60;
\r
487 SNPRINTF(buffer, 99, "%01lu:%02lu:%02lu / %01lu:%02lu:%02lu", currentHours, currentMinutes, dcurrentSeconds, lengthHours, lengthMinutes, dlengthSeconds);
\r
488 logger->log("VRadioRec", Log::DEBUG, buffer);
\r
492 strcpy(buffer, "-:--:-- / -:--:--");
\r
495 drawText(buffer, clocksRegion.x, clocksRegion.y, DrawStyle::LIGHTTEXT);
\r
497 // Draw progress bar
\r
498 int progBarXbase = barRegion.x + 300;
\r
500 rectangle(barRegion.x + progBarXbase, barRegion.y + 12, 310, 24, DrawStyle::LIGHTTEXT);
\r
501 rectangle(barRegion.x + progBarXbase + 2, barRegion.y + 14, 306, 20, barBlue);
\r
503 if (currentSeconds > lengthSeconds) return;
\r
504 if (lengthSeconds == 0) return;
\r
506 // Draw yellow portion
\r
507 int progressWidth = 302 * currentSeconds / lengthSeconds;
\r
508 rectangle(barRegion.x + progBarXbase + 4, barRegion.y + 16, progressWidth, 16, DrawStyle::SELECTHIGHLIGHT);
\r
511 if (myRec->recInfo->timerEnd > time(NULL)) // if chasing
\r
513 int nrWidth = (int)(302 * ((double)(lengthFrames - 0) / lengthFrames)); // 0 inserted instead of getlengthframes
\r
515 Log::getInstance()->log("GVASDF", Log::DEBUG, "Length Frames: %lu", lengthFrames);
\r
516 // Log::getInstance()->log("GVASDF", Log::DEBUG, "Player lf: %lu", player->getLengthFrames());
\r
517 Log::getInstance()->log("GVASDF", Log::DEBUG, "NR WDITH: %i", nrWidth);
\r
518 rectangle(barRegion.x + progBarXbase + 4 + 302 - nrWidth, barRegion.y + 16, nrWidth, 16, DrawStyle::RED);
\r
522 logger->log("VRadioRec", Log::DEBUG, "blips");
\r
524 // Now calc position for start margin blips
\r
527 posPix = 302 * startMargin / lengthSeconds;
\r
528 logger->log("VRadioRec", Log::DEBUG, "posPix %i", posPix);
\r
530 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 2, 2, DrawStyle::LIGHTTEXT);
\r
531 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 + 24, 2, 2, DrawStyle::LIGHTTEXT);
\r
533 posPix = 302 * (lengthSeconds - endMargin) / lengthSeconds;
\r
535 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 2, 2, DrawStyle::LIGHTTEXT);
\r
536 rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 + 24, 2, 2, DrawStyle::LIGHTTEXT);
\r
539 void VRadioRec::removeBar()
\r
541 if (!barShowing) return;
\r
542 timers->cancelTimer(this, 2);
\r
543 barShowing = false;
\r
544 rectangle(barRegion, DrawStyle::BLACK);
\r
545 boxstack->update(this, &barRegion);
\r