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;
36 videoMode = Video::getInstance()->getMode();
37 if (streamType == VDR::RADIO) player = new PlayerVideo(Command::getInstance(), 0, 1);
38 else player = new PlayerVideo(Command::getInstance(), 0, 0);
42 Video* video = Video::getInstance();
43 create(video->getScreenWidth(), video->getScreenHeight());
44 Colour transparent(0, 0, 0, 0);
45 setBackgroundColour(transparent);
48 VVideoLive::~VVideoLive()
52 Video::getInstance()->setDefaultAspect();
55 VVideoLive* VVideoLive::getInstance()
60 void VVideoLive::draw()
65 int VVideoLive::handleCommand(int command)
71 if (!unavailable) player->play(); // do resync
76 if (!unavailable) player->resyncAudio(); // do resync2
84 if (unavailable) showUnavailable(0);
88 // Take up and down from new remote and do live banner
96 case Remote::CHANNELUP:
98 if (unavailable) showUnavailable(0);
100 channelChange(OFFSET, UP);
103 case Remote::DF_DOWN:
104 case Remote::CHANNELDOWN:
106 if (unavailable) showUnavailable(0);
108 channelChange(OFFSET, DOWN);
111 case Remote::PREVCHANNEL:
113 if (unavailable) showUnavailable(0);
115 channelChange(PREVIOUS, 0);
130 case Remote::ZERO ... Remote::NINE:
132 VChannelSelect* v = new VChannelSelect(this, command);
135 viewman->updateView(v);
142 void VVideoLive::channelChange(UCHAR changeType, UINT newData)
146 if (changeType == INDEX)
148 newChannel = newData;
150 else if (changeType == NUMBER)
153 for(i = 0; i < chanList->size(); i++)
155 if ((*chanList)[i]->number == (UINT)newData)
162 if (i == chanList->size())
168 else if (changeType == OFFSET)
170 if (newData == UP) newChannel = upChannel();
171 else newChannel = downChannel();
173 else if (changeType == PREVIOUS)
175 newChannel = previousChannel;
179 return; // bad input!
182 previousChannel = currentChannel;
183 currentChannel = newChannel;
185 if (unavailable) showUnavailable(0);
188 VEpg* vepg = VEpg::getInstance();
189 if(vepg) vepg->setCurrentChannel((*chanList)[currentChannel]->name);
193 void VVideoLive::processMessage(Message* m)
195 if (m->message == Message::CHANNEL_CHANGE)
197 channelChange(NUMBER, m->parameter);
199 else if (m->message == Message::CHANNEL_UP)
201 // this message is from vlivebanner
202 channelChange(OFFSET, UP);
203 if(!VEpg::getInstance())
205 VLiveBanner* vlb = VLiveBanner::getInstance(); // guaranteed to be one
206 vlb->setChannel((*chanList)[currentChannel]);
208 viewman->updateView(vlb);
211 else if (m->message == Message::CHANNEL_DOWN)
213 // this message is from vlivebanner
214 channelChange(OFFSET, DOWN);
215 if(!VEpg::getInstance())
217 VLiveBanner* vlb = VLiveBanner::getInstance(); // guaranteed to be one
218 vlb->setChannel((*chanList)[currentChannel]);
220 viewman->updateView(vlb);
223 else if (m->message == Message::STREAM_END)
225 Log::getInstance()->log("VVideoLive", Log::DEBUG, "streamEnd");
229 else if (m->message == Message::EPG)
231 Log::getInstance()->log("VVideoLive", Log::DEBUG, "EPG requested from live banner");
234 else if (m->message == Message::EPG_CLOSE)
236 Video::getInstance()->setMode(videoMode);
237 if (saveUnavailable) showUnavailable(1);
241 void VVideoLive::doBanner(bool bannerTakesCommands)
243 if (VEpg::getInstance()) return;
245 if (VLiveBanner::getInstance()) return; // there already is one
247 VLiveBanner* vlb = new VLiveBanner(this, (*chanList)[currentChannel], bannerTakesCommands);
251 viewman->updateView(vlb);
254 void VVideoLive::doNoSuchChannel()
256 Log::getInstance()->log("VVideoLive", Log::ERR, "No such channel");
257 // FIXME do gui for this
260 void VVideoLive::showUnavailable(int active)
262 if (active == unavailable) return;
268 unavailableView = new VInfo();
269 unavailableView->create(400, 200);
270 if (Video::getInstance()->getFormat() == Video::PAL)
272 unavailableView->setScreenPos(170, 200);
276 unavailableView->setScreenPos(160, 150);
278 unavailableView->setTitleText((*chanList)[currentChannel]->name);
279 unavailableView->setOneLiner(tr("Channel unavailable"));
280 unavailableView->setDropThrough();
281 unavailableView->draw();
282 viewman->add(unavailableView);
283 viewman->updateView(unavailableView);
288 viewman->removeView(unavailableView);
289 unavailableView = NULL;
293 void VVideoLive::play(int noShowVLB)
297 int available = vdr->streamChannel((*chanList)[currentChannel]->number);
301 if (!noShowVLB) doBanner(false);
306 if (!noShowVLB) doBanner(false);
311 void VVideoLive::stop(int noRemoveVLB)
313 if (unavailable) return;
314 if (!noRemoveVLB && VLiveBanner::getInstance()) viewman->removeView(VLiveBanner::getInstance()); // if live banner is present, remove it. won't cause damage if its not present
317 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay starts here due to time taken by plugin to stop");
318 vdr->stopStreaming();
319 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay ends here due to time taken by plugin to stop");
322 UINT VVideoLive::upChannel()
324 if (currentChannel == (chanList->size() - 1)) // at the end
325 return 0; // so go to start
327 return currentChannel + 1;
330 UINT VVideoLive::downChannel()
332 if (currentChannel == 0) // at the start
333 return chanList->size() - 1; // so go to end
335 return currentChannel - 1;
338 void VVideoLive::showEPG()
340 saveUnavailable = unavailable;
341 if (unavailable) showUnavailable(0);
343 if (VEpg::getInstance()) return; // already showing!
345 Video::getInstance()->setMode(Video::QUARTER);
346 Video::getInstance()->setPosition(170, 5); //TODO need to deal with 4:3 switching
348 VEpg* vepg = new VEpg(this, currentChannel);
352 viewman->updateView(vepg);