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 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
79 if (unavailable) showUnavailable(0);
84 case Remote::CHANNELUP:
86 if (unavailable) showUnavailable(0);
88 channelChange(OFFSET, UP);
92 case Remote::CHANNELDOWN:
94 if (unavailable) showUnavailable(0);
96 channelChange(OFFSET, DOWN);
99 case Remote::PREVCHANNEL:
101 if (unavailable) showUnavailable(0);
103 channelChange(PREVIOUS, 0);
122 case Remote::ZERO ... Remote::NINE:
124 VChannelSelect* v = new VChannelSelect(this, command);
134 void VVideoLive::channelChange(UCHAR changeType, UINT newData)
138 if (changeType == INDEX)
140 newChannel = newData;
142 else if (changeType == NUMBER)
144 newChannel = channelIndexFromNumber(newData);
146 else if (changeType == OFFSET)
148 if (newData == UP) newChannel = upChannel();
149 else newChannel = downChannel();
151 else if (changeType == PREVIOUS)
153 newChannel = previousChannel;
157 return; // bad input!
160 previousChannel = currentChannel;
161 currentChannel = newChannel;
163 if (unavailable) showUnavailable(0);
167 vepg->setCurrentChannel((*chanList)[currentChannel]->name);
171 void VVideoLive::processMessage(Message* m)
173 if (m->message == Message::CHANNEL_CHANGE)
175 channelChange(NUMBER, m->parameter);
177 else if (m->message == Message::CHANNEL_UP)
179 // this message is from vlivebanner
180 channelChange(OFFSET, UP);
183 VLiveBanner* vlb = VLiveBanner::getInstance(); // guaranteed to be one
184 vlb->setChannel((*chanList)[currentChannel]);
189 else if (m->message == Message::CHANNEL_DOWN)
191 // this message is from vlivebanner
192 channelChange(OFFSET, DOWN);
195 VLiveBanner* vlb = VLiveBanner::getInstance(); // guaranteed to be one
196 vlb->setChannel((*chanList)[currentChannel]);
201 else if (m->message == Message::STREAM_END)
203 Log::getInstance()->log("VVideoLive", Log::DEBUG, "streamEnd");
207 else if (m->message == Message::EPG)
209 Log::getInstance()->log("VVideoLive", Log::DEBUG, "EPG requested from live banner");
214 epgmode=!epgmode; // shouldn't this be within the braces? // same for above in handleCommand, ask Brian FIXME
219 void VVideoLive::doBanner(bool bannerTakesCommands)
224 if (VLiveBanner::getInstance()) return; // there already is one
226 VLiveBanner* vlb = new VLiveBanner(this, (*chanList)[currentChannel], bannerTakesCommands);
228 Message* m = new Message();
231 m->message = Message::ADD_VIEW;
232 m->parameter = (ULONG)vlb;
234 viewman->postMessage(m);
237 void VVideoLive::showUnavailable(int active)
239 if (active == unavailable) return;
245 unavailableView = new VInfo();
246 unavailableView->create(400, 200);
247 if (Video::getInstance()->getFormat() == Video::PAL)
249 unavailableView->setScreenPos(170, 200);
253 unavailableView->setScreenPos(160, 150);
255 unavailableView->setTitleText((*chanList)[currentChannel]->name);
256 unavailableView->setOneLiner(tr("Channel unavailable"));
257 unavailableView->setDropThrough();
259 Message* m = new Message();
262 m->message = Message::ADD_VIEW;
263 m->parameter = (ULONG)unavailableView;
265 viewman->postMessage(m);
270 ViewMan::getInstance()->removeView(unavailableView);
271 unavailableView = NULL;
275 void VVideoLive::play(int noShowVLB)
279 int available = vdr->streamChannel((*chanList)[currentChannel]->number);
284 if (!noShowVLB) doBanner(false);
288 if (!noShowVLB) doBanner(false);
293 void VVideoLive::stop(int noRemoveVLB)
296 if (unavailable) return;
298 if (!noRemoveVLB && VLiveBanner::getInstance()) viewman->removeView(VLiveBanner::getInstance()); // if live banner is present, remove it. won't cause damage if its not present
303 vdr->stopStreaming();
307 UINT VVideoLive::upChannel()
309 if (currentChannel == (chanList->size() - 1)) // at the end
310 return 0; // so go to start
312 return currentChannel + 1;
315 UINT VVideoLive::downChannel()
317 if (currentChannel == 0) // at the start
318 return chanList->size() - 1; // so go to end
320 return currentChannel - 1;
323 UINT VVideoLive::channelIndexFromNumber(int number)
325 for(UINT i = 0; i < chanList->size(); i++)
327 if ((*chanList)[i]->number == (UINT)number) return i;
332 UINT VVideoLive::getCurrentChannelIndex()
334 return channelIndexFromNumber(currentChannel);
337 void VVideoLive::showEPG()
339 if (unavailable) showUnavailable(0);
340 vepg = new VEpg(this, currentChannel);
341 ViewMan::getInstance()->add(vepg);
342 Video::getInstance()->setMode(Video::QUARTER);
343 Video::getInstance()->setPosition(170, 5); //TODO need to deal with 4:3 switching
348 void VVideoLive::setEpgMode(bool mode)