Commit graph

21 commits

Author SHA1 Message Date
Takashi Iwai
54931e5a54 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.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-07-11 15:25:30 +02:00
Mike Frysinger
7e90867487 pcm: drop unused sys/shm.h inclusion
This header isn't used in these files, so stop trying to include it.
This helps builds on systems that don't provide the header (such as
Android/Bionic).

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-11-05 14:37:10 +01:00
Takashi Iwai
65ff6fdafb pcm: Implement timestamp type handling in all plugins
Now all PCM plugins do support the proper timestamp type or pass it
over slaves.  The internal monotonic flag is dropped and replaced with
tstamp_type in all places.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2014-07-14 18:12:34 +02:00
Takashi Iwai
03c26d0ede PCM: Fix conflict of _snd_pcm_hw_params definitions
Fix the call of _snd_pcm_hw_params() to _snd_pcm_hw_params_internal().
The build passed wrongly because of _snd_pcm_hw_params define.
Having the same function name as the struct name is is simply
confusing...

Also, to be sure, _snd_pcm_hw_params is undef'ed in pcm_local.h, too.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-12-04 12:17:00 +01:00
Takashi Iwai
3fd4ab9be0 PCM: Avoid busy loop in snd_pcm_write_areas() with rate plugin
snd_pcm_write_areas() tries to wait until avail >= avail_min condition
is satisfied.  This doesn't work always well when a rate plugin is in
the play.

When a partial data with a smaller size than a period is written, the
rate plugin doesn't transfer the data immediately to the slave PCM,
but kept in an internal buffer and it changes only the hwptr of the
plugin.  Thus, the condition "avail < avail_min" is triggered for a
wait check although the underlying slave PCM has enough room.  This
results in a call of snd_pcm_wait() which returns immediately after
poll() call, and the snd_pcm_write_areas() loop continues.  As a
consequence, it falls into a CPU hog.

This patch fixes that busy loop by introducing a new fast_ops to check
the availability for wait of avail_min.  Then a plugin can ask the
slave PCM whether the wait is required (or possible).

A few plugins like multi plugin need a special handling.  Otherwise a
generic plugin function can be used.

Reported-by: Trent Piepho <tpiepho@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-11-13 16:16:26 +01:00
Jaroslav Kysela
49dde08641 Reduce compilation warnings
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2012-10-30 13:09:10 +01:00
Takashi Iwai
9c1a0ce72d PCM: Introduce snd_pcm_chmap_t and snd_pcm_chmap_query_t
Instead of passing ambiguous integer array, define snd_pcm_chmap_t and
snd_pcm_chmap_query_t so that user can understand more easily which
element is for what.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-09-13 08:24:58 +02:00
Takashi Iwai
3c4a22ea49 Implement the channel mapping API
Added new channel-mapping API functions.
Not all plugins are covered, especially the route, multi and external
plugins don't work yet.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-09-11 11:34:50 +02:00
Jaroslav Kysela
c88672d86f implemented snd_pcm_rewindable() and snd_pcm_forwardable(), removed can_rewind and can_forward 2008-04-21 12:46:50 +02:00
Takashi Iwai
91fc64cefb Implement missing htimestamp callbacks
Implemented the missing htimestamp callbacks for ioplug, rate and null
plugins.
2008-01-15 14:29:34 +01:00
Jaroslav Kysela
2c1318803f Impemented snd_pcm_htimestamp() function. 2008-01-09 13:50:45 +01:00
Jaroslav Kysela
d25e281230 Changed Jaroslav Kysela's e-mail from perex@suse.cz to perex@perex.cz 2007-10-15 10:24:55 +02:00
Takashi Iwai
8048321c76 More better fix for linked start/stop
Instead of link_fd, more generic callback link_slaves is introduced.
This is called for linking the slave streams as the source to the
given master stream.
2007-03-13 02:52:33 +01:00
Takashi Iwai
69194a1f99 Fix channel_info callback of plugins
Fixed channel_info callback of plugins with different src/dest sizes.
2005-10-27 16:58:40 +00:00
Takashi Iwai
ffdb04c3ea Fix buffer allocation and mmap with plugins
Fixed the bug producing silent tones with some combinations of plugins.
The internal buffer handling is now better (cleaner) integrated with
snd_pcm_generic_*().
2005-09-02 16:36:40 +00:00
Takashi Iwai
18053076e2 Fix generic channel_info callbacks
Fixed generic channel_info callbacks for many plugins.
The allocation of unnecessary internal buffers is avoided.
2005-05-19 16:50:24 +00:00
Takashi Iwai
a6d3b9e4e0 Remove poll_ask callback
Removed poll_ask callbacks.
poll_ask function is merged to poll_descriptors callbacks.
2005-05-18 10:50:09 +00:00
Takashi Iwai
842b573424 Add poll_descriptors and poll_descriptors_count callbacks
Added poll_descriptors and poll_descriptors_count callbacks for multiple
poll_fd's.
2005-05-18 10:45:06 +00:00
Takashi Iwai
e5b91844bf Fix channel_info callbacks of hooks, file and plug plugins
Fixed channel_info callbacks of hooks, file and plug plugins (BTS #1034).
snd_pcm_generic_channel_info_slave() is added.
2005-04-05 15:48:01 +00:00
Jaroslav Kysela
a5831c7300 The stream linking problem for pcm_multi.c should be fixed now
- extended link_fd callback
- added snd_pcm_generic_link2()
- added _snd_pcm_link_descriptors()
2005-01-20 18:37:13 +00:00
Jaroslav Kysela
836987aa99 improved stream linking and plugin code cleanups
- added link/unlink/link_fd fast_ops callbacks
- moved code from snd_pcm_link to pcm_hw.c
- moved "empty" routines pointing to slave to pcm_generic.c
- introduced snd_pcm_generic_t
2005-01-20 15:07:51 +00:00