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 vlb = (VLiveBanner*)1; // Can't be NULL because then that is sent to ViewMan::remove and it takes the top view off .. FIXME!
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);
85 case Remote::CHANNELUP:
87 if (unavailable) showUnavailable(0);
89 channelChange(OFFSET, UP);
93 case Remote::CHANNELDOWN:
95 if (unavailable) showUnavailable(0);
97 channelChange(OFFSET, DOWN);
116 case Remote::ZERO ... Remote::NINE:
118 VChannelSelect* v = new VChannelSelect(this, command);
119 viewman->addNoLock(v);
128 void VVideoLive::channelChange(UCHAR changeType, UINT newData)
132 if (changeType == INDEX)
134 newChannel = newData;
136 else if (changeType == NUMBER)
138 newChannel = channelIndexFromNumber(newData);
140 else if (changeType == OFFSET)
142 if (newData == UP) newChannel = upChannel();
143 else newChannel = downChannel();
145 else if (changeType == PREVIOUS)
147 newChannel = previousChannel;
151 return; // bad input!
154 previousChannel = currentChannel;
155 currentChannel = newChannel;
157 if (unavailable) showUnavailable(0);
161 vepg->setCurrentChannel((*chanList)[currentChannel]->name);
165 void VVideoLive::processMessage(Message* m)
167 if (m->message == Message::CHANNEL_CHANGE)
169 channelChange(NUMBER, m->parameter);
171 else if (m->message == Message::CHANNEL_UP)
173 // this message is from vlivebanner
174 channelChange(OFFSET, UP);
177 vlb->setChannel((*chanList)[currentChannel]);
182 else if (m->message == Message::CHANNEL_DOWN)
184 // this message is from vlivebanner
185 channelChange(OFFSET, DOWN);
188 vlb->setChannel((*chanList)[currentChannel]);
193 else if (m->message == Message::STREAM_END)
195 Log::getInstance()->log("VVideoLive", Log::DEBUG, "streamEnd");
201 void VVideoLive::doBanner(bool bannerTakesCommands)
205 vlb = new VLiveBanner(this, (*chanList)[currentChannel], bannerTakesCommands);
207 Message* m = new Message();
210 m->message = Message::ADD_VIEW;
211 m->parameter = (ULONG)vlb;
213 viewman->postMessage(m);
216 void VVideoLive::showUnavailable(int active)
218 if (active == unavailable) return;
224 unavailableView = new VInfo();
225 unavailableView->create(400, 200);
226 if (Video::getInstance()->getFormat() == Video::PAL)
228 unavailableView->setScreenPos(170, 200);
232 unavailableView->setScreenPos(160, 150);
234 unavailableView->setTitleText((*chanList)[currentChannel]->name);
235 unavailableView->setOneLiner(tr("Channel unavailable"));
236 unavailableView->setDropThrough();
238 Message* m = new Message();
241 m->message = Message::ADD_VIEW;
242 m->parameter = (ULONG)unavailableView;
244 viewman->postMessage(m);
249 ViewMan::getInstance()->removeView(unavailableView, 1);
250 unavailableView = NULL;
254 void VVideoLive::play(int noShowVLB)
258 int available = vdr->streamChannel((*chanList)[currentChannel]->number);
263 if (!noShowVLB) doBanner(false);
267 if (!noShowVLB) doBanner(false);
272 void VVideoLive::stop(int noRemoveVLB)
275 if (unavailable) return;
277 if (!noRemoveVLB) viewman->removeView(vlb, 1); // if live banner is present, remove it. won't cause damage if its not present
282 vdr->stopStreaming();
286 UINT VVideoLive::upChannel()
288 if (currentChannel == (chanList->size() - 1)) // at the end
289 return 0; // so go to start
291 return currentChannel + 1;
294 UINT VVideoLive::downChannel()
296 if (currentChannel == 0) // at the start
297 return chanList->size() - 1; // so go to end
299 return currentChannel - 1;
302 UINT VVideoLive::channelIndexFromNumber(int number)
304 for(UINT i = 0; i < chanList->size(); i++)
306 if ((*chanList)[i]->number == (UINT)number) return i;
311 UINT VVideoLive::getCurrentChannelIndex()
313 return channelIndexFromNumber(currentChannel);
316 void VVideoLive::showEPG()
318 if (unavailable) showUnavailable(0);
319 vepg = new VEpg(this, currentChannel);
320 ViewMan::getInstance()->addNoLock(vepg);
321 Video::getInstance()->setMode(Video::QUARTER);
322 Video::getInstance()->setPosition(170, 5); //TODO need to deal with 4:3 switching
327 void VVideoLive::setEpgMode(bool mode)