From: Mike Brady Date: Mon, 20 Aug 2018 18:53:16 +0000 (+0100) Subject: Fix a stupid divide-by-zero error and remove unrecognised warning options for FreeBSD X-Git-Tag: 3.3RC0~249^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d5197081ef0506b0ed16a4037d6fbfb79085c5f6;p=thirdparty%2Fshairport-sync.git Fix a stupid divide-by-zero error and remove unrecognised warning options for FreeBSD --- diff --git a/Makefile.am b/Makefile.am index 83fc2132..cc88b530 100644 --- a/Makefile.am +++ b/Makefile.am @@ -8,7 +8,7 @@ shairport_sync_SOURCES = shairport.c rtsp.c mdns.c mdns_external.c common.c rtp. AM_CFLAGS = -Wno-multichar -Wall -Wextra -Wno-clobbered -Wno-psabi -pthread -DSYSCONFDIR=\"$(sysconfdir)\" if BUILD_FOR_FREEBSD - AM_CXXFLAGS = -I/usr/local/include -Wno-multichar -Wall -Wextra -Wno-clobbered -Wno-psabi -pthread -DSYSCONFDIR=\"$(sysconfdir)\" -O2 + AM_CXXFLAGS = -I/usr/local/include -Wno-multichar -Wall -Wextra -pthread -DSYSCONFDIR=\"$(sysconfdir)\" -O2 else if BUILD_FOR_OPENBSD AM_CXXFLAGS = -I/usr/local/include -Wno-multichar -Wall -Wextra -Wno-clobbered -Wno-psabi -pthread -DSYSCONFDIR=\"$(sysconfdir)\" diff --git a/player.c b/player.c index 5853a4ac..47758a9a 100644 --- a/player.c +++ b/player.c @@ -2095,8 +2095,12 @@ void *player_thread_func(void *arg) { int64_t should_be_frame; local_time_to_frame(local_time_now, &should_be_frame, conn); + + int64_t absolute_difference_in_frames = td_in_frames + rt - should_be_frame; + if (absolute_difference_in_frames < 0) + absolute_difference_in_frames = -absolute_difference_in_frames; - if (abs(td_in_frames + rt - should_be_frame) > 10 * conn->output_sample_ratio) + if (absolute_difference_in_frames > 10 * conn->output_sample_ratio) debug(1, "Difference between old and new frame number is %" PRId64 " frames.", td_in_frames + rt - should_be_frame); // this is the actual delay, including the latency we actually want, which will diff --git a/rtp.c b/rtp.c index 9d3c6f76..5b5b3d3b 100644 --- a/rtp.c +++ b/rtp.c @@ -765,35 +765,34 @@ void *rtp_timing_receiver(void *arg) { x_bar += (conn->time_pings[cc].local_time >> 12); sample_count++; } - - y_bar = y_bar / sample_count; - x_bar = x_bar / sample_count; - - int64_t xid, yid; - int64_t mtl, mbl; - mtl = 0; - mbl = 0; - for (cc = 0; cc < conn->time_ping_count; cc++) - if ((conn->time_pings[cc].chosen) && - (conn->time_pings[cc].sequence_number > (settling_time / 3))) { - - uint64_t slt = conn->time_pings[cc].local_time >> 12; - if (slt > x_bar) - xid = slt - x_bar; - else - xid = -(x_bar - slt); - - uint64_t srt = conn->time_pings[cc].remote_time >> 12; - if (srt > y_bar) - yid = srt - y_bar; - else - yid = -(y_bar - srt); - - mtl = mtl + xid * yid; - mbl = mbl + xid * xid; - } - conn->local_to_remote_time_gradient_sample_count = sample_count; if (sample_count > sample_point_minimum) { + y_bar = y_bar / sample_count; + x_bar = x_bar / sample_count; + + int64_t xid, yid; + int64_t mtl, mbl; + mtl = 0; + mbl = 0; + for (cc = 0; cc < conn->time_ping_count; cc++) + if ((conn->time_pings[cc].chosen) && + (conn->time_pings[cc].sequence_number > (settling_time / 3))) { + + uint64_t slt = conn->time_pings[cc].local_time >> 12; + if (slt > x_bar) + xid = slt - x_bar; + else + xid = -(x_bar - slt); + + uint64_t srt = conn->time_pings[cc].remote_time >> 12; + if (srt > y_bar) + yid = srt - y_bar; + else + yid = -(y_bar - srt); + + mtl = mtl + xid * yid; + mbl = mbl + xid * xid; + } + conn->local_to_remote_time_gradient_sample_count = sample_count; conn->local_to_remote_time_gradient = (1.0 * mtl) / mbl; // debug(1,"Drift is %12.2f ppm, based on %d // samples.",(1.0-conn->local_to_remote_time_gradient)*1000000,sample_count);