microsoft / MixedReality-WebRTC

MixedReality-WebRTC is a collection of components to help mixed reality app developers integrate audio and video real-time communication into their application and improve their collaborative experience
https://microsoft.github.io/MixedReality-WebRTC/
MIT License
898 stars 278 forks source link

Camera2Session: Error: Camera device could not be opened because there are too many other open camera devices. #767

Open esengun opened 3 years ago

esengun commented 3 years ago

I am trying to send video feed of the android tablet camera (galaxy tab s6) in which arfoundation is running. In another scene where there is no rtc operation, camera feed is displayed perfectly on the ui. However, when rtc is enabled and communication starts with the peer, then the camera image is complete black on both peers' devices.

I tried to debug the problem using android studio and noticed the below error:

"29959-31814/? E/org.webrtc.Logging: Camera2Session: Error: Camera device could not be opened because there are too many other open camera devices."

As far as I understand, the library is having difficulty sharing camera with arcore, but this is just an assumption.

Is there any way to solve this problem? Thanks in advance.

Aka-Amir commented 3 years ago

Have You Ever try to get permission first ? I had this problem for sound and i got permission then it fixed ☻

esengun commented 3 years ago

I acquire all permissions at the start. And as mentioned before, camera feed is actually rendered when rtc is not enabled.

Aka-Amir commented 3 years ago

You should force it with java classes. i dont know exactly for camera but i set this for microphone issue.

Aka-Amir commented 3 years ago

By the way , do you know anything about multiple connections ? for example three or ten person in a room

esengun commented 3 years ago

I haven't worked in multiple connections use case. But there is an asset other than this called webrtc video chat in assetstore. I guess it supports multi user but has no uwp support.

How did you force getting permissions with java classes inside unity?

Aka-Amir commented 3 years ago
private static void RouteToSpeaker(bool speaker)
    {
#if UNITY_ANDROID
        try
        {
            AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            AndroidJavaObject activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
            AndroidJavaObject audioManager = activity.Call<AndroidJavaObject>("getSystemService", "audio");
            // bool isSpeakers = audioManager.Call<Boolean>("isSpeakerphoneOn");
            audioManager.Call("setSpeakerphoneOn", speaker);
            bool res = audioManager.Call<Boolean>("isSpeakerphoneOn");

            Debug.Log("Speakers are now set to: " + res);
        }
        catch (Exception ex)
        {
            Debug.Log(ex.ToString());
        }
#endif
    } 

Like This