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, VChannelList* tvchannelList)
28 vdr = VDR::getInstance();
29 viewman = ViewMan::getInstance();
30 video = Video::getInstance();
33 vchannelList = tvchannelList;
38 unavailableView = NULL;
39 streamType = tstreamType;
40 videoMode = video->getMode();
41 if (streamType == VDR::RADIO) player = new Player(Command::getInstance(), 0, 1);
42 else player = new Player(Command::getInstance(), 0, 0);
45 create(video->getScreenWidth(), video->getScreenHeight());
46 Colour transparent(0, 0, 0, 0);
47 setBackgroundColour(transparent);
50 VVideoLive::~VVideoLive()
54 video->setDefaultAspect();
57 VVideoLive* VVideoLive::getInstance()
62 void VVideoLive::draw()
67 int VVideoLive::handleCommand(int command)
73 if (!unavailable) player->play(); // do resync
78 if (!unavailable) player->resyncAudio(); // do resync2
86 if (unavailable) showUnavailable(0);
89 vchannelList->highlightChannel((*chanList)[currentChannel]);
92 // Take up and down from new remote and do live banner
100 case Remote::CHANNELUP:
102 if (unavailable) showUnavailable(0);
104 channelChange(OFFSET, UP);
107 case Remote::DF_DOWN:
108 case Remote::CHANNELDOWN:
110 if (unavailable) showUnavailable(0);
112 channelChange(OFFSET, DOWN);
115 case Remote::PREVCHANNEL:
117 if (unavailable) showUnavailable(0);
119 channelChange(PREVIOUS, 0);
140 case Remote::ZERO ... Remote::NINE:
142 VChannelSelect* v = new VChannelSelect(this, command);
145 viewman->updateView(v);
153 void VVideoLive::channelChange(UCHAR changeType, UINT newData)
157 if (changeType == INDEX)
159 newChannel = newData;
161 else if (changeType == NUMBER)
164 for(i = 0; i < chanList->size(); i++)
166 if ((*chanList)[i]->number == (UINT)newData)
173 if (i == chanList->size())
179 else if (changeType == OFFSET)
181 if (newData == UP) newChannel = upChannel();
182 else newChannel = downChannel();
184 else if (changeType == PREVIOUS)
186 newChannel = previousChannel;
190 return; // bad input!
193 previousChannel = currentChannel;
194 currentChannel = newChannel;
196 if (unavailable) showUnavailable(0);
199 VEpg* vepg = VEpg::getInstance();
200 if(vepg) vepg->setCurrentChannel((*chanList)[currentChannel]->name);
202 VLiveBanner* vlb = VLiveBanner::getInstance();
205 vlb->setChannel((*chanList)[currentChannel]);
207 viewman->updateView(vlb);
213 void VVideoLive::streamEnd()
215 Log::getInstance()->log("VVideoLive", Log::DEBUG, "streamEnd");
220 void VVideoLive::processMessage(Message* m)
222 if (m->message == Message::CHANNEL_CHANGE)
224 channelChange(NUMBER, m->parameter);
226 else if (m->message == Message::EPG)
228 Log::getInstance()->log("VVideoLive", Log::DEBUG, "EPG requested from live banner");
231 else if (m->message == Message::EPG_CLOSE)
233 video->setMode(videoMode);
234 if (saveUnavailable) showUnavailable(1);
238 void VVideoLive::doBanner(bool bannerTakesCommands)
240 if (VEpg::getInstance()) return;
242 if (VLiveBanner::getInstance()) return; // there already is one
244 VLiveBanner* vlb = new VLiveBanner(this, (*chanList)[currentChannel], bannerTakesCommands);
248 viewman->updateView(vlb);
251 void VVideoLive::doNoSuchChannel()
253 Log::getInstance()->log("VVideoLive", Log::ERR, "No such channel");
254 // FIXME do gui for this
257 void VVideoLive::showUnavailable(int active)
259 if (active == unavailable) return;
265 unavailableView = new VInfo();
266 unavailableView->create(400, 200);
267 if (video->getFormat() == Video::PAL)
269 unavailableView->setScreenPos(170, 200);
273 unavailableView->setScreenPos(160, 150);
275 unavailableView->setTitleText((*chanList)[currentChannel]->name);
276 unavailableView->setOneLiner(tr("Channel unavailable"));
277 unavailableView->setDropThrough();
278 unavailableView->draw();
279 viewman->add(unavailableView);
280 viewman->updateView(unavailableView);
285 viewman->removeView(unavailableView);
286 unavailableView = NULL;
290 void VVideoLive::play(int noShowVLB)
294 int available = vdr->streamChannel((*chanList)[currentChannel]->number);
298 if (!noShowVLB) doBanner(false);
300 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
304 if (!noShowVLB) doBanner(false);
309 void VVideoLive::stop(int noRemoveVLB)
311 if (unavailable) return;
312 if (!noRemoveVLB && VLiveBanner::getInstance()) viewman->removeView(VLiveBanner::getInstance()); // if live banner is present, remove it. won't cause damage if its not present
315 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay starts here due to time taken by plugin to stop");
316 vdr->stopStreaming();
317 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
318 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay ends here due to time taken by plugin to stop");
321 UINT VVideoLive::upChannel()
323 if (currentChannel == (chanList->size() - 1)) // at the end
324 return 0; // so go to start
326 return currentChannel + 1;
329 UINT VVideoLive::downChannel()
331 if (currentChannel == 0) // at the start
332 return chanList->size() - 1; // so go to end
334 return currentChannel - 1;
337 void VVideoLive::showEPG()
339 saveUnavailable = unavailable;
340 if (unavailable) showUnavailable(0);
342 if (VEpg::getInstance()) return; // already showing!
344 video->setMode(Video::QUARTER);
345 video->setPosition(170, 5); //TODO need to deal with 4:3 switching
347 VEpg* vepg = new VEpg(this, currentChannel);
351 viewman->updateView(vepg);
354 void VVideoLive::toggleChopSides()
356 if (video->getTVsize() == Video::ASPECT16X9) return; // Means nothing for 16:9 TVs
358 if (videoMode == Video::NORMAL)
360 videoMode = Video::LETTERBOX;
361 video->setMode(Video::LETTERBOX);
365 videoMode = Video::NORMAL;
366 video->setMode(Video::NORMAL);