alsa/0015-pcm-dmix-fix-sw_params-handling-of-timestamp-types-i.patch
Takashi Iwai 4594d6ec9e Accepting request 796086 from home:tiwai:branches:multimedia:libs
- Backport recent upstream fixes:
  topology API fix, UCM fixes/improvements, config fixes, chmap
  support in route plugin, timestamp type fix for dmix:
  0006-topology-add-back-asrc-to-widget_map-in-dapm.c.patch
  0007-ucm-clarify-the-index-syntax-for-the-device-names.patch
  0008-ucm-fix-uc_mgr_scan_master_configs.patch
  0009-namehint-remember-the-direction-from-the-upper-level.patch
  0010-conf-fix-namehint-for-pcm.front-and-pcm.iec958.patch
  0011-pcm-add-chmap-option-to-route-plugin.patch
  0012-usecase-allow-indexes-also-for-modifier-names.patch
  0013-ucm-fix-the-device-remove-operation.patch
  0014-ucm-fix-copy-n-paste-typo-RemoveDevice-list.patch
  0015-pcm-dmix-fix-sw_params-handling-of-timestamp-types-i.patch
  0016-conf-USB-Audio-Fix-S-PDIF-output-of-ASUS-Xonar-AE.patch

OBS-URL: https://build.opensuse.org/request/show/796086
OBS-URL: https://build.opensuse.org/package/show/multimedia:libs/alsa?expand=0&rev=271
2020-04-23 12:31:46 +00:00

239 lines
8.0 KiB
Diff

From d12df1dc9c095bcb52d104e5a39043b56424e9d2 Mon Sep 17 00:00:00 2001
From: "sylvain.bertrand@gmail.com" <sylvain.bertrand@gmail.com>
Date: Wed, 15 Apr 2020 00:44:39 +0000
Subject: [PATCH 15/16] pcm: dmix: fix sw_params handling of timestamp types in
direct plugins
In pcms using direct plugins (dmix/dsnoop/dshare), the timestamp type could
be different from the terminating hw plugin, then the kernel driver.
Be sure such pcms have plugins using consistently the same timestamp type.
signed-off-by: Sylvain Bertrand <sylvain.bertrand@legeek.net>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
src/conf/alsa.conf | 1 +
src/conf/pcm/dmix.conf | 4 ++++
src/conf/pcm/dsnoop.conf | 4 ++++
src/pcm/pcm_direct.c | 36 +++++++++++++++++++++++++++++++++++-
src/pcm/pcm_direct.h | 2 ++
src/pcm/pcm_dmix.c | 4 ++++
src/pcm/pcm_dshare.c | 4 ++++
src/pcm/pcm_dsnoop.c | 4 ++++
src/pcm/pcm_local.h | 2 ++
9 files changed, 60 insertions(+), 1 deletion(-)
diff --git a/src/conf/alsa.conf b/src/conf/alsa.conf
index a091b810f9ed..0e01c887dc28 100644
--- a/src/conf/alsa.conf
+++ b/src/conf/alsa.conf
@@ -69,6 +69,7 @@ defaults.pcm.minperiodtime 5000 # in us
defaults.pcm.ipc_key 5678293
defaults.pcm.ipc_gid audio
defaults.pcm.ipc_perm 0660
+defaults.pcm.tstamp_type "default"
defaults.pcm.dmix.max_periods 0
defaults.pcm.dmix.channels 2
defaults.pcm.dmix.rate 48000
diff --git a/src/conf/pcm/dmix.conf b/src/conf/pcm/dmix.conf
index 7fa5c8b2e20a..50e573da5d35 100644
--- a/src/conf/pcm/dmix.conf
+++ b/src/conf/pcm/dmix.conf
@@ -56,6 +56,10 @@ pcm.!dmix {
@func refer
name defaults.pcm.ipc_perm
}
+ tstamp_type {
+ @func refer
+ name defaults.pcm.tstamp_type
+ }
slave {
pcm {
type hw
diff --git a/src/conf/pcm/dsnoop.conf b/src/conf/pcm/dsnoop.conf
index abbd44f7fd79..f4336e5f5e07 100644
--- a/src/conf/pcm/dsnoop.conf
+++ b/src/conf/pcm/dsnoop.conf
@@ -49,6 +49,10 @@ pcm.!dsnoop {
@func refer
name defaults.pcm.ipc_perm
}
+ tstamp_type {
+ @func refer
+ name defaults.pcm.tstamp_type
+ }
slave {
pcm {
type hw
diff --git a/src/pcm/pcm_direct.c b/src/pcm/pcm_direct.c
index 54d99005461b..aa60a47774ae 100644
--- a/src/pcm/pcm_direct.c
+++ b/src/pcm/pcm_direct.c
@@ -991,8 +991,11 @@ int snd_pcm_direct_hw_free(snd_pcm_t *pcm ATTRIBUTE_UNUSED)
return 0;
}
-int snd_pcm_direct_sw_params(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_sw_params_t * params ATTRIBUTE_UNUSED)
+int snd_pcm_direct_sw_params(snd_pcm_t *pcm, snd_pcm_sw_params_t *params)
{
+ if (params->tstamp_type != pcm->tstamp_type)
+ return -EINVAL;
+
/* values are cached in the pcm structure */
return 0;
}
@@ -1318,6 +1321,15 @@ int snd_pcm_direct_initialize_slave(snd_pcm_direct_t *dmix, snd_pcm_t *spcm, str
return ret;
}
+ if (dmix->tstamp_type != -1) {
+ ret = snd_pcm_sw_params_set_tstamp_type(spcm, &sw_params,
+ dmix->tstamp_type);
+ if (ret < 0) {
+ SNDERR("unable to set tstamp type");
+ return ret;
+ }
+ }
+
if (dmix->type != SND_PCM_TYPE_DMIX &&
dmix->type != SND_PCM_TYPE_DSHARE)
goto __skip_silencing;
@@ -1878,6 +1890,7 @@ int snd_pcm_direct_parse_open_conf(snd_config_t *root, snd_config_t *conf,
rec->var_periodsize = 0;
rec->direct_memory_access = 1;
rec->hw_ptr_alignment = SND_PCM_HW_PTR_ALIGNMENT_AUTO;
+ rec->tstamp_type = -1;
/* read defaults */
if (snd_config_search(root, "defaults.pcm.dmix_max_periods", &n) >= 0) {
@@ -1941,6 +1954,27 @@ int snd_pcm_direct_parse_open_conf(snd_config_t *root, snd_config_t *conf,
continue;
}
+ if (strcmp(id, "tstamp_type") == 0) {
+ const char *str;
+ err = snd_config_get_string(n, &str);
+ if (err < 0) {
+ SNDERR("Invalid type for %s", id);
+ return -EINVAL;
+ }
+ if (strcmp(str, "default") == 0)
+ rec->tstamp_type = -1;
+ else if (strcmp(str, "gettimeofday") == 0)
+ rec->tstamp_type = SND_PCM_TSTAMP_TYPE_GETTIMEOFDAY;
+ else if (strcmp(str, "monotonic") == 0)
+ rec->tstamp_type = SND_PCM_TSTAMP_TYPE_MONOTONIC;
+ else if (strcmp(str, "monotonic_raw") == 0)
+ rec->tstamp_type = SND_PCM_TSTAMP_TYPE_MONOTONIC_RAW;
+ else {
+ SNDERR("The field tstamp_type is invalid : %s", str);
+ return -EINVAL;
+ }
+ continue;
+ }
if (strcmp(id, "ipc_gid") == 0) {
char *group;
char *endp;
diff --git a/src/pcm/pcm_direct.h b/src/pcm/pcm_direct.h
index 221edbe16879..8a236970a3a1 100644
--- a/src/pcm/pcm_direct.h
+++ b/src/pcm/pcm_direct.h
@@ -173,6 +173,7 @@ struct snd_pcm_direct {
unsigned int recoveries; /* mirror of executed recoveries on slave */
int direct_memory_access; /* use arch-optimized buffer RW */
snd_pcm_direct_hw_ptr_alignment_t hw_ptr_alignment;
+ int tstamp_type; /* cached from conf, can be -1(default) on top of real types */
union {
struct {
int shmid_sum; /* IPC global sum ring buffer memory identification */
@@ -357,6 +358,7 @@ struct snd_pcm_direct_open_conf {
int var_periodsize;
int direct_memory_access;
snd_pcm_direct_hw_ptr_alignment_t hw_ptr_alignment;
+ int tstamp_type;
snd_config_t *slave;
snd_config_t *bindings;
};
diff --git a/src/pcm/pcm_dmix.c b/src/pcm/pcm_dmix.c
index d533f40c5892..843fa3168756 100644
--- a/src/pcm/pcm_dmix.c
+++ b/src/pcm/pcm_dmix.c
@@ -1038,6 +1038,7 @@ int snd_pcm_dmix_open(snd_pcm_t **pcmp, const char *name,
dmix->ipc_key = opts->ipc_key;
dmix->ipc_perm = opts->ipc_perm;
dmix->ipc_gid = opts->ipc_gid;
+ dmix->tstamp_type = opts->tstamp_type;
dmix->semid = -1;
dmix->shmid = -1;
@@ -1237,6 +1238,9 @@ pcm.name {
# roundup
# rounddown
# auto (default)
+ tstamp_type STR # timestamp type
+ # STR can be one of the below strings :
+ # default, gettimeofday, monotonic, monotonic_raw
slave STR
# or
slave { # Slave definition
diff --git a/src/pcm/pcm_dshare.c b/src/pcm/pcm_dshare.c
index 59448cfb5883..6a99452b80fb 100644
--- a/src/pcm/pcm_dshare.c
+++ b/src/pcm/pcm_dshare.c
@@ -723,6 +723,7 @@ int snd_pcm_dshare_open(snd_pcm_t **pcmp, const char *name,
dshare->ipc_key = opts->ipc_key;
dshare->ipc_perm = opts->ipc_perm;
dshare->ipc_gid = opts->ipc_gid;
+ dshare->tstamp_type = opts->tstamp_type;
dshare->semid = -1;
dshare->shmid = -1;
@@ -929,6 +930,9 @@ pcm.name {
# roundup
# rounddown
# auto (default)
+ tstamp_type STR # timestamp type
+ # STR can be one of the below strings :
+ # default, gettimeofday, monotonic, monotonic_raw
slave STR
# or
slave { # Slave definition
diff --git a/src/pcm/pcm_dsnoop.c b/src/pcm/pcm_dsnoop.c
index 24f472c72c8e..c64df381e225 100644
--- a/src/pcm/pcm_dsnoop.c
+++ b/src/pcm/pcm_dsnoop.c
@@ -591,6 +591,7 @@ int snd_pcm_dsnoop_open(snd_pcm_t **pcmp, const char *name,
dsnoop->ipc_key = opts->ipc_key;
dsnoop->ipc_perm = opts->ipc_perm;
dsnoop->ipc_gid = opts->ipc_gid;
+ dsnoop->tstamp_type = opts->tstamp_type;
dsnoop->semid = -1;
dsnoop->shmid = -1;
@@ -780,6 +781,9 @@ pcm.name {
# roundup
# rounddown
# auto (default)
+ tstamp_type STR # timestamp type
+ # STR can be one of the below strings :
+ # default, gettimeofday, monotonic, monotonic_raw
slave STR
# or
slave { # Slave definition
diff --git a/src/pcm/pcm_local.h b/src/pcm/pcm_local.h
index 05ed935f1f16..89d4125b875d 100644
--- a/src/pcm/pcm_local.h
+++ b/src/pcm/pcm_local.h
@@ -928,6 +928,8 @@ int INTERNAL(snd_pcm_hw_params_set_buffer_size_last)(snd_pcm_t *pcm, snd_pcm_hw_
int snd_pcm_sw_params_set_tstamp_mode(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_tstamp_t val);
int INTERNAL(snd_pcm_sw_params_get_tstamp_mode)(const snd_pcm_sw_params_t *params, snd_pcm_tstamp_t *val);
+int snd_pcm_sw_params_set_tstamp_type(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_tstamp_type_t val);
+int snd_pcm_sw_params_get_tstamp_type(const snd_pcm_sw_params_t *params, snd_pcm_tstamp_type_t *val);
int snd_pcm_sw_params_set_avail_min(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val);
int INTERNAL(snd_pcm_sw_params_get_avail_min)(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val);
int snd_pcm_sw_params_set_start_threshold(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val);
--
2.16.4