@@ -75,6 +75,12 @@ public sealed class DecouplingFramedClock : ISourceChangeableClock, IAdjustableC
7575
7676 private IAdjustableClock adjustableSourceClock ;
7777
78+ /// <summary>
79+ /// Denotes a state where a negative seek stopped the source clock and entered decoupled mode, meaning that
80+ /// after crossing into positive time again we should attempt to start and use the source clock.
81+ /// </summary>
82+ private bool pendingSourceRestartAfterNegativeSeek ;
83+
7884 public DecouplingFramedClock ( IClock ? source = null )
7985 {
8086 ChangeSource ( source ) ;
@@ -118,12 +124,12 @@ public void ProcessFrame()
118124
119125 currentTime += elapsedReferenceTime ;
120126
121- // When crossing the zero time boundary forwards, we should start and use the source clock.
122- // Note that this implicitly assumes the source starts at zero,
123- // and additionally the right-side boundary is not handled as we don't know where the source's max time is.
124- // This could be potentially handled if need be, if we had a notion of what the source's max allowable time is.
125- if ( lastTime < 0 && currentTime >= 0 )
127+ // When crossing into positive time, we should attempt to start and use the source clock.
128+ // Note that this carries the common assumption that the source clock *should* be able to run from zero.
129+ if ( pendingSourceRestartAfterNegativeSeek && currentTime >= 0 )
126130 {
131+ pendingSourceRestartAfterNegativeSeek = false ;
132+
127133 // We still need to check the seek was successful, else we might have already exceeded valid length of the source.
128134 lastSeekFailed = ! adjustableSourceClock . Seek ( currentTime ) ;
129135 if ( ! lastSeekFailed )
@@ -166,6 +172,7 @@ public void ChangeSource(IClock? source)
166172 public void Reset ( )
167173 {
168174 adjustableSourceClock . Reset ( ) ;
175+ pendingSourceRestartAfterNegativeSeek = false ;
169176 shouldBeRunning = false ;
170177 lastSeekFailed = false ;
171178 currentTime = 0 ;
@@ -212,6 +219,7 @@ public bool Seek(double position)
212219
213220 // Ensure the underlying clock is stopped as we enter decoupled mode.
214221 adjustableSourceClock . Stop ( ) ;
222+ pendingSourceRestartAfterNegativeSeek = position < 0 ;
215223 }
216224
217225 currentTime = position ;
0 commit comments