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()
57 VVideoLive* VVideoLive::getInstance()
62 void VVideoLive::draw()
67 int VVideoLive::handleCommand(int command)
73 if (!unavailable) player->play(); // do resync
81 if (unavailable) showUnavailable(0);
86 case Remote::CHANNELUP:
88 if (unavailable) showUnavailable(0);
95 case Remote::CHANNELDOWN:
97 if (unavailable) showUnavailable(0);
109 case Remote::ZERO ... Remote::NINE:
111 VChannelSelect* v = new VChannelSelect(this, command);
112 viewman->addNoLock(v);
113 // ViewMan::getInstance()->timedDelete(v, 4, 0);
122 void VVideoLive::processMessage(Message* m)
124 if (m->message == Message::CHANNEL_CHANGE)
126 // check channel number is valid
127 currentChannel = channelIndexFromNumber(m->parameter);
128 if (unavailable) showUnavailable(0);
132 else if (m->message == Message::CHANNEL_UP)
135 if (unavailable) showUnavailable(0);
139 vlb->setChannel((*chanList)[currentChannel]);
143 else if (m->message == Message::CHANNEL_DOWN)
146 if (unavailable) showUnavailable(0);
150 vlb->setChannel((*chanList)[currentChannel]);
154 else if (m->message == Message::STREAM_END)
156 Log::getInstance()->log("VVideoLive", Log::DEBUG, "streamEnd");
162 void VVideoLive::doBanner()
164 vlb = new VLiveBanner(this, (*chanList)[currentChannel]);
165 viewman->timedDelete(vlb, 4, 0);
167 Message* m = new Message();
170 m->message = Message::ADD_VIEW;
171 m->parameter = (ULONG)vlb;
173 viewman->postMessage(m);
176 void VVideoLive::showUnavailable(int active)
178 if (active == unavailable) return;
184 unavailableView = new VInfo();
185 unavailableView->setDimensions(400, 200);
186 if (Video::getInstance()->getFormat() == Video::PAL)
188 unavailableView->setScreenPos(170, 200);
192 unavailableView->setScreenPos(160, 150);
194 unavailableView->setTitleText((*chanList)[currentChannel]->name);
195 unavailableView->setMainText("\n Channel unavailable");
196 unavailableView->setDropThrough();
198 Message* m = new Message();
201 m->message = Message::ADD_VIEW;
202 m->parameter = (ULONG)unavailableView;
204 viewman->postMessage(m);
209 ViewMan::getInstance()->removeView(unavailableView, 1);
210 unavailableView = NULL;
214 void VVideoLive::setChannel(int number)
216 currentChannel = channelIndexFromNumber(number);
220 void VVideoLive::play(int noShowVLB)
224 int available = vdr->streamChannel((*chanList)[currentChannel]->number);
229 if (!noShowVLB) doBanner();
233 if (!noShowVLB) doBanner();
238 void VVideoLive::stop(int noRemoveVLB)
240 if (unavailable) return;
241 if (!noRemoveVLB) viewman->removeView(vlb, 1, 1); // if live banner is present, remove it. won't cause damage if its not present
244 vdr->stopStreaming();
247 int VVideoLive::upChannel()
249 if (currentChannel == (chanList->size() - 1)) return 0; // at the end
255 int VVideoLive::downChannel()
257 if (currentChannel == 0) return 0; // at the start
263 UINT VVideoLive::channelIndexFromNumber(int number)
265 for(UINT i = 0; i < chanList->size(); i++)
267 if ((*chanList)[i]->number == (UINT)number) return i;