#endif
#ifdef COMPILE_FOR_FREEBSD
-#include <netinet/in.h>
-#include <net/if_types.h>
#include <net/if_dl.h>
+#include <net/if_types.h>
+#include <netinet/in.h>
#endif
#ifdef COMPILE_FOR_OSX
return time_now_fp;
}
+uint64_t get_monotonic_time_in_ns() {
+ uint64_t time_now_ns;
+
+#ifdef COMPILE_FOR_LINUX_AND_FREEBSD_AND_CYGWIN_AND_OPENBSD
+ struct timespec tn;
+ // can't use CLOCK_MONOTONIC_RAW as it's not implemented in OpenWrt
+ // CLOCK_REALTIME because PTP uses it.
+ clock_gettime(CLOCK_MONOTONIC, &tn);
+ 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);
+ }
+
+ // 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;
+}
+
uint64_t get_absolute_time_in_ns() {
uint64_t time_now_ns;
uint64_t elapsedNano;
static mach_timebase_info_data_t sTimebaseInfo = {0, 0};
+ // this actually give you a monotonic clock
time_now_mach = mach_absolute_time();
// If this is the first time we've run, get the timebase.
t = id;
int found = 0;
for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
- #ifdef AF_PACKET
+#ifdef AF_PACKET
if ((ifa->ifa_addr) && (ifa->ifa_addr->sa_family == AF_PACKET)) {
struct sockaddr_ll *s = (struct sockaddr_ll *)ifa->ifa_addr;
if ((strcmp(ifa->ifa_name, "lo") != 0) && (found == 0)) {
found = 1;
}
}
- #else
- #ifdef AF_LINK
- struct sockaddr_dl * sdl = (struct sockaddr_dl *) ifa->ifa_addr;
- if ((sdl) && (sdl->sdl_family == AF_LINK)) {
+#else
+#ifdef AF_LINK
+ struct sockaddr_dl *sdl = (struct sockaddr_dl *)ifa->ifa_addr;
+ if ((sdl) && (sdl->sdl_family == AF_LINK)) {
if (sdl->sdl_type == IFT_ETHER) {
char *s = LLADDR(sdl);
for (i = 0; i < sdl->sdl_alen; i++) {
- debug(1,"char %d: \"%c\".", i, *s);
- *t++ = (uint8_t)*s++;
- }
+ debug(1, "char %d: \"%c\".", i, *s);
+ *t++ = (uint8_t)*s++;
+ }
found = 1;
}
}
- #endif
- #endif
-
+#endif
+#endif
}
freeifaddrs(ifaddr);
}
return response;
}
-
// return a time in nanoseconds
// uint64_t get_absolute_time_in_fp(void); // obselete
uint64_t get_absolute_time_in_ns(void);
+uint64_t get_monotonic_time_in_ns(void); // to try and get precise FPS values
// time at startup for debugging timing
extern uint64_t ns_time_at_startup, ns_time_at_last_debug_message;
void *player_thread_func(void *arg) {
rtsp_conn_info *conn = (rtsp_conn_info *)arg;
-
+
uint64_t previous_frames_played;
uint64_t previous_frames_played_time;
int previous_frames_played_valid = 0;
-
// pthread_cleanup_push(player_thread_initial_cleanup_handler, arg);
conn->packet_count = 0;
conn->packet_count_since_flush = 0;
uint64_t frames_sent_for_play;
int status = -1;
if ((config.output->delay) && (config.no_sync == 0) && (config.output->rate_info)) {
+ uint64_t monotonic_time_now = get_monotonic_time_in_ns();
uint64_t elapsed_play_time; // dummy
status = config.output->rate_info(&elapsed_play_time, &frames_sent_for_play);
uint64_t frames_played = frames_sent_for_play - play_samples - current_delay;
// last time the rate_info call was made. Thus, the frame rate should be valid.
if ((status == 0) && (previous_frames_played_valid)) {
uint64_t frames_played_in_this_interval = frames_played - previous_frames_played;
- uint64_t interval = local_time_now - previous_frames_played_time;
+ uint64_t interval = monotonic_time_now - previous_frames_played_time;
conn->frame_rate = (1e9 * frames_played_in_this_interval) / interval;
conn->frame_rate_valid = 1;
}
-
+
// uncomment the if statement if your want to get as long a period for
// calculating the frame rate
// if ((status != 0) || (previous_frames_played_valid == 0)) {
- // if we have just detected an outputting error, or if we have no
- // starting information
- previous_frames_played = frames_played;
- previous_frames_played_time = local_time_now;
- previous_frames_played_valid = 1;
- // }
+ // if we have just detected an outputting error, or if we have no
+ // starting information
+ previous_frames_played = frames_played;
+ previous_frames_played_time = monotonic_time_now;
+ previous_frames_played_valid = 1;
+ //}
}
-
+
// we can now calculate running averages for sync error (frames), corrections (ppm),
// insertions plus deletions (ppm), drift (ppm)
double moving_average_sync_error = (1.0 * tsum_of_sync_errors) / number_of_statistics;
else
sw_min_db = (sw_max_db - desired_sw_range);
} else {
- hw_min_db = hw_max_db - desired_range_db;
+ hw_min_db = hw_max_db - desired_range_db;
}
}
} else {
remote_control_stream
} airplay_stream_c; // "c" for category
-
#ifdef CONFIG_AIRPLAY_2
typedef enum { ts_ntp, ts_ptp } timing_t;
typedef enum { ap_1, ap_2 } airplay_t;
clock_status_t clock_status;
airplay_stream_c
- airplay_stream_category; // is it a remote control stream or a normal "full service" stream? (will be unspecified if not build for AirPlay 2)
+ airplay_stream_category; // is it a remote control stream or a normal "full service" stream?
+ // (will be unspecified if not build for AirPlay 2)
#ifdef CONFIG_AIRPLAY_2
char *airplay_gid; // UUID in the Bonjour advertisement -- if NULL, the group UUID is the same as