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();
42 if (streamType == VDR::RADIO)
44 player = (void*)new PlayerRadio(Command::getInstance(), this, false);
45 ((PlayerRadio*)player)->init(0, 0);
49 player = (void*)new Player(Command::getInstance(), this, false);
50 ((Player*)player)->init();
53 create(video->getScreenWidth(), video->getScreenHeight());
54 Colour transparent(0, 0, 0, 0);
55 setBackgroundColour(transparent);
58 char* optionWSS = vdr->configLoad("General", "WSS");
61 if (strstr(optionWSS, "Yes")) dowss = true;
64 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Do WSS: %u", dowss);
66 wss.setFormat(video->getFormat());
67 wss.setSurface(surface);
72 wssRegion.w = video->getScreenWidth();
76 VVideoLive::~VVideoLive()
78 if (streamType == VDR::RADIO)
80 delete (PlayerRadio*)player;
84 delete (Player*)player;
88 video->setDefaultAspect();
91 VVideoLive* VVideoLive::getInstance()
96 void VVideoLive::draw()
101 int VVideoLive::handleCommand(int command)
109 if (unavailable) showUnavailable(0);
112 vchannelList->highlightChannel((*chanList)[currentChannel]);
115 // Take up and down from new remote and do live banner
123 case Remote::CHANNELUP:
125 if (unavailable) showUnavailable(0);
127 channelChange(OFFSET, UP);
130 case Remote::DF_DOWN:
131 case Remote::CHANNELDOWN:
133 if (unavailable) showUnavailable(0);
135 channelChange(OFFSET, DOWN);
138 case Remote::PREVCHANNEL:
140 if (unavailable) showUnavailable(0);
142 channelChange(PREVIOUS, 0);
174 VChannelSelect* v = new VChannelSelect(this, command);
177 viewman->updateView(v);
195 void VVideoLive::channelChange(UCHAR changeType, UINT newData)
199 if (changeType == INDEX)
201 newChannel = newData;
203 else if (changeType == NUMBER)
206 for(i = 0; i < chanList->size(); i++)
208 if ((*chanList)[i]->number == (UINT)newData)
215 if (i == chanList->size())
221 else if (changeType == OFFSET)
223 if (newData == UP) newChannel = upChannel();
224 else newChannel = downChannel();
226 else if (changeType == PREVIOUS)
228 newChannel = previousChannel;
232 return; // bad input!
235 previousChannel = currentChannel;
236 currentChannel = newChannel;
238 if (unavailable) showUnavailable(0);
241 VEpg* vepg = VEpg::getInstance();
242 if(vepg) vepg->setCurrentChannel((*chanList)[currentChannel]->name);
244 VLiveBanner* vlb = VLiveBanner::getInstance();
247 vlb->setChannel((*chanList)[currentChannel]);
249 viewman->updateView(vlb);
255 void VVideoLive::streamEnd()
257 Log::getInstance()->log("VVideoLive", Log::DEBUG, "streamEnd");
262 void VVideoLive::processMessage(Message* m)
264 if (m->message == Message::CHANNEL_CHANGE)
266 channelChange(NUMBER, m->parameter);
268 else if (m->message == Message::EPG)
270 Log::getInstance()->log("VVideoLive", Log::DEBUG, "EPG requested from live banner");
273 else if (m->message == Message::EPG_CLOSE)
275 video->setMode(videoMode);
276 if (saveUnavailable) showUnavailable(1);
278 else if (m->message == Message::PLAYER_EVENT)
282 case Player::CONNECTION_LOST: // connection lost detected
284 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Received connection lost from player");
285 // I can't handle this, send it to command
286 Message* m = new Message();
287 m->to = Command::getInstance();
288 m->message = Message::CONNECTION_LOST;
289 Command::getInstance()->postMessageNoLock(m);
292 case Player::STREAM_END:
294 // I can't handle this, send it to command - improve this
295 Message* m = new Message(); // Must be done after this thread finishes, and must break into master mutex
296 m->to = Command::getInstance();
297 m->message = Message::STREAM_END;
298 Command::getInstance()->postMessageNoLock(m);
301 case Player::ASPECT43:
305 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 43");
308 ViewMan::getInstance()->updateView(this, &wssRegion);
312 case Player::ASPECT169:
316 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 169");
319 ViewMan::getInstance()->updateView(this, &wssRegion);
327 void VVideoLive::doBanner(bool bannerTakesCommands)
329 if (VEpg::getInstance()) return;
331 if (VLiveBanner::getInstance()) return; // there already is one
333 VLiveBanner* vlb = new VLiveBanner(this, (*chanList)[currentChannel], bannerTakesCommands);
337 viewman->updateView(vlb);
340 void VVideoLive::doNoSuchChannel()
342 Log::getInstance()->log("VVideoLive", Log::ERR, "No such channel");
343 // FIXME do gui for this
346 void VVideoLive::showUnavailable(int active)
348 if (active == unavailable) return;
354 unavailableView = new VInfo();
355 unavailableView->create(400, 200);
356 if (video->getFormat() == Video::PAL)
358 unavailableView->setScreenPos(170, 200);
362 unavailableView->setScreenPos(160, 150);
364 unavailableView->setTitleText((*chanList)[currentChannel]->name);
365 unavailableView->setOneLiner(tr("Channel unavailable"));
366 unavailableView->setDropThrough();
367 unavailableView->draw();
368 viewman->add(unavailableView);
369 viewman->updateView(unavailableView);
374 viewman->removeView(unavailableView);
375 unavailableView = NULL;
379 void VVideoLive::play(int noShowVLB)
383 int available = vdr->streamChannel((*chanList)[currentChannel]->number);
387 if (!noShowVLB) doBanner(false);
389 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
393 if (!noShowVLB) doBanner(false);
395 // FIXME - change this streamType thingy to the new system using getPids
396 // FIXME - upgrade PlayerRadio to new getPids
398 Channel* toPlay = (*chanList)[currentChannel];
401 if (streamType == VDR::RADIO)
403 ((PlayerRadio*)player)->play(toPlay->apids[0].pid);
407 ((Player*)player)->play(toPlay->vpid, toPlay->apids[0].pid);
412 void VVideoLive::stop(int noRemoveVLB)
414 if (unavailable) return;
415 if (!noRemoveVLB && VLiveBanner::getInstance()) viewman->removeView(VLiveBanner::getInstance()); // if live banner is present, remove it. won't cause damage if its not present
417 if (streamType == VDR::RADIO)
419 ((PlayerRadio*)player)->stop();
423 ((Player*)player)->stop();
426 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay starts here due to time taken by plugin to stop");
427 vdr->stopStreaming();
428 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
429 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay ends here due to time taken by plugin to stop");
432 UINT VVideoLive::upChannel()
434 if (currentChannel == (chanList->size() - 1)) // at the end
435 return 0; // so go to start
437 return currentChannel + 1;
440 UINT VVideoLive::downChannel()
442 if (currentChannel == 0) // at the start
443 return chanList->size() - 1; // so go to end
445 return currentChannel - 1;
448 void VVideoLive::showEPG()
450 saveUnavailable = unavailable;
451 if (unavailable) showUnavailable(0);
453 if (VEpg::getInstance()) return; // already showing!
455 video->setMode(Video::QUARTER);
456 video->setPosition(170, 5); //TODO need to deal with 4:3 switching
458 VEpg* vepg = new VEpg(this, currentChannel);
462 viewman->updateView(vepg);
465 void VVideoLive::toggleChopSides()
467 if (video->getTVsize() == Video::ASPECT16X9) return; // Means nothing for 16:9 TVs
469 if (videoMode == Video::NORMAL)
471 videoMode = Video::LETTERBOX;
472 video->setMode(Video::LETTERBOX);
476 videoMode = Video::NORMAL;
477 video->setMode(Video::NORMAL);