File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed
Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -88,16 +88,22 @@ private TimeSpan RemainingCycleTime
8888 {
8989 get
9090 {
91+ const double MaxFrameDuration = 50d ;
92+ const double MinFrameDuration = 10d ;
93+
9194 try
9295 {
9396 var frameDuration = Container . Components . MainMediaType == MediaType . Video && MediaCore . Blocks [ MediaType . Video ] . Count > 0
9497 ? MediaCore . Blocks [ MediaType . Video ] . AverageBlockDuration
9598 : Constants . DefaultTimingPeriod ;
9699
97- // protect against too slow of a video framerate
100+ // protect against too slow or too fast of a video framerate
98101 // which might impact audio rendering.
99- if ( frameDuration . TotalMilliseconds > 50d )
100- frameDuration = TimeSpan . FromMilliseconds ( 50 ) ;
102+ frameDuration = frameDuration . TotalMilliseconds > MaxFrameDuration
103+ ? TimeSpan . FromMilliseconds ( MaxFrameDuration )
104+ : frameDuration . TotalMilliseconds < MinFrameDuration
105+ ? TimeSpan . FromMilliseconds ( MinFrameDuration )
106+ : frameDuration ;
101107
102108 return TimeSpan . FromTicks ( frameDuration . Ticks - CurrentCycleElapsed . Ticks ) ;
103109 }
@@ -202,7 +208,9 @@ private void RunQuantumThread(object state)
202208 else
203209 {
204210 // Perform a synthetic wait
205- QuantumWaiter . Wait ( Constants . DefaultTimingPeriod ) ;
211+ var waitTime = RemainingCycleTime ;
212+ if ( waitTime . Ticks > 0 )
213+ QuantumWaiter . Wait ( waitTime ) ;
206214 }
207215
208216 if ( ! TryBeginCycle ( ) )
You can’t perform that action at this time.
0 commit comments