2 Copyright 2004-2005 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "vvideolive.h"
23 VVideoLive* VVideoLive::instance = NULL;
25 VVideoLive::VVideoLive(ChannelList* tchanList, ULONG tstreamType, VChannelList* tvchannelList)
28 vdr = VDR::getInstance();
29 viewman = ViewMan::getInstance();
30 video = Video::getInstance();
33 vchannelList = tvchannelList;
38 unavailableView = NULL;
39 streamType = tstreamType;
40 videoMode = video->getMode();
41 if (streamType == VDR::RADIO) player = new Player(Command::getInstance(), false, true);
42 else player = new Player(Command::getInstance(), false, false);
45 create(video->getScreenWidth(), video->getScreenHeight());
46 Colour transparent(0, 0, 0, 0);
47 setBackgroundColour(transparent);
50 VVideoLive::~VVideoLive()
54 video->setDefaultAspect();
57 VVideoLive* VVideoLive::getInstance()
62 void VVideoLive::draw()
67 int VVideoLive::handleCommand(int command)
75 if (unavailable) showUnavailable(0);
78 vchannelList->highlightChannel((*chanList)[currentChannel]);
81 // Take up and down from new remote and do live banner
89 case Remote::CHANNELUP:
91 if (unavailable) showUnavailable(0);
93 channelChange(OFFSET, UP);
97 case Remote::CHANNELDOWN:
99 if (unavailable) showUnavailable(0);
101 channelChange(OFFSET, DOWN);
104 case Remote::PREVCHANNEL:
106 if (unavailable) showUnavailable(0);
108 channelChange(PREVIOUS, 0);
140 VChannelSelect* v = new VChannelSelect(this, command);
143 viewman->updateView(v);
163 void VVideoLive::channelChange(UCHAR changeType, UINT newData)
167 if (changeType == INDEX)
169 newChannel = newData;
171 else if (changeType == NUMBER)
174 for(i = 0; i < chanList->size(); i++)
176 if ((*chanList)[i]->number == (UINT)newData)
183 if (i == chanList->size())
189 else if (changeType == OFFSET)
191 if (newData == UP) newChannel = upChannel();
192 else newChannel = downChannel();
194 else if (changeType == PREVIOUS)
196 newChannel = previousChannel;
200 return; // bad input!
203 previousChannel = currentChannel;
204 currentChannel = newChannel;
206 if (unavailable) showUnavailable(0);
209 VEpg* vepg = VEpg::getInstance();
210 if(vepg) vepg->setCurrentChannel((*chanList)[currentChannel]->name);
212 VLiveBanner* vlb = VLiveBanner::getInstance();
215 vlb->setChannel((*chanList)[currentChannel]);
217 viewman->updateView(vlb);
223 void VVideoLive::streamEnd()
225 Log::getInstance()->log("VVideoLive", Log::DEBUG, "streamEnd");
230 void VVideoLive::processMessage(Message* m)
232 if (m->message == Message::CHANNEL_CHANGE)
234 channelChange(NUMBER, m->parameter);
236 else if (m->message == Message::EPG)
238 Log::getInstance()->log("VVideoLive", Log::DEBUG, "EPG requested from live banner");
241 else if (m->message == Message::EPG_CLOSE)
243 video->setMode(videoMode);
244 if (saveUnavailable) showUnavailable(1);
248 void VVideoLive::doBanner(bool bannerTakesCommands)
250 if (VEpg::getInstance()) return;
252 if (VLiveBanner::getInstance()) return; // there already is one
254 VLiveBanner* vlb = new VLiveBanner(this, (*chanList)[currentChannel], bannerTakesCommands);
258 viewman->updateView(vlb);
261 void VVideoLive::doNoSuchChannel()
263 Log::getInstance()->log("VVideoLive", Log::ERR, "No such channel");
264 // FIXME do gui for this
267 void VVideoLive::showUnavailable(int active)
269 if (active == unavailable) return;
275 unavailableView = new VInfo();
276 unavailableView->create(400, 200);
277 if (video->getFormat() == Video::PAL)
279 unavailableView->setScreenPos(170, 200);
283 unavailableView->setScreenPos(160, 150);
285 unavailableView->setTitleText((*chanList)[currentChannel]->name);
286 unavailableView->setOneLiner(tr("Channel unavailable"));
287 unavailableView->setDropThrough();
288 unavailableView->draw();
289 viewman->add(unavailableView);
290 viewman->updateView(unavailableView);
295 viewman->removeView(unavailableView);
296 unavailableView = NULL;
300 void VVideoLive::play(int noShowVLB)
304 int available = vdr->streamChannel((*chanList)[currentChannel]->number);
308 if (!noShowVLB) doBanner(false);
310 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
314 if (!noShowVLB) doBanner(false);
319 void VVideoLive::stop(int noRemoveVLB)
321 if (unavailable) return;
322 if (!noRemoveVLB && VLiveBanner::getInstance()) viewman->removeView(VLiveBanner::getInstance()); // if live banner is present, remove it. won't cause damage if its not present
325 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay starts here due to time taken by plugin to stop");
326 vdr->stopStreaming();
327 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
328 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay ends here due to time taken by plugin to stop");
331 UINT VVideoLive::upChannel()
333 if (currentChannel == (chanList->size() - 1)) // at the end
334 return 0; // so go to start
336 return currentChannel + 1;
339 UINT VVideoLive::downChannel()
341 if (currentChannel == 0) // at the start
342 return chanList->size() - 1; // so go to end
344 return currentChannel - 1;
347 void VVideoLive::showEPG()
349 saveUnavailable = unavailable;
350 if (unavailable) showUnavailable(0);
352 if (VEpg::getInstance()) return; // already showing!
354 video->setMode(Video::QUARTER);
355 video->setPosition(170, 5); //TODO need to deal with 4:3 switching
357 VEpg* vepg = new VEpg(this, currentChannel);
361 viewman->updateView(vepg);
364 void VVideoLive::toggleChopSides()
366 if (video->getTVsize() == Video::ASPECT16X9) return; // Means nothing for 16:9 TVs
368 if (videoMode == Video::NORMAL)
370 videoMode = Video::LETTERBOX;
371 video->setMode(Video::LETTERBOX);
375 videoMode = Video::NORMAL;
376 video->setMode(Video::NORMAL);