alsa分析:alsa的那些配置文件 ( 1 )

 

 http://blog.csdn.net/doom66151/article/details/6573176

在根文件系统下,alsa相关的配置文件有:

在/system/usr/share/alsa目录下:

  1. ├── alsa.conf  
  2. ├── cards  
  3. │   └── aliases.conf  
  4. └── pcm  
  5.     ├── center_lfe.conf  
  6.     ├── default.conf  
  7.     ├── dmix.conf  
  8.     ├── dpl.conf  
  9.     ├── dsnoop.conf  
  10.     ├── front.conf  
  11.     ├── iec958.conf  
  12.     ├── modem.conf  
  13.     ├── rear.conf  
  14.     ├── side.conf  
  15.     ├── surround40.conf  
  16.     ├── surround41.conf  
  17.     ├── surround50.conf  
  18.     ├── surround51.conf  
  19.     └── surround71.conf  
 

/system/etc/asound.state

 

这些配置文件是如何工作的?

alsa-lib是如何解析这些脚本的?

上层app是如何实现不同需要中的通道选择,音量调整等???比如手机使用过程中打电话/录音/蓝牙耳机输入/外放喇叭输入.......

 

下面分别分析这些配置脚本。

+++++++++++++++++++++++++++++++++++++++++++++++

 

【/system/etc/asound.state】

asound.state用来控制音频通道的初始设置。使用方法:

1 使用alsa_ctl store来将当前音频的初始设置导出为asound.state文件。

2 修改文件内容:设置播放/录制的通道,增益等。

3 使用alsa_ctl restore 重新加载修改过的配置。

4 在init.rc中添加一行,用于系统启动是自动加载此配置:

  1. service asound_conf /system/bin/alsa_ctl restore  
  2.     oneshot  
 

asound.state中的信息是抽取在驱动里面注册的snd_controls的信息。

 

 

 

 

【/system/usr/share/alsa/alsa.conf】

 

这里主要参考整理 http://hi.baidu.com/zmjdx/blog/item/35d570347a36e947241f1475.html

 

ALSA的配置文件alsa.conf定义了一些简单的语法,通过这些语法记录了alsa环境变量。

 

该文件开头处包含了用户可以配置的hook.

用户自定义的配置信息可以保存在/etc/asound.conf或~/.asoundrc里,当然也可以自己定义的位置。

我们感兴趣的是,alsa lib是如何解析这些配置的。

 

首先我们可以从使用alsa lib时,最先的入口函数snd_pcm_open处开始说起:

  1. int snd_pcm_open(snd_pcm_t **pcmp, const char *name,  
  2. snd_pcm_stream_t stream, int mode)  
  3. {  
  4. int err;  
  5. assert(pcmp && name);  
  6. err = snd_config_update();  
  7. if (err < 0)  
  8. return err;  
  9. return snd_pcm_open_noupdate(pcmp, snd_config, name, stream, mode, 0);  
  10. }  
 

其中调用了函数snd_config_update(),这个函数就是加载alsa的配置文件中配置信息的。

这个函数直接调用了 snd_config_update_r,见下面函数注释:

  1. /**  
  2.  * /brief Updates a configuration tree by rereading the configuration files (if needed). 
  3.  * /param _top Address of the handle to the top level node. 
  4.  * /param _update Address of a pointer to private update information. 
  5.  * /param cfgs A list of configuration file names, delimited with ':'. 
  6.  *             If /p cfgs is set to /c NULL, the default global configuration 
  7.  *             file is used ("/usr/share/alsa/alsa.conf"). 
  8.  * /return A non-negative value if successful, otherwise a negative error code. 
  9.  * /retval 0 No action is needed. 
  10.  * /retval 1 The configuration tree has been rebuilt. 
  11.  * 
  12.  * The global configuration files are specified in the environment variable 
  13.  * /c ALSA_CONFIG_PATH. 
  14.  * 
  15.  * /warning If the configuration tree is reread, all string pointers and 
  16.  * configuration node handles previously obtained from this tree become invalid. 
  17.  */  
  18. int snd_config_update_r(snd_config_t **_top, snd_config_update_t **_update, const char *cfgs)  
  19. {  
  20. int err;  
  21. const char *configs, *c;  
  22. unsigned int k;  
  23. size_t l;  
  24. snd_config_update_t *local;  
  25. snd_config_update_t *update;  
  26. snd_config_t *top;  
  27. assert(_top && _update);  
  28. top = *_top;  
  29. update = *_update;  
  30. configs = cfgs;  
  31. if (!configs) {  
  32. configs = getenv(ALSA_CONFIG_PATH_VAR);  
  33. if (!configs || !*configs)  
  34. configs = ALSA_CONFIG_PATH_DEFAULT;  
  35. }  
  36. //...............   
  37. }  
 

参数一和二:snd_config, snd_config_global_update 都是全局变量,定义在conf.c中。

第三个参数cfgs,是包含配置文件名的字符串,snd_config_update调用它时没有传递该参数,所以为空。

 

snd_config_udpate_r首先分析第三个参数cfgs,如果为空,就获取系统环境变量ALSA_CONFIG_PATH_VAR值,如果还是为空,就取ALSA_CONFIG_PATH_DEFAULT.

  1. /** The name of the default files used by #snd_config_update. */  
  2. #define ALSA_CONFIG_PATH_DEFAULT ALSA_CONFIG_DIR "/alsa.conf"   
  3. #define ALSA_CONFIG_DIR "/usr/share/alsa"  
 

然后提取cfgs里的文件名。

注意cfgs可以包含多个文件名,以:或空格分开。并把每个文件的文件信息保存在snd_config_update_t变量local中,其成员count记录了有多少个文件,finfo则是对应的文件信息链表。

 

接下来分析第二个参数update,如果该参数值为空(前面提到过,最开始是为空),就重新去读配置文件,否则与local变量比较,如果发现不一样(配置文件被修改过),也会跳转到重读配置文件的代码。

重新读取配置文件的代码主要做三件事:

第一,以第一个参数snd_config_t * top为参数调用snd_config_top(top);

第二,打开local中保存的每一个配置文件,并调用 snd_config_load(top,in),其中in是snd_input_t类型,是alsa内部定义的结构,代表输入流; 

第三,snd_config_hooks(top,NULL);

 

 

+++++++++++++++++++++++++++++++++++++++

暂时分析到这里,未完待续。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值