From 5a30731854baa74ecb92520e4bb2d54d720cdfd0 Mon Sep 17 00:00:00 2001 From: Eric Coissac Date: Sun, 11 Jan 2026 08:04:24 +0100 Subject: [PATCH] Validate playback position against duration in control point This commit adds validation to ensure that the playback position does not exceed the track duration. When the position is greater than the duration (which can happen during track initialization on some UPNP renderers), the position is set to None to avoid displaying bogus timestamps. This improves the robustness of playback position handling. --- pmocontrol/src/control_point.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/pmocontrol/src/control_point.rs b/pmocontrol/src/control_point.rs index 768f7cc1..4b2d89e7 100644 --- a/pmocontrol/src/control_point.rs +++ b/pmocontrol/src/control_point.rs @@ -1519,10 +1519,22 @@ impl ControlPoint { #[cfg(feature = "pmoserver")] fn convert_runtime_position(position: Option<&PlaybackPositionInfo>) -> (Option, Option) { match position { - Some(info) => ( - parse_hms_to_ms(info.rel_time.as_deref()), - parse_hms_to_ms(info.track_duration.as_deref()), - ), + Some(info) => { + let position_ms = parse_hms_to_ms(info.rel_time.as_deref()); + let duration_ms = parse_hms_to_ms(info.track_duration.as_deref()); + + // Validate that position doesn't exceed duration + // If position > duration, the renderer is reporting invalid data + // (common during track initialization on some UPNP renderers) + match (position_ms, duration_ms) { + (Some(pos), Some(dur)) if pos > dur => { + // Position exceeds duration - invalid state during initialization + // Return None for position to avoid showing bogus timestamps + (None, duration_ms) + } + _ => (position_ms, duration_ms), + } + } None => (None, None), } }