From f76191c792e9072788ff5fa6a37fc0f4a5ef31e6 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 29 Jun 2023 16:23:39 +0200 Subject: [PATCH] alsa: add option to disable htimestamps Add api.alsa.htimestamp to disable the use of hires timestamps. --- spa/plugins/alsa/alsa-pcm.c | 29 ++++++++++++++++++++++------- spa/plugins/alsa/alsa-pcm.h | 1 + 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/spa/plugins/alsa/alsa-pcm.c b/spa/plugins/alsa/alsa-pcm.c index 6c8899d11..6478de1c1 100644 --- a/spa/plugins/alsa/alsa-pcm.c +++ b/spa/plugins/alsa/alsa-pcm.c @@ -128,6 +128,8 @@ static int alsa_set_param(struct state *state, const char *k, const char *s) state->props.use_chmap = spa_atob(s); } else if (spa_streq(k, "api.alsa.multi-rate")) { state->multi_rate = spa_atob(s); + } else if (spa_streq(k, "api.alsa.htimestamp")) { + state->htimestamp = spa_atob(s); } else if (spa_streq(k, "latency.internal.rate")) { state->process_latency.rate = atoi(s); } else if (spa_streq(k, "latency.internal.ns")) { @@ -308,6 +310,14 @@ struct spa_pod *spa_alsa_enum_propinfo(struct state *state, SPA_PROP_INFO_params, SPA_POD_Bool(true)); break; case 14: + param = spa_pod_builder_add_object(b, + SPA_TYPE_OBJECT_PropInfo, SPA_PARAM_PropInfo, + SPA_PROP_INFO_name, SPA_POD_String("api.alsa.htimestamp"), + SPA_PROP_INFO_description, SPA_POD_String("Use hires timestamps"), + SPA_PROP_INFO_type, SPA_POD_CHOICE_Bool(state->htimestamp), + SPA_PROP_INFO_params, SPA_POD_Bool(true)); + break; + case 15: param = spa_pod_builder_add_object(b, SPA_TYPE_OBJECT_PropInfo, SPA_PARAM_PropInfo, SPA_PROP_INFO_name, SPA_POD_String("latency.internal.rate"), @@ -316,7 +326,7 @@ struct spa_pod *spa_alsa_enum_propinfo(struct state *state, 0, 65536), SPA_PROP_INFO_params, SPA_POD_Bool(true)); break; - case 15: + case 16: param = spa_pod_builder_add_object(b, SPA_TYPE_OBJECT_PropInfo, SPA_PARAM_PropInfo, SPA_PROP_INFO_name, SPA_POD_String("latency.internal.ns"), @@ -325,7 +335,7 @@ struct spa_pod *spa_alsa_enum_propinfo(struct state *state, 0LL, 2 * SPA_NSEC_PER_SEC), SPA_PROP_INFO_params, SPA_POD_Bool(true)); break; - case 16: + case 17: param = spa_pod_builder_add_object(b, SPA_TYPE_OBJECT_PropInfo, SPA_PARAM_PropInfo, SPA_PROP_INFO_name, SPA_POD_String("clock.name"), @@ -394,6 +404,9 @@ int spa_alsa_add_prop_params(struct state *state, struct spa_pod_builder *b) spa_pod_builder_string(b, "api.alsa.multi-rate"); spa_pod_builder_bool(b, state->multi_rate); + spa_pod_builder_string(b, "api.alsa.htimestamp"); + spa_pod_builder_bool(b, state->htimestamp); + spa_pod_builder_string(b, "latency.internal.rate"); spa_pod_builder_int(b, state->process_latency.rate); @@ -490,6 +503,7 @@ int spa_alsa_init(struct state *state, const struct spa_dict *info) snd_config_update_free_global(); state->multi_rate = true; + state->htimestamp = true; for (i = 0; info && i < info->n_items; i++) { const char *k = info->items[i].key; const char *s = info->items[i].value; @@ -1957,7 +1971,6 @@ recover: return do_start(state); } -#if 0 static int get_avail(struct state *state, uint64_t current_time, snd_pcm_uframes_t *delay) { int res, missed; @@ -1980,8 +1993,7 @@ static int get_avail(struct state *state, uint64_t current_time, snd_pcm_uframes return avail; } -#else -static int get_avail(struct state *state, uint64_t current_time, snd_pcm_uframes_t *delay) +static int get_avail_htimestamp(struct state *state, uint64_t current_time, snd_pcm_uframes_t *delay) { int res, missed; snd_pcm_uframes_t avail; @@ -2023,7 +2035,6 @@ static int get_avail(struct state *state, uint64_t current_time, snd_pcm_uframes } return SPA_MIN(avail, state->buffer_frames); } -#endif static int get_status(struct state *state, uint64_t current_time, snd_pcm_uframes_t *avail, snd_pcm_uframes_t *delay, snd_pcm_uframes_t *target) @@ -2031,7 +2042,11 @@ static int get_status(struct state *state, uint64_t current_time, snd_pcm_uframe int res; snd_pcm_uframes_t a, d; - if ((res = get_avail(state, current_time, &d)) < 0) + if (state->htimestamp) + res = get_avail_htimestamp(state, current_time, &d); + else + res = get_avail(state, current_time, &d); + if (res < 0) return res; a = SPA_MIN(res, (int)state->buffer_frames); diff --git a/spa/plugins/alsa/alsa-pcm.h b/spa/plugins/alsa/alsa-pcm.h index a1295c6ec..3ae9a97de 100644 --- a/spa/plugins/alsa/alsa-pcm.h +++ b/spa/plugins/alsa/alsa-pcm.h @@ -201,6 +201,7 @@ struct state { unsigned int is_iec958:1; unsigned int is_hdmi:1; unsigned int multi_rate:1; + unsigned int htimestamp:1; uint64_t iec958_codecs;