public void StartPreview(DeviceCamera camera, Action startCallback, Action frameCallback)
 {
     this.startCallback = startCallback;
     this.frameCallback = frameCallback;
     NatCamBridge.StartPreview((IntPtr)(camera as DeviceCameraiOS));
     OnOrient();
 }
Exemple #2
0
 public NatCamiOS()
 {
     NatCamBridge.RegisterCoreCallbacks(onStart, onFrame, onPhoto, null);
     Device = new NatCamDeviceiOS();
     OrientationUtility.onOrient += OnOrient;
     Debug.Log("NatCam: Initialized NatCam 2.0 iOS backend");
 }
 public void StopPreview()
 {
     NatCamBridge.StopPreview();
     Texture2D.Destroy(preview);
     preview           = null;
     startCallback     =
         frameCallback = null;
 }
Exemple #4
0
        public void CaptureFrame(Texture2D frame)
        {
            // Get buffer info
            IntPtr ptr;

            NatCamBridge.CaptureFrame(out ptr);
            // Copy
            frame.LoadRawTextureData(ptr, preview.width * preview.height * 4);
            frame.Apply();
        }
Exemple #5
0
 public void Release()
 {
     OnStart     =
         OnFrame = null;
     NatCamBridge.Release();
     if (preview)
     {
         Texture2D.Destroy(preview);
     }
     preview = null;
 }
Exemple #6
0
 public NatCamiOS()
 {
     NatCamBridge.RegisterCoreCallbacks(onStart, onFrame, onPhoto);
     Device = new NatCamDeviceiOS();
     #if NATCAM_CORE
     DispatchUtility.onOrient += OnOrient;
     #endif
     #if NATCAM_PRO || NATCAM_PROFESSIONAL
     NatCamBridge.RegisterProCallbacks(OnVideo);
     #endif
     Utilities.Log("Initialized NatCam 1.6 iOS backend");
 }
Exemple #7
0
 public void Release()
 {
     OnStart     =
         OnFrame = null;
     #if NATCAM_PRO || NATCAM_PROFESSIONAL
     NatCamBridge.ReleaseBuffer();
     #endif
     NatCamBridge.Release();
     if (preview != null)
     {
         MonoBehaviour.Destroy(preview);
     }
     preview = null;
 }
Exemple #8
0
 private static void onPhoto(IntPtr imgPtr, int width, int height)
 {
     using (var dispatch = new MainDispatch()) {
         if (instance.photoCallback != null && imgPtr != IntPtr.Zero)
         {
             var photo = new Texture2D(width, height, TextureFormat.BGRA32, false);
             photo.LoadRawTextureData(unchecked ((IntPtr)(long)(ulong)imgPtr), width * height * 4);
             photo.Apply();
             NatCamBridge.ReleasePhoto(imgPtr);
             instance.photoCallback(photo);
         }
         instance.photoCallback = null;
     }
 }
Exemple #9
0
 public void Release()
 {
     OnStart     =
         OnFrame = null;
     #if NATCAM_PRO
     // ...
     #endif
     NatCamBridge.Release();
     if (preview != null)
     {
         MonoBehaviour.Destroy(preview);
     }
     preview = null;
 }
Exemple #10
0
        public void CaptureFrame(Texture2D frame)
        {
            // Get buffer info
            IntPtr ptr;

            NatCamBridge.CaptureFrame(out ptr);
            if (ptr == IntPtr.Zero)
            {
                return;                     // Only happens in frame when app is suspended
            }
            // Copy
            frame.LoadRawTextureData(ptr, preview.width * preview.height * 4);
            frame.Apply();
        }
Exemple #11
0
 public void CaptureFrame(byte[] pixels, bool flip)
 {
     // Handle flip specially
     if (flip)
     {
         var handle = GCHandle.Alloc(pixels, GCHandleType.Pinned);
         NatCamBridge.InvertFrame(handle.AddrOfPinnedObject());
         handle.Free();
     }
     else
     {
         IntPtr ptr;
         NatCamBridge.CaptureFrame(out ptr);
         Marshal.Copy(ptr, pixels, 0, preview.width * preview.height * 4);
     }
 }
Exemple #12
0
 public NatCamAndroid()
 {
     using (var player = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) {
         var cacheDir = player
                        .GetStatic <AndroidJavaObject>("currentActivity")
                        .Call <AndroidJavaObject>("getCacheDir")
                        .Call <string>("toString");
         NatCamBridge.RegisterCoreCallbacks(onStart, onFrame, onPhoto, cacheDir);
     }
     natcam = new AndroidJavaObject("com.yusufolokoba.natcam.NatCam");
     Device = new NatCamDeviceAndroid();
     RenderDispatch.Initialize();
     DispatchUtility.onPause     += OnPause;
     OrientationUtility.onOrient += OnOrient;
     Debug.Log("NatCam: Initialized NatCam 2.0 Android backend");
 }
Exemple #13
0
        public void PreviewBuffer(out IntPtr ptr, out int width, out int height, out int size)
        {
            width = preview.width; height = preview.height;
            if (buffer != null && buffer.Length != width * height)
            {
                ReleaseBuffer();
            }
            if (buffer == null)
            {
                InitializeBuffer();
            }
            preview.GetPixels32(buffer);
            size = buffer.Length * Marshal.SizeOf(typeof(Color32));
            GCHandle pin = GCHandle.Alloc(buffer, GCHandleType.Pinned);

            NatCamBridge.memcpy(handle, pin.AddrOfPinnedObject(), (UIntPtr)size);
            pin.Free();
            ptr = handle;
        }
Exemple #14
0
 private static void onPhoto(IntPtr imgPtr, int width, int height, int size)
 {
     using (var dispatch = new MainDispatch()) {
         if (instance.photoCallback == null)
         {
             NatCamBridge.ReleasePhoto();
             return;
         }
         if (imgPtr == IntPtr.Zero)
         {
             return;
         }
         var photo = new Texture2D(width, height, TextureFormat.BGRA32, false);
         photo.LoadRawTextureData(unchecked ((IntPtr)(long)(ulong)imgPtr), size);
         photo.Apply();
         NatCamBridge.ReleasePhoto();
         instance.photoCallback(photo, 0);
         instance.photoCallback = null;
     }
 }
Exemple #15
0
 public void CaptureFrame(byte[] pixels, bool flip)
 {
     // Handle flip specially
     if (flip)
     {
         var handle = GCHandle.Alloc(pixels, GCHandleType.Pinned);
         NatCamBridge.InvertFrame(handle.AddrOfPinnedObject());
         handle.Free();
     }
     else
     {
         IntPtr ptr;
         NatCamBridge.CaptureFrame(out ptr);
         if (ptr == IntPtr.Zero)
         {
             return;                     // Only happens in frame when app is suspended
         }
         Marshal.Copy(ptr, pixels, 0, preview.width * preview.height * 4);
     }
 }
Exemple #16
0
 private void OnOrient()
 {
     #if NATCAM_CORE
     NatCamBridge.SetOrientation((byte)DispatchUtility.Orientation);
     #endif
 }
Exemple #17
0
 public void CapturePhoto(PhotoCallback callback)
 {
     photoCallback = callback;
     NatCamBridge.CapturePhoto();
 }
Exemple #18
0
 public void Play()
 {
     NatCamBridge.Play();
 }
 public void CaptureFrame(byte[] dest)
 {
     NatCamBridge.CaptureFrame(dest);
 }
Exemple #20
0
 public void Pause()
 {
     NatCamBridge.Pause();
 }
Exemple #21
0
 public void PreviewBuffer(out IntPtr ptr, out int width, out int height, out int size)
 {
     NatCamBridge.PreviewBuffer(out ptr, out width, out height, out size);
 }
 public NatCamiOS()
 {
     NatCamBridge.RegisterCoreCallbacks(OnStart, OnFrame, OnPhoto, null);
     OrientationUtility.onOrient += OnOrient;
     Debug.Log("NatCam: Initialized NatCam 2.1 iOS backend");
 }
Exemple #23
0
 private void OnOrient()
 {
     NatCamBridge.OnOrient((int)OrientationUtility.Orientation);
 }
Exemple #24
0
 public void Play()
 {
     OnOrient();
     NatCamBridge.Play();
 }
Exemple #25
0
 public void StartRecording(Configuration configuration, SaveCallback callback)
 {
     recordingCallback = callback;
     NatCamBridge.StartRecording(configuration.bitrate, configuration.keyframeInterval, configuration.recordAudio);
 }
Exemple #26
0
 public void StopRecording()
 {
     NatCamBridge.StopRecording();
 }
 public void CapturePhoto(Action <Texture2D> callback)
 {
     photoCallback = callback;
     NatCamBridge.CapturePhoto();
 }