Пример #1
0
 public void StartPreview(DeviceCamera camera, Action startCallback, Action frameCallback)
 {
     this.startCallback = startCallback;
     this.frameCallback = frameCallback;
     NatCamBridge.StartPreview((IntPtr)(camera as DeviceCameraiOS));
     OnOrient();
 }
Пример #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");
 }
Пример #3
0
 public void StopPreview()
 {
     NatCamBridge.StopPreview();
     Texture2D.Destroy(preview);
     preview           = null;
     startCallback     =
         frameCallback = null;
 }
Пример #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();
        }
Пример #5
0
 public void Release()
 {
     OnStart     =
         OnFrame = null;
     NatCamBridge.Release();
     if (preview)
     {
         Texture2D.Destroy(preview);
     }
     preview = null;
 }
Пример #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");
 }
Пример #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;
 }
Пример #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;
     }
 }
Пример #9
0
 public void Release()
 {
     OnStart     =
         OnFrame = null;
     #if NATCAM_PRO
     // ...
     #endif
     NatCamBridge.Release();
     if (preview != null)
     {
         MonoBehaviour.Destroy(preview);
     }
     preview = null;
 }
Пример #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();
        }
Пример #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);
     }
 }
Пример #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");
 }
Пример #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;
        }
Пример #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;
     }
 }
Пример #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);
     }
 }
Пример #16
0
 private void OnOrient()
 {
     #if NATCAM_CORE
     NatCamBridge.SetOrientation((byte)DispatchUtility.Orientation);
     #endif
 }
Пример #17
0
 public void CapturePhoto(PhotoCallback callback)
 {
     photoCallback = callback;
     NatCamBridge.CapturePhoto();
 }
Пример #18
0
 public void Play()
 {
     NatCamBridge.Play();
 }
Пример #19
0
 public void CaptureFrame(byte[] dest)
 {
     NatCamBridge.CaptureFrame(dest);
 }
Пример #20
0
 public void Pause()
 {
     NatCamBridge.Pause();
 }
Пример #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);
 }
Пример #22
0
 public NatCamiOS()
 {
     NatCamBridge.RegisterCoreCallbacks(OnStart, OnFrame, OnPhoto, null);
     OrientationUtility.onOrient += OnOrient;
     Debug.Log("NatCam: Initialized NatCam 2.1 iOS backend");
 }
Пример #23
0
 private void OnOrient()
 {
     NatCamBridge.OnOrient((int)OrientationUtility.Orientation);
 }
Пример #24
0
 public void Play()
 {
     OnOrient();
     NatCamBridge.Play();
 }
Пример #25
0
 public void StartRecording(Configuration configuration, SaveCallback callback)
 {
     recordingCallback = callback;
     NatCamBridge.StartRecording(configuration.bitrate, configuration.keyframeInterval, configuration.recordAudio);
 }
Пример #26
0
 public void StopRecording()
 {
     NatCamBridge.StopRecording();
 }
Пример #27
0
 public void CapturePhoto(Action <Texture2D> callback)
 {
     photoCallback = callback;
     NatCamBridge.CapturePhoto();
 }