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

How do I exclude my custom lock screen layer when sharing a screen? #561

Open
zoujiaqing opened this issue Dec 15, 2024 · 11 comments
Open
Assignees
Labels
enhancement New feature or request

Comments

@zoujiaqing
Copy link

I have a mobile workstation.
I want to see it run and operate remotely.
But my app has a lock screen that hides the phone's screen.
How do I filter out this mask when I look at it remotely?

livekit sdk has an API same this code?

val localVideoTrackOptions = LocalVideoTrackOptions.Builder()
    .excludeApps(listOf("com.example.customlock"))  // exclude this
    .build()
@zoujiaqing zoujiaqing added the enhancement New feature or request label Dec 15, 2024
@davidliu
Copy link
Contributor

I'm not sure what you want to do. Do you want to exclude an app from being shared from the screen share?

If it helps, you can write your response in Chinese, I can understand a bit.

@zoujiaqing
Copy link
Author

好的兄弟,我说一下我的思路。

我在做的是手机群控系统,但是手机托管在第三方的机房中,我需要这一个自定义的app来锁定这个屏幕,让第三方机房无法看到我手机的界面,但是我在屏幕共享的时候没有排除这个锁屏界面的显示,我之前的方案是要修改 framework层达到目的,但是毕竟手机系统不是我们的,所以 VisualDisplay 加上修改底层 framework 的方案不行。按理说通过 VisualDisplay 可以让虚拟显示器不显示这个自定义锁屏activity,然后推流这个虚拟显示器的内容即可达到需要的效果。但是 livekitsdk for android 将 visualdisplay 封装在内部了吧,不知道我要的这个方式如何能实现。

谢谢你。

@zoujiaqing
Copy link
Author

Do you know my mean? @davidliu

@davidliu
Copy link
Contributor

Hmm, I don't think that's something we can support? We go through MediaProjection, which just captures what's on screen and doesn't have any ability to exclude apps.

What you can do is if you have a solution, you can write your own custom VideoCapturer to deal with your own case.

Here's the original ScreenCapturer code you can copy and modify for your own purposes.

Once you have the video capturer, you can create a track out of it and publish it directly:

val track = room.localParticipant.createVideoTrack(videoCapturer = yourScreenCapturer)
track.startCapture()
room.localParticipant.publishVideoTrack(track)

Hope that helps.

@zoujiaqing
Copy link
Author

zoujiaqing commented Dec 17, 2024

Yes, I need create a custom VirtualDiaplay object transmitted to room.localParticipant.publishVideoTrack(track)?

@davidliu
Copy link
Contributor

Yes. You can reference the code I linked above to make your own implementation.

@zoujiaqing
Copy link
Author

I created a custom VideoCapturer. But what the remote video is seeing is not what my video is about. How to make this video replace the screen recorded video stream?

My code:

    private fun startScreenCapture(intentData: Intent) {
        val localParticipant = room.localParticipant

        GlobalScope.launch {
            val resolution = VideoResolution.H240
            val frameRate = 6
            val captureParams = getCaptureParams(context, resolution, frameRate)

            val excludedPackages = setOf("com.xxx.remote")

            val screenShareVideoCapturer = ScreenShareVideoCapturer(context, intentData, captureParams, excludedPackages)

            val track = localParticipant.createVideoTrack(
                capturer = screenShareVideoCapturer,
                name = "screenshare"
            )

            localParticipant.publishVideoTrack(
                track = track,
                options = VideoTrackPublishOptions(
                    simulcast = false,
                    videoEncoding = createCustomVideoEncoding(context, resolution, frameRate)
                )
            )

            screenShareVideoCapturer.startCapture(captureParams.width, captureParams.height, frameRate)
        }
    }

@davidliu
Copy link
Contributor

Your custom video capturer needs to pass the frames to the capturerObserver that's given in the initialize method.

@zoujiaqing
Copy link
Author

zoujiaqing commented Dec 25, 2024

Yes, it's can capture video, now!
thanks ;)

but, I want shared screen.

How to create ScreencastTrack?

Because the receiver is using the interface for watch screen sharing.

@zoujiaqing
Copy link
Author

My custom VideoCapturer can capture android screen video publish to livekit server.

but, the video have big black background. why?

I use room.localParticipant.setScreenShareEnabled(true, intentData) not black background.

@davidliu
Copy link
Contributor

davidliu commented Jan 8, 2025

Yes, it's can capture video, now! thanks ;)

but, I want shared screen.

How to create ScreencastTrack?

It doesn't need to be a LocalScreencastVideoTrack, that's for our internal handling of it for user convenience, but you can just publish it as a LocalVideoTrack.

Because the receiver is using the interface for watch screen sharing.

If you mean the receiver is getting the track through Track.Source.SCREEN_SHARE, you can choose which source you want to publish it as:

room.localParticipant.publishVideoTrack(
    track = yourTrack,
    options = VideoTrackPublishOptions(
        base = room.screenShareTrackPublishDefaults,
        source = Track.Source.SCREEN_SHARE
    )
)

but, the video have big black background. why?

You may be setting the wrong dimensions when capturing the screen share.

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