Don't pace frame delivery if the display refresh rate has dropped

This commit is contained in:
Cameron Gutman
2022-02-12 19:14:06 -06:00
parent 6435afd229
commit 6fb6b9bf38
+13 -2
View File
@@ -99,7 +99,10 @@
- (void)start - (void)start
{ {
_displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(displayLinkCallback:)]; _displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(displayLinkCallback:)];
if (@available(iOS 10.0, tvOS 10.0, *)) { if (@available(iOS 15.0, tvOS 15.0, *)) {
_displayLink.preferredFrameRateRange = CAFrameRateRangeMake(self->frameRate, self->frameRate, self->frameRate);
}
else if (@available(iOS 10.0, tvOS 10.0, *)) {
_displayLink.preferredFramesPerSecond = self->frameRate; _displayLink.preferredFramesPerSecond = self->frameRate;
} }
[_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode]; [_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
@@ -117,7 +120,14 @@ int DrSubmitDecodeUnit(PDECODE_UNIT decodeUnit);
LiCompleteVideoFrame(handle, DrSubmitDecodeUnit(du)); LiCompleteVideoFrame(handle, DrSubmitDecodeUnit(du));
if (framePacing) { if (framePacing) {
// Always keep one pending frame smooth out gaps due to // Calculate the actual display refresh rate
double displayRefreshRate = 1 / (_displayLink.targetTimestamp - _displayLink.timestamp);
// Only pace frames if the display refresh rate is >= 90% of our stream frame rate.
// Battery saver, accessibility settings, or device thermals can cause the actual
// refresh rate of the display to drop below the physical maximum.
if (displayRefreshRate >= frameRate * 0.9f) {
// Keep one pending frame to smooth out gaps due to
// network jitter at the cost of 1 frame of latency // network jitter at the cost of 1 frame of latency
if (LiGetPendingVideoFrames() == 1) { if (LiGetPendingVideoFrames() == 1) {
break; break;
@@ -125,6 +135,7 @@ int DrSubmitDecodeUnit(PDECODE_UNIT decodeUnit);
} }
} }
} }
}
- (void)stop - (void)stop
{ {