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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "vaudioselector.h"
35 VAudioSelector::VAudioSelector(void* tparent, bool* availableMpegAudioChannels,
36 bool* availableAc3AudioChannels, int currentAudioChannel, RecInfo* recInfo)
38 Log::getInstance()->log("VAS", Log::DEBUG, "%i", currentAudioChannel);
47 sl.setPosition(40, 30);
48 sl.setSize(area.w - 45, area.h - 30);
51 // Load data from availableAudioChannels, currentAudioChannel and recInfo
55 for (i = 0; i < PES_AUDIO_MAXCHANNELS; i++)
57 if (availableMpegAudioChannels[i])
59 AudioChannel* ac = new AudioChannel();
62 ac->pestype = PES_AUDIO_START + i;
66 if (availableAc3AudioChannels != NULL)
68 for (i = 0; i < PES_AUDIO_AC3_MAXCHANNELS; i++)
70 if (availableAc3AudioChannels[i])
72 AudioChannel* ac = new AudioChannel();
75 ac->pestype = PES_AUDIO_AC3_START + i;
81 unsigned char numchan_recinfo = recInfo->numComponents;
82 unsigned char numchan_siz = acl.size();
83 int mp_audcounter = 0;
87 for (i = 0; i < numchan_siz; i++)
89 AudioChannel* ac = acl[i];
104 for (i = 0; i < numchan_recinfo; i++)
106 if (recInfo->streams[i] != 2) continue; //not an audio component
107 type = recInfo->types[i];
108 lang = recInfo->languages[i];
109 description = recInfo->descriptions[i];
110 AudioChannel* ac = NULL;
115 case 1: //mpaudio mono
116 case 3: //mpaudio stereo
117 if (mp_audcounter < numchan_siz) ac = acl[mp_audcounter];
121 if (ac3_counter + ac3_offset < numchan_siz) ac = acl[ac3_counter + ac3_offset];
128 if (ac->type == type_int)
130 if (description && (strlen(description) > 0))
132 ac->name = new char[strlen(description)+1];
133 strcpy(ac->name, description);
135 else if (lang && (strlen(lang) > 0))
137 ac->name = new char[strlen(lang)+1];
138 strcpy(ac->name, lang);
156 char tempString[300];
157 int audioChannelListSize = acl.size();
159 if (audioChannelListSize)
161 for(i = 0; i < audioChannelListSize; i++)
163 AudioChannel* ac = acl[i];
167 sl.addOption(ac->name, (ULONG)ac, (ac->pestype == currentAudioChannel));
173 SNPRINTF(tempString, 299, "%lu", (ULONG)(ac->pestype - PES_AUDIO_START));
175 else if (ac->type==1)
177 SNPRINTF(tempString, 299, "ac3 %lu", (ULONG)(ac->pestype - PES_AUDIO_AC3_START));
181 SNPRINTF(tempString, 299, "unknown");
183 sl.addOption(tempString, (ULONG)ac, (ac->pestype == currentAudioChannel));
189 sl.addOption(tr("No audio channel data available"), 0, 1);
193 VAudioSelector::VAudioSelector(void* tparent, Channel* channel, int currentAudioChannel)
202 sl.setPosition(40, 30);
203 sl.setSize(area.w - 45, area.h - 30);
206 // Load data from availableAudioChannels, currentAudioChannel and recInfo
208 for (UINT i = 0; i < channel->numAPids; i++)
210 AudioChannel* ac = new AudioChannel();
212 ac->name = new char[strlen(channel->apids[i].name) + 1];
213 strcpy(ac->name, channel->apids[i].name);
214 ac->pestype = channel->apids[i].pid;
217 if (Audio::getInstance()->supportsAc3()) {
218 for (UINT i = 0; i < channel->numDPids; i++)
220 AudioChannel* ac = new AudioChannel();
222 ac->name = new char[strlen(channel->dpids[i].name) + 1];
223 strcpy(ac->name, channel->dpids[i].name);
224 ac->pestype = channel->dpids[i].pid;
229 int audioChannelListSize = acl.size();
231 if (audioChannelListSize)
233 for(int i = 0; i < audioChannelListSize; i++)
235 AudioChannel* ac = acl[i];
236 sl.addOption(ac->name, (ULONG)ac, (ac->pestype == currentAudioChannel));
241 sl.addOption(tr("No audio channel data available"), 0, 1);
245 VAudioSelector::~VAudioSelector()
247 int audioChannelListSize = acl.size();
248 for(int i = 0; i < audioChannelListSize; i++)
250 delete acl[i]; // FIXME memory leak - nobody is deleting audio channel name?
256 Message* m = new Message();
259 m->message = Message::CHILD_CLOSE;
260 Command::getInstance()->postMessageNoLock(m);
263 void VAudioSelector::draw()
269 rectangle(0, 0, area.w, 30, Colour::TITLEBARBACKGROUND);
270 drawText(tr("Audio"), 45, 5, Colour::LIGHTTEXT);
272 sl.setBackgroundColour(backgroundColour);
276 int VAudioSelector::handleCommand(int command)
292 BoxStack::getInstance()->update(this);
294 Message* m = new Message();
297 m->message = Message::AUDIO_CHANGE_CHANNEL;
298 m->parameter = (((AudioChannel*)sl.getCurrentOptionData())->pestype &0xFFFF)|(((AudioChannel*)sl.getCurrentOptionData())->type &0xFF)<<16 ;
299 Command::getInstance()->postMessageNoLock(m);
303 case Remote::DF_DOWN:
309 BoxStack::getInstance()->update(this);
311 Message* m = new Message();
314 m->message = Message::AUDIO_CHANGE_CHANNEL;
315 m->parameter = (((AudioChannel*)sl.getCurrentOptionData())->pestype &0xFFFF)|(((AudioChannel*)sl.getCurrentOptionData())->type &0xFF)<<16 ;
316 Command::getInstance()->postMessageNoLock(m);
325 void VAudioSelector::processMessage(Message* m)
327 if (m->message == Message::MOUSE_MOVE)
329 UINT lastsel=sl.getCurrentOption();
330 if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
333 BoxStack::getInstance()->update(this);
334 if ((int)lastsel!=sl.getCurrentOption())
336 Message* m2 = new Message();
339 m2->message = Message::AUDIO_CHANGE_CHANNEL;
340 m2->parameter = (((AudioChannel*)sl.getCurrentOptionData())->pestype &0xFFFF)|(((AudioChannel*)sl.getCurrentOptionData())->type &0xFF)<<16 ;
341 Command::getInstance()->postMessageNoLock(m2);
345 else if (m->message == Message::MOUSE_LBDOWN)
347 if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
349 BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
352 { //check if press is outside this view! then simulate cancel
353 int x=(m->parameter>>16)-getScreenX();
354 int y=(m->parameter&0xFFFF)-getScreenY();
355 if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
357 BoxStack::getInstance()->handleCommand(Remote::BACK); //simulate cancel press