ALSA Analysis: Alsa profiles (1)

Source: Internet
Author: User
Tags assert

Under the root file system, the ALSA related configuration files are:

Under the/system/usr/share/alsa directory:

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

And

/system/etc/asound.state

How these configuration files work.

Alsa-lib how these scripts are parsed.

Top app is how to achieve different needs of the channel selection, volume adjustment, etc. ... For example, phone/audio/bluetooth headset input/out speaker input during the use of mobile phones ....

These configuration scripts are analyzed separately below.

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

"/system/etc/asound.state"

Asound.state is used to control the initial settings of the audio channel. How to use:

1 Use the Alsa_ctl store to export the initial settings of the current audio to the Asound.state file.

2 Modify the contents of the file: set the playback/recording channel, gain and so on.

3 Reload the modified configuration with Alsa_ctl restore.

4 Add a row to the Init.rc for system startup to automatically load this configuration:

Service Asound_conf/system/bin/alsa_ctl Restore OneShot

The information in the asound.state is the information that extracts the Snd_controls registered in the driver.

"/system/usr/share/alsa/alsa.conf"

Here the main reference finishing http://hi.baidu.com/zmjdx/blog/item/35d570347a36e947241f1475.html

The ALSA configuration file alsa.conf defines some simple syntax that records ALSA environment variables.

The file at the beginning contains the hooks that the user can configure.

User-defined configuration information can be stored in/etc/asound.conf or ~/.ASOUNDRC, and of course it can be defined in its own place.

We are interested in how Alsa lib resolves these configurations.

First we can start by using Alsa Lib, the first entry function Snd_pcm_open:

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); }

Where the function snd_config_update () is invoked, which loads the configuration information in the ALSA configuration file.

This function directly calls the Snd_config_update_r, see the following function comment:

/** */brief Updates a configuration tree by rereading the configuration files (if needed). */param _top address of the "handle" to "top level node." */param _update Address of the 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 is reread, all string pointers and * Configuration node handles previously From that tree become invalid. * * int Snd_config_update_r (snd_config_t **_top, snd_config_update_t **_update, const char *CFGS) {int err; const char *co Nfigs, *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; /............... }  

Parameters one and two: Snd_config, snd_config_global_update are global variables, defined in CONF.C.

The third parameter, CFGs, is the string that contains the configuration file name, and is null when Snd_config_update calls it without passing the argument.

Snd_config_udpate_r first analyzes the third parameter cfgs, if empty, gets the system environment variable Alsa_config_path_var value, if or is empty, takes the Alsa_config_path_default.

/** 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"

Then extract the name of the file in CFGs.

Note CFGs can contain multiple file names, separated by: or spaces. The file information for each file is saved in the snd_config_update_t variable local, and its member count records how many files there are, and Finfo is the corresponding file information list.

Next, analyze the second parameter update, if the parameter value is null (previously mentioned, first is empty), read the configuration file again, otherwise, compared to the local variables, if found to be different (the configuration file has been modified), will also jump to reread the configuration file code.

The code that re-read the configuration file mainly does three things:

First, call Snd_config_top (top) with the first parameter snd_config_t * top;

Second, open each configuration file saved in the local, and call Snd_config_load (Top,in), where in is the snd_input_t type, is the ALSA internally defined structure that represents the input stream;

Third, snd_config_hooks (Top,null);

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

The analysis is here for the time being.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.