예제 #1
0
 public void DispatchContinuous(Action action)
 {
     lock (queueLock) {
         Ext.LogVerbose("Dispatch Enqueue Update");
         update.Add(action);
     }
 }
예제 #2
0
 public static void Initialize(PreviewType previewType, bool metadataDetection)
 {
     mReadablePreview   = previewType == PreviewType.Readable;
     mPhotoSaveMode     = (int)SaveMode.DoNotSave;
     mMetadataDetection = metadataDetection;
     listener           = new GameObject("NatCamHelper").AddComponent <NatCamHelper>();
     Dispatch           = NatCamDispatch.Prepare(DispatchMode.Synchronous, listener);
     RegisterCallbacks(Render, Update, UpdatePhoto, UpdateCode, UpdateFace);
     InspectDeviceCameras();
     isInitialized = true;
     Ext.LogVerbose("Initialized native interface");
 }
예제 #3
0
 private static void Update(IntPtr RGBA32GPUPtr, UIntPtr RGBA32Ptr, UIntPtr width, UIntPtr height, UIntPtr size)
 {
     //Dispatch on main thread
     Dispatch.Dispatch(() => {
         Ext.LogVerbose("Received native update: " + string.Format("ptr<{0}>, ptr<{1}>, {2}, {3}, {4}", RGBA32GPUPtr.ToInt32().ToString(), RGBA32Ptr.ToUInt32().ToString(), width.ToString(), height.ToString(), size.ToString()));
         //Initialization
         Preview = Preview ?? Texture2D.CreateExternalTexture((int)width, (int)height, TextureFormat.RGBA32, false, false, RGBA32GPUPtr);
         //Size checking
         if (Preview.width != (int)width || Preview.height != (int)height)
         {
             Preview.Resize((int)width, (int)height, Preview.format, false);
         }
         //Update
         Preview.UpdateExternalTexture(RGBA32GPUPtr);
         //Propagation
         if (OnNativePreviewUpdate != null)
         {
             OnNativePreviewUpdate(ComponentBuffer.RGBA32GPU, unchecked ((UIntPtr)(ulong)(long)RGBA32GPUPtr), (int)width, (int)height, (int)size);
             if (mReadablePreview)
             {
                 OnNativePreviewUpdate(ComponentBuffer.RGBA32, RGBA32Ptr, (int)width, (int)height, (int)size);
             }
         }
         //OpenCV
         #if OPENCV_DEVELOPER_MODE
         if (mReadablePreview)
         {
             PreviewMatrix = PreviewMatrix ?? new Mat(new Size((int)width, (int)height), CvType.CV_8UC4);
             if (PreviewMatrix.cols() != (int)width || PreviewMatrix.rows() != (int)height)
             {
                 Imgproc.resize(PreviewMatrix, PreviewMatrix, new Size((int)width, (int)height));
             }
             Utils.copyToMat(unchecked ((IntPtr)(long)(ulong)RGBA32Ptr), PreviewMatrix);
             //Core.flip (PreviewMatrix, PreviewMatrix, 0); //Dev should do this themselves
         }
         #endif
         //Propagation
         if (
             !FirstFrameReceived
             #if UNITY_ANDROID
             && !A.Get <bool>("orientationDirty") //In NCNA, this flag is bound to active camera state
             #endif
             )
         {
             PropagateStart(); FirstFrameReceived = isPlaying = true;
         }
         if (FirstFrameReceived)
         {
             PropagateUpdate();
         }
     });
 }
예제 #4
0
 public void Dispatch(Action action)
 {
     //Check that we aren't already on the target thread
     if (Thread.CurrentThread.ManagedThreadId == targetThread.ManagedThreadId)
     {
         Ext.LogVerbose("Dispatch Execute");
         action();
     }
     //Enqueue
     else
     {
         lock (queueLock) {
             Ext.LogVerbose("Dispatch Enqueue");
             invocation.Add(action);
         }
     }
 }
예제 #5
0
            private static FaceCallback PropagateFace; //Maybe one day
            #endregion


            #region ---Public Ops---

            public static void Initialize(bool metadataDetection)
            {
                if (!supportedDevice)
                {
                    return;
                }
                mMetadataDetection = metadataDetection;
                Dispatch           = NatCamDispatch.Prepare(DispatchMode.Synchronous);
                Dispatch.DispatchContinuous(Update);
                if (mMetadataDetection)
                {
                    MetadataDispatch = NatCamDispatch.Prepare(DispatchMode.Asynchronous);
                    MetadataDispatch.DispatchContinuous(UpdateMetadata);
                }
                isInitialized = true;
                Ext.LogVerbose("Initialized fallback interface");
            }
예제 #6
0
 private static void Render(int request)
 {
     #if UNITY_ANDROID
     if (Dispatch == null)
     {
         return;
     }
     //Dispatch on the main thread
     Dispatch.Dispatch(() => {
         //Invocation
         Ext.LogVerbose("Native requested callback " + request + " on render thread");
         GL.IssuePluginEvent(NatCamNativeCallback(), request);
         //Release
         if (request == 3)
         {
             NatCamDispatch.Release(Dispatch);
             Dispatch = null;
         }
     });
     #endif
 }