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 wss.setSurface(surface);
54 wssRegion.w = video->getScreenWidth();
58 VVideoLive::~VVideoLive()
62 video->setDefaultAspect();
65 VVideoLive* VVideoLive::getInstance()
70 void VVideoLive::draw()
75 int VVideoLive::handleCommand(int command)
83 if (unavailable) showUnavailable(0);
86 vchannelList->highlightChannel((*chanList)[currentChannel]);
89 // Take up and down from new remote and do live banner
97 case Remote::CHANNELUP:
99 if (unavailable) showUnavailable(0);
101 channelChange(OFFSET, UP);
104 case Remote::DF_DOWN:
105 case Remote::CHANNELDOWN:
107 if (unavailable) showUnavailable(0);
109 channelChange(OFFSET, DOWN);
112 case Remote::PREVCHANNEL:
114 if (unavailable) showUnavailable(0);
116 channelChange(PREVIOUS, 0);
148 VChannelSelect* v = new VChannelSelect(this, command);
151 viewman->updateView(v);
171 void VVideoLive::channelChange(UCHAR changeType, UINT newData)
175 if (changeType == INDEX)
177 newChannel = newData;
179 else if (changeType == NUMBER)
182 for(i = 0; i < chanList->size(); i++)
184 if ((*chanList)[i]->number == (UINT)newData)
191 if (i == chanList->size())
197 else if (changeType == OFFSET)
199 if (newData == UP) newChannel = upChannel();
200 else newChannel = downChannel();
202 else if (changeType == PREVIOUS)
204 newChannel = previousChannel;
208 return; // bad input!
211 previousChannel = currentChannel;
212 currentChannel = newChannel;
214 if (unavailable) showUnavailable(0);
217 VEpg* vepg = VEpg::getInstance();
218 if(vepg) vepg->setCurrentChannel((*chanList)[currentChannel]->name);
220 VLiveBanner* vlb = VLiveBanner::getInstance();
223 vlb->setChannel((*chanList)[currentChannel]);
225 viewman->updateView(vlb);
231 void VVideoLive::streamEnd()
233 Log::getInstance()->log("VVideoLive", Log::DEBUG, "streamEnd");
238 void VVideoLive::processMessage(Message* m)
240 if (m->message == Message::CHANNEL_CHANGE)
242 channelChange(NUMBER, m->parameter);
244 else if (m->message == Message::EPG)
246 Log::getInstance()->log("VVideoLive", Log::DEBUG, "EPG requested from live banner");
249 else if (m->message == Message::EPG_CLOSE)
251 video->setMode(videoMode);
252 if (saveUnavailable) showUnavailable(1);
254 else if (m->message == Message::PLAYER_EVENT)
258 case Player::CONNECTION_LOST: // connection lost detected
260 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Received connection lost from player");
261 // I can't handle this, send it to command
262 Message* m = new Message();
263 m->to = Command::getInstance();
264 m->message = Message::CONNECTION_LOST;
265 Command::getInstance()->postMessageNoLock(m);
268 case Player::STREAM_END:
270 // I can't handle this, send it to command - improve this
271 Message* m = new Message(); // Must be done after this thread finishes, and must break into master mutex
272 m->to = Command::getInstance();
273 m->message = Message::STREAM_END;
274 Command::getInstance()->postMessageNoLock(m);
277 case Player::ASPECT43:
279 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 43");
282 ViewMan::getInstance()->updateView(this, &wssRegion);
285 case Player::ASPECT169:
287 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 169");
290 ViewMan::getInstance()->updateView(this, &wssRegion);
297 void VVideoLive::doBanner(bool bannerTakesCommands)
299 if (VEpg::getInstance()) return;
301 if (VLiveBanner::getInstance()) return; // there already is one
303 VLiveBanner* vlb = new VLiveBanner(this, (*chanList)[currentChannel], bannerTakesCommands);
307 viewman->updateView(vlb);
310 void VVideoLive::doNoSuchChannel()
312 Log::getInstance()->log("VVideoLive", Log::ERR, "No such channel");
313 // FIXME do gui for this
316 void VVideoLive::showUnavailable(int active)
318 if (active == unavailable) return;
324 unavailableView = new VInfo();
325 unavailableView->create(400, 200);
326 if (video->getFormat() == Video::PAL)
328 unavailableView->setScreenPos(170, 200);
332 unavailableView->setScreenPos(160, 150);
334 unavailableView->setTitleText((*chanList)[currentChannel]->name);
335 unavailableView->setOneLiner(tr("Channel unavailable"));
336 unavailableView->setDropThrough();
337 unavailableView->draw();
338 viewman->add(unavailableView);
339 viewman->updateView(unavailableView);
344 viewman->removeView(unavailableView);
345 unavailableView = NULL;
349 void VVideoLive::play(int noShowVLB)
353 int available = vdr->streamChannel((*chanList)[currentChannel]->number);
357 if (!noShowVLB) doBanner(false);
359 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
363 if (!noShowVLB) doBanner(false);
368 void VVideoLive::stop(int noRemoveVLB)
370 if (unavailable) return;
371 if (!noRemoveVLB && VLiveBanner::getInstance()) viewman->removeView(VLiveBanner::getInstance()); // if live banner is present, remove it. won't cause damage if its not present
374 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay starts here due to time taken by plugin to stop");
375 vdr->stopStreaming();
376 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
377 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay ends here due to time taken by plugin to stop");
380 UINT VVideoLive::upChannel()
382 if (currentChannel == (chanList->size() - 1)) // at the end
383 return 0; // so go to start
385 return currentChannel + 1;
388 UINT VVideoLive::downChannel()
390 if (currentChannel == 0) // at the start
391 return chanList->size() - 1; // so go to end
393 return currentChannel - 1;
396 void VVideoLive::showEPG()
398 saveUnavailable = unavailable;
399 if (unavailable) showUnavailable(0);
401 if (VEpg::getInstance()) return; // already showing!
403 video->setMode(Video::QUARTER);
404 video->setPosition(170, 5); //TODO need to deal with 4:3 switching
406 VEpg* vepg = new VEpg(this, currentChannel);
410 viewman->updateView(vepg);
413 void VVideoLive::toggleChopSides()
415 if (video->getTVsize() == Video::ASPECT16X9) return; // Means nothing for 16:9 TVs
417 if (videoMode == Video::NORMAL)
419 videoMode = Video::LETTERBOX;
420 video->setMode(Video::LETTERBOX);
424 videoMode = Video::NORMAL;
425 video->setMode(Video::NORMAL);