src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
   150 
   150 
   151 bool QAudioDeviceInfoInternal::open()
   151 bool QAudioDeviceInfoInternal::open()
   152 {
   152 {
   153     int err = 0;
   153     int err = 0;
   154     QString dev = device;
   154     QString dev = device;
   155     if(!dev.contains(QLatin1String("default"))) {
   155     QList<QByteArray> devices = availableDevices(mode);
       
   156 
       
   157     if(dev.compare(QLatin1String("default")) == 0) {
   156 #if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
   158 #if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
   157          dev = QString(QLatin1String("default:CARD=%1")).arg(dev);
   159         dev = QLatin1String(devices.first().constData());
       
   160 #else
       
   161         dev = QLatin1String("hw:0,0");
       
   162 #endif
       
   163     } else {
       
   164 #if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
       
   165         dev = device;
   158 #else
   166 #else
   159         int idx = 0;
   167         int idx = 0;
   160         char *name;
   168         char *name;
       
   169 
       
   170         QString shortName = device.mid(device.indexOf(QLatin1String("="),0)+1);
   161 
   171 
   162 	while(snd_card_get_name(idx,&name) == 0) {
   172 	while(snd_card_get_name(idx,&name) == 0) {
   163             if(dev.contains(QLatin1String(name)))
   173             if(dev.contains(QLatin1String(name)))
   164                 break;
   174                 break;
   165             idx++;
   175             idx++;
   193     int err = 0;
   203     int err = 0;
   194     snd_pcm_t* handle;
   204     snd_pcm_t* handle;
   195     snd_pcm_hw_params_t *params;
   205     snd_pcm_hw_params_t *params;
   196     QString dev = device;
   206     QString dev = device;
   197 
   207 
   198     // open()
   208     QList<QByteArray> devices = QAudioDeviceInfoInternal::availableDevices(QAudio::AudioOutput);
   199     if(!dev.contains(QLatin1String("default"))) {
   209 
       
   210     if(dev.compare(QLatin1String("default")) == 0) {
   200 #if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
   211 #if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
   201          dev = QString(QLatin1String("default:CARD=%1")).arg(dev);
   212         dev = QLatin1String(devices.first().constData());
       
   213 #else
       
   214         dev = QLatin1String("hw:0,0");
       
   215 #endif
       
   216     } else {
       
   217 #if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
       
   218         dev = device;
   202 #else
   219 #else
   203         int idx = 0;
   220         int idx = 0;
   204         char *name;
   221         char *name;
   205     
   222 
       
   223         QString shortName = device.mid(device.indexOf(QLatin1String("="),0)+1);
       
   224 
   206         while(snd_card_get_name(idx,&name) == 0) {
   225         while(snd_card_get_name(idx,&name) == 0) {
   207             if(dev.contains(QLatin1String(name)))
   226             if(shortName.compare(QLatin1String(name)) == 0)
   208                 break;
   227                 break;
   209             idx++;
   228             idx++;
   210         }
   229         }
   211         dev = QString(QLatin1String("hw:%1,0")).arg(idx);
   230         dev = QString(QLatin1String("hw:%1,0")).arg(idx);
   212 #endif
   231 #endif
   380     typez.append(QAudioFormat::Float);
   399     typez.append(QAudioFormat::Float);
   381     codecz.append(QLatin1String("audio/pcm"));
   400     codecz.append(QLatin1String("audio/pcm"));
   382     close();
   401     close();
   383 }
   402 }
   384 
   403 
   385 QList<QByteArray> QAudioDeviceInfoInternal::deviceList(QAudio::Mode mode)
   404 QList<QByteArray> QAudioDeviceInfoInternal::availableDevices(QAudio::Mode mode)
   386 {
   405 {
       
   406     QList<QByteArray> allDevices;
   387     QList<QByteArray> devices;
   407     QList<QByteArray> devices;
   388     QByteArray filter;
   408     QByteArray filter;
       
   409 
   389 #if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
   410 #if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
   390     // Create a list of all current audio devices that support mode
   411     // Create a list of all current audio devices that support mode
   391     void **hints, **n;
   412     void **hints, **n;
   392     char *name, *descr, *io;
   413     char *name, *descr, *io;
   393 
   414 
   406     while (*n != NULL) {
   427     while (*n != NULL) {
   407         name = snd_device_name_get_hint(*n, "NAME");
   428         name = snd_device_name_get_hint(*n, "NAME");
   408         descr = snd_device_name_get_hint(*n, "DESC");
   429         descr = snd_device_name_get_hint(*n, "DESC");
   409         io = snd_device_name_get_hint(*n, "IOID");
   430         io = snd_device_name_get_hint(*n, "IOID");
   410         if((name != NULL) && (descr != NULL) && ((io == NULL) || (io == filter))) {
   431         if((name != NULL) && (descr != NULL) && ((io == NULL) || (io == filter))) {
   411             QString str = QLatin1String(name);
   432             QString deviceName = QLatin1String(name);
   412 
   433             QString deviceDescription = QLatin1String(descr);
   413             if(str.contains(QLatin1String("default"))) {
   434             allDevices.append(deviceName.toLocal8Bit().constData());
   414                 int pos = str.indexOf(QLatin1String("="),0);
   435             if(deviceDescription.contains(QLatin1String("Default Audio Device")))
   415                 devices.append(str.mid(pos+1).toLocal8Bit().constData());
   436                 devices.append(deviceName.toLocal8Bit().constData());
   416             }
       
   417         }
   437         }
   418         if(name != NULL)
   438         if(name != NULL)
   419             free(name);
   439             free(name);
   420         if(descr != NULL)
   440         if(descr != NULL)
   421             free(descr);
   441             free(descr);
   437         idx++;
   457         idx++;
   438     }
   458     }
   439     if (idx > 0)
   459     if (idx > 0)
   440         devices.append("default");
   460         devices.append("default");
   441 #endif
   461 #endif
       
   462     if (devices.size() == 0 && allDevices.size() > 0)
       
   463         return allDevices;
       
   464 
   442     return devices;
   465     return devices;
   443 }
   466 }
   444 
   467 
   445 QByteArray QAudioDeviceInfoInternal::defaultInputDevice()
   468 QByteArray QAudioDeviceInfoInternal::defaultInputDevice()
   446 {
   469 {
   447     QList<QByteArray> devices = deviceList(QAudio::AudioInput);
   470     QList<QByteArray> devices = availableDevices(QAudio::AudioInput);
   448     if(devices.size() == 0)
   471     if(devices.size() == 0)
   449         return QByteArray();
   472         return QByteArray();
   450 
   473 
   451     return QByteArray("default");
   474     return devices.first();
   452 }
   475 }
   453 
   476 
   454 QByteArray QAudioDeviceInfoInternal::defaultOutputDevice()
   477 QByteArray QAudioDeviceInfoInternal::defaultOutputDevice()
   455 {
   478 {
   456     QList<QByteArray> devices = deviceList(QAudio::AudioOutput);
   479     QList<QByteArray> devices = availableDevices(QAudio::AudioOutput);
   457     if(devices.size() == 0)
   480     if(devices.size() == 0)
   458         return QByteArray();
   481         return QByteArray();
   459 
   482 
   460     return QByteArray("default");
   483     return devices.first();
   461 }
   484 }
   462 
   485 
   463 QT_END_NAMESPACE
   486 QT_END_NAMESPACE