Detailed changes v1.1.1 v1.1.2

From AlsaProject
Jump to: navigation, search

Contents

Detailed changelog between 1.1.1 and 1.1.2 releases

Changelog between 1.1.1 and 1.1.2 releases

alsa-lib

Core

- Release v1.1.2
- pcm: Remove home brew atomic operations
We've had a few home brew atomic operations in a couple of places in
the PCM code. This was for supporting the concurrent accesses, but in
practice, it couldn't cover the race properly by itself alone.
Since we have a wider concurrency protection via mutex now, we can get
rid of these atomic codes, which worsens the portability
significantly.
- pcm: Add thread-safety to PCM API
Traditionally, many of ALSA library functions are supposed to be
thread-unsafe, and applications are required to take care of thread
safety by themselves. However, people never be careful enough, and
almost all applications fail in this regard.
This patch is an attempt to harden the thread safety in exported PCM
functions in a simplistic way: just wrap some of exported functions
with the pthread mutex of each PCM object. Not all API functions are
wrapped by the mutex since it doesn't make sense. Instead, the
patchset covers only the functions that may be likely called
concurrently. The supposedly thread-safe API functions are marked in
the document.
For achieving the feature, two new fields are added snd_pcm_t when the
option is enabled: thread_safe and lock. The former indicates that
the plugin is thread-safe that doesn't need this workaround and the
latter is the pthread mutex. Currently only hw plugin have
thread_safe=1. So, the most of real-time sensitive apps won't be
influenced by this patchset.
Although the patch covers most of PCM ops, a few snd_pcm_fast_ops are
left without the extra mutex locking: namely, the ones that may have
blocking behavior, i.e. resume, drain, readi, writei, readn and
writen. These are supposed to handle own locking in the callbacks.
Also, if anyone wants to disable this new thread-safe API feature, it
can be still turned off via --disable-thread-safety configure option.
- conf/ucm: chtrt5645: Add UCM config for chtrt5645
Add a UCM configuration for the rt5645 codec on Intel's Cherry-Trail
platform. Tested on the Microsoft Surface 3.
- conf/ucm: ROCKCHIP-I2S: rename to VEYRON-I2S
Commit a192f52fc63a introduced an ucm profile for Rockchip Veyron-
Chromebooks by taking the ucm profile from the ChromeOS userspace.
But similarly to DAISY-I2S, PAZ00 and most other profiles, the audio
setup is pretty specific to a board type, so hogging the Rockchip name
will make it harder for future Rockchip based boards to fit in nicely.
And while Veyron also is a family of boards, all of them share the
same audio setup. The ucm profile was not released with any official
alsa release and the audio setup also isn't in the mainline kernel yet,
so such a rename should be easily possible.
Fixes: a192f52fc63a ("conf/ucm: ROCKCHIP-I2S: add Rockchip I2S UCM config.")
- conf/ucm: ROCKCHIP-I2S: add Rockchip I2S UCM config.
Taken from the ChromeOS sources, this configuration was tested on Veyron
Jerry based Chromebook from Google.
[Added missing Makefile changes by tiwai]
- conf: topology: Generate Private data binary blobs
The DSP modules need private data and that is provided as binary
blob. These blobs are compiled from C structures which specify module
configuration.
- conf: topology: Add Skylake i2s conf
The Skylake topology configuration for simple topology graph is
provided. This exposes the PCM capabilities of the DSP.

Config API

- conf: Add thread-safe global tree reference
Most of open functions in alsa-lib have the call pattern:
snd_config_update();
return snd_xxx_open(x, snd_config, ...);
This means that the toplevel config gets updated, and passed to a
local open function. Although snd_config_update() itself has a
pthread mutex to be thread safe, the whole procedure above isn't
thread safe. Namely, the global snd_config tree may be deleted and
recreated at any time while the open function is being processed.
This may lead to a data corruption and crash of the program.
For avoiding the corruption, this patch introduces a refcount to
config tree object. A few new helper functions are introduced as
well:
- snd_config_update_ref() does update and take the refcount of the
toplevel tree. The obtained config tree has to be freed via
snd_config_unref() below.
- snd_config_ref() and snd_config_unref() manage the refcount of the
config object. The latter eventually deletes the object when all
references are gone.
Along with these additions, the caller of snd_config_update() and
snd_config global tree in alsa-lib are replaced with the new helpers.

Control API

- ctl: use condition statements instead of assert() for new APIs to add an element set
Usage of assert() is not better practice of programming as shared library
APIs. They should return appropriate error code to promote applications to
handle error state.
This commit applies condition statements with return value of -EINVAL,
instead of assert(). As a backward compatibility for existent applications,
old APIs still call assert().
- ctl: rename APIs to add an element set so that their names are appropriate
In this development period, some APIs have already been added. Most of
them are to add an element set, while their names are not so appropriate
against their feature. This is due to following to names of old APIs.
This commit renames them.
- ctl: add compatibility information for snd_ctl_elem_info_set_dimension()
I forgot it when committing to the API.
Fixes: 16812b70daeb('ctl: add an API to set dimension levels to element information')
- hctl: remove assertion from element event handler because removal event overwrites all of queued events
In ALSA control core, when several events occurs for an element, they're
represented bit mask (struct snd_ctl_event.data.elem.mask). Thus userspace
applications can handles these events separately in one I/O operation.
There's an exception; removal event. This is represented by all of bits in
the mask. Therefore, when a removal event occurs for an element, all of
queued events for the element are overwritten.
This works worse for a combination of applications which add/remove control
elements and applications which keep a cache of elements. For example,
let's assume a case that:
1.some elements are added by ioctl(SNDRV_CTL_IOCTL_ELEM_ADD).
2.ALSA control core handles the request and queues 'add' event.
3.applications don't read the event yet.
4.the elements are removed by ioctl(SNDRV_CTL_IOCTL_ELEM_REMOVE)
5.ALSA control core handles the request and queues 'removal' event by
overwriting queued events.
6.applications read the event at last.
7.the applications cannot find removed elements in their cache data.
Especially, when applications use hctl interface of ALSA userspace library,
this situation occurs because the interface is designed to keep element
cache implicitly inner the library. PulseAudio is such an application. When
executing a test program of ALSA library (test/user-ctl-element-set.c),
pulseaudio process aborts due to assertion at calls of
snd_hctl_handle_events().
The rule to represent events is in ALSA kernel/userspace interfaces
(UAPI header) and it's difficult to improve the rule. Therefore,
developers should pay enough attention to the fact that userspace
applications can receive removal events for elements which are not
notified with 'add' event.
For this reason, this commit removes assertion from event handler of ALSA
hctl API.
- ctl: improve documentation of APIs to add an element set
Currently, documentation of APIs to add an element set describes causes of
errors partly. But it gives an opinion to describe them thoroughly. This
is not good for users.
This commit changes the documentation so that it partly describes the
causes.
- ctl: add dimension validator
Linux 4.7 or former have no validator of dimension information. This can
causes an issue related to user-defined element set. For example, When
calculated total members in multi-dimensional matrix is larger than actual
capacity of snd_ctl_elem_value_t, processes to handle the element can
cause buffer-over-run.
For backward portability of this userspace library, this commit adds a
validator of dimension information. When userspace applications give
invalid dimension information to APIs to add element set, they receive
-EINVAL.
- ctl: add an API to set dimension levels to element information
In a former commit, 'struct snd_ctl_elem_info' is used as a 'container' to
transfer extra fields of element information for APIs to add an element
set. The extra fields should be filled in advance of call of the APIs.
Currently, dimension level is in the extra fields and no APIs to set it.
This commit adds an API to set dimension level to the information
structure. This API is expected to be used in advance of usage of APIs
to add an element set, for nothing others. When the information structure
is extended in future, then the similar APIs shall be added for the new
feature.
- ctl: support extra information to user-defined element set
In ALSA control feature, information of an element includes extra fields
to type-specific parameters; i.e. dimension. The fields can be extended in
future.
Meanwhile, current APIs to add user-defined element set can not support
such an extended fields. This may cause inconveniences in future.
This commit supports the fields, by changing APIs for element set.
- ctl: use consistent name for second argument of snd_ctl_elem_read/write
Second argument of these functions has three different names in
documentation/header/code (obj/control/value). This easily causes users'
confusion.
This commit applies consistent names for the arguments.
Fixes: 90020c05f886 ('ctl: improve comments for handling element data')
- ctl: use automatic variable instead of call of alloca(3)
Inner this library, layouts of all structures are public. At a compilation
time, each size of the structures can be calculated. It means that we can
use automatic variable instead of calling alloca(3) to program this
library because in both ways storages are kept on stack frame of process
VMA. Besides, the usage of automatic variables requires less instructions
than calls of alloca(3). Furthermore, alloca(3) is not described in any
C language standards.
This commit replaces calls of alloca(3) just for structures with automatic
variables, for control features.
- ctl: fix returning zero for dimension level 4
In ALSA kernel/userspace interfaces, 'struct snd_ctl_elem_info' has a
'dimension' parameter. This parameter consists of an array with four
elements. Each element represents the number of members in corresponding
dimension level to construct matrix.
In current implementation, a get function, 'snd_ctl_elem_info_get_dimension()'
is hardcoded to return zero to level 4, against actual value. This commit fixes
the bug.
- ctl: improve API documentation for threshold level operations
In alsa-lib, threshold level operations require an array of unsigned-int
members, while there's little explanation about how to fill it. To usual
developers such as me, they're quite hard to understand.
This commit adds a few comment for easy understanding about how to use
the APIs.
- ctl: add explanation about threshold level feature
ALSA ctl feature includes threshold level feature. This is introduced in
2006, and there's little resources about it.
This commit adds a simple explanation about the feature.
- ctl: change former APIs as wrapper functions of element set APIs
In former commit, userspace library gets some APIs for element set. Some
existed functions can be simple wrappers of them.
This commit changes these APIs as wrapper functions. Additionally, this
commit also adds local variables for identical information of elements.
This modification is important to keep API consistency.
Some old APIs to add an element have id variables with const type
qualifier, while some new APIs to add element set changes the content of
given parameters. This comes from a change in Linux kernel 4.1.
In this commit [1], in-kernel implementation fills all fields of identical
data in userspace. As a result, when adding a new element set, userspace
applications can get an identical data for the first element in the set.
This lost the semantics of const type qualifier in userspace.
[1] http://git.kernel.org/cgit/linux/kernel/git/tiwai/sound.git/commit/sound/core?id=cab2ed7474bffafd2a68a885e03b85526194abcd
- ctl: improve comments for API to add an element of IEC958 type
In ALSA control core, it's not allowed to an element set of IEC 958 type
to have several elements. Therefore, consecutive patchset doesn't touch an
API to add an element of IEC958 type. However, it's better to supplement
comments for the API.
This commit do it.
- ctl: add functions to add an element set
ALSA control core allows userspace applications to add an element set.
However, in ALSA userspace library, there's no APIs enough to utilize
the feature. The library has APIs just to add an element set with a single
element.
This commit adds functions to add an element set with several elements.
- ctl: improve comments for handling element data
Some parts of control API documentation are described with core-developer
friendly explanations. To usual developer such as me, they're quite hard
to understand.
This commit improves such comments for a part of APIs to handle data of
each element.
- ctl: add an overview for design of ALSA control interface
This commit adds a description about the design of ALSA control interface
for developers to understand a few components of low level.
- conf: Add thread-safe global tree reference
Most of open functions in alsa-lib have the call pattern:
snd_config_update();
return snd_xxx_open(x, snd_config, ...);
This means that the toplevel config gets updated, and passed to a
local open function. Although snd_config_update() itself has a
pthread mutex to be thread safe, the whole procedure above isn't
thread safe. Namely, the global snd_config tree may be deleted and
recreated at any time while the open function is being processed.
This may lead to a data corruption and crash of the program.
For avoiding the corruption, this patch introduces a refcount to
config tree object. A few new helper functions are introduced as
well:
- snd_config_update_ref() does update and take the refcount of the
toplevel tree. The obtained config tree has to be freed via
snd_config_unref() below.
- snd_config_ref() and snd_config_unref() manage the refcount of the
config object. The latter eventually deletes the object when all
references are gone.
Along with these additions, the caller of snd_config_update() and
snd_config global tree in alsa-lib are replaced with the new helpers.
- namehint: Don't enumerate as duplex if only a single direction is defined
When a hint description has only either device_input or device_output,
we shouldn't handle it as a full duplex but rather a single
direction. In that way, we can avoid to list up a playback stream
like dmix or surround51 as a capture stream in the namehint.
Reported-by: Trent Reed <treed0803@gmail.com>

HWDEP API

- conf: Add thread-safe global tree reference
Most of open functions in alsa-lib have the call pattern:
snd_config_update();
return snd_xxx_open(x, snd_config, ...);
This means that the toplevel config gets updated, and passed to a
local open function. Although snd_config_update() itself has a
pthread mutex to be thread safe, the whole procedure above isn't
thread safe. Namely, the global snd_config tree may be deleted and
recreated at any time while the open function is being processed.
This may lead to a data corruption and crash of the program.
For avoiding the corruption, this patch introduces a refcount to
config tree object. A few new helper functions are introduced as
well:
- snd_config_update_ref() does update and take the refcount of the
toplevel tree. The obtained config tree has to be freed via
snd_config_unref() below.
- snd_config_ref() and snd_config_unref() manage the refcount of the
config object. The latter eventually deletes the object when all
references are gone.
Along with these additions, the caller of snd_config_update() and
snd_config global tree in alsa-lib are replaced with the new helpers.

Mixer API

- mixer: remove alloca() from simple_event_add()
Both of alloca() and automatic variables keep storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- mixer: change code formatting for simple_event_add()
This commit applies code format according to typical and moderate rule.
- mixer: remove alloca() from simple_add1()
Both of alloca() and automatic variables keep storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- mixer: change code formatting for simple_add1()
This commit applies code format according to typical and moderate rule.
- mixer: remove alloca() from set_enum_item_ops()
Both of alloca() and automatic variables keep storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- mixer: remove alloca() from get_enum_item_ops()
Both of alloca() and automatic variables keep storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- mixer: remove alloca() from enum_item_name_ops()
Both of alloca() and automatic variables keep storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- mixer: remove alloca() from init_db_range()
Both of alloca() and automatic variables keep storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- mixer: change code formatting for init_db_range()
This commit applies code format according to typical and moderate rule.
- mixer: remove alloca() from selem_write_main()
Both of alloca() and automatic variables keep storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- mixer: change code formatting for selem_write_main()
This commit applies code format according to typical and moderate rule.
- mixer: remove alloca() from elem_write_route()
Both of alloca() and automatic variables keep storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- mixer: change code formatting for elem_write_route()
This commit applies code format according to typical and moderate rule.
- mixer: remove alloca() from elem_write_enum()
Both of alloca() and automatic variables keep storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- mixer: change code formatting for elem_write_enum()
This commit applies code format according to typical and moderate rule.
- mixer: remove alloca() from elem_write_switch_constant()
Both of alloca() and automatic variables keep storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- mixer: remove alloca() from elem_write_switch()
Both of alloca() and automatic variables keep storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- mixer: change code formatting for elem_write_switch()
This commit applies code format according to typical and moderate rule.
- mixer: remove alloca() from elem_write_volume()
Both of alloca() and automatic variables keep storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- mixer: change code formatting for elem_write_volume()
This commit applies code format according to typical and moderate rule.
- mixer: remove alloca() from selem_read()
Both of alloca() and automatic variables keep storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- mixer: change code formatting for selem_read()
This commit applies code format according to typical and moderate rule.
- mixer: remove alloca() from elem_read_enum()
Both of alloca() and automatic variables keep storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- mixer: change code formatting for elem_read_enum()
This commit applies code format according to typical and moderate rule.
- mixer: remove alloca() from elem_read_route()
Both of alloca() and automatic variables keep storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- mixer: change code formatting for elem_read_route()
This commit applies code format according to typical and moderate rule.
- mixer: remove alloca() from elem_read_volume()
Both of alloca() and automatic variables keep storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- mixer: change code formatting for elem_read_volume()
This commit applies code format according to typical and moderate rule.
- mixer: include library local header to find layout of structures
Inner this library, implementation of each features can find actual layout
of structures by including local header. Although, mixer feature is written
without the header and as the same way for applications. This brings some
inefficiencies such as usage of alloca() to keep memory objects for the
structures.
This commit includes the header for further improvements in mixer
feature.

PCM API

- ctl: rename APIs to add an element set so that their names are appropriate
In this development period, some APIs have already been added. Most of
them are to add an element set, while their names are not so appropriate
against their feature. This is due to following to names of old APIs.
This commit renames them.
- pcm: remove alloca() from _snd_pcm_softvol_open()
Both of alloca() and automatic variables keeps storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- pcm: change code formatting for _snd_pcm_softvol_open()
This commit applies code format according to typical and moderate rule,
for _snd_pcm_softvol_open().
- pcm: remove alloca() from softvol_load_control()
Both of alloca() and automatic variables keeps storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- pcm: change code formatting for softvol_load_control()
This commit applies code format according to typical and moderate rule,
for softvol_load_control().
- pcm: remove alloca() from snd_spcm_init_duplex()
Both of alloca() and automatic variables keeps storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- pcm: remove alloca() from snd_spcm_init()
Both of alloca() and automatic variables keeps storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- pcm: remove alloca() from snd_pcm_hw_set_chmap()
Both of alloca() and automatic variables keeps storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- pcm: remove alloca() from snd_pcm_hw_get_chmap()
Both of alloca() and automatic variables keeps storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- pcm: remove alloca() from snd_pcm_query_chmaps_from_hw()
Both of alloca() and automatic variables keeps storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- pcm: remove alloca() from snd_pcm_hw_change_timer()
Both of alloca() and automatic variables keeps storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- pcm: change code formatting for snd_pcm_hw_change_timer()
This commit applies code format according to typical and moderate rule,
for snd_pcm_hw_change_timer().
- pcm: remove alloca() from _snd_pcm_hook_ctl_elems_install()
Both of alloca() and automatic variables keeps storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- pcm: remove alloca() from snd_pcm_direct_set_timer_params
Both of alloca() and automatic variables keeps storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- pcm: change code formatting for snd_pcm_direct_set_timer_params()
This commit applies code format according to typical and moderate rule,
for snd_pcm_direct_set_timer_params().
- pcm: remove alloca() from snd_pcm_direct_initialize_poll_fd()
Both of alloca() and automatic variables keeps storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- pcm: change code formatting for snd_pcm_direct_initialize_poll_fd()
This commit applies code format according to typical and moderate rule,
for snd_pcm_direct_initialize_poll_fd().
- pcm: remove alloca() from snd_pcm_direct_initialize_slave
Both of alloca() and automatic variables keeps storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- pcm: change code formatting for snd_pcm_direct_initialize_slave()
This commit applies code format according to typical and moderate rule,
for snd_pcm_direct_initialize_slave().
- pcm: remove alloca() from snd_pcm_get_params
Both of alloca() and automatic variables keeps storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- pcm: change code formatting for snd_pcm_get_params()
This commit applies code format according to typical and moderate rule,
for snd_pcm_get_params().
- pcm: remove alloca() from snd_pcm_set_params()
Both of alloca() and automatic variables keeps storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- pcm: change code formatting for snd_pcm_set_params()
This commit applies code format according to typical and moderate rule,
for snd_pcm_set_params().
- pcm: fix return value of snd_pcm_ioplug_sw_params()
In former commits for thread-safe PCM APIs, snd_pcm_ioplug_sw_params() got
0 as its return value, against the original implementation.
This commit fixes it.
Fixes: 54931e5a5455('pcm: Add thread-safety to PCM API')
- pcm: fix missing return value of snd_pcm_status()
In former commits for thread-safe PCM APIs, snd_pcm_status() lost its
return value.
This commit regain it.
Fixes: 54931e5a5455('pcm: Add thread-safety to PCM API')
- pcm: Add LIBASOUND_THREAD_SAFE env variable check
For making the debugging with any deadlocks by the newly introduced
thread-safety feature, add a check with LIBASOUND_THREAD_SAFE
environment variable. When this variable is set to "0", alsa-lib PCM
forcibly disables the whole thread-safe pthread mutex calls.
- pcm: Remove home brew atomic operations
We've had a few home brew atomic operations in a couple of places in
the PCM code. This was for supporting the concurrent accesses, but in
practice, it couldn't cover the race properly by itself alone.
Since we have a wider concurrency protection via mutex now, we can get
rid of these atomic codes, which worsens the portability
significantly.
- pcm: Add thread-safety to PCM API
Traditionally, many of ALSA library functions are supposed to be
thread-unsafe, and applications are required to take care of thread
safety by themselves. However, people never be careful enough, and
almost all applications fail in this regard.
This patch is an attempt to harden the thread safety in exported PCM
functions in a simplistic way: just wrap some of exported functions
with the pthread mutex of each PCM object. Not all API functions are
wrapped by the mutex since it doesn't make sense. Instead, the
patchset covers only the functions that may be likely called
concurrently. The supposedly thread-safe API functions are marked in
the document.
For achieving the feature, two new fields are added snd_pcm_t when the
option is enabled: thread_safe and lock. The former indicates that
the plugin is thread-safe that doesn't need this workaround and the
latter is the pthread mutex. Currently only hw plugin have
thread_safe=1. So, the most of real-time sensitive apps won't be
influenced by this patchset.
Although the patch covers most of PCM ops, a few snd_pcm_fast_ops are
left without the extra mutex locking: namely, the ones that may have
blocking behavior, i.e. resume, drain, readi, writei, readn and
writen. These are supposed to handle own locking in the callbacks.
Also, if anyone wants to disable this new thread-safe API feature, it
can be still turned off via --disable-thread-safety configure option.
- pcm: add 'default' case for switch statement
This commit fixes below compiler warnings.
pcm_direct.c: In function ‘snd1_pcm_direct_prepare’:
pcm_direct.c:821:2: warning: enumeration value ‘SND_PCM_STATE_PREPARED’ not handled in switch [-Wswitch]
switch (snd_pcm_state(dmix->spcm)) {
^
- pcm: set error code at failure path
This commit fixes below compiler warnings.
pcm_hw.c: In function ‘_snd_pcm_hw_open’:
pcm_hw.c:1816:16: warning: ‘err’ may be used uninitialized in this function [-Wmaybe-uninitialized]
return err;
^
- pcm: Remove superfluous rmb() from PCM meter plugin
rmb() is still left in the code without any actual meaning there just
before the atomic operation. Let's clean it up.
- ctl: support extra information to user-defined element set
In ALSA control feature, information of an element includes extra fields
to type-specific parameters; i.e. dimension. The fields can be extended in
future.
Meanwhile, current APIs to add user-defined element set can not support
such an extended fields. This may cause inconveniences in future.
This commit supports the fields, by changing APIs for element set.
- pcm: use new APIs to add a control element set for softvol plugin
In previous commit, some APIs to add a single element are discouraged to
continue using.
This commit replaces usage of the old APIs with new APIs.
- pcm: dmix: Return error when slave is in OPEN or DISCONNECTED
A slave PCM in OPEN or DISCONNECTED state can't be used properly at
all, so the best option is to return -EBADFD error.
- pcm: dmix: Prepare slave when it's in SETUP, too
SETUP is an unusual state, but it's still possible.
- pcm: dmix: resume workaround for buggy driver
The previous commit removed the whole handling of resume in dmix, but
this seems causing another regression; some buggy drivers assume that
the device-resume needs to be triggered before transitioning to
PREPARED state. As an ugly workaround, in this patch, when the slave
PCM supports resume, snd_pcm_direct_resume() does resume of the slave
PCM but immediately drop the stream after that. In that way, the
device is brought to the sane active state, then the apps can prepare
and restart the stream properly.
- pcm: Fix secondary retry in dsnoop and dshare
The commit [fdba9e1bad8f: pcm: Fallback open as the first instance for
dmix & co] introduced a mechanism to retry the open of slave PCM for
the secondary streams, but this also introduced a regression in dsnoop
and dshare plugins: since the retry goto-tag was placed at a wrong
position, it retries to re-fetch the shm unnecessarily and eventually
leads to the fatal error.
The bug can be easily reproduced by starting arecord and killing it
via SIGKILL, then starting arecord again. The second arecord fails.
The fix is obviously to move the wrong retry goto-tags to the right
positions.
- pcm: Remove resume support from dmix & co
PCM dmix and other plugins inherit the resume behavior from the slave
PCM. However, the resume on dmix can't work reliably even if the
slave PCM may do resume. The running state of each dmix stream is
individual and may be PREPARED or RUN_PENDING while the slave PCM is
already in RUNNING. And, when the slave PCM is resumed, the whole
samples that have been already mapped are also played back, even if
the corresponding dmix stream is still in SUSPENDED. Such
inconsistencies can't be avoided as long as we manage each stream
individually.
That said, dmix & co can't provide the proper resume support "by
design". For aligning with it, we should drop the whole resume code
and clear the PCM SND_PCM_INFO_RESUME flag.
Reported-by: Shengjiu Wang <shengjiu.wang@nxp.com>
- conf: Add thread-safe global tree reference
Most of open functions in alsa-lib have the call pattern:
snd_config_update();
return snd_xxx_open(x, snd_config, ...);
This means that the toplevel config gets updated, and passed to a
local open function. Although snd_config_update() itself has a
pthread mutex to be thread safe, the whole procedure above isn't
thread safe. Namely, the global snd_config tree may be deleted and
recreated at any time while the open function is being processed.
This may lead to a data corruption and crash of the program.
For avoiding the corruption, this patch introduces a refcount to
config tree object. A few new helper functions are introduced as
well:
- snd_config_update_ref() does update and take the refcount of the
toplevel tree. The obtained config tree has to be freed via
snd_config_unref() below.
- snd_config_ref() and snd_config_unref() manage the refcount of the
config object. The latter eventually deletes the object when all
references are gone.
Along with these additions, the caller of snd_config_update() and
snd_config global tree in alsa-lib are replaced with the new helpers.
- pcm: dmix: Fix doubly resume of slave PCM
The dmix plugin and co may trigger the resume for each instance in
snd_pcm_direct_resume(). It means that the slave PCM gets resumed or
re-prepared/started by each opened dmix stream, and this may end up
with the doubly triggers even though the slave PCM has been already
resumed by another dmix stream.
For avoiding this conflicts, check the slave PCM state and resume only
when it's still in the suspended state. Meanwhile we keep the shadow
state updated no matter whether the slave was triggered or not.
- pcm: Fix suspend/resume regression with dmix & co
The recent fix commit [8985742d91db: pcm: dmix: Handle slave PCM xrun
and unexpected states properly] caused a regression in dmix and other
plugins regarding suspend/resume. For example, aplay endlessly prints
"Suspended. Trying resume. Done." message if suspend and resume are
performed in the middle of playback.
The reason is that the commit above changed the shadow PCM state
(dmix->state) to SUSPENDED when the slave PCM is in suspend, while it
doesn't restore the shadow state upon resume. Thus it appears as if
it's always suspended even after the resume is invoked.
The fix is just to add the proper update of the shadow state in
snd_pcm_direct_resume().
Reported-by: Shengjiu Wang <shengjiu.wang@freescale.com>
- pcm: softvol: fix conversion of TLVs min_db and max_dB value
Both, min_dB and max_dB, are floating type whereas the TLV is (always)
unsigned.
The problem with the conversion of a negative floating-point number into an
unsigned integer is, that the behavior is undefined. This may, depending on
the platform, result in a wrong TLV, i.e. for the default values of min_dB
(-51dB) and max_dB (0dB), alsactl generates the following state on an ARM
cpu build with GCC:
control.1 {
iface MIXER
name Master
value.0 255
value.1 255
comment {
access 'read write user'
type INTEGER
count 2
range '0 - 255'
tlv '00000001000000080000000000000014'
dbmin 0
dbmax 5100
dbvalue.0 5100
dbvalue.1 5100
}
}
With the fix applied, alsactl stores the correct TLV:
control.1 {
iface MIXER
name Master
value.0 255
value.1 255
comment {
access 'read write user'
type INTEGER
count 2
range '0 - 255'
tlv '0000000100000008ffffec1400000014'
dbmin -5100
dbmax 0
dbvalue.0 0
dbvalue.1 0
}
}
Also tested for different combinations of min_dB and max_dB other than the
default values.
Replaces:
http://mailman.alsa-project.org/pipermail/alsa-devel/2016-May/107733.html
Fixes:
http://mailman.alsa-project.org/pipermail/alsa-devel/2016-May/107628.html
- pcm: Fallback open as the first instance for dmix & co
dmix and other PCM plugins tries to open a secondary stream with
O_APPEND flag when the shmem was already attached by another.
However, when another streams have been already closed after the
shmem check, this open may return the error EBADFD, since the kernel
accepts O_APPEND only for the secondary streams.
This patch adds a workaround for such a case. It just retries opening
the stream as the first instance (i.e. without O_APPEND flag).
This is basically safe behavior (the kernel takes care of races), even
we may do this even unconditionally. But it's bad from the
performance POV, so we do it only when really needed.
Reported-by: Lars Lindqvist <lars.lindqvist@yandex.ru>
- pcm: Clean up error paths in snd_pcm_plugin_*() helpers
Minor code refactoring to unify the error return paths.
- pcm_plugin: fix appl pointer not correct when mmap_commit() return error
When snd_pcm_mmap_commit() return error, the appl pointer is also updated.
which cause the avail_update()'s result wrong.
This patch move the snd_pcm_mmap_appl_forward() to the place when
snd_pcm_mmap_commit() is successfully returned.

RawMidi API

- conf: Add thread-safe global tree reference
Most of open functions in alsa-lib have the call pattern:
snd_config_update();
return snd_xxx_open(x, snd_config, ...);
This means that the toplevel config gets updated, and passed to a
local open function. Although snd_config_update() itself has a
pthread mutex to be thread safe, the whole procedure above isn't
thread safe. Namely, the global snd_config tree may be deleted and
recreated at any time while the open function is being processed.
This may lead to a data corruption and crash of the program.
For avoiding the corruption, this patch introduces a refcount to
config tree object. A few new helper functions are introduced as
well:
- snd_config_update_ref() does update and take the refcount of the
toplevel tree. The obtained config tree has to be freed via
snd_config_unref() below.
- snd_config_ref() and snd_config_unref() manage the refcount of the
config object. The latter eventually deletes the object when all
references are gone.
Along with these additions, the caller of snd_config_update() and
snd_config global tree in alsa-lib are replaced with the new helpers.

Topology API

- topology: Fix the missing referenced elem ptr when merging private data
tplg_copy_data() should set the valid referenced data element pointer
on success. The caller will double check this pointer for all kinds of
references, including controls and data.
- topology: Fix inaccurate message on failure to find a widgets's reference
A widget may have references to control or data elements. So the message
should not only use "control" here.
- topology: Check address and length before string copy
elem_copy_text() is widely used for string copy in topology. Because some
name fields are not mandatory for users, sometimes the source can be
invalid and we should not do the copy. So we add check here.
Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
- topology: Add ATTRIBUTE_UNUSED for unused parameters to fix compiler warning
This commit adds ATTRIBUTE_UNUSED to the unused parameter 'tplg' for
function tplg_parse_streams() and tplg_parse_fe_dai(). These two functions
need to keep 'tplg' as ops for tplg_parse_compound().
The compiler warnings below are fixed:
pcm.c: In function 'tplg_parse_streams':
pcm.c:262:43: warning: unused parameter 'tplg' [-Wunused-parameter]
static int tplg_parse_streams(snd_tplg_t *tplg, snd_config_t *cfg,
^
pcm.c: In function 'tplg_parse_fe_dai':
pcm.c:324:42: warning: unused parameter 'tplg' [-Wunused-parameter]
static int tplg_parse_fe_dai(snd_tplg_t *tplg, snd_config_t *cfg,
Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
- topology: Remove support for control flag SNDRV_CTL_ELEM_ACCESS_USER
This access flag is used to add controls from user space by ioctl.
But topology only configures controls in user space and these controls
will eventually be created by ASoC in kernel, so topology should not
support this flag.
Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
- topology: Tuple type can have an extenstion
After the type specific string ("uuid", "string", "byte", "short" and
"word"), users may append a string, like "uuidxxx". The topology parser
will check the first few characters to get the tuple type.
This can allow users to put multiple tuples of the same type into one
vendor tuple section (SectionVendorTuples), e.g. parameters of multiple
firmware modules.
Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
- topology: Parse vendor private data for manifest
In text conf file, user can define a manifest section and let it refer
to private data sections, in the same syntax as other element types.
The text conf file can have at most 1 manifest section.
Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
- topology: Change uuid value to 16 separate characters in text conf file
Previously in text conf file, the uuid value of vendor tuples is a
16-characer string. Now change it to 16 characters separated by commas,
easier for users to edit it manually.
Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
- topology: Merge lookup for data reference into tplg_copy_data()
Code refactor to reduce function calls. Now tplg_copy_data() can look up
a referenced data element and merge its data.
Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
- topology: An element can refer to multipe data sections in text conf file
Previously in text conf file, an element can only refer to one data
section (SectionData). Now it can also refer to a list of data sections.
Thus users can split groups of firmware parameters to multiple data
sections, and put them all in the reference list.
Finally, data of these data sections will be merged, in the same order as
they are in the reference list, as the element's private data for kernel.
We still support the original syntax of reference to a single data
section. The doc is updated for the syntax extension.
Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
- topology: initialize variable for error output
This commit fixes below compiler warnings.
In file included from ../../include/local.h:165:0,
from tplg_local.h:17,
from data.c:20:
data.c: In function ‘tplg_parse_tuples’:
../../include/error.h:64:21: warning: ‘id’ may be used uninitialized in this function [-Wmaybe-uninitialized]
#define SNDERR(...) snd_lib_error(__FILE__, __LINE__, __FUNCTION__, 0, __VA_ARGS__) /**< Shows a sound error message. */
^
data.c:576:14: note: ‘id’ was declared here
const char *id;
^
- topology: apply the same type to compared two variables
This commit fixes below compiler warnings.
data.c: In function ‘get_token_value’:
data.c:262:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < tokens->num_tokens; i++) {
^
data.c: In function ‘copy_tuples’:
data.c:351:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < tuples->num_sets ; i++) {
^
data.c:378:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (j = 0; j < tuple_set->num_tuples; j++) {
^
data.c: In function ‘tplg_free_tuples’:
data.c:723:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < tuples->num_sets; i++)
^
- topology: remove unused variable in get_tokens()
This commit fixes below compiler warnings.
data.c: In function ‘get_tokens’:
data.c:276:6: warning: unused variable ‘err’ [-Wunused-variable]
int err = 0;
^
data.c: In function ‘has_tuples’:
data.c:302:6: warning: unused variable ‘err’ [-Wunused-variable]
int err = 0;
^
- topology: remove unused variable in tplg_parse_fe_dai()
This commit fixes below compiler warnings.
pcm.c: In function ‘tplg_parse_fe_dai’:
pcm.c:333:6: warning: unused variable ‘err’ [-Wunused-variable]
int err;
^
- topology: Parse front-end DAI name and ID for the PCM
These two fields are necessary to create the front-end DAIs
in kernel but the support is missing in text conf previously.
- topology: Fix pcm ID & name parsing
The name and ID of SectionPCM should be set to pcm_name and pcm_id,
for a front-end DAI link in the kernel, not for the front-end DAI
of the link.
- topology: Use generic pointer to realloc buffer for private data
Many element types have private data. So use the generic obj pointer
instead of the type-specific pointer when reallocating the object to
accommodate the private data.
Empty private data will be overlooked.
- topology: Refactor functions to parse and build streams
Previously these functions are only used by pcm elements (front-end DAI
& DAI link) to parse stream capablities. Now refactor them to be reused
by back-end DAI elements later.
- topology: Set manifest size for ABI
The topology kernel driver will check the size of manifest struct, and
will stop loading topology info if size mismatch is detected.
- topology: Build data objects with tuples
For data objects with tuples, the parser will bind the vendor tuples
and tokens, copy the tuples to the private buffer of its parent data
object. Then later the builder will export the vendor tuples as private
binary data for the control or widgets objects.
- topology: Add support for parsing vendor tuples
Vendor can define several tuple arrays in 'SectionVendorTuples', as
well as the reference to a vendor token list object.
A later patche will copy vendor tuples in ABI format to the private
buffer of its parent data object in the building phase.
- topology: Add support for vendor tokens
Vendor can define a token list in SectionVendorTokens. Each token element
is a pair of string ID and integer value. And both the ID and value are
vendor-specific.
- topology: Add doc for vendor tuples
Describe how to define vendor tokens and tuples in the text conf file.
- topology: Define a free handler for the element
This handler is defined for type-specific destruction of an element.
- topology: Use the generic pointer to free an element's object
The element is a wrapper for different types of objects.So use the
generic pointer 'obj' instead of the type-specific pointer to free
the object.

Use Case Manager API

- ucm: add cset-tlv
This patch enables UCM to set a file in TLV format to kcontrol by:
cset-tlv "name='<kcontrol-name>' <path-to-file>"
This new 'cset-tlv' command will be used to write audio DSP to
specific alsa control, where the driver expectes a file in TLV
format.
The TLV file to set to kcontrol will be checked first by file size
not larger than 16 MB, and then examine if the length field reports
correct number of bytes in the TLV file.
Reviewed-by: Vinod Koul <vinod.koul@intel.com>

/include/Makefile.am

- pcm: Remove home brew atomic operations
We've had a few home brew atomic operations in a couple of places in
the PCM code. This was for supporting the concurrent accesses, but in
practice, it couldn't cover the race properly by itself alone.
Since we have a wider concurrency protection via mutex now, we can get
rid of these atomic codes, which worsens the portability
significantly.

ALSA Lisp

- alisp: remove alloca() from FA_pcm_info()
Both of alloca() and automatic variables keeps storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- alisp: remove alloca() from FA_hctl_elem_write()
Both of alloca() and automatic variables keeps storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- alisp: remove alloca() from FA_hctl_elem_read()
Both of alloca() and automatic variables keeps storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- alisp: remove alloca() from FA_hctl_elem_info()
Both of alloca() and automatic variables keeps storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- alisp: remove alloca() from FA_hctl_find_elem()
Both of alloca() and automatic variables keeps storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- alisp: remove alloca() from FA_card_info()
Both of alloca() and automatic variables keeps storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.

Async helpers

- async: Handle previously installed signal handler
The issue is with the signal handler installed and deinstalled in
alsa-lib async handler. This code makes no attempt to remember any
previously installed signal handlers for SIGIO, if SIGIO is used.
Consequently it does not call any previous handlers from its own
handler once installed, and does not reinstall any previous handler
when deinstalling its handler. Consequently, use of also-lib within
applications that depend on SIGIO will break those applications,
rendering them inoperative once alsa-lib is running because their
signal handlers are no longer called.
This patch does remember and restore any previous handler, and chains
calls to the handler if it exists.

Configuration

- Makefile: fix sklrt286 dist files
- conf: remove alloca() from snd_func_private_pcm_subdevice()
Both of alloca() and automatic variables keeps storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- conf: remove alloca() from snd_func_pcm_args_by_class()
Both of alloca() and automatic variables keeps storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- conf: remove alloca() from snd_func_pcm_id()
Both of alloca() and automatic variables keeps storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- conf: remove alloca() from snd_func_card_name()
Both of alloca() and automatic variables keeps storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- conf: remove alloca() from snd_func_card_id()
Both of alloca() and automatic variables keeps storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- conf: remove alloca() from snd_determine_driver()
Both of alloca() and automatic variables keeps storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
- conf/ucm: chtrt5645: Add UCM config for chtrt5645
Add a UCM configuration for the rt5645 codec on Intel's Cherry-Trail
platform. Tested on the Microsoft Surface 3.
- conf/ucm: ROCKCHIP-I2S: rename to VEYRON-I2S
Commit a192f52fc63a introduced an ucm profile for Rockchip Veyron-
Chromebooks by taking the ucm profile from the ChromeOS userspace.
But similarly to DAISY-I2S, PAZ00 and most other profiles, the audio
setup is pretty specific to a board type, so hogging the Rockchip name
will make it harder for future Rockchip based boards to fit in nicely.
And while Veyron also is a family of boards, all of them share the
same audio setup. The ucm profile was not released with any official
alsa release and the audio setup also isn't in the mainline kernel yet,
so such a rename should be easily possible.
Fixes: a192f52fc63a ("conf/ucm: ROCKCHIP-I2S: add Rockchip I2S UCM config.")
- conf: Add thread-safe global tree reference
Most of open functions in alsa-lib have the call pattern:
snd_config_update();
return snd_xxx_open(x, snd_config, ...);
This means that the toplevel config gets updated, and passed to a
local open function. Although snd_config_update() itself has a
pthread mutex to be thread safe, the whole procedure above isn't
thread safe. Namely, the global snd_config tree may be deleted and
recreated at any time while the open function is being processed.
This may lead to a data corruption and crash of the program.
For avoiding the corruption, this patch introduces a refcount to
config tree object. A few new helper functions are introduced as
well:
- snd_config_update_ref() does update and take the refcount of the
toplevel tree. The obtained config tree has to be freed via
snd_config_unref() below.
- snd_config_ref() and snd_config_unref() manage the refcount of the
config object. The latter eventually deletes the object when all
references are gone.
Along with these additions, the caller of snd_config_update() and
snd_config global tree in alsa-lib are replaced with the new helpers.
- pcm: Define namehint for single directional PCM types
The PCM namehint for some PCM types like dmix, dsnoop and surround51
should be defined as single directional.
Reported-by: Trent Reed <treed0803@gmail.com>
- conf/ucm: ROCKCHIP-I2S: add Rockchip I2S UCM config.
Taken from the ChromeOS sources, this configuration was tested on Veyron
Jerry based Chromebook from Google.
[Added missing Makefile changes by tiwai]
- topology: Update PCM configurations in Broadwell text conf file
To make this conf file a better example, update the name & ID of PCMs
(front-end DAI link) and their cpu DAI (front-end DAI), same as those
defined by Broadwell upstream driver.
- conf: topology: Generate Private data binary blobs
The DSP modules need private data and that is provided as binary
blob. These blobs are compiled from C structures which specify module
configuration.
- conf: topology: Add Skylake i2s conf
The Skylake topology configuration for simple topology graph is
provided. This exposes the PCM capabilities of the DSP.

Documentation

- pcm: Add thread-safety to PCM API
Traditionally, many of ALSA library functions are supposed to be
thread-unsafe, and applications are required to take care of thread
safety by themselves. However, people never be careful enough, and
almost all applications fail in this regard.
This patch is an attempt to harden the thread safety in exported PCM
functions in a simplistic way: just wrap some of exported functions
with the pthread mutex of each PCM object. Not all API functions are
wrapped by the mutex since it doesn't make sense. Instead, the
patchset covers only the functions that may be likely called
concurrently. The supposedly thread-safe API functions are marked in
the document.
For achieving the feature, two new fields are added snd_pcm_t when the
option is enabled: thread_safe and lock. The former indicates that
the plugin is thread-safe that doesn't need this workaround and the
latter is the pthread mutex. Currently only hw plugin have
thread_safe=1. So, the most of real-time sensitive apps won't be
influenced by this patchset.
Although the patch covers most of PCM ops, a few snd_pcm_fast_ops are
left without the extra mutex locking: namely, the ones that may have
blocking behavior, i.e. resume, drain, readi, writei, readn and
writen. These are supposed to handle own locking in the callbacks.
Also, if anyone wants to disable this new thread-safe API feature, it
can be still turned off via --disable-thread-safety configure option.
- doxygen: Suppress timestamp
The build timestamp in the doc is bad for packaging in general, so
let's disable it as default.
- INSTALL: update text and drop reference to Hg
This is really just nitpick, but it annoyed me for a few seconds, so I thought
I'd just fix it.
In d7534b2ceec7 (hgcompile -> gitcompile) the filename was updated but
INSTALL was not, leaving outdated docs.

External PCM I/O Plugin SDK

- pcm: Add thread-safety to PCM API
Traditionally, many of ALSA library functions are supposed to be
thread-unsafe, and applications are required to take care of thread
safety by themselves. However, people never be careful enough, and
almost all applications fail in this regard.
This patch is an attempt to harden the thread safety in exported PCM
functions in a simplistic way: just wrap some of exported functions
with the pthread mutex of each PCM object. Not all API functions are
wrapped by the mutex since it doesn't make sense. Instead, the
patchset covers only the functions that may be likely called
concurrently. The supposedly thread-safe API functions are marked in
the document.
For achieving the feature, two new fields are added snd_pcm_t when the
option is enabled: thread_safe and lock. The former indicates that
the plugin is thread-safe that doesn't need this workaround and the
latter is the pthread mutex. Currently only hw plugin have
thread_safe=1. So, the most of real-time sensitive apps won't be
influenced by this patchset.
Although the patch covers most of PCM ops, a few snd_pcm_fast_ops are
left without the extra mutex locking: namely, the ones that may have
blocking behavior, i.e. resume, drain, readi, writei, readn and
writen. These are supposed to handle own locking in the callbacks.
Also, if anyone wants to disable this new thread-safe API feature, it
can be still turned off via --disable-thread-safety configure option.

Kernel Headers

- topology: Fix pcm ID & name parsing
The name and ID of SectionPCM should be set to pcm_name and pcm_id,
for a front-end DAI link in the kernel, not for the front-end DAI
of the link.
- Add u8 in type_compat.h
Skylake headers use u8 data types which were not present in
type_compat so add them.
- topology: ABI - Define types for vendor tuples
Tuples, a pair of token and value, can be used to define vendor specific
data, for controls and widgets. This can avoid importing binary data blob
from other files.
Vendor specific tuple arrays will be embeded in the private data buffer
of a control or widget object. To be backward compatible, union is used
to define the tuple arrays in the existing private data ABI object
'struct snd_soc_tplg_private'.
Vendors need to make sure the token values defined by the topology conf
file match those defined by their driver.
Now supported tuple types are uuid, string, bool, byte, short and word.

Simple Abstraction Mixer Modules

- mixer: remove assignment to unused variable
This commit fixes below compiler warnings.
sbase.c:327:16: warning: variable ‘values’ set but not used [-Wunused-but-set-variable]
unsigned long values;
^

Test/Example code

- ctl: rename APIs to add an element set so that their names are appropriate
In this development period, some APIs have already been added. Most of
them are to add an element set, while their names are not so appropriate
against their feature. This is due to following to names of old APIs.
This commit renames them.
- test: add linker flag with pthread for pcm-multi-thread stress test
This test program is a pthread application, while Makefile has no flags
for linker about pthread library. This can cause below error.
$ make pcm-multi-thread
CCLD pcm-multi-thread
/usr/bin/ld: pcm-multi-thread.o: undefined reference to symbol 'pthread_cancel@@GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Makefile:523: recipe for target 'pcm-multi-thread' failed
make: *** [pcm-multi-thread] Error 1
This commit fixes the bug by adding a corresponding flag.
Fixes: 147093ac5b8d('test: Add pcm-multi-thread program')
- test: Add pcm-multi-thread program
A simple multi-thread stress test for PCM is added to test
subdirectory. It can perform various PCM update function in the
worker threads while reading/writing the data in the main thread.
It can help catching the unexpected error or blockage. For example,
running the capture test with a softvol plugin will lead to the assert
due to the races.
- ctl: fix a test for user-defined element set in a point of dimension
Currently, this test program has a bug related to dimension information.
When testing an element set with byte type, the program adds 512 members
to an element. This is a maximum number permitted for this type.
On the other hand, dimension information of the elements consists of
[8, 4, 8, 4]. Calculated members in the multi-dimensional matrix is 1024.
This should be less than 512.
This commit fixes the bug.
- ctl: support dimension test for user-defined element set
In former commits, APIs to add an element set are extended to support extra
fields to information structure. Currently, the fields are mainly used to
describe dimension level.
This commit adds tests to check the dimension level.
- ctl: optimize a test for user-defined element set to changes of APIs
In former commits, APIs to add an element set are changed, while a test
program for user-defined element set doesn't follow them.
This commit add support the change.
- ctl: optimize a test for user-defined element set to older kernels
In Linux 4.0 or former, call of ioctl(2) with SNDRV_CTL_IOCTL_ELEM_ADD
doesn't fill all of identical information in an argument; i.e. numid.
With the kernel, a test of user-defined element set fails.
This commit fixes the bug. The 'numid' field in identical information
is always zero when adding an element set, therefore zero check has an
effect.
- ctl: add test program for control element set
The feature of control element set has been abandoned for a long time since
firstly introduced in 2003. Furthermore, there's few applications to utilize
this feature. These situations bring a hard work to persons who need the
feature. Especially, a lack of test program make it harder to fix much bugs
in this feature.
This commit adds a test program as a sample of the feature. This program
adds element sets of each element type to 'hw:0' in this order; boolean,
integer, enumerated, bytes, IEC958 and integer64. Each iteration includes
below scheme:
1. add an element set with 900 elements. Each of them has maximum number
of members allowed by ALSA ctl core.
2. check all of events generated by above operation.
3. retrieve information of each element, then validate it.
4. unlock each member of all elements because they're initially locked.
5. write to all of members in all elements and read.
6. check all of events generated by above operation.
7. write information for threshold level to the element set and read it.
8. check all of events generated by above operation.
9. remove the element set.
10.check all of events generated by above operation.
When any of these operations fail, it means regression occurs. Then, added
elements still remain in a certain sound card. In this case, unloading
drivers corresponding to the card is an easy way to recover.
Besides, this program doesn't perform below element operations of ALSA ctl
feature:
- list
- lock
- replace

alsa-utils

Core

- Release v1.1.2
- alsabat: align the data type on float
Aligning the data type of fftw analyzer, sample converter and other
components on float, because:
1. avoid unnecessary data type conversion;
2. using float is more efficient than using double;
3. the extra double accuracy is not required.

aplay/arecord

- aplay: fix lurking capture file overwrite bug
If -d was given to arecord while commit
8aa13eec80eac312e4b99423909387660fb99b8f (now reverted) was in effect,
the last read would be shorter than the chunk size, but pcm_read would
read and return the chunk size, the samples were discarded, and
capture() continued in a loop because count never reached 0. arecord
opens a new file each loop iteration, if arecord is dynamically naming
files, --use-strftime option or beyond the wave 2GB limit, this will
generate a series of header only wave files. If the file is unique
the originally recorded data is lost and it will continue overwriting
the same file with a header only wave file.
While the current pcm_read can't fail (it can exit), it is better to
just fix this lurking bug in case it is "fixed" again.

bat (basic audio tester)

- alsabat: make snr_is_valid static
The compilation fails due to multiple defination of snr_is_valid
common.o: In function `snr_is_valid':
bat/common.h:99: multiple definition of `snr_is_valid'
bat.o:bat/common.h:99: first defined here
signal.o: In function `snr_is_valid':
bat/common.h:99: multiple definition of `snr_is_valid'
bat.o:bat/common.h:99: first defined here
latencytest.o: In function `snr_is_valid':
bat/common.h:99: multiple definition of `snr_is_valid'
bat.o:bat/common.h:99: first defined here
analyze.o: In function `snr_is_valid':
bat/common.h:99: multiple definition of `snr_is_valid'
bat.o:bat/common.h:99: first defined here
alsa.o: In function `snr_is_valid':
bat/common.h:99: multiple definition of `snr_is_valid'
bat.o:bat/common.h:99: first defined here
- alsabat: fix a missing break in switch
Add the break line for OPT_ROUNDUPLATENCY case.
- alsabat: add noise detection
Alsabat reports error when noise above threshold be detected.
Use either of the options below to designate the threshold. (e.g.
if the ratio of noise to signal is 5%, the snr is about 26dB.)
--snr-db <value in dB>
--snr-pc <value in %>
The noise detection is performed in time domain. On each period
of the sine wave being analyzed, alsabat substracts a clean sine
wave from the source, calculates the RMS value of the residual,
and compares the result with the threshold. At last, alsabat
returns the number of periods with noise above threshold. 0 is
returned when the source is clean.
- alsabat: add a single channel sine wave generator
Add function generate_sine_wave_raw_mono(). It serves as a single
channel sine wave generator, to provide data for calculation (e.g.
for noise analysis).
The function is similar to generate_sine_wave(), but a lite revision.
It has no dependency on bat channels and target frequency, no malloc
inside, no data conversion from float to integer samples, and supports
one channel only.
- alsabat: add channels parameter for adjust_waveform()
The function adjust_waveform() is a component of generate_sine_wave(),
and depended on bat->channels parameter. Add parameter "channels" to
remove the dependency, and then adjust_waveform() can be applied on
other use cases, e.g. a single channel sine wave generator.
- alsabat: align the data type on float
Aligning the data type of fftw analyzer, sample converter and other
components on float, because:
1. avoid unnecessary data type conversion;
2. using float is more efficient than using double;
3. the extra double accuracy is not required.
- alsabat: add round trip audio latency test
Audio latency is the time delay as an audio signal passes through
a system. There are many kinds of audio latency metrics. One useful
metric is the round trip latency, which is the sum of output latency
and input latency.
The measurement step works like below:
1. Listen and measure the average loudness of the environment for
one second;
2. Create a threshold value 16 decibels higher than the average
loudness;
3. Begin playing a ~1000 Hz sine wave and start counting the samples
elapsed;
4. Stop counting and playing if the input's loudness is higher than
the threshold, as the output wave is probably coming back;
5. Calculate the audio latency value in milliseconds.
- alsabat: fix a possible memory leak
Fix a possible memory leak in generate_sine_wave(). Memory free was
ignored when the function return an error.
- alsabat: add buffer size and period size settings
Add buffer size and period size settings in alsabat.
With -E and -B options, alsabat performs the test with
specified buffer size and period size
- alsabat: add terminate status check for capture thread
In loopback test, alsabat use pthread_join(pthread_t thread, **retval)
to wait for the capture thread to terminate. If the capture thread was
canceled, PTHREAD_CANCELED is placed in *retval, and the access to the
**retval will fail. Add status check to prevent illegal access to the
**retval.
Custom Search
Personal tools
Namespaces

Variants
Actions
Navigation
wiki
Toolbox