Linux音频驱动之二:声卡的创建


1. struct snd_card

1.1. snd_card是什么

snd_card可以说是整个ALSA音频驱动最顶层的一个结构,整个声卡的软件逻辑结构开始于该结构,几乎所有与声音相关的逻辑设备都是在snd_card的管理之下,声卡驱动的第一个动作通常就是创建一个snd_card结构体。正因为如此,本节中,我们也从 struct cnd_card开始吧。

Linux音频驱动之一:ALSA架构简介

1.2. snd_card的定义

snd_card的定义位于改头文件中:include/sound/core.h

  1. /* main structure for soundcard */  
  2.   
  3. struct snd_card {   
  4.     int number;         /* number of soundcard (index to  
  5.                                 snd_cards) */  
  6.   
  7.     char id[16];            /* id string of this card */  
  8.     char driver[16];        /* driver name */  
  9.     char shortname[32];     /* short name of this soundcard */  
  10.     char longname[80];      /* name of this soundcard */  
  11.     char mixername[80];     /* mixer name */  
  12.     char components[128];       /* card components delimited with  
  13.                                 space */  
  14.     struct module *module;      /* top-level module */  
  15.   
  16.     void *private_data;     /* private data for soundcard */  
  17.     void (*private_free) (struct snd_card *card); /* callback for freeing of  
  18.                                 private data */  
  19.     struct list_head devices;   /* devices */  
  20.   
  21.     unsigned int last_numid;    /* last used numeric ID */  
  22.     struct rw_semaphore controls_rwsem; /* controls list lock */  
  23.     rwlock_t ctl_files_rwlock;  /* ctl_files list lock */  
  24.     int controls_count;     /* count of all controls */  
  25.     int user_ctl_count;     /* count of all user controls */  
  26.     struct list_head controls;  /* all controls for this card */  
  27.     struct list_head ctl_files; /* active control files */  
  28.   
  29.     struct snd_info_entry *proc_root;   /* root for soundcard specific files */  
  30.     struct snd_info_entry *proc_id; /* the card id */  
  31.     struct proc_dir_entry *proc_root_link;  /* number link to real id */  
  32.   
  33.     struct list_head files_list;    /* all files associated to this card */  
  34.     struct snd_shutdown_f_ops *s_f_ops; /* file operations in the shutdown  
  35.                                 state */  
  36.     spinlock_t files_lock;      /* lock the files for this card */  
  37.     int shutdown;           /* this card is going down */  
  38.     int free_on_last_close;     /* free in context of file_release */  
  39.     wait_queue_head_t shutdown_sleep;   
  40.     struct device *dev;     /* device assigned to this card */ 
  41. #ifndef CONFIG_SYSFS_DEPRECATED   
  42.     struct device *card_dev;    /* cardX object for sysfs */ 
  43. #endif  
  44.  
  45. #ifdef CONFIG_PM   
  46.     unsigned int power_state;   /* power state */  
  47.     struct mutex power_lock;    /* power lock */  
  48.     wait_queue_head_t power_sleep;  
  49. #endif  
  50.  
  51. #if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)   
  52.     struct snd_mixer_oss *mixer_oss;   
  53.     int mixer_oss_change_count;  
  54. #endif   
  55. };  

  • struct list_head devices     记录该声卡下所有逻辑设备的链表
  • struct list_head controls    记录该声卡下所有的控制单元的链表
  • void *private_data            声卡的私有数据,可以在创建声卡时通过参数指定数据的大小
  • 1
  • 2
  • 3
  • 下一页

相关内容