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.setFormat(video->getFormat());
59 wss.setSurface(surface);
64 wssRegion.w = video->getScreenWidth();
68 VVideoLive::~VVideoLive()
72 video->setDefaultAspect();
75 VVideoLive* VVideoLive::getInstance()
80 void VVideoLive::draw()
85 int VVideoLive::handleCommand(int command)
93 if (unavailable) showUnavailable(0);
96 vchannelList->highlightChannel((*chanList)[currentChannel]);
99 // Take up and down from new remote and do live banner
107 case Remote::CHANNELUP:
109 if (unavailable) showUnavailable(0);
111 channelChange(OFFSET, UP);
114 case Remote::DF_DOWN:
115 case Remote::CHANNELDOWN:
117 if (unavailable) showUnavailable(0);
119 channelChange(OFFSET, DOWN);
122 case Remote::PREVCHANNEL:
124 if (unavailable) showUnavailable(0);
126 channelChange(PREVIOUS, 0);
158 VChannelSelect* v = new VChannelSelect(this, command);
161 viewman->updateView(v);
181 void VVideoLive::channelChange(UCHAR changeType, UINT newData)
185 if (changeType == INDEX)
187 newChannel = newData;
189 else if (changeType == NUMBER)
192 for(i = 0; i < chanList->size(); i++)
194 if ((*chanList)[i]->number == (UINT)newData)
201 if (i == chanList->size())
207 else if (changeType == OFFSET)
209 if (newData == UP) newChannel = upChannel();
210 else newChannel = downChannel();
212 else if (changeType == PREVIOUS)
214 newChannel = previousChannel;
218 return; // bad input!
221 previousChannel = currentChannel;
222 currentChannel = newChannel;
224 if (unavailable) showUnavailable(0);
227 VEpg* vepg = VEpg::getInstance();
228 if(vepg) vepg->setCurrentChannel((*chanList)[currentChannel]->name);
230 VLiveBanner* vlb = VLiveBanner::getInstance();
233 vlb->setChannel((*chanList)[currentChannel]);
235 viewman->updateView(vlb);
241 void VVideoLive::streamEnd()
243 Log::getInstance()->log("VVideoLive", Log::DEBUG, "streamEnd");
248 void VVideoLive::processMessage(Message* m)
250 if (m->message == Message::CHANNEL_CHANGE)
252 channelChange(NUMBER, m->parameter);
254 else if (m->message == Message::EPG)
256 Log::getInstance()->log("VVideoLive", Log::DEBUG, "EPG requested from live banner");
259 else if (m->message == Message::EPG_CLOSE)
261 video->setMode(videoMode);
262 if (saveUnavailable) showUnavailable(1);
264 else if (m->message == Message::PLAYER_EVENT)
268 case Player::CONNECTION_LOST: // connection lost detected
270 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Received connection lost from player");
271 // I can't handle this, send it to command
272 Message* m = new Message();
273 m->to = Command::getInstance();
274 m->message = Message::CONNECTION_LOST;
275 Command::getInstance()->postMessageNoLock(m);
278 case Player::STREAM_END:
280 // I can't handle this, send it to command - improve this
281 Message* m = new Message(); // Must be done after this thread finishes, and must break into master mutex
282 m->to = Command::getInstance();
283 m->message = Message::STREAM_END;
284 Command::getInstance()->postMessageNoLock(m);
287 case Player::ASPECT43:
291 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 43");
294 ViewMan::getInstance()->updateView(this, &wssRegion);
298 case Player::ASPECT169:
302 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 169");
305 ViewMan::getInstance()->updateView(this, &wssRegion);
313 void VVideoLive::doBanner(bool bannerTakesCommands)
315 if (VEpg::getInstance()) return;
317 if (VLiveBanner::getInstance()) return; // there already is one
319 VLiveBanner* vlb = new VLiveBanner(this, (*chanList)[currentChannel], bannerTakesCommands);
323 viewman->updateView(vlb);
326 void VVideoLive::doNoSuchChannel()
328 Log::getInstance()->log("VVideoLive", Log::ERR, "No such channel");
329 // FIXME do gui for this
332 void VVideoLive::showUnavailable(int active)
334 if (active == unavailable) return;
340 unavailableView = new VInfo();
341 unavailableView->create(400, 200);
342 if (video->getFormat() == Video::PAL)
344 unavailableView->setScreenPos(170, 200);
348 unavailableView->setScreenPos(160, 150);
350 unavailableView->setTitleText((*chanList)[currentChannel]->name);
351 unavailableView->setOneLiner(tr("Channel unavailable"));
352 unavailableView->setDropThrough();
353 unavailableView->draw();
354 viewman->add(unavailableView);
355 viewman->updateView(unavailableView);
360 viewman->removeView(unavailableView);
361 unavailableView = NULL;
365 void VVideoLive::play(int noShowVLB)
369 int available = vdr->streamChannel((*chanList)[currentChannel]->number);
373 if (!noShowVLB) doBanner(false);
375 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
379 if (!noShowVLB) doBanner(false);
384 void VVideoLive::stop(int noRemoveVLB)
386 if (unavailable) return;
387 if (!noRemoveVLB && VLiveBanner::getInstance()) viewman->removeView(VLiveBanner::getInstance()); // if live banner is present, remove it. won't cause damage if its not present
390 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay starts here due to time taken by plugin to stop");
391 vdr->stopStreaming();
392 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
393 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay ends here due to time taken by plugin to stop");
396 UINT VVideoLive::upChannel()
398 if (currentChannel == (chanList->size() - 1)) // at the end
399 return 0; // so go to start
401 return currentChannel + 1;
404 UINT VVideoLive::downChannel()
406 if (currentChannel == 0) // at the start
407 return chanList->size() - 1; // so go to end
409 return currentChannel - 1;
412 void VVideoLive::showEPG()
414 saveUnavailable = unavailable;
415 if (unavailable) showUnavailable(0);
417 if (VEpg::getInstance()) return; // already showing!
419 video->setMode(Video::QUARTER);
420 video->setPosition(170, 5); //TODO need to deal with 4:3 switching
422 VEpg* vepg = new VEpg(this, currentChannel);
426 viewman->updateView(vepg);
429 void VVideoLive::toggleChopSides()
431 if (video->getTVsize() == Video::ASPECT16X9) return; // Means nothing for 16:9 TVs
433 if (videoMode == Video::NORMAL)
435 videoMode = Video::LETTERBOX;
436 video->setMode(Video::LETTERBOX);
440 videoMode = Video::NORMAL;
441 video->setMode(Video::NORMAL);