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::MOUSE_LBDOWN)
266 ViewMan::getInstance()->handleCommand(Remote::OK); //simulate rok press
268 else if (m->message == Message::CHANNEL_CHANGE)
270 channelChange(NUMBER, m->parameter);
272 else if (m->message == Message::EPG)
274 Log::getInstance()->log("VVideoLive", Log::DEBUG, "EPG requested from live banner");
277 else if (m->message == Message::EPG_CLOSE)
279 video->setMode(videoMode);
280 if (saveUnavailable) showUnavailable(1);
282 else if (m->message == Message::PLAYER_EVENT)
286 case Player::CONNECTION_LOST: // connection lost detected
288 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Received connection lost from player");
289 // I can't handle this, send it to command
290 Message* m = new Message();
291 m->to = Command::getInstance();
292 m->message = Message::CONNECTION_LOST;
293 Command::getInstance()->postMessageNoLock(m);
296 case Player::STREAM_END:
298 // I can't handle this, send it to command - improve this
299 Message* m = new Message(); // Must be done after this thread finishes, and must break into master mutex
300 m->to = Command::getInstance();
301 m->message = Message::STREAM_END;
302 Command::getInstance()->postMessageNoLock(m);
305 case Player::ASPECT43:
309 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 43");
312 ViewMan::getInstance()->updateView(this, &wssRegion);
316 case Player::ASPECT169:
320 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 169");
323 ViewMan::getInstance()->updateView(this, &wssRegion);
331 void VVideoLive::doBanner(bool bannerTakesCommands)
333 if (VEpg::getInstance()) return;
335 if (VLiveBanner::getInstance()) return; // there already is one
337 VLiveBanner* vlb = new VLiveBanner(this, (*chanList)[currentChannel], bannerTakesCommands);
341 viewman->updateView(vlb);
344 void VVideoLive::doNoSuchChannel()
346 Log::getInstance()->log("VVideoLive", Log::ERR, "No such channel");
347 // FIXME do gui for this
350 void VVideoLive::showUnavailable(int active)
352 if (active == unavailable) return;
358 unavailableView = new VInfo();
359 unavailableView->create(400, 200);
360 if (video->getFormat() == Video::PAL)
362 unavailableView->setScreenPos(170, 200);
366 unavailableView->setScreenPos(160, 150);
368 unavailableView->setTitleText((*chanList)[currentChannel]->name);
369 unavailableView->setOneLiner(tr("Channel unavailable"));
370 unavailableView->setDropThrough();
371 unavailableView->draw();
372 viewman->add(unavailableView);
373 viewman->updateView(unavailableView);
378 viewman->removeView(unavailableView);
379 unavailableView = NULL;
383 void VVideoLive::play(int noShowVLB)
387 int available = vdr->streamChannel((*chanList)[currentChannel]->number);
391 if (!noShowVLB) doBanner(false);
393 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
397 if (!noShowVLB) doBanner(false);
399 // FIXME - change this streamType thingy to the new system using getPids
400 // FIXME - upgrade PlayerRadio to new getPids
402 Channel* toPlay = (*chanList)[currentChannel];
405 if (streamType == VDR::RADIO)
407 ((PlayerRadio*)player)->play(toPlay->apids[0].pid);
411 ((Player*)player)->play(toPlay->vpid, toPlay->apids[0].pid);
416 void VVideoLive::stop(int noRemoveVLB)
418 if (unavailable) return;
419 if (!noRemoveVLB && VLiveBanner::getInstance()) viewman->removeView(VLiveBanner::getInstance()); // if live banner is present, remove it. won't cause damage if its not present
421 if (streamType == VDR::RADIO)
423 ((PlayerRadio*)player)->stop();
427 ((Player*)player)->stop();
430 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay starts here due to time taken by plugin to stop");
431 vdr->stopStreaming();
432 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
433 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay ends here due to time taken by plugin to stop");
436 UINT VVideoLive::upChannel()
438 if (currentChannel == (chanList->size() - 1)) // at the end
439 return 0; // so go to start
441 return currentChannel + 1;
444 UINT VVideoLive::downChannel()
446 if (currentChannel == 0) // at the start
447 return chanList->size() - 1; // so go to end
449 return currentChannel - 1;
452 void VVideoLive::showEPG()
454 saveUnavailable = unavailable;
455 if (unavailable) showUnavailable(0);
457 if (VEpg::getInstance()) return; // already showing!
459 video->setMode(Video::QUARTER);
460 video->setPosition(170, 5); //TODO need to deal with 4:3 switching
462 VEpg* vepg = new VEpg(this, currentChannel);
466 viewman->updateView(vepg);
469 void VVideoLive::toggleChopSides()
471 if (video->getTVsize() == Video::ASPECT16X9) return; // Means nothing for 16:9 TVs
473 if (videoMode == Video::NORMAL)
475 videoMode = Video::LETTERBOX;
476 video->setMode(Video::LETTERBOX);
480 videoMode = Video::NORMAL;
481 video->setMode(Video::NORMAL);