diff --git a/src/misc.c b/src/misc.c index bdc1da40..6251d2d6 100644 --- a/src/misc.c +++ b/src/misc.c @@ -750,11 +750,11 @@ murmur_hash64(const void *key, int len, uint32_t seed) return h; } - #else # error Platform not supported #endif +#if defined(__linux__) int 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 return 0; } +#endif /* __linux__ */ diff --git a/src/misc.h b/src/misc.h index 4a1f2658..1207df5b 100644 --- a/src/misc.h +++ b/src/misc.h @@ -3,7 +3,9 @@ #define __MISC_H__ #include -#include +#if defined(__linux__) +# include +#endif struct onekeyval { char *name; @@ -72,7 +74,8 @@ b64_encode(uint8_t *in, size_t len); uint64_t murmur_hash64(const void *key, int len, uint32_t seed); -/* timer functions */ +#if defined(__linux__) +/* Timer functions for platforms without hi-res timers */ int 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 timespec_cmp(struct timespec time1, struct timespec time2); - +#endif /* __linux__ */ #endif /* !__MISC_H__ */ diff --git a/src/player.c b/src/player.c index 324a6348..55b0f533 100644 --- a/src/player.c +++ b/src/player.c @@ -366,7 +366,11 @@ player_get_current_pos_clock(uint64_t *pos, struct timespec *ts, int commit) uint64_t delta; int ret; +#if defined(__linux__) ret = clock_gettime_with_res(CLOCK_MONOTONIC, ts, &timer_res); +#else + ret = clock_gettime(CLOCK_MONOTONIC, ts); +#endif if (ret < 0) { 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(); +#if defined(__linux__) ret = clock_gettime_with_res(CLOCK_MONOTONIC, ts, &timer_res); +#else + ret = clock_gettime(CLOCK_MONOTONIC, ts); +#endif if (ret < 0) { DPRINTF(E_LOG, L_PLAYER, "Couldn't get clock: %s\n", strerror(errno)); @@ -1420,14 +1428,16 @@ player_playback_cb(int fd, short what, void *arg) packet_timer_last = timespec_add(packet_timer_last, packet_time); packet_send_count++; /* not possible to have more than 126 audio packets per second */ - if(packet_send_count > 126) - { - DPRINTF(E_LOG, L_PLAYER, "Timing error detected during playback! Aborting.\n"); - playback_abort(); - return; - } + if (packet_send_count > 126) + { + DPRINTF(E_LOG, L_PLAYER, "Timing error detected during playback! Aborting.\n"); + + playback_abort(); + 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 */ if (player_state == PLAY_STOPPED) @@ -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 defined(__linux__) ret = clock_gettime_with_res(CLOCK_MONOTONIC, &ts, &timer_res); +#else + ret = clock_gettime(CLOCK_MONOTONIC, &ts); +#endif if (ret < 0) { 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); +#else + ret = clock_gettime(CLOCK_MONOTONIC, &pb_pos_stamp); +#endif if (ret < 0) { DPRINTF(E_LOG, L_PLAYER, "Couldn't get current clock: %s\n", strerror(errno)); @@ -4054,17 +4072,20 @@ player_init(void) update_handler = NULL; +#if defined(__linux__) /* * Determine if the resolution of the system timer is > or < the size * of an audio packet. NOTE: this assumes the system clock resolution * is less than one second. */ - 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"); + return -1; } MINIMUM_STREAM_PERIOD = MAX(timer_res.tv_nsec, AIRTUNES_V2_STREAM_PERIOD); +#endif /* Random RTP time start */ gcry_randomize(&rnd, sizeof(rnd), GCRY_STRONG_RANDOM); diff --git a/src/player.h b/src/player.h index f52a61c3..7e42a3c9 100644 --- a/src/player.h +++ b/src/player.h @@ -7,7 +7,7 @@ #if defined(__linux__) /* AirTunes v2 packet interval in ns */ /* (352 samples/packet * 1e9 ns/s) / 44100 samples/s = 7981859 ns/packet */ -#define AIRTUNES_V2_STREAM_PERIOD 7981859 +# define AIRTUNES_V2_STREAM_PERIOD 7981859 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) /* AirTunes v2 packet interval in ms */ # define AIRTUNES_V2_STREAM_PERIOD 8