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 #include "vchannellist.h"
26 #include "playerradio.h"
28 #include "vlivebanner.h"
30 #include "vchannelselect.h"
39 #include "vaudioselector.h"
41 VVideoLive* VVideoLive::instance = NULL;
43 VVideoLive::VVideoLive(ChannelList* tchanList, ULONG tstreamType, VChannelList* tvchannelList)
46 vdr = VDR::getInstance();
47 boxstack = BoxStack::getInstance();
48 video = Video::getInstance();
51 vchannelList = tvchannelList;
56 unavailableView = NULL;
57 streamType = tstreamType;
58 videoMode = video->getMode();
60 if (streamType == VDR::RADIO)
62 player = (void*)new PlayerRadio(Command::getInstance(), this, false);
63 ((PlayerRadio*)player)->init(0, 0);
67 player = (void*)new Player(Command::getInstance(), this, false);
68 ((Player*)player)->init();
71 setSize(video->getScreenWidth(), video->getScreenHeight());
73 Colour transparent(0, 0, 0, 0);
74 fillColour(transparent);
77 char* optionWSS = vdr->configLoad("General", "WSS");
80 if (strstr(optionWSS, "Yes")) dowss = true;
83 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Do WSS: %u", dowss);
85 wss.setFormat(video->getFormat());
91 wssRegion.w = video->getScreenWidth();
95 VVideoLive::~VVideoLive()
97 if (streamType == VDR::RADIO)
99 delete (PlayerRadio*)player;
103 delete (Player*)player;
107 video->setDefaultAspect();
110 VVideoLive* VVideoLive::getInstance()
115 int VVideoLive::handleCommand(int command)
123 if (unavailable) showUnavailable(0);
126 vchannelList->highlightChannel((*chanList)[currentChannel]);
129 // Take up and down from new remote and do live banner
137 case Remote::CHANNELUP:
139 if (unavailable) showUnavailable(0);
141 channelChange(OFFSET, UP);
144 case Remote::DF_DOWN:
145 case Remote::CHANNELDOWN:
147 if (unavailable) showUnavailable(0);
149 channelChange(OFFSET, DOWN);
152 case Remote::PREVCHANNEL:
154 if (unavailable) showUnavailable(0);
156 channelChange(PREVIOUS, 0);
188 VChannelSelect* v = new VChannelSelect(this);
193 v->handleCommand(command);
199 if (streamType == VDR::VIDEO)
201 VAudioSelector* vas = new VAudioSelector(this, (*chanList)[currentChannel], ((Player*)player)->getCurrentAudioChannel());
202 vas->setBackgroundColour(Colour::VIEWBACKGROUND);
203 vas->setPosition(0, getHeight()-200);
205 BoxStack::getInstance()->add(vas);
206 BoxStack::getInstance()->update(vas);
222 void VVideoLive::channelChange(UCHAR changeType, UINT newData)
226 if (changeType == INDEX)
228 newChannel = newData;
230 else if (changeType == NUMBER)
233 for(i = 0; i < chanList->size(); i++)
235 if ((*chanList)[i]->number == (UINT)newData)
242 if (i == chanList->size())
248 else if (changeType == OFFSET)
250 if (newData == UP) newChannel = upChannel();
251 else newChannel = downChannel();
253 else if (changeType == PREVIOUS)
255 newChannel = previousChannel;
259 return; // bad input!
262 previousChannel = currentChannel;
263 currentChannel = newChannel;
265 if (unavailable) showUnavailable(0);
268 VEpg* vepg = VEpg::getInstance();
269 if(vepg) vepg->setCurrentChannel((*chanList)[currentChannel]->name);
271 VLiveBanner* vlb = VLiveBanner::getInstance();
274 vlb->setChannel((*chanList)[currentChannel]);
276 boxstack->update(vlb);
282 void VVideoLive::streamEnd()
284 Log::getInstance()->log("VVideoLive", Log::DEBUG, "streamEnd");
289 void VVideoLive::processMessage(Message* m)
291 if (m->message == Message::MOUSE_LBDOWN)
293 BoxStack::getInstance()->handleCommand(Remote::OK); //simulate rok press
295 else if (m->message == Message::CHANNEL_CHANGE)
297 channelChange(NUMBER, m->parameter);
299 else if (m->message == Message::EPG)
301 Log::getInstance()->log("VVideoLive", Log::DEBUG, "EPG requested from live banner");
304 else if (m->message == Message::EPG_CLOSE)
306 video->setMode(videoMode);
307 if (saveUnavailable) showUnavailable(1);
309 else if (m->message == Message::AUDIO_CHANGE_CHANNEL)
311 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Received change audio channel to %i", m->parameter);
312 ((Player*)player)->setAudioChannel(m->parameter);
314 else if (m->message == Message::PLAYER_EVENT)
318 case Player::CONNECTION_LOST: // connection lost detected
320 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Received connection lost from player");
321 // I can't handle this, send it to command
322 Message* m2 = new Message();
323 m2->to = Command::getInstance();
324 m2->message = Message::CONNECTION_LOST;
325 Command::getInstance()->postMessageNoLock(m2);
328 case Player::STREAM_END:
330 // I can't handle this, send it to command - improve this
331 Message* m2 = new Message(); // Must be done after this thread finishes, and must break into master mutex
332 m2->to = Command::getInstance();
333 m2->message = Message::STREAM_END;
334 Command::getInstance()->postMessageNoLock(m2);
337 case Player::ASPECT43:
341 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 43");
344 BoxStack::getInstance()->update(this, &wssRegion);
348 case Player::ASPECT169:
352 Log::getInstance()->log("VVideoRec", Log::DEBUG, "Received do WSS 169");
355 BoxStack::getInstance()->update(this, &wssRegion);
363 void VVideoLive::doBanner(bool bannerTakesCommands)
365 if (VEpg::getInstance()) return;
367 if (VLiveBanner::getInstance()) return; // there already is one
369 VLiveBanner* vlb = new VLiveBanner(this, (*chanList)[currentChannel], bannerTakesCommands);
373 boxstack->update(vlb);
376 void VVideoLive::doNoSuchChannel()
378 Log::getInstance()->log("VVideoLive", Log::ERR, "No such channel");
379 // FIXME do gui for this
382 void VVideoLive::showUnavailable(int active)
384 if (active == unavailable) return;
390 unavailableView = new VInfo();
391 unavailableView->setSize(400, 200);
392 unavailableView->createBuffer();
393 if (video->getFormat() == Video::PAL)
395 unavailableView->setPosition(170, 200);
399 unavailableView->setPosition(160, 150);
401 unavailableView->setTitleText((*chanList)[currentChannel]->name);
402 unavailableView->setOneLiner(tr("Channel unavailable"));
403 unavailableView->setDropThrough();
404 unavailableView->draw();
405 boxstack->add(unavailableView);
406 boxstack->update(unavailableView);
411 boxstack->remove(unavailableView);
412 unavailableView = NULL;
416 void VVideoLive::play(int noShowVLB)
420 int available = vdr->streamChannel((*chanList)[currentChannel]->number);
424 if (!noShowVLB) doBanner(false);
426 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
430 if (!noShowVLB) doBanner(false);
432 // FIXME - change this streamType thingy to the new system using getPids
433 // FIXME - upgrade PlayerRadio to new getPids
435 Channel* toPlay = (*chanList)[currentChannel];
438 if (streamType == VDR::RADIO)
440 ((PlayerRadio*)player)->play(toPlay->apids[0].pid);
444 ((Player*)player)->play(toPlay->vpid, toPlay->apids[0].pid);
449 void VVideoLive::stop(int noRemoveVLB)
451 if (unavailable) return;
452 if (!noRemoveVLB && VLiveBanner::getInstance()) boxstack->remove(VLiveBanner::getInstance()); // if live banner is present, remove it. won't cause damage if its not present
454 if (streamType == VDR::RADIO)
456 ((PlayerRadio*)player)->stop();
460 ((Player*)player)->stop();
463 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay starts here due to time taken by plugin to stop");
464 vdr->stopStreaming();
465 if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; }
466 Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay ends here due to time taken by plugin to stop");
469 UINT VVideoLive::upChannel()
471 if (currentChannel == (chanList->size() - 1)) // at the end
472 return 0; // so go to start
474 return currentChannel + 1;
477 UINT VVideoLive::downChannel()
479 if (currentChannel == 0) // at the start
480 return chanList->size() - 1; // so go to end
482 return currentChannel - 1;
485 void VVideoLive::showEPG()
487 saveUnavailable = unavailable;
488 if (unavailable) showUnavailable(0);
490 if (VEpg::getInstance()) return; // already showing!
492 video->setMode(Video::QUARTER);
493 video->setPosition(170, 5); //TODO need to deal with 4:3 switching
495 VEpg* vepg = new VEpg(this, currentChannel, streamType);
499 boxstack->update(vepg);
502 void VVideoLive::toggleChopSides()
504 if (video->getTVsize() == Video::ASPECT16X9) return; // Means nothing for 16:9 TVs
506 if (videoMode == Video::NORMAL)
508 videoMode = Video::LETTERBOX;
509 video->setMode(Video::LETTERBOX);
513 videoMode = Video::NORMAL;
514 video->setMode(Video::NORMAL);