From: Mike Brady Date: Tue, 9 Jan 2018 20:54:03 +0000 (+0000) Subject: Move a play session's latency into the play session's data structure, duh. X-Git-Tag: 3.2d22~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3e5dbe9e1aa8bd12ba001911ce5e5eae50dc7a7b;p=thirdparty%2Fshairport-sync.git Move a play session's latency into the play session's data structure, duh. --- diff --git a/common.h b/common.h index aa4633b8..5c16358b 100644 --- a/common.h +++ b/common.h @@ -121,7 +121,6 @@ typedef struct { char *mdns_name; mdns_backend *mdns; int buffer_start_fill; - int64_t latency; int64_t userSuppliedLatency; // overrides all other latencies -- use with caution int64_t fixedLatencyOffset; // add this to all automatic latencies supplied to get the actual total latency // the total latency will be limited to the min and max-latency values, if supplied diff --git a/player.c b/player.c index 736fcd07..f37be4b9 100644 --- a/player.c +++ b/player.c @@ -862,7 +862,7 @@ static abuf_t *buffer_get_frame(rtsp_conn_info *conn) { // debug(1, "Output sample ratio is %d", conn->output_sample_ratio); int64_t delta = (conn->first_packet_timestamp - reference_timestamp) + - config.latency * conn->output_sample_ratio + + conn->latency * conn->output_sample_ratio + (int64_t)(config.audio_backend_latency_offset * config.output_rate); if (delta >= 0) { @@ -888,7 +888,7 @@ static abuf_t *buffer_get_frame(rtsp_conn_info *conn) { if (conn->first_packet_time_to_play != 0) { // recalculate conn->first_packet_time_to_play -- the latency might change int64_t delta = (conn->first_packet_timestamp - reference_timestamp) + - config.latency * conn->output_sample_ratio + + conn->latency * conn->output_sample_ratio + (int64_t)(config.audio_backend_latency_offset * config.output_rate); if (delta >= 0) { @@ -1088,7 +1088,7 @@ static abuf_t *buffer_get_frame(rtsp_conn_info *conn) { int64_t packet_timestamp = curframe->timestamp; // types okay int64_t delta = packet_timestamp - reference_timestamp; int64_t offset = - config.latency * conn->output_sample_ratio + + conn->latency * conn->output_sample_ratio + (int64_t)(config.audio_backend_latency_offset * config.output_rate) - config.audio_backend_buffer_desired_length * config.output_rate; // all arguments are int32_t, so expression promotion okay @@ -1463,7 +1463,7 @@ static void *player_thread_func(void *arg) { // check that there are enough buffers to accommodate the desired latency and the latency offset int maximum_latency = - config.latency + (int)(config.audio_backend_latency_offset * config.output_rate); + conn->latency + (int)(config.audio_backend_latency_offset * config.output_rate); if ((maximum_latency + (352 - 1)) / 352 + 10 > BUFFER_FRAMES) die("Not enough buffers available for a total latency of %d frames. A maximum of %d 352-frame " "packets may be accommodated.", @@ -1841,7 +1841,7 @@ static void *player_thread_func(void *arg) { // if negative, the packet will be early -- the delay is less than expected. sync_error = - delay - (config.latency * conn->output_sample_ratio + + delay - (conn->latency * conn->output_sample_ratio + (int64_t)(config.audio_backend_latency_offset * config.output_rate)); // int64_t from int64_t - int32_t, so okay diff --git a/player.h b/player.h index 2b0a47c7..6310dec7 100644 --- a/player.h +++ b/player.h @@ -63,6 +63,7 @@ typedef struct { typedef struct { int connection_number; // for debug ID purposes, nothing else... + int64_t latency; // the actual latency used for this play session int64_t minimum_latency; // set if an a=min-latency: line appears in the ANNOUNCE message; zero otherwise int64_t maximum_latency; // set if an a=max-latency: line appears in the ANNOUNCE message; zero otherwise diff --git a/rtp.c b/rtp.c index c24940ca..7fc1a035 100644 --- a/rtp.c +++ b/rtp.c @@ -1,7 +1,7 @@ /* * Apple RTP protocol handler. This file is part of Shairport. * Copyright (c) James Laird 2013 - * Copyright (c) Mike Brady 2014 -- 2017 + * Copyright (c) Mike Brady 2014 -- 2018 * All rights reserved. * * Permission is hereby granted, free of charge, to any person @@ -225,12 +225,12 @@ void *rtp_control_receiver(void *arg) { rtp_timestamp_less_latency = monotonic_timestamp(ntohl(*((uint32_t *)&packet[4])), conn); sync_rtp_timestamp = monotonic_timestamp(ntohl(*((uint32_t *)&packet[16])), conn); - + if (config.userSuppliedLatency) { - if (config.userSuppliedLatency != config.latency) { + if (config.userSuppliedLatency != conn->latency) { debug(1,"Using the user-supplied latency: %lld.",config.userSuppliedLatency); } - config.latency = config.userSuppliedLatency; + conn->latency = config.userSuppliedLatency; } else { int64_t la = sync_rtp_timestamp - rtp_timestamp_less_latency + config.fixedLatencyOffset; @@ -239,8 +239,8 @@ void *rtp_control_receiver(void *arg) { if ((conn->minimum_latency) && (conn->minimum_latency>la)) la = conn->minimum_latency; - if (la != config.latency) { - config.latency = la; + if (la != conn->latency) { + conn->latency = la; debug(1,"New latency: %lld, sync latency: %lld, minimum latency: %lld, maximum latency: %lld, fixed offset: %lld.", la,sync_rtp_timestamp - rtp_timestamp_less_latency,conn->minimum_latency,conn->maximum_latency,config.fixedLatencyOffset); } @@ -255,6 +255,7 @@ void *rtp_control_receiver(void *arg) { // it's as if the first sync after a flush or resume is the timing of the next packet // after the one whose RTP is given. Weird. } + pthread_mutex_lock(&conn->reference_time_mutex); conn->remote_reference_timestamp_time = remote_time_of_sync; conn->reference_timestamp_time = diff --git a/shairport.c b/shairport.c index e14830eb..ee459fdd 100644 --- a/shairport.c +++ b/shairport.c @@ -1108,10 +1108,8 @@ int main(int argc, char **argv) { strcat(configuration_file_path, ".conf"); config.configfile = configuration_file_path; - config.statistics_requested = 0; // don't print stats in the log - config.latency = -1; // -1 means not set. 88200 works well. This is also reset in rtsp.c when play - // is about to start - config.userSuppliedLatency = 0; // zero means none supplied + //config.statistics_requested = 0; // don't print stats in the log + //config.userSuppliedLatency = 0; // zero means none supplied config.resyncthreshold = 0.05; // 50 ms config.timeout = 120; // this number of seconds to wait for [more] audio before switching to idle. config.tolerance =