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].name) + 1];
309 strcpy(sc->name, channel->spids[i].name);
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].name) + 1];
365 strcpy(ac->name, channel->apids[i].name);
366 ac->pestype = channel->apids[i].pid;
370 if (Audio::getInstance()->supportsAc3())
372 for (i = 0; i < channel->numDPids; i++)
374 AudioSubtitleChannel* ac = new AudioSubtitleChannel();
376 ac->name = new char[strlen(channel->dpids[i].name) + 1];
377 strcpy(ac->name, channel->dpids[i].name);
378 ac->pestype = channel->dpids[i].pid;
383 int audioChannelListSize = acl.size();
385 if (audioChannelListSize)
387 for(int j = 0; j < audioChannelListSize; j++)
389 AudioSubtitleChannel* ac = acl[j];
390 asl.addOption(ac->name, (ULONG)ac, (ac->pestype == currentAudioChannel));
395 asl.addOption(tr("No audio channel data available"), 0, 1);
397 int subtitlesChannelListSize = scl.size();
400 ssl.setDarkSelOption(true);
401 for(int j = 0; j < subtitlesChannelListSize; j++)
403 AudioSubtitleChannel* sc = scl[j];
405 if ((sc->type==currentSubtitletype) && (sc->pestype == currentSubtitleChannel)) selected=true;
406 ssl.addOption(sc->name, (ULONG)sc, selected);
412 VAudioSelector::~VAudioSelector()
414 int audioChannelListSize = acl.size();
415 for(int i = 0; i < audioChannelListSize; i++)
417 // FIXME memory leak - nobody is deleting audio channel name? // try:
418 delete[] acl[i]->name;
419 Log::getInstance()->log("VAudioSelector", Log::DEBUG, "Deleted char[] on close");
426 int subtitleChannelListSize = scl.size();
427 for(int i = 0; i < subtitleChannelListSize; i++)
429 // FIXME memory leak - nobody is deleting audio channel name? // try:
430 delete[] scl[i]->name;
431 Log::getInstance()->log("VAudioSelector", Log::DEBUG, "Deleted char[] on close");
438 Message* m = new Message();
441 m->message = Message::CHILD_CLOSE;
442 Command::getInstance()->postMessageNoLock(m);
445 void VAudioSelector::draw()
451 rectangle(0, 0, area.w, 30, Colour::TITLEBARBACKGROUND);
452 drawText(tr("Audio"), 45, 5, Colour::LIGHTTEXT);
454 drawText(tr("Subtitles"), 45+200, 5, Colour::LIGHTTEXT);
455 ssl.setBackgroundColour(backgroundColour);
459 asl.setBackgroundColour(backgroundColour);
465 int VAudioSelector::handleCommand(int command)
481 BoxStack::getInstance()->update(this);
482 Message* m = new Message();
485 m->message = Message::SUBTITLE_CHANGE_CHANNEL;
486 m->parameter = (((AudioSubtitleChannel*)ssl.getCurrentOptionData())->pestype &0xFFFF)|(((AudioSubtitleChannel*)ssl.getCurrentOptionData())->type &0xFF)<<16 ;
487 Command::getInstance()->postMessageNoLock(m);
491 BoxStack::getInstance()->update(this);
492 Message* m = new Message();
495 m->message = Message::AUDIO_CHANGE_CHANNEL;
496 m->parameter = (((AudioSubtitleChannel*)asl.getCurrentOptionData())->pestype &0xFFFF)|(((AudioSubtitleChannel*)asl.getCurrentOptionData())->type &0xFF)<<16 ;
497 Command::getInstance()->postMessageNoLock(m);
502 case Remote::DF_DOWN:
508 BoxStack::getInstance()->update(this);
509 Message* m = new Message();
512 m->message = Message::SUBTITLE_CHANGE_CHANNEL;
513 m->parameter = (((AudioSubtitleChannel*)ssl.getCurrentOptionData())->pestype &0xFFFF)|(((AudioSubtitleChannel*)ssl.getCurrentOptionData())->type &0xFF)<<16 ;
514 Command::getInstance()->postMessageNoLock(m);
518 BoxStack::getInstance()->update(this);
519 Message* m = new Message();
522 m->message = Message::AUDIO_CHANGE_CHANNEL;
523 m->parameter = (((AudioSubtitleChannel*)asl.getCurrentOptionData())->pestype &0xFFFF)|(((AudioSubtitleChannel*)asl.getCurrentOptionData())->type &0xFF)<<16 ;
524 Command::getInstance()->postMessageNoLock(m);
531 if (editsubtitles && subtitles) {
532 ssl.setDarkSelOption(true);
533 asl.setDarkSelOption(false);
537 BoxStack::getInstance()->update(this);
543 if (!editsubtitles && subtitles) {
544 ssl.setDarkSelOption(false);
545 asl.setDarkSelOption(true);
549 BoxStack::getInstance()->update(this);
558 void VAudioSelector::processMessage(Message* m)
560 if (m->message == Message::MOUSE_MOVE)
563 UINT lastsel=asl.getCurrentOption();
565 if (((m->parameter>>16)-getScreenX()) < 200 && asl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
568 ssl.setDarkSelOption(true);
569 asl.setDarkSelOption(false);
572 BoxStack::getInstance()->update(this);
573 if ((int)lastsel!=asl.getCurrentOption())
575 Message* m2 = new Message();
578 m2->message = Message::AUDIO_CHANGE_CHANNEL;
579 m2->parameter = (((AudioSubtitleChannel*)asl.getCurrentOptionData())->pestype &0xFFFF)|(((AudioSubtitleChannel*)asl.getCurrentOptionData())->type &0xFF)<<16 ;
580 Command::getInstance()->postMessageNoLock(m2);
585 lastsel=ssl.getCurrentOption();
587 if (ssl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
590 ssl.setDarkSelOption(false);
591 asl.setDarkSelOption(true);
594 BoxStack::getInstance()->update(this);
595 if ((int)lastsel!=ssl.getCurrentOption())
597 Message* m2 = new Message();
600 m2->message = Message::SUBTITLE_CHANGE_CHANNEL;
601 m2->parameter = (((AudioSubtitleChannel*)ssl.getCurrentOptionData())->pestype &0xFFFF)|(((AudioSubtitleChannel*)ssl.getCurrentOptionData())->type &0xFF)<<16 ;
602 Command::getInstance()->postMessageNoLock(m2);
607 else if (m->message == Message::MOUSE_LBDOWN)
609 if (asl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
612 ssl.setDarkSelOption(true);
613 asl.setDarkSelOption(false);
616 BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
618 else if (ssl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
621 ssl.setDarkSelOption(false);
622 asl.setDarkSelOption(true);
625 BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
628 { //check if press is outside this view! then simulate cancel
629 int x=(m->parameter>>16)-getScreenX();
630 int y=(m->parameter&0xFFFF)-getScreenY();
631 if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
633 BoxStack::getInstance()->handleCommand(Remote::BACK); //simulate cancel press