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();
33 unavailableView = NULL;
34 streamType = tstreamType;
35 if (streamType == VDR::VIDEO)
37 player = new PlayerVideo(Command::getInstance(), 0);
41 player = new PlayerRadio();
45 Video* video = Video::getInstance();
46 setDimensions(video->getScreenWidth(), video->getScreenHeight());
47 Colour transparent(0, 0, 0, 0);
48 setBackgroundColour(transparent);
51 VVideoLive::~VVideoLive()
55 Video::getInstance()->setDefaultAspect();
58 VVideoLive* VVideoLive::getInstance()
63 void VVideoLive::draw()
68 int VVideoLive::handleCommand(int command)
74 if (!unavailable) player->play(); // do resync
82 if (unavailable) showUnavailable(0);
87 case Remote::CHANNELUP:
89 if (unavailable) showUnavailable(0);
96 case Remote::CHANNELDOWN:
98 if (unavailable) showUnavailable(0);
110 case Remote::ZERO ... Remote::NINE:
112 VChannelSelect* v = new VChannelSelect(this, command);
113 viewman->addNoLock(v);
114 // ViewMan::getInstance()->timedDelete(v, 4, 0);
123 void VVideoLive::processMessage(Message* m)
125 if (m->message == Message::CHANNEL_CHANGE)
127 // check channel number is valid
128 currentChannel = channelIndexFromNumber(m->parameter);
129 if (unavailable) showUnavailable(0);
133 else if (m->message == Message::CHANNEL_UP)
136 if (unavailable) showUnavailable(0);
140 vlb->setChannel((*chanList)[currentChannel]);
144 else if (m->message == Message::CHANNEL_DOWN)
147 if (unavailable) showUnavailable(0);
151 vlb->setChannel((*chanList)[currentChannel]);
155 else if (m->message == Message::STREAM_END)
157 Log::getInstance()->log("VVideoLive", Log::DEBUG, "streamEnd");
163 void VVideoLive::doBanner()
165 vlb = new VLiveBanner(this, (*chanList)[currentChannel]);
166 viewman->timedDelete(vlb, 4, 0);
168 Message* m = new Message();
171 m->message = Message::ADD_VIEW;
172 m->parameter = (ULONG)vlb;
174 viewman->postMessage(m);
177 void VVideoLive::showUnavailable(int active)
179 if (active == unavailable) return;
185 unavailableView = new VInfo();
186 unavailableView->setDimensions(400, 200);
187 if (Video::getInstance()->getFormat() == Video::PAL)
189 unavailableView->setScreenPos(170, 200);
193 unavailableView->setScreenPos(160, 150);
195 unavailableView->setTitleText((*chanList)[currentChannel]->name);
196 unavailableView->setMainText("\n Channel unavailable");
197 unavailableView->setDropThrough();
199 Message* m = new Message();
202 m->message = Message::ADD_VIEW;
203 m->parameter = (ULONG)unavailableView;
205 viewman->postMessage(m);
210 ViewMan::getInstance()->removeView(unavailableView, 1);
211 unavailableView = NULL;
215 void VVideoLive::setChannel(int number)
217 currentChannel = channelIndexFromNumber(number);
221 void VVideoLive::play(int noShowVLB)
225 int available = vdr->streamChannel((*chanList)[currentChannel]->number);
230 if (!noShowVLB) doBanner();
234 if (!noShowVLB) doBanner();
239 void VVideoLive::stop(int noRemoveVLB)
241 if (unavailable) return;
242 if (!noRemoveVLB) viewman->removeView(vlb, 1, 1); // if live banner is present, remove it. won't cause damage if its not present
245 vdr->stopStreaming();
248 int VVideoLive::upChannel()
250 if (currentChannel == (chanList->size() - 1)) return 0; // at the end
256 int VVideoLive::downChannel()
258 if (currentChannel == 0) return 0; // at the start
264 UINT VVideoLive::channelIndexFromNumber(int number)
266 for(UINT i = 0; i < chanList->size(); i++)
268 if ((*chanList)[i]->number == (UINT)number) return i;