2 Copyright 2006 Chris Tallon, Marten Richter
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 "vaudioselector.h"
34 VAudioSelector::VAudioSelector(void* tparent, bool* availableMpegAudioChannels,
35 bool* availableAc3AudioChannels, int currentAudioChannel, RecInfo* recInfo)
37 Log::getInstance()->log("VAS", Log::DEBUG, "%i", currentAudioChannel);
46 sl.setPosition(40, 30);
47 sl.setSize(area.w - 45, area.h - 30);
50 // Load data from availableAudioChannels, currentAudioChannel and recInfo
54 for (i = 0; i < PES_AUDIO_MAXCHANNELS; i++)
56 if (availableMpegAudioChannels[i])
58 AudioChannel* ac = new AudioChannel();
61 ac->pestype = PES_AUDIO_START + i;
65 if (availableAc3AudioChannels != NULL)
67 for (i = 0; i < PES_AUDIO_AC3_MAXCHANNELS; i++)
69 if (availableAc3AudioChannels[i])
71 AudioChannel* ac = new AudioChannel();
74 ac->pestype = PES_AUDIO_AC3_START + i;
80 unsigned char numchan_recinfo = recInfo->numComponents;
81 unsigned char numchan_siz = acl.size();
82 int mp_audcounter = 0;
86 for (i = 0; i < numchan_siz; i++)
88 AudioChannel* ac = acl[i];
103 for (i = 0; i < numchan_recinfo; i++)
105 if (recInfo->streams[i] != 2) continue; //not an audio component
106 type = recInfo->types[i];
107 lang = recInfo->languages[i];
108 description = recInfo->descriptions[i];
109 AudioChannel* ac = NULL;
114 case 1: //mpaudio mono
115 case 3: //mpaudio stereo
116 if (mp_audcounter < numchan_siz) ac = acl[mp_audcounter];
120 if (ac3_counter + ac3_offset < numchan_siz) ac = acl[ac3_counter + ac3_offset];
127 if (ac->type == type_int)
129 if (description && (strlen(description) > 0))
131 ac->name = new char[strlen(description)+1];
132 strcpy(ac->name, description);
134 else if (lang && (strlen(lang) > 0))
136 ac->name = new char[strlen(lang)+1];
137 strcpy(ac->name, lang);
155 char tempString[300];
156 int audioChannelListSize = acl.size();
158 if (audioChannelListSize)
160 for(i = 0; i < audioChannelListSize; i++)
162 AudioChannel* ac = acl[i];
166 sl.addOption(ac->name, (ULONG)ac, (ac->pestype == currentAudioChannel));
172 SNPRINTF(tempString, 299, "%lu", (ULONG)(ac->pestype - PES_AUDIO_START));
174 else if (ac->type==1)
176 SNPRINTF(tempString, 299, "ac3 %lu", (ULONG)(ac->pestype - PES_AUDIO_AC3_START));
180 SNPRINTF(tempString, 299, "unknown");
182 sl.addOption(tempString, (ULONG)ac, (ac->pestype == currentAudioChannel));
188 sl.addOption(tr("No audio channel data available"), 0, 1);
192 VAudioSelector::VAudioSelector(void* tparent, Channel* channel, int currentAudioChannel)
201 sl.setPosition(40, 30);
202 sl.setSize(area.w - 45, area.h - 30);
205 // Load data from availableAudioChannels, currentAudioChannel and recInfo
207 for (UINT i = 0; i < channel->numAPids; i++)
209 AudioChannel* ac = new AudioChannel();
211 ac->name = new char[strlen(channel->apids[i].name) + 1];
212 strcpy(ac->name, channel->apids[i].name);
213 ac->pestype = channel->apids[i].pid;
217 int audioChannelListSize = acl.size();
219 if (audioChannelListSize)
221 for(int i = 0; i < audioChannelListSize; i++)
223 AudioChannel* ac = acl[i];
224 sl.addOption(ac->name, (ULONG)ac, (ac->pestype == currentAudioChannel));
229 sl.addOption(tr("No audio channel data available"), 0, 1);
233 VAudioSelector::~VAudioSelector()
235 int audioChannelListSize = acl.size();
236 for(int i = 0; i < audioChannelListSize; i++)
238 delete acl[i]; // FIXME memory leak - nobody is deleting audio channel name?
244 Message* m = new Message();
247 m->message = Message::CHILD_CLOSE;
248 Command::getInstance()->postMessageNoLock(m);
251 void VAudioSelector::draw()
257 rectangle(0, 0, area.w, 30, Colour::TITLEBARBACKGROUND);
258 drawText(tr("Audio"), 45, 5, Colour::LIGHTTEXT);
260 sl.setBackgroundColour(backgroundColour);
264 int VAudioSelector::handleCommand(int command)
280 BoxStack::getInstance()->update(this);
282 Message* m = new Message();
285 m->message = Message::AUDIO_CHANGE_CHANNEL;
286 m->parameter = ((AudioChannel*)sl.getCurrentOptionData())->pestype;
287 Command::getInstance()->postMessageNoLock(m);
291 case Remote::DF_DOWN:
297 BoxStack::getInstance()->update(this);
299 Message* m = new Message();
302 m->message = Message::AUDIO_CHANGE_CHANNEL;
303 m->parameter = ((AudioChannel*)sl.getCurrentOptionData())->pestype;
304 Command::getInstance()->postMessageNoLock(m);
313 void VAudioSelector::processMessage(Message* m)
315 if (m->message == Message::MOUSE_MOVE)
317 if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
320 BoxStack::getInstance()->update(this);
323 else if (m->message == Message::MOUSE_LBDOWN)
325 if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
327 BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
330 { //check if press is outside this view! then simulate cancel
331 int x=(m->parameter>>16)-getScreenX();
332 int y=(m->parameter&0xFFFF)-getScreenY();
333 if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
335 BoxStack::getInstance()->handleCommand(Remote::BACK); //simulate cancel press