RenderHeads / UnityPlugin-AVProLiveCamera

AVPro Live Camera is a Unity plugin for webcams, TV cards and capture cards

Home Page:https://renderheads.com/products/avpro-live-camera/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hotswap doesn't work

Oneiros90 opened this issue · comments

Describe the bug
The hotswap feature doesn't seem to work. If I understand it correctly, this feature should allow me to disconnect my USB webcam and reconnect it back without problems.
The problem is that the webcam shows itself as active even after disconnection, while the image is frozen and does not resume after reconnection.

Your Setup (please complete the following information):

  • Unity version: Unity 2021.2.19f1
  • AVPro Live Camera version: 2.9.1
  • Operating system version: Windows 10
  • Hardware/webcam model: Wansview 102JD
  • Video mode (resolution, frame-rate, etc): 1080p 30fps

To Reproduce
Steps to reproduce the behavior:

  1. Open the DefaultCameraDemo scene
  2. Check the "Update Hot Swap" option in the LiveCamera component
  3. Play the scene with an USB webcam on
  4. Disconnect the USB webcam while playing
  5. See the frozen image and the webcam in the inspector says "Displayed"
  6. Reconnect the USB webcam back
  7. See that the image is not resumed and the webcam shows as "Stopped"

Hi @Oneiros90,
Did you also tick the "Support Hot Swapping" option in the Manager component?

This was exactly my problem 3 days ago 😄
(https://forum.unity.com/threads/avpro-live-camera.137233/page-12#post-8119073)
I also check if the device is null and connected (AVProLiveCameraPlugin.IsDeviceConnected (avplCamera.Device.DeviceIndex))
Hot Swapping seems to work now when both Update Hot Swap and Support Hot Swap are enabled.

Hi @Oneiros90, Did you also tick the "Support Hot Swapping" option in the Manager component?

It worked :D thanks

Awesome! Thanks for the reply :)

Hi @Chris-RH, sorry if I write again here, but I'm facing a weird problem with some of my clients' pc.
After I enabled both Update Hot Swap and Support Hot Swap as you suggested, some of my clients reported an heavy and noticeable performance decrease. I compiled for them a build with just the DefaultCameraDemo scene with the hot swap flags disabled, then I compiled a second build with the same setup BUT with the flags enabled. They confirm that the second build is very laggy and they also recorded a video for me to see the lack of fluidity.
The weird thing is that it doesn't happen on several workstations I tried on, in my tests the performance are always good!
Any idea how to address this problem? They also sent me the Unity log but it's clean from errors...

Hi @Oneiros90,
I'm here to help, so please feel free to get in contact any time you need to :)

So a bit of info about Hotswap. If you have Hotswap enabled, it will scan/enumerate all video capture devices at each frame. This can be fast or slow depending on a few factors, such as the number of devices connected to the system, the number of devices registered with the system, or how fast/slow/light/heavy the device drivers are.

Your clients machine might have other capture devices installed, or possibly different driver versions installed. So they should uninstall any extra devices/drivers from their system, uninstall any extra codec packs, and also check the driver version of the device(s) they are using.

A second option for yourself would be to change the C# code to run Hotswap check every N frames instead of every frame. Though this may still not be acceptable depending on how large the delay is.

hotswap

You would need to change line 144 to: if (_supportHotSwapping && (Time.frameCount % 60) == 0)
That will make it check every 60 frames instead of every 1 frame.

Finally, you should make sure that Vsync is enabled in the client build, otherwise it might be trying to Hotswap check 1000 times a second, because the app will not be locked to monitor refresh rates and will instead run as fast as it can.

I hope that all helps and makes sense :)

Thank you for the suggestions @Chris-RH, I'm going with the second option :) I'll update this thread after the clients have given me feedbacks about this

Great, thank you :)

commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

I'm going to close this for now. Please reopen if you are still having problems with this.

Hi @Chris-RH, I actually just had an answer from my client so I can update this issue. Updating the devices only each 60 frames did help to make the application run smoothly but... you can actually see that each 60 frames there's a noticeable lag spike :( so not the ideal solution. Is there a way to update the devices in a secondary thread? Or maybe the only solution is to update them manually through an UI button?