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 void VVideoLiveTV::preDelete()
243 VVideoLiveTV::~VVideoLiveTV()
246 video->setDefaultAspect();
250 void VVideoLiveTV::delData()
254 int eventListSize = eventList->size();
255 for(int i = 0; i < eventListSize; i++)
257 delete (*eventList)[i];
266 int VVideoLiveTV::handleCommand(int command)
272 if (osd.getVisible())
277 // else drop through to stop
282 vchannelList->highlightChannel((*chanList)[currentChannelIndex]);
315 // Old remote, decide what to do based on whether the osd is showing
316 if (osd.getVisible()) doUpDown(false);
317 else doChanUpDown(UP);
320 case Remote::DF_DOWN:
322 // Old remote, decide what to do based on whether the osd is showing
323 if (osd.getVisible()) doUpDown(true);
324 else doChanUpDown(DOWN);
327 case Remote::CHANNELUP:
332 case Remote::CHANNELDOWN:
337 case Remote::PREVCHANNEL:
339 channelChange(PREVIOUS, 0);
340 osdChannelIndex = currentChannelIndex;
373 // key in channel number
380 if (streamType == VDR::VIDEO) doAudioSelector();
398 void VVideoLiveTV::go()
402 boxstack->update(this);
407 player->go(currentChannelIndex);
410 void VVideoLiveTV::stop()
412 Timers::getInstance()->cancelTimer(this, 1);
413 Timers::getInstance()->cancelTimer(this, 2);
418 void VVideoLiveTV::doLeftRight(bool right)
420 if (osd.getVisible())
422 if (right) osdChannelIndex = upChannel(osdChannelIndex);
423 else osdChannelIndex = downChannel(osdChannelIndex);
427 osdChannelIndex = currentChannelIndex;
432 void VVideoLiveTV::doUpDown(bool down)
434 if (osd.getVisible())
448 void VVideoLiveTV::doChanUpDown(int which)
450 channelChange(OFFSET, which);
451 osdChannelIndex = currentChannelIndex;
455 void VVideoLiveTV::doOK()
457 if (osd.getVisible())
462 for(int i = keying - 1; i >= 0; i--) newChannel += keyingInput[i] * (ULONG)pow(10., i);
464 channelChange(NUMBER, newChannel);
465 osdChannelIndex = currentChannelIndex;
468 else if (osdChannelIndex == currentChannelIndex)
474 channelChange(INDEX, osdChannelIndex);
480 osdChannelIndex = currentChannelIndex;
485 void VVideoLiveTV::doSummary()
487 if (summary.getVisible())
489 summary.setVisible(false);
491 boxstack->update(this, summary.getRegion());
492 Timers::getInstance()->setTimerD(this, 1, 8); // Restart a timer to get rid of osd
496 summary.setVisible(true);
498 if (osd.getVisible())
500 Timers::getInstance()->cancelTimer(this, 1);
509 void VVideoLiveTV::doKey(int command)
511 if (!osd.getVisible()) // First key. prep the data
518 for (i = keying - 1; i >= 0; i--) keyingInput[i+1] = keyingInput[i];
519 keyingInput[0] = command;
522 char* keyingString = new char[numberWidth + 1];
523 for (i = 0; i < numberWidth; i++) keyingString[i] = '_';
524 keyingString[numberWidth] = '\0';
526 for (i = 0; i < keying; i++) keyingString[i] = keyingInput[keying - 1 - i] + 48;
528 if (keying == numberWidth)
531 for(i = keying - 1; i >= 0; i--) newChannel += keyingInput[i] * (ULONG)pow(10., i);
533 channelChange(NUMBER, newChannel);
534 osdChannelIndex = currentChannelIndex;
535 Timers::getInstance()->cancelTimer(this, 1); // cancel the timer to react to keying input,
536 displayOSD(true); // this will put one back if required
540 osdChanNum.setText(keyingString);
542 if (!osd.getVisible())
544 osd.setVisible(true);
551 boxstack->update(this, osd.getRegion());
552 Timers::getInstance()->setTimerD(this, 1, 3); // 3s for keying input
554 delete[] keyingString;
557 void VVideoLiveTV::doAudioSelector()
559 // If the osd is already visisble there might be a timer for it
560 Timers::getInstance()->cancelTimer(this, 1);
566 // and reset the display - this is a copy from setNowNextData
567 char formatChanNum[20];
568 SNPRINTF(formatChanNum, 19, "%0*lu", numberWidth, (*chanList)[osdChannelIndex]->number);
569 osdChanNum.setText(formatChanNum);
570 osdChanName.setText((*chanList)[osdChannelIndex]->name);
574 vas = new VAudioSelector(this, (*chanList)[currentChannelIndex], ((PlayerLiveTV*)player)->getCurrentAudioChannel());
575 Colour osdBack = Colour(0, 0, 0, 128);
576 vas->setBackgroundColour(osdBack);
577 vas->setPosition(0, osd.getScreenY() - vas->getHeight());
580 // make vas != null and displayOSD will not set a timer or do any boxstack update
581 summary.setVisible(false);
582 if (osd.getVisible()) displayOSD(false);
583 else displayOSD(true);
586 BoxStack::getInstance()->add(vas);
587 BoxStack::getInstance()->update(this);
588 BoxStack::getInstance()->update(vas);
591 void VVideoLiveTV::doEPG()
593 if (osd.getVisible()) clearScreen();
595 video->setMode(Video::QUARTER);
596 video->setPosition(170, 5); //TODO need to deal with 4:3 switching
598 VEpg* vepg = new VEpg(this, currentChannelIndex, VDR::VIDEO);
601 boxstack->update(vepg);
604 void VVideoLiveTV::setNowNextData()
608 Channel* currentChannel = (*chanList)[osdChannelIndex];
610 char formatChanNum[20];
611 SNPRINTF(formatChanNum, 19, "%0*lu", numberWidth, currentChannel->number);
612 osdChanNum.setText(formatChanNum);
613 osdChanName.setText(currentChannel->name);
615 eventList = VDR::getInstance()->getChannelSchedule(currentChannel->number);
619 sl.addOption(tr("No channel data available"), 0, 1);
623 sort(eventList->begin(), eventList->end(), EventSorter());
625 char tempString[300];
626 char tempString2[300];
629 int eventListSize = eventList->size();
630 for(int i = 0; i < eventListSize; i++)
632 event = (*eventList)[i];
634 //btime = localtime((time_t*)&event->time);
635 time_t etime = event->time;
636 btime = localtime(&etime);
638 strftime(tempString2, 299, "%0H:%0M ", btime);
640 strftime(tempString2, 299, "%H:%M ", btime);
642 SNPRINTF(tempString, 299, "%s %s", tempString2, event->title);
644 sl.addOption(tempString, (ULONG)event, (i==0));
649 void VVideoLiveTV::setSummaryData()
651 // If osd is not being displayed, sl will be filled with now, current channel
652 // If the display was already on, sl will have programme to show summary for, not necessarily current channel and now
653 Event* selectedEvent = (Event*)sl.getCurrentOptionData();
657 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "No summary");
658 textSummary.setText(tr("No summary available"));
662 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Summary: %s", selectedEvent->description);
663 textSummary.setText(selectedEvent->description);
667 void VVideoLiveTV::displayOSD(bool newNowNextData)
669 osd.setVisible(true);
677 if (summary.getVisible())
681 boxstack->update(this, &osdSummaryRegion);
685 boxstack->update(this, osd.getRegion());
688 bool setTimer = true;
689 if (vas) setTimer = false;
690 if (summary.getVisible()) setTimer = false;
691 if (textUnavailable.getVisible()) setTimer = false;
693 if (setTimer) Timers::getInstance()->setTimerD(this, 1, 4);
696 void VVideoLiveTV::clearScreen()
698 if (!summary.getVisible()) Timers::getInstance()->cancelTimer(this, 1);
700 textUnavailable.setVisible(false);
701 osd.setVisible(false);
702 summary.setVisible(false);
705 boxstack->update(this);
708 void VVideoLiveTV::showUnavailable()
710 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Show unavailable called");
711 textUnavailable.setVisible(true);
712 textUnavailable.draw();
714 if (!osd.getVisible()) displayOSD(true);
716 boxstack->update(this, textUnavailable.getRegion());
719 void VVideoLiveTV::setClock()
724 struct tm* tms = localtime(&t);
725 strftime(timeString, 19, "%H:%M", tms);
726 clock.setText(timeString);
728 time_t dt = 60 - (t % 60); // seconds to the next minute
729 if (dt == 0) dt = 60; // advance a whole minute if necessary
730 dt += t; // get a time_t value for it rather than using duration
731 // (so it will occur at the actual second and not second and a half)
733 Timers::getInstance()->setTimerT(this, 2, dt);
736 void VVideoLiveTV::timercall(int ref)
743 for(int i = keying - 1; i >= 0; i--) newChannel += keyingInput[i] * (ULONG)pow(10., i);
745 Message* m = new Message();
746 m->message = Message::CHANNEL_CHANGE;
748 m->parameter = newChannel;
749 m->tag = 1; // signal to call displayOSD();
750 Command::getInstance()->postMessageFromOuterSpace(m);
754 // We have received a timer, we are not keying. If still prebuffering, don't remove the bar
755 if (preBuffering < 100)
757 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Still prebuffering, not removing osd...");
758 Timers::getInstance()->setTimerD(this, 1, 2); // reset timer for another 2s
762 osd.setVisible(false);
764 boxstack->update(this, osd.getRegion());
770 if (osd.getVisible())
773 boxstack->update(this, osd.getRegion());
778 bool VVideoLiveTV::channelChange(UCHAR changeType, UINT newData)
782 if (changeType == INDEX)
784 newChannel = newData;
786 else if (changeType == NUMBER)
789 for(i = 0; i < chanList->size(); i++)
791 if ((*chanList)[i]->number == (UINT)newData)
798 if (i == chanList->size())
804 else if (changeType == OFFSET)
806 if (newData == UP) newChannel = upChannel(currentChannelIndex);
807 else newChannel = downChannel(currentChannelIndex);
809 else if (changeType == PREVIOUS)
811 newChannel = previousChannelIndex;
815 return false; // bad input
818 if (newChannel == currentChannelIndex) return true;
820 previousChannelIndex = currentChannelIndex;
821 currentChannelIndex = newChannel;
825 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Set player to channel %u", currentChannelIndex);
826 player->setChannel(currentChannelIndex);
827 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Done Set player to channel %u", currentChannelIndex);
829 // Blank out the symbols
830 sAspectRatio.setVisible(false);
831 bufferBar.setPercent(0);
832 sAudioChannels.setVisible(false);
834 // Remove other stuff
835 if (textUnavailable.getVisible())
837 textUnavailable.setVisible(false);
839 BoxStack::getInstance()->update(this);
845 void VVideoLiveTV::processMessage(Message* m)
847 if (m->message == Message::MOUSE_LBDOWN)
849 //check if press is outside this view! then simulate cancel
850 int x=(m->parameter>>16)-osd.getScreenX();
851 int y=(m->parameter&0xFFFF)-osd.getScreenY();
852 if (osd.getVisible()) {
854 if ((boxRed.getX()<=x) && (boxRed.getX()+(int)boxRed.getWidth()>=x ) &&
855 (boxRed.getY()<=y) && (boxRed.getY()+(int)boxRed.getHeight()>=y )) {
856 BoxStack::getInstance()->handleCommand(Remote::RED);
857 } else if ((boxGreen.getX()<=x) && (boxGreen.getX()+(int)boxGreen.getWidth()>=x ) &&
858 (boxGreen.getY()<=y) && (boxGreen.getY()+(int)boxGreen.getHeight()>=y)){
859 BoxStack::getInstance()->handleCommand(Remote::GREEN);
860 } else if ((boxYellow.getX()<=x) && (boxYellow.getX()+(int)boxYellow.getWidth()>=x ) &&
861 (boxYellow.getY()<=y) && (boxYellow.getY()+(int)boxYellow.getHeight()>=y )){
862 BoxStack::getInstance()->handleCommand(Remote::YELLOW);
863 } else if ((boxBlue.getX()<=x) && (boxBlue.getX()+(int)boxBlue.getWidth()>=x ) &&
864 (boxBlue.getY()<=y) && (boxBlue.getY()+(int)boxBlue.getHeight()>=y )){
865 BoxStack::getInstance()->handleCommand(Remote::BLUE);
867 BoxStack::getInstance()->handleCommand(Remote::OK); //simulate rok press
871 BoxStack::getInstance()->handleCommand(Remote::OK); //simulate rok press
874 else if (m->message == Message::CHANNEL_CHANGE)
876 channelChange(NUMBER, m->parameter);
877 osdChannelIndex = currentChannelIndex;
878 if (m->tag == 1) displayOSD(true);
880 else if (m->message == Message::EPG_CLOSE)
882 video->setMode(videoMode);
884 else if (m->message == Message::CHILD_CLOSE)
892 else if (m->message == Message::AUDIO_CHANGE_CHANNEL)
894 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Received change audio channel to %i", m->parameter);
895 player->setAudioChannel((m->parameter & 0xFFFF),(m->parameter & 0xFF0000)>>16);
897 else if (m->message == Message::PLAYER_EVENT)
901 case PlayerLiveTV::CONNECTION_LOST: // connection lost detected
903 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Received connection lost from player");
904 Command::getInstance()->connectionLost();
908 case PlayerLiveTV::STREAM_END:
910 // Message comes from playerlivetv through master mutex, so can do anything here
915 case PlayerLiveTV::ASPECT43:
917 if ((video->getTVsize() == Video::ASPECT16X9) && dowss)
919 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 43");
922 BoxStack::getInstance()->update(this, &wssRegion);
925 sAspectRatio.nextSymbol = WSymbol::VIDEOASPECT43;
926 sAspectRatio.setVisible(true);
928 if (osd.getVisible()) // don't wake up the whole osd just for a aspect change
931 BoxStack::getInstance()->update(this, osd.getRegion());
936 case PlayerLiveTV::ASPECT169:
938 if ((video->getTVsize() == Video::ASPECT16X9) && dowss)
940 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 169");
943 BoxStack::getInstance()->update(this, &wssRegion);
946 sAspectRatio.nextSymbol = WSymbol::VIDEOASPECT169;
947 sAspectRatio.setVisible(true);
949 if (osd.getVisible()) // don't wake up the whole osd just for a aspect change
952 BoxStack::getInstance()->update(this, osd.getRegion());
957 case PlayerLiveTV::PREBUFFERING:
959 preBuffering = m->tag;
960 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Prebuffering - %u", preBuffering);
961 bufferBar.setPercent(preBuffering);
963 if (osd.getVisible())
965 bufferBar.setVisible(true);
968 bufferBar.getRootBoxRegion(&r); ///////// FIXME !!!
969 BoxStack::getInstance()->update(this, &r);
971 if (preBuffering == 100)
973 doAudioChannelSymbol();
981 void VVideoLiveTV::doAudioChannelSymbol()
984 Channel* currentChannel = (*chanList)[osdChannelIndex];
986 bool multiAudio = false;
988 if (currentChannel->numDPids > 1) multiAudio = true;
990 if (currentChannel->numAPids > 1) multiAudio = true;
994 if (multiAudio) sAudioChannels.nextSymbol = WSymbol::MULTIAUDIO;
995 else sAudioChannels.nextSymbol = WSymbol::SINGLEAUDIO;
996 sAudioChannels.setVisible(true);
998 if (osd.getVisible())
1000 sAudioChannels.draw();
1002 sAudioChannels.getRootBoxRegion(&r); ///////// FIXME !!!
1006 BoxStack::getInstance()->update(this, &r);
1010 UINT VVideoLiveTV::upChannel(UINT index)
1012 if (index == (chanList->size() - 1)) // at the end
1013 return 0; // so go to start
1018 UINT VVideoLiveTV::downChannel(UINT index)
1020 if (index == 0) // at the start
1021 return chanList->size() - 1; // so go to end
1026 void VVideoLiveTV::toggleChopSides()
1028 if (video->getTVsize() == Video::ASPECT16X9) return; // Means nothing for 16:9 TVs
1030 if (videoMode == Video::NORMAL)
1032 videoMode = Video::LETTERBOX;
1033 video->setMode(Video::LETTERBOX);
1037 videoMode = Video::NORMAL;
1038 video->setMode(Video::NORMAL);