Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

NatDevice - Media Device API

Discussion in 'Assets and Asset Store' started by Lanre, Dec 17, 2015.

?

Should we add exposure controls in v1.3? This means dropping support for iOS 7

Poll closed Jun 10, 2016.
  1. Yes

    9 vote(s)
    75.0%
  2. No

    3 vote(s)
    25.0%
  1. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    Permissions handling on Android is very finicky. The fix for this is to wait (using a coroutine) until the permissions have been granted before going ahead to start the camera preview.
    We are considering dropping back to API level 21.
     
  2. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    I don't have experience with this, but you are passing block width as the width and height. ZXing might not support cropping or scanning an ROI. Use the full frame (preview texture width and height).
     
  3. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    Can you share the crash logs from the iPad? I'll try to reproduce this.
     
  4. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    This has been fixed in the upcoming update. I'm aiming to release it next week.
     
  5. markalles21

    markalles21

    Joined:
    Apr 2, 2019
    Posts:
    5
    I also sent an email with these information.
    The crash happens when taking a picture with the rearcamera of the IPad.
    Also do you know why the camera on ios is rotated 90 degrees on landscape left (home button on the right) mode, but works on landscape right (home button on the left)?
    Code (CSharp):
    1. 2019-07-23 19:43:43.806075+0200 test[8669:2822701] Uncaught exception: NSInvalidArgumentException: *** -[AVCapturePhotoOutput capturePhotoWithSettings:delegate:] flashMode must be set to a value present in the supportedFlashModes array
    2. (
    3.     0   CoreFoundation                      0x0000000196400edc <redacted> + 252
    4.     1   libobjc.A.dylib                     0x00000001955d1a40 objc_exception_throw + 56
    5.     2   AVFoundation                        0x000000019c598b8c <redacted> + 820
    6.     3   test                    0x0000000104e983ec -[NCCaptureDevice capturePhoto:] + 460
    7.     4   test                    0x0000000104e95bcc NCCapturePhoto + 168
    8.     5   test                    0x000000010507fee8 UnityAction_Invoke_mC9FF5AA1F82FDE635B3B6644CE71C94C31C3E71A + 492
    9.     6   test                    0x0000000105086e70 UnityEvent_Invoke_mB2FA1C76256FE34D5E7F84ABE528AC61CE8A0325 + 396
     
    Last edited: Jul 29, 2019
    Lanre likes this.
  6. Stamp-Enzi

    Stamp-Enzi

    Joined:
    Aug 17, 2017
    Posts:
    17
    What is the intended solution for the Android permission problem? I'm facing the same thing on first start up and I'm not able to get it to work even with waiting for permissions. I'm using 2.0f4. Wanting to upgrade which leads me to:

    Lanre, please respond to my mail about the previous Natcam version. Api Level 21 is not an option for us.
     
  7. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    Got the email, working on a fix. As for rotation issues, I'll try to reproduce. It's probably because the iPad reports different orientation than the iPhone (landscape vs portrait).
     
  8. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    I believe there are free Unity plugins out there that do permissions handling for Android. We aren't adding this it in NatCam.
    21 or 23? We've dropped the requirement to 21 from 23 in the most recent build. We can't go below that (camera2 was introduced in 21), and I pretty much never share older builds because of regressions.
     
  9. Stamp-Enzi

    Stamp-Enzi

    Joined:
    Aug 17, 2017
    Posts:
    17
    Is this because of my old version or something that also happens in newer Natcam versions?
    edit: I fixed this with Unitys Permission.RequestUserPermission(Permission.Camera)

    Yes, sorry I mixed it up. 23 is the api level we can't use, that's why I need Natcam 2.1.3 which was the last version that used level 22, which would be the maximum for our users.
    Can you make an exception for me? I'd really appreciate it. I'm kind of running out of time for the next release and i want to add at least some improvements for the camera.
     
    Last edited: Jul 30, 2019
  10. tonidurans

    tonidurans

    Joined:
    Jan 30, 2015
    Posts:
    6
    Hi Lanre, is the version that requires API 21 instead of 23 available on Asset Store? I think I've got the latest from store, and still requires 23.

    Regards
     
  11. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    The build hasn't been released yet. Should be out later today or tomorrow.
     
  12. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    Email me with your invoice number and I'll share the latest build with you.
     
  13. tonidurans

    tonidurans

    Joined:
    Jan 30, 2015
    Posts:
    6
    Thanks ;)
     
  14. neshius108

    neshius108

    Joined:
    Nov 19, 2015
    Posts:
    110
    Great to hear that!

    Keep me updated on it :)
     
  15. neshius108

    neshius108

    Joined:
    Nov 19, 2015
    Posts:
    110
    @Lanre: any update on the new version? Looking forward on that fix for the duplicate frames. :D
     
  16. tantanix

    tantanix

    Joined:
    Nov 20, 2013
    Posts:
    10
    I'm getting an error in latest iOS version (12.4) when switching to front camera and then calling camera.FocusLock

    Using NatCam 2.2.1

    Code (CSharp):
    1. Uncaught exception: NSInvalidArgumentException: *** -[AVCaptureDevice setFocusMode:] Unsupported focusMode - use -isFocusModeSupported: to discover valid focus modes
     
  17. chriscode

    chriscode

    Joined:
    Mar 2, 2015
    Posts:
    48
    Hi there,

    Will NatCAm allow you to have the camera preview running, equivalent of WebCamTexture running at the same time as the flashlight on? On Android and IOS? Any version restrictions?

    Cheers,

    CHris
     
  18. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    Later today. I apologize for the late response; I've had a whole lot to work on so I haven't had enough time to sit and hash the update out.
     
  19. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    The NatCam 2.3 update will add `CameraDevice.IsFocusLockSupported` so you can check this in your code before setting it.
     
  20. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    Yes, this is supported. In the upcoming version, NatCam's minimum requirements are iOS 11 and Android API level 21.
     
  21. Mojo-Game-Studio

    Mojo-Game-Studio

    Joined:
    Sep 18, 2015
    Posts:
    111
    Hiya,

    Building to 32bit android and the camera works as expected, but when I build for 64bit android we just get a white screen, any ideas?
     
  22. arturmandas

    arturmandas

    Joined:
    Sep 29, 2012
    Posts:
    240
    After upgrade from Unity 2018.2.5 to Unity 2018.3.13, I needed to update NatCam, and it stopped working for me -> I am also using Vuforia in my project and previously disabled Vuforia before enabling NatCam preview, then re-enabled it after closing preview of NatCam (all while using Vuforia Delayed Initialization). Now I am experiencing black screens, Vuforia failing to init.

    TL;DR: how to marry NatCam with Vuforia?
     
  23. arturmandas

    arturmandas

    Joined:
    Sep 29, 2012
    Posts:
    240
    OPENGL NATIVE PLUG-IN ERROR: GL_INVALID_FRAMEBUFFER_OPERATION: Framebuffer is not complete or incompatible with command.

    This appears when trying to de-initializaing NatCam camera feed, breaking my later try to initialize Vuforia. Anyone?
     
  24. arturmandas

    arturmandas

    Joined:
    Sep 29, 2012
    Posts:
    240
    @Lanre I have sent you private message with the issue. Thanks!
     
  25. SistemasImascono

    SistemasImascono

    Joined:
    Aug 16, 2016
    Posts:
    1
    I encountered the same issue and finally came to a solution after some struggling.
    · Go to Project Settings/OtherSettings/Graphics APIs
    · Remove Vulkan
    · Add OpenGLES2 after OpenGLES3
     
    Lanre likes this.
  26. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    Can you share the full logs from logcat in a .txt file?
     
  27. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    I'll send you the NatCam 2.3 build sometime tomorrow to test. Hopefully it fixes this. Technically this is a Vuforia issue, not a NatCam one.
     
  28. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,557
    Hello, Lanre.

    I tried the latest NatCam 2.3.0, but when I opened the camera, the Unity editor crashed.
    My environment is Windows, Unity 2017.1.5f1.
    I think this problem can be solved by replacing the code on line 207 of CameraDeviceLegacy.cs with "previewTexture.UpdateExternalTexture (webcamTexture.GetNativeTexturePtr ()); " to "previewTexture.Apply ();".
     
    Lanre likes this.
  29. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    Thanks for this. I'll push an update with it.
     
  30. EnoxSoftware

    EnoxSoftware

    Joined:
    Oct 29, 2014
    Posts:
    1,557
    Thank you for the response.
    I encountered another problem in NatCam 2.3.0.
    When the "CameraDevice.StopPreview ()" method is called, the OnStart event seems to occurs after that.
    I have encountered this problem on Android devices and haven't tried it on iOS devices yet.
    In the example of MiniCam, when the "SwitchCamera" button is pressed, the OnStart event occurs twice.
     
  31. tiffanybailey24124

    tiffanybailey24124

    Joined:
    Sep 22, 2019
    Posts:
    4
    Hi.
    Anything planned for supporting emulators like bluestacks? It's crashing atm when trying to start the preview. Thanks!
     
  32. tiffanybailey24124

    tiffanybailey24124

    Joined:
    Sep 22, 2019
    Posts:
    4
    Also the flash doesn't seem to be working. I only tried on android for now.Using the torch mode works fine, so I know that the light is definitely working.
     
  33. lazyninjacat

    lazyninjacat

    Joined:
    Feb 8, 2019
    Posts:
    4
    I'm having trouble with the orientation of the photo once it has been taken. The preview displays in the correct orientation, but when you press the capture button to capture the photo, it come out upside down. This is using the mini cam example. What am I missing? How can I fix?
     
  34. JannickL

    JannickL

    Joined:
    May 18, 2016
    Posts:
    78
    Hey there,
    in order to build a complete application I use two scenes (one introduction scene without natcam and the second one that searches for a qr code). I can go from the first scene to the second scene, scan something and everything works well but when I then go back to scene one again in order to restart the process and now go to scene two netcam throws an error. So I can't setup use NatCam after it already got used once.

    Here is the issue: NatCam (QRReader) gives me a nullreference exception after changing the scene.
    I can't see any preview. Seems like the issue is based on the preview.Apply() call:



    Any ideas?
     
  35. darrylday

    darrylday

    Joined:
    Oct 12, 2018
    Posts:
    1
    Hi there,

    I have been using NatCam for a while now and it seems like every update a few of my problems I encounter get fixed but then an equal or greater amount of problems get introduced.

    In the latest 2.3.0 update I encountered the following bugs on Android 9 before I had to revert back to an old update:
    - OnPhoto is returning a texture that is upside down (same issue as lazyninjacat is having). I have my app orientation locked to Landscape.Right but if I hold my device in portrait orientation the OnPhoto will return a portrait orientated texture that is upside-down.
    - Running the MiniCam example on a fresh project/install throws a permission error (no dialog box gets prompted like it has in the past)
    - After taking a photo my video preview texture turns gray.
    - When I set the camera device photo resolution to 3840x2160 and then immediately read it back it returns 4128x2322 but then when I take a photo and read the texture size from OnPhoto it's size is 4128x3096.

    My app also uses NatCam for iOS but not gonna start testing that until at least these get fixed.

    For reference, I am using Unity 2019.1.14f1.
     
  36. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    Thanks for bringing this to my attention. I'll check it out. I'll also submit a new PR for the NatCam-OpenCV example.
     
  37. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    Unfortunately we don't support emulators. I would expect that the emulator has a camera2 implementation.
     
  38. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    You seem to be running a much older version of NatCam. I recommend upgrading to NatCam 2.3.
     
  39. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    We changed how we handle orientation in the latest update. NatCam does not perform autorotation any longer, as it is both bad UX for camera apps and is very expensive to perform in native code. If your app uses autorotation, I recommend locking the app orientation when the camera is enabled, or stopping and restarting the camera so that it uses the current app orientation.
    This sounds like a Unity issue. Unity should automatically request the camera permission. I'll look into this.
    Hm this is weird. What device does this happen on?
    Setting a value and reading a different value is expected behaviour; NatCam will try to set the closest supported resolution to what you requested. As for the photo size being different, this is weird indeed. Again, what device?
     
  40. tantanix

    tantanix

    Joined:
    Nov 20, 2013
    Posts:
    10
    Hi,

    We are getting crashes when loading another scene. There is something wrong with the way NatCam is disposed internally. After we updated to v2.3.0, we are getting this exception in ios. If we disable NatCam, everything works okay.

    libc++abi.dylib: terminating with uncaught exception of type Il2CppExceptionWrapper
     
  41. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    This means that there is an exception in .NET, not in native code. When switching scenes, make sure that you stop the camera because any callbacks you have might be referencing stale or destroyed references.
     
  42. tantanix

    tantanix

    Joined:
    Nov 20, 2013
    Posts:
    10
    Yup, I also did that. I even waited for IsRunning to be false before changing scenes just to be sure. Even removed the reference to the used texture before closing just to be extra sure. Not sure what's going on TBH.
     
  43. tantanix

    tantanix

    Joined:
    Nov 20, 2013
    Posts:
    10
    @Lanre Thanks to your response, you gave me a clue. I found the issue: I didn't keep a reference to the active camera (only the index) so I was always calling CameraDevice.GetDevices() everywhere which internally was (I think) creating multiple arrays of CameraDeviceiOS and instances.
     
    Lanre likes this.
  44. SarbaJB

    SarbaJB

    Joined:
    Jul 6, 2017
    Posts:
    2
    Small question! We already bought NatCorder and I'm considering this one also, since I'm looking for an alternative to the crappy WebCamTexture.

    I have to capture a video to "edit" it a little bit, and then I'll record it back again with NatCorder. Could I use NatCam to send the camera feed on a texture and use NatCorder to record it at the same time with a good framerate?
     
  45. tiffanybailey24124

    tiffanybailey24124

    Joined:
    Sep 22, 2019
    Posts:
    4
    What about the flash? I tried it on android, but it doesn't work. The values don't change even after trying to set to a different value. Is there something I can do to fix it?
     
  46. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    You need to keep a reference to the CameraDevice instance. Multiple instances can refer to the same hardware camera, each with its own state. This is why we changed the static getter property to an explicit function.
     
  47. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    Yes you can. Simply commit each frame to NatCorder (use the OnFrame event from NatCam to know when to commit a new frame for recording).
     
  48. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    The flash issue has existed for quite a while now. For some reason, we can't get Android's camera2 API to fire the flash when capturing a photo.
     
  49. nctw

    nctw

    Joined:
    Oct 8, 2019
    Posts:
    4
    Hi, after upgrading to the latest update the camera preview stopped working on multiple android devices. The StartPreview callback does not fire anymore. What could be the problem?
     
  50. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,969
    I'll need to see the unfiltered logs from logcat. What devices and OS versions does this happen on?