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)
28 vdr = VDR::getInstance();
29 viewman = ViewMan::getInstance();
33 unavailableView = NULL;
34 streamType = tstreamType;
35 if (streamType == VDR::RADIO) player = new PlayerVideo(Command::getInstance(), 0, 1);
36 else player = new PlayerVideo(Command::getInstance(), 0, 0);
40 Video* video = Video::getInstance();
41 create(video->getScreenWidth(), video->getScreenHeight());
42 Colour transparent(0, 0, 0, 0);
43 setBackgroundColour(transparent);
46 VVideoLive::~VVideoLive()
50 Video::getInstance()->setDefaultAspect();
53 VVideoLive* VVideoLive::getInstance()
58 void VVideoLive::draw()
63 int VVideoLive::handleCommand(int command)
69 if (!unavailable) player->play(); // do resync
77 if (unavailable) showUnavailable(0);
82 case Remote::CHANNELUP:
84 if (unavailable) showUnavailable(0);
91 case Remote::CHANNELDOWN:
93 if (unavailable) showUnavailable(0);
105 case Remote::ZERO ... Remote::NINE:
107 VChannelSelect* v = new VChannelSelect(this, command);
108 viewman->addNoLock(v);
109 // ViewMan::getInstance()->timedDelete(v, 4, 0);
118 void VVideoLive::processMessage(Message* m)
120 if (m->message == Message::CHANNEL_CHANGE)
122 // check channel number is valid
123 currentChannel = channelIndexFromNumber(m->parameter);
124 if (unavailable) showUnavailable(0);
128 else if (m->message == Message::CHANNEL_UP)
131 if (unavailable) showUnavailable(0);
135 vlb->setChannel((*chanList)[currentChannel]);
139 else if (m->message == Message::CHANNEL_DOWN)
142 if (unavailable) showUnavailable(0);
146 vlb->setChannel((*chanList)[currentChannel]);
150 else if (m->message == Message::STREAM_END)
152 Log::getInstance()->log("VVideoLive", Log::DEBUG, "streamEnd");
158 void VVideoLive::doBanner()
160 vlb = new VLiveBanner(this, (*chanList)[currentChannel]);
161 viewman->timedDelete(vlb, 4, 0);
163 Message* m = new Message();
166 m->message = Message::ADD_VIEW;
167 m->parameter = (ULONG)vlb;
169 viewman->postMessage(m);
172 void VVideoLive::showUnavailable(int active)
174 if (active == unavailable) return;
180 unavailableView = new VInfo();
181 unavailableView->create(400, 200);
182 if (Video::getInstance()->getFormat() == Video::PAL)
184 unavailableView->setScreenPos(170, 200);
188 unavailableView->setScreenPos(160, 150);
190 unavailableView->setTitleText((*chanList)[currentChannel]->name);
191 unavailableView->setMainText("\n Channel unavailable");
192 unavailableView->setDropThrough();
194 Message* m = new Message();
197 m->message = Message::ADD_VIEW;
198 m->parameter = (ULONG)unavailableView;
200 viewman->postMessage(m);
205 ViewMan::getInstance()->removeView(unavailableView, 1);
206 unavailableView = NULL;
210 void VVideoLive::setChannel(int number)
212 currentChannel = channelIndexFromNumber(number);
216 void VVideoLive::play(int noShowVLB)
220 int available = vdr->streamChannel((*chanList)[currentChannel]->number);
225 if (!noShowVLB) doBanner();
229 if (!noShowVLB) doBanner();
234 void VVideoLive::stop(int noRemoveVLB)
236 if (unavailable) return;
237 if (!noRemoveVLB) viewman->removeView(vlb, 1, 1); // if live banner is present, remove it. won't cause damage if its not present
240 vdr->stopStreaming();
243 int VVideoLive::upChannel()
245 if (currentChannel == (chanList->size() - 1)) return 0; // at the end
251 int VVideoLive::downChannel()
253 if (currentChannel == 0) return 0; // at the start
259 UINT VVideoLive::channelIndexFromNumber(int number)
261 for(UINT i = 0; i < chanList->size(); i++)
263 if ((*chanList)[i]->number == (UINT)number) return i;