Jaroslav Kysela [Tue, 5 Nov 2019 12:02:41 +0000 (13:02 +0100)]
ucm: add If condition block
The syntax is simple:
If./any-if-identificator/ {
Condition {
Type /type_here/
/optional defines/
}
True {
/block used when condition is evaluated as true/
}
False {
/block used when condition is evaluated as false/
}
}
The Type "ControlExists" is implemented:
Condition {
Type ControlExists
Device "hw:${CardId}"
Control "iface=CARD,name='Headphone Jack'"
}
Jaroslav Kysela [Sun, 3 Nov 2019 18:05:54 +0000 (19:05 +0100)]
ucm: extend snd_use_case_mgr_open() to address the sound card directly
Some clients like pulseaudio wants to access the multiple instances
of sound cards. This patch adds prefixes like "hw:" to the card_name
argument to handle this. The card index (value) or card identification
(string) can be used for this prefix.
Also the prefix "strict:" was added to avoid the driver name and
driver long name matching. It might be useable for use case
configurations which are not bound to the one sound card.
Jaroslav Kysela [Sun, 10 Nov 2019 12:00:59 +0000 (13:00 +0100)]
conf: improve the include paths code
- various cleanups (more straight code and allocations)
- do not add the base config path /usr/share/alsa to the
explicit include list of directories
(it's not wanted for ucm configs)
pcm: Fix the wrong PCM object passed for locking/unlocking
Most of PCM API functions have snd_pcm_lock()/unlock() wraps for the
actual calls of ops, and some plugins try to unlock/relock internally
for the given PCM object. This, unfortunately, causes a problem in
some configurations and leads to the unexpected behavior or deadlock.
The main problem is that we call snd_pcm_lock() with the given PCM
object, while calling the ops with pcm->op_arg or pcm->fast_op_arg as
the slave PCM object. Meanwhile the plugin code assumes that the
passed PCM object is already locked, and calls snd_pcm_unlock().
This bug doesn't hit always because in most cases pcm->op_arg and
fast_op_arg are identical with pcm itself. But in some configurations
they have different values, so the problem surfaces.
This patch is an attempt to resolve these inconsistencies. It
replaces most of snd_pcm_lock()/unlock() calls with either pcm->op_arg
or pcm->fast_op_arg, depending on the call pattern, so that the plugin
code can safely run snd_pcm_unlock() to the given PCM object.
Fixes: 54931e5a5455 ("pcm: Add thread-safety to PCM API") Reported-by: Ben Russell <thematrixeatsyou@gmail.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
pcm: chmap: Fix memory leak at snd_pcm_set_chmap()
snd_pcm_set_chmap() leaks the memory returned from snd_pcm_get_chmap()
without releasing. Add the missing free() call as well as a slight
code refactoring.
Reported-by: Conrad Jones BugLink: https://github.com/alsa-project/alsa-lib/pull/11 Fixes: d20e24e5d161 ("chmap: Always succeed setting the map to what it already is") Signed-off-by: Takashi Iwai <tiwai@suse.de>
Keyon Jie [Thu, 1 Aug 2019 09:15:06 +0000 (17:15 +0800)]
topology: add support to parse private data for pcm
We have private data section in struct snd_soc_tplg_pcm, but alsatplg
doesn't support handling it yet, here add handling in tplg_parse_pcm()
to enable it.
Signed-off-by: Keyon Jie <yang.jie@linux.intel.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Adam Miartus [Fri, 5 Jul 2019 14:40:48 +0000 (16:40 +0200)]
pcm_file: improve error checking in write_wav_header function
previously errno would be returned even for cases where it may have
not been populated, for example one of the write functions failing,
or writing only partial buffer,
now progress through write operations separately and report errno when
appropriate
Signed-off-by: Adam Miartus <amiartus@de.adit-jv.com> Reviewed-by: Timo Wischer <twischer@de.adit-jv.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Adam Miartus [Mon, 1 Jul 2019 13:25:18 +0000 (15:25 +0200)]
pcm_file: in case of failed write clear file buffer variables
previously, in case of failed write to output file, error is returned
from snd_pcm_writei/read APIs, user could run pcm_drain as fallback and
encounter an assert, since drain would try to write remaining file
buffer to a file
if failed to write to output file in first place, it makes sense to clear
current internal pmc_file file buffer variables
Signed-off-by: Adam Miartus <amiartus@de.adit-jv.com> Reviewed-by: Timo Wischer <twischer@de.adit-jv.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Adam Miartus [Wed, 12 Jun 2019 06:48:27 +0000 (08:48 +0200)]
pcm_file: do not disrupt playback on output file write fail
previously playback could be interrupted by snd_pcm_file_add_frames:
assert(file->wbuf_used_bytes < file->wbuf_size_bytes)
in case snd_pcm_file_write_bytes fails to write full amount of bytes
to file, variable wbuf_used_bytes would not be fully decremented by
requested amount of bytes function was called with
for the assert to trigger, multiple write fails need to happen, so
that wbuf_used_bytes overflows wbuf_size_bytes,
this patch will allow application to report error code to api user
who might have an idea how to recover, before assert is triggered,
also reporting error along with the print out message might give user
a better idea of what is going on, where previously reason for
mentioned assert was not immediately clear
Signed-off-by: Adam Miartus <amiartus@de.adit-jv.com> Reviewed-by: Timo Wischer <twischer@de.adit-jv.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Adam Miartus [Thu, 23 May 2019 13:00:39 +0000 (15:00 +0200)]
pcm: add mmap_begin callback to snd_pcm_fast_ops_t api
main motivation for adding the callback is to use it to enable operation
on mmaped buffer before user access for pcm_file plugin
support for MMAP read access with masking by data from input file is not
implemented for pcm_file plugin, by adding this callback implementing
such feature can be done by rewriting next continuous portion of buffer
on each mmap_begin call
plugins like softvol use pcm_plugin interface and overwrite the buffer by
looping around it in avail_update callback, this patch hopes to simplify
the task by adding new api callback, removing the need for rewriting
pcm_file (to use pcm_plugin callbacks) and careful checking when looping
around whole mmaped buffer
Signed-off-by: Adam Miartus <amiartus@de.adit-jv.com> Reviewed-by: Timo Wischer <twischer@de.adit-jv.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Adam Miartus [Tue, 21 May 2019 13:33:08 +0000 (15:33 +0200)]
pcm: file: use snd_pcm_file_areas_read_infile for readi
use previously introduced helper function, this commit unifies behavior
of readi and readn
corner case behavior of readi is changed by this commit, previously,
in case 0 bytes were red from file (EOF), frames = 0 was returned,
signaling api user as if no data was red from slave, after the patch,
amount of frames red from slave with data red from slave stored in buffer
is returned when EOF is reached
Signed-off-by: Adam Miartus <amiartus@de.adit-jv.com> Reviewed-by: Timo Wischer <twischer@de.adit-jv.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Adam Miartus [Tue, 21 May 2019 13:32:47 +0000 (15:32 +0200)]
pcm: file: add support for infile reading in non interleaved mode
add helper function to copy input file data to buffer mapped by areas,
in case of an error, do not fill the areas, allowing device read buffer
to be provided to api caller
previously unused rbuf variable is reused for this purpose
Signed-off-by: Adam Miartus <amiartus@de.adit-jv.com> Reviewed-by: Timo Wischer <twischer@de.adit-jv.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
pcm: dsnoop: Added "hw_ptr_alignment" option in configuration for slave pointer alignment
This change adapt the fix commit 6b058fda9dce
("pcm: dmix: Add option to allow alignment of slave pointers")
for dsnoop plugin
Issue is that snd_pcm_wait() goes back to waiting because the hw_ptr
is not period aligned. Therefore snd_pcm_wait() will block for a longer
time as required.
With these rcar driver changes the exact position of the dma is returned.
During snd_pcm_start they read hw_ptr as reference, and this hw_ptr
is now not period aligned, and is a little ahead over the period while it
is read. Therefore when the avail is calculated during snd_pcm_wait(),
it is missing the avail_min by a few frames.
An additional option hw_ptr_alignment is provided to dsnoop configuration,
to allow the user to configure the slave application and hw pointer
alignment at startup
pcm: dshare: Added "hw_ptr_alignment" option in configuration for alignment of slave pointers
This change adapt the fix commit 6b058fda9dce
("pcm: dmix: Add option to allow alignment of slave pointers")
for dshare plugin
Issue is that snd_pcm_wait() goes back to waiting because the hw_ptr
is not period aligned. Therefore snd_pcm_wait() will block for a longer
time as required.
With these rcar driver changes the exact position of the dma is returned.
During snd_pcm_start they read hw_ptr as reference, and this hw_ptr
is now not period aligned, and is a little ahead over the period while it
is read. Therefore when the avail is calculated during snd_pcm_wait(),
it is missing the avail_min by a few frames.
An additional option hw_ptr_alignment is provided to dshare configuration,
to allow the user to configure the slave application and hw pointer
alignment at startup
pcm: direct: Add generic hw_ptr_alignment function for dmix, dshare and dsnoop
Move the code snd_pcm_direct_reset_slave_ptr() from pcm_dmix.c
to pcm_direct.c and its header so that the helper function can be
re-used by other direct-pcm plugins.
There is no change in the behavior or the functionality.
Jaroslav Kysela [Tue, 9 Apr 2019 08:12:34 +0000 (10:12 +0200)]
pcm: multi plugin: detach the hw_ptr and appl_ptr from master_slave
Unfortunately, the master_slave buffer pointers are not always in sync with
the presented avail value and the higher layers (like write_areas) got
confused. Create own hw_ptr and appl_ptr.
This commit also tries to fix the hwsync and delay implementation (iterate
through all slaves).
The multi plugin was designed only for hardware which runs really in sync.
Anyway, users are trying to use this plugin for other purposes.
Timo Wischer [Mon, 8 Apr 2019 08:55:54 +0000 (10:55 +0200)]
pcm: null: Do not allow a period size of 0
Some applications do not expect that get_period_size_min() could
return 0. Therefore these applications cannot use the null plugin without
this patch.
Due to there is no use case for having a period size of 0 this patch
disallows a period size of 0 when using the null plugin.
Signed-off-by: Timo Wischer <twischer@de.adit-jv.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Takashi Iwai [Tue, 26 Mar 2019 13:48:23 +0000 (14:48 +0100)]
Drop -I$includedir/alsa from alsa.pc
We used to put the additional include path $includedir/alsa in
pkgconfig just because some applications have included asoundlib.h
like
#include <asoundlib.h>
although the canonical form should be
#include <alsa/asoundlib.h>
However, adding this include path is significantly dangerous due to
possible conflicts of file names like version.h. It's already the
reason to discourage people using alsa.pc for the packages.
In this patch, the additional include path from alsa.pc is dropped
finally. At the same time, as a rescue plan for the programs
including via <asoundlib.h>, a stub header file is provided in
include/sound/asoundlib.h. It just includes alsa/asoundlib.h with a
warning to suggest for replacing with alsa/asoundlib.h.
Actually this is the same file as we install into sys/asoundlib.h, so
the whole changes are very minimal here.
Acked-by: Jaroslav Kysela <perex@perex.cz> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Brendan Shanks [Mon, 11 Feb 2019 19:51:26 +0000 (11:51 -0800)]
pcm: dshare: Fix overflow when slave_hw_ptr rolls over boundary
In snd_pcm_dshare_sync_area() when 'slave_hw_ptr' rolls over
'slave_boundary', the wrong variable is checked ('dshare->slave_hw_ptr' vs
the local 'slave_hw_ptr'). In some cases, this results in 'slave_hw_ptr'
not rolling over correctly. 'slave_size' and 'size' are then much too
large, and the for loop blocks for several minutes copying samples.
This was likely only triggered on 32-bit systems, since the PCM boundary
is computed based on LONG_MAX and is much larger on 64-bit systems.
Hans de Goede [Sun, 3 Feb 2019 11:37:41 +0000 (12:37 +0100)]
ucm: bytcr/PlatformEnableSeq.conf update some comments
Commit f91cc3c7d6b7 ("Update chtrt5645 ucm variants to use
bytcr/PlatformEnableSeq.conf component") updated the
following 2 comments:
# codec0_out settings (used if SSP2 is connected to aif1)
# modem_out settings (used if SSP0 is connected to aif2)
Specifically it added the " to aif1" resp. " to aif2" part of the comments.
This is not correct, AIF1 / AIF2 are something which is present on
Realtek codecs only, and either one can be used indepedent of
SSP0 or SSP2 being used (the comments in the chtrt5645 UCM profile
before this change were wrong / outdated).
Besides there not being any relationship between SSP0 or SSP2 being
used, bytcr/PlatformEnableSeq.conf is also used with other codecs,
e.g. the ESS8316 codec where this is not applicable at all.
Therefor this commit removes the " to aif?" part of the comments again
to avoid confusing people reading this in the future.
Cc: Russell Parker <russell.parker7@gmail.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>