From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Mon, 23 May 2022 19:34:37 +0000 (+0100) Subject: Fix a stupid bug in the selection of timebases. X-Git-Tag: 4.1-rc1~24^2~178 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cdb4d384d3386f5672b773990d25d507ef809fe1;p=thirdparty%2Fshairport-sync.git Fix a stupid bug in the selection of timebases. --- diff --git a/common.c b/common.c index 5112d7cd..a21dc9c4 100644 --- a/common.c +++ b/common.c @@ -1211,61 +1211,7 @@ uint64_t get_monotonic_time_in_ns() { #ifdef COMPILE_FOR_LINUX_AND_FREEBSD_AND_CYGWIN_AND_OPENBSD struct timespec tn; -#ifdef CLOCK_MONOTONIC_RAW - clock_gettime(CLOCK_MONOTONIC_RAW, &tn); -#else - clock_gettime(CLOCK_MONOTONIC, &tn); -#endif - uint64_t tnnsec = tn.tv_sec; - tnnsec = tnnsec * 1000000000; - uint64_t tnjnsec = tn.tv_nsec; - time_now_ns = tnnsec + tnjnsec; -#endif - -#ifdef COMPILE_FOR_OSX - uint64_t time_now_mach; - uint64_t elapsedNano; - static mach_timebase_info_data_t sTimebaseInfo = {0, 0}; - - // this actually give you a monotonic clock - // see https://news.ycombinator.com/item?id=6303755 - time_now_mach = mach_absolute_time(); - - // If this is the first time we've run, get the timebase. - // We can use denom == 0 to indicate that sTimebaseInfo is - // uninitialised because it makes no sense to have a zero - // denominator in a fraction. - - if (sTimebaseInfo.denom == 0) { - debug(1, "Mac initialise timebase info."); - (void)mach_timebase_info(&sTimebaseInfo); - } - - if (sTimebaseInfo.denom == 0) - die("could not initialise Mac timebase info in get_monotonic_time_in_ns().") - - // Do the maths. We hope that the multiplication doesn't - // overflow; the price you pay for working in fixed point. - - // this gives us nanoseconds - time_now_ns = time_now_mach * sTimebaseInfo.numer / sTimebaseInfo.denom; -#endif - - return time_now_ns; -} - -// all these clock things are now in macOS now since 10.13 (September 2017). Must update... -uint64_t get_monotonic_raw_time_in_ns() { - // CLOCK_MONOTONIC_RAW/CLOCK_MONOTONIC in Linux/FreeBSD etc, monotonic in MacOSX - uint64_t time_now_ns; - -#ifdef COMPILE_FOR_LINUX_AND_FREEBSD_AND_CYGWIN_AND_OPENBSD - struct timespec tn; -#ifdef CLOCK_MONOTONIC_RAW - clock_gettime(CLOCK_MONOTONIC_RAW, &tn); -#else clock_gettime(CLOCK_MONOTONIC, &tn); -#endif uint64_t tnnsec = tn.tv_sec; tnnsec = tnnsec * 1000000000; uint64_t tnjnsec = tn.tv_nsec; @@ -1308,13 +1254,8 @@ uint64_t get_monotonic_raw_time_in_ns() { // Not defined for macOS uint64_t get_realtime_in_ns() { uint64_t time_now_ns; - struct timespec tn; -#ifdef CLOCK_MONOTONIC_RAW - clock_gettime(CLOCK_MONOTONIC_RAW, &tn); -#else - clock_gettime(CLOCK_MONOTONIC, &tn); -#endif + clock_gettime(CLOCK_REALTIME, &tn); uint64_t tnnsec = tn.tv_sec; tnnsec = tnnsec * 1000000000; uint64_t tnjnsec = tn.tv_nsec; diff --git a/player.c b/player.c index 9031e229..0eb6b2df 100644 --- a/player.c +++ b/player.c @@ -1321,7 +1321,7 @@ static abuf_t *buffer_get_frame(rtsp_conn_info *conn) { struct timespec time_of_wakeup; time_of_wakeup.tv_sec = sec; time_of_wakeup.tv_nsec = nsec; - // pthread_cond_timedwait(&conn->flowcontrol, &conn->ab_mutex, &time_of_wakeup); + int rc = pthread_cond_timedwait(&conn->flowcontrol, &conn->ab_mutex, &time_of_wakeup); // this is a pthread cancellation point if ((rc != 0) && (rc != ETIMEDOUT))