Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI Freezes on rtcVideoTrack.add(VideoRendererAdapter(target: videoRenderer)), when entering from background #626

Open
patryk-sredzinski opened this issue Mar 11, 2025 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@patryk-sredzinski
Copy link
Contributor

patryk-sredzinski commented Mar 11, 2025

We were observing issues with videoViews stopping rendering when entered background for at least 15 seconds and returning. Camera was on and delivering to server, although the preview was not working.
All VideoViews stops rendering, both local and remote, although the stream is received/published

So we started observing AppState like that:

import LiveKit
import UIKit

extension CallController {
    func startObservingAppState() {
        let center = NotificationCenter.default
        center.addObserver(self, selector: #selector(didEnterBackgroundNotification), name: UIApplication.didEnterBackgroundNotification, object: nil)
        center.addObserver(self, selector: #selector(willEnterForegroundNotification), name: UIApplication.willEnterForegroundNotification, object: nil)
    }
    
    func stopObservingAppState() {
        let center = NotificationCenter.default
        center.removeObserver(self, name: UIApplication.didEnterBackgroundNotification, object: nil)
        center.removeObserver(self, name: UIApplication.willEnterForegroundNotification, object: nil)
    }
    
    @objc private func didEnterBackgroundNotification() {
        updateVideoViews(areEnabled: false)
    }
    
    @objc private func willEnterForegroundNotification() {
        updateVideoViews(areEnabled: true)
    }
    
    private func updateVideoViews(areEnabled: Bool) {
        var videoViews = [PersonVideoView]()
        videoViews.append(localPipManager.localParticipantView.videoView)
        videoViews.append(localPipManager.currentParticipantView.videoView)
        videoViews.append(contentsOf: collectionManager.participantViews.values.compactMap { $0.videoView })
        videoViews.forEach { $0.videoView.isEnabled = areEnabled }
    }
}

This sometimes ends up in UI Freeze which leads to a crash. When we pause the debugger it points to:

rtcVideoTrack.add(VideoRendererAdapter(target: videoRenderer))

Should we observe app state?

🔷 EDIT:
We are rendering in SampleBuffer mode, not Metal one
We picked up SampleBuffer, because the camera looks very pixelated on small views.
If we switch to Metal, background does not freeze, but the previews are having really bad quality

@patryk-sredzinski patryk-sredzinski added the bug Something isn't working label Mar 11, 2025
@pblazej
Copy link
Contributor

pblazej commented Mar 13, 2025

Hi @patryk-sredzinski! Unfortunately, I was unable to reproduce this one.

Should we observe app state?

Yes, technically it should be possible to pause rendering - looks like the main thread is being blocked for too long.

  • Can you provide a minimal reproducible example?
  • Can you check didBecomeActiveNotification as well (bad timing)?
  • Is delaying the update (via dispatch main) changing anything here?

@pblazej pblazej self-assigned this Mar 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants