alsa分析:alsa的那些配置文件 ( 1 )
2017-05-20 15:02
369 查看
http://blog.csdn.net/doom66151/article/details/6573176
在根文件系统下,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
[c-sharp] view
plain copy
├── 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
和
/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中添加一行,用于系统启动是自动加载此配置:
service asound_conf /system/bin/alsa_ctl restore
oneshot
[c-sharp] view
plain copy
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
plaincopy
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
plain copy
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);
}
其中调用了函数snd_config_update(),这个函数就是加载alsa的配置文件中配置信息的。
这个函数直接调用了 snd_config_update_r,见下面函数注释:
[cpp] view
plaincopy
/**
* /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;
}
//...............
}
[cpp] view
plain copy
/**
* /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
plaincopy
/** 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"
[cpp] view
plain copy
/** 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);
+++++++++++++++++++++++++++++++++++++++
暂时分析到这里,未完待续。
在根文件系统下,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
[c-sharp] view
plain copy
├── 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
和
/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中添加一行,用于系统启动是自动加载此配置:
service asound_conf /system/bin/alsa_ctl restore
oneshot
[c-sharp] view
plain copy
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
plaincopy
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
plain copy
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);
}
其中调用了函数snd_config_update(),这个函数就是加载alsa的配置文件中配置信息的。
这个函数直接调用了 snd_config_update_r,见下面函数注释:
[cpp] view
plaincopy
/**
* /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;
}
//...............
}
[cpp] view
plain copy
/**
* /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
plaincopy
/** 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"
[cpp] view
plain copy
/** 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);
+++++++++++++++++++++++++++++++++++++++
暂时分析到这里,未完待续。
相关文章推荐
- alsa分析:alsa的那些配置文件 ( 2 )
- alsa分析:alsa的那些配置文件 ( 2 )
- alsa分析:alsa的那些配置文件1
- alsa分析:alsa的那些配置文件1
- alsa分析:alsa的那些配置文件 ( 2 )
- alsa分析:alsa的那些配置文件2
- alsa分析:alsa的那些配置文件2
- alsa分析:alsa的那些配置文件 ( 1 )
- alsa分析:alsa的那些配置文件 ( 1 )
- struts简单例子的分析(含代码注释和配置文件说明)
- Struts2.0配置文件的加载分析
- struts2配置文件加载流程分析
- Fetion分析之二:服务器地址从何而来——变态的配置文件(转)
- [原创]ALSA 音频系统源代码分析: ALSA library 分析 --- 配置系统(二)
- 蔡军生先生第二人生的源码分析(六十九)使用LLXmlTree类来分析XML配置文件
- 人物技能栏配置文件的数据分析(密传)
- svn权限配置文件(authz)分析
- 理解和使用Alsa的配置文件
- struts中log4j日志文件的相对路径配置实例分析
- Oracle管理与维护.配置文件的简要分析