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 // FIXME memory leak - nobody is deleting audio channel name? // try:
253 delete[] acl[i]->name;
254 Log::getInstance()->log("VAudioSelector", Log::DEBUG, "Deleted char[] on close");
261 Message* m = new Message();
264 m->message = Message::CHILD_CLOSE;
265 Command::getInstance()->postMessageNoLock(m);
268 void VAudioSelector::draw()
274 rectangle(0, 0, area.w, 30, Colour::TITLEBARBACKGROUND);
275 drawText(tr("Audio"), 45, 5, Colour::LIGHTTEXT);
277 sl.setBackgroundColour(backgroundColour);
281 int VAudioSelector::handleCommand(int command)
297 BoxStack::getInstance()->update(this);
299 Message* m = new Message();
302 m->message = Message::AUDIO_CHANGE_CHANNEL;
303 m->parameter = (((AudioChannel*)sl.getCurrentOptionData())->pestype &0xFFFF)|(((AudioChannel*)sl.getCurrentOptionData())->type &0xFF)<<16 ;
304 Command::getInstance()->postMessageNoLock(m);
308 case Remote::DF_DOWN:
314 BoxStack::getInstance()->update(this);
316 Message* m = new Message();
319 m->message = Message::AUDIO_CHANGE_CHANNEL;
320 m->parameter = (((AudioChannel*)sl.getCurrentOptionData())->pestype &0xFFFF)|(((AudioChannel*)sl.getCurrentOptionData())->type &0xFF)<<16 ;
321 Command::getInstance()->postMessageNoLock(m);
330 void VAudioSelector::processMessage(Message* m)
332 if (m->message == Message::MOUSE_MOVE)
334 UINT lastsel=sl.getCurrentOption();
335 if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
338 BoxStack::getInstance()->update(this);
339 if ((int)lastsel!=sl.getCurrentOption())
341 Message* m2 = new Message();
344 m2->message = Message::AUDIO_CHANGE_CHANNEL;
345 m2->parameter = (((AudioChannel*)sl.getCurrentOptionData())->pestype &0xFFFF)|(((AudioChannel*)sl.getCurrentOptionData())->type &0xFF)<<16 ;
346 Command::getInstance()->postMessageNoLock(m2);
350 else if (m->message == Message::MOUSE_LBDOWN)
352 if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
354 BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
357 { //check if press is outside this view! then simulate cancel
358 int x=(m->parameter>>16)-getScreenX();
359 int y=(m->parameter&0xFFFF)-getScreenY();
360 if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
362 BoxStack::getInstance()->handleCommand(Remote::BACK); //simulate cancel press