hi-res timer commit broke FreeBSD. This attempts to go back to the

old code for FreeBSD.
This commit is contained in:
ejurgensen 2014-02-08 22:59:07 +01:00
parent 01f290cc2a
commit 258163e6ce
4 changed files with 38 additions and 13 deletions

View File

@ -750,11 +750,11 @@ murmur_hash64(const void *key, int len, uint32_t seed)
return h; return h;
} }
#else #else
# error Platform not supported # error Platform not supported
#endif #endif
#if defined(__linux__)
int int
clock_gettime_with_res(clockid_t clock_id, struct timespec *tp, struct timespec *res) clock_gettime_with_res(clockid_t clock_id, struct timespec *tp, struct timespec *res)
{ {
@ -805,3 +805,4 @@ timespec_cmp(struct timespec time1, struct timespec time2)
else else
return 0; return 0;
} }
#endif /* __linux__ */

View File

@ -3,7 +3,9 @@
#define __MISC_H__ #define __MISC_H__
#include <stdint.h> #include <stdint.h>
#if defined(__linux__)
# include <time.h> # include <time.h>
#endif
struct onekeyval { struct onekeyval {
char *name; char *name;
@ -72,7 +74,8 @@ b64_encode(uint8_t *in, size_t len);
uint64_t uint64_t
murmur_hash64(const void *key, int len, uint32_t seed); murmur_hash64(const void *key, int len, uint32_t seed);
/* timer functions */ #if defined(__linux__)
/* Timer functions for platforms without hi-res timers */
int int
clock_gettime_with_res(clockid_t clock_id, struct timespec *tp, struct timespec *res); clock_gettime_with_res(clockid_t clock_id, struct timespec *tp, struct timespec *res);
@ -81,6 +84,6 @@ timespec_add(struct timespec time1, struct timespec time2);
int int
timespec_cmp(struct timespec time1, struct timespec time2); timespec_cmp(struct timespec time1, struct timespec time2);
#endif /* __linux__ */
#endif /* !__MISC_H__ */ #endif /* !__MISC_H__ */

View File

@ -366,7 +366,11 @@ player_get_current_pos_clock(uint64_t *pos, struct timespec *ts, int commit)
uint64_t delta; uint64_t delta;
int ret; int ret;
#if defined(__linux__)
ret = clock_gettime_with_res(CLOCK_MONOTONIC, ts, &timer_res); ret = clock_gettime_with_res(CLOCK_MONOTONIC, ts, &timer_res);
#else
ret = clock_gettime(CLOCK_MONOTONIC, ts);
#endif
if (ret < 0) if (ret < 0)
{ {
DPRINTF(E_LOG, L_PLAYER, "Couldn't get clock: %s\n", strerror(errno)); DPRINTF(E_LOG, L_PLAYER, "Couldn't get clock: %s\n", strerror(errno));
@ -410,7 +414,11 @@ player_get_current_pos_laudio(uint64_t *pos, struct timespec *ts, int commit)
*pos = laudio_get_pos(); *pos = laudio_get_pos();
#if defined(__linux__)
ret = clock_gettime_with_res(CLOCK_MONOTONIC, ts, &timer_res); ret = clock_gettime_with_res(CLOCK_MONOTONIC, ts, &timer_res);
#else
ret = clock_gettime(CLOCK_MONOTONIC, ts);
#endif
if (ret < 0) if (ret < 0)
{ {
DPRINTF(E_LOG, L_PLAYER, "Couldn't get clock: %s\n", strerror(errno)); DPRINTF(E_LOG, L_PLAYER, "Couldn't get clock: %s\n", strerror(errno));
@ -1423,10 +1431,12 @@ player_playback_cb(int fd, short what, void *arg)
if (packet_send_count > 126) if (packet_send_count > 126)
{ {
DPRINTF(E_LOG, L_PLAYER, "Timing error detected during playback! Aborting.\n"); DPRINTF(E_LOG, L_PLAYER, "Timing error detected during playback! Aborting.\n");
playback_abort(); playback_abort();
return; return;
} }
} }
while(timespec_cmp(packet_timer_last, next_tick) < 0); while(timespec_cmp(packet_timer_last, next_tick) < 0);
/* Make sure playback is still running */ /* Make sure playback is still running */
@ -1857,7 +1867,11 @@ device_activate_cb(struct raop_device *dev, struct raop_session *rs, enum raop_s
if ((player_state == PLAY_PLAYING) && (raop_sessions == 1)) if ((player_state == PLAY_PLAYING) && (raop_sessions == 1))
{ {
#if defined(__linux__)
ret = clock_gettime_with_res(CLOCK_MONOTONIC, &ts, &timer_res); ret = clock_gettime_with_res(CLOCK_MONOTONIC, &ts, &timer_res);
#else
ret = clock_gettime(CLOCK_MONOTONIC, &ts);
#endif
if (ret < 0) if (ret < 0)
{ {
DPRINTF(E_LOG, L_PLAYER, "Could not get current time: %s\n", strerror(errno)); DPRINTF(E_LOG, L_PLAYER, "Could not get current time: %s\n", strerror(errno));
@ -2183,7 +2197,11 @@ playback_start_bh(struct player_command *cmd)
} }
} }
#if defined(__linux__)
ret = clock_gettime_with_res(CLOCK_MONOTONIC, &pb_pos_stamp, &timer_res); ret = clock_gettime_with_res(CLOCK_MONOTONIC, &pb_pos_stamp, &timer_res);
#else
ret = clock_gettime(CLOCK_MONOTONIC, &pb_pos_stamp);
#endif
if (ret < 0) if (ret < 0)
{ {
DPRINTF(E_LOG, L_PLAYER, "Couldn't get current clock: %s\n", strerror(errno)); DPRINTF(E_LOG, L_PLAYER, "Couldn't get current clock: %s\n", strerror(errno));
@ -4054,6 +4072,7 @@ player_init(void)
update_handler = NULL; update_handler = NULL;
#if defined(__linux__)
/* /*
* Determine if the resolution of the system timer is > or < the size * Determine if the resolution of the system timer is > or < the size
* of an audio packet. NOTE: this assumes the system clock resolution * of an audio packet. NOTE: this assumes the system clock resolution
@ -4062,9 +4081,11 @@ player_init(void)
if (clock_getres(CLOCK_MONOTONIC, &timer_res) < 0) if (clock_getres(CLOCK_MONOTONIC, &timer_res) < 0)
{ {
DPRINTF(E_LOG, L_PLAYER, "Could not get the system timer resolution.\n"); DPRINTF(E_LOG, L_PLAYER, "Could not get the system timer resolution.\n");
return -1; return -1;
} }
MINIMUM_STREAM_PERIOD = MAX(timer_res.tv_nsec, AIRTUNES_V2_STREAM_PERIOD); MINIMUM_STREAM_PERIOD = MAX(timer_res.tv_nsec, AIRTUNES_V2_STREAM_PERIOD);
#endif
/* Random RTP time start */ /* Random RTP time start */
gcry_randomize(&rnd, sizeof(rnd), GCRY_STRONG_RANDOM); gcry_randomize(&rnd, sizeof(rnd), GCRY_STRONG_RANDOM);