AgoraIO / Video-Call-for-Mobile-Gaming

33 stars 14 forks source link

Using a RenderTexture instread of camera #20

Closed nsmith1024 closed 4 years ago

nsmith1024 commented 4 years ago

Hello,

Im currently using your video chat in my game, but i now need to send parts of the screen as video rather than video taken from the camera.

So is it possible for your video system to capture and send portions of the screen (like from a RenderTexture) instead of the video camera, and let others see a live video of that instead of the video camera?

This should be pretty easy for you to do, instead of encoding the image from the camera, just continuously grab bitmaps from the RenderTexture, encode and send that as the video instead of the phone or PC camera.

Thanks

icywind commented 4 years ago

Yes, you got the idea. After grabbing the raw data from the RenderTexture (in byte[] format), you can use a function like this one to share the video to the audience side.

https://gist.github.com/icywind/92053d0983e713515c64d5c532ebee21

Also make sure when you set up the Agora RTC engine, enable external video source using this call: mRtcEngine.SetExternalVideoSource(true, false);

nsmith1024 commented 4 years ago

Thanks for the info, so if i have one person transmitting (sharing their screen to audience) then this person wants to stop sharing and let another person from audience share, after that, then another person from the audience can share their screen etc. Anybody can take over sharing their screen (while all others watch), But only 1 person share at a time.

Do you know how to do that?

icywind commented 4 years ago

It will come down to some business logic from your design. Generally speaking, you can have a UI that toggles a "Share" button. When the first person finishes sharing, you signal the end to other people so they are able to share. One way to send the signal to all user is by using this function: https://docs.agora.io/en/Video/API%20Reference/unity/classagora__gaming__rtc_1_1_i_rtc_engine.html#a0cdf49d0e0eea938c07bfe0cb2e4aaf9

nsmith1024 commented 4 years ago

But how do you implement the switch (Agora code) to switch transmission/reception is what i was getting at....

zhangtao1104 commented 4 years ago

Do you want to change the person who can share their screen in agora channel or outside of agora channel ?

nsmith1024 commented 4 years ago

Lets say i set up a channel called "xyz", with 3 people on there (A,B,C). Person A is sending their screen, B, and C receiving. Then B wants to send and A,C receive.

So A stops sending, and B takes over sending on the same channel. Next C sends and A,B receive. How to do that with the Agora API to change whose sending and whos receiving? How to control who sending and whos receiving etc?

zhangtao1104 commented 4 years ago

You can realize your requirement according to this document: https://docs.agora.io/en/Video/custom_video_unity?platform=Unity

And you can read the api named muteLocalAudioStream and muteLocalVideoStream. This api can help you to control who can share their screen to others.

zhangtao1104 commented 4 years ago

But choose who can share their screen depends on your self, your server know it, you can notify others by your server or signal, im ,etc.

zhangtao1104 commented 4 years ago

We have an api named createDataStream and sendStreamMessage . This api can help you to send stream message to others If you in channel.Maybe you can notify others by this api, Because I do not know the detail of your requirement, so I do not know If it can help you ,you can have a look and have a try.