您的位置:首页 > 其它

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

2012-11-17 20:04 176 查看
/article/1912336.html

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

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

├── alsa.conf
├── cards
│ └── aliases.conf
└── pcm
├── center_lfe.conf
├── default.conf
├── dmix.conf
├── dpl.conf
├── dsnoop.conf
├── front.conf
├── iec958.conf
├── modem.conf
├── rear.conf
├── side.conf
├── surround40.conf
├── surround41.conf
├── surround50.conf
├── surround51.conf
└── surround71.conf

service asound_conf /system/bin/alsa_ctl restore
oneshot

service asound_conf /system/bin/alsa_ctl restore
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处开始说起:

[cpp]
view plaincopyprint?

int snd_pcm_open(snd_pcm_t **pcmp, const char *name,
snd_pcm_stream_t stream, int mode)
{
int err;
assert(pcmp && name);
err = snd_config_update();
if (err < 0)
return err;
return snd_pcm_open_noupdate(pcmp, snd_config, name, stream, mode, 0);
}

[cpp]
view plaincopyprint?

/**
* /brief Updates a configuration tree by rereading the configuration files (if needed).
* /param _top Address of the handle to the top level node.
* /param _update Address of a pointer to private update information.
* /param cfgs A list of configuration file names, delimited with ':'.
*             If /p cfgs is set to /c NULL, the default global configuration
*             file is used ("/usr/share/alsa/alsa.conf").
* /return A non-negative value if successful, otherwise a negative error code.
* /retval 0 No action is needed.
* /retval 1 The configuration tree has been rebuilt.
*
* The global configuration files are specified in the environment variable
* /c ALSA_CONFIG_PATH.
*
* /warning If the configuration tree is reread, all string pointers and
* configuration node handles previously obtained from this tree become invalid.
*/
int snd_config_update_r(snd_config_t **_top, snd_config_update_t **_update, const char *cfgs)
{
int err;
const char *configs, *c;
unsigned int k;
size_t l;
snd_config_update_t *local;
snd_config_update_t *update;
snd_config_t *top;
assert(_top && _update);
top = *_top;
update = *_update;
configs = cfgs;
if (!configs) {
configs = getenv(ALSA_CONFIG_PATH_VAR);
if (!configs || !*configs)
configs = ALSA_CONFIG_PATH_DEFAULT;
}
//...............
}

/**
* /brief Updates a configuration tree by rereading the configuration files (if needed).
* /param _top Address of the handle to the top level node.
* /param _update Address of a pointer to private update information.
* /param cfgs A list of configuration file names, delimited with ':'.
*             If /p cfgs is set to /c NULL, the default global configuration
*             file is used ("/usr/share/alsa/alsa.conf").
* /return A non-negative value if successful, otherwise a negative error code.
* /retval 0 No action is needed.
* /retval 1 The configuration tree has been rebuilt.
*
* The global configuration files are specified in the environment variable
* /c ALSA_CONFIG_PATH.
*
* /warning If the configuration tree is reread, all string pointers and
* configuration node handles previously obtained from this tree become invalid.
*/
int snd_config_update_r(snd_config_t **_top, snd_config_update_t **_update, const char *cfgs)
{
int err;
const char *configs, *c;
unsigned int k;
size_t l;
snd_config_update_t *local;
snd_config_update_t *update;
snd_config_t *top;
assert(_top && _update);
top = *_top;
update = *_update;
configs = cfgs;
if (!configs) {
configs = getenv(ALSA_CONFIG_PATH_VAR);
if (!configs || !*configs)
configs = ALSA_CONFIG_PATH_DEFAULT;
}
//...............
}


参数一和二: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.

[cpp]
view plaincopyprint?

/** The name of the default files used by #snd_config_update. */
#define ALSA_CONFIG_PATH_DEFAULT ALSA_CONFIG_DIR "/alsa.conf"

#define ALSA_CONFIG_DIR "/usr/share/alsa"

/** The name of the default files used by #snd_config_update. */
#define ALSA_CONFIG_PATH_DEFAULT ALSA_CONFIG_DIR "/alsa.conf"
#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);

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

暂时分析到这里,未完待续。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: