2 Copyright 2007-2008 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 "vvideolivetv.h"
23 #include "vchannellist.h"
25 #include "playerlive.h"
26 #include "playerlivetv.h"
27 #include "playerliveradio.h"
36 #include "vaudioselector.h"
42 VVideoLiveTV::VVideoLiveTV(ChannelList* tchanList, ULONG initialChannelNumber, VChannelList* tvchannelList)
44 vdr = VDR::getInstance();
45 boxstack = BoxStack::getInstance();
46 video = Video::getInstance();
51 vchannelList = tvchannelList;
52 numberWidth = (int)VDR::getInstance()->getChannelNumberWidth();
54 currentChannelIndex = 0;
55 previousChannelIndex = 0;
62 // Convert channel number to index
64 for(i = 0; i < chanList->size(); i++)
66 if ((*chanList)[i]->number == (UINT)initialChannelNumber)
68 currentChannelIndex = i;
76 videoMode = video->getMode();
78 if ((*chanList)[currentChannelIndex]->type == VDR::VIDEO)
80 streamType = VDR::VIDEO;
81 player = new PlayerLiveTV(Command::getInstance(), this, chanList);
85 streamType = VDR::RADIO;
86 player = new PlayerLiveRadio(Command::getInstance(), this, chanList);
90 setSize(video->getScreenWidth(), video->getScreenHeight());
92 Colour transparent(0, 0, 0, 0);
93 setBackgroundColour(transparent);
96 char* optionWSS = vdr->configLoad("General", "WSS");
99 if (strstr(optionWSS, "Yes")) dowss = true;
102 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Do WSS: %u", dowss);
106 wss.setFormat(video->getFormat());
112 wssRegion.w = video->getScreenWidth();
116 Colour osdBack = Colour(0, 0, 0, 128);
118 osd.setBackgroundColour(osdBack);
119 osd.setPosition(0, video->getScreenHeight() - 150);
120 osd.setSize(video->getScreenWidth(), 150);
121 osd.setVisible(false);
124 clock.setBackgroundColour(osdBack);
125 clock.setPosition(osd.getWidth() - 100, 4);
126 clock.setSize(90, 30);
129 osdChanNum.setBackgroundColour(osdBack);
130 osdChanNum.setPosition(40, 4);
131 osdChanNum.setSize((numberWidth*10) + 22, 30); // 10 px = width of number chars in font
132 osd.add(&osdChanNum);
134 osdChanName.setBackgroundColour(osdBack);
135 osdChanName.setPosition(osdChanNum.getX2() + 10, 4);
136 osdChanName.setSize(300, 30);
137 osd.add(&osdChanName);
139 boxRed.setBackgroundColour(Colour::RED);
140 boxRed.setPosition(50, 104);
141 boxRed.setSize(18, 16);
144 boxGreen.setBackgroundColour(Colour::GREEN);
145 boxGreen.setPosition(220, 104);
146 boxGreen.setSize(18, 16);
149 boxYellow.setBackgroundColour(Colour::YELLOW);
150 boxYellow.setPosition(390, 104);
151 boxYellow.setSize(18, 16);
154 boxBlue.setBackgroundColour(Colour::BLUE);
155 boxBlue.setPosition(560, 104);
156 boxBlue.setSize(18, 16);
159 textRed.setBackgroundColour(osdBack);
160 textRed.setPosition(boxRed.getX()+18, 98);
161 textRed.setSize(120, 30);
162 textRed.setText("Summary");
165 if (streamType == VDR::VIDEO)
167 textGreen.setBackgroundColour(osdBack);
168 textGreen.setPosition(boxGreen.getX()+18, 98);
169 textGreen.setSize(120, 30);
170 textGreen.setText("Audio");
174 textYellow.setBackgroundColour(osdBack);
175 textYellow.setPosition(boxYellow.getX()+18, 98);
176 textYellow.setSize(120, 30);
177 textYellow.setText("");
178 osd.add(&textYellow);
180 textBlue.setBackgroundColour(osdBack);
181 textBlue.setPosition(boxBlue.getX()+18, 98);
182 textBlue.setSize(90, 30);
183 textBlue.setText("EPG");
186 sl.setBackgroundColour(osdBack);
187 sl.setPosition(70, 36);
193 summary.setBackgroundColour(osdBack);
194 summary.setPosition(0, video->getScreenHeight() - 300);
195 summary.setSize(video->getScreenWidth(), 150);
196 summary.setVisible(false);
199 textSummary.setBackgroundColour(osdBack);
200 textSummary.setPosition(40, 10);
201 textSummary.setSize(video->getScreenWidth() - 80, 130);
202 textSummary.setParaMode(true);
203 summary.add(&textSummary);
205 summaryBlackLine.setBackgroundColour(Colour::BLACK);
206 summaryBlackLine.setPosition(0, summary.getHeight() - 4);
207 summaryBlackLine.setSize(summary.getWidth(), 4);
208 summary.add(&summaryBlackLine);
210 sAspectRatio.setPosition(osd.getWidth() - 90, clock.getY2()+4);
211 sAspectRatio.nextColour = Colour::YELLOW;
212 sAspectRatio.setVisible(false);
213 osd.add(&sAspectRatio);
215 bufferBar.setPosition(osd.getWidth() - 94, 70);
216 bufferBar.setSize(50, 20);
217 bufferBar.setVisible(true);
221 Region r1 = summary.getRegionR();
222 Region r2 = osd.getRegionR();
223 osdSummaryRegion = r1 + r2;
226 VVideoLiveTV::~VVideoLiveTV()
231 video->setDefaultAspect();
235 void VVideoLiveTV::delData()
239 int eventListSize = eventList->size();
240 for(int i = 0; i < eventListSize; i++)
242 delete (*eventList)[i];
251 int VVideoLiveTV::handleCommand(int command)
257 if (osd.getVisible())
262 // else drop through to stop
267 vchannelList->highlightChannel((*chanList)[currentChannelIndex]);
299 case Remote::CHANNELUP:
304 case Remote::DF_DOWN:
305 case Remote::CHANNELDOWN:
310 case Remote::PREVCHANNEL:
312 channelChange(PREVIOUS, 0);
313 osdChannelIndex = currentChannelIndex;
346 // key in channel number
353 if (streamType == VDR::VIDEO) doAudioSelector();
371 void VVideoLiveTV::go()
375 boxstack->update(this);
380 player->go(currentChannelIndex);
383 void VVideoLiveTV::stop()
385 Timers::getInstance()->cancelTimer(this, 1);
386 Timers::getInstance()->cancelTimer(this, 2);
391 void VVideoLiveTV::doLeftRight(bool right)
393 if (osd.getVisible())
395 if (right) osdChannelIndex = upChannel(osdChannelIndex);
396 else osdChannelIndex = downChannel(osdChannelIndex);
400 osdChannelIndex = currentChannelIndex;
405 void VVideoLiveTV::doUpDown(bool down)
407 if (osd.getVisible())
421 void VVideoLiveTV::doChanUpDown(int which)
423 channelChange(OFFSET, which);
424 osdChannelIndex = currentChannelIndex;
428 void VVideoLiveTV::doOK()
430 if (osd.getVisible())
435 for(int i = keying - 1; i >= 0; i--) newChannel += keyingInput[i] * (ULONG)pow(10., i);
437 channelChange(NUMBER, newChannel);
438 osdChannelIndex = currentChannelIndex;
441 else if (osdChannelIndex == currentChannelIndex)
447 channelChange(INDEX, osdChannelIndex);
453 osdChannelIndex = currentChannelIndex;
458 void VVideoLiveTV::doSummary()
460 if (summary.getVisible())
462 summary.setVisible(false);
464 boxstack->update(this, summary.getRegion());
465 Timers::getInstance()->setTimerD(this, 1, 8); // Restart a timer to get rid of osd
469 summary.setVisible(true);
471 if (osd.getVisible())
473 Timers::getInstance()->cancelTimer(this, 1);
482 void VVideoLiveTV::doKey(int command)
484 if (!osd.getVisible()) // First key. prep the data
491 for (i = keying - 1; i >= 0; i--) keyingInput[i+1] = keyingInput[i];
492 keyingInput[0] = command;
495 char* keyingString = new char[numberWidth + 1];
496 for (i = 0; i < numberWidth; i++) keyingString[i] = '_';
497 keyingString[numberWidth] = '\0';
499 for (i = 0; i < keying; i++) keyingString[i] = keyingInput[keying - 1 - i] + 48;
501 if (keying == numberWidth)
504 for(i = keying - 1; i >= 0; i--) newChannel += keyingInput[i] * (ULONG)pow(10., i);
506 channelChange(NUMBER, newChannel);
507 osdChannelIndex = currentChannelIndex;
508 Timers::getInstance()->cancelTimer(this, 1); // cancel the timer to react to keying input,
509 displayOSD(true); // this will put one back if required
513 osdChanNum.setText(keyingString);
515 if (!osd.getVisible())
517 osd.setVisible(true);
524 boxstack->update(this, osd.getRegion());
525 Timers::getInstance()->setTimerD(this, 1, 3); // 3s for keying input
527 delete[] keyingString;
530 void VVideoLiveTV::doAudioSelector()
532 // If the osd is already visisble there might be a timer for it
533 Timers::getInstance()->cancelTimer(this, 1);
539 // and reset the display - this is a copy from setNowNextData
540 char formatChanNum[20];
541 SNPRINTF(formatChanNum, 19, "%0*lu", numberWidth, (*chanList)[osdChannelIndex]->number);
542 osdChanNum.setText(formatChanNum);
543 osdChanName.setText((*chanList)[osdChannelIndex]->name);
547 vas = new VAudioSelector(this, (*chanList)[currentChannelIndex], ((PlayerLiveTV*)player)->getCurrentAudioChannel());
548 Colour osdBack = Colour(0, 0, 0, 128);
549 vas->setBackgroundColour(osdBack);
550 vas->setPosition(0, osd.getScreenY() - vas->getHeight());
553 // make vas != null and displayOSD will not set a timer or do any boxstack update
554 summary.setVisible(false);
555 if (osd.getVisible()) displayOSD(false);
556 else displayOSD(true);
559 BoxStack::getInstance()->add(vas);
560 BoxStack::getInstance()->update(this);
561 BoxStack::getInstance()->update(vas);
564 void VVideoLiveTV::doEPG()
566 if (osd.getVisible()) clearScreen();
568 video->setMode(Video::QUARTER);
569 video->setPosition(170, 5); //TODO need to deal with 4:3 switching
571 VEpg* vepg = new VEpg(this, currentChannelIndex, VDR::VIDEO);
574 boxstack->update(vepg);
577 void VVideoLiveTV::setNowNextData()
581 Channel* currentChannel = (*chanList)[osdChannelIndex];
583 char formatChanNum[20];
584 SNPRINTF(formatChanNum, 19, "%0*lu", numberWidth, currentChannel->number);
585 osdChanNum.setText(formatChanNum);
586 osdChanName.setText(currentChannel->name);
588 eventList = VDR::getInstance()->getChannelSchedule(currentChannel->number);
592 sl.addOption(tr("No channel data available"), 0, 1);
596 sort(eventList->begin(), eventList->end(), EventSorter());
598 char tempString[300];
599 char tempString2[300];
602 int eventListSize = eventList->size();
603 for(int i = 0; i < eventListSize; i++)
605 event = (*eventList)[i];
607 //btime = localtime((time_t*)&event->time);
608 time_t etime = event->time;
609 btime = localtime(&etime);
611 strftime(tempString2, 299, "%0H:%0M ", btime);
613 strftime(tempString2, 299, "%H:%M ", btime);
615 SNPRINTF(tempString, 299, "%s %s", tempString2, event->title);
617 sl.addOption(tempString, (ULONG)event, (i==0));
622 void VVideoLiveTV::setSummaryData()
624 // If osd is not being displayed, sl will be filled with now, current channel
625 // If the display was already on, sl will have programme to show summary for, not necessarily current channel and now
626 Event* selectedEvent = (Event*)sl.getCurrentOptionData();
630 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "No summary");
631 textSummary.setText(tr("No summary available"));
635 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Summary: %s", selectedEvent->description);
636 textSummary.setText(selectedEvent->description);
640 void VVideoLiveTV::displayOSD(bool newNowNextData)
642 osd.setVisible(true);
650 if (summary.getVisible())
654 boxstack->update(this, &osdSummaryRegion);
658 boxstack->update(this, osd.getRegion());
659 Timers::getInstance()->setTimerD(this, 1, 4);
663 void VVideoLiveTV::clearScreen()
665 if (!summary.getVisible()) Timers::getInstance()->cancelTimer(this, 1);
667 osd.setVisible(false);
669 if (summary.getVisible())
671 summary.setVisible(false);
673 boxstack->update(this, &osdSummaryRegion);
678 boxstack->update(this, osd.getRegion());
682 void VVideoLiveTV::setClock()
687 struct tm* tms = localtime(&t);
688 strftime(timeString, 19, "%H:%M", tms);
689 clock.setText(timeString);
691 time_t dt = 60 - (t % 60); // seconds to the next minute
692 if (dt == 0) dt = 60; // advance a whole minute if necessary
693 dt += t; // get a time_t value for it rather than using duration
694 // (so it will occur at the actual second and not second and a half)
696 Timers::getInstance()->setTimerT(this, 2, dt);
699 void VVideoLiveTV::timercall(int ref)
705 // Really, now that cancelTimer basically protects us from deletion, why can't we execute gui stuff here?
708 for(int i = keying - 1; i >= 0; i--) newChannel += keyingInput[i] * (ULONG)pow(10., i);
710 Message* m = new Message();
711 m->message = Message::CHANNEL_CHANGE;
713 m->parameter = newChannel;
714 m->tag = 1; // signal to call displayOSD();
715 Command::getInstance()->postMessageFromOuterSpace(m); // FIXME cjt yeah you know what.
719 // We have received a timer, we are not keying. If still prebuffering, don't remove the bar
720 if (preBuffering < 100)
722 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Still prebuffering, not removing osd...");
723 Timers::getInstance()->setTimerD(this, 1, 2); // reset timer for another 2s
727 osd.setVisible(false);
729 Message* m = new Message();
730 m->message = Message::REDRAW;
731 m->to = BoxStack::getInstance();
733 m->parameter = (ULONG)osd.getRegion();
734 Command::getInstance()->postMessageFromOuterSpace(m); // FIXME cjt yeah you know what.
740 if (osd.getVisible())
743 Message* m = new Message();
744 m->message = Message::REDRAW;
745 m->to = BoxStack::getInstance();
747 m->parameter = (ULONG)osd.getRegion();
748 Command::getInstance()->postMessageFromOuterSpace(m); // FIXME cjt yeah you know what.
753 bool VVideoLiveTV::channelChange(UCHAR changeType, UINT newData)
757 if (changeType == INDEX)
759 newChannel = newData;
761 else if (changeType == NUMBER)
764 for(i = 0; i < chanList->size(); i++)
766 if ((*chanList)[i]->number == (UINT)newData)
773 if (i == chanList->size())
779 else if (changeType == OFFSET)
781 if (newData == UP) newChannel = upChannel(currentChannelIndex);
782 else newChannel = downChannel(currentChannelIndex);
784 else if (changeType == PREVIOUS)
786 newChannel = previousChannelIndex;
790 return false; // bad input
793 if (newChannel == currentChannelIndex) return true;
795 previousChannelIndex = currentChannelIndex;
796 currentChannelIndex = newChannel;
800 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Set player to channel %u", currentChannelIndex);
801 player->setChannel(currentChannelIndex);
802 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Done Set player to channel %u", currentChannelIndex);
804 // Blank out the symbols
805 sAspectRatio.setVisible(false);
806 bufferBar.setPercent(0);
811 void VVideoLiveTV::processMessage(Message* m)
813 if (m->message == Message::MOUSE_LBDOWN)
815 //check if press is outside this view! then simulate cancel
816 int x=(m->parameter>>16)-osd.getScreenX();
817 int y=(m->parameter&0xFFFF)-osd.getScreenY();
818 if (osd.getVisible()) {
820 if ((boxRed.getX()<=x) && (boxRed.getX()+(int)boxRed.getWidth()>=x ) &&
821 (boxRed.getY()<=y) && (boxRed.getY()+(int)boxRed.getHeight()>=y )) {
822 BoxStack::getInstance()->handleCommand(Remote::RED);
823 } else if ((boxGreen.getX()<=x) && (boxGreen.getX()+(int)boxGreen.getWidth()>=x ) &&
824 (boxGreen.getY()<=y) && (boxGreen.getY()+(int)boxGreen.getHeight()>=y)){
825 BoxStack::getInstance()->handleCommand(Remote::GREEN);
826 } else if ((boxYellow.getX()<=x) && (boxYellow.getX()+(int)boxYellow.getWidth()>=x ) &&
827 (boxYellow.getY()<=y) && (boxYellow.getY()+(int)boxYellow.getHeight()>=y )){
828 BoxStack::getInstance()->handleCommand(Remote::YELLOW);
829 } else if ((boxBlue.getX()<=x) && (boxBlue.getX()+(int)boxBlue.getWidth()>=x ) &&
830 (boxBlue.getY()<=y) && (boxBlue.getY()+(int)boxBlue.getHeight()>=y )){
831 BoxStack::getInstance()->handleCommand(Remote::BLUE);
833 BoxStack::getInstance()->handleCommand(Remote::OK); //simulate rok press
837 BoxStack::getInstance()->handleCommand(Remote::OK); //simulate rok press
840 else if (m->message == Message::CHANNEL_CHANGE)
842 channelChange(NUMBER, m->parameter);
843 osdChannelIndex = currentChannelIndex;
844 if (m->tag == 1) displayOSD(true);
846 else if (m->message == Message::EPG_CLOSE)
848 video->setMode(videoMode);
850 else if (m->message == Message::CHILD_CLOSE)
858 else if (m->message == Message::AUDIO_CHANGE_CHANNEL)
860 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Received change audio channel to %i", m->parameter);
861 player->setAudioChannel((m->parameter & 0xFFFF),(m->parameter & 0xFF0000)>>16);
863 else if (m->message == Message::PLAYER_EVENT)
867 case PlayerLiveTV::CONNECTION_LOST: // connection lost detected
869 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Received connection lost from player");
870 // I can't handle this, send it to command
871 Message* m2 = new Message();
872 m2->to = Command::getInstance();
873 m2->message = Message::CONNECTION_LOST;
874 Command::getInstance()->postMessageNoLock(m2);
879 case PlayerLiveTV::STREAM_END:
881 // I can't handle this, send it to command - improve this
882 Message* m2 = new Message(); // Must be done after this thread finishes, and must break into master mutex
883 m2->to = Command::getInstance();
884 m2->message = Message::STREAM_END;
885 Command::getInstance()->postMessageNoLock(m2);
890 case PlayerLiveTV::ASPECT43:
892 if ((video->getTVsize() == Video::ASPECT16X9) && dowss)
894 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 43");
897 BoxStack::getInstance()->update(this, &wssRegion);
900 sAspectRatio.nextSymbol = WSymbol::VIDEOASPECT43;
901 sAspectRatio.setVisible(true);
903 if (osd.getVisible()) // don't wake up the whole osd just for a aspect change
906 BoxStack::getInstance()->update(this, osd.getRegion());
911 case PlayerLiveTV::ASPECT169:
913 if ((video->getTVsize() == Video::ASPECT16X9) && dowss)
915 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 169");
918 BoxStack::getInstance()->update(this, &wssRegion);
921 sAspectRatio.nextSymbol = WSymbol::VIDEOASPECT169;
922 sAspectRatio.setVisible(true);
924 if (osd.getVisible()) // don't wake up the whole osd just for a aspect change
927 BoxStack::getInstance()->update(this, osd.getRegion());
932 case PlayerLiveTV::PREBUFFERING:
934 preBuffering = m->tag;
935 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Prebuffering - %u", preBuffering);
936 bufferBar.setPercent(preBuffering);
938 if (osd.getVisible())
940 bufferBar.setVisible(true);
943 bufferBar.getRootBoxRegion(&r);
944 BoxStack::getInstance()->update(this, &r);
951 UINT VVideoLiveTV::upChannel(UINT index)
953 if (index == (chanList->size() - 1)) // at the end
954 return 0; // so go to start
959 UINT VVideoLiveTV::downChannel(UINT index)
961 if (index == 0) // at the start
962 return chanList->size() - 1; // so go to end
967 void VVideoLiveTV::toggleChopSides()
969 if (video->getTVsize() == Video::ASPECT16X9) return; // Means nothing for 16:9 TVs
971 if (videoMode == Video::NORMAL)
973 videoMode = Video::LETTERBOX;
974 video->setMode(Video::LETTERBOX);
978 videoMode = Video::NORMAL;
979 video->setMode(Video::NORMAL);