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;
218 if (Audio::getInstance()->supportsAc3())
220 for (UINT i = 0; i < channel->numDPids; i++)
222 AudioChannel* ac = new AudioChannel();
224 ac->name = new char[strlen(channel->dpids[i].name) + 1];
225 strcpy(ac->name, channel->dpids[i].name);
226 ac->pestype = channel->dpids[i].pid;
231 int audioChannelListSize = acl.size();
233 if (audioChannelListSize)
235 for(int i = 0; i < audioChannelListSize; i++)
237 AudioChannel* ac = acl[i];
238 sl.addOption(ac->name, (ULONG)ac, (ac->pestype == currentAudioChannel));
243 sl.addOption(tr("No audio channel data available"), 0, 1);
247 VAudioSelector::~VAudioSelector()
249 int audioChannelListSize = acl.size();
250 for(int i = 0; i < audioChannelListSize; i++)
252 delete acl[i]; // FIXME memory leak - nobody is deleting audio channel name?
258 Message* m = new Message();
261 m->message = Message::CHILD_CLOSE;
262 Command::getInstance()->postMessageNoLock(m);
265 void VAudioSelector::draw()
271 rectangle(0, 0, area.w, 30, Colour::TITLEBARBACKGROUND);
272 drawText(tr("Audio"), 45, 5, Colour::LIGHTTEXT);
274 sl.setBackgroundColour(backgroundColour);
278 int VAudioSelector::handleCommand(int command)
294 BoxStack::getInstance()->update(this);
296 Message* m = new Message();
299 m->message = Message::AUDIO_CHANGE_CHANNEL;
300 m->parameter = (((AudioChannel*)sl.getCurrentOptionData())->pestype &0xFFFF)|(((AudioChannel*)sl.getCurrentOptionData())->type &0xFF)<<16 ;
301 Command::getInstance()->postMessageNoLock(m);
305 case Remote::DF_DOWN:
311 BoxStack::getInstance()->update(this);
313 Message* m = new Message();
316 m->message = Message::AUDIO_CHANGE_CHANNEL;
317 m->parameter = (((AudioChannel*)sl.getCurrentOptionData())->pestype &0xFFFF)|(((AudioChannel*)sl.getCurrentOptionData())->type &0xFF)<<16 ;
318 Command::getInstance()->postMessageNoLock(m);
327 void VAudioSelector::processMessage(Message* m)
329 if (m->message == Message::MOUSE_MOVE)
331 UINT lastsel=sl.getCurrentOption();
332 if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
335 BoxStack::getInstance()->update(this);
336 if ((int)lastsel!=sl.getCurrentOption())
338 Message* m2 = new Message();
341 m2->message = Message::AUDIO_CHANGE_CHANNEL;
342 m2->parameter = (((AudioChannel*)sl.getCurrentOptionData())->pestype &0xFFFF)|(((AudioChannel*)sl.getCurrentOptionData())->type &0xFF)<<16 ;
343 Command::getInstance()->postMessageNoLock(m2);
347 else if (m->message == Message::MOUSE_LBDOWN)
349 if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
351 BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
354 { //check if press is outside this view! then simulate cancel
355 int x=(m->parameter>>16)-getScreenX();
356 int y=(m->parameter&0xFFFF)-getScreenY();
357 if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
359 BoxStack::getInstance()->handleCommand(Remote::BACK); //simulate cancel press