fix: attempt to fix background and resume issues with pip and new renderer changes

This commit is contained in:
Acaki committed 2025-07-13 00:52:08 +08:00
1 parent 29c8382825
commit 80c6d488cf
3 files changed
+58 -5

No files matched your search

+1
View File
@@ -30,6 +30,7 @@
- (void)safeCopyMetricsTo:(PlotMetrics *)dst from:(PlotMetrics *)src; - (void)safeCopyMetricsTo:(PlotMetrics *)dst from:(PlotMetrics *)src;
- (void)getAllStats:(video_stats_t *)stats; - (void)getAllStats:(video_stats_t *)stats;
- (void)optimizeRefreshRate; - (void)optimizeRefreshRate;
- (void)resetFramePacing;
- (int)submitDecodeBuffer:(unsigned char *)data - (int)submitDecodeBuffer:(unsigned char *)data
length:(int)length length:(int)length
+24
View File
@@ -98,6 +98,8 @@ extern int ff_isom_write_av1c(AVIOContext *pb, const uint8_t *buf, int size,
} }
if (_decompressionSession != nil){ if (_decompressionSession != nil){
VTDecompressionSessionWaitForAsynchronousFrames(_decompressionSession);
VTDecompressionSessionInvalidate(_decompressionSession); VTDecompressionSessionInvalidate(_decompressionSession);
CFRelease(_decompressionSession); CFRelease(_decompressionSession);
_decompressionSession = nil; _decompressionSession = nil;
@@ -1129,4 +1131,26 @@ int DrSubmitDecodeUnit(PDECODE_UNIT decodeUnit);
} }
} }
- (void)resetFramePacing {
// Ensure this only runs for the AVSampleBuffer rendering backend and that the display link exists.
if (_renderingBackend == RENDER_AVSB && _displayLink) {
Log(LOG_I, @"Frame pacing is being reset to %d FPS...", self->_frameRate);
// Toggling the paused state can help re-engage the display link with the
// run loop correctly after the app resumes from a background state like PiP.
_displayLink.paused = YES;
// Re-apply the desired frame rate range. This is the critical hint for ProMotion
// that may have been lost or ignored during the PiP transition.
if (@available(iOS 15.0, *)) {
_displayLink.preferredFrameRateRange = CAFrameRateRangeMake(self->_frameRate, self->_frameRate, self->_frameRate);
} else {
_displayLink.preferredFramesPerSecond = self->_frameRate;
}
// Resume the display link immediately.
_displayLink.paused = NO;
}
}
@end @end
@@ -95,6 +95,10 @@
- (void)pictureInPictureControllerWillStartPictureInPicture:(AVPictureInPictureController *)pictureInPictureController { - (void)pictureInPictureControllerWillStartPictureInPicture:(AVPictureInPictureController *)pictureInPictureController {
_streamView.hidden = YES; _streamView.hidden = YES;
if (self.imguiView) {
self.imguiView.mtkView.hidden = YES;
Log(LOG_I, @"Hiding ImGui view for PiP start.");
}
} }
- (void)pictureInPictureControllerDidStartPictureInPicture:(AVPictureInPictureController *)pictureInPictureController { - (void)pictureInPictureControllerDidStartPictureInPicture:(AVPictureInPictureController *)pictureInPictureController {
@@ -110,15 +114,23 @@
- (void)pictureInPictureControllerDidStopPictureInPicture:(AVPictureInPictureController *)pictureInPictureController { - (void)pictureInPictureControllerDidStopPictureInPicture:(AVPictureInPictureController *)pictureInPictureController {
_streamView.hidden = NO; _streamView.hidden = NO;
if (self.imguiView) {
self.imguiView.mtkView.hidden = NO;
Log(LOG_I, @"Showing ImGui view after PiP stop.");
}
if (!_isRestoringFromPiP) { if (!_isRestoringFromPiP) {
[self returnToMainFrame]; [self returnToMainFrame];
} }
_isRestoringFromPiP = NO;
} }
- (void)pictureInPictureController:(AVPictureInPictureController *)pictureInPictureController restoreUserInterfaceForPictureInPictureStopWithCompletionHandler:(void (^)(BOOL restored))completionHandler { - (void)pictureInPictureController:(AVPictureInPictureController *)pictureInPictureController restoreUserInterfaceForPictureInPictureStopWithCompletionHandler:(void (^)(BOOL restored))completionHandler {
_isRestoringFromPiP = YES; _isRestoringFromPiP = YES;
_streamView.hidden = NO; _streamView.hidden = NO;
if (self.imguiView) {
self.imguiView.mtkView.hidden = NO;
Log(LOG_I, @"Showing ImGui view for PiP restore.");
}
completionHandler(YES); completionHandler(YES);
} }
@@ -343,6 +355,13 @@
userInfo:nil userInfo:nil
repeats:_settings.statsOverlayEnabled]; repeats:_settings.statsOverlayEnabled];
if (self.metalViewController && self.metalViewController.view.superview) {
[self.view bringSubviewToFront:self.metalViewController.view];
}
if (self.imguiView && self.imguiView.mtkView.superview) {
[self.view bringSubviewToFront:self.imguiView.mtkView];
}
NSLog(@"frameview gestures: %d", (uint32_t)[self.view.gestureRecognizers count]); NSLog(@"frameview gestures: %d", (uint32_t)[self.view.gestureRecognizers count]);
NSLog(@"streamview gestures: %d", (uint32_t)[_streamView.gestureRecognizers count]); NSLog(@"streamview gestures: %d", (uint32_t)[_streamView.gestureRecognizers count]);
} }
@@ -909,19 +928,23 @@
} }
- (void)applicationDidBecomeActive:(NSNotification *)notification { - (void)applicationDidBecomeActive:(NSNotification *)notification {
// Stop the background timer, since we're foregrounded again // Stop the background timer
if (_inactivityTimer != nil) { if (_inactivityTimer != nil) {
Log(LOG_I, @"Stopping inactivity timer after becoming active again"); Log(LOG_I, @"Stopping inactivity timer after becoming active again");
[_inactivityTimer invalidate]; [_inactivityTimer invalidate];
_inactivityTimer = nil; _inactivityTimer = nil;
} }
// Check if we were in PiP
if (self.pipController && self.pipController.isPictureInPictureActive) { if (self.pipController && self.pipController.isPictureInPictureActive) {
[self.pipController stopPictureInPicture]; [self.pipController stopPictureInPicture];
} }
//self.pipController = nil; if (_isRestoringFromPiP) {
//[self setupPiPControllerWithRenderer:self->_streamMan.videoRenderer]; [self->_streamMan.videoRenderer resetFramePacing];
//self->_streamMan.videoRenderer. }
_isRestoringFromPiP = NO;
} }
// This fires when the home button is pressed // This fires when the home button is pressed
@@ -1365,6 +1388,11 @@
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator { - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
if (_isRestoringFromPiP) {
Log(LOG_I, @"View size changed during PiP restore, skipping redundant reconfiguration.");
return;
}
Log(LOG_I, @"View size changed, terminating stream"); Log(LOG_I, @"View size changed, terminating stream");
double delayInSeconds = 0.2; double delayInSeconds = 0.2;