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);
120 // ViewMan::getInstance()->timedDelete(v, 4, 0);
129 void VVideoLive::channelChange(UCHAR changeType, UINT newData)
133 if (changeType == INDEX)
135 newChannel = newData;
137 else if (changeType == NUMBER)
139 newChannel = channelIndexFromNumber(newData);
141 else if (changeType == OFFSET)
143 if (newData == UP) newChannel = upChannel();
144 else newChannel = downChannel();
146 else if (changeType == PREVIOUS)
148 newChannel = previousChannel;
152 return; // bad input!
155 previousChannel = currentChannel;
156 currentChannel = newChannel;
158 if (unavailable) showUnavailable(0);
162 vepg->setCurrentChannel((*chanList)[currentChannel]->name);
166 void VVideoLive::processMessage(Message* m)
168 if (m->message == Message::CHANNEL_CHANGE)
170 channelChange(NUMBER, m->parameter);
172 else if (m->message == Message::CHANNEL_UP)
174 // this message is from vlivebanner
175 channelChange(OFFSET, UP);
178 vlb->setChannel((*chanList)[currentChannel]);
183 else if (m->message == Message::CHANNEL_DOWN)
185 // this message is from vlivebanner
186 channelChange(OFFSET, DOWN);
189 vlb->setChannel((*chanList)[currentChannel]);
194 else if (m->message == Message::STREAM_END)
196 Log::getInstance()->log("VVideoLive", Log::DEBUG, "streamEnd");
202 void VVideoLive::doBanner(bool bannerTakesCommands)
206 vlb = new VLiveBanner(this, (*chanList)[currentChannel], bannerTakesCommands);
207 viewman->timedDelete(vlb, 4, 0);
209 Message* m = new Message();
212 m->message = Message::ADD_VIEW;
213 m->parameter = (ULONG)vlb;
215 viewman->postMessage(m);
218 void VVideoLive::showUnavailable(int active)
220 if (active == unavailable) return;
226 unavailableView = new VInfo();
227 unavailableView->create(400, 200);
228 if (Video::getInstance()->getFormat() == Video::PAL)
230 unavailableView->setScreenPos(170, 200);
234 unavailableView->setScreenPos(160, 150);
236 unavailableView->setTitleText((*chanList)[currentChannel]->name);
237 unavailableView->setOneLiner(tr("Channel unavailable"));
238 unavailableView->setDropThrough();
240 Message* m = new Message();
243 m->message = Message::ADD_VIEW;
244 m->parameter = (ULONG)unavailableView;
246 viewman->postMessage(m);
251 ViewMan::getInstance()->removeView(unavailableView, 1);
252 unavailableView = NULL;
256 void VVideoLive::play(int noShowVLB)
260 int available = vdr->streamChannel((*chanList)[currentChannel]->number);
265 if (!noShowVLB) doBanner(false);
269 if (!noShowVLB) doBanner(false);
274 void VVideoLive::stop(int noRemoveVLB)
277 if (unavailable) return;
279 if (!noRemoveVLB) viewman->removeView(vlb, 1); // if live banner is present, remove it. won't cause damage if its not present
284 vdr->stopStreaming();
288 UINT VVideoLive::upChannel()
290 if (currentChannel == (chanList->size() - 1)) // at the end
291 return 0; // so go to start
293 return currentChannel + 1;
296 UINT VVideoLive::downChannel()
298 if (currentChannel == 0) // at the start
299 return chanList->size() - 1; // so go to end
301 return currentChannel - 1;
304 UINT VVideoLive::channelIndexFromNumber(int number)
306 for(UINT i = 0; i < chanList->size(); i++)
308 if ((*chanList)[i]->number == (UINT)number) return i;
313 UINT VVideoLive::getCurrentChannelIndex()
315 return channelIndexFromNumber(currentChannel);
318 void VVideoLive::showEPG()
320 if (unavailable) showUnavailable(0);
321 vepg = new VEpg(this, currentChannel);
322 ViewMan::getInstance()->addNoLock(vepg);
323 Video::getInstance()->setMode(Video::QUARTER);
324 Video::getInstance()->setPosition(170, 5); //TODO need to deal with 4:3 switching
329 void VVideoLive::setEpgMode(bool mode)