]> git.vomp.tv Git - vompclient.git/blob - vvideolive.cc
Another stab at radio support, fix for chasing playback
[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(List* tchanList, ULONG tstreamType)
24 {
25   vdr = VDR::getInstance();
26   viewman = ViewMan::getInstance();
27   chanList = tchanList;
28   currentChannel = NULL;
29   unavailable = 0;
30   unavailableView = NULL;
31   streamType = tstreamType;
32   if (streamType == VDR::VIDEO)
33   {
34     player = new PlayerVideo(NULL, 0);
35   }
36   else
37   {
38     player = new PlayerRadio();
39   }
40   player->init();
41
42   Video* video = Video::getInstance();
43   setDimensions(video->getScreenHeight(), video->getScreenWidth());
44   Colour transparent(0, 0, 0, 0);
45   setBackgroundColour(transparent);
46 }
47
48 VVideoLive::~VVideoLive()
49 {
50   delete player;
51 }
52
53 void VVideoLive::draw()
54 {
55   View::draw();
56 }
57
58 int VVideoLive::handleCommand(int command)
59 {
60   switch(command)
61   {
62     case Remote::PLAY:
63     {
64       if (!unavailable) player->play(); // do resync
65       return 2;
66     }
67
68     case Remote::STOP:
69     case Remote::BACK:
70     case Remote::MENU:
71     {
72       if (unavailable) showUnavailable(0);
73       else stop();
74       return 4;
75     }
76     case Remote::DF_UP:
77     case Remote::UP:
78     {
79       if (unavailable) showUnavailable(0);
80       else stop();
81       upChannel();
82       play();
83       return 2;
84     }
85     case Remote::DF_DOWN:
86     case Remote::DOWN:
87     {
88       if (unavailable) showUnavailable(0);
89       else stop();
90       downChannel();
91       play();
92       return 2;
93     }
94     case Remote::OK:
95     {
96       if (!unavailable) doBanner();
97       return 2;
98     }
99
100     case Remote::ZERO ... Remote::NINE:
101     {
102       VChannelSelect* v = new VChannelSelect(this, command);
103       viewman->addNoLock(v);
104 //      ViewMan::getInstance()->timedDelete(v, 4, 0);
105       v->draw();
106       v->show();
107     }
108   }
109
110   return 1;
111 }
112
113 void VVideoLive::processMessage(Message* m)
114 {
115   if (m->message == Message::CHANNEL_CHANGE)
116   {
117     // check channel number is valid
118     currentChannel = channelFromNumber(m->parameter);
119     if (!currentChannel) return; // this should never happen
120     if (unavailable) showUnavailable(0);
121     else stop();
122     play();
123   }
124 }
125
126 void VVideoLive::doBanner()
127 {
128   VLiveBanner* v = new VLiveBanner(currentChannel);
129   viewman->timedDelete(v, 4, 0);
130
131   Message* m = new Message();
132   m->from = this;
133   m->to = viewman;
134   m->message = Message::ADD_VIEW;
135   m->parameter = (ULONG)v;
136
137   viewman->postMessage(m);
138 }
139
140 void VVideoLive::showUnavailable(int active)
141 {
142   if (active == unavailable) return;
143
144   if (active)
145   {
146     unavailable = 1;
147
148     unavailableView = new VInfo();
149     unavailableView->setDimensions(200, 400);
150     if (Video::getInstance()->getFormat() == Video::PAL)
151     {
152       unavailableView->setScreenPos(170, 200);
153     }
154     else
155     {
156       unavailableView->setScreenPos(160, 150);
157     }
158     unavailableView->setTitleText(currentChannel->name);
159     unavailableView->setMainText("\n                    Channel unavailable");
160     unavailableView->setDropThrough();
161
162     Message* m = new Message();
163     m->from = this;
164     m->to = viewman;
165     m->message = Message::ADD_VIEW;
166     m->parameter = (ULONG)unavailableView;
167
168     viewman->postMessage(m);
169   }
170   else
171   {
172     unavailable = 0;
173     ViewMan::getInstance()->removeView(unavailableView, 1);
174     unavailableView = NULL;
175   }
176 }
177
178 void VVideoLive::setChannel(int number)
179 {
180   currentChannel = channelFromNumber(number);
181   if (!currentChannel) return; // should never happen
182   play();
183 }
184
185 void VVideoLive::play()
186 {
187   showUnavailable(0);
188
189   int available = vdr->streamChannel(currentChannel->number);
190
191   if (!available)
192   {
193     showUnavailable(1);
194   }
195   else
196   {
197     doBanner();
198     player->play();
199   }
200 }
201
202 void VVideoLive::stop()
203 {
204   if (unavailable) return;
205   player->stop();
206   vdr->stopStreaming();
207 }
208
209 void VVideoLive::upChannel()
210 {
211   Channel* channel;
212   for(chanList->reset(); (channel = (Channel*)chanList->getCurrent()); chanList->next())
213   {
214     if (channel == currentChannel)
215     {
216       chanList->next();
217       channel = (Channel*)chanList->getCurrent();
218       if (!channel) return;
219       currentChannel = channel;
220     }
221   }
222 }
223
224 void VVideoLive::downChannel()
225 {
226   Channel* channel;
227   Channel* prevChannel = NULL;
228   for(chanList->reset(); (channel = (Channel*)chanList->getCurrent()); chanList->next())
229   {
230     if (channel == currentChannel)
231     {
232       if (!prevChannel) return;
233       currentChannel = prevChannel;
234     }
235     prevChannel = channel;
236   }
237 }
238
239 Channel* VVideoLive::channelFromNumber(int number)
240 {
241   Channel* channel;
242   for(chanList->reset(); (channel = (Channel*)chanList->getCurrent()); chanList->next())
243   {
244     if (channel->number == (UINT)number) return channel;
245   }
246   return NULL;
247 }
248