mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-11-03 09:01:52 -05:00
check availability of CLOCK_MONOTONIC
Use monotonic timestamps only after checking that CLOCK_MONOTONIC is actually supported by the C library.
This commit is contained in:
parent
07e1341548
commit
0e8a259914
2 changed files with 16 additions and 7 deletions
|
|
@ -412,7 +412,9 @@ int snd_pcm_file_open(snd_pcm_t **pcmp, const char *name,
|
||||||
snd_pcm_t *pcm;
|
snd_pcm_t *pcm;
|
||||||
snd_pcm_file_t *file;
|
snd_pcm_file_t *file;
|
||||||
snd_pcm_file_format_t format;
|
snd_pcm_file_format_t format;
|
||||||
|
struct timespec timespec;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
assert(pcmp);
|
assert(pcmp);
|
||||||
if (fmt == NULL ||
|
if (fmt == NULL ||
|
||||||
strcmp(fmt, "raw") == 0)
|
strcmp(fmt, "raw") == 0)
|
||||||
|
|
@ -467,7 +469,11 @@ int snd_pcm_file_open(snd_pcm_t **pcmp, const char *name,
|
||||||
pcm->poll_fd = slave->poll_fd;
|
pcm->poll_fd = slave->poll_fd;
|
||||||
pcm->poll_events = slave->poll_events;
|
pcm->poll_events = slave->poll_events;
|
||||||
pcm->mmap_shadow = 1;
|
pcm->mmap_shadow = 1;
|
||||||
pcm->monotonic = 1;
|
#ifdef HAVE_CLOCK_GETTIME
|
||||||
|
pcm->monotonic = clock_gettime(CLOCK_MONOTONIC, ×pec) == 0;
|
||||||
|
#else
|
||||||
|
pcm->monotonic = 0;
|
||||||
|
#endif
|
||||||
snd_pcm_link_hw_ptr(pcm, slave);
|
snd_pcm_link_hw_ptr(pcm, slave);
|
||||||
snd_pcm_link_appl_ptr(pcm, slave);
|
snd_pcm_link_appl_ptr(pcm, slave);
|
||||||
*pcmp = pcm;
|
*pcmp = pcm;
|
||||||
|
|
|
||||||
|
|
@ -996,6 +996,8 @@ int snd_pcm_hw_open_fd(snd_pcm_t **pcmp, const char *name,
|
||||||
|
|
||||||
#ifdef HAVE_CLOCK_GETTIME
|
#ifdef HAVE_CLOCK_GETTIME
|
||||||
if (SNDRV_PROTOCOL_VERSION(2, 0, 9) <= ver) {
|
if (SNDRV_PROTOCOL_VERSION(2, 0, 9) <= ver) {
|
||||||
|
struct timespec timespec;
|
||||||
|
if (clock_gettime(CLOCK_MONOTONIC, ×pec) == 0) {
|
||||||
int on = SNDRV_PCM_TSTAMP_TYPE_MONOTONIC;
|
int on = SNDRV_PCM_TSTAMP_TYPE_MONOTONIC;
|
||||||
if (ioctl(fd, SNDRV_PCM_IOCTL_TTSTAMP, &on) < 0) {
|
if (ioctl(fd, SNDRV_PCM_IOCTL_TTSTAMP, &on) < 0) {
|
||||||
ret = -errno;
|
ret = -errno;
|
||||||
|
|
@ -1004,6 +1006,7 @@ int snd_pcm_hw_open_fd(snd_pcm_t **pcmp, const char *name,
|
||||||
}
|
}
|
||||||
monotonic = 1;
|
monotonic = 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
else if (SNDRV_PROTOCOL_VERSION(2, 0, 5) <= ver) {
|
else if (SNDRV_PROTOCOL_VERSION(2, 0, 5) <= ver) {
|
||||||
int on = 1;
|
int on = 1;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue