From: Mike Brady Date: Tue, 2 Apr 2019 14:37:38 +0000 (+0100) Subject: allow calculation of nominal source frame rates even when the connection is error... X-Git-Tag: 3.3rc4~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1f45b8c00660f51bb88c8183dbced76816e909a5;p=thirdparty%2Fshairport-sync.git allow calculation of nominal source frame rates even when the connection is error prone. --- diff --git a/audio_alsa.c b/audio_alsa.c index ebeff907..d9904959 100644 --- a/audio_alsa.c +++ b/audio_alsa.c @@ -1191,7 +1191,7 @@ int delay_and_status(snd_pcm_state_t *state, snd_pcm_sframes_t *delay, enum yndk if (update_timestamp_ns == 0) { ret = snd_pcm_delay (alsa_handle,delay); - measurement_data_is_valid = 0; // can't really check frame rates + measurement_data_is_valid = 0; // frame rates are likely to be very unreliable if it can't set the update_timestamp, so don't publish them. } else { *delay = snd_pcm_status_get_delay(alsa_snd_pcm_status); diff --git a/player.c b/player.c index 9d3b007b..546b474e 100644 --- a/player.c +++ b/player.c @@ -209,7 +209,6 @@ static inline seq_t seq_sum(seq_t a, seq_t b) { void reset_input_flow_metrics(rtsp_conn_info *conn) { conn->play_number_after_flush = 0; conn->packet_count_since_flush = 0; - conn->packet_stream_established = 0; conn->input_frame_rate_starting_point_is_valid = 0; conn->initial_reference_time = 0; conn->initial_reference_timestamp = 0; @@ -892,8 +891,7 @@ static abuf_t *buffer_get_frame(rtsp_conn_info *conn) { curframe->given_timestamp; // we will keep buffering until we are // supposed to start playing this have_sent_prefiller_silence = 0; - conn->packet_stream_established = 1; - + // debug(1, "First packet timestamp is %" PRId64 ".", conn->first_packet_timestamp); // say we have started playing here diff --git a/player.h b/player.h index daff6236..cb197e4a 100644 --- a/player.h +++ b/player.h @@ -202,9 +202,6 @@ typedef struct { uint32_t reference_timestamp; uint64_t remote_reference_timestamp_time; - int packet_stream_established; // true if a stream of packets is flowing, made true by a first - // packet, false by a flush - // used as the initials values for calculating the rate at which the source thinks it's sending // frames uint32_t initial_reference_timestamp; diff --git a/rtp.c b/rtp.c index 35a74ecd..94de81c2 100644 --- a/rtp.c +++ b/rtp.c @@ -381,28 +381,26 @@ void *rtp_control_receiver(void *arg) { debug_mutex_lock(&conn->reference_time_mutex, 1000, 0); - if (conn->packet_stream_established) { - if (conn->initial_reference_time == 0) { - conn->initial_reference_time = remote_time_of_sync; - conn->initial_reference_timestamp = sync_rtp_timestamp; + if (conn->initial_reference_time == 0) { + conn->initial_reference_time = remote_time_of_sync; + conn->initial_reference_timestamp = sync_rtp_timestamp; + } else { + uint64_t remote_frame_time_interval = + conn->remote_reference_timestamp_time - + conn->initial_reference_time; // here, this should never be zero + if (remote_frame_time_interval) { + conn->remote_frame_rate = + (1.0 * (conn->reference_timestamp - conn->initial_reference_timestamp)) / + remote_frame_time_interval; // an IEEE double calculation with a 32-bit + // numerator and 64-bit denominator + // integers + conn->remote_frame_rate = conn->remote_frame_rate * + (uint64_t)0x100000000; // this should just change the + // [binary] exponent in the IEEE + // FP representation; the + // mantissa should be unaffected. } else { - uint64_t remote_frame_time_interval = - conn->remote_reference_timestamp_time - - conn->initial_reference_time; // here, this should never be zero - if (remote_frame_time_interval) { - conn->remote_frame_rate = - (1.0 * (conn->reference_timestamp - conn->initial_reference_timestamp)) / - remote_frame_time_interval; // an IEEE double calculation with a 32-bit - // numerator and 64-bit denominator - // integers - conn->remote_frame_rate = conn->remote_frame_rate * - (uint64_t)0x100000000; // this should just change the - // [binary] exponent in the IEEE - // FP representation; the - // mantissa should be unaffected. - } else { - conn->remote_frame_rate = 0.0; // use as a flag. - } + conn->remote_frame_rate = 0.0; // use as a flag. } } @@ -1088,8 +1086,7 @@ int sanitised_source_rate_information(uint32_t *frames, uint64_t *time, rtsp_con *frames = fs; uint64_t one_fp = (uint64_t)(0x100000000); // one second in fp form *time = one_fp; - if ((conn->packet_stream_established) && (conn->initial_reference_time) && - (conn->initial_reference_timestamp)) { + if ((conn->initial_reference_time) && (conn->initial_reference_timestamp)) { // uint32_t local_frames = conn->reference_timestamp - conn->initial_reference_timestamp; uint32_t local_frames = modulo_32_offset(conn->initial_reference_timestamp, conn->reference_timestamp);