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);
215 Region r1 = summary.getRegionR();
216 Region r2 = osd.getRegionR();
217 osdSummaryRegion = r1 + r2;
220 VVideoLiveTV::~VVideoLiveTV()
225 video->setDefaultAspect();
229 void VVideoLiveTV::delData()
233 int eventListSize = eventList->size();
234 for(int i = 0; i < eventListSize; i++)
236 delete (*eventList)[i];
245 int VVideoLiveTV::handleCommand(int command)
251 if (osd.getVisible())
256 // else drop through to stop
261 vchannelList->highlightChannel((*chanList)[currentChannelIndex]);
293 case Remote::CHANNELUP:
298 case Remote::DF_DOWN:
299 case Remote::CHANNELDOWN:
304 case Remote::PREVCHANNEL:
306 channelChange(PREVIOUS, 0);
338 // key in channel number
345 if (streamType == VDR::VIDEO) doAudioSelector();
363 void VVideoLiveTV::go()
367 boxstack->update(this);
372 player->go(currentChannelIndex);
375 void VVideoLiveTV::stop()
377 Timers::getInstance()->cancelTimer(this, 1);
378 Timers::getInstance()->cancelTimer(this, 2);
383 void VVideoLiveTV::doLeftRight(bool right)
385 if (osd.getVisible())
387 if (right) osdChannelIndex = upChannel(osdChannelIndex);
388 else osdChannelIndex = downChannel(osdChannelIndex);
392 osdChannelIndex = currentChannelIndex;
397 void VVideoLiveTV::doUpDown(bool down)
399 if (osd.getVisible())
413 void VVideoLiveTV::doChanUpDown(int which)
415 channelChange(OFFSET, which);
416 osdChannelIndex = currentChannelIndex;
420 void VVideoLiveTV::doOK()
422 if (osd.getVisible())
427 for(int i = keying - 1; i >= 0; i--) newChannel += keyingInput[i] * (ULONG)pow(10., i);
429 channelChange(NUMBER, newChannel);
430 osdChannelIndex = currentChannelIndex;
433 else if (osdChannelIndex == currentChannelIndex)
439 channelChange(INDEX, osdChannelIndex);
445 osdChannelIndex = currentChannelIndex;
450 void VVideoLiveTV::doSummary()
452 if (summary.getVisible())
454 summary.setVisible(false);
456 boxstack->update(this, summary.getRegion());
457 Timers::getInstance()->setTimerD(this, 1, 8); // Restart a timer to get rid of osd
461 summary.setVisible(true);
463 if (osd.getVisible())
465 Timers::getInstance()->cancelTimer(this, 1);
474 void VVideoLiveTV::doKey(int command)
476 if (!osd.getVisible()) // First key. prep the data
483 for (i = keying - 1; i >= 0; i--) keyingInput[i+1] = keyingInput[i];
484 keyingInput[0] = command;
487 char* keyingString = new char[numberWidth + 1];
488 for (i = 0; i < numberWidth; i++) keyingString[i] = '_';
489 keyingString[numberWidth] = '\0';
491 for (i = 0; i < keying; i++) keyingString[i] = keyingInput[keying - 1 - i] + 48;
493 if (keying == numberWidth)
496 for(i = keying - 1; i >= 0; i--) newChannel += keyingInput[i] * (ULONG)pow(10., i);
498 channelChange(NUMBER, newChannel);
499 osdChannelIndex = currentChannelIndex;
500 Timers::getInstance()->cancelTimer(this, 1); // cancel the timer to react to keying input,
501 displayOSD(true); // this will put one back if required
505 osdChanNum.setText(keyingString);
507 if (!osd.getVisible())
509 osd.setVisible(true);
516 boxstack->update(this, osd.getRegion());
517 Timers::getInstance()->setTimerD(this, 1, 3); // 3s for keying input
519 delete[] keyingString;
522 void VVideoLiveTV::doAudioSelector()
524 // If the osd is already visisble there might be a timer for it
525 Timers::getInstance()->cancelTimer(this, 1);
531 // and reset the display - this is a copy from setNowNextData
532 char formatChanNum[20];
533 SNPRINTF(formatChanNum, 19, "%0*lu", numberWidth, (*chanList)[osdChannelIndex]->number);
534 osdChanNum.setText(formatChanNum);
535 osdChanName.setText((*chanList)[osdChannelIndex]->name);
539 vas = new VAudioSelector(this, (*chanList)[currentChannelIndex], ((PlayerLiveTV*)player)->getCurrentAudioChannel());
540 Colour osdBack = Colour(0, 0, 0, 128);
541 vas->setBackgroundColour(osdBack);
542 vas->setPosition(0, osd.getScreenY() - vas->getHeight());
545 // make vas != null and displayOSD will not set a timer or do any boxstack update
546 summary.setVisible(false);
547 if (osd.getVisible()) displayOSD(false);
548 else displayOSD(true);
551 BoxStack::getInstance()->add(vas);
552 BoxStack::getInstance()->update(this);
553 BoxStack::getInstance()->update(vas);
556 void VVideoLiveTV::doEPG()
558 if (osd.getVisible()) clearScreen();
560 video->setMode(Video::QUARTER);
561 video->setPosition(170, 5); //TODO need to deal with 4:3 switching
563 VEpg* vepg = new VEpg(this, currentChannelIndex, VDR::VIDEO);
566 boxstack->update(vepg);
569 void VVideoLiveTV::setNowNextData()
573 Channel* currentChannel = (*chanList)[osdChannelIndex];
575 char formatChanNum[20];
576 SNPRINTF(formatChanNum, 19, "%0*lu", numberWidth, currentChannel->number);
577 osdChanNum.setText(formatChanNum);
578 osdChanName.setText(currentChannel->name);
580 eventList = VDR::getInstance()->getChannelSchedule(currentChannel->number);
584 sl.addOption(tr("No channel data available"), 0, 1);
588 sort(eventList->begin(), eventList->end(), EventSorter());
590 char tempString[300];
591 char tempString2[300];
594 int eventListSize = eventList->size();
595 for(int i = 0; i < eventListSize; i++)
597 event = (*eventList)[i];
599 //btime = localtime((time_t*)&event->time);
600 time_t etime = event->time;
601 btime = localtime(&etime);
603 strftime(tempString2, 299, "%0H:%0M ", btime);
605 strftime(tempString2, 299, "%H:%M ", btime);
607 SNPRINTF(tempString, 299, "%s %s", tempString2, event->title);
609 sl.addOption(tempString, (ULONG)event, (i==0));
614 void VVideoLiveTV::setSummaryData()
616 // If osd is not being displayed, sl will be filled with now, current channel
617 // If the display was already on, sl will have programme to show summary for, not necessarily current channel and now
618 Event* selectedEvent = (Event*)sl.getCurrentOptionData();
622 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "No summary");
623 textSummary.setText(tr("No summary available"));
627 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Summary: %s", selectedEvent->description);
628 textSummary.setText(selectedEvent->description);
632 void VVideoLiveTV::displayOSD(bool newNowNextData)
634 osd.setVisible(true);
642 if (summary.getVisible())
646 boxstack->update(this, &osdSummaryRegion);
650 boxstack->update(this, osd.getRegion());
651 Timers::getInstance()->setTimerD(this, 1, 4);
655 void VVideoLiveTV::clearScreen()
657 if (!summary.getVisible()) Timers::getInstance()->cancelTimer(this, 1);
659 osd.setVisible(false);
661 if (summary.getVisible())
663 summary.setVisible(false);
665 boxstack->update(this, &osdSummaryRegion);
670 boxstack->update(this, osd.getRegion());
674 void VVideoLiveTV::setClock()
679 struct tm* tms = localtime(&t);
680 strftime(timeString, 19, "%H:%M", tms);
681 clock.setText(timeString);
683 time_t dt = 60 - (t % 60); // seconds to the next minute
684 if (dt == 0) dt = 60; // advance a whole minute if necessary
685 dt += t; // get a time_t value for it rather than using duration
686 // (so it will occur at the actual second and not second and a half)
688 Timers::getInstance()->setTimerT(this, 2, dt);
691 void VVideoLiveTV::timercall(int ref)
697 // Really, now that cancelTimer basically protects us from deletion, why can't we execute gui stuff here?
700 for(int i = keying - 1; i >= 0; i--) newChannel += keyingInput[i] * (ULONG)pow(10., i);
702 Message* m = new Message();
703 m->message = Message::CHANNEL_CHANGE;
705 m->parameter = newChannel;
706 m->tag = 1; // signal to call displayOSD();
707 Command::getInstance()->postMessageFromOuterSpace(m); // FIXME cjt yeah you know what.
711 osd.setVisible(false);
713 Message* m = new Message();
714 m->message = Message::REDRAW;
715 m->to = BoxStack::getInstance();
717 m->parameter = (ULONG)osd.getRegion();
718 Command::getInstance()->postMessageFromOuterSpace(m); // FIXME cjt yeah you know what.
724 if (osd.getVisible())
727 Message* m = new Message();
728 m->message = Message::REDRAW;
729 m->to = BoxStack::getInstance();
731 m->parameter = (ULONG)osd.getRegion();
732 Command::getInstance()->postMessageFromOuterSpace(m); // FIXME cjt yeah you know what.
737 bool VVideoLiveTV::channelChange(UCHAR changeType, UINT newData)
741 if (changeType == INDEX)
743 newChannel = newData;
745 else if (changeType == NUMBER)
748 for(i = 0; i < chanList->size(); i++)
750 if ((*chanList)[i]->number == (UINT)newData)
757 if (i == chanList->size())
763 else if (changeType == OFFSET)
765 if (newData == UP) newChannel = upChannel(currentChannelIndex);
766 else newChannel = downChannel(currentChannelIndex);
768 else if (changeType == PREVIOUS)
770 newChannel = previousChannelIndex;
774 return false; // bad input
777 if (newChannel == currentChannelIndex) return true;
779 previousChannelIndex = currentChannelIndex;
780 currentChannelIndex = newChannel;
782 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Set player to channel %u", currentChannelIndex);
783 player->setChannel(currentChannelIndex);
784 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Done Set player to channel %u", currentChannelIndex);
789 void VVideoLiveTV::processMessage(Message* m)
791 if (m->message == Message::MOUSE_LBDOWN)
793 //check if press is outside this view! then simulate cancel
794 int x=(m->parameter>>16)-osd.getScreenX();
795 int y=(m->parameter&0xFFFF)-osd.getScreenY();
796 if (osd.getVisible()) {
798 if ((boxRed.getX()<=x) && (boxRed.getX()+(int)boxRed.getWidth()>=x ) &&
799 (boxRed.getY()<=y) && (boxRed.getY()+(int)boxRed.getHeight()>=y )) {
800 BoxStack::getInstance()->handleCommand(Remote::RED);
801 } else if ((boxGreen.getX()<=x) && (boxGreen.getX()+(int)boxGreen.getWidth()>=x ) &&
802 (boxGreen.getY()<=y) && (boxGreen.getY()+(int)boxGreen.getHeight()>=y)){
803 BoxStack::getInstance()->handleCommand(Remote::GREEN);
804 } else if ((boxYellow.getX()<=x) && (boxYellow.getX()+(int)boxYellow.getWidth()>=x ) &&
805 (boxYellow.getY()<=y) && (boxYellow.getY()+(int)boxYellow.getHeight()>=y )){
806 BoxStack::getInstance()->handleCommand(Remote::YELLOW);
807 } else if ((boxBlue.getX()<=x) && (boxBlue.getX()+(int)boxBlue.getWidth()>=x ) &&
808 (boxBlue.getY()<=y) && (boxBlue.getY()+(int)boxBlue.getHeight()>=y )){
809 BoxStack::getInstance()->handleCommand(Remote::BLUE);
811 BoxStack::getInstance()->handleCommand(Remote::OK); //simulate rok press
815 BoxStack::getInstance()->handleCommand(Remote::OK); //simulate rok press
818 else if (m->message == Message::CHANNEL_CHANGE)
820 channelChange(NUMBER, m->parameter);
821 osdChannelIndex = currentChannelIndex;
822 if (m->tag == 1) displayOSD(true);
824 else if (m->message == Message::EPG_CLOSE)
826 video->setMode(videoMode);
828 else if (m->message == Message::CHILD_CLOSE)
836 else if (m->message == Message::AUDIO_CHANGE_CHANNEL)
838 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Received change audio channel to %i", m->parameter);
839 player->setAudioChannel((m->parameter & 0xFFFF),(m->parameter & 0xFF0000)>>16);
841 else if (m->message == Message::PLAYER_EVENT)
845 case PlayerLiveTV::CONNECTION_LOST: // connection lost detected
847 Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Received connection lost from player");
848 // I can't handle this, send it to command
849 Message* m2 = new Message();
850 m2->to = Command::getInstance();
851 m2->message = Message::CONNECTION_LOST;
852 Command::getInstance()->postMessageNoLock(m2);
857 case PlayerLiveTV::STREAM_END:
859 // I can't handle this, send it to command - improve this
860 Message* m2 = new Message(); // Must be done after this thread finishes, and must break into master mutex
861 m2->to = Command::getInstance();
862 m2->message = Message::STREAM_END;
863 Command::getInstance()->postMessageNoLock(m2);
868 case PlayerLiveTV::ASPECT43:
872 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 43");
875 BoxStack::getInstance()->update(this, &wssRegion);
878 sAspectRatio.nextSymbol = WSymbol::VIDEOASPECT43;
879 sAspectRatio.setVisible(true);
881 BoxStack::getInstance()->update(this, osd.getRegion());
885 case PlayerLiveTV::ASPECT169:
889 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 169");
892 BoxStack::getInstance()->update(this, &wssRegion);
895 sAspectRatio.nextSymbol = WSymbol::VIDEOASPECT169;
896 sAspectRatio.setVisible(true);
898 BoxStack::getInstance()->update(this, osd.getRegion());
902 case PlayerLiveTV::PREBUFFERING:
904 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Prebuffering - %u", m->tag);
910 UINT VVideoLiveTV::upChannel(UINT index)
912 if (index == (chanList->size() - 1)) // at the end
913 return 0; // so go to start
918 UINT VVideoLiveTV::downChannel(UINT index)
920 if (index == 0) // at the start
921 return chanList->size() - 1; // so go to end
926 void VVideoLiveTV::toggleChopSides()
928 if (video->getTVsize() == Video::ASPECT16X9) return; // Means nothing for 16:9 TVs
930 if (videoMode == Video::NORMAL)
932 videoMode = Video::LETTERBOX;
933 video->setMode(Video::LETTERBOX);
937 videoMode = Video::NORMAL;
938 video->setMode(Video::NORMAL);