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)
28 vdr = VDR::getInstance();
29 viewman = ViewMan::getInstance();
34 unavailableView = NULL;
35 streamType = tstreamType;
37 videoMode = Video::getInstance()->getMode();
38 if (streamType == VDR::RADIO) player = new PlayerVideo(Command::getInstance(), 0, 1);
39 else player = new PlayerVideo(Command::getInstance(), 0, 0);
43 Video* video = Video::getInstance();
44 create(video->getScreenWidth(), video->getScreenHeight());
45 Colour transparent(0, 0, 0, 0);
46 setBackgroundColour(transparent);
49 VVideoLive::~VVideoLive()
53 Video::getInstance()->setDefaultAspect();
56 VVideoLive* VVideoLive::getInstance()
61 void VVideoLive::draw()
66 int VVideoLive::handleCommand(int command)
72 if (!unavailable) player->play(); // do resync
80 if (unavailable) showUnavailable(0);
84 // Take up and down from new remote and do live banner
92 case Remote::CHANNELUP:
94 if (unavailable) showUnavailable(0);
96 channelChange(OFFSET, UP);
100 case Remote::CHANNELDOWN:
102 if (unavailable) showUnavailable(0);
104 channelChange(OFFSET, DOWN);
107 case Remote::PREVCHANNEL:
109 if (unavailable) showUnavailable(0);
111 channelChange(PREVIOUS, 0);
130 case Remote::ZERO ... Remote::NINE:
132 VChannelSelect* v = new VChannelSelect(this, command);
142 void VVideoLive::channelChange(UCHAR changeType, UINT newData)
146 if (changeType == INDEX)
148 newChannel = newData;
150 else if (changeType == NUMBER)
152 newChannel = channelIndexFromNumber(newData);
154 else if (changeType == OFFSET)
156 if (newData == UP) newChannel = upChannel();
157 else newChannel = downChannel();
159 else if (changeType == PREVIOUS)
161 newChannel = previousChannel;
165 return; // bad input!
168 previousChannel = currentChannel;
169 currentChannel = newChannel;
171 if (unavailable) showUnavailable(0);
175 vepg->setCurrentChannel((*chanList)[currentChannel]->name);
179 void VVideoLive::processMessage(Message* m)
181 if (m->message == Message::CHANNEL_CHANGE)
183 channelChange(NUMBER, m->parameter);
185 else if (m->message == Message::CHANNEL_UP)
187 // this message is from vlivebanner
188 channelChange(OFFSET, UP);
191 VLiveBanner* vlb = VLiveBanner::getInstance(); // guaranteed to be one
192 vlb->setChannel((*chanList)[currentChannel]);
197 else if (m->message == Message::CHANNEL_DOWN)
199 // this message is from vlivebanner
200 channelChange(OFFSET, DOWN);
203 VLiveBanner* vlb = VLiveBanner::getInstance(); // guaranteed to be one
204 vlb->setChannel((*chanList)[currentChannel]);
209 else if (m->message == Message::STREAM_END)
211 Log::getInstance()->log("VVideoLive", Log::DEBUG, "streamEnd");
215 else if (m->message == Message::EPG)
217 Log::getInstance()->log("VVideoLive", Log::DEBUG, "EPG requested from live banner");
222 epgmode=!epgmode; // shouldn't this be within the braces? // same for above in handleCommand, ask Brian FIXME
227 void VVideoLive::doBanner(bool bannerTakesCommands)
232 if (VLiveBanner::getInstance()) return; // there already is one
234 VLiveBanner* vlb = new VLiveBanner(this, (*chanList)[currentChannel], bannerTakesCommands);
236 Message* m = new Message();
239 m->message = Message::ADD_VIEW;
240 m->parameter = (ULONG)vlb;
242 viewman->postMessage(m);
245 void VVideoLive::showUnavailable(int active)
247 if (active == unavailable) return;
253 unavailableView = new VInfo();
254 unavailableView->create(400, 200);
255 if (Video::getInstance()->getFormat() == Video::PAL)
257 unavailableView->setScreenPos(170, 200);
261 unavailableView->setScreenPos(160, 150);
263 unavailableView->setTitleText((*chanList)[currentChannel]->name);
264 unavailableView->setOneLiner(tr("Channel unavailable"));
265 unavailableView->setDropThrough();
267 Message* m = new Message();
270 m->message = Message::ADD_VIEW;
271 m->parameter = (ULONG)unavailableView;
273 viewman->postMessage(m);
278 ViewMan::getInstance()->removeView(unavailableView);
279 unavailableView = NULL;
283 void VVideoLive::play(int noShowVLB)
287 int available = vdr->streamChannel((*chanList)[currentChannel]->number);
292 if (!noShowVLB) doBanner(false);
296 if (!noShowVLB) doBanner(false);
301 void VVideoLive::stop(int noRemoveVLB)
303 if (unavailable) return;
304 if (!noRemoveVLB && VLiveBanner::getInstance()) viewman->removeView(VLiveBanner::getInstance()); // if live banner is present, remove it. won't cause damage if its not present
307 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay starts here due to time taken by plugin to stop");
308 vdr->stopStreaming();
309 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay ends here due to time taken by plugin to stop");
312 UINT VVideoLive::upChannel()
314 if (currentChannel == (chanList->size() - 1)) // at the end
315 return 0; // so go to start
317 return currentChannel + 1;
320 UINT VVideoLive::downChannel()
322 if (currentChannel == 0) // at the start
323 return chanList->size() - 1; // so go to end
325 return currentChannel - 1;
328 UINT VVideoLive::channelIndexFromNumber(int number)
330 for(UINT i = 0; i < chanList->size(); i++)
332 if ((*chanList)[i]->number == (UINT)number) return i;
337 UINT VVideoLive::getCurrentChannelIndex()
339 return channelIndexFromNumber(currentChannel);
342 void VVideoLive::showEPG()
344 if (unavailable) showUnavailable(0);
345 vepg = new VEpg(this, currentChannel);
346 ViewMan::getInstance()->add(vepg);
347 Video::getInstance()->setMode(Video::QUARTER);
348 Video::getInstance()->setPosition(170, 5); //TODO need to deal with 4:3 switching
353 void VVideoLive::setEpgMode(bool mode)
357 // Ok so we do need this function
358 // but FIXME improve this, integrate with live mode switching from remote
361 Video::getInstance()->setMode(videoMode);