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.
This commit is contained in:
2026-01-11 08:04:24 +01:00
parent 36a05a2575
commit 5a30731854

View File

@@ -1519,10 +1519,22 @@ impl ControlPoint {
#[cfg(feature = "pmoserver")] #[cfg(feature = "pmoserver")]
fn convert_runtime_position(position: Option<&PlaybackPositionInfo>) -> (Option<u64>, Option<u64>) { fn convert_runtime_position(position: Option<&PlaybackPositionInfo>) -> (Option<u64>, Option<u64>) {
match position { match position {
Some(info) => ( Some(info) => {
parse_hms_to_ms(info.rel_time.as_deref()), let position_ms = parse_hms_to_ms(info.rel_time.as_deref());
parse_hms_to_ms(info.track_duration.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), None => (None, None),
} }
} }