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);
49 char* optionWSS = vdr->configLoad("General", "WSS");
50 if (strstr(optionWSS, "Yes")) dowss = true;
52 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Do WSS: %u", dowss);
55 wss.setSurface(surface);
60 wssRegion.w = video->getScreenWidth();
64 VVideoLive::~VVideoLive()
68 video->setDefaultAspect();
71 VVideoLive* VVideoLive::getInstance()
76 void VVideoLive::draw()
81 int VVideoLive::handleCommand(int command)
89 if (unavailable) showUnavailable(0);
92 vchannelList->highlightChannel((*chanList)[currentChannel]);
95 // Take up and down from new remote and do live banner
103 case Remote::CHANNELUP:
105 if (unavailable) showUnavailable(0);
107 channelChange(OFFSET, UP);
110 case Remote::DF_DOWN:
111 case Remote::CHANNELDOWN:
113 if (unavailable) showUnavailable(0);
115 channelChange(OFFSET, DOWN);
118 case Remote::PREVCHANNEL:
120 if (unavailable) showUnavailable(0);
122 channelChange(PREVIOUS, 0);
154 VChannelSelect* v = new VChannelSelect(this, command);
157 viewman->updateView(v);
177 void VVideoLive::channelChange(UCHAR changeType, UINT newData)
181 if (changeType == INDEX)
183 newChannel = newData;
185 else if (changeType == NUMBER)
188 for(i = 0; i < chanList->size(); i++)
190 if ((*chanList)[i]->number == (UINT)newData)
197 if (i == chanList->size())
203 else if (changeType == OFFSET)
205 if (newData == UP) newChannel = upChannel();
206 else newChannel = downChannel();
208 else if (changeType == PREVIOUS)
210 newChannel = previousChannel;
214 return; // bad input!
217 previousChannel = currentChannel;
218 currentChannel = newChannel;
220 if (unavailable) showUnavailable(0);
223 VEpg* vepg = VEpg::getInstance();
224 if(vepg) vepg->setCurrentChannel((*chanList)[currentChannel]->name);
226 VLiveBanner* vlb = VLiveBanner::getInstance();
229 vlb->setChannel((*chanList)[currentChannel]);
231 viewman->updateView(vlb);
237 void VVideoLive::streamEnd()
239 Log::getInstance()->log("VVideoLive", Log::DEBUG, "streamEnd");
244 void VVideoLive::processMessage(Message* m)
246 if (m->message == Message::CHANNEL_CHANGE)
248 channelChange(NUMBER, m->parameter);
250 else if (m->message == Message::EPG)
252 Log::getInstance()->log("VVideoLive", Log::DEBUG, "EPG requested from live banner");
255 else if (m->message == Message::EPG_CLOSE)
257 video->setMode(videoMode);
258 if (saveUnavailable) showUnavailable(1);
260 else if (m->message == Message::PLAYER_EVENT)
264 case Player::CONNECTION_LOST: // connection lost detected
266 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Received connection lost from player");
267 // I can't handle this, send it to command
268 Message* m = new Message();
269 m->to = Command::getInstance();
270 m->message = Message::CONNECTION_LOST;
271 Command::getInstance()->postMessageNoLock(m);
274 case Player::STREAM_END:
276 // I can't handle this, send it to command - improve this
277 Message* m = new Message(); // Must be done after this thread finishes, and must break into master mutex
278 m->to = Command::getInstance();
279 m->message = Message::STREAM_END;
280 Command::getInstance()->postMessageNoLock(m);
283 case Player::ASPECT43:
287 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 43");
290 ViewMan::getInstance()->updateView(this, &wssRegion);
294 case Player::ASPECT169:
298 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 169");
301 ViewMan::getInstance()->updateView(this, &wssRegion);
309 void VVideoLive::doBanner(bool bannerTakesCommands)
311 if (VEpg::getInstance()) return;
313 if (VLiveBanner::getInstance()) return; // there already is one
315 VLiveBanner* vlb = new VLiveBanner(this, (*chanList)[currentChannel], bannerTakesCommands);
319 viewman->updateView(vlb);
322 void VVideoLive::doNoSuchChannel()
324 Log::getInstance()->log("VVideoLive", Log::ERR, "No such channel");
325 // FIXME do gui for this
328 void VVideoLive::showUnavailable(int active)
330 if (active == unavailable) return;
336 unavailableView = new VInfo();
337 unavailableView->create(400, 200);
338 if (video->getFormat() == Video::PAL)
340 unavailableView->setScreenPos(170, 200);
344 unavailableView->setScreenPos(160, 150);
346 unavailableView->setTitleText((*chanList)[currentChannel]->name);
347 unavailableView->setOneLiner(tr("Channel unavailable"));
348 unavailableView->setDropThrough();
349 unavailableView->draw();
350 viewman->add(unavailableView);
351 viewman->updateView(unavailableView);
356 viewman->removeView(unavailableView);
357 unavailableView = NULL;
361 void VVideoLive::play(int noShowVLB)
365 int available = vdr->streamChannel((*chanList)[currentChannel]->number);
369 if (!noShowVLB) doBanner(false);
371 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
375 if (!noShowVLB) doBanner(false);
380 void VVideoLive::stop(int noRemoveVLB)
382 if (unavailable) return;
383 if (!noRemoveVLB && VLiveBanner::getInstance()) viewman->removeView(VLiveBanner::getInstance()); // if live banner is present, remove it. won't cause damage if its not present
386 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay starts here due to time taken by plugin to stop");
387 vdr->stopStreaming();
388 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
389 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay ends here due to time taken by plugin to stop");
392 UINT VVideoLive::upChannel()
394 if (currentChannel == (chanList->size() - 1)) // at the end
395 return 0; // so go to start
397 return currentChannel + 1;
400 UINT VVideoLive::downChannel()
402 if (currentChannel == 0) // at the start
403 return chanList->size() - 1; // so go to end
405 return currentChannel - 1;
408 void VVideoLive::showEPG()
410 saveUnavailable = unavailable;
411 if (unavailable) showUnavailable(0);
413 if (VEpg::getInstance()) return; // already showing!
415 video->setMode(Video::QUARTER);
416 video->setPosition(170, 5); //TODO need to deal with 4:3 switching
418 VEpg* vepg = new VEpg(this, currentChannel);
422 viewman->updateView(vepg);
425 void VVideoLive::toggleChopSides()
427 if (video->getTVsize() == Video::ASPECT16X9) return; // Means nothing for 16:9 TVs
429 if (videoMode == Video::NORMAL)
431 videoMode = Video::LETTERBOX;
432 video->setMode(Video::LETTERBOX);
436 videoMode = Video::NORMAL;
437 video->setMode(Video::NORMAL);