]> git.vomp.tv Git - vompclient.git/blob - vvideolive.cc
Widescreen version 2...
[vompclient.git] / vvideolive.cc
1 /*
2     Copyright 2004-2005 Chris Tallon
3
4     This file is part of VOMP.
5
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.
10
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.
15
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
19 */
20
21 #include "vvideolive.h"
22
23 VVideoLive* VVideoLive::instance = NULL;
24
25 VVideoLive::VVideoLive(ChannelList* tchanList, ULONG tstreamType)
26 {
27   instance = this;
28   vdr = VDR::getInstance();
29   viewman = ViewMan::getInstance();
30   chanList = tchanList;
31   currentChannel = 0;
32   unavailable = 0;
33   unavailableView = NULL;
34   streamType = tstreamType;
35   if (streamType == VDR::VIDEO)
36   {
37     player = new PlayerVideo(Command::getInstance(), 0);
38   }
39   else
40   {
41     player = new PlayerRadio();
42   }
43   player->init();
44
45   Video* video = Video::getInstance();
46   setDimensions(video->getScreenWidth(), video->getScreenHeight());
47   Colour transparent(0, 0, 0, 0);
48   setBackgroundColour(transparent);
49 }
50
51 VVideoLive::~VVideoLive()
52 {
53   delete player;
54   instance = NULL;
55   Video::getInstance()->setDefaultAspect();
56 }
57
58 VVideoLive* VVideoLive::getInstance()
59 {
60   return instance;
61 }
62
63 void VVideoLive::draw()
64 {
65   View::draw();
66 }
67
68 int VVideoLive::handleCommand(int command)
69 {
70   switch(command)
71   {
72     case Remote::PLAY:
73     {
74       if (!unavailable) player->play(); // do resync
75       return 2;
76     }
77
78     case Remote::STOP:
79     case Remote::BACK:
80     case Remote::MENU:
81     {
82       if (unavailable) showUnavailable(0);
83       else stop();
84       return 4;
85     }
86     case Remote::DF_UP:
87     case Remote::CHANNELUP:
88     {
89       if (unavailable) showUnavailable(0);
90       else stop();
91       upChannel();
92       play();
93       return 2;
94     }
95     case Remote::DF_DOWN:
96     case Remote::CHANNELDOWN:
97     {
98       if (unavailable) showUnavailable(0);
99       else stop();
100       downChannel();
101       play();
102       return 2;
103     }
104     case Remote::OK:
105     {
106       doBanner();
107       return 2;
108     }
109
110     case Remote::ZERO ... Remote::NINE:
111     {
112       VChannelSelect* v = new VChannelSelect(this, command);
113       viewman->addNoLock(v);
114 //      ViewMan::getInstance()->timedDelete(v, 4, 0);
115       v->draw();
116       v->show();
117     }
118   }
119
120   return 1;
121 }
122
123 void VVideoLive::processMessage(Message* m)
124 {
125   if (m->message == Message::CHANNEL_CHANGE)
126   {
127     // check channel number is valid
128     currentChannel = channelIndexFromNumber(m->parameter);
129     if (unavailable) showUnavailable(0);
130     else stop();
131     play();
132   }
133   else if (m->message == Message::CHANNEL_UP)
134   {
135     // from vlivebanner
136     if (unavailable) showUnavailable(0);
137     else stop(1);
138     upChannel();
139     play(1);
140     vlb->setChannel((*chanList)[currentChannel]);
141     vlb->draw();
142     vlb->show();
143   }
144   else if (m->message == Message::CHANNEL_DOWN)
145   {
146     // from vlivebanner
147     if (unavailable) showUnavailable(0);
148     else stop(1);
149     downChannel();
150     play(1);
151     vlb->setChannel((*chanList)[currentChannel]);
152     vlb->draw();
153     vlb->show();
154   }
155   else if (m->message == Message::STREAM_END)
156   {
157     Log::getInstance()->log("VVideoLive", Log::DEBUG, "streamEnd");
158     stop();
159     play(1);
160   }
161 }
162
163 void VVideoLive::doBanner()
164 {
165   vlb = new VLiveBanner(this, (*chanList)[currentChannel]);
166   viewman->timedDelete(vlb, 4, 0);
167
168   Message* m = new Message();
169   m->from = this;
170   m->to = viewman;
171   m->message = Message::ADD_VIEW;
172   m->parameter = (ULONG)vlb;
173
174   viewman->postMessage(m);
175 }
176
177 void VVideoLive::showUnavailable(int active)
178 {
179   if (active == unavailable) return;
180
181   if (active)
182   {
183     unavailable = 1;
184
185     unavailableView = new VInfo();
186     unavailableView->setDimensions(400, 200);
187     if (Video::getInstance()->getFormat() == Video::PAL)
188     {
189       unavailableView->setScreenPos(170, 200);
190     }
191     else
192     {
193       unavailableView->setScreenPos(160, 150);
194     }
195     unavailableView->setTitleText((*chanList)[currentChannel]->name);
196     unavailableView->setMainText("\n                    Channel unavailable");
197     unavailableView->setDropThrough();
198
199     Message* m = new Message();
200     m->from = this;
201     m->to = viewman;
202     m->message = Message::ADD_VIEW;
203     m->parameter = (ULONG)unavailableView;
204
205     viewman->postMessage(m);
206   }
207   else
208   {
209     unavailable = 0;
210     ViewMan::getInstance()->removeView(unavailableView, 1);
211     unavailableView = NULL;
212   }
213 }
214
215 void VVideoLive::setChannel(int number)
216 {
217   currentChannel = channelIndexFromNumber(number);
218   play();
219 }
220
221 void VVideoLive::play(int noShowVLB)
222 {
223   showUnavailable(0);
224
225   int available = vdr->streamChannel((*chanList)[currentChannel]->number);
226
227   if (!available)
228   {
229     showUnavailable(1);
230     if (!noShowVLB) doBanner();
231   }
232   else
233   {
234     if (!noShowVLB) doBanner();
235     player->play();
236   }
237 }
238
239 void VVideoLive::stop(int noRemoveVLB)
240 {
241   if (unavailable) return;
242   if (!noRemoveVLB) viewman->removeView(vlb, 1, 1); // if live banner is present, remove it. won't cause damage if its not present
243
244   player->stop();
245   vdr->stopStreaming();
246 }
247
248 int VVideoLive::upChannel()
249 {
250   if (currentChannel == (chanList->size() - 1)) return 0; // at the end
251
252   ++currentChannel;
253   return 1;
254 }
255
256 int VVideoLive::downChannel()
257 {
258   if (currentChannel == 0) return 0; // at the start
259
260   --currentChannel;
261   return 1;
262 }
263
264 UINT VVideoLive::channelIndexFromNumber(int number)
265 {
266   for(UINT i = 0; i < chanList->size(); i++)
267   {
268     if ((*chanList)[i]->number == (UINT)number) return i;
269   }
270   return 0;
271 }
272