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;
61 // Convert channel number to index
63 for(i = 0; i < chanList->size(); i++)
65 if ((*chanList)[i]->number == (UINT)initialChannelNumber)
67 currentChannelIndex = i;
75 videoMode = video->getMode();
77 if ((*chanList)[currentChannelIndex]->type == VDR::VIDEO)
79 streamType = VDR::VIDEO;
80 player = new PlayerLiveTV(Command::getInstance(), this, chanList);
84 streamType = VDR::RADIO;
85 player = new PlayerLiveRadio(Command::getInstance(), this, chanList);
89 setSize(video->getScreenWidth(), video->getScreenHeight());
91 Colour transparent(0, 0, 0, 0);
92 setBackgroundColour(transparent);
95 char* optionWSS = vdr->configLoad("General", "WSS");
98 if (strstr(optionWSS, "Yes")) dowss = true;
101 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Do WSS: %u", dowss);
105 wss.setFormat(video->getFormat());
111 wssRegion.w = video->getScreenWidth();
115 Colour osdBack = Colour(0, 0, 0, 128);
117 osd.setBackgroundColour(osdBack);
118 osd.setPosition(0, video->getScreenHeight() - 150);
119 osd.setSize(video->getScreenWidth(), 150);
120 osd.setVisible(false);
123 clock.setBackgroundColour(osdBack);
124 clock.setPosition(osd.getWidth() - 100, 4);
125 clock.setSize(90, 30);
128 osdChanNum.setBackgroundColour(osdBack);
129 osdChanNum.setPosition(40, 4);
130 osdChanNum.setSize((numberWidth*10) + 22, 30); // 10 px = width of number chars in font
131 osd.add(&osdChanNum);
133 osdChanName.setBackgroundColour(osdBack);
134 osdChanName.setPosition(osdChanNum.getX2() + 10, 4);
135 osdChanName.setSize(300, 30);
136 osd.add(&osdChanName);
138 boxRed.setBackgroundColour(Colour::RED);
139 boxRed.setPosition(50, 104);
140 boxRed.setSize(18, 16);
143 boxGreen.setBackgroundColour(Colour::GREEN);
144 boxGreen.setPosition(220, 104);
145 boxGreen.setSize(18, 16);
148 boxYellow.setBackgroundColour(Colour::YELLOW);
149 boxYellow.setPosition(390, 104);
150 boxYellow.setSize(18, 16);
153 boxBlue.setBackgroundColour(Colour::BLUE);
154 boxBlue.setPosition(560, 104);
155 boxBlue.setSize(18, 16);
158 textRed.setBackgroundColour(osdBack);
159 textRed.setPosition(boxRed.getX()+18, 98);
160 textRed.setSize(120, 30);
161 textRed.setText("Summary");
164 if (streamType == VDR::VIDEO)
166 textGreen.setBackgroundColour(osdBack);
167 textGreen.setPosition(boxGreen.getX()+18, 98);
168 textGreen.setSize(120, 30);
169 textGreen.setText("Audio");
173 textYellow.setBackgroundColour(osdBack);
174 textYellow.setPosition(boxYellow.getX()+18, 98);
175 textYellow.setSize(120, 30);
176 textYellow.setText("");
177 osd.add(&textYellow);
179 textBlue.setBackgroundColour(osdBack);
180 textBlue.setPosition(boxBlue.getX()+18, 98);
181 textBlue.setSize(90, 30);
182 textBlue.setText("EPG");
185 sl.setBackgroundColour(osdBack);
186 sl.setPosition(70, 36);
192 summary.setBackgroundColour(osdBack);
193 summary.setPosition(0, video->getScreenHeight() - 300);
194 summary.setSize(video->getScreenWidth(), 150);
195 summary.setVisible(false);
198 textSummary.setBackgroundColour(osdBack);
199 textSummary.setPosition(40, 10);
200 textSummary.setSize(video->getScreenWidth() - 80, 130);
201 textSummary.setParaMode(true);
202 summary.add(&textSummary);
204 summaryBlackLine.setBackgroundColour(Colour::BLACK);
205 summaryBlackLine.setPosition(0, summary.getHeight() - 4);
206 summaryBlackLine.setSize(summary.getWidth(), 4);
207 summary.add(&summaryBlackLine);
209 sAspectRatio.setPosition(osd.getWidth() - 90, clock.getY2()+4);
210 sAspectRatio.nextColour = Colour::YELLOW;
211 sAspectRatio.setVisible(false);
212 osd.add(&sAspectRatio);
214 bufferBar.setPosition(osd.getWidth() - 94, 70);
215 bufferBar.setSize(50, 20);
216 bufferBar.setVisible(true);
220 Region r1 = summary.getRegionR();
221 Region r2 = osd.getRegionR();
222 osdSummaryRegion = r1 + r2;
225 VVideoLiveTV::~VVideoLiveTV()
230 video->setDefaultAspect();
234 void VVideoLiveTV::delData()
238 int eventListSize = eventList->size();
239 for(int i = 0; i < eventListSize; i++)
241 delete (*eventList)[i];
250 int VVideoLiveTV::handleCommand(int command)
256 if (osd.getVisible())
261 // else drop through to stop
266 vchannelList->highlightChannel((*chanList)[currentChannelIndex]);
298 case Remote::CHANNELUP:
303 case Remote::DF_DOWN:
304 case Remote::CHANNELDOWN:
309 case Remote::PREVCHANNEL:
311 channelChange(PREVIOUS, 0);
343 // key in channel number
350 if (streamType == VDR::VIDEO) doAudioSelector();
368 void VVideoLiveTV::go()
372 boxstack->update(this);
377 player->go(currentChannelIndex);
380 void VVideoLiveTV::stop()
382 Timers::getInstance()->cancelTimer(this, 1);
383 Timers::getInstance()->cancelTimer(this, 2);
388 void VVideoLiveTV::doLeftRight(bool right)
390 if (osd.getVisible())
392 if (right) osdChannelIndex = upChannel(osdChannelIndex);
393 else osdChannelIndex = downChannel(osdChannelIndex);
397 osdChannelIndex = currentChannelIndex;
402 void VVideoLiveTV::doUpDown(bool down)
404 if (osd.getVisible())
418 void VVideoLiveTV::doChanUpDown(int which)
420 channelChange(OFFSET, which);
421 osdChannelIndex = currentChannelIndex;
425 void VVideoLiveTV::doOK()
427 if (osd.getVisible())
432 for(int i = keying - 1; i >= 0; i--) newChannel += keyingInput[i] * (ULONG)pow(10., i);
434 channelChange(NUMBER, newChannel);
435 osdChannelIndex = currentChannelIndex;
438 else if (osdChannelIndex == currentChannelIndex)
444 channelChange(INDEX, osdChannelIndex);
450 osdChannelIndex = currentChannelIndex;
455 void VVideoLiveTV::doSummary()
457 if (summary.getVisible())
459 summary.setVisible(false);
461 boxstack->update(this, summary.getRegion());
462 Timers::getInstance()->setTimerD(this, 1, 8); // Restart a timer to get rid of osd
466 summary.setVisible(true);
468 if (osd.getVisible())
470 Timers::getInstance()->cancelTimer(this, 1);
479 void VVideoLiveTV::doKey(int command)
481 if (!osd.getVisible()) // First key. prep the data
488 for (i = keying - 1; i >= 0; i--) keyingInput[i+1] = keyingInput[i];
489 keyingInput[0] = command;
492 char* keyingString = new char[numberWidth + 1];
493 for (i = 0; i < numberWidth; i++) keyingString[i] = '_';
494 keyingString[numberWidth] = '\0';
496 for (i = 0; i < keying; i++) keyingString[i] = keyingInput[keying - 1 - i] + 48;
498 if (keying == numberWidth)
501 for(i = keying - 1; i >= 0; i--) newChannel += keyingInput[i] * (ULONG)pow(10., i);
503 channelChange(NUMBER, newChannel);
504 osdChannelIndex = currentChannelIndex;
505 Timers::getInstance()->cancelTimer(this, 1); // cancel the timer to react to keying input,
506 displayOSD(true); // this will put one back if required
510 osdChanNum.setText(keyingString);
512 if (!osd.getVisible())
514 osd.setVisible(true);
521 boxstack->update(this, osd.getRegion());
522 Timers::getInstance()->setTimerD(this, 1, 3); // 3s for keying input
524 delete[] keyingString;
527 void VVideoLiveTV::doAudioSelector()
529 // If the osd is already visisble there might be a timer for it
530 Timers::getInstance()->cancelTimer(this, 1);
536 // and reset the display - this is a copy from setNowNextData
537 char formatChanNum[20];
538 SNPRINTF(formatChanNum, 19, "%0*lu", numberWidth, (*chanList)[osdChannelIndex]->number);
539 osdChanNum.setText(formatChanNum);
540 osdChanName.setText((*chanList)[osdChannelIndex]->name);
544 vas = new VAudioSelector(this, (*chanList)[currentChannelIndex], ((PlayerLiveTV*)player)->getCurrentAudioChannel());
545 Colour osdBack = Colour(0, 0, 0, 128);
546 vas->setBackgroundColour(osdBack);
547 vas->setPosition(0, osd.getScreenY() - vas->getHeight());
550 // make vas != null and displayOSD will not set a timer or do any boxstack update
551 summary.setVisible(false);
552 if (osd.getVisible()) displayOSD(false);
553 else displayOSD(true);
556 BoxStack::getInstance()->add(vas);
557 BoxStack::getInstance()->update(this);
558 BoxStack::getInstance()->update(vas);
561 void VVideoLiveTV::doEPG()
563 if (osd.getVisible()) clearScreen();
565 video->setMode(Video::QUARTER);
566 video->setPosition(170, 5); //TODO need to deal with 4:3 switching
568 VEpg* vepg = new VEpg(this, currentChannelIndex, VDR::VIDEO);
571 boxstack->update(vepg);
574 void VVideoLiveTV::setNowNextData()
578 Channel* currentChannel = (*chanList)[osdChannelIndex];
580 char formatChanNum[20];
581 SNPRINTF(formatChanNum, 19, "%0*lu", numberWidth, currentChannel->number);
582 osdChanNum.setText(formatChanNum);
583 osdChanName.setText(currentChannel->name);
585 eventList = VDR::getInstance()->getChannelSchedule(currentChannel->number);
589 sl.addOption(tr("No channel data available"), 0, 1);
593 sort(eventList->begin(), eventList->end(), EventSorter());
595 char tempString[300];
596 char tempString2[300];
599 int eventListSize = eventList->size();
600 for(int i = 0; i < eventListSize; i++)
602 event = (*eventList)[i];
604 //btime = localtime((time_t*)&event->time);
605 time_t etime = event->time;
606 btime = localtime(&etime);
608 strftime(tempString2, 299, "%0H:%0M ", btime);
610 strftime(tempString2, 299, "%H:%M ", btime);
612 SNPRINTF(tempString, 299, "%s %s", tempString2, event->title);
614 sl.addOption(tempString, (ULONG)event, (i==0));
619 void VVideoLiveTV::setSummaryData()
621 // If osd is not being displayed, sl will be filled with now, current channel
622 // If the display was already on, sl will have programme to show summary for, not necessarily current channel and now
623 Event* selectedEvent = (Event*)sl.getCurrentOptionData();
627 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "No summary");
628 textSummary.setText(tr("No summary available"));
632 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Summary: %s", selectedEvent->description);
633 textSummary.setText(selectedEvent->description);
637 void VVideoLiveTV::displayOSD(bool newNowNextData)
639 osd.setVisible(true);
647 if (summary.getVisible())
651 boxstack->update(this, &osdSummaryRegion);
655 boxstack->update(this, osd.getRegion());
656 Timers::getInstance()->setTimerD(this, 1, 4);
660 void VVideoLiveTV::clearScreen()
662 if (!summary.getVisible()) Timers::getInstance()->cancelTimer(this, 1);
664 osd.setVisible(false);
666 if (summary.getVisible())
668 summary.setVisible(false);
670 boxstack->update(this, &osdSummaryRegion);
675 boxstack->update(this, osd.getRegion());
679 void VVideoLiveTV::setClock()
684 struct tm* tms = localtime(&t);
685 strftime(timeString, 19, "%H:%M", tms);
686 clock.setText(timeString);
688 time_t dt = 60 - (t % 60); // seconds to the next minute
689 if (dt == 0) dt = 60; // advance a whole minute if necessary
690 dt += t; // get a time_t value for it rather than using duration
691 // (so it will occur at the actual second and not second and a half)
693 Timers::getInstance()->setTimerT(this, 2, dt);
696 void VVideoLiveTV::timercall(int ref)
702 // Really, now that cancelTimer basically protects us from deletion, why can't we execute gui stuff here?
705 for(int i = keying - 1; i >= 0; i--) newChannel += keyingInput[i] * (ULONG)pow(10., i);
707 Message* m = new Message();
708 m->message = Message::CHANNEL_CHANGE;
710 m->parameter = newChannel;
711 m->tag = 1; // signal to call displayOSD();
712 Command::getInstance()->postMessageFromOuterSpace(m); // FIXME cjt yeah you know what.
716 osd.setVisible(false);
718 Message* m = new Message();
719 m->message = Message::REDRAW;
720 m->to = BoxStack::getInstance();
722 m->parameter = (ULONG)osd.getRegion();
723 Command::getInstance()->postMessageFromOuterSpace(m); // FIXME cjt yeah you know what.
729 if (osd.getVisible())
732 Message* m = new Message();
733 m->message = Message::REDRAW;
734 m->to = BoxStack::getInstance();
736 m->parameter = (ULONG)osd.getRegion();
737 Command::getInstance()->postMessageFromOuterSpace(m); // FIXME cjt yeah you know what.
742 bool VVideoLiveTV::channelChange(UCHAR changeType, UINT newData)
746 if (changeType == INDEX)
748 newChannel = newData;
750 else if (changeType == NUMBER)
753 for(i = 0; i < chanList->size(); i++)
755 if ((*chanList)[i]->number == (UINT)newData)
762 if (i == chanList->size())
768 else if (changeType == OFFSET)
770 if (newData == UP) newChannel = upChannel(currentChannelIndex);
771 else newChannel = downChannel(currentChannelIndex);
773 else if (changeType == PREVIOUS)
775 newChannel = previousChannelIndex;
779 return false; // bad input
782 if (newChannel == currentChannelIndex) return true;
784 previousChannelIndex = currentChannelIndex;
785 currentChannelIndex = newChannel;
787 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Set player to channel %u", currentChannelIndex);
788 player->setChannel(currentChannelIndex);
789 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Done Set player to channel %u", currentChannelIndex);
791 // Blank out the symbols
792 sAspectRatio.setVisible(false);
793 bufferBar.setPercent(0);
798 void VVideoLiveTV::processMessage(Message* m)
800 if (m->message == Message::MOUSE_LBDOWN)
802 //check if press is outside this view! then simulate cancel
803 int x=(m->parameter>>16)-osd.getScreenX();
804 int y=(m->parameter&0xFFFF)-osd.getScreenY();
805 if (osd.getVisible()) {
807 if ((boxRed.getX()<=x) && (boxRed.getX()+(int)boxRed.getWidth()>=x ) &&
808 (boxRed.getY()<=y) && (boxRed.getY()+(int)boxRed.getHeight()>=y )) {
809 BoxStack::getInstance()->handleCommand(Remote::RED);
810 } else if ((boxGreen.getX()<=x) && (boxGreen.getX()+(int)boxGreen.getWidth()>=x ) &&
811 (boxGreen.getY()<=y) && (boxGreen.getY()+(int)boxGreen.getHeight()>=y)){
812 BoxStack::getInstance()->handleCommand(Remote::GREEN);
813 } else if ((boxYellow.getX()<=x) && (boxYellow.getX()+(int)boxYellow.getWidth()>=x ) &&
814 (boxYellow.getY()<=y) && (boxYellow.getY()+(int)boxYellow.getHeight()>=y )){
815 BoxStack::getInstance()->handleCommand(Remote::YELLOW);
816 } else if ((boxBlue.getX()<=x) && (boxBlue.getX()+(int)boxBlue.getWidth()>=x ) &&
817 (boxBlue.getY()<=y) && (boxBlue.getY()+(int)boxBlue.getHeight()>=y )){
818 BoxStack::getInstance()->handleCommand(Remote::BLUE);
820 BoxStack::getInstance()->handleCommand(Remote::OK); //simulate rok press
824 BoxStack::getInstance()->handleCommand(Remote::OK); //simulate rok press
827 else if (m->message == Message::CHANNEL_CHANGE)
829 channelChange(NUMBER, m->parameter);
830 osdChannelIndex = currentChannelIndex;
831 if (m->tag == 1) displayOSD(true);
833 else if (m->message == Message::EPG_CLOSE)
835 video->setMode(videoMode);
837 else if (m->message == Message::CHILD_CLOSE)
845 else if (m->message == Message::AUDIO_CHANGE_CHANNEL)
847 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Received change audio channel to %i", m->parameter);
848 player->setAudioChannel((m->parameter & 0xFFFF),(m->parameter & 0xFF0000)>>16);
850 else if (m->message == Message::PLAYER_EVENT)
854 case PlayerLiveTV::CONNECTION_LOST: // connection lost detected
856 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Received connection lost from player");
857 // I can't handle this, send it to command
858 Message* m2 = new Message();
859 m2->to = Command::getInstance();
860 m2->message = Message::CONNECTION_LOST;
861 Command::getInstance()->postMessageNoLock(m2);
866 case PlayerLiveTV::STREAM_END:
868 // I can't handle this, send it to command - improve this
869 Message* m2 = new Message(); // Must be done after this thread finishes, and must break into master mutex
870 m2->to = Command::getInstance();
871 m2->message = Message::STREAM_END;
872 Command::getInstance()->postMessageNoLock(m2);
877 case PlayerLiveTV::ASPECT43:
879 if ((video->getTVsize() == Video::ASPECT16X9) && dowss)
881 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 43");
884 BoxStack::getInstance()->update(this, &wssRegion);
887 sAspectRatio.nextSymbol = WSymbol::VIDEOASPECT43;
888 sAspectRatio.setVisible(true);
890 if (osd.getVisible()) // don't wake up the whole osd just for a aspect change
893 BoxStack::getInstance()->update(this, osd.getRegion());
898 case PlayerLiveTV::ASPECT169:
900 if ((video->getTVsize() == Video::ASPECT16X9) && dowss)
902 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 169");
905 BoxStack::getInstance()->update(this, &wssRegion);
908 sAspectRatio.nextSymbol = WSymbol::VIDEOASPECT169;
909 sAspectRatio.setVisible(true);
911 if (osd.getVisible()) // don't wake up the whole osd just for a aspect change
914 BoxStack::getInstance()->update(this, osd.getRegion());
919 case PlayerLiveTV::PREBUFFERING:
921 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Prebuffering - %u", m->tag);
922 bufferBar.setVisible(true);
923 bufferBar.setPercent(m->tag);
926 if (osd.getVisible())
929 bufferBar.getRootBoxRegion(&r);
930 BoxStack::getInstance()->update(this, &r);
937 UINT VVideoLiveTV::upChannel(UINT index)
939 if (index == (chanList->size() - 1)) // at the end
940 return 0; // so go to start
945 UINT VVideoLiveTV::downChannel(UINT index)
947 if (index == 0) // at the start
948 return chanList->size() - 1; // so go to end
953 void VVideoLiveTV::toggleChopSides()
955 if (video->getTVsize() == Video::ASPECT16X9) return; // Means nothing for 16:9 TVs
957 if (videoMode == Video::NORMAL)
959 videoMode = Video::LETTERBOX;
960 video->setMode(Video::LETTERBOX);
964 videoMode = Video::NORMAL;
965 video->setMode(Video::NORMAL);