mirror of
				https://github.com/alsa-project/alsa-lib.git
				synced 2025-11-03 09:01:52 -05:00 
			
		
		
		
	Extend snd_card_get_index() to accept also control device name like /dev/snd/controlC0
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
		
							parent
							
								
									3e30007a19
								
							
						
					
					
						commit
						33ab0b5381
					
				
					 1 changed files with 28 additions and 13 deletions
				
			
		| 
						 | 
					@ -39,29 +39,42 @@
 | 
				
			||||||
#define SND_FILE_LOAD		ALOAD_DEVICE_DIRECTORY "aloadC%i"
 | 
					#define SND_FILE_LOAD		ALOAD_DEVICE_DIRECTORY "aloadC%i"
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int snd_card_load1(int card)
 | 
					static int snd_card_load2(const char *control)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int open_dev;
 | 
						int open_dev;
 | 
				
			||||||
	char control[sizeof(SND_FILE_CONTROL) + 10];
 | 
						snd_ctl_card_info_t info;
 | 
				
			||||||
 | 
					 | 
				
			||||||
	sprintf(control, SND_FILE_CONTROL, card);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	open_dev = snd_open_device(control, O_RDONLY);
 | 
						open_dev = snd_open_device(control, O_RDONLY);
 | 
				
			||||||
#ifdef SUPPORT_ALOAD
 | 
					 | 
				
			||||||
	if (open_dev < 0) {
 | 
					 | 
				
			||||||
		char aload[sizeof(SND_FILE_LOAD) + 10];
 | 
					 | 
				
			||||||
		sprintf(aload, SND_FILE_LOAD, card);
 | 
					 | 
				
			||||||
		open_dev = snd_open_device(aload, O_RDONLY);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
	if (open_dev >= 0) {
 | 
						if (open_dev >= 0) {
 | 
				
			||||||
		close (open_dev);
 | 
							if (ioctl(open_dev, SNDRV_CTL_IOCTL_CARD_INFO, &info) < 0) {
 | 
				
			||||||
		return 0;
 | 
								int err = -errno;
 | 
				
			||||||
 | 
								close(open_dev);
 | 
				
			||||||
 | 
								return err;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							close(open_dev);
 | 
				
			||||||
 | 
							return info.card;
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		return -errno;
 | 
							return -errno;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int snd_card_load1(int card)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int res;
 | 
				
			||||||
 | 
						char control[sizeof(SND_FILE_CONTROL) + 10];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						sprintf(control, SND_FILE_CONTROL, card);
 | 
				
			||||||
 | 
						res = snd_card_load2(control);
 | 
				
			||||||
 | 
					#ifdef SUPPORT_ALOAD
 | 
				
			||||||
 | 
						if (res < 0) {
 | 
				
			||||||
 | 
							char aload[sizeof(SND_FILE_LOAD) + 10];
 | 
				
			||||||
 | 
							sprintf(aload, SND_FILE_LOAD, card);
 | 
				
			||||||
 | 
							res = snd_card_load2(aload);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
						return res;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * \brief Try to load the driver for a card.
 | 
					 * \brief Try to load the driver for a card.
 | 
				
			||||||
 * \param card Card number.
 | 
					 * \param card Card number.
 | 
				
			||||||
| 
						 | 
					@ -127,6 +140,8 @@ int snd_card_get_index(const char *string)
 | 
				
			||||||
			return card;
 | 
								return card;
 | 
				
			||||||
		return err;
 | 
							return err;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if (string[0] == '/')	/* device name */
 | 
				
			||||||
 | 
							return snd_card_load2(string);
 | 
				
			||||||
	for (card = 0; card < 32; card++) {
 | 
						for (card = 0; card < 32; card++) {
 | 
				
			||||||
#ifdef SUPPORT_ALOAD
 | 
					#ifdef SUPPORT_ALOAD
 | 
				
			||||||
		if (! snd_card_load(card))
 | 
							if (! snd_card_load(card))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue