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(tr("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(tr("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(tr("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, 40);
211 sAspectRatio.nextColour = Colour::SELECTHIGHLIGHT;
212 sAspectRatio.setVisible(false);
213 osd.add(&sAspectRatio);
215 bufferBar.setPosition(osd.getWidth() - 90, 70);
216 bufferBar.setSize(40, 20);
217 bufferBar.setVisible(true);
220 sAudioChannels.setPosition(osd.getWidth() - 130, 40);
221 sAudioChannels.nextColour = Colour::SELECTHIGHLIGHT;
222 sAudioChannels.setVisible(false);
223 osd.add(&sAudioChannels);
225 textUnavailable.setBackgroundColour(osdBack);
226 textUnavailable.setPosition(60, 30);
227 textUnavailable.setSize(osd.getWidth() - 120, 30);
228 textUnavailable.setText(tr("Channel Unavailable"));
229 textUnavailable.setVisible(false);
230 add(&textUnavailable);
233 Region r1 = summary.getRegionR();
234 Region r2 = osd.getRegionR();
235 osdSummaryRegion = r1 + r2;
238 VVideoLiveTV::~VVideoLiveTV()
243 video->setDefaultAspect();
247 void VVideoLiveTV::delData()
251 int eventListSize = eventList->size();
252 for(int i = 0; i < eventListSize; i++)
254 delete (*eventList)[i];
263 int VVideoLiveTV::handleCommand(int command)
269 if (osd.getVisible())
274 // else drop through to stop
279 vchannelList->highlightChannel((*chanList)[currentChannelIndex]);
312 // Old remote, decide what to do based on whether the osd is showing
313 if (osd.getVisible()) doUpDown(false);
314 else doChanUpDown(UP);
317 case Remote::DF_DOWN:
319 // Old remote, decide what to do based on whether the osd is showing
320 if (osd.getVisible()) doUpDown(true);
321 else doChanUpDown(DOWN);
324 case Remote::CHANNELUP:
329 case Remote::CHANNELDOWN:
334 case Remote::PREVCHANNEL:
336 channelChange(PREVIOUS, 0);
337 osdChannelIndex = currentChannelIndex;
370 // key in channel number
377 if (streamType == VDR::VIDEO) doAudioSelector();
395 void VVideoLiveTV::go()
399 boxstack->update(this);
404 player->go(currentChannelIndex);
407 void VVideoLiveTV::stop()
409 Timers::getInstance()->cancelTimer(this, 1);
410 Timers::getInstance()->cancelTimer(this, 2);
415 void VVideoLiveTV::doLeftRight(bool right)
417 if (osd.getVisible())
419 if (right) osdChannelIndex = upChannel(osdChannelIndex);
420 else osdChannelIndex = downChannel(osdChannelIndex);
424 osdChannelIndex = currentChannelIndex;
429 void VVideoLiveTV::doUpDown(bool down)
431 if (osd.getVisible())
445 void VVideoLiveTV::doChanUpDown(int which)
447 channelChange(OFFSET, which);
448 osdChannelIndex = currentChannelIndex;
452 void VVideoLiveTV::doOK()
454 if (osd.getVisible())
459 for(int i = keying - 1; i >= 0; i--) newChannel += keyingInput[i] * (ULONG)pow(10., i);
461 channelChange(NUMBER, newChannel);
462 osdChannelIndex = currentChannelIndex;
465 else if (osdChannelIndex == currentChannelIndex)
471 channelChange(INDEX, osdChannelIndex);
477 osdChannelIndex = currentChannelIndex;
482 void VVideoLiveTV::doSummary()
484 if (summary.getVisible())
486 summary.setVisible(false);
488 boxstack->update(this, summary.getRegion());
489 Timers::getInstance()->setTimerD(this, 1, 8); // Restart a timer to get rid of osd
493 summary.setVisible(true);
495 if (osd.getVisible())
497 Timers::getInstance()->cancelTimer(this, 1);
506 void VVideoLiveTV::doKey(int command)
508 if (!osd.getVisible()) // First key. prep the data
515 for (i = keying - 1; i >= 0; i--) keyingInput[i+1] = keyingInput[i];
516 keyingInput[0] = command;
519 char* keyingString = new char[numberWidth + 1];
520 for (i = 0; i < numberWidth; i++) keyingString[i] = '_';
521 keyingString[numberWidth] = '\0';
523 for (i = 0; i < keying; i++) keyingString[i] = keyingInput[keying - 1 - i] + 48;
525 if (keying == numberWidth)
528 for(i = keying - 1; i >= 0; i--) newChannel += keyingInput[i] * (ULONG)pow(10., i);
530 channelChange(NUMBER, newChannel);
531 osdChannelIndex = currentChannelIndex;
532 Timers::getInstance()->cancelTimer(this, 1); // cancel the timer to react to keying input,
533 displayOSD(true); // this will put one back if required
537 osdChanNum.setText(keyingString);
539 if (!osd.getVisible())
541 osd.setVisible(true);
548 boxstack->update(this, osd.getRegion());
549 Timers::getInstance()->setTimerD(this, 1, 3); // 3s for keying input
551 delete[] keyingString;
554 void VVideoLiveTV::doAudioSelector()
556 // If the osd is already visisble there might be a timer for it
557 Timers::getInstance()->cancelTimer(this, 1);
563 // and reset the display - this is a copy from setNowNextData
564 char formatChanNum[20];
565 SNPRINTF(formatChanNum, 19, "%0*lu", numberWidth, (*chanList)[osdChannelIndex]->number);
566 osdChanNum.setText(formatChanNum);
567 osdChanName.setText((*chanList)[osdChannelIndex]->name);
571 vas = new VAudioSelector(this, (*chanList)[currentChannelIndex], ((PlayerLiveTV*)player)->getCurrentAudioChannel());
572 Colour osdBack = Colour(0, 0, 0, 128);
573 vas->setBackgroundColour(osdBack);
574 vas->setPosition(0, osd.getScreenY() - vas->getHeight());
577 // make vas != null and displayOSD will not set a timer or do any boxstack update
578 summary.setVisible(false);
579 if (osd.getVisible()) displayOSD(false);
580 else displayOSD(true);
583 BoxStack::getInstance()->add(vas);
584 BoxStack::getInstance()->update(this);
585 BoxStack::getInstance()->update(vas);
588 void VVideoLiveTV::doEPG()
590 if (osd.getVisible()) clearScreen();
592 video->setMode(Video::QUARTER);
593 video->setPosition(170, 5); //TODO need to deal with 4:3 switching
595 VEpg* vepg = new VEpg(this, currentChannelIndex, VDR::VIDEO);
598 boxstack->update(vepg);
601 void VVideoLiveTV::setNowNextData()
605 Channel* currentChannel = (*chanList)[osdChannelIndex];
607 char formatChanNum[20];
608 SNPRINTF(formatChanNum, 19, "%0*lu", numberWidth, currentChannel->number);
609 osdChanNum.setText(formatChanNum);
610 osdChanName.setText(currentChannel->name);
612 eventList = VDR::getInstance()->getChannelSchedule(currentChannel->number);
616 sl.addOption(tr("No channel data available"), 0, 1);
620 sort(eventList->begin(), eventList->end(), EventSorter());
622 char tempString[300];
623 char tempString2[300];
626 int eventListSize = eventList->size();
627 for(int i = 0; i < eventListSize; i++)
629 event = (*eventList)[i];
631 //btime = localtime((time_t*)&event->time);
632 time_t etime = event->time;
633 btime = localtime(&etime);
635 strftime(tempString2, 299, "%0H:%0M ", btime);
637 strftime(tempString2, 299, "%H:%M ", btime);
639 SNPRINTF(tempString, 299, "%s %s", tempString2, event->title);
641 sl.addOption(tempString, (ULONG)event, (i==0));
646 void VVideoLiveTV::setSummaryData()
648 // If osd is not being displayed, sl will be filled with now, current channel
649 // If the display was already on, sl will have programme to show summary for, not necessarily current channel and now
650 Event* selectedEvent = (Event*)sl.getCurrentOptionData();
654 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "No summary");
655 textSummary.setText(tr("No summary available"));
659 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Summary: %s", selectedEvent->description);
660 textSummary.setText(selectedEvent->description);
664 void VVideoLiveTV::displayOSD(bool newNowNextData)
666 osd.setVisible(true);
674 if (summary.getVisible())
678 boxstack->update(this, &osdSummaryRegion);
682 boxstack->update(this, osd.getRegion());
685 bool setTimer = true;
686 if (vas) setTimer = false;
687 if (summary.getVisible()) setTimer = false;
688 if (textUnavailable.getVisible()) setTimer = false;
690 if (setTimer) Timers::getInstance()->setTimerD(this, 1, 4);
693 void VVideoLiveTV::clearScreen()
695 if (!summary.getVisible()) Timers::getInstance()->cancelTimer(this, 1);
697 textUnavailable.setVisible(false);
698 osd.setVisible(false);
699 summary.setVisible(false);
702 boxstack->update(this);
705 void VVideoLiveTV::showUnavailable()
707 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Show unavailable called");
708 textUnavailable.setVisible(true);
709 textUnavailable.draw();
711 if (!osd.getVisible()) displayOSD(true);
713 boxstack->update(this, textUnavailable.getRegion());
716 void VVideoLiveTV::setClock()
721 struct tm* tms = localtime(&t);
722 strftime(timeString, 19, "%H:%M", tms);
723 clock.setText(timeString);
725 time_t dt = 60 - (t % 60); // seconds to the next minute
726 if (dt == 0) dt = 60; // advance a whole minute if necessary
727 dt += t; // get a time_t value for it rather than using duration
728 // (so it will occur at the actual second and not second and a half)
730 Timers::getInstance()->setTimerT(this, 2, dt);
733 void VVideoLiveTV::timercall(int ref)
740 for(int i = keying - 1; i >= 0; i--) newChannel += keyingInput[i] * (ULONG)pow(10., i);
742 Message* m = new Message();
743 m->message = Message::CHANNEL_CHANGE;
745 m->parameter = newChannel;
746 m->tag = 1; // signal to call displayOSD();
747 Command::getInstance()->postMessageFromOuterSpace(m);
751 // We have received a timer, we are not keying. If still prebuffering, don't remove the bar
752 if (preBuffering < 100)
754 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Still prebuffering, not removing osd...");
755 Timers::getInstance()->setTimerD(this, 1, 2); // reset timer for another 2s
759 osd.setVisible(false);
761 boxstack->update(this, osd.getRegion());
767 if (osd.getVisible())
770 boxstack->update(this, osd.getRegion());
775 bool VVideoLiveTV::channelChange(UCHAR changeType, UINT newData)
779 if (changeType == INDEX)
781 newChannel = newData;
783 else if (changeType == NUMBER)
786 for(i = 0; i < chanList->size(); i++)
788 if ((*chanList)[i]->number == (UINT)newData)
795 if (i == chanList->size())
801 else if (changeType == OFFSET)
803 if (newData == UP) newChannel = upChannel(currentChannelIndex);
804 else newChannel = downChannel(currentChannelIndex);
806 else if (changeType == PREVIOUS)
808 newChannel = previousChannelIndex;
812 return false; // bad input
815 if (newChannel == currentChannelIndex) return true;
817 previousChannelIndex = currentChannelIndex;
818 currentChannelIndex = newChannel;
822 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Set player to channel %u", currentChannelIndex);
823 player->setChannel(currentChannelIndex);
824 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Done Set player to channel %u", currentChannelIndex);
826 // Blank out the symbols
827 sAspectRatio.setVisible(false);
828 bufferBar.setPercent(0);
829 sAudioChannels.setVisible(false);
831 // Remove other stuff
832 if (textUnavailable.getVisible())
834 textUnavailable.setVisible(false);
836 BoxStack::getInstance()->update(this);
842 void VVideoLiveTV::processMessage(Message* m)
844 if (m->message == Message::MOUSE_LBDOWN)
846 //check if press is outside this view! then simulate cancel
847 int x=(m->parameter>>16)-osd.getScreenX();
848 int y=(m->parameter&0xFFFF)-osd.getScreenY();
849 if (osd.getVisible()) {
851 if ((boxRed.getX()<=x) && (boxRed.getX()+(int)boxRed.getWidth()>=x ) &&
852 (boxRed.getY()<=y) && (boxRed.getY()+(int)boxRed.getHeight()>=y )) {
853 BoxStack::getInstance()->handleCommand(Remote::RED);
854 } else if ((boxGreen.getX()<=x) && (boxGreen.getX()+(int)boxGreen.getWidth()>=x ) &&
855 (boxGreen.getY()<=y) && (boxGreen.getY()+(int)boxGreen.getHeight()>=y)){
856 BoxStack::getInstance()->handleCommand(Remote::GREEN);
857 } else if ((boxYellow.getX()<=x) && (boxYellow.getX()+(int)boxYellow.getWidth()>=x ) &&
858 (boxYellow.getY()<=y) && (boxYellow.getY()+(int)boxYellow.getHeight()>=y )){
859 BoxStack::getInstance()->handleCommand(Remote::YELLOW);
860 } else if ((boxBlue.getX()<=x) && (boxBlue.getX()+(int)boxBlue.getWidth()>=x ) &&
861 (boxBlue.getY()<=y) && (boxBlue.getY()+(int)boxBlue.getHeight()>=y )){
862 BoxStack::getInstance()->handleCommand(Remote::BLUE);
864 BoxStack::getInstance()->handleCommand(Remote::OK); //simulate rok press
868 BoxStack::getInstance()->handleCommand(Remote::OK); //simulate rok press
871 else if (m->message == Message::CHANNEL_CHANGE)
873 channelChange(NUMBER, m->parameter);
874 osdChannelIndex = currentChannelIndex;
875 if (m->tag == 1) displayOSD(true);
877 else if (m->message == Message::EPG_CLOSE)
879 video->setMode(videoMode);
881 else if (m->message == Message::CHILD_CLOSE)
889 else if (m->message == Message::AUDIO_CHANGE_CHANNEL)
891 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Received change audio channel to %i", m->parameter);
892 player->setAudioChannel((m->parameter & 0xFFFF),(m->parameter & 0xFF0000)>>16);
894 else if (m->message == Message::PLAYER_EVENT)
898 case PlayerLiveTV::CONNECTION_LOST: // connection lost detected
900 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Received connection lost from player");
901 Command::getInstance()->connectionLost();
905 case PlayerLiveTV::STREAM_END:
907 // Message comes from playerlivetv through master mutex, so can do anything here
912 case PlayerLiveTV::ASPECT43:
914 if ((video->getTVsize() == Video::ASPECT16X9) && dowss)
916 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 43");
919 BoxStack::getInstance()->update(this, &wssRegion);
922 sAspectRatio.nextSymbol = WSymbol::VIDEOASPECT43;
923 sAspectRatio.setVisible(true);
925 if (osd.getVisible()) // don't wake up the whole osd just for a aspect change
928 BoxStack::getInstance()->update(this, osd.getRegion());
933 case PlayerLiveTV::ASPECT169:
935 if ((video->getTVsize() == Video::ASPECT16X9) && dowss)
937 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 169");
940 BoxStack::getInstance()->update(this, &wssRegion);
943 sAspectRatio.nextSymbol = WSymbol::VIDEOASPECT169;
944 sAspectRatio.setVisible(true);
946 if (osd.getVisible()) // don't wake up the whole osd just for a aspect change
949 BoxStack::getInstance()->update(this, osd.getRegion());
954 case PlayerLiveTV::PREBUFFERING:
956 preBuffering = m->tag;
957 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Prebuffering - %u", preBuffering);
958 bufferBar.setPercent(preBuffering);
960 if (osd.getVisible())
962 bufferBar.setVisible(true);
965 bufferBar.getRootBoxRegion(&r); ///////// FIXME !!!
966 BoxStack::getInstance()->update(this, &r);
968 if (preBuffering == 100)
970 doAudioChannelSymbol();
978 void VVideoLiveTV::doAudioChannelSymbol()
981 Channel* currentChannel = (*chanList)[osdChannelIndex];
983 bool multiAudio = false;
985 if (currentChannel->numDPids > 1) multiAudio = true;
987 if (currentChannel->numAPids > 1) multiAudio = true;
991 if (multiAudio) sAudioChannels.nextSymbol = WSymbol::MULTIAUDIO;
992 else sAudioChannels.nextSymbol = WSymbol::SINGLEAUDIO;
993 sAudioChannels.setVisible(true);
995 if (osd.getVisible())
997 sAudioChannels.draw();
999 sAudioChannels.getRootBoxRegion(&r); ///////// FIXME !!!
1003 BoxStack::getInstance()->update(this, &r);
1007 UINT VVideoLiveTV::upChannel(UINT index)
1009 if (index == (chanList->size() - 1)) // at the end
1010 return 0; // so go to start
1015 UINT VVideoLiveTV::downChannel(UINT index)
1017 if (index == 0) // at the start
1018 return chanList->size() - 1; // so go to end
1023 void VVideoLiveTV::toggleChopSides()
1025 if (video->getTVsize() == Video::ASPECT16X9) return; // Means nothing for 16:9 TVs
1027 if (videoMode == Video::NORMAL)
1029 videoMode = Video::LETTERBOX;
1030 video->setMode(Video::LETTERBOX);
1034 videoMode = Video::NORMAL;
1035 video->setMode(Video::NORMAL);