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);
50 VVideoLive::~VVideoLive()
54 video->setDefaultAspect();
57 VVideoLive* VVideoLive::getInstance()
62 void VVideoLive::draw()
67 int VVideoLive::handleCommand(int command)
75 if (unavailable) showUnavailable(0);
78 vchannelList->highlightChannel((*chanList)[currentChannel]);
81 // Take up and down from new remote and do live banner
89 case Remote::CHANNELUP:
91 if (unavailable) showUnavailable(0);
93 channelChange(OFFSET, UP);
97 case Remote::CHANNELDOWN:
99 if (unavailable) showUnavailable(0);
101 channelChange(OFFSET, DOWN);
104 case Remote::PREVCHANNEL:
106 if (unavailable) showUnavailable(0);
108 channelChange(PREVIOUS, 0);
140 VChannelSelect* v = new VChannelSelect(this, command);
143 viewman->updateView(v);
163 void VVideoLive::channelChange(UCHAR changeType, UINT newData)
167 if (changeType == INDEX)
169 newChannel = newData;
171 else if (changeType == NUMBER)
174 for(i = 0; i < chanList->size(); i++)
176 if ((*chanList)[i]->number == (UINT)newData)
183 if (i == chanList->size())
189 else if (changeType == OFFSET)
191 if (newData == UP) newChannel = upChannel();
192 else newChannel = downChannel();
194 else if (changeType == PREVIOUS)
196 newChannel = previousChannel;
200 return; // bad input!
203 previousChannel = currentChannel;
204 currentChannel = newChannel;
206 if (unavailable) showUnavailable(0);
209 VEpg* vepg = VEpg::getInstance();
210 if(vepg) vepg->setCurrentChannel((*chanList)[currentChannel]->name);
212 VLiveBanner* vlb = VLiveBanner::getInstance();
215 vlb->setChannel((*chanList)[currentChannel]);
217 viewman->updateView(vlb);
223 void VVideoLive::streamEnd()
225 Log::getInstance()->log("VVideoLive", Log::DEBUG, "streamEnd");
230 void VVideoLive::processMessage(Message* m)
232 if (m->message == Message::CHANNEL_CHANGE)
234 channelChange(NUMBER, m->parameter);
236 else if (m->message == Message::EPG)
238 Log::getInstance()->log("VVideoLive", Log::DEBUG, "EPG requested from live banner");
241 else if (m->message == Message::EPG_CLOSE)
243 video->setMode(videoMode);
244 if (saveUnavailable) showUnavailable(1);
246 else if (m->message == Message::PLAYER_EVENT)
250 case Player::CONNECTION_LOST: // connection lost detected
252 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Received connection lost from player");
253 // I can't handle this, send it to command
254 Message* m = new Message();
255 m->to = Command::getInstance();
256 m->message = Message::CONNECTION_LOST;
257 Command::getInstance()->postMessageNoLock(m);
260 case Player::STREAM_END:
262 // I can't handle this, send it to command - improve this
263 Message* m = new Message(); // Must be done after this thread finishes, and must break into master mutex
264 m->to = Command::getInstance();
265 m->message = Message::STREAM_END;
266 Command::getInstance()->postMessageNoLock(m);
269 case Player::ASPECT43:
271 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Received do WSS 43");
274 case Player::ASPECT169:
276 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Received do WSS 169");
283 void VVideoLive::doBanner(bool bannerTakesCommands)
285 if (VEpg::getInstance()) return;
287 if (VLiveBanner::getInstance()) return; // there already is one
289 VLiveBanner* vlb = new VLiveBanner(this, (*chanList)[currentChannel], bannerTakesCommands);
293 viewman->updateView(vlb);
296 void VVideoLive::doNoSuchChannel()
298 Log::getInstance()->log("VVideoLive", Log::ERR, "No such channel");
299 // FIXME do gui for this
302 void VVideoLive::showUnavailable(int active)
304 if (active == unavailable) return;
310 unavailableView = new VInfo();
311 unavailableView->create(400, 200);
312 if (video->getFormat() == Video::PAL)
314 unavailableView->setScreenPos(170, 200);
318 unavailableView->setScreenPos(160, 150);
320 unavailableView->setTitleText((*chanList)[currentChannel]->name);
321 unavailableView->setOneLiner(tr("Channel unavailable"));
322 unavailableView->setDropThrough();
323 unavailableView->draw();
324 viewman->add(unavailableView);
325 viewman->updateView(unavailableView);
330 viewman->removeView(unavailableView);
331 unavailableView = NULL;
335 void VVideoLive::play(int noShowVLB)
339 int available = vdr->streamChannel((*chanList)[currentChannel]->number);
343 if (!noShowVLB) doBanner(false);
345 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
349 if (!noShowVLB) doBanner(false);
354 void VVideoLive::stop(int noRemoveVLB)
356 if (unavailable) return;
357 if (!noRemoveVLB && VLiveBanner::getInstance()) viewman->removeView(VLiveBanner::getInstance()); // if live banner is present, remove it. won't cause damage if its not present
360 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay starts here due to time taken by plugin to stop");
361 vdr->stopStreaming();
362 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
363 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay ends here due to time taken by plugin to stop");
366 UINT VVideoLive::upChannel()
368 if (currentChannel == (chanList->size() - 1)) // at the end
369 return 0; // so go to start
371 return currentChannel + 1;
374 UINT VVideoLive::downChannel()
376 if (currentChannel == 0) // at the start
377 return chanList->size() - 1; // so go to end
379 return currentChannel - 1;
382 void VVideoLive::showEPG()
384 saveUnavailable = unavailable;
385 if (unavailable) showUnavailable(0);
387 if (VEpg::getInstance()) return; // already showing!
389 video->setMode(Video::QUARTER);
390 video->setPosition(170, 5); //TODO need to deal with 4:3 switching
392 VEpg* vepg = new VEpg(this, currentChannel);
396 viewman->updateView(vepg);
399 void VVideoLive::toggleChopSides()
401 if (video->getTVsize() == Video::ASPECT16X9) return; // Means nothing for 16:9 TVs
403 if (videoMode == Video::NORMAL)
405 videoMode = Video::LETTERBOX;
406 video->setMode(Video::LETTERBOX);
410 videoMode = Video::NORMAL;
411 video->setMode(Video::NORMAL);