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 videoMode = Video::getInstance()->getMode();
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
76 if (!unavailable) player->resyncAudio(); // do resync2
84 if (unavailable) showUnavailable(0);
88 // Take up and down from new remote and do live banner
96 case Remote::CHANNELUP:
98 if (unavailable) showUnavailable(0);
100 channelChange(OFFSET, UP);
103 case Remote::DF_DOWN:
104 case Remote::CHANNELDOWN:
106 if (unavailable) showUnavailable(0);
108 channelChange(OFFSET, DOWN);
111 case Remote::PREVCHANNEL:
113 if (unavailable) showUnavailable(0);
115 channelChange(PREVIOUS, 0);
130 case Remote::ZERO ... Remote::NINE:
132 VChannelSelect* v = new VChannelSelect(this, command);
135 viewman->updateView(v);
142 void VVideoLive::channelChange(UCHAR changeType, UINT newData)
146 if (changeType == INDEX)
148 newChannel = newData;
150 else if (changeType == NUMBER)
153 for(i = 0; i < chanList->size(); i++)
155 if ((*chanList)[i]->number == (UINT)newData)
162 if (i == chanList->size())
168 else if (changeType == OFFSET)
170 if (newData == UP) newChannel = upChannel();
171 else newChannel = downChannel();
173 else if (changeType == PREVIOUS)
175 newChannel = previousChannel;
179 return; // bad input!
182 previousChannel = currentChannel;
183 currentChannel = newChannel;
185 if (unavailable) showUnavailable(0);
188 VEpg* vepg = VEpg::getInstance();
189 if(vepg) vepg->setCurrentChannel((*chanList)[currentChannel]->name);
191 VLiveBanner* vlb = VLiveBanner::getInstance();
194 vlb->setChannel((*chanList)[currentChannel]);
196 viewman->updateView(vlb);
202 void VVideoLive::streamEnd()
204 Log::getInstance()->log("VVideoLive", Log::DEBUG, "streamEnd");
209 void VVideoLive::processMessage(Message* m)
211 if (m->message == Message::CHANNEL_CHANGE)
213 channelChange(NUMBER, m->parameter);
215 else if (m->message == Message::EPG)
217 Log::getInstance()->log("VVideoLive", Log::DEBUG, "EPG requested from live banner");
220 else if (m->message == Message::EPG_CLOSE)
222 Video::getInstance()->setMode(videoMode);
223 if (saveUnavailable) showUnavailable(1);
227 void VVideoLive::doBanner(bool bannerTakesCommands)
229 if (VEpg::getInstance()) return;
231 if (VLiveBanner::getInstance()) return; // there already is one
233 VLiveBanner* vlb = new VLiveBanner(this, (*chanList)[currentChannel], bannerTakesCommands);
237 viewman->updateView(vlb);
240 void VVideoLive::doNoSuchChannel()
242 Log::getInstance()->log("VVideoLive", Log::ERR, "No such channel");
243 // FIXME do gui for this
246 void VVideoLive::showUnavailable(int active)
248 if (active == unavailable) return;
254 unavailableView = new VInfo();
255 unavailableView->create(400, 200);
256 if (Video::getInstance()->getFormat() == Video::PAL)
258 unavailableView->setScreenPos(170, 200);
262 unavailableView->setScreenPos(160, 150);
264 unavailableView->setTitleText((*chanList)[currentChannel]->name);
265 unavailableView->setOneLiner(tr("Channel unavailable"));
266 unavailableView->setDropThrough();
267 unavailableView->draw();
268 viewman->add(unavailableView);
269 viewman->updateView(unavailableView);
274 viewman->removeView(unavailableView);
275 unavailableView = NULL;
279 void VVideoLive::play(int noShowVLB)
283 int available = vdr->streamChannel((*chanList)[currentChannel]->number);
287 if (!noShowVLB) doBanner(false);
292 if (!noShowVLB) doBanner(false);
297 void VVideoLive::stop(int noRemoveVLB)
299 if (unavailable) return;
300 if (!noRemoveVLB && VLiveBanner::getInstance()) viewman->removeView(VLiveBanner::getInstance()); // if live banner is present, remove it. won't cause damage if its not present
303 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay starts here due to time taken by plugin to stop");
304 vdr->stopStreaming();
305 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay ends here due to time taken by plugin to stop");
308 UINT VVideoLive::upChannel()
310 if (currentChannel == (chanList->size() - 1)) // at the end
311 return 0; // so go to start
313 return currentChannel + 1;
316 UINT VVideoLive::downChannel()
318 if (currentChannel == 0) // at the start
319 return chanList->size() - 1; // so go to end
321 return currentChannel - 1;
324 void VVideoLive::showEPG()
326 saveUnavailable = unavailable;
327 if (unavailable) showUnavailable(0);
329 if (VEpg::getInstance()) return; // already showing!
331 Video::getInstance()->setMode(Video::QUARTER);
332 Video::getInstance()->setPosition(170, 5); //TODO need to deal with 4:3 switching
334 VEpg* vepg = new VEpg(this, currentChannel);
338 viewman->updateView(vepg);