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(), 0, 1);
42 else player = new Player(Command::getInstance(), 0, 0);
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);
162 void VVideoLive::channelChange(UCHAR changeType, UINT newData)
166 if (changeType == INDEX)
168 newChannel = newData;
170 else if (changeType == NUMBER)
173 for(i = 0; i < chanList->size(); i++)
175 if ((*chanList)[i]->number == (UINT)newData)
182 if (i == chanList->size())
188 else if (changeType == OFFSET)
190 if (newData == UP) newChannel = upChannel();
191 else newChannel = downChannel();
193 else if (changeType == PREVIOUS)
195 newChannel = previousChannel;
199 return; // bad input!
202 previousChannel = currentChannel;
203 currentChannel = newChannel;
205 if (unavailable) showUnavailable(0);
208 VEpg* vepg = VEpg::getInstance();
209 if(vepg) vepg->setCurrentChannel((*chanList)[currentChannel]->name);
211 VLiveBanner* vlb = VLiveBanner::getInstance();
214 vlb->setChannel((*chanList)[currentChannel]);
216 viewman->updateView(vlb);
222 void VVideoLive::streamEnd()
224 Log::getInstance()->log("VVideoLive", Log::DEBUG, "streamEnd");
229 void VVideoLive::processMessage(Message* m)
231 if (m->message == Message::CHANNEL_CHANGE)
233 channelChange(NUMBER, m->parameter);
235 else if (m->message == Message::EPG)
237 Log::getInstance()->log("VVideoLive", Log::DEBUG, "EPG requested from live banner");
240 else if (m->message == Message::EPG_CLOSE)
242 video->setMode(videoMode);
243 if (saveUnavailable) showUnavailable(1);
247 void VVideoLive::doBanner(bool bannerTakesCommands)
249 if (VEpg::getInstance()) return;
251 if (VLiveBanner::getInstance()) return; // there already is one
253 VLiveBanner* vlb = new VLiveBanner(this, (*chanList)[currentChannel], bannerTakesCommands);
257 viewman->updateView(vlb);
260 void VVideoLive::doNoSuchChannel()
262 Log::getInstance()->log("VVideoLive", Log::ERR, "No such channel");
263 // FIXME do gui for this
266 void VVideoLive::showUnavailable(int active)
268 if (active == unavailable) return;
274 unavailableView = new VInfo();
275 unavailableView->create(400, 200);
276 if (video->getFormat() == Video::PAL)
278 unavailableView->setScreenPos(170, 200);
282 unavailableView->setScreenPos(160, 150);
284 unavailableView->setTitleText((*chanList)[currentChannel]->name);
285 unavailableView->setOneLiner(tr("Channel unavailable"));
286 unavailableView->setDropThrough();
287 unavailableView->draw();
288 viewman->add(unavailableView);
289 viewman->updateView(unavailableView);
294 viewman->removeView(unavailableView);
295 unavailableView = NULL;
299 void VVideoLive::play(int noShowVLB)
303 int available = vdr->streamChannel((*chanList)[currentChannel]->number);
307 if (!noShowVLB) doBanner(false);
309 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
313 if (!noShowVLB) doBanner(false);
318 void VVideoLive::stop(int noRemoveVLB)
320 if (unavailable) return;
321 if (!noRemoveVLB && VLiveBanner::getInstance()) viewman->removeView(VLiveBanner::getInstance()); // if live banner is present, remove it. won't cause damage if its not present
324 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay starts here due to time taken by plugin to stop");
325 vdr->stopStreaming();
326 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
327 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay ends here due to time taken by plugin to stop");
330 UINT VVideoLive::upChannel()
332 if (currentChannel == (chanList->size() - 1)) // at the end
333 return 0; // so go to start
335 return currentChannel + 1;
338 UINT VVideoLive::downChannel()
340 if (currentChannel == 0) // at the start
341 return chanList->size() - 1; // so go to end
343 return currentChannel - 1;
346 void VVideoLive::showEPG()
348 saveUnavailable = unavailable;
349 if (unavailable) showUnavailable(0);
351 if (VEpg::getInstance()) return; // already showing!
353 video->setMode(Video::QUARTER);
354 video->setPosition(170, 5); //TODO need to deal with 4:3 switching
356 VEpg* vepg = new VEpg(this, currentChannel);
360 viewman->updateView(vepg);
363 void VVideoLive::toggleChopSides()
365 if (video->getTVsize() == Video::ASPECT16X9) return; // Means nothing for 16:9 TVs
367 if (videoMode == Video::NORMAL)
369 videoMode = Video::LETTERBOX;
370 video->setMode(Video::LETTERBOX);
374 videoMode = Video::NORMAL;
375 video->setMode(Video::NORMAL);