Fail over when FFmpeg audio clock queries fail - #149
Blackspirits wants to merge 1 commit into
Conversation
Blackspirits
left a comment
There was a problem hiding this comment.
Final adversarial review on 3a408d581df214ca76f7227d8b45c919b8691faa after CI SubtitleEdit#293: no blocker found. Verified WinMM/Core Audio expose current clock-read validity while retaining the best-known position, SilentAudioSink remains always-valid, only the current/latest anchored serial can promote a clock-read failure to device failover, a pending newer seek wins instead, write-failure and clock-failure paths share the same wall-clock transition, and a later successful seek/reset can attempt native recovery. No merge/promotion performed.
21a37e7 to
ee6ca3a
Compare
Blackspirits
left a comment
There was a problem hiding this comment.
Final adversarial review on ee6ca3a2a1aebdd4f2be7871cc3b61bb1cdcab39 after CI SubtitleEdit#307: no blocker found. Verified invalid reset baselines fail safe at zero played delta until a later reset, one transient native clock-query failure is tolerated, two consecutive failures mark the clock unhealthy, successful reads recover the transient-failure count, only the current/latest anchored serial can trigger failover, and wall-clock rebasing preserves continuity without trusting an absolute native counter as a post-seek delta. No merge/promotion performed.
Purpose
Dependent FFmpeg audio-runtime follow-up to #148 ("Validate WinMM hardening on integrated FFmpeg audio core").
#147/#148 compose the audited audio pipeline and Windows sink hardening. One residual failure mode remained: WinMM and Core Audio returned the last known playback position when their native clock-query APIs failed, so the player could not distinguish a legitimate temporarily unchanged clock from an invalid clock source.
That can leave the player permanently anchored to a frozen audio master clock even while PCM writes continue to succeed.
Current upstream
SubtitleEdit/subtitleeditmain was rechecked atdda1fce8f9d4a605b1b6732acc072c7109dc6323; the newer upstream changes are Auto-Translate related and do not touch the FFmpeg player or audio sinks.Finding fixed
WinMM
waveOutGetPosition()errors or unsupported returned MMTIME formats previously collapsed to_lastRawPositionwith no validity signal.Core Audio
AudioQueueGetCurrentTime()errors or non-finite sample times previously collapsed to_lastSampleTimewith no validity signal.In both cases
FfmpegPlayer.Clock()could trust a frozen value indefinitely.Clock-health contract
IAudioSinknow exposes:bool TryGetPlayedSeconds(out double playedSeconds)The output contains the safest usable position for continuity; the boolean says whether that sink clock is healthy enough to remain the player's master clock.
SilentAudioSinkis always valid.0played seconds + unhealthy until a later reset establishes a fresh baseline.The baseline rule prevents an accumulated absolute WinMM/Core Audio counter from being misinterpreted as time played since the new seek.
Player failover
When the active/current/latest serial has an anchored audio clock and
TryGetPlayedSecondsreports unhealthy:If a newer seek is already pending, the old serial's clock failure does not take ownership from that transaction.
The write-failure path also uses
TryGetPlayedSeconds, so write failure and clock-health failure converge on one failover transition.Regression coverage
Native-free tests pin:
Scope / branch state
fd98fcc6bce4c01845ddff9b1ad5d35757478c99ee6ca3a2a1aebdd4f2be7871cc3b61bb1cdcab393a408d581df214ca76f7227d8b45c919b8691faa/ CI Improve batch convert SubtitleEdit/subtitleedit#293dda1fce8f9d4a605b1b6732acc072c7109dc6323Acceptance
AI assistance: ChatGPT was used for native-clock failure modelling, post-reset baseline analysis, transient-error policy design, seek/failover ordering review, WinMM/Core Audio reconciliation and focused regression design.
Final CI
Authoritative run: SubtitleEdit#307 on
ee6ca3a2a1aebdd4f2be7871cc3b61bb1cdcab39Final adversarial review was performed on this exact HEAD after CI; no blocker found.