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"
37 VAudioSelector::VAudioSelector(void* tparent, bool* availableMpegAudioChannels,
38 bool* availableAc3AudioChannels, int currentAudioChannel, bool *availableSubtitleChannels,int*ttxtpages,
39 int currentSubtitleChannel,int currentSubtitleType, RecInfo* recInfo)
41 Log::getInstance()->log("VAS", Log::DEBUG, "%i", currentAudioChannel);
48 editsubtitles = false;
51 if (availableSubtitleChannels != NULL) {
52 for (i = 0; i < PES_DVBSUBTITLE_MAXCHANNELS; i++) {
53 if (availableSubtitleChannels[i])
55 AudioSubtitleChannel* sc = new AudioSubtitleChannel();
56 sc->type = 0x10;//dvbsubtitle
58 sc->pestype = PES_DVBSUBTITLE_START+ i;
64 AudioSubtitleChannel* sc = new AudioSubtitleChannel();
65 int length=strlen(tr("TTxt:"))+1+1+3+1;
66 sc->type = 0x11;//Teletxt
67 sc->name = new char[length];
68 SNPRINTF(sc->name,length,"%s %3x",tr("TTxt:"),ttxtpages[i]);
69 sc->pestype = ttxtpages[i];
76 AudioSubtitleChannel* sc = new AudioSubtitleChannel();
77 sc->type = 0xFF;//special
78 sc->name = new char[strlen(tr("No Subtitles"))+1];
79 strcpy(sc->name,tr("No Subtitles"));
81 scl.insert(scl.begin(),sc);
95 asl.setPosition(40, 30);
96 asl.setSize(200 - 45, area.h - 30);
100 ssl.setPosition(200+40,30);
101 ssl.setSize(200 - 45, area.h - 30);
105 // Load data from availableAudioChannels, currentAudioChannel and recInfo
108 for (i = 0; i < PES_AUDIO_MAXCHANNELS; i++)
110 if (availableMpegAudioChannels[i])
112 AudioSubtitleChannel* ac = new AudioSubtitleChannel();
115 ac->pestype = PES_AUDIO_START + i;
119 if (availableAc3AudioChannels != NULL)
121 for (i = 0; i < PES_AUDIO_AC3_MAXCHANNELS; i++)
123 if (availableAc3AudioChannels[i])
125 AudioSubtitleChannel* ac = new AudioSubtitleChannel();
128 ac->pestype = PES_AUDIO_AC3_START + i;
139 unsigned char numchan_recinfo = recInfo->numComponents;
140 unsigned char numchan_siz = acl.size();
141 unsigned char numchan_subtitles_siz = scl.size();
142 int mp_audcounter = 0;
145 int dvb_subcounter = 1;
147 for (i = 0; i < numchan_siz; i++)
149 AudioSubtitleChannel* ac = acl[i];
164 for (i = 0; i < numchan_recinfo; i++)
167 type = recInfo->types[i];
168 lang = recInfo->languages[i];
169 description = recInfo->descriptions[i];
170 AudioSubtitleChannel* ac = NULL;
172 if (recInfo->streams[i] == 2) {
175 case 1: //mpaudio mono
176 case 3: //mpaudio stereo
177 if (mp_audcounter < numchan_siz) ac = acl[mp_audcounter];
181 if (ac3_counter + ac3_offset < numchan_siz) ac = acl[ac3_counter + ac3_offset];
185 } else if (recInfo->streams[i] == 3){
189 if (dvb_subcounter < numchan_subtitles_siz) ac = scl[dvb_subcounter];
193 } else continue; //neither audio nor subtitle
197 if (ac->type == type_int)
199 if (description && (strlen(description) > 0))
201 ac->name = new char[strlen(description)+1];
202 strcpy(ac->name, description);
204 else if (lang && (strlen(lang) > 0))
206 ac->name = new char[strlen(lang)+1];
207 strcpy(ac->name, lang);
228 char tempString[300];
229 int audioChannelListSize = acl.size();
231 if (audioChannelListSize)
233 for(i = 0; i < audioChannelListSize; i++)
235 AudioSubtitleChannel* ac = acl[i];
239 asl.addOption(ac->name, (ULONG)ac, (ac->pestype == currentAudioChannel));
245 SNPRINTF(tempString, 299, "%lu", (ULONG)(ac->pestype - PES_AUDIO_START));
247 else if (ac->type==1)
249 SNPRINTF(tempString, 299, "ac3 %lu", (ULONG)(ac->pestype - PES_AUDIO_AC3_START));
253 SNPRINTF(tempString, 299, "unknown");
255 asl.addOption(tempString, (ULONG)ac, (ac->pestype == currentAudioChannel));
261 asl.addOption(tr("No audio channel data available"), 0, 1);
264 int subtitlesChannelListSize = scl.size();
267 ssl.setDarkSelOption(true);
268 for(i = 0; i < subtitlesChannelListSize; i++)
270 AudioSubtitleChannel* sc = scl[i];
272 if (sc->pestype == currentSubtitleChannel && sc->type ==currentSubtitleType) selected=true;
276 ssl.addOption(sc->name, (ULONG)sc, selected);
282 SNPRINTF(tempString, 299, "%lu", (ULONG)(sc->pestype - PES_DVBSUBTITLE_START));
286 SNPRINTF(tempString, 299, "unknown");
288 ssl.addOption(tempString, (ULONG)sc, selected);
295 VAudioSelector::VAudioSelector(void* tparent, Channel* channel, int currentAudioChannel,int currentSubtitletype,int currentSubtitleChannel,int*ttxtpages)
300 editsubtitles = false;
304 for (i = 0; i < channel->numSPids; i++)
306 AudioSubtitleChannel* sc = new AudioSubtitleChannel();
308 sc->name = new char[strlen(channel->spids[i].desc) + 1];
309 strcpy(sc->name, channel->spids[i].desc);
310 sc->pestype = channel->spids[i].pid;
315 if (ttxtpages[i]>0) {
316 AudioSubtitleChannel* sc = new AudioSubtitleChannel();
317 int length=strlen(tr("TTxt:"))+1+1+3+1;
318 sc->type = 0x11;//Teletxt
319 sc->name = new char[length];
320 SNPRINTF(sc->name,length,"%s %3x",tr("TTxt:"),ttxtpages[i]);
321 sc->pestype = ttxtpages[i];
329 AudioSubtitleChannel* sc = new AudioSubtitleChannel();
330 sc->type = 0xFF;//special
331 sc->name = new char[strlen(tr("No Subtitles"))+1];
332 strcpy(sc->name,tr("No Subtitles"));
334 scl.insert(scl.begin(),sc);
348 asl.setPosition(40, 30);
349 asl.setSize(200 - 45, area.h - 30);
353 ssl.setPosition(200+40,30);
354 ssl.setSize(200 - 45, area.h - 30);
358 // Load data from availableAudioChannels, currentAudioChannel and recInfo
360 for (i = 0; i < channel->numAPids; i++)
362 AudioSubtitleChannel* ac = new AudioSubtitleChannel();
364 ac->name = new char[strlen(channel->apids[i].desc) + 1];
365 strcpy(ac->name, channel->apids[i].desc);
366 ac->pestype = channel->apids[i].pid;
367 ac->streamtype=channel->apids[i].type;
368 if (Audio::getInstance()->streamTypeSupported(ac->streamtype))acl.push_back(ac);
371 if (Audio::getInstance()->supportsAc3())
373 for (i = 0; i < channel->numDPids; i++)
375 AudioSubtitleChannel* ac = new AudioSubtitleChannel();
377 ac->name = new char[strlen(channel->dpids[i].desc) + 1];
378 strcpy(ac->name, channel->dpids[i].desc);
379 ac->pestype = channel->dpids[i].pid;
380 ac->streamtype=channel->dpids[i].type;
381 if (Audio::getInstance()->streamTypeSupported(ac->streamtype))acl.push_back(ac);
385 int audioChannelListSize = acl.size();
387 if (audioChannelListSize)
389 for(int j = 0; j < audioChannelListSize; j++)
391 AudioSubtitleChannel* ac = acl[j];
392 asl.addOption(ac->name, (ULONG)ac, (ac->pestype == currentAudioChannel));
397 asl.addOption(tr("No audio channel data available"), 0, 1);
399 int subtitlesChannelListSize = scl.size();
402 ssl.setDarkSelOption(true);
403 for(int j = 0; j < subtitlesChannelListSize; j++)
405 AudioSubtitleChannel* sc = scl[j];
407 if ((sc->type==currentSubtitletype) && (sc->pestype == currentSubtitleChannel)) selected=true;
408 ssl.addOption(sc->name, (ULONG)sc, selected);
414 VAudioSelector::~VAudioSelector()
416 int audioChannelListSize = acl.size();
417 for(int i = 0; i < audioChannelListSize; i++)
419 // FIXME memory leak - nobody is deleting audio channel name? // try:
420 delete[] acl[i]->name;
421 Log::getInstance()->log("VAudioSelector", Log::DEBUG, "Deleted char[] on close");
428 int subtitleChannelListSize = scl.size();
429 for(int i = 0; i < subtitleChannelListSize; i++)
431 // FIXME memory leak - nobody is deleting audio channel name? // try:
432 delete[] scl[i]->name;
433 Log::getInstance()->log("VAudioSelector", Log::DEBUG, "Deleted char[] on close");
440 Message* m = new Message();
443 m->message = Message::CHILD_CLOSE;
444 Command::getInstance()->postMessageNoLock(m);
447 void VAudioSelector::draw()
453 rectangle(0, 0, area.w, 30, DrawStyle::TITLEBARBACKGROUND);
454 drawText(tr("Audio"), 45, 5, DrawStyle::LIGHTTEXT);
456 drawText(tr("Subtitles"), 45+200, 5, DrawStyle::LIGHTTEXT);
457 ssl.setBackgroundColour(backgroundColour);
461 asl.setBackgroundColour(backgroundColour);
467 int VAudioSelector::handleCommand(int command)
483 BoxStack::getInstance()->update(this);
484 Message* m = new Message();
487 m->message = Message::SUBTITLE_CHANGE_CHANNEL;
488 m->parameter = (((AudioSubtitleChannel*)ssl.getCurrentOptionData())->pestype &0xFFFF)|(((AudioSubtitleChannel*)ssl.getCurrentOptionData())->type &0xFF)<<16 ;
489 Command::getInstance()->postMessageNoLock(m);
493 BoxStack::getInstance()->update(this);
494 Message* m = new Message();
497 m->message = Message::AUDIO_CHANGE_CHANNEL;
498 m->parameter = (((AudioSubtitleChannel*)asl.getCurrentOptionData())->pestype &0xFFFF)|(((AudioSubtitleChannel*)asl.getCurrentOptionData())->type &0xFF)<<16 ;
499 Command::getInstance()->postMessageNoLock(m);
504 case Remote::DF_DOWN:
510 BoxStack::getInstance()->update(this);
511 Message* m = new Message();
514 m->message = Message::SUBTITLE_CHANGE_CHANNEL;
515 m->parameter = (((AudioSubtitleChannel*)ssl.getCurrentOptionData())->pestype &0xFFFF)|(((AudioSubtitleChannel*)ssl.getCurrentOptionData())->type &0xFF)<<16
516 |(((AudioSubtitleChannel*)asl.getCurrentOptionData())->streamtype &0xFF)<<24 ;
517 Command::getInstance()->postMessageNoLock(m);
521 BoxStack::getInstance()->update(this);
522 Message* m = new Message();
525 m->message = Message::AUDIO_CHANGE_CHANNEL;
526 m->parameter = (((AudioSubtitleChannel*)asl.getCurrentOptionData())->pestype &0xFFFF)|(((AudioSubtitleChannel*)asl.getCurrentOptionData())->type &0xFF)<<16
527 |(((AudioSubtitleChannel*)asl.getCurrentOptionData())->streamtype &0xFF)<<24 ;
528 Command::getInstance()->postMessageNoLock(m);
534 case Remote::DF_LEFT:
536 if (editsubtitles && subtitles) {
537 ssl.setDarkSelOption(true);
538 asl.setDarkSelOption(false);
542 BoxStack::getInstance()->update(this);
547 case Remote::DF_RIGHT:
549 if (!editsubtitles && subtitles) {
550 ssl.setDarkSelOption(false);
551 asl.setDarkSelOption(true);
555 BoxStack::getInstance()->update(this);
564 void VAudioSelector::processMessage(Message* m)
566 if (m->message == Message::MOUSE_MOVE)
569 UINT lastsel=asl.getCurrentOption();
571 if (((m->parameter>>16)-getScreenX()) < 200 && asl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
574 ssl.setDarkSelOption(true);
575 asl.setDarkSelOption(false);
578 BoxStack::getInstance()->update(this);
579 if ((int)lastsel!=asl.getCurrentOption())
581 Message* m2 = new Message();
584 m2->message = Message::AUDIO_CHANGE_CHANNEL;
585 m2->parameter = (((AudioSubtitleChannel*)asl.getCurrentOptionData())->pestype &0xFFFF)|(((AudioSubtitleChannel*)asl.getCurrentOptionData())->type &0xFF)<<16 ;
586 Command::getInstance()->postMessageNoLock(m2);
591 lastsel=ssl.getCurrentOption();
593 if (ssl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
596 ssl.setDarkSelOption(false);
597 asl.setDarkSelOption(true);
600 BoxStack::getInstance()->update(this);
601 if ((int)lastsel!=ssl.getCurrentOption())
603 Message* m2 = new Message();
606 m2->message = Message::SUBTITLE_CHANGE_CHANNEL;
607 m2->parameter = (((AudioSubtitleChannel*)ssl.getCurrentOptionData())->pestype &0xFFFF)|(((AudioSubtitleChannel*)ssl.getCurrentOptionData())->type &0xFF)<<16 ;
608 Command::getInstance()->postMessageNoLock(m2);
613 else if (m->message == Message::MOUSE_LBDOWN)
615 if (asl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
618 ssl.setDarkSelOption(true);
619 asl.setDarkSelOption(false);
622 BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
624 else if (ssl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
627 ssl.setDarkSelOption(false);
628 asl.setDarkSelOption(true);
631 BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
634 { //check if press is outside this view! then simulate cancel
635 int x=(m->parameter>>16)-getScreenX();
636 int y=(m->parameter&0xFFFF)-getScreenY();
637 if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
639 BoxStack::getInstance()->handleCommand(Remote::BACK); //simulate cancel press