MixedReality-WebRTC icon indicating copy to clipboard operation
MixedReality-WebRTC copied to clipboard

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

Open esengun opened this issue 3 years ago • 6 comments

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.

esengun avatar Jun 02 '21 11:06 esengun

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

Aka-Amir avatar Jun 02 '21 13:06 Aka-Amir

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

esengun avatar Jun 02 '21 14:06 esengun

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

Aka-Amir avatar Jun 04 '21 06:06 Aka-Amir

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

Aka-Amir avatar Jun 04 '21 06:06 Aka-Amir

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?

esengun avatar Jun 04 '21 06:06 esengun

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

Aka-Amir avatar Jun 04 '21 08:06 Aka-Amir