Sophie

Sophie

distrib > Mandriva > 2010.1 > i586 > by-pkgid > 34546d63baef3ab2a7675f37737b66ab > files > 34

libalsa2-docs-1.0.23-2.1mdv2010.1.i586.rpm

<!-- This comment will put IE 6, 7 and 8 in quirks mode -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>ALSA project - the C library reference: External Control Plugin SDK</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javaScript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body onload='searchBox.OnSelectItem(0);'>
<!-- Generated by Doxygen 1.6.3 -->
<script type="text/javascript"><!--
var searchBox = new SearchBox("searchBox", "search",false,'Search');
--></script>
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li class="current"><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <img id="MSearchSelect" src="search/search.png"
             onmouseover="return searchBox.OnSearchSelectShow()"
             onmouseout="return searchBox.OnSearchSelectHide()"
             alt=""/>
        <input type="text" id="MSearchField" value="Search" accesskey="S"
             onfocus="searchBox.OnSearchFieldFocus(true)" 
             onblur="searchBox.OnSearchFieldFocus(false)" 
             onkeyup="searchBox.OnSearchFieldChange(event)"/>
        <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
        </div>
      </li>
    </ul>
  </div>
</div>
<div class="contents">


<h1><a class="anchor" id="ctl_external_plugins">External Control Plugin SDK </a></h1><h2><a class="anchor" id="ctl_externals">
External Control Plugins</a></h2>
<p>The external plugins are implemented in a shared object file located at /usr/lib/alsa-lib (the exact location depends on the build option and asoundrc configuration). It has to be the file like libasound_module_ctl_MYPLUGIN.so, where MYPLUGIN corresponds to your own plugin name.</p>
<p>The entry point of the plugin is defined via <a class="el" href="group___ctl_plugin___s_d_k.html#ga13e494fe5c6068d6608a974f5a62a430">SND_CTL_PLUGIN_DEFINE_FUNC()</a> macro. This macro defines the function with a proper name to be referred from alsa-lib. The function takes the following 5 arguments: </p>
<div class="fragment"><pre class="fragment">int (<a class="code" href="group___control.html#ga06628f38def84a0fe3da74041db9d51f">snd_ctl_t</a> **phandle, <span class="keyword">const</span> <span class="keywordtype">char</span> *name, <a class="code" href="group___config.html#ga1c20905af775ae77d04d1a5696f67985" title="Internal structure for a configuration node object.">snd_config_t</a> *root,
        <a class="code" href="group___config.html#ga1c20905af775ae77d04d1a5696f67985" title="Internal structure for a configuration node object.">snd_config_t</a> *conf, <span class="keywordtype">int</span> mode)
</pre></div><p> The first argument, phandle, is the pointer to store the resultant control handle. The arguments name, root and mode are the parameters to be passed to the plugin constructor. The conf is the configuration tree for the plugin. The arguments above are defined in the macro itself, so don't use variables with the same names to shadow parameters.</p>
<p>After parsing the configuration parameters in the given conf tree, usually you will call the external plugin API function <a class="el" href="group___ctl_plugin___s_d_k.html#ga317775f9c5e239781e71735ca5ba1ca6" title="Create an external control plugin instance.">snd_ctl_ext_create()</a>. The control handle must be filled *phandle in return. Then this function must return either a value 0 when succeeded, or a negative value as the error code.</p>
<p>Finally, add <a class="el" href="group___ctl_plugin___s_d_k.html#gaa94fc65e8951f16e4b273b0f81e90f7e">SND_CTL_PLUGIN_SYMBOL()</a> with the name of your plugin as the argument at the end. This defines the proper versioned symbol as the reference.</p>
<p>The typical code would look like below: </p>
<div class="fragment"><pre class="fragment"><span class="keyword">struct </span>myctl_info {
        snd_ctl_ext_t ext;
        <span class="keywordtype">int</span> my_own_data;
        ...
};

<a class="code" href="group___ctl_plugin___s_d_k.html#ga13e494fe5c6068d6608a974f5a62a430">SND_CTL_PLUGIN_DEFINE_FUNC</a>(myctl)
{
        <a class="code" href="group___config.html#ga6c621ab8875a222e1fcb56e9feed6ec6" title="Type for a configuration compound iterator.">snd_config_iterator_t</a> i, next;
        <span class="keyword">struct </span>myctl_info *myctl;
        <span class="keywordtype">int</span> err;

        <a class="code" href="group___config.html#gac3f21333e1f9b602cad9b06cb418fa80" title="Helper macro to iterate over the children of a compound node.">snd_config_for_each</a>(i, next, conf) {
                <a class="code" href="group___config.html#ga1c20905af775ae77d04d1a5696f67985" title="Internal structure for a configuration node object.">snd_config_t</a> *n = <a class="code" href="group___config.html#gaa91fe1d926d88041ed516a6a7293f606" title="Returns the configuration node handle pointed to by an iterator.">snd_config_iterator_entry</a>(i);
                <span class="keyword">const</span> <span class="keywordtype">char</span> *id;
                <span class="keywordflow">if</span> (<a class="code" href="group___config.html#gae366751e8ea98aeb69f9ef876f7b949c" title="Returns the id of a configuration node.">snd_config_get_id</a>(n, &amp;<span class="keywordtype">id</span>) &lt; 0)
                        <span class="keywordflow">continue</span>;
                <span class="keywordflow">if</span> (strcmp(<span class="keywordtype">id</span>, <span class="stringliteral">&quot;comment&quot;</span>) == 0 || strcmp(<span class="keywordtype">id</span>, <span class="stringliteral">&quot;type&quot;</span>) == 0)
                        <span class="keywordflow">continue</span>;
                <span class="keywordflow">if</span> (strcmp(<span class="keywordtype">id</span>, <span class="stringliteral">&quot;my_own_parameter&quot;</span>) == 0) {
                        ....
                        <span class="keywordflow">continue</span>;
                }
                <a class="code" href="group___error.html#ga281420eb1344fe9f01d67d20c92457f0">SNDERR</a>(<span class="stringliteral">&quot;Unknown field %s&quot;</span>, <span class="keywordtype">id</span>);
                <span class="keywordflow">return</span> -EINVAL;
        }

        myctl = calloc(1, <span class="keyword">sizeof</span>(*myctl));
        <span class="keywordflow">if</span> (myctl == NULL)
                <span class="keywordflow">return</span> -ENOMEM;

        myctl-&gt;ext.version = <a class="code" href="group___ctl_plugin___s_d_k.html#ga65ea29f84b09ee3e640f88b06d05a1a2">SND_CTL_EXT_VERSION</a>;
        myctl-&gt;ext.card_idx = 0;
        strcpy(myctl-&gt;ext.id, <span class="stringliteral">&quot;Myctl&quot;</span>);
        strcpy(myctl-&gt;ext.name, <span class="stringliteral">&quot;My Control&quot;</span>);
        strcpy(myctl-&gt;ext.longname, <span class="stringliteral">&quot;My External Control for Foobar&quot;</span>);
        strcpy(myctl-&gt;ext.mixername, <span class="stringliteral">&quot;My Control&quot;</span>);
        myctl-&gt;ext.callback = &amp;my_own_callback;
        myctl-&gt;ext.private_data = myctl;
        ....

        err = <a class="code" href="group___p_c_m___ext_plug.html#gab0b27889f74c83cd033062981320fd62" title="Create an extplug instance.">snd_pcm_extplug_create</a>(&amp;myctl-&gt;ext, name, mode);
        <span class="keywordflow">if</span> (err &lt; 0) {
                myctl_free(myctl);
                <span class="keywordflow">return</span> err;
        }

        *phandle = myctl-&gt;ext.handle;
        <span class="keywordflow">return</span> 0;
}

<a class="code" href="group___ctl_plugin___s_d_k.html#gaa94fc65e8951f16e4b273b0f81e90f7e">SND_CTL_PLUGIN_SYMBOL</a>(myctl);
</pre></div><p>Read the codes in alsa-plugins package for the real examples.</p>
<h2><a class="anchor" id="ctl_ext_impl">
Implementation of External Control Plugins</a></h2>
<p>The following fields have to be filled in external control record before calling <a class="el" href="group___ctl_plugin___s_d_k.html#ga317775f9c5e239781e71735ca5ba1ca6" title="Create an external control plugin instance.">snd_ctl_ext_create()</a> : version, card_idx, id, name, longname, mixername, poll_fd and callback. Otherfields are optional and should be initialized with zero.</p>
<p>The constant <a class="el" href="group___ctl_plugin___s_d_k.html#ga65ea29f84b09ee3e640f88b06d05a1a2">SND_CTL_EXT_VERSION</a> must be passed to the version field for the version check in alsa-lib. The card_idx field specifies the card index of this control. [FIXME: solve confliction of card index in alsa-lib?]</p>
<p>The id, name, longname and mixername fields are the strings shown in the card_info inqurirys. They are the char arrays, so you have to <em>copy</em> strings to these fields.</p>
<p>The callback field contains the table of callback functions for this plugin (defined as snd_ctl_ext_callback_t). The poll_fd can be used to specify the poll file descriptor for this control. Set -1 if not available. Alternatively, you can define poll_descriptors_count and poll_descriptors callbacks in the callback table for handling the poll descriptor(s) dynamically after the creation of plugin instance.</p>
<p>The driver can set an arbitrary value (pointer) to private_data field to refer its own data in the callbacks.</p>
<p>The rest fields are filled by <a class="el" href="group___ctl_plugin___s_d_k.html#ga317775f9c5e239781e71735ca5ba1ca6" title="Create an external control plugin instance.">snd_ctl_ext_create()</a>. The handle field is the resultant PCM handle. The others are the current status of the PCM.</p>
<h2><a class="anchor" id="ctl_ext_impl">
Implementation of External Control Plugins</a></h2>
<p>The callback functions in snd_ctl_ext_callback_t define the real behavior of the driver. There are many callbacks but many of them are optional.</p>
<p>The close callback is called when the PCM is closed. If the plugin allocates private resources, this is the place to release them again. This callback is optional.</p>
<p>The elem_count and elem_list callbacks are mandatory. The elem_count returns the total number of control elements. The elem_list returns the control element ID of the corresponding element offset (the offset is from 0 to elem_count - 1). The id field is initialized to all zero in prior to elem_list callback. The callback has to fill the necessary field (typically iface, name and index) in return via the standard control API functions like <a class="el" href="group___control.html#ga33855eaf0261c321cbf0a88baf290418" title="Set interface part for a CTL element identifier.">snd_ctl_elem_id_set_interface</a>, <a class="el" href="group___control.html#ga813d02a44a9d01a4a2fe81eda7a8670a" title="Set name part for a CTL element identifier.">snd_ctl_elem_id_set_name</a> and <a class="el" href="group___control.html#ga65af30a51becd092f6da1e357fc46094" title="Set index part for a CTL element identifier.">snd_ctl_elem_id_set_index</a>, etc. The callbacks should return 0 if successful, or a negative error code.</p>
<p>The find_elem callback is used to convert the given control element ID to the certain key value for the faster access to get, read and write callbacks. The key type is alias of unsigned long, so you can assign some static number (e.g. index of the array) to this value of the corresponding element, or assign the pointer (cast to <a class="el" href="group___ctl_plugin___s_d_k.html#gac73a66a3973afb51c4e585177647c693">snd_ctl_ext_key_t</a>). When no key is defined or found, return <a class="el" href="group___ctl_plugin___s_d_k.html#gac1f0737189a30bbb1e4dcbf681df39fd">SND_CTL_EXT_KEY_NOT_FOUND</a>. This callback is (very likely) required if you use get, read and write callbacks as follows. If you need to create a record dynamically (e.g. via malloc) at each find_elem call, the allocated record can be released with the optional free_key callback.</p>
<p>The get_attribute is a mandatory callback, which returns the attribute of the control element given via a key value (converted with find_elem callback). It must fill the control element type (<a class="el" href="group___control.html#gac42e0ed6713b62711af5e80b4b3bcfec">snd_ctl_elem_type_t</a>), the access type (<a class="el" href="group___ctl_plugin___s_d_k.html#gaeedd1d7413b3025e9cede1b27e509de5">snd_ctl_ext_access_t</a>), and the count (element array size). The callback returns 0 if successful, or a negative error code, as usual.</p>
<p>The get_integer_info, get_integetr64_info and get_enumerated_info callbacks are called to return the information of the given control element for each element type. For integer and integer64 types, the callbacks need to fill the minimal (imin), maximal (imax) and the step (istep) values of the control. For the enumerated type, the number of enum items must be filled. Additionally, the enum control has to define get_enumerated_name callback to store the name of the enumerated item of the given control element. All functions return 0 if successful, or a negative error code.</p>
<p>For reading the current values of a control element, read_integer, read_integer64, read_enumerated, read_bytes and read_iec958 callbacks are called depending on the element type. These callbacks have to fill the current values of the element in return. Note that a control element can be an array. If it contains more than one values (i.e. the count value in get_attribute callback is more than 1), <em>all</em> values must be filled on the given value pointer as an array. Also, note that the boolean type is handled as integer here (although boolean type doesn't need to define the corresponding info callback since it's obvious). These callbacks return 0 if successful, or a negative error code.</p>
<p>For writing the current values, write_integer, write_integer64, write_bytes, and write_iec958 callbacks are called as well as for read. The callbacks should check the current values and compare with the given values. If they are identical, the callbacks should do nothing and return 0. If they differ, update the current values and return 1, instead. For any errors, return a negative error code.</p>
<p>The subscribe_events callback is called when the application subscribes or cancels the event notifications (e.g. through mixer API). The current value of event subscription is kept in the subscribed field. The read_event callback is called for reading a pending notification event. The callback needs to fill the event_mask value, a bit-field defined as SND_CTL_EVENT_MASK_XXX. If no event is pending, return -EAGAIN. These two callbacks are optional.</p>
<p>The poll_descriptors_count and poll_descriptors callbacks are used to return the poll descriptor(s) via callbacks. As already mentioned, if the callback cannot set the static poll_fd, you can define these callbacks to return dynamically. Also, when multiple poll descriptors are required, use these callbacks. The poll_revents callback is used for handle poll revents. </p>
</div>
<!--- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&nbsp;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&nbsp;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&nbsp;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&nbsp;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&nbsp;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&nbsp;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&nbsp;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&nbsp;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&nbsp;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<hr class="footer"/><address style="text-align: right;"><small>Generated on Sat Nov 20 07:42:24 2010 for ALSA project - the C library reference by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
</body>
</html>