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);
177 viewman->updateView(v);
179 v->handleCommand(command);
198 void VVideoLive::channelChange(UCHAR changeType, UINT newData)
202 if (changeType == INDEX)
204 newChannel = newData;
206 else if (changeType == NUMBER)
209 for(i = 0; i < chanList->size(); i++)
211 if ((*chanList)[i]->number == (UINT)newData)
218 if (i == chanList->size())
224 else if (changeType == OFFSET)
226 if (newData == UP) newChannel = upChannel();
227 else newChannel = downChannel();
229 else if (changeType == PREVIOUS)
231 newChannel = previousChannel;
235 return; // bad input!
238 previousChannel = currentChannel;
239 currentChannel = newChannel;
241 if (unavailable) showUnavailable(0);
244 VEpg* vepg = VEpg::getInstance();
245 if(vepg) vepg->setCurrentChannel((*chanList)[currentChannel]->name);
247 VLiveBanner* vlb = VLiveBanner::getInstance();
250 vlb->setChannel((*chanList)[currentChannel]);
252 viewman->updateView(vlb);
258 void VVideoLive::streamEnd()
260 Log::getInstance()->log("VVideoLive", Log::DEBUG, "streamEnd");
265 void VVideoLive::processMessage(Message* m)
267 if (m->message == Message::MOUSE_LBDOWN)
269 ViewMan::getInstance()->handleCommand(Remote::OK); //simulate rok press
271 else if (m->message == Message::CHANNEL_CHANGE)
273 channelChange(NUMBER, m->parameter);
275 else if (m->message == Message::EPG)
277 Log::getInstance()->log("VVideoLive", Log::DEBUG, "EPG requested from live banner");
280 else if (m->message == Message::EPG_CLOSE)
282 video->setMode(videoMode);
283 if (saveUnavailable) showUnavailable(1);
285 else if (m->message == Message::PLAYER_EVENT)
289 case Player::CONNECTION_LOST: // connection lost detected
291 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Received connection lost from player");
292 // I can't handle this, send it to command
293 Message* m2 = new Message();
294 m2->to = Command::getInstance();
295 m2->message = Message::CONNECTION_LOST;
296 Command::getInstance()->postMessageNoLock(m2);
299 case Player::STREAM_END:
301 // I can't handle this, send it to command - improve this
302 Message* m2 = new Message(); // Must be done after this thread finishes, and must break into master mutex
303 m2->to = Command::getInstance();
304 m2->message = Message::STREAM_END;
305 Command::getInstance()->postMessageNoLock(m2);
308 case Player::ASPECT43:
312 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 43");
315 ViewMan::getInstance()->updateView(this, &wssRegion);
319 case Player::ASPECT169:
323 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 169");
326 ViewMan::getInstance()->updateView(this, &wssRegion);
334 void VVideoLive::doBanner(bool bannerTakesCommands)
336 if (VEpg::getInstance()) return;
338 if (VLiveBanner::getInstance()) return; // there already is one
340 VLiveBanner* vlb = new VLiveBanner(this, (*chanList)[currentChannel], bannerTakesCommands);
344 viewman->updateView(vlb);
347 void VVideoLive::doNoSuchChannel()
349 Log::getInstance()->log("VVideoLive", Log::ERR, "No such channel");
350 // FIXME do gui for this
353 void VVideoLive::showUnavailable(int active)
355 if (active == unavailable) return;
361 unavailableView = new VInfo();
362 unavailableView->create(400, 200);
363 if (video->getFormat() == Video::PAL)
365 unavailableView->setScreenPos(170, 200);
369 unavailableView->setScreenPos(160, 150);
371 unavailableView->setTitleText((*chanList)[currentChannel]->name);
372 unavailableView->setOneLiner(tr("Channel unavailable"));
373 unavailableView->setDropThrough();
374 unavailableView->draw();
375 viewman->add(unavailableView);
376 viewman->updateView(unavailableView);
381 viewman->removeView(unavailableView);
382 unavailableView = NULL;
386 void VVideoLive::play(int noShowVLB)
390 int available = vdr->streamChannel((*chanList)[currentChannel]->number);
394 if (!noShowVLB) doBanner(false);
396 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
400 if (!noShowVLB) doBanner(false);
402 // FIXME - change this streamType thingy to the new system using getPids
403 // FIXME - upgrade PlayerRadio to new getPids
405 Channel* toPlay = (*chanList)[currentChannel];
408 if (streamType == VDR::RADIO)
410 ((PlayerRadio*)player)->play(toPlay->apids[0].pid);
414 ((Player*)player)->play(toPlay->vpid, toPlay->apids[0].pid);
419 void VVideoLive::stop(int noRemoveVLB)
421 if (unavailable) return;
422 if (!noRemoveVLB && VLiveBanner::getInstance()) viewman->removeView(VLiveBanner::getInstance()); // if live banner is present, remove it. won't cause damage if its not present
424 if (streamType == VDR::RADIO)
426 ((PlayerRadio*)player)->stop();
430 ((Player*)player)->stop();
433 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay starts here due to time taken by plugin to stop");
434 vdr->stopStreaming();
435 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
436 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay ends here due to time taken by plugin to stop");
439 UINT VVideoLive::upChannel()
441 if (currentChannel == (chanList->size() - 1)) // at the end
442 return 0; // so go to start
444 return currentChannel + 1;
447 UINT VVideoLive::downChannel()
449 if (currentChannel == 0) // at the start
450 return chanList->size() - 1; // so go to end
452 return currentChannel - 1;
455 void VVideoLive::showEPG()
457 saveUnavailable = unavailable;
458 if (unavailable) showUnavailable(0);
460 if (VEpg::getInstance()) return; // already showing!
462 video->setMode(Video::QUARTER);
463 video->setPosition(170, 5); //TODO need to deal with 4:3 switching
465 VEpg* vepg = new VEpg(this, currentChannel, streamType);
469 viewman->updateView(vepg);
472 void VVideoLive::toggleChopSides()
474 if (video->getTVsize() == Video::ASPECT16X9) return; // Means nothing for 16:9 TVs
476 if (videoMode == Video::NORMAL)
478 videoMode = Video::LETTERBOX;
479 video->setMode(Video::LETTERBOX);
483 videoMode = Video::NORMAL;
484 video->setMode(Video::NORMAL);