From bb226a41844dafd052dfb41894f37019da1f9e52 Mon Sep 17 00:00:00 2001 From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Thu, 13 May 2021 20:10:38 +0100 Subject: [PATCH 1/6] fix flush of a large sync error, hopefully. --- player.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/player.c b/player.c index c8eca4de..1a4d855e 100644 --- a/player.c +++ b/player.c @@ -2305,15 +2305,8 @@ void *player_thread_func(void *arg) { debug(1, "Large positive sync error of: %" PRId64 " frames (%f seconds).", sync_error, (sync_error * 1.0) / config.output_rate); int64_t local_frames_to_drop = sync_error / conn->output_sample_ratio; - uint32_t frames_to_drop_sized = local_frames_to_drop; - - debug_mutex_lock(&conn->flush_mutex, 1000, 1); - conn->flush_rtp_timestamp = - inframe->given_timestamp + - frames_to_drop_sized; // flush all packets up to (and including?) this - reset_input_flow_metrics(conn); - debug_mutex_unlock(&conn->flush_mutex, 3); - + uint32_t frames_to_drop_sized = local_frames_to_drop; + do_flush(inframe->given_timestamp + frames_to_drop_sized, conn); } else if ((sync_error < 0) && ((-sync_error) > filler_length)) { debug(1, "Large negative sync error of: %" PRId64 From 2180c7147f0170001d3c35a98d793bd078004525 Mon Sep 17 00:00:00 2001 From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Thu, 13 May 2021 20:12:12 +0100 Subject: [PATCH 2/6] If a PTP clock isn't available, use existing timing data if it's still valid. --- rtp.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/rtp.c b/rtp.c index 2dd5f185..ab85cc09 100644 --- a/rtp.c +++ b/rtp.c @@ -1274,7 +1274,7 @@ int get_ptp_anchor_local_time_info(rtsp_conn_info *conn, uint32_t *anchorRTP, if ((clock_status_t)response != conn->clock_status) { switch (response) { case clock_ok: - debug(1, "Connection %d: NQPTP clock is valid and available.", conn->connection_number); + debug(1, "Connection %d: NQPTP clock % " PRIx64 " on line.", conn->connection_number, actual_clock_id); break; case clock_service_unavailable: debug(1, "Connection %d: NQPTP clock is not available.", conn->connection_number); @@ -1311,6 +1311,14 @@ int get_ptp_anchor_local_time_info(rtsp_conn_info *conn, uint32_t *anchorRTP, } conn->clock_status = response; } + + if ((response != clock_ok) && (conn->last_anchor_info_is_valid != 0)) { + if (anchorRTP != NULL) + *anchorRTP = conn->anchor_rtptime; + if (anchorLocalTime != NULL) + *anchorLocalTime = conn->anchor_time - conn->last_anchor_clock_offset; + response = clock_ok; + } return response; } From c7bdc2c40961e1257e051636b5f4797f1b4586bd Mon Sep 17 00:00:00 2001 From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Thu, 13 May 2021 20:58:03 +0100 Subject: [PATCH 3/6] Tidy up a message. --- rtp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rtp.c b/rtp.c index ab85cc09..22424632 100644 --- a/rtp.c +++ b/rtp.c @@ -1274,7 +1274,7 @@ int get_ptp_anchor_local_time_info(rtsp_conn_info *conn, uint32_t *anchorRTP, if ((clock_status_t)response != conn->clock_status) { switch (response) { case clock_ok: - debug(1, "Connection %d: NQPTP clock % " PRIx64 " on line.", conn->connection_number, actual_clock_id); + debug(1, "Connection %d: NQPTP new master clock % " PRIx64 ".", conn->connection_number, actual_clock_id); break; case clock_service_unavailable: debug(1, "Connection %d: NQPTP clock is not available.", conn->connection_number); From e41795f4dad1dd4a01f4eee4ed3fbd1ead0087d2 Mon Sep 17 00:00:00 2001 From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Thu, 13 May 2021 20:59:38 +0100 Subject: [PATCH 4/6] clang --- player.c | 2 +- rtp.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/player.c b/player.c index 1a4d855e..5996c5c4 100644 --- a/player.c +++ b/player.c @@ -2305,7 +2305,7 @@ void *player_thread_func(void *arg) { debug(1, "Large positive sync error of: %" PRId64 " frames (%f seconds).", sync_error, (sync_error * 1.0) / config.output_rate); int64_t local_frames_to_drop = sync_error / conn->output_sample_ratio; - uint32_t frames_to_drop_sized = local_frames_to_drop; + uint32_t frames_to_drop_sized = local_frames_to_drop; do_flush(inframe->given_timestamp + frames_to_drop_sized, conn); } else if ((sync_error < 0) && ((-sync_error) > filler_length)) { debug(1, diff --git a/rtp.c b/rtp.c index 22424632..a78a1156 100644 --- a/rtp.c +++ b/rtp.c @@ -1274,7 +1274,8 @@ int get_ptp_anchor_local_time_info(rtsp_conn_info *conn, uint32_t *anchorRTP, if ((clock_status_t)response != conn->clock_status) { switch (response) { case clock_ok: - debug(1, "Connection %d: NQPTP new master clock % " PRIx64 ".", conn->connection_number, actual_clock_id); + debug(1, "Connection %d: NQPTP new master clock % " PRIx64 ".", conn->connection_number, + actual_clock_id); break; case clock_service_unavailable: debug(1, "Connection %d: NQPTP clock is not available.", conn->connection_number); @@ -1311,7 +1312,7 @@ int get_ptp_anchor_local_time_info(rtsp_conn_info *conn, uint32_t *anchorRTP, } conn->clock_status = response; } - + if ((response != clock_ok) && (conn->last_anchor_info_is_valid != 0)) { if (anchorRTP != NULL) *anchorRTP = conn->anchor_rtptime; From 7592e237d83924086eb9e781ff8958e3b0bd69b2 Mon Sep 17 00:00:00 2001 From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Thu, 13 May 2021 21:07:56 +0100 Subject: [PATCH 5/6] quieten a debug message --- player.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/player.c b/player.c index 5996c5c4..7c308b9a 100644 --- a/player.c +++ b/player.c @@ -1186,7 +1186,7 @@ static abuf_t *buffer_get_frame(rtsp_conn_info *conn) { } } } else { - debug(1, "Unexpected response to getting dac delay: %d.", resp); + debug(3, "Unexpected response to getting dac delay: %d.", resp); } } } From c8e45b3206fade3edc2cf63a326572666ad69bf6 Mon Sep 17 00:00:00 2001 From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Thu, 13 May 2021 21:16:58 +0100 Subject: [PATCH 6/6] Bump for changes to missing clock and flushing. --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 3336dcfc..ca4cc228 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ([2.50]) -AC_INIT([shairport-sync], [4.0d3], [4265913+mikebrady@users.noreply.github.com]) +AC_INIT([shairport-sync], [4.0d4], [4265913+mikebrady@users.noreply.github.com]) AM_INIT_AUTOMAKE AC_CONFIG_SRCDIR([shairport.c]) AC_CONFIG_HEADERS([config.h])