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(), this, false, true);
42 else player = new Player(Command::getInstance(), this, false, false);
45 create(video->getScreenWidth(), video->getScreenHeight());
46 Colour transparent(0, 0, 0, 0);
47 setBackgroundColour(transparent);
50 char* optionWSS = vdr->configLoad("General", "WSS");
53 if (strstr(optionWSS, "Yes")) dowss = true;
56 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Do WSS: %u", dowss);
58 wss.setSurface(surface);
63 wssRegion.w = video->getScreenWidth();
67 VVideoLive::~VVideoLive()
71 video->setDefaultAspect();
74 VVideoLive* VVideoLive::getInstance()
79 void VVideoLive::draw()
84 int VVideoLive::handleCommand(int command)
92 if (unavailable) showUnavailable(0);
95 vchannelList->highlightChannel((*chanList)[currentChannel]);
98 // Take up and down from new remote and do live banner
106 case Remote::CHANNELUP:
108 if (unavailable) showUnavailable(0);
110 channelChange(OFFSET, UP);
113 case Remote::DF_DOWN:
114 case Remote::CHANNELDOWN:
116 if (unavailable) showUnavailable(0);
118 channelChange(OFFSET, DOWN);
121 case Remote::PREVCHANNEL:
123 if (unavailable) showUnavailable(0);
125 channelChange(PREVIOUS, 0);
157 VChannelSelect* v = new VChannelSelect(this, command);
160 viewman->updateView(v);
180 void VVideoLive::channelChange(UCHAR changeType, UINT newData)
184 if (changeType == INDEX)
186 newChannel = newData;
188 else if (changeType == NUMBER)
191 for(i = 0; i < chanList->size(); i++)
193 if ((*chanList)[i]->number == (UINT)newData)
200 if (i == chanList->size())
206 else if (changeType == OFFSET)
208 if (newData == UP) newChannel = upChannel();
209 else newChannel = downChannel();
211 else if (changeType == PREVIOUS)
213 newChannel = previousChannel;
217 return; // bad input!
220 previousChannel = currentChannel;
221 currentChannel = newChannel;
223 if (unavailable) showUnavailable(0);
226 VEpg* vepg = VEpg::getInstance();
227 if(vepg) vepg->setCurrentChannel((*chanList)[currentChannel]->name);
229 VLiveBanner* vlb = VLiveBanner::getInstance();
232 vlb->setChannel((*chanList)[currentChannel]);
234 viewman->updateView(vlb);
240 void VVideoLive::streamEnd()
242 Log::getInstance()->log("VVideoLive", Log::DEBUG, "streamEnd");
247 void VVideoLive::processMessage(Message* m)
249 if (m->message == Message::CHANNEL_CHANGE)
251 channelChange(NUMBER, m->parameter);
253 else if (m->message == Message::EPG)
255 Log::getInstance()->log("VVideoLive", Log::DEBUG, "EPG requested from live banner");
258 else if (m->message == Message::EPG_CLOSE)
260 video->setMode(videoMode);
261 if (saveUnavailable) showUnavailable(1);
263 else if (m->message == Message::PLAYER_EVENT)
267 case Player::CONNECTION_LOST: // connection lost detected
269 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Received connection lost from player");
270 // I can't handle this, send it to command
271 Message* m = new Message();
272 m->to = Command::getInstance();
273 m->message = Message::CONNECTION_LOST;
274 Command::getInstance()->postMessageNoLock(m);
277 case Player::STREAM_END:
279 // I can't handle this, send it to command - improve this
280 Message* m = new Message(); // Must be done after this thread finishes, and must break into master mutex
281 m->to = Command::getInstance();
282 m->message = Message::STREAM_END;
283 Command::getInstance()->postMessageNoLock(m);
286 case Player::ASPECT43:
290 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 43");
293 ViewMan::getInstance()->updateView(this, &wssRegion);
297 case Player::ASPECT169:
301 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 169");
304 ViewMan::getInstance()->updateView(this, &wssRegion);
312 void VVideoLive::doBanner(bool bannerTakesCommands)
314 if (VEpg::getInstance()) return;
316 if (VLiveBanner::getInstance()) return; // there already is one
318 VLiveBanner* vlb = new VLiveBanner(this, (*chanList)[currentChannel], bannerTakesCommands);
322 viewman->updateView(vlb);
325 void VVideoLive::doNoSuchChannel()
327 Log::getInstance()->log("VVideoLive", Log::ERR, "No such channel");
328 // FIXME do gui for this
331 void VVideoLive::showUnavailable(int active)
333 if (active == unavailable) return;
339 unavailableView = new VInfo();
340 unavailableView->create(400, 200);
341 if (video->getFormat() == Video::PAL)
343 unavailableView->setScreenPos(170, 200);
347 unavailableView->setScreenPos(160, 150);
349 unavailableView->setTitleText((*chanList)[currentChannel]->name);
350 unavailableView->setOneLiner(tr("Channel unavailable"));
351 unavailableView->setDropThrough();
352 unavailableView->draw();
353 viewman->add(unavailableView);
354 viewman->updateView(unavailableView);
359 viewman->removeView(unavailableView);
360 unavailableView = NULL;
364 void VVideoLive::play(int noShowVLB)
368 int available = vdr->streamChannel((*chanList)[currentChannel]->number);
372 if (!noShowVLB) doBanner(false);
374 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
378 if (!noShowVLB) doBanner(false);
383 void VVideoLive::stop(int noRemoveVLB)
385 if (unavailable) return;
386 if (!noRemoveVLB && VLiveBanner::getInstance()) viewman->removeView(VLiveBanner::getInstance()); // if live banner is present, remove it. won't cause damage if its not present
389 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay starts here due to time taken by plugin to stop");
390 vdr->stopStreaming();
391 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
392 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay ends here due to time taken by plugin to stop");
395 UINT VVideoLive::upChannel()
397 if (currentChannel == (chanList->size() - 1)) // at the end
398 return 0; // so go to start
400 return currentChannel + 1;
403 UINT VVideoLive::downChannel()
405 if (currentChannel == 0) // at the start
406 return chanList->size() - 1; // so go to end
408 return currentChannel - 1;
411 void VVideoLive::showEPG()
413 saveUnavailable = unavailable;
414 if (unavailable) showUnavailable(0);
416 if (VEpg::getInstance()) return; // already showing!
418 video->setMode(Video::QUARTER);
419 video->setPosition(170, 5); //TODO need to deal with 4:3 switching
421 VEpg* vepg = new VEpg(this, currentChannel);
425 viewman->updateView(vepg);
428 void VVideoLive::toggleChopSides()
430 if (video->getTVsize() == Video::ASPECT16X9) return; // Means nothing for 16:9 TVs
432 if (videoMode == Video::NORMAL)
434 videoMode = Video::LETTERBOX;
435 video->setMode(Video::LETTERBOX);
439 videoMode = Video::NORMAL;
440 video->setMode(Video::NORMAL);