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
77 if (!unavailable) player->resyncAudio(); // do resync2
85 if (unavailable) showUnavailable(0);
89 // Take up and down from new remote and do live banner
97 case Remote::CHANNELUP:
99 if (unavailable) showUnavailable(0);
101 channelChange(OFFSET, UP);
104 case Remote::DF_DOWN:
105 case Remote::CHANNELDOWN:
107 if (unavailable) showUnavailable(0);
109 channelChange(OFFSET, DOWN);
112 case Remote::PREVCHANNEL:
114 if (unavailable) showUnavailable(0);
116 channelChange(PREVIOUS, 0);
135 case Remote::ZERO ... Remote::NINE:
137 VChannelSelect* v = new VChannelSelect(this, command);
140 viewman->updateView(v);
147 void VVideoLive::channelChange(UCHAR changeType, UINT newData)
151 if (changeType == INDEX)
153 newChannel = newData;
155 else if (changeType == NUMBER)
158 for(i = 0; i < chanList->size(); i++)
160 if ((*chanList)[i]->number == (UINT)newData)
167 if (i == chanList->size())
173 else if (changeType == OFFSET)
175 if (newData == UP) newChannel = upChannel();
176 else newChannel = downChannel();
178 else if (changeType == PREVIOUS)
180 newChannel = previousChannel;
184 return; // bad input!
187 previousChannel = currentChannel;
188 currentChannel = newChannel;
190 if (unavailable) showUnavailable(0);
194 vepg->setCurrentChannel((*chanList)[currentChannel]->name);
198 void VVideoLive::processMessage(Message* m)
200 if (m->message == Message::CHANNEL_CHANGE)
202 channelChange(NUMBER, m->parameter);
204 else if (m->message == Message::CHANNEL_UP)
206 // this message is from vlivebanner
207 channelChange(OFFSET, UP);
210 VLiveBanner* vlb = VLiveBanner::getInstance(); // guaranteed to be one
211 vlb->setChannel((*chanList)[currentChannel]);
213 viewman->updateView(vlb);
216 else if (m->message == Message::CHANNEL_DOWN)
218 // this message is from vlivebanner
219 channelChange(OFFSET, DOWN);
222 VLiveBanner* vlb = VLiveBanner::getInstance(); // guaranteed to be one
223 vlb->setChannel((*chanList)[currentChannel]);
225 viewman->updateView(vlb);
228 else if (m->message == Message::STREAM_END)
230 Log::getInstance()->log("VVideoLive", Log::DEBUG, "streamEnd");
234 else if (m->message == Message::EPG)
236 Log::getInstance()->log("VVideoLive", Log::DEBUG, "EPG requested from live banner");
241 epgmode=!epgmode; // shouldn't this be within the braces? // same for above in handleCommand, ask Brian FIXME
246 void VVideoLive::doBanner(bool bannerTakesCommands)
251 if (VLiveBanner::getInstance()) return; // there already is one
253 VLiveBanner* vlb = new VLiveBanner(this, (*chanList)[currentChannel], bannerTakesCommands);
255 Message* m = new Message();
258 m->message = Message::ADD_VIEW;
259 m->parameter = (ULONG)vlb;
261 viewman->postMessage(m);
264 void VVideoLive::doNoSuchChannel()
266 Log::getInstance()->log("VVideoLive", Log::ERR, "No such channel");
267 // FIXME do gui for this
270 void VVideoLive::showUnavailable(int active)
272 if (active == unavailable) return;
278 unavailableView = new VInfo();
279 unavailableView->create(400, 200);
280 if (Video::getInstance()->getFormat() == Video::PAL)
282 unavailableView->setScreenPos(170, 200);
286 unavailableView->setScreenPos(160, 150);
288 unavailableView->setTitleText((*chanList)[currentChannel]->name);
289 unavailableView->setOneLiner(tr("Channel unavailable"));
290 unavailableView->setDropThrough();
292 Message* m = new Message();
295 m->message = Message::ADD_VIEW;
296 m->parameter = (ULONG)unavailableView;
298 viewman->postMessage(m);
303 viewman->removeView(unavailableView);
304 unavailableView = NULL;
308 void VVideoLive::play(int noShowVLB)
312 int available = vdr->streamChannel((*chanList)[currentChannel]->number);
317 if (!noShowVLB) doBanner(false);
321 if (!noShowVLB) doBanner(false);
326 void VVideoLive::stop(int noRemoveVLB)
328 if (unavailable) return;
329 if (!noRemoveVLB && VLiveBanner::getInstance()) viewman->removeView(VLiveBanner::getInstance()); // if live banner is present, remove it. won't cause damage if its not present
332 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay starts here due to time taken by plugin to stop");
333 vdr->stopStreaming();
334 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay ends here due to time taken by plugin to stop");
337 UINT VVideoLive::upChannel()
339 if (currentChannel == (chanList->size() - 1)) // at the end
340 return 0; // so go to start
342 return currentChannel + 1;
345 UINT VVideoLive::downChannel()
347 if (currentChannel == 0) // at the start
348 return chanList->size() - 1; // so go to end
350 return currentChannel - 1;
353 void VVideoLive::showEPG()
355 if (unavailable) showUnavailable(0);
357 Video::getInstance()->setMode(Video::QUARTER);
358 Video::getInstance()->setPosition(170, 5); //TODO need to deal with 4:3 switching
360 vepg = new VEpg(this, currentChannel);
364 viewman->updateView(vepg);
367 void VVideoLive::setEpgMode(bool mode)
371 // Ok so we do need this function
372 // but FIXME improve this, integrate with live mode switching from remote
375 Video::getInstance()->setMode(videoMode);