pa_assert(r);
pa_assert(u);
+ pa_log_debug("Suspending source %s, because another application requested us to release the device.", u->source->name);
+
if (pa_source_suspend(u->source, TRUE, PA_SUSPEND_APPLICATION) < 0)
return PA_HOOK_CANCEL;
}
static pa_hook_result_t monitor_cb(pa_reserve_monitor_wrapper *w, void* busy, struct userdata *u) {
- pa_bool_t b;
-
pa_assert(w);
pa_assert(u);
- b = PA_PTR_TO_UINT(busy) && !u->reserve;
+ if (PA_PTR_TO_UINT(busy) && !u->reserve) {
+ pa_log_debug("Suspending source %s, because another application is blocking the access to the device.", u->source->name);
+ pa_source_suspend(u->source, true, PA_SUSPEND_APPLICATION);
+ } else {
+ pa_log_debug("Resuming source %s, because other applications aren't blocking access to the device any more.", u->source->name);
+ pa_source_suspend(u->source, false, PA_SUSPEND_APPLICATION);
+ }
- pa_source_suspend(u->source, b, PA_SUSPEND_APPLICATION);
return PA_HOOK_OK;
}
int err;
pa_usec_t now1 = 0, now2;
snd_pcm_status_t *status;
+ snd_htimestamp_t htstamp = { 0, 0 };
snd_pcm_status_alloca(&status);
/* Let's update the time smoother */
- if (PA_UNLIKELY((err = pa_alsa_safe_delay(u->pcm_handle, &delay, u->hwbuf_size, &u->source->sample_spec, TRUE)) < 0)) {
+ if (PA_UNLIKELY((err = pa_alsa_safe_delay(u->pcm_handle, status, &delay, u->hwbuf_size, &u->source->sample_spec, TRUE)) < 0)) {
pa_log_warn("Failed to get delay: %s", pa_alsa_strerror(err));
return;
}
- if (PA_UNLIKELY((err = snd_pcm_status(u->pcm_handle, status)) < 0))
- pa_log_warn("Failed to get timestamp: %s", pa_alsa_strerror(err));
- else {
- snd_htimestamp_t htstamp = { 0, 0 };
- snd_pcm_status_get_htstamp(status, &htstamp);
- now1 = pa_timespec_load(&htstamp);
- }
+ snd_pcm_status_get_htstamp(status, &htstamp);
+ now1 = pa_timespec_load(&htstamp);
/* Hmm, if the timestamp is 0, then it wasn't set and we take the current time */
if (now1 <= 0)
for (;;) {
int ret;
- pa_usec_t rtpoll_sleep = 0;
+ pa_usec_t rtpoll_sleep = 0, real_sleep;
#ifdef DEBUG_TIMING
pa_log_debug("Loop");
}
}
- if (rtpoll_sleep > 0)
+ if (rtpoll_sleep > 0) {
pa_rtpoll_set_timer_relative(u->rtpoll, rtpoll_sleep);
+ real_sleep = pa_rtclock_now();
+ }
else
pa_rtpoll_set_timer_disabled(u->rtpoll);
if ((ret = pa_rtpoll_run(u->rtpoll, TRUE)) < 0)
goto fail;
+ if (rtpoll_sleep > 0) {
+ real_sleep = pa_rtclock_now() - real_sleep;
+#ifdef DEBUG_TIMING
+ pa_log_debug("Expected sleep: %0.2fms, real sleep: %0.2fms (diff %0.2f ms)",
+ (double) rtpoll_sleep / PA_USEC_PER_MSEC, (double) real_sleep / PA_USEC_PER_MSEC,
+ (double) ((int64_t) real_sleep - (int64_t) rtpoll_sleep) / PA_USEC_PER_MSEC);
+#endif
+ if (u->use_tsched && real_sleep > rtpoll_sleep + u->tsched_watermark)
+ pa_log_info("Scheduling delay of %0.2fms, you might want to investigate this to improve latency...",
+ (double) (real_sleep - rtpoll_sleep) / PA_USEC_PER_MSEC);
+ }
+
if (u->source->flags & PA_SOURCE_DEFERRED_VOLUME)
pa_source_volume_change_apply(u->source, NULL);
pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, pa_card *card, pa_alsa_mapping *mapping) {
struct userdata *u = NULL;
- const char *dev_id = NULL, *key;
+ const char *dev_id = NULL, *key, *mod_name;
pa_sample_spec ss;
uint32_t alternate_sample_rate;
pa_channel_map map;
goto fail;
}
+ if ((mod_name = pa_proplist_gets(mapping->proplist, PA_ALSA_PROP_UCM_MODIFIER))) {
+ if (snd_use_case_set(u->ucm_context->ucm->ucm_mgr, "_enamod", mod_name) < 0)
+ pa_log("Failed to enable ucm modifier %s", mod_name);
+ else
+ pa_log_debug("Enabled ucm modifier %s", mod_name);
+ }
+
if (!(u->pcm_handle = pa_alsa_open_by_device_id_mapping(
dev_id,
&u->device_name,
pa_log_info("Disabling latency range changes on overrun");
}
- u->rates = pa_alsa_get_supported_rates(u->pcm_handle);
+ u->rates = pa_alsa_get_supported_rates(u->pcm_handle, ss.rate);
if (!u->rates) {
pa_log_error("Failed to find any supported sample rates.");
goto fail;