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