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)
157 newChannel = channelIndexFromNumber(newData);
159 else if (changeType == OFFSET)
161 if (newData == UP) newChannel = upChannel();
162 else newChannel = downChannel();
164 else if (changeType == PREVIOUS)
166 newChannel = previousChannel;
170 return; // bad input!
173 previousChannel = currentChannel;
174 currentChannel = newChannel;
176 if (unavailable) showUnavailable(0);
180 vepg->setCurrentChannel((*chanList)[currentChannel]->name);
184 void VVideoLive::processMessage(Message* m)
186 if (m->message == Message::CHANNEL_CHANGE)
188 channelChange(NUMBER, m->parameter);
190 else if (m->message == Message::CHANNEL_UP)
192 // this message is from vlivebanner
193 channelChange(OFFSET, UP);
196 VLiveBanner* vlb = VLiveBanner::getInstance(); // guaranteed to be one
197 vlb->setChannel((*chanList)[currentChannel]);
199 viewman->updateView(vlb);
202 else if (m->message == Message::CHANNEL_DOWN)
204 // this message is from vlivebanner
205 channelChange(OFFSET, DOWN);
208 VLiveBanner* vlb = VLiveBanner::getInstance(); // guaranteed to be one
209 vlb->setChannel((*chanList)[currentChannel]);
211 viewman->updateView(vlb);
214 else if (m->message == Message::STREAM_END)
216 Log::getInstance()->log("VVideoLive", Log::DEBUG, "streamEnd");
220 else if (m->message == Message::EPG)
222 Log::getInstance()->log("VVideoLive", Log::DEBUG, "EPG requested from live banner");
227 epgmode=!epgmode; // shouldn't this be within the braces? // same for above in handleCommand, ask Brian FIXME
232 void VVideoLive::doBanner(bool bannerTakesCommands)
237 if (VLiveBanner::getInstance()) return; // there already is one
239 VLiveBanner* vlb = new VLiveBanner(this, (*chanList)[currentChannel], bannerTakesCommands);
241 Message* m = new Message();
244 m->message = Message::ADD_VIEW;
245 m->parameter = (ULONG)vlb;
247 viewman->postMessage(m);
250 void VVideoLive::showUnavailable(int active)
252 if (active == unavailable) return;
258 unavailableView = new VInfo();
259 unavailableView->create(400, 200);
260 if (Video::getInstance()->getFormat() == Video::PAL)
262 unavailableView->setScreenPos(170, 200);
266 unavailableView->setScreenPos(160, 150);
268 unavailableView->setTitleText((*chanList)[currentChannel]->name);
269 unavailableView->setOneLiner(tr("Channel unavailable"));
270 unavailableView->setDropThrough();
272 Message* m = new Message();
275 m->message = Message::ADD_VIEW;
276 m->parameter = (ULONG)unavailableView;
278 viewman->postMessage(m);
283 viewman->removeView(unavailableView);
284 unavailableView = NULL;
288 void VVideoLive::play(int noShowVLB)
292 int available = vdr->streamChannel((*chanList)[currentChannel]->number);
297 if (!noShowVLB) doBanner(false);
301 if (!noShowVLB) doBanner(false);
306 void VVideoLive::stop(int noRemoveVLB)
308 if (unavailable) return;
309 if (!noRemoveVLB && VLiveBanner::getInstance()) viewman->removeView(VLiveBanner::getInstance()); // if live banner is present, remove it. won't cause damage if its not present
312 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay starts here due to time taken by plugin to stop");
313 vdr->stopStreaming();
314 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay ends here due to time taken by plugin to stop");
317 UINT VVideoLive::upChannel()
319 if (currentChannel == (chanList->size() - 1)) // at the end
320 return 0; // so go to start
322 return currentChannel + 1;
325 UINT VVideoLive::downChannel()
327 if (currentChannel == 0) // at the start
328 return chanList->size() - 1; // so go to end
330 return currentChannel - 1;
333 UINT VVideoLive::channelIndexFromNumber(int number)
335 for(UINT i = 0; i < chanList->size(); i++)
337 if ((*chanList)[i]->number == (UINT)number) return i;
342 UINT VVideoLive::getCurrentChannelIndex()
344 return channelIndexFromNumber(currentChannel);
347 void VVideoLive::showEPG()
349 if (unavailable) showUnavailable(0);
351 Video::getInstance()->setMode(Video::QUARTER);
352 Video::getInstance()->setPosition(170, 5); //TODO need to deal with 4:3 switching
354 vepg = new VEpg(this, currentChannel);
358 viewman->updateView(vepg);
361 void VVideoLive::setEpgMode(bool mode)
365 // Ok so we do need this function
366 // but FIXME improve this, integrate with live mode switching from remote
369 Video::getInstance()->setMode(videoMode);