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
903 stars 278 forks source link

Crash related to 'EnumVideoCaptureDevicesAsync' #455

Open Korangar opened 4 years ago

Korangar commented 4 years ago

Hi, so I've been running into some crashes on some of my devices. I am working with v1.03

All devices are Win10 x64, but strangely on devices with integrated Cameras (Laptop, Windows Tablet) I get crashes as soon as I run any Scene with a peer Connection.

On my Desktop PC i had no issues so far, but I can reproduce similar errors if I e.g.

  1. Start a built executable.
  2. Open the project in Unity.
  3. Press Play. -> Editor crashes.

-- or --

  1. Play in Editor.
  2. Stay in Playmode or end it.
  3. Start a built executable. -> .exe crashes.

It seems like the Webcam is "reserved" for whoever has requested it first. The thing with Builds is that I can not get a crash report because the Bugreporter freezes as well. For the Editor the logs usually look like this:

0x00007FFDF2C048FC (Microsoft.MixedReality.WebRTC.N) Microsoft::MixedReality::WebRTC::operator!=
0x00007FFDF2AFD4C4 (Microsoft.MixedReality.WebRTC.N) mrsEnumVideoCaptureDevicesAsync
0x000002902C54A5E6 (Microsoft.MixedReality.WebRTC) Microsoft.MixedReality.WebRTC.Interop.PeerConnectionInterop.EnumVideoCaptureDevicesAsync()
0x000002902C54A323 (Microsoft.MixedReality.WebRTC) <>c__DisplayClass92_0.<GetVideoCaptureDevicesAsync>b__0()
0x000002902C547FCD (mscorlib) System.Threading.Tasks.Task`1.InnerInvoke()
0x000002902C54736A (mscorlib) System.Threading.Tasks.Task.Execute()
0x000002902C5471AB (mscorlib) System.Threading.Tasks.Task.ExecutionContextCallback()
0x000002902C5452F9 (mscorlib) System.Threading.ExecutionContext.RunInternal()
0x000002902C544B8B (mscorlib) System.Threading.ExecutionContext.Run()
0x000002902C54374B (mscorlib) System.Threading.Tasks.Task.ExecuteWithThreadLocal()
0x000002902C54231B (mscorlib) System.Threading.Tasks.Task.ExecuteEntry()
0x000002902C541B73 (mscorlib) System.Threading.Tasks.Task.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()

Currently the last thing I see in the Editor Console is the Log of my WebCam being found. For some crashes this was not the case, but usually the StackTraces revolve around "EnumVideoCaptureDevicesAsync".

I tried reboots, enabling/disabling Cam, connecting an external Cam, closing anything that might be accessing the camera.

I hope you can point me in a direction, to find some kind of fix for this. Might be I am missing something ...

Thanks.

djee-ms commented 4 years ago

It sounds like you are trying to use the same camera from 2 different apps at the same time, correct? If so then yes this is not supported, the camera is opened in exclusive mode to be able to select various options on it, including its capture resolution and framerate, and therefore cannot be shared across processes. In v1.0.3 you also cannot share it with another peer connection from the same process, although this becomes available with the new API on master (and soon in the upcoming 2.0 release).

Just for information also there is a bug in the Google code where the camera is identified by display name (e.g. "Camera XXX from brand YYY") instead of by unique bus identifier, and in that case you cannot use 2 cameras of the same model as they return the same name (although have different unique ID) and so the camera selection code will always pick the same one by mistake, resulting in the same error as if you had only 1 camera : cannot share a camera open in exclusive mode.

Korangar commented 4 years ago

Thanks for your answer.

Ah sorry my goal is currently not to have the camera work with different apps at the same time. This was just the results from troubleshooting the Crashes that keep happening on 2 of my Test Devices. (Laptop and Tablet)

I am currently setting up a project for a client, to create a proof of concept I am using the stuff from v1.03 VideoPlayer Sample.

I saw some features we need on the master branch, but building the project did not work for me. Seems like last week something broke (I am not sure if it was my setup or one of the newer commits?) and I had to go back to a stable Version to use the NuGet packages.)

My scene currently does have two Peer Connections "Sharing" one Camera, but I do not have any issues running it on my Desktop Computer. On my laptop and Tablet though the scene keeps crashing.

Let me try and go back to the vanilla example to see if the crashes keep happening.

The strange thing is it works perfectly fine on Desktop.

djee-ms commented 4 years ago

I saw some features we need on the master branch, but building the project did not work for me. Seems like last week something broke

If this is the logging thing, this was reverted an hour ago and CI is now green.

The strange thing is it works perfectly fine on Desktop.

The camera might have some capability to be shared in exclusive mode, not sure. Are you using only Desktop, or also UWP?

Korangar commented 4 years ago

Ah! The logging thing, yes ... My client was like: "Why is it not working it worked yesterday." ... I spent like two days reinstalling, recloning, re-everything until I saw Azure being red.

For now yes, but the goal is to have connections between a HoloLens2 (which will be ARM32 afaik?) and two Windows PCs (x64). But the required Hardware has not been shipped yet so I am trying to get accustomed to WebRTC and figure out how the connections have to be laid out.

I tried out the Vanilla Samples from v1.03 and it works again. So it must have been an issue with the Multiple Peer Connections fighting for the Camera.

Well, this is very limiting so I will try to compile the master branch again, wish me luck.