Jaroslav Kysela [Tue, 19 Nov 2019 12:10:19 +0000 (13:10 +0100)]
ucm: fix again the long name configuration filename lookup
The fix in commit 77119d83a1f4 assumes that both ucm1 / ucm2 directories
have the configurations for the long name in the same directory. For v2
we changed the location to card_name/card_long_name aka
driver_name/driver_long_name to make the directory layout more structured.
Fixes: 77119d83a1f4 ("ucm: Fix opening of master-configs by the card's longname") Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Hans de Goede [Tue, 19 Nov 2019 10:48:21 +0000 (11:48 +0100)]
ucm: Only look in ucm[1] or ucm2 dir once we've found a config file in one
Unless environment variables are set, then configuration_filename()
when initially called by load_master_config() will first try to find
the requested master-config under <prefix>/alsa/ucm2 and then under
<prefix>/alsa/ucm.
Once a master-config is found this way, we should set conf_format to
match, so that subsequent lookups only look under the same directory
as where the master-config was found.
This fixes 2 problems:
1. uc_mgr_config_load() looking under <prefix>/alsa/ucm for includes for
UCM2 profiles because it is called with uc_mgr->conf_format as format
and before this commit that would stay 0 when autodetecion is used.
2. parse_verb_file() possibly loading an UCM2 verb-file for an UCM1 profile,
the chance of this happening is small as this means that even though
there is no UCM2 master-config there is an UCM2 profile dir matching
uc_mgr->conf_file_name, which would be weird.
Fixes: aba2260ae7b5 ("ucm: switch to ucm2 directory and v2 format, keep backward compatibility") Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Hans de Goede [Tue, 19 Nov 2019 10:48:20 +0000 (11:48 +0100)]
ucm: Fix fallback to card_name (shortname) config for ucm1 profiles
uc_mgr_import_master_config() first calls load_master_config()
with the card's longname and if that fails then calls it again with the
card_name.
Before this commit configuration_filename() would force conf_format to 2
when it the access(fn, R_OK) test failed for the ucm1 longname
master-config filename.
This would cause configuration_filename() to blindly return a filename
under <prefix>/ucm2 without seeing if that is actually there and without
trying to fallback to the old profiles under <prefix>/ucm, breaking the
loading of UCM1 profiles by card_name.
This commit fixes this by modifying configuration_filename() to not set
conf_format when checking for the UCM1 config filename fails.
Instead, to make sure that any errors about opening the file still report
the new path, configuration_filename() now resets the filename to the UCM2
path if the access() check has failed for both the UCM2 and UCM1 paths,
without touching conf_format.
Fixes: aba2260ae7b5 ("ucm: switch to ucm2 directory and v2 format, keep backward compatibility") Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Hans de Goede [Tue, 19 Nov 2019 10:48:19 +0000 (11:48 +0100)]
ucm: Fix opening of master-configs by the card's longname
Prior to commit aba2260ae7b5 ("ucm: switch to ucm2 directory and v2 format,
keep backward compatibility").
The filename build in parse_verb_file() was build like this:
<prefix>/<uc_mgr->conf_file_name>/<file>
Where uc_mgr->conf_file_name would contain either the card_name or the
card's longname depending on the detection of a longname based config in
uc_mgr_import_master_config().
While the filename used in load_master_config() was build like this:
<prefix>/<card_name>/<card_name>.conf
And uc_mgr_import_master_config() first calls load_master_config()
with the card's longname and if that succeeds it overwrites
uc_mgr->conf_file_name with the longname so that the subsequent uses
of uc_mgr->conf_file_name in parse_verb_file() correctly use the longname.
But the new configuration_filename() helper added in commit aba2260ae7b5
_always_ builds the filename like this:
<prefix>/<uc_mgr->conf_file_name>/<file><suffix>
This breaks the loading of the master-config by its longname, as when
the longname is tried uc_mgr->conf_file_name still contains the card_name.
This commit fixes this by adding a dir parameter to configuration_filename()
and restoring the old behavior by passing card_name as dir in
load_master_config().
Fixes: aba2260ae7b5 ("ucm: switch to ucm2 directory and v2 format, keep backward compatibility") Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
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.