AC_MSG_RESULT(no)
fi
+dnl Check for librt
+AC_MSG_CHECKING(for librt)
+AC_ARG_WITH(librt,
+ AS_HELP_STRING([--with-librt], [Use librt for monotonic clock (default = yes)]),
+ [ have_librt="$withval" ], [ have_librt="yes" ])
+if test "$have_librt" = "yes"; then
+ AC_CHECK_LIB([rt], [clock_gettime], [HAVE_LIBRT="yes"])
+ if test "$HAVE_LIBRT" = "yes" ; then
+ ALSA_DEPLIBS="$ALSA_DEPLIBS -lrt"
+ AC_DEFINE([HAVE_LIBRT], 1, [Have librt])
+ AC_DEFINE([HAVE_CLOCK_GETTIME], 1, [Have clock gettime])
+ fi
+else
+ AC_MSG_RESULT(no)
+fi
+
AC_SUBST(ALSA_DEPLIBS)
dnl Check for architecture
* bit flags for additional conditions
*/
#define SND_PCM_IOPLUG_FLAG_LISTED (1<<0) /* list up this PCM */
+#define SND_PCM_IOPLUG_FLAG_MONOTONIC (1<<1) /* monotonic timestamps */
/*
* Protocol version
pcm->private_data = adpcm;
pcm->poll_fd = slave->poll_fd;
pcm->poll_events = slave->poll_events;
+ pcm->monotonic = slave->monotonic;
snd_pcm_set_hw_ptr(pcm, &adpcm->plug.hw_ptr, -1, 0);
snd_pcm_set_appl_ptr(pcm, &adpcm->plug.appl_ptr, -1, 0);
*pcmp = pcm;
pcm->private_data = alaw;
pcm->poll_fd = slave->poll_fd;
pcm->poll_events = slave->poll_events;
+ pcm->monotonic = slave->monotonic;
snd_pcm_set_hw_ptr(pcm, &alaw->plug.hw_ptr, -1, 0);
snd_pcm_set_appl_ptr(pcm, &alaw->plug.appl_ptr, -1, 0);
*pcmp = pcm;
pcm->private_data = copy;
pcm->poll_fd = slave->poll_fd;
pcm->poll_events = slave->poll_events;
+ pcm->monotonic = slave->monotonic;
snd_pcm_set_hw_ptr(pcm, ©->plug.hw_ptr, -1, 0);
snd_pcm_set_appl_ptr(pcm, ©->plug.appl_ptr, -1, 0);
*pcmp = pcm;
unsigned int period_size;
unsigned int period_time;
snd_interval_t periods;
- unsigned int tick_time; /* not used */
+ unsigned int monotonic;
snd_pcm_tstamp_t tstamp_mode;
unsigned int period_step;
unsigned int sleep_min; /* not used */
dmix->avail_max = avail;
if (avail >= pcm->stop_threshold) {
snd_timer_stop(dmix->timer);
- gettimestamp(&dmix->trigger_tstamp);
+ gettimestamp(&dmix->trigger_tstamp, pcm->monotonic);
if (dmix->state == SND_PCM_STATE_RUNNING) {
dmix->state = SND_PCM_STATE_XRUN;
return -EPIPE;
if (pcm->tstamp_mode == SND_PCM_TSTAMP_MMAP)
status->tstamp = snd_pcm_hw_fast_tstamp(dmix->spcm);
else
- gettimestamp(&status->tstamp);
+ gettimestamp(&status->tstamp, pcm->monotonic);
status->avail = snd_pcm_mmap_playback_avail(pcm);
status->avail_max = status->avail > dmix->avail_max ? status->avail : dmix->avail_max;
dmix->avail_max = 0;
return err;
snd_pcm_dmix_sync_area(pcm);
}
- gettimestamp(&dmix->trigger_tstamp);
+ gettimestamp(&dmix->trigger_tstamp, pcm->monotonic);
return 0;
}
dshare->avail_max = avail;
if (avail >= pcm->stop_threshold) {
snd_timer_stop(dshare->timer);
- gettimestamp(&dshare->trigger_tstamp);
+ gettimestamp(&dshare->trigger_tstamp, pcm->monotonic);
if (dshare->state == SND_PCM_STATE_RUNNING) {
dshare->state = SND_PCM_STATE_XRUN;
return -EPIPE;
if (pcm->tstamp_mode == SND_PCM_TSTAMP_MMAP)
status->tstamp = snd_pcm_hw_fast_tstamp(dshare->spcm);
else
- gettimestamp(&status->tstamp);
+ gettimestamp(&status->tstamp, pcm->monotonic);
status->avail = snd_pcm_mmap_playback_avail(pcm);
status->avail_max = status->avail > dshare->avail_max ? status->avail : dshare->avail_max;
dshare->avail_max = 0;
return err;
snd_pcm_dshare_sync_area(pcm);
}
- gettimestamp(&dshare->trigger_tstamp);
+ gettimestamp(&dshare->trigger_tstamp, pcm->monotonic);
return 0;
}
if (pcm->stop_threshold >= pcm->boundary) /* don't care */
return 0;
if ((avail = snd_pcm_mmap_capture_hw_avail(pcm)) >= pcm->stop_threshold) {
- gettimestamp(&dsnoop->trigger_tstamp);
+ gettimestamp(&dsnoop->trigger_tstamp, pcm->monotonic);
dsnoop->state = SND_PCM_STATE_XRUN;
dsnoop->avail_max = avail;
return -EPIPE;
if (pcm->tstamp_mode == SND_PCM_TSTAMP_MMAP)
status->tstamp = snd_pcm_hw_fast_tstamp(dsnoop->spcm);
else
- gettimestamp(&status->tstamp);
+ gettimestamp(&status->tstamp, pcm->monotonic);
status->avail = snd_pcm_mmap_capture_avail(pcm);
status->avail_max = status->avail > dsnoop->avail_max ? status->avail : dsnoop->avail_max;
dsnoop->avail_max = 0;
if (err < 0)
return err;
dsnoop->state = SND_PCM_STATE_RUNNING;
- gettimestamp(&dsnoop->trigger_tstamp);
+ gettimestamp(&dsnoop->trigger_tstamp, pcm->monotonic);
return 0;
}
pcm->poll_fd = slave->poll_fd;
pcm->poll_events = slave->poll_events;
pcm->mmap_shadow = 1;
+ pcm->monotonic = 1;
snd_pcm_link_hw_ptr(pcm, slave);
snd_pcm_link_appl_ptr(pcm, slave);
*pcmp = pcm;
pcm->poll_fd = slave->poll_fd;
pcm->poll_events = slave->poll_events;
pcm->mmap_shadow = 1;
+ pcm->monotonic = slave->monotonic;
snd_pcm_link_hw_ptr(pcm, slave);
snd_pcm_link_appl_ptr(pcm, slave);
*pcmp = pcm;
int fd, int mmap_emulation ATTRIBUTE_UNUSED,
int sync_ptr_ioctl)
{
- int ver;
+ int ver, mode, monotonic = 0;
long fmode;
- int mode;
snd_pcm_t *pcm = NULL;
snd_pcm_hw_t *hw = NULL;
snd_pcm_info_t info;
ret = -errno;
SNDMSG("TSTAMP failed\n");
return ret;
- }
+ }
+ }
+#ifdef HAVE_CLOCK_GETTIME
+ else if (SNDRV_PROTOCOL_VERSION(2, 0, 9) >= ver) {
+ int on = SNDRV_PCM_TSTAMP_TYPE_MONOTONIC;
+ if (ioctl(fd, SNDRV_PCM_IOCTL_TTSTAMP, &on) < 0) {
+ ret = -errno;
+ SNDMSG("TTSTAMP failed\n");
+ return ret;
+ }
+ monotonic = 1;
}
+#endif
hw = calloc(1, sizeof(snd_pcm_hw_t));
if (!hw) {
pcm->private_data = hw;
pcm->poll_fd = fd;
pcm->poll_events = info.stream == SND_PCM_STREAM_PLAYBACK ? POLLOUT : POLLIN;
+ pcm->monotonic = monotonic;
ret = snd_pcm_hw_mmap_status(pcm);
if (ret < 0) {
pcm->private_data = iec;
pcm->poll_fd = slave->poll_fd;
pcm->poll_events = slave->poll_events;
+ pcm->monotonic = slave->monotonic;
snd_pcm_set_hw_ptr(pcm, &iec->plug.hw_ptr, -1, 0);
snd_pcm_set_appl_ptr(pcm, &iec->plug.appl_ptr, -1, 0);
*pcmp = pcm;
if (err < 0)
return err;
- gettimestamp(&io->trigger_tstamp);
+ gettimestamp(&io->trigger_tstamp, pcm->monotonic);
io->data->state = SND_PCM_STATE_RUNNING;
return 0;
io->data->callback->stop(io->data);
- gettimestamp(&io->trigger_tstamp);
+ gettimestamp(&io->trigger_tstamp, pcm->monotonic);
io->data->state = SND_PCM_STATE_SETUP;
return 0;
{
ioplug->pcm->poll_fd = ioplug->poll_fd;
ioplug->pcm->poll_events = ioplug->poll_events;
+ ioplug->pcm->monotonic = (ioplug->flags & SND_PCM_IOPLUG_FLAG_MONOTONIC) != 0;
ioplug->pcm->mmap_rw = ioplug->mmap_rw;
return 0;
}
pcm->private_data = ladspa;
pcm->poll_fd = slave->poll_fd;
pcm->poll_events = slave->poll_events;
+ pcm->monotonic = slave->monotonic;
snd_pcm_set_hw_ptr(pcm, &ladspa->plug.hw_ptr, -1, 0);
snd_pcm_set_appl_ptr(pcm, &ladspa->plug.appl_ptr, -1, 0);
*pcmp = pcm;
pcm->private_data = lfloat;
pcm->poll_fd = slave->poll_fd;
pcm->poll_events = slave->poll_events;
+ pcm->monotonic = slave->monotonic;
snd_pcm_set_hw_ptr(pcm, &lfloat->plug.hw_ptr, -1, 0);
snd_pcm_set_appl_ptr(pcm, &lfloat->plug.appl_ptr, -1, 0);
*pcmp = pcm;
pcm->private_data = linear;
pcm->poll_fd = slave->poll_fd;
pcm->poll_events = slave->poll_events;
+ pcm->monotonic = slave->monotonic;
snd_pcm_set_hw_ptr(pcm, &linear->plug.hw_ptr, -1, 0);
snd_pcm_set_appl_ptr(pcm, &linear->plug.appl_ptr, -1, 0);
*pcmp = pcm;
int poll_fd_count;
int poll_fd;
unsigned short poll_events;
- int setup;
+ int setup: 1,
+ monotonic: 1;
snd_pcm_access_t access; /* access mode */
snd_pcm_format_t format; /* SND_PCM_FORMAT_* */
snd_pcm_subformat_t subformat; /* subformat */
} snd_tmp_double_t;
/* get the current timestamp */
-static inline void gettimestamp(snd_htimestamp_t *tstamp)
+static inline void gettimestamp(snd_htimestamp_t *tstamp, int monotonic)
{
- struct timeval tv;
-
- gettimeofday(&tv, 0);
- tstamp->tv_sec = tv.tv_sec;
- tstamp->tv_nsec = tv.tv_usec * 1000L;
+ if (monotonic) {
+ clock_gettime(CLOCK_MONOTONIC, tstamp);
+ } else {
+ struct timeval tv;
+
+ gettimeofday(&tv, 0);
+ tstamp->tv_sec = tv.tv_sec;
+ tstamp->tv_nsec = tv.tv_usec * 1000L;
+ }
}
pcm->private_data = meter;
pcm->poll_fd = slave->poll_fd;
pcm->poll_events = slave->poll_events;
+ pcm->monotonic = slave->monotonic;
snd_pcm_link_hw_ptr(pcm, slave);
snd_pcm_link_appl_ptr(pcm, slave);
*pcmp = pcm;
pcm->private_data = map;
pcm->poll_fd = slave->poll_fd;
pcm->poll_events = slave->poll_events;
+ pcm->monotonic = slave->monotonic;
snd_pcm_set_hw_ptr(pcm, &map->hw_ptr, -1, 0);
snd_pcm_set_appl_ptr(pcm, &map->appl_ptr, -1, 0);
*pcmp = pcm;
pcm->private_data = mulaw;
pcm->poll_fd = slave->poll_fd;
pcm->poll_events = slave->poll_events;
+ pcm->monotonic = slave->monotonic;
snd_pcm_set_hw_ptr(pcm, &mulaw->plug.hw_ptr, -1, 0);
snd_pcm_set_appl_ptr(pcm, &mulaw->plug.appl_ptr, -1, 0);
*pcmp = pcm;
pcm->private_data = multi;
pcm->poll_fd = multi->slaves[master_slave].pcm->poll_fd;
pcm->poll_events = multi->slaves[master_slave].pcm->poll_events;
+ pcm->monotonic = multi->slaves[master_slave].pcm->monotonic;
snd_pcm_link_hw_ptr(pcm, multi->slaves[master_slave].pcm);
snd_pcm_link_appl_ptr(pcm, multi->slaves[master_slave].pcm);
*pcmp = pcm;
memset(status, 0, sizeof(*status));
status->state = null->state;
status->trigger_tstamp = null->trigger_tstamp;
- gettimestamp(&status->tstamp);
+ gettimestamp(&status->tstamp, pcm->monotonic);
status->avail = pcm->buffer_size;
status->avail_max = status->avail;
return 0;
pcm->poll_fd = slave->poll_fd;
pcm->poll_events = slave->poll_events;
pcm->mmap_shadow = 1;
+ pcm->monotonic = slave->monotonic;
snd_pcm_link_hw_ptr(pcm, slave);
snd_pcm_link_appl_ptr(pcm, slave);
*pcmp = pcm;
if (snd_pcm_state(rate->gen.slave) != SND_PCM_STATE_PREPARED)
return -EBADFD;
- gettimestamp(&rate->trigger_tstamp);
+ gettimestamp(&rate->trigger_tstamp, pcm->monotonic);
avail = snd_pcm_mmap_playback_hw_avail(rate->gen.slave);
if (avail == 0) {
pcm->poll_fd = slave->poll_fd;
pcm->poll_events = slave->poll_events;
pcm->mmap_rw = 1;
+ pcm->monotonic = slave->monotonic;
snd_pcm_set_hw_ptr(pcm, &rate->hw_ptr, -1, 0);
snd_pcm_set_appl_ptr(pcm, &rate->appl_ptr, -1, 0);
*pcmp = pcm;
pcm->private_data = route;
pcm->poll_fd = slave->poll_fd;
pcm->poll_events = slave->poll_events;
+ pcm->monotonic = slave->monotonic;
snd_pcm_set_hw_ptr(pcm, &route->plug.hw_ptr, -1, 0);
snd_pcm_set_appl_ptr(pcm, &route->plug.appl_ptr, -1, 0);
err = route_load_ttable(&route->params, pcm->stream, tt_ssize, ttable, tt_cused, tt_sused);
}
slave->running_count++;
_snd_pcm_share_update(pcm);
- gettimestamp(&share->trigger_tstamp);
+ gettimestamp(&share->trigger_tstamp, pcm->monotonic);
_end:
Pthread_mutex_unlock(&slave->mutex);
return err;
return;
}
#endif
- gettimestamp(&share->trigger_tstamp);
+ gettimestamp(&share->trigger_tstamp, pcm->monotonic);
if (pcm->stream == SND_PCM_STREAM_CAPTURE) {
snd_pcm_areas_copy(pcm->stopped_areas, 0,
pcm->running_areas, 0,
pcm->private_data = share;
pcm->poll_fd = share->client_socket;
pcm->poll_events = stream == SND_PCM_STREAM_PLAYBACK ? POLLOUT : POLLIN;
+ pcm->monotonic = pcm->monotonic;
snd_pcm_set_hw_ptr(pcm, &share->hw_ptr, -1, 0);
snd_pcm_set_appl_ptr(pcm, &share->appl_ptr, -1, 0);
* an extra buffer.
*/
pcm->mmap_shadow = 1;
+ pcm->monotonic = slave->monotonic;
snd_pcm_set_hw_ptr(pcm, &svol->plug.hw_ptr, -1, 0);
snd_pcm_set_appl_ptr(pcm, &svol->plug.appl_ptr, -1, 0);
*pcmp = pcm;