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)
73 if (!unavailable) player->play(); // do resync
78 if (!unavailable) player->resyncAudio(); // do resync2
86 if (unavailable) showUnavailable(0);
89 vchannelList->highlightChannel((*chanList)[currentChannel]);
92 // Take up and down from new remote and do live banner
100 case Remote::CHANNELUP:
102 if (unavailable) showUnavailable(0);
104 channelChange(OFFSET, UP);
107 case Remote::DF_DOWN:
108 case Remote::CHANNELDOWN:
110 if (unavailable) showUnavailable(0);
112 channelChange(OFFSET, DOWN);
115 case Remote::PREVCHANNEL:
117 if (unavailable) showUnavailable(0);
119 channelChange(PREVIOUS, 0);
151 VChannelSelect* v = new VChannelSelect(this, command);
154 viewman->updateView(v);
174 void VVideoLive::channelChange(UCHAR changeType, UINT newData)
178 if (changeType == INDEX)
180 newChannel = newData;
182 else if (changeType == NUMBER)
185 for(i = 0; i < chanList->size(); i++)
187 if ((*chanList)[i]->number == (UINT)newData)
194 if (i == chanList->size())
200 else if (changeType == OFFSET)
202 if (newData == UP) newChannel = upChannel();
203 else newChannel = downChannel();
205 else if (changeType == PREVIOUS)
207 newChannel = previousChannel;
211 return; // bad input!
214 previousChannel = currentChannel;
215 currentChannel = newChannel;
217 if (unavailable) showUnavailable(0);
220 VEpg* vepg = VEpg::getInstance();
221 if(vepg) vepg->setCurrentChannel((*chanList)[currentChannel]->name);
223 VLiveBanner* vlb = VLiveBanner::getInstance();
226 vlb->setChannel((*chanList)[currentChannel]);
228 viewman->updateView(vlb);
234 void VVideoLive::streamEnd()
236 Log::getInstance()->log("VVideoLive", Log::DEBUG, "streamEnd");
241 void VVideoLive::processMessage(Message* m)
243 if (m->message == Message::CHANNEL_CHANGE)
245 channelChange(NUMBER, m->parameter);
247 else if (m->message == Message::EPG)
249 Log::getInstance()->log("VVideoLive", Log::DEBUG, "EPG requested from live banner");
252 else if (m->message == Message::EPG_CLOSE)
254 video->setMode(videoMode);
255 if (saveUnavailable) showUnavailable(1);
259 void VVideoLive::doBanner(bool bannerTakesCommands)
261 if (VEpg::getInstance()) return;
263 if (VLiveBanner::getInstance()) return; // there already is one
265 VLiveBanner* vlb = new VLiveBanner(this, (*chanList)[currentChannel], bannerTakesCommands);
269 viewman->updateView(vlb);
272 void VVideoLive::doNoSuchChannel()
274 Log::getInstance()->log("VVideoLive", Log::ERR, "No such channel");
275 // FIXME do gui for this
278 void VVideoLive::showUnavailable(int active)
280 if (active == unavailable) return;
286 unavailableView = new VInfo();
287 unavailableView->create(400, 200);
288 if (video->getFormat() == Video::PAL)
290 unavailableView->setScreenPos(170, 200);
294 unavailableView->setScreenPos(160, 150);
296 unavailableView->setTitleText((*chanList)[currentChannel]->name);
297 unavailableView->setOneLiner(tr("Channel unavailable"));
298 unavailableView->setDropThrough();
299 unavailableView->draw();
300 viewman->add(unavailableView);
301 viewman->updateView(unavailableView);
306 viewman->removeView(unavailableView);
307 unavailableView = NULL;
311 void VVideoLive::play(int noShowVLB)
315 int available = vdr->streamChannel((*chanList)[currentChannel]->number);
319 if (!noShowVLB) doBanner(false);
321 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
325 if (!noShowVLB) doBanner(false);
330 void VVideoLive::stop(int noRemoveVLB)
332 if (unavailable) return;
333 if (!noRemoveVLB && VLiveBanner::getInstance()) viewman->removeView(VLiveBanner::getInstance()); // if live banner is present, remove it. won't cause damage if its not present
336 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay starts here due to time taken by plugin to stop");
337 vdr->stopStreaming();
338 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
339 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay ends here due to time taken by plugin to stop");
342 UINT VVideoLive::upChannel()
344 if (currentChannel == (chanList->size() - 1)) // at the end
345 return 0; // so go to start
347 return currentChannel + 1;
350 UINT VVideoLive::downChannel()
352 if (currentChannel == 0) // at the start
353 return chanList->size() - 1; // so go to end
355 return currentChannel - 1;
358 void VVideoLive::showEPG()
360 saveUnavailable = unavailable;
361 if (unavailable) showUnavailable(0);
363 if (VEpg::getInstance()) return; // already showing!
365 video->setMode(Video::QUARTER);
366 video->setPosition(170, 5); //TODO need to deal with 4:3 switching
368 VEpg* vepg = new VEpg(this, currentChannel);
372 viewman->updateView(vepg);
375 void VVideoLive::toggleChopSides()
377 if (video->getTVsize() == Video::ASPECT16X9) return; // Means nothing for 16:9 TVs
379 if (videoMode == Video::NORMAL)
381 videoMode = Video::LETTERBOX;
382 video->setMode(Video::LETTERBOX);
386 videoMode = Video::NORMAL;
387 video->setMode(Video::NORMAL);