免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2882 | 回复: 0
打印 上一主题 下一主题

ALSA 音频系统源代码分析: ALSA library 分析 --- 配置系统 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-02-08 09:44 |只看该作者 |倒序浏览

                ALSA的配置主文件默认是:/usr/share/alsa/alsa.conf
ALSA lib源代码中的conf.c负责load,解析这个配置文件。
配置以层次结构组织的,由一个snd_config_t 数据结构对象snd_config保存着总配置根,用list_head的方法将各个层次的配置组织起来。
view plain
copy to clipboard
print
?
struct _snd_config {      char *id;      snd_config_type_t type;      union {          long integer;          long long integer64;          char *string;          double real;          const void *ptr;          struct {              struct list_head fields;              int join;          } compound;      } u;      struct list_head list;      snd_config_t *father;      int hop;  };  
这个数据结构中的type的成员指定,此配置的属性,可以是一个值,也可以是个拥有下层配置的分支。类型如下,除了SND_CONFIG_TYPE_COMPOUND类型,其他类型不能有下层配置而拥有一个值。
view plain
copy to clipboard
print
?
/** Configuration node type. */  typedef enum _snd_config_type {      /** Integer number. */          SND_CONFIG_TYPE_INTEGER,      /** 64 bit Integer number. */          SND_CONFIG_TYPE_INTEGER64,      /** Real number. */          SND_CONFIG_TYPE_REAL,      /** Character string. */          SND_CONFIG_TYPE_STRING,          /** Pointer (runtime only, cannot be saved). */          SND_CONFIG_TYPE_POINTER,      /** Compound node. */      SND_CONFIG_TYPE_COMPOUND = 1024  } 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完成后调用显示所有的配置信息:
view plain
copy to clipboard
print
?
static void snd_config_dump(snd_config_t *top,char *prefix)  {      char str[100];      snd_config_iterator_t i,next;      snd_config_for_each(i,next,top) {          snd_config_t *s=snd_config_iterator_entry(i);          switch(s->type) {              case SND_CONFIG_TYPE_COMPOUND:                  if(prefix) {                      sprintf(str,"%s.%s",prefix,s->id);                  }                  else {                      sprintf(str,"%s",s->id);                  }                  snd_config_dump(s,str);                  break;              case SND_CONFIG_TYPE_STRING:                  printf("%s.%s=%s\n",prefix,s->id,s->u.string);                  break;              case SND_CONFIG_TYPE_INTEGER:                  printf("%s.%s=%d\n",prefix,s->id,s->u.integer);                  break;              case SND_CONFIG_TYPE_INTEGER64:                  printf("%s.%s=%d\n",prefix,s->id,s->u.integer64);                  break;              default:                  break;          }      }  }  
可以在调用了snd_config_load函数后调用。我在snd_config_update_r函数中如下调用:
view plain
copy to clipboard
print
?
_skip:  snd_config_dump(top,NULL);  err = snd_config_hooks(top, NULL);  
"@hook"关键字可以由第三方编写共享库来扩充功能。
而在alsa.conf中开头的部分,则是用于load其他配置文件:
view plain
copy to clipboard
print
?
@hooks [      {          func load          files [              "/etc/asound.conf"              "~/.asoundrc"          ]          errors false      }  ]  
这里没有指定第三方共享库,则会调用snd_config_hook_load这个函数,
其中调用snd_config_load装载/etc/asound.conf和~/.asoundrc这2个特定的配置文件。
另外一点,可以用“”, 包含其他配置文件。
如:
               
               
               
               
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/111072/showart_2179758.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP