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, 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);
226 Region r1 = summary.getRegionR();
227 Region r2 = osd.getRegionR();
228 osdSummaryRegion = r1 + r2;
231 VVideoLiveTV::~VVideoLiveTV()
236 video->setDefaultAspect();
240 void VVideoLiveTV::delData()
244 int eventListSize = eventList->size();
245 for(int i = 0; i < eventListSize; i++)
247 delete (*eventList)[i];
256 int VVideoLiveTV::handleCommand(int command)
262 if (osd.getVisible())
267 // else drop through to stop
272 vchannelList->highlightChannel((*chanList)[currentChannelIndex]);
304 case Remote::CHANNELUP:
309 case Remote::DF_DOWN:
310 case Remote::CHANNELDOWN:
315 case Remote::PREVCHANNEL:
317 channelChange(PREVIOUS, 0);
318 osdChannelIndex = currentChannelIndex;
351 // key in channel number
358 if (streamType == VDR::VIDEO) doAudioSelector();
376 void VVideoLiveTV::go()
380 boxstack->update(this);
385 player->go(currentChannelIndex);
388 void VVideoLiveTV::stop()
390 Timers::getInstance()->cancelTimer(this, 1);
391 Timers::getInstance()->cancelTimer(this, 2);
396 void VVideoLiveTV::doLeftRight(bool right)
398 if (osd.getVisible())
400 if (right) osdChannelIndex = upChannel(osdChannelIndex);
401 else osdChannelIndex = downChannel(osdChannelIndex);
405 osdChannelIndex = currentChannelIndex;
410 void VVideoLiveTV::doUpDown(bool down)
412 if (osd.getVisible())
426 void VVideoLiveTV::doChanUpDown(int which)
428 channelChange(OFFSET, which);
429 osdChannelIndex = currentChannelIndex;
433 void VVideoLiveTV::doOK()
435 if (osd.getVisible())
440 for(int i = keying - 1; i >= 0; i--) newChannel += keyingInput[i] * (ULONG)pow(10., i);
442 channelChange(NUMBER, newChannel);
443 osdChannelIndex = currentChannelIndex;
446 else if (osdChannelIndex == currentChannelIndex)
452 channelChange(INDEX, osdChannelIndex);
458 osdChannelIndex = currentChannelIndex;
463 void VVideoLiveTV::doSummary()
465 if (summary.getVisible())
467 summary.setVisible(false);
469 boxstack->update(this, summary.getRegion());
470 Timers::getInstance()->setTimerD(this, 1, 8); // Restart a timer to get rid of osd
474 summary.setVisible(true);
476 if (osd.getVisible())
478 Timers::getInstance()->cancelTimer(this, 1);
487 void VVideoLiveTV::doKey(int command)
489 if (!osd.getVisible()) // First key. prep the data
496 for (i = keying - 1; i >= 0; i--) keyingInput[i+1] = keyingInput[i];
497 keyingInput[0] = command;
500 char* keyingString = new char[numberWidth + 1];
501 for (i = 0; i < numberWidth; i++) keyingString[i] = '_';
502 keyingString[numberWidth] = '\0';
504 for (i = 0; i < keying; i++) keyingString[i] = keyingInput[keying - 1 - i] + 48;
506 if (keying == numberWidth)
509 for(i = keying - 1; i >= 0; i--) newChannel += keyingInput[i] * (ULONG)pow(10., i);
511 channelChange(NUMBER, newChannel);
512 osdChannelIndex = currentChannelIndex;
513 Timers::getInstance()->cancelTimer(this, 1); // cancel the timer to react to keying input,
514 displayOSD(true); // this will put one back if required
518 osdChanNum.setText(keyingString);
520 if (!osd.getVisible())
522 osd.setVisible(true);
529 boxstack->update(this, osd.getRegion());
530 Timers::getInstance()->setTimerD(this, 1, 3); // 3s for keying input
532 delete[] keyingString;
535 void VVideoLiveTV::doAudioSelector()
537 // If the osd is already visisble there might be a timer for it
538 Timers::getInstance()->cancelTimer(this, 1);
544 // and reset the display - this is a copy from setNowNextData
545 char formatChanNum[20];
546 SNPRINTF(formatChanNum, 19, "%0*lu", numberWidth, (*chanList)[osdChannelIndex]->number);
547 osdChanNum.setText(formatChanNum);
548 osdChanName.setText((*chanList)[osdChannelIndex]->name);
552 vas = new VAudioSelector(this, (*chanList)[currentChannelIndex], ((PlayerLiveTV*)player)->getCurrentAudioChannel());
553 Colour osdBack = Colour(0, 0, 0, 128);
554 vas->setBackgroundColour(osdBack);
555 vas->setPosition(0, osd.getScreenY() - vas->getHeight());
558 // make vas != null and displayOSD will not set a timer or do any boxstack update
559 summary.setVisible(false);
560 if (osd.getVisible()) displayOSD(false);
561 else displayOSD(true);
564 BoxStack::getInstance()->add(vas);
565 BoxStack::getInstance()->update(this);
566 BoxStack::getInstance()->update(vas);
569 void VVideoLiveTV::doEPG()
571 if (osd.getVisible()) clearScreen();
573 video->setMode(Video::QUARTER);
574 video->setPosition(170, 5); //TODO need to deal with 4:3 switching
576 VEpg* vepg = new VEpg(this, currentChannelIndex, VDR::VIDEO);
579 boxstack->update(vepg);
582 void VVideoLiveTV::setNowNextData()
586 Channel* currentChannel = (*chanList)[osdChannelIndex];
588 char formatChanNum[20];
589 SNPRINTF(formatChanNum, 19, "%0*lu", numberWidth, currentChannel->number);
590 osdChanNum.setText(formatChanNum);
591 osdChanName.setText(currentChannel->name);
593 eventList = VDR::getInstance()->getChannelSchedule(currentChannel->number);
597 sl.addOption(tr("No channel data available"), 0, 1);
601 sort(eventList->begin(), eventList->end(), EventSorter());
603 char tempString[300];
604 char tempString2[300];
607 int eventListSize = eventList->size();
608 for(int i = 0; i < eventListSize; i++)
610 event = (*eventList)[i];
612 //btime = localtime((time_t*)&event->time);
613 time_t etime = event->time;
614 btime = localtime(&etime);
616 strftime(tempString2, 299, "%0H:%0M ", btime);
618 strftime(tempString2, 299, "%H:%M ", btime);
620 SNPRINTF(tempString, 299, "%s %s", tempString2, event->title);
622 sl.addOption(tempString, (ULONG)event, (i==0));
627 void VVideoLiveTV::setSummaryData()
629 // If osd is not being displayed, sl will be filled with now, current channel
630 // If the display was already on, sl will have programme to show summary for, not necessarily current channel and now
631 Event* selectedEvent = (Event*)sl.getCurrentOptionData();
635 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "No summary");
636 textSummary.setText(tr("No summary available"));
640 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Summary: %s", selectedEvent->description);
641 textSummary.setText(selectedEvent->description);
645 void VVideoLiveTV::displayOSD(bool newNowNextData)
647 osd.setVisible(true);
655 if (summary.getVisible())
659 boxstack->update(this, &osdSummaryRegion);
663 boxstack->update(this, osd.getRegion());
664 Timers::getInstance()->setTimerD(this, 1, 4);
668 void VVideoLiveTV::clearScreen()
670 if (!summary.getVisible()) Timers::getInstance()->cancelTimer(this, 1);
672 osd.setVisible(false);
674 if (summary.getVisible())
676 summary.setVisible(false);
678 boxstack->update(this, &osdSummaryRegion);
683 boxstack->update(this, osd.getRegion());
687 void VVideoLiveTV::setClock()
692 struct tm* tms = localtime(&t);
693 strftime(timeString, 19, "%H:%M", tms);
694 clock.setText(timeString);
696 time_t dt = 60 - (t % 60); // seconds to the next minute
697 if (dt == 0) dt = 60; // advance a whole minute if necessary
698 dt += t; // get a time_t value for it rather than using duration
699 // (so it will occur at the actual second and not second and a half)
701 Timers::getInstance()->setTimerT(this, 2, dt);
704 void VVideoLiveTV::timercall(int ref)
710 // Really, now that cancelTimer basically protects us from deletion, why can't we execute gui stuff here?
713 for(int i = keying - 1; i >= 0; i--) newChannel += keyingInput[i] * (ULONG)pow(10., i);
715 Message* m = new Message();
716 m->message = Message::CHANNEL_CHANGE;
718 m->parameter = newChannel;
719 m->tag = 1; // signal to call displayOSD();
720 Command::getInstance()->postMessageFromOuterSpace(m); // FIXME cjt yeah you know what.
724 // We have received a timer, we are not keying. If still prebuffering, don't remove the bar
725 if (preBuffering < 100)
727 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Still prebuffering, not removing osd...");
728 Timers::getInstance()->setTimerD(this, 1, 2); // reset timer for another 2s
732 osd.setVisible(false);
734 Message* m = new Message();
735 m->message = Message::REDRAW;
736 m->to = BoxStack::getInstance();
738 m->parameter = (ULONG)osd.getRegion();
739 Command::getInstance()->postMessageFromOuterSpace(m); // FIXME cjt yeah you know what.
745 if (osd.getVisible())
748 Message* m = new Message();
749 m->message = Message::REDRAW;
750 m->to = BoxStack::getInstance();
752 m->parameter = (ULONG)osd.getRegion();
753 Command::getInstance()->postMessageFromOuterSpace(m); // FIXME cjt yeah you know what.
758 bool VVideoLiveTV::channelChange(UCHAR changeType, UINT newData)
762 if (changeType == INDEX)
764 newChannel = newData;
766 else if (changeType == NUMBER)
769 for(i = 0; i < chanList->size(); i++)
771 if ((*chanList)[i]->number == (UINT)newData)
778 if (i == chanList->size())
784 else if (changeType == OFFSET)
786 if (newData == UP) newChannel = upChannel(currentChannelIndex);
787 else newChannel = downChannel(currentChannelIndex);
789 else if (changeType == PREVIOUS)
791 newChannel = previousChannelIndex;
795 return false; // bad input
798 if (newChannel == currentChannelIndex) return true;
800 previousChannelIndex = currentChannelIndex;
801 currentChannelIndex = newChannel;
805 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Set player to channel %u", currentChannelIndex);
806 player->setChannel(currentChannelIndex);
807 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Done Set player to channel %u", currentChannelIndex);
809 // Blank out the symbols
810 sAspectRatio.setVisible(false);
811 bufferBar.setPercent(0);
812 sAudioChannels.setVisible(false);
817 void VVideoLiveTV::processMessage(Message* m)
819 if (m->message == Message::MOUSE_LBDOWN)
821 //check if press is outside this view! then simulate cancel
822 int x=(m->parameter>>16)-osd.getScreenX();
823 int y=(m->parameter&0xFFFF)-osd.getScreenY();
824 if (osd.getVisible()) {
826 if ((boxRed.getX()<=x) && (boxRed.getX()+(int)boxRed.getWidth()>=x ) &&
827 (boxRed.getY()<=y) && (boxRed.getY()+(int)boxRed.getHeight()>=y )) {
828 BoxStack::getInstance()->handleCommand(Remote::RED);
829 } else if ((boxGreen.getX()<=x) && (boxGreen.getX()+(int)boxGreen.getWidth()>=x ) &&
830 (boxGreen.getY()<=y) && (boxGreen.getY()+(int)boxGreen.getHeight()>=y)){
831 BoxStack::getInstance()->handleCommand(Remote::GREEN);
832 } else if ((boxYellow.getX()<=x) && (boxYellow.getX()+(int)boxYellow.getWidth()>=x ) &&
833 (boxYellow.getY()<=y) && (boxYellow.getY()+(int)boxYellow.getHeight()>=y )){
834 BoxStack::getInstance()->handleCommand(Remote::YELLOW);
835 } else if ((boxBlue.getX()<=x) && (boxBlue.getX()+(int)boxBlue.getWidth()>=x ) &&
836 (boxBlue.getY()<=y) && (boxBlue.getY()+(int)boxBlue.getHeight()>=y )){
837 BoxStack::getInstance()->handleCommand(Remote::BLUE);
839 BoxStack::getInstance()->handleCommand(Remote::OK); //simulate rok press
843 BoxStack::getInstance()->handleCommand(Remote::OK); //simulate rok press
846 else if (m->message == Message::CHANNEL_CHANGE)
848 channelChange(NUMBER, m->parameter);
849 osdChannelIndex = currentChannelIndex;
850 if (m->tag == 1) displayOSD(true);
852 else if (m->message == Message::EPG_CLOSE)
854 video->setMode(videoMode);
856 else if (m->message == Message::CHILD_CLOSE)
864 else if (m->message == Message::AUDIO_CHANGE_CHANNEL)
866 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Received change audio channel to %i", m->parameter);
867 player->setAudioChannel((m->parameter & 0xFFFF),(m->parameter & 0xFF0000)>>16);
869 else if (m->message == Message::PLAYER_EVENT)
873 case PlayerLiveTV::CONNECTION_LOST: // connection lost detected
875 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Received connection lost from player");
876 // I can't handle this, send it to command
877 Message* m2 = new Message();
878 m2->to = Command::getInstance();
879 m2->message = Message::CONNECTION_LOST;
880 Command::getInstance()->postMessageNoLock(m2);
885 case PlayerLiveTV::STREAM_END:
887 // I can't handle this, send it to command - improve this
888 Message* m2 = new Message(); // Must be done after this thread finishes, and must break into master mutex
889 m2->to = Command::getInstance();
890 m2->message = Message::STREAM_END;
891 Command::getInstance()->postMessageNoLock(m2);
896 case PlayerLiveTV::ASPECT43:
898 if ((video->getTVsize() == Video::ASPECT16X9) && dowss)
900 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 43");
903 BoxStack::getInstance()->update(this, &wssRegion);
906 sAspectRatio.nextSymbol = WSymbol::VIDEOASPECT43;
907 sAspectRatio.setVisible(true);
909 if (osd.getVisible()) // don't wake up the whole osd just for a aspect change
912 BoxStack::getInstance()->update(this, osd.getRegion());
917 case PlayerLiveTV::ASPECT169:
919 if ((video->getTVsize() == Video::ASPECT16X9) && dowss)
921 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 169");
924 BoxStack::getInstance()->update(this, &wssRegion);
927 sAspectRatio.nextSymbol = WSymbol::VIDEOASPECT169;
928 sAspectRatio.setVisible(true);
930 if (osd.getVisible()) // don't wake up the whole osd just for a aspect change
933 BoxStack::getInstance()->update(this, osd.getRegion());
938 case PlayerLiveTV::PREBUFFERING:
940 preBuffering = m->tag;
941 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Prebuffering - %u", preBuffering);
942 bufferBar.setPercent(preBuffering);
944 if (osd.getVisible())
946 bufferBar.setVisible(true);
949 bufferBar.getRootBoxRegion(&r); ///////// FIXME !!!
950 BoxStack::getInstance()->update(this, &r);
952 if (preBuffering == 100)
954 doAudioChannelSymbol();
962 void VVideoLiveTV::doAudioChannelSymbol()
965 Channel* currentChannel = (*chanList)[osdChannelIndex];
967 bool multiAudio = false;
969 if (currentChannel->numDPids > 1) multiAudio = true;
971 if (currentChannel->numAPids > 1) multiAudio = true;
975 if (multiAudio) sAudioChannels.nextSymbol = WSymbol::MULTIAUDIO;
976 else sAudioChannels.nextSymbol = WSymbol::SINGLEAUDIO;
977 sAudioChannels.setVisible(true);
979 if (osd.getVisible())
981 sAudioChannels.draw();
983 sAudioChannels.getRootBoxRegion(&r); ///////// FIXME !!!
987 BoxStack::getInstance()->update(this, &r);
991 UINT VVideoLiveTV::upChannel(UINT index)
993 if (index == (chanList->size() - 1)) // at the end
994 return 0; // so go to start
999 UINT VVideoLiveTV::downChannel(UINT index)
1001 if (index == 0) // at the start
1002 return chanList->size() - 1; // so go to end
1007 void VVideoLiveTV::toggleChopSides()
1009 if (video->getTVsize() == Video::ASPECT16X9) return; // Means nothing for 16:9 TVs
1011 if (videoMode == Video::NORMAL)
1013 videoMode = Video::LETTERBOX;
1014 video->setMode(Video::LETTERBOX);
1018 videoMode = Video::NORMAL;
1019 video->setMode(Video::NORMAL);