From 3bd7298cfeda339c265d300e1344f418f3d7f0ed Mon Sep 17 00:00:00 2001 From: Tom Briden Date: Thu, 8 May 2025 11:08:54 +0100 Subject: [PATCH] MT#55283 codec: disable clock skew calculation during media playback when media playback happens, all packets get scheduled at the same time with a send time in the future. however, this results in the output_skew calculation triggering an unnecessary shift in the send timer, which can cause choppy playback Change-Id: I449f221a4d348eb615c2af1dca30bec163aa4fc6 --- daemon/codec.c | 8 +++++++- include/codec.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/daemon/codec.c b/daemon/codec.c index e81e7b289..7da9d8f0a 100644 --- a/daemon/codec.c +++ b/daemon/codec.c @@ -937,6 +937,10 @@ struct codec_handler *codec_handler_make_media_player(const rtp_payload_type *sr struct codec_handler *h = codec_handler_make_playback(src_pt, dst_pt, last_ts, media, ssrc, codec_set); if (!h) return NULL; + + ilogs(transcoding, LOG_DEBUG, "Disabling clock skew calculation for media playback handler"); + h->ssrc_handler->csch.is_media_playback = true; + if (audio_player_is_active(media)) { h->packet_decoded = packet_decoded_audio_player; if (!audio_player_pt_match(media, dst_pt)) @@ -2484,7 +2488,9 @@ void codec_output_rtp(struct media_packet *mp, struct codec_scheduler *csch, ts_diff_us = p->ttq_entry.when - rtpe_now; - csch->output_skew = csch->output_skew * 15 / 16 + ts_diff_us / 16; + if (!csch->is_media_playback) + csch->output_skew = csch->output_skew * 15 / 16 + ts_diff_us / 16; + if (csch->output_skew > 50000 && ts_diff_us > 10000) { // arbitrary value, 50 ms, 10 ms shift ilogs(transcoding, LOG_DEBUG, "Steady clock skew of %li.%01li ms detected, shifting send timer back by 10 ms", csch->output_skew / 1000, diff --git a/include/codec.h b/include/codec.h index 482ad049f..679e5aafd 100644 --- a/include/codec.h +++ b/include/codec.h @@ -106,6 +106,7 @@ struct codec_scheduler { int64_t first_send; unsigned long first_send_ts; long output_skew; + bool is_media_playback; // used to track media playback so we can skip skew calculation }; struct transcode_config {