@@ -297,7 +297,10 @@ - (void)displayDidRefresh:(SDDisplayLink *)displayLink {
297
297
NSTimeInterval currentDuration = [self .animatedProvider animatedImageDurationAtIndex: currentFrameIndex];
298
298
currentDuration = currentDuration / playbackRate;
299
299
if (self.currentTime < currentDuration) {
300
- // Current frame timestamp not reached, return
300
+ // Current frame timestamp not reached, prefetch frame in advance.
301
+ [self prefetchFrameAtIndex: currentFrameIndex
302
+ nextIndex: nextFrameIndex
303
+ bufferFull: bufferFull];
301
304
return ;
302
305
}
303
306
@@ -332,15 +335,25 @@ - (void)displayDidRefresh:(SDDisplayLink *)displayLink {
332
335
return ;
333
336
}
334
337
335
- // Check if we should prefetch next frame or current frame
336
- // When buffer miss, means the decode speed is slower than render speed, we fetch current miss frame
337
- // Or, most cases, the decode speed is faster than render speed, we fetch next frame
338
- NSUInteger fetchFrameIndex = self.bufferMiss ? currentFrameIndex : nextFrameIndex;
339
- UIImage *fetchFrame;
340
- SD_LOCK (_lock);
341
- fetchFrame = self.bufferMiss ? nil : self.frameBuffer [@(nextFrameIndex)];
342
- SD_UNLOCK (_lock);
343
-
338
+ [self prefetchFrameAtIndex: currentFrameIndex
339
+ nextIndex: nextFrameIndex
340
+ bufferFull: bufferFull];
341
+ }
342
+
343
+ // Check if we should prefetch next frame or current frame
344
+ // When buffer miss, means the decode speed is slower than render speed, we fetch current miss frame
345
+ // Or, most cases, the decode speed is faster than render speed, we fetch next frame
346
+ - (void )prefetchFrameAtIndex : (NSUInteger )currentIndex
347
+ nextIndex : (NSUInteger )nextIndex
348
+ bufferFull : (BOOL )bufferFull {
349
+ NSUInteger fetchFrameIndex = currentIndex;
350
+ UIImage *fetchFrame = nil ;
351
+ if (!self.bufferMiss ) {
352
+ fetchFrameIndex = nextIndex;
353
+ SD_LOCK (_lock);
354
+ fetchFrame = self.frameBuffer [@(nextIndex)];
355
+ SD_UNLOCK (_lock);
356
+ }
344
357
if (!fetchFrame && !bufferFull && self.fetchQueue .operationCount == 0 ) {
345
358
// Prefetch next frame in background queue
346
359
id <SDAnimatedImageProvider> animatedProvider = self.animatedProvider ;
0 commit comments