From 6d1469839191a24c0d734e8a29e879f7b20bf2ff Mon Sep 17 00:00:00 2001 From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Tue, 21 Dec 2021 15:02:43 +0000 Subject: [PATCH 1/6] Send an empty timing list when a player is acquired. --- rtsp.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/rtsp.c b/rtsp.c index 6b46310a..cd76c537 100644 --- a/rtsp.c +++ b/rtsp.c @@ -2538,7 +2538,7 @@ void handle_teardown_2(rtsp_conn_info *conn, __attribute__((unused)) rtsp_messag resp->respcode = 451; // don't know what to do here } // debug(1,"Bogus exit for valgrind -- remember to comment it out!."); - // exit(EXIT_SUCCESS); // + // exit(EXIT_SUCCESS); // } #endif @@ -2679,6 +2679,7 @@ void handle_setup_2(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp) // if it's a full service PTP stream, we get groupUUID, groupContainsGroupLeader and // timingPeerList if (conn->airplay_stream_category == ptp_stream) { + ptp_send_control_message_string("T"); // remove all previous history debug_log_rtsp_message(2, "SETUP \"PTP\" message", req); plist_t groupUUID = plist_dict_get_item(messagePlist, "groupUUID"); if (groupUUID) { @@ -2836,8 +2837,8 @@ void handle_setup_2(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp) debug(2, "Connection %d: SETUP mdns_update on %s.", conn->connection_number, get_category_string(conn->airplay_stream_category)); mdns_update(NULL, secondary_txt_records); - - + + resp->respcode = 200; } else { From 2e6eb23a04c0bef5bbc318ef5ce5cc0a57b22512 Mon Sep 17 00:00:00 2001 From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Tue, 21 Dec 2021 15:03:28 +0000 Subject: [PATCH 2/6] Wait for 300 secodns before complaining about the age of a sync. --- rtp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rtp.c b/rtp.c index 4bd07a60..17ee7d8b 100644 --- a/rtp.c +++ b/rtp.c @@ -1280,7 +1280,7 @@ int get_ptp_anchor_local_time_info(rtsp_conn_info *conn, uint32_t *anchorRTP, if (response == clock_ok) { uint64_t time_now = get_absolute_time_in_ns(); int64_t time_since_sample = time_now - actual_time_of_sample; - if (time_since_sample > 10000000000) { + if (time_since_sample > 300000000000) { if (long_time_notifcation_done == 0) { debug(1, "The last PTP timing sample is pretty old: %f seconds.", 0.000000001 * time_since_sample); From f0134387b9b11ad947b6c196300c84074100647d Mon Sep 17 00:00:00 2001 From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Tue, 21 Dec 2021 15:04:15 +0000 Subject: [PATCH 3/6] Flush if the first packet is less than 100 ms in the future. --- player.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/player.c b/player.c index 1feee08f..7750c504 100644 --- a/player.c +++ b/player.c @@ -1062,17 +1062,20 @@ static abuf_t *buffer_get_frame(rtsp_conn_info *conn) { conn->first_packet_time_to_play = should_be_time; int64_t lt = conn->first_packet_time_to_play - local_time_now; - - if (lt < 100000000) - debug(1, "Connection %d: Short lead time for first frame %" PRId64 ": %f seconds.", - conn->connection_number, conn->first_packet_timestamp, lt * 0.000000001); + if (lt < 100000000) { + debug(1, "Connection %d: Short lead time for first frame %" PRId64 ": %f seconds. Flushing 0.5 seconds", + conn->connection_number, conn->first_packet_timestamp, lt * 0.000000001); + do_flush(conn->first_packet_timestamp + 5 * 4410, conn); + } +/* int64_t lateness = local_time_now - conn->first_packet_time_to_play; if (lateness > 0) { debug(1, "First packet is %" PRId64 " nanoseconds late! Flushing 0.5 seconds", lateness); - do_flush(conn->first_packet_timestamp + 5 * 4410, conn); + } +*/ } if (conn->first_packet_time_to_play != 0) { From fc736cd12f907bffb93ca1a313c8d97ec703648c Mon Sep 17 00:00:00 2001 From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Tue, 21 Dec 2021 15:18:14 +0000 Subject: [PATCH 4/6] Look for 0.15 seconds of a lead time... --- player.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/player.c b/player.c index 7750c504..37757f8b 100644 --- a/player.c +++ b/player.c @@ -1063,7 +1063,7 @@ static abuf_t *buffer_get_frame(rtsp_conn_info *conn) { int64_t lt = conn->first_packet_time_to_play - local_time_now; - if (lt < 100000000) { + if (lt < 150000000) { debug(1, "Connection %d: Short lead time for first frame %" PRId64 ": %f seconds. Flushing 0.5 seconds", conn->connection_number, conn->first_packet_timestamp, lt * 0.000000001); do_flush(conn->first_packet_timestamp + 5 * 4410, conn); From 8656149d68d3a4321fdc558f2041258667587904 Mon Sep 17 00:00:00 2001 From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Tue, 21 Dec 2021 15:32:16 +0000 Subject: [PATCH 5/6] Adjust the time needed to allow the clock to settle and the lead time. --- player.c | 3 +++ rtp.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/player.c b/player.c index 37757f8b..2e9819c9 100644 --- a/player.c +++ b/player.c @@ -1067,6 +1067,9 @@ static abuf_t *buffer_get_frame(rtsp_conn_info *conn) { debug(1, "Connection %d: Short lead time for first frame %" PRId64 ": %f seconds. Flushing 0.5 seconds", conn->connection_number, conn->first_packet_timestamp, lt * 0.000000001); do_flush(conn->first_packet_timestamp + 5 * 4410, conn); + } else { + debug(1, "Connection %d: Lead time for first frame %" PRId64 ": %f seconds.", + conn->connection_number, conn->first_packet_timestamp, lt * 0.000000001); } /* int64_t lateness = local_time_now - conn->first_packet_time_to_play; diff --git a/rtp.c b/rtp.c index 17ee7d8b..348ac869 100644 --- a/rtp.c +++ b/rtp.c @@ -1305,7 +1305,7 @@ int get_ptp_anchor_local_time_info(rtsp_conn_info *conn, uint32_t *anchorRTP, // if the master clock and the anchor clock are the same // wait at least this time before using the new master clock // note that mastershipo may be backdated - if (duration_of_mastership < 2000000000) { + if (duration_of_mastership < 1500000000) { debug(3, "master not old enough yet: %f ms", 0.000001 * duration_of_mastership); response = clock_not_ready; } else if ((duration_of_mastership > 5000000000) || From ce7bbd3999912c557f8bc513cee0f27e42043eee Mon Sep 17 00:00:00 2001 From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Tue, 21 Dec 2021 16:28:38 +0000 Subject: [PATCH 6/6] Update RELEASENOTES-DEVELOPMENT.md --- RELEASENOTES-DEVELOPMENT.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/RELEASENOTES-DEVELOPMENT.md b/RELEASENOTES-DEVELOPMENT.md index e845aa33..c91f6307 100644 --- a/RELEASENOTES-DEVELOPMENT.md +++ b/RELEASENOTES-DEVELOPMENT.md @@ -1,3 +1,7 @@ +Version-4.1-dev-115-g8656149d +==== +* Simplify and improve timing when a play session from a new device is started. + Version-4.1-dev-106-ge98111fb ==== #### Enhancement