static char *ListAvailableDevices( demux_t *p_demux, bool b_probe ) { snd_ctl_card_info_t *p_info = NULL; snd_ctl_card_info_alloca( &p_info ); snd_pcm_info_t *p_pcminfo = NULL; snd_pcm_info_alloca( &p_pcminfo ); if( !b_probe ) msg_Dbg( p_demux, "Available alsa capture devices:" ); int i_card = -1; while( !snd_card_next( &i_card ) && i_card >= 0 ) { char psz_devname[10]; snprintf( psz_devname, 10, "hw:%d", i_card ); snd_ctl_t *p_ctl = NULL; if( snd_ctl_open( &p_ctl, psz_devname, 0 ) < 0 ) continue; snd_ctl_card_info( p_ctl, p_info ); if( !b_probe ) msg_Dbg( p_demux, " %s (%s)", snd_ctl_card_info_get_id( p_info ), snd_ctl_card_info_get_name( p_info ) ); int i_dev = -1; while( !snd_ctl_pcm_next_device( p_ctl, &i_dev ) && i_dev >= 0 ) { snd_pcm_info_set_device( p_pcminfo, i_dev ); snd_pcm_info_set_subdevice( p_pcminfo, 0 ); snd_pcm_info_set_stream( p_pcminfo, SND_PCM_STREAM_CAPTURE ); if( snd_ctl_pcm_info( p_ctl, p_pcminfo ) < 0 ) continue; if( !b_probe ) msg_Dbg( p_demux, " hw:%d,%d : %s (%s)", i_card, i_dev, snd_pcm_info_get_id( p_pcminfo ), snd_pcm_info_get_name( p_pcminfo ) ); else { char *psz_device; if( asprintf( &psz_device, "hw:%d,%d", i_card, i_dev ) > 0 ) { if( ProbeAudioDevAlsa( p_demux, psz_device ) ) { snd_ctl_close( p_ctl ); return psz_device; } else free( psz_device ); } } } snd_ctl_close( p_ctl ); } return NULL; }
int deviceInfoIterator(UINT32 deviceID, snd_pcm_info_t* pcminfo, snd_ctl_card_info_t* cardinfo, void* userData) { char buffer[300]; ALSA_AudioDeviceDescription* desc = (ALSA_AudioDeviceDescription*)userData; #ifdef ALSA_PCM_USE_PLUGHW int usePlugHw = 1; #else int usePlugHw = 0; #endif initAlsaSupport(); if (desc->index == 0) { // we found the device with correct index *(desc->maxSimultaneousLines) = needEnumerateSubdevices(ALSA_PCM) ? 1 : snd_pcm_info_get_subdevices_count(pcminfo); *desc->deviceID = deviceID; buffer[0]=' '; buffer[1]='['; // buffer[300] is enough to store the actual device string w/o overrun getDeviceStringFromDeviceID(&buffer[2], deviceID, usePlugHw, ALSA_PCM); strncat(buffer, "]", sizeof(buffer) - strlen(buffer) - 1); strncpy(desc->name, (cardinfo != NULL) ? snd_ctl_card_info_get_id(cardinfo) : snd_pcm_info_get_id(pcminfo), desc->strLen - strlen(buffer)); strncat(desc->name, buffer, desc->strLen - strlen(desc->name)); strncpy(desc->vendor, "ALSA (http://www.alsa-project.org)", desc->strLen); strncpy(desc->description, (cardinfo != NULL) ? snd_ctl_card_info_get_name(cardinfo) : snd_pcm_info_get_name(pcminfo), desc->strLen); strncat(desc->description, ", ", desc->strLen - strlen(desc->description)); strncat(desc->description, snd_pcm_info_get_id(pcminfo), desc->strLen - strlen(desc->description)); strncat(desc->description, ", ", desc->strLen - strlen(desc->description)); strncat(desc->description, snd_pcm_info_get_name(pcminfo), desc->strLen - strlen(desc->description)); getALSAVersion(desc->version, desc->strLen); TRACE4("Returning %s, %s, %s, %s\n", desc->name, desc->vendor, desc->description, desc->version); return FALSE; // do not continue iteration } desc->index--; return TRUE; }
static void DumpDevice (vlc_object_t *obj, snd_pcm_t *pcm) { snd_pcm_info_t *info; Dump (obj, " ", snd_pcm_dump, pcm); snd_pcm_info_alloca (&info); if (snd_pcm_info (pcm, info) == 0) { msg_Dbg (obj, " device name : %s", snd_pcm_info_get_name (info)); msg_Dbg (obj, " device ID : %s", snd_pcm_info_get_id (info)); msg_Dbg (obj, " subdevice name: %s", snd_pcm_info_get_subdevice_name (info)); } }
void list_cards(void) { snd_ctl_card_info_t *p_info = NULL; snd_ctl_card_info_alloca(&p_info); snd_pcm_info_t *p_pcminfo = NULL; snd_pcm_info_alloca(&p_pcminfo); printf("Availible alsa capture devices:\n"); int i_card = -1; while (!snd_card_next(&i_card) && i_card >= 0) { char devname[10]; snprintf( devname, 10, "hw:%d", i_card ); snd_ctl_t *p_ctl = NULL; if ( snd_ctl_open( &p_ctl, devname, 0 ) < 0) continue; snd_ctl_card_info( p_ctl, p_info); printf("\t%s (%s)\n", snd_ctl_card_info_get_id(p_info), snd_ctl_card_info_get_name(p_info)); int i_dev = -1; while (!snd_ctl_pcm_next_device(p_ctl, &i_dev) && i_dev >= 0) { snd_pcm_info_set_device(p_pcminfo, i_dev); snd_pcm_info_set_subdevice(p_pcminfo, 0); snd_pcm_info_set_stream(p_pcminfo, SND_PCM_STREAM_CAPTURE); if (snd_ctl_pcm_info(p_ctl, p_pcminfo) < 0) continue; printf("\t\thw:%d,%d : %s (%s)\n", i_card, i_dev, snd_pcm_info_get_id(p_pcminfo), snd_pcm_info_get_name(p_pcminfo)); } snd_ctl_close(p_ctl); } }
static void device_list(snd_pcm_stream_t stream) { snd_ctl_t *handle; int card, err, dev, idx; snd_ctl_card_info_t *info; snd_pcm_info_t *pcminfo; snd_ctl_card_info_alloca(&info); snd_pcm_info_alloca(&pcminfo); card = -1; if (snd_card_next(&card) < 0 || card < 0) { error(_("no soundcards found...")); return; } printf(_("**** List of %s Hardware Devices ****\n"), snd_pcm_stream_name(stream)); while (card >= 0) { char name[32]; sprintf(name, "hw:%d", card); if ((err = snd_ctl_open(&handle, name, 0)) < 0) { error("control open (%i): %s", card, snd_strerror(err)); goto next_card; } if ((err = snd_ctl_card_info(handle, info)) < 0) { error("control hardware info (%i): %s", card, snd_strerror(err)); snd_ctl_close(handle); goto next_card; } dev = -1; while (1) { unsigned int count; if (snd_ctl_pcm_next_device(handle, &dev)<0) error("snd_ctl_pcm_next_device"); if (dev < 0) break; snd_pcm_info_set_device(pcminfo, dev); snd_pcm_info_set_subdevice(pcminfo, 0); snd_pcm_info_set_stream(pcminfo, stream); if ((err = snd_ctl_pcm_info(handle, pcminfo)) < 0) { if (err != -ENOENT) error("control digital audio info (%i): %s", card, snd_strerror(err)); continue; } printf(_("card %i: [%s,%i] %s [%s], device %i: %s [%s]\n"), card, name, dev, snd_ctl_card_info_get_id(info), snd_ctl_card_info_get_name(info), dev, snd_pcm_info_get_id(pcminfo), snd_pcm_info_get_name(pcminfo)); count = snd_pcm_info_get_subdevices_count(pcminfo); printf( _(" Subdevices: %i/%i\n"), snd_pcm_info_get_subdevices_avail(pcminfo), count); for (idx = 0; idx < (int)count; idx++) { snd_pcm_info_set_subdevice(pcminfo, idx); if ((err = snd_ctl_pcm_info(handle, pcminfo)) < 0) { error("control digital audio playback info (%i): %s", card, snd_strerror(err)); } else { printf(_(" Subdevice #%i: %s\n"), idx, snd_pcm_info_get_subdevice_name(pcminfo)); } } } snd_ctl_close(handle); next_card: if (snd_card_next(&card) < 0) { error("snd_card_next"); break; } } }