ALSA 音频系统源代码分析: ALSA library 分析 --- 配置系统

ALSA的配置主文件默认是:/usr/share/alsa/alsa.conf

ALSA lib源代码中的conf.c负责load,解析这个配置文件。

配置以层次结构组织的,由一个snd_config_t 数据结构对象snd_config保存着总配置根,用list_head的方法将各个层次的配置组织起来。

[cpp]  view plain  copy
  1. struct _snd_config {  
  2.     char *id;  
  3.     snd_config_type_t type;  
  4.     union {  
  5.         long integer;  
  6.         long long integer64;  
  7.         char *string;  
  8.         double real;  
  9.         const void *ptr;  
  10.         struct {  
  11.             struct list_head fields;  
  12.             int join;  
  13.         } compound;  
  14.     } u;  
  15.     struct list_head list;  
  16.     snd_config_t *father;  
  17.     int hop;  
  18. };  

这个数据结构中的type的成员指定,此配置的属性,可以是一个值,也可以是个拥有下层配置的分支。类型如下,除了SND_CONFIG_TYPE_COMPOUND类型,其他类型不能有下层配置而拥有一个值。

[c-sharp]  view plain  copy
  1. /** Configuration node type. */  
  2. typedef enum _snd_config_type {  
  3.     /** Integer number. */  
  4.         SND_CONFIG_TYPE_INTEGER,  
  5.     /** 64 bit Integer number. */  
  6.         SND_CONFIG_TYPE_INTEGER64,  
  7.     /** Real number. */  
  8.         SND_CONFIG_TYPE_REAL,  
  9.     /** Character string. */  
  10.         SND_CONFIG_TYPE_STRING,  
  11.         /** Pointer (runtime only, cannot be saved). */  
  12.         SND_CONFIG_TYPE_POINTER,  
  13.     /** Compound node. */  
  14.     SND_CONFIG_TYPE_COMPOUND = 1024  
  15. } snd_config_type_t;  

配置的层次结构在配置文件中有几种相同效果的方式:

a 1 和 a=1等效

a  {

     b 1  和  a.b=1等效

}

 

[ ]是数组方式的配置,在[ ]中的各个代码块赋值一个递增的数字

a [

     {

          b 1

          c 2

     }

     {

           d 3

           e 4

     }

]

a.0.b=1

a.0.c=2

a.1.d=3

a.1.e=4

等效

 

特殊一点的地方:

a [

b c d e

]

a.0=b

a.1=c

a.2=d

a.3=e

等效

 

下面是本人写的一个将配置dump出来的代码,可以在load完成后调用显示所有的配置信息:

[cpp]  view plain  copy
  1. static void snd_config_dump(snd_config_t *top,char *prefix)  
  2. {  
  3.     char str[100];  
  4.     snd_config_iterator_t i,next;  
  5.     snd_config_for_each(i,next,top) {  
  6.         snd_config_t *s=snd_config_iterator_entry(i);  
  7.         switch(s->type) {  
  8.             case SND_CONFIG_TYPE_COMPOUND:  
  9.                 if(prefix) {  
  10.                     sprintf(str,"%s.%s",prefix,s->id);  
  11.                 }  
  12.                 else {  
  13.                     sprintf(str,"%s",s->id);  
  14.                 }  
  15.                 snd_config_dump(s,str);  
  16.                 break;  
  17.             case SND_CONFIG_TYPE_STRING:  
  18.                 printf("%s.%s=%s/n",prefix,s->id,s->u.string);  
  19.                 break;  
  20.             case SND_CONFIG_TYPE_INTEGER:  
  21.                 printf("%s.%s=%d/n",prefix,s->id,s->u.integer);  
  22.                 break;  
  23.             case SND_CONFIG_TYPE_INTEGER64:  
  24.                 printf("%s.%s=%d/n",prefix,s->id,s->u.integer64);  
  25.                 break;  
  26.             default:  
  27.                 break;  
  28.         }  
  29.     }  
  30. }  

 

可以在调用了snd_config_load函数后调用。我在snd_config_update_r函数中如下调用:

[cpp]  view plain  copy
  1. _skip:  
  2. snd_config_dump(top,NULL);  
  3. err = snd_config_hooks(top, NULL);  

 

"@hook"关键字可以由第三方编写共享库来扩充功能。

而在alsa.conf中开头的部分,则是用于load其他配置文件:

[cpp]  view plain  copy
  1. @hooks [  
  2.     {  
  3.         func load  
  4.         files [  
  5.             "/etc/asound.conf"  
  6.             "~/.asoundrc"  
  7.         ]  
  8.         errors false  
  9.     }  
  10. ]  

这里没有指定第三方共享库,则会调用snd_config_hook_load这个函数,

其中调用snd_config_load装载/etc/asound.conf和~/.asoundrc这2个特定的配置文件。

 

另外一点,可以用“<>”, 包含其他配置文件。

如:

<confdir:pcm/surround.conf>

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值