protected override void OnCallback(Wrapper.CallbackType type, Wrapper.CallbackState args)
        {
            if (type == Wrapper.CallbackType.Capture)
            {
                switch (args.CaptureState.stateType)
                {
                case Wrapper.CaptureStateType.PreviewStarted:
                    startPreviewCompletionSource?.TrySetResult(args.CaptureState);
                    break;

                case Wrapper.CaptureStateType.PreviewStopped:
                    stopCompletionSource?.TrySetResult(args.CaptureState);
                    break;

                case Wrapper.CaptureStateType.PreviewAudioFrame:
                    //Debug.Log("PreviewAudioFrame");
                    break;

                case Wrapper.CaptureStateType.PreviewVideoFrame:
                    OnPreviewFrameChanged(args.CaptureState);
                    break;

                case Wrapper.CaptureStateType.PhotoFrame:
                    photoCompletionSource?.TrySetResult(args.CaptureState);
                    break;
                }
            }
        }
Пример #2
0
        private void OnStateChanged(Wrapper.CallbackState args)
        {
            switch (args.Type)
            {
            case Wrapper.CallbackType.Failed:
                OnFailed(args.FailState);
                break;

            default:
                OnCallback(args.Type, args);
                break;
            }
        }
Пример #3
0
        internal void OnStateChanged(Wrapper.CallbackState args)
        {
            // TODO: validate callback is on the right thread
            // if not queue callback action(QueueCallback(() => { OnStateChanged(args); });)
            QueueCallback(() =>
            {
                switch (args.Type)
                {
                case Wrapper.CallbackType.Failed:
                    OnFailed(args.FailState);
                    break;

                default:
                    OnCallback(args.Type, args);
                    break;
                }
            });
        }
Пример #4
0
        internal void CompleteCallback(Wrapper.CallbackState args)
        {
#if UNITY_WSA_10_0
            if (!UnityEngine.WSA.Application.RunningOnAppThread())
            {
                UnityEngine.WSA.Application.InvokeOnAppThread(() =>
                {
                    OnStateChanged(args);
                }, false);
            }
            else
            {
                OnStateChanged(args);
            }
#else
            // there is still a chance the callback is on a non AppThread(callbacks genereated from WaitForEndOfFrame are not)
            // this will process the callback on AppThread on a FixedUpdate
            OnStateChanged(args);
#endif
        }
Пример #5
0
        internal static void PInvokeCallbackHandler(IntPtr senderPtr, Wrapper.CallbackState args)
        {
            if (senderPtr == IntPtr.Zero)
            {
                Debug.LogError("OnCallback: senderPtr is null.");

                return;
            }

            GCHandle handle = default(GCHandle);

            try
            {
                handle = GCHandle.FromIntPtr(senderPtr);
            }
            catch (Exception ex)
            {
                Debug.LogError("OnCallback: " + ex.Message);

                return;
            }

            // check if this is of correct type
            if (handle.Target is CameraCapture)
            {
                var thisObject = (CameraCapture)handle.Target;
                thisObject.CompleteCallback(args);
            }
            //else if (handle.Target is OtherClass)
            //{
            //    var thisObject = (OtherClass)handle.Target;
            //    thisObject.CompleteCallback(args);
            //}
            else
            {
                Debug.LogError("OnCallback: senderPtr is not null, but not of correct type.");

                return;
            }
        }
Пример #6
0
        internal static void Capture_Callback(IntPtr senderPtr, Wrapper.CallbackState args)
        {
            if (senderPtr == IntPtr.Zero)
            {
                Debug.LogError("Plugin_Callback: requires thisObjectPtr.");

                return;
            }

            GCHandle handle = GCHandle.FromIntPtr(senderPtr);

            var thisObject = handle.Target as CameraCapture;

            if (thisObject == null)
            {
                Debug.LogError("Plugin_Callback: thisObjectPtr is not null, but seems invalid.");

                return;
            }

#if UNITY_WSA_10_0
            if (!UnityEngine.WSA.Application.RunningOnAppThread())
            {
                UnityEngine.WSA.Application.InvokeOnAppThread(() =>
                {
                    thisObject.OnStateChanged(args);
                }, false);
            }
            else
            {
                thisObject.OnStateChanged(args);
            }
#else
            // there is still a chance the callback is on a non AppThread(callbacks genereated from WaitForEndOfFrame are not)
            // this will process the callback on AppThread on a FixedUpdate
            thisObject.OnStateChanged(args);
#endif
        }
Пример #7
0
        protected override void OnCallback(Wrapper.CallbackType type, Wrapper.CallbackState args)
        {
            if (type == Wrapper.CallbackType.Capture)
            {
                switch (args.CaptureState.stateType)
                {
                case Wrapper.CaptureStateType.PreviewStarted:
                    Debug.Log("PreviewStarted");
                    break;

                case Wrapper.CaptureStateType.PreviewStopped:
                    Debug.Log("PreviewStopped");
                    break;

                case Wrapper.CaptureStateType.PreviewAudioFrame:
                    //Debug.Log("PreviewAudioFrame");
                    break;

                case Wrapper.CaptureStateType.PreviewVideoFrame:
                    OnVideoFrame(args.CaptureState);
                    break;
                }
            }
        }
Пример #8
0
 // callback handler for derived class
 protected abstract void OnCallback(Wrapper.CallbackType type, Wrapper.CallbackState args);