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

Picture in Picture support for VideoView and SwiftUI VideoView #458

Open
VatamanuBogdan opened this issue Aug 9, 2024 · 0 comments
Open
Assignees
Labels
enhancement New feature or request

Comments

@VatamanuBogdan
Copy link

Is your feature request related to a problem? Please describe.

I read about how to add Picture in Picture in a video call application and there are two steps that you have to follow to add PiP support:

  1. You have to create an AVPictureInPictureController that has an AVSampleBufferDisplayLayer attached to it where the buffer contains the video content that will be shown on the PiP window.
  2. Make sure that the AVSampleBufferDisplayLayer from the previous step is added as a subview to the view hierarchy otherwise the PiP will not work

I've tried to add PiP support to my LiveKit application, the implementation makes use of avSampleBufferDisplayLayer VideoView property by using sampleBuffer rendering mode. It worked but it has some flaws. The problem is caused by the internal renderer invalidation that happens here, the renderer will be recreated and thus the avSampleBufferDisplayLayer will be changed, this way the AVPictureInPictureController won't point to the right buffer and PiP won't work.

Describe the solution you'd like

I think that the best way to enable Picture in Picture support in LiveKit would be to add to the VideoView an extra SampleBufferVideoRenderer that will have the purpose of exposing to the users its internal AVSampleBufferDisplayLayer (a new property on VideoView that is named pictureInPictureDisplayLayer). Another aspect of this implementation is that the pictureInPictureDisplayLayer must not be destroyed whenever the track state changes instead it should be flushed.

The new overhead added to VideoView should be on user demand. I suggest adding a new boolean property pictureInPictureEnabled on VideoView that will handle the creation of pictureInPictureDisplayLayer.

Describe alternatives you've considered

Other alternative solutions, would be:

  1. Stop invalidating the renderer whenever the track state changes and flush the old content of SampleBufferVideoRenderer
  2. Add a new PictureInPictureRenderer renderer class that exposes the implementation of SampleBufferVideoRenderer as public, this way the library users will be able to attach it to a VideoTrack and add Picture in Picture support by themselves without the usage of VideoView.

Additional context

I would like to help with this new feature if you agree and create a PR with one of the solutions that were proposed above.

@VatamanuBogdan VatamanuBogdan added the enhancement New feature or request label Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants