[vlc-commits] [Git][videolan/vlc][master] vout/vsbd: flush if needed and on becoming active

Felix Paul Kühne (@fkuehne) gitlab at videolan.org
Tue Aug 4 16:28:11 UTC 2026



Felix Paul Kühne pushed to branch master at VideoLAN / VLC


Commits:
6c097ec6 by Felix Paul Kühne at 2026-08-04T17:07:43+02:00
vout/vsbd: flush if needed and on becoming active

This adds a listener to check whether the OS determines that a flush is
needed to continue decoding.

Also, on non-macOS, a flush is executed every time the app becomes
active again. Previously, video rendering broke on these OS if an audio
session was allowed in the background and decoding continued.

Finally, we stopp rendering if the display layer is in a "failed" state.

Fixes VLC-iOS#2317 and VLCKit#743

- - - - -


1 changed file:

- modules/video_output/apple/VLCSampleBufferDisplay.m


Changes:

=====================================
modules/video_output/apple/VLCSampleBufferDisplay.m
=====================================
@@ -755,15 +755,63 @@ shouldInheritContentsScale:(CGFloat)newScale
         @synchronized(sys.displayLayer) {
             sys.displayLayer = displayView.displayLayer;
         }
+        [sys observeDisplayLayerFailures];
         [sys preparePictureInPicture];
     });
 }
 
+- (void)observeDisplayLayerFailures {
+    NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
+
+#if !TARGET_OS_OSX
+    [notificationCenter addObserver:self
+                           selector:@selector(applicationDidBecomeActive:)
+                               name:UIApplicationDidBecomeActiveNotification
+                             object:nil];
+#endif
+
+    if (@available(iOS 14.0, tvOS 14.0, macOS 11.0, *)) {
+        [notificationCenter addObserver:self
+                               selector:@selector(displayLayerRequiresFlushDidChange:)
+                                   name:AVSampleBufferDisplayLayerRequiresFlushToResumeDecodingDidChangeNotification
+                                 object:self.displayLayer];
+    }
+}
+
+- (void)applicationDidBecomeActive:(NSNotification *)notification {
+    [self flushToResumeDecoding];
+}
+
+- (void)displayLayerRequiresFlushDidChange:(NSNotification *)notification {
+    [self flushToResumeDecoding];
+}
+
+- (void)flushToResumeDecoding {
+    AVSampleBufferDisplayLayer * const displayLayer = self.displayLayer;
+    @synchronized(displayLayer) {
+        if (displayLayer.status != AVQueuedSampleBufferRenderingStatusFailed)
+            return;
+
+        /* only a failure caused by revoked decoder resources is recoverable */
+        if (@available(iOS 14.0, tvOS 14.0, macOS 11.0, *)) {
+            if (!displayLayer.requiresFlushToResumeDecoding) {
+                msg_Err(_vd, "display layer failed permanently: %s",
+                        displayLayer.error.localizedDescription.UTF8String);
+                return;
+            }
+        }
+
+        [displayLayer flush];
+    }
+}
+
 - (void)placeVideo:(vout_display_place_t)newPlace {
     self.displayView.frame = [self frameForPlace:&newPlace];
 }
 
 - (void)close {
+    [[NSNotificationCenter defaultCenter] removeObserver:self];
+
     VLCSampleBufferDisplay *sys = self;
     dispatch_async(dispatch_get_main_queue(), ^{
         [sys.displayView removeFromSuperview];
@@ -829,6 +877,8 @@ static void RenderPicture(vout_display_t *vd, picture_t *pic, vlc_tick_t date) {
     @synchronized(sys.displayLayer) {
         if (sys.displayLayer == nil)
             return;
+        if (sys.displayLayer.status == AVQueuedSampleBufferRenderingStatusFailed)
+            return;
     }
 
     picture_Hold(pic);



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/6c097ec6605a9a19919e620641ad0412cea228e3

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/6c097ec6605a9a19919e620641ad0412cea228e3
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help




More information about the vlc-commits mailing list