Exemple #1
0
        public void StartIsoStreaming(ref StreamControl control, FrameCallback callback)
        {
            var error = NativeMethods.uvc_start_iso_streaming(handle, ref control, callback, IntPtr.Zero);

            UvcException.ThrowExceptionForUvcError(error);
            cb = callback;
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="frameOrLabel"></param>
        /// <param name="callback"></param>
        /// <returns></returns>
        public bool addFrameScript(object frameOrLabel, FrameCallback callback)
        {
            if (frameCallbacks == null)
            {
                return(false);
            }
            if (m_MovieClipInfo == null)
            {
                return(false);
            }
            if (m_SymbolName == null)
            {
                return(false);
            }
            int num = 0;

            if (frameOrLabel is string)
            {
                num = getFrameLabel((string)frameOrLabel) - 1;
            }
            else if (frameOrLabel is int)
            {
                num = ((int)frameOrLabel) - 1;
            }
            if ((num < 0) || (num >= m_MovieClipInfo.frames.Count))
            {
                return(false);
            }
            if (frameCallbacks.ContainsKey(num))
            {
                return(false);
            }
            frameCallbacks[num] = callback;
            return(true);
        }
Exemple #3
0
        internal _FrameCallbackEntry(FrameCallback callback, bool rescheduling = false) {
            this.callback = callback;

            D.assert(() => {
                if (rescheduling) {
                    D.assert(() => {
                        if (debugCurrentCallbackStack == null) {
                            throw new UIWidgetsError(
                                new List<DiagnosticsNode> {
                                    new ErrorSummary(
                                        "scheduleFrameCallback called with rescheduling true, but no callback is in scope."),
                                    new ErrorDescription(
                                        "The \"rescheduling\" argument should only be set to true if the " +
                                        "callback is being reregistered from within the callback itself, " +
                                        "and only then if the callback itself is entirely synchronous."),
                                    new ErrorHint("If this is the initial registration of the callback, or if the " +
                                                  "callback is asynchronous, then do not use the \"rescheduling\" " +
                                                  "argument.")
                                });
                        }

                        return true;
                    });
                    debugStack = debugCurrentCallbackStack;
                }
                else {
                    debugStack = StackTraceUtility.ExtractStackTrace();
                }

                return true;
            });
        }
Exemple #4
0
        void _invokeFrameCallback(FrameCallback callback, TimeSpan timeStamp, StackTrace callbackStack = null)
        {
            D.assert(callback != null);
            D.assert(_FrameCallbackEntry.debugCurrentCallbackStack == null);
            D.assert(() => {
                _FrameCallbackEntry.debugCurrentCallbackStack = callbackStack;
                return(true);
            });

            try {
                callback(timeStamp);
            } catch (Exception ex) {
                UIWidgetsError.reportError(new UIWidgetsErrorDetails(
                                               exception: ex,
                                               library: "scheduler library",
                                               context: "during a scheduler callback",
                                               informationCollector: callbackStack == null
                        ? (InformationCollector)null
                        : information => {
                    information.AppendLine(
                        "\nThis exception was thrown in the context of a scheduler callback. " +
                        "When the scheduler callback was _registered_ (as opposed to when the " +
                        "exception was thrown), this was the stack:"
                        );
                    UIWidgetsError.defaultStackFilter(callbackStack.ToString().TrimEnd().Split('\n'))
                    .Each((line) => information.AppendLine(line));
                }
                                               ));
            }

            D.assert(() => {
                _FrameCallbackEntry.debugCurrentCallbackStack = null;
                return(true);
            });
        }
Exemple #5
0
 public int scheduleFrameCallback(FrameCallback callback, bool rescheduling = false) {
     scheduleFrame();
     _nextFrameCallbackId += 1;
     _transientCallbacks[key: _nextFrameCallbackId] =
         new _FrameCallbackEntry(callback: callback, rescheduling: rescheduling);
     return _nextFrameCallbackId;
 }
Exemple #6
0
        //[HandleProcessCorruptedStateExceptions]
        public void Close()
        {
            try
            {
                m_bRunning = false;
                int nTry = 200;
                while (true && m_ThreadCamera != null && m_bException == false)
                {
                    nTry--;
                    System.Windows.Forms.Application.DoEvents();
                    bool bret = m_ThreadCamera == null || m_ThreadCamera.Join(10);
                    if (bret || nTry <= 0)
                    {
                        break;
                    }
                }
                m_cbFrame      = null;
                m_ThreadCamera = null;

                //make sure the camera is closed
                if (m_nOpenCount > 0)
                {
                    m_nOpenCount = 0;
                    CloseCamera(m_nID);
                }
            }
            catch (System.Exception ex)
            {
                m_bException = true;
                ProcessException(m_nID, FUNC_CLOSE, ex.ToString());
            }
            m_cbError = null;
        }
Exemple #7
0
        internal _FrameCallbackEntry(FrameCallback callback, bool rescheduling = false)
        {
            this.callback = callback;

            D.assert(() => {
                if (rescheduling)
                {
                    D.assert(() => {
                        if (debugCurrentCallbackStack == null)
                        {
                            throw new UIWidgetsError(
                                "scheduleFrameCallback called with rescheduling true, but no callback is in scope.\n" +
                                "The \"rescheduling\" argument should only be set to true if the " +
                                "callback is being reregistered from within the callback itself, " +
                                "and only then if the callback itself is entirely synchronous. " +
                                "If this is the initial registration of the callback, or if the " +
                                "callback is asynchronous, then do not use the \"rescheduling\" " +
                                "argument.");
                        }

                        return(true);
                    });
                    this.debugStack = debugCurrentCallbackStack;
                }
                else
                {
                    this.debugStack = new StackTrace(2, true);
                }

                return(true);
            });
        }
Exemple #8
0
        //[HandleProcessCorruptedStateExceptions]
        public bool Start(FrameCallback func, int nWidht = 640, int nHeight = 480, int nFPS = 30)
        {
            try
            {
                if (m_ThreadCamera != null)
                {
                    Close();
                }

                m_bException = false;

                if (0 != OpenCamera(m_nID, nWidht, nHeight, nFPS))
                {
                    return(false);
                }
                m_nOpenCount++;

                m_cbFrame = func;
                ParameterizedThreadStart ParStart = new ParameterizedThreadStart(ThreadCamera);
                m_ThreadCamera = new Thread(ParStart);
                m_ThreadCamera.Start(m_nID);

                return(true);
            }
            catch (System.Exception ex)
            {
                m_bException = true;
                ProcessException(m_nID, FUNC_START, ex.ToString());
            }

            return(false);
        }
Exemple #9
0
 public int scheduleFrameCallback(FrameCallback callback, bool rescheduling = false)
 {
     this.scheduleFrame();
     this._nextFrameCallbackId += 1;
     this._transientCallbacks[this._nextFrameCallbackId] =
         new _FrameCallbackEntry(callback, rescheduling: rescheduling);
     return(this._nextFrameCallbackId);
 }
Exemple #10
0
        /// <summary>
        /// Start the processing block, delivering frames to a callback
        /// </summary>
        /// <param name="cb"></param>
        public void Start(FrameCallback cb)
        {
            frameCallbackHandle = GCHandle.Alloc(cb, GCHandleType.Normal);
            IntPtr cbPtr = GCHandle.ToIntPtr(frameCallbackHandle);

            object error;

            NativeMethods.rs2_start_processing_fptr(m_instance.Handle, m_frameCallback, cbPtr, out error);
        }
Exemple #11
0
 public CameraWrapper(int nID, ErrorCallback func = null)
 {
     m_nID          = nID;
     m_cbError      = func;
     m_bRunning     = false;
     m_ThreadCamera = null;
     m_cbFrame      = null;
     m_nOpenCount   = 0;
 }
Exemple #12
0
 public void removeFrameCallback(FrameCallback callbackWrapper)
 {
     if (IS_JELLYBEAN_OR_HIGHER)
     {
         choreographerRemoveFrameCallback(callbackWrapper.getFrameCallback());
     }
     else
     {
         mHandler.RemoveCallbacks(callbackWrapper.getRunnable());
     }
 }
Exemple #13
0
 public void postFrameCallbackDelayed(FrameCallback callbackWrapper, long delayMillis)
 {
     if (IS_JELLYBEAN_OR_HIGHER)
     {
         choreographerPostFrameCallbackDelayed(callbackWrapper.getFrameCallback(), delayMillis);
     }
     else
     {
         mHandler.PostDelayed(callbackWrapper.getRunnable(), delayMillis + ONE_FRAME_MILLIS);
     }
 }
Exemple #14
0
 public void PostFrameCallback(FrameCallback callbackWrapper)
 {
     if (IS_JELLYBEAN_OR_HIGHER)
     {
         choreographerPostFrameCallback(callbackWrapper.getFrameCallback());
     }
     else
     {
         mHandler.PostDelayed(callbackWrapper.getRunnable(), 0);
     }
 }
Exemple #15
0
		public Device(int id, PacketPipeline pipeline = PacketPipeline.Default)
		{
            handle = freenect2_device_create(Context, id, pipeline);

            if (handle == IntPtr.Zero) {
                throw new Exception("Could not create Kinect device");
            }

            ++contextRefCount;

            frameCallback = new FrameCallback(HandleFrame);
            freenect2_device_set_frame_callback(handle, frameCallback);
		}
Exemple #16
0
        public void Start(FrameCallback cb)
        {
            object         error;
            frame_callback cb2 = (IntPtr f, IntPtr u) =>
            {
                using (var frame = new Frame(f))
                    cb(frame);
            };

            m_callback = cb2;
            m_queue    = null;
            NativeMethods.rs2_start(m_instance, cb2, IntPtr.Zero, out error);
        }
Exemple #17
0
        public Device(int id, PacketPipeline pipeline = PacketPipeline.Default)
        {
            handle = freenect2_device_create(Context, id, pipeline);

            if (handle == IntPtr.Zero)
            {
                throw new Exception("Could not create Kinect device");
            }

            ++contextRefCount;

            frameCallback = new FrameCallback(HandleFrame);
            freenect2_device_set_frame_callback(handle, frameCallback);
        }
Exemple #18
0
        public PipelineProfile Start(Config cfg, FrameCallback cb)
        {
            object         error;
            frame_callback cb2 = (IntPtr f, IntPtr u) =>
            {
                using (var frame = new Frame(f))
                    cb(frame);
            };

            m_callback = cb2;
            var res  = NativeMethods.rs2_pipeline_start_with_config_and_callback(m_instance.Handle, cfg.m_instance.Handle, cb2, IntPtr.Zero, out error);
            var prof = new PipelineProfile(res);

            return(prof);
        }
Exemple #19
0
        /// <summary>start streaming from specified configured sensor</summary>
        /// <param name="cb">delegate to register as per-frame callback</param>
        // TODO: overload with state object and Action<Frame, object> callback to avoid allocations
        public void Start(FrameCallback cb)
        {
            object         error;
            frame_callback cb2 = (IntPtr f, IntPtr u) =>
            {
                using (var frame = Frame.Create(f))
                {
                    cb(frame);
                }
            };

            m_callback = cb2;
            m_queue    = null;
            NativeMethods.rs2_start(Handle, cb2, IntPtr.Zero, out error);
        }
Exemple #20
0
        /// <summary>
        /// Sets up a frame callback that is called immediately when an image is available,
        /// with no synchronization logic applied.
        /// </summary>
        /// <param name="onFrame">The function to be called whenever a new image is available.</param>
        public void Start(FrameCallback onFrame)
        {
            if (onFrame == null)
            {
                throw new ArgumentNullException(nameof(onFrame));
            }

            frameCallback = (frame, user) =>
            {
                var frameHandle = new FrameHandle(frame);
                onFrame(new Frame(frameHandle, this));
            };
            NativeMethods.rs2_start(handle, frameCallback, IntPtr.Zero, out IntPtr error);
            NativeHelper.ThrowExceptionForRsError(error);
        }
Exemple #21
0
        public void Start(FrameCallback cb)
        {
            object         error;
            frame_callback cb2 = (IntPtr f, IntPtr u) =>
            {
                //!TODO: check whether or not frame should be diposed here... I've got 2 concerns here:
                // 1. Best practice says that since the user's callback isn't the owner, frame should be diposed here...
                // 2. Users might need the frame for longer, but then they could clone it

                //cb(new Frame(f));
                using (var frame = new Frame(f))
                    cb(frame);
            };

            NativeMethods.rs2_start(m_instance, cb2, IntPtr.Zero, out error);
        }
Exemple #22
0
        void _invokeFrameCallback(FrameCallback callback, TimeSpan timeStamp, string callbackStack = null)
        {
            D.assert(callback != null);
            D.assert(_FrameCallbackEntry.debugCurrentCallbackStack == null);
            D.assert(() => {
                _FrameCallbackEntry.debugCurrentCallbackStack = callbackStack;
                return(true);
            });

            try {
                callback(timeStamp: timeStamp);
            }
            catch (Exception ex) {
                IEnumerable <DiagnosticsNode> infoCollector()
                {
                    yield return(DiagnosticsNode.message(
                                     "\nThis exception was thrown in the context of a scheduler callback. " +
                                     "When the scheduler callback was _registered_ (as opposed to when the " +
                                     "exception was thrown), this was the stack:"));

                    var builder = new StringBuilder();

                    foreach (var line in UIWidgetsError.defaultStackFilter(
                                 callbackStack.TrimEnd().Split('\n')))
                    {
                        builder.AppendLine(value: line);
                    }

                    yield return(DiagnosticsNode.message(builder.ToString()));
                }

                UIWidgetsError.reportError(new UIWidgetsErrorDetails(
                                               exception: ex,
                                               "scheduler library",
                                               new ErrorDescription("during a scheduler callback"),
                                               informationCollector: callbackStack == null
                        ? (InformationCollector)null
                        : infoCollector
                                               ));
            }

            D.assert(() => {
                _FrameCallbackEntry.debugCurrentCallbackStack = null;
                return(true);
            });
        }
Exemple #23
0
        /// <summary>
        /// Start the pipeline streaming with its default configuration.
        /// <para>
        /// The pipeline captures samples from the device, and delivers them to the through the provided frame callback.
        /// </para>
        /// </summary>
        /// <remarks>
        /// Starting the pipeline is possible only when it is not started. If the pipeline was started, an exception is raised.
        /// When starting the pipeline with a callback both <see cref="WaitForFrames"/> or <see cref="PollForFrames"/> will throw exception.
        /// </remarks>
        /// <param name="cb">Delegate to register as per-frame callback</param>
        /// <returns>The actual pipeline device and streams profile, which was successfully configured to the streaming device.</returns>
        // TODO: overload with state object and Action<Frame, object> callback to avoid allocations
        public PipelineProfile Start(FrameCallback cb)
        {
            object         error;
            frame_callback cb2 = (IntPtr f, IntPtr u) =>
            {
                using (var frame = Frame.Create(f))
                {
                    cb(frame);
                }
            };

            m_callback = cb2;
            var res  = NativeMethods.rs2_pipeline_start_with_callback(Handle, cb2, IntPtr.Zero, out error);
            var prof = new PipelineProfile(res);

            return(prof);
        }
Exemple #24
0
        public Form1()
        {
            InitializeComponent();

            int id = 0;

            m_dl2[id] = new DeckLinkCSCaptureApi(id);

            AppSettings.Instance.Load("DeckLinkDueCaptureApp.json");

            this.KeyPreview = true;
            Control.CheckForIllegalCrossThreadCalls = false;
            pFrameCallback = new FrameCallback(FrameCallbackData);
            //m_dl2[id].SetFrameCallback(pFrameCallback);
            m_dl2[id].SetVideoHandle(panel1.Handle);
            m_dl2[id].SetWindowSize(0, 0, panel1.Width, panel1.Height);

            if (AppSettings.Instance.Config.EnableDownGraph > 0)
            {
                if (AppSettings.Instance.Config.EnableDownGraph == 1)
                {
                    m_dl2[id].Build_H264_TransportMux_Network(AppSettings.Instance.Config.MulticastIpAddress,
                                                              AppSettings.Instance.Config.MulticastPort,
                                                              AppSettings.Instance.Config.NicIpAddress, AppSettings.Instance.Config.bitrate,
                                                              AppSettings.Instance.Config.gopLength);
                }

                if (AppSettings.Instance.Config.EnableDownGraph == 2)
                {
                    m_dl2[id].Build_H264QS_TransportMux_Network(AppSettings.Instance.Config.MulticastIpAddress,
                                                                AppSettings.Instance.Config.MulticastPort,
                                                                AppSettings.Instance.Config.NicIpAddress, AppSettings.Instance.Config.bitrate,
                                                                AppSettings.Instance.Config.gopLength);
                }
            }

            int res;

            if ((res = m_dl2[id].StartCapture(AppSettings.Instance.Config.Device, SURFACE_ENGINE.DX9)) < 0)
            {
                MessageBox.Show("Failed to start capture: " + res);
            }
        }
Exemple #25
0
 public void addPersistentFrameCallback(FrameCallback callback)
 {
     _persistentCallbacks.Add(item: callback);
 }
Exemple #26
0
		public mupen64plusApi(N64 bizhawkCore, byte[] rom, VideoPluginSettings video_settings, int SaveType, int CoreType, bool DisableExpansionSlot)
		{
			// There can only be one core (otherwise breaks mupen64plus)
			if (AttachedCore != null)
			{
				AttachedCore.Dispose();
				AttachedCore = null;
			}
			this.bizhawkCore = bizhawkCore;

			CoreDll = LoadLibrary("mupen64plus.dll");
			if (CoreDll == IntPtr.Zero)
				throw new InvalidOperationException(string.Format("Failed to load mupen64plus.dll"));

			connectFunctionPointers();

			// Start up the core
			m64p_error result = m64pCoreStartup(0x20001, "", "", "Core",
				null, "", IntPtr.Zero);

			// Set the savetype if needed
			if (DisableExpansionSlot)
			{
				IntPtr core_section = IntPtr.Zero;
				int disable = 1;
				m64pConfigOpenSection("Core", ref core_section);
				m64pConfigSetParameter(core_section, "DisableExtraMem", m64p_type.M64TYPE_INT, ref disable);
			}

			// Set the savetype if needed
			if (SaveType != 0)
			{
				IntPtr core_section = IntPtr.Zero;
				m64pConfigOpenSection("Core", ref core_section);
				m64pConfigSetParameter(core_section, "SaveType", m64p_type.M64TYPE_INT, ref SaveType);
			}

			IntPtr coreSection = IntPtr.Zero;
			m64pConfigOpenSection("Core", ref coreSection);
			m64pConfigSetParameter(coreSection, "R4300Emulator", m64p_type.M64TYPE_INT, ref CoreType);

			// Pass the rom to the core
			result = m64pCoreDoCommandByteArray(m64p_command.M64CMD_ROM_OPEN, rom.Length, rom);

			// Open the general video settings section in the config system
			IntPtr video_section = IntPtr.Zero;
			m64pConfigOpenSection("Video-General", ref video_section);

			// Set the desired width and height for mupen64plus
			result = m64pConfigSetParameter(video_section, "ScreenWidth", m64p_type.M64TYPE_INT, ref video_settings.Width);
			result = m64pConfigSetParameter(video_section, "ScreenHeight", m64p_type.M64TYPE_INT, ref video_settings.Height);

			set_video_parameters(video_settings);

			InitSaveram();

			// Initialize event invoker
			m64pFrameCallback = new FrameCallback(FireFrameFinishedEvent);
			result = m64pCoreDoCommandFrameCallback(m64p_command.M64CMD_SET_FRAME_CALLBACK, 0, m64pFrameCallback);
			m64pVICallback = new VICallback(FireVIEvent);
			result = m64pCoreDoCommandVICallback(m64p_command.M64CMD_SET_VI_CALLBACK, 0, m64pVICallback);
			m64pRenderCallback = new RenderCallback(FireRenderEvent);
			result = m64pCoreDoCommandRenderCallback(m64p_command.M64CMD_SET_RENDER_CALLBACK, 0, m64pRenderCallback);

			// Prepare to start the emulator in a different thread
			m64pEmulator = new Thread(ExecuteEmulator);

			AttachedCore = this;
		}
        public mupen64plusApi(N64 bizhawkCore, byte[] rom, VideoPluginSettings video_settings, int SaveType, int CoreType, bool DisableExpansionSlot)
        {
            // There can only be one core (otherwise breaks mupen64plus)
            if (AttachedCore != null)
            {
                AttachedCore.Dispose();
                AttachedCore = null;
            }
            this.bizhawkCore = bizhawkCore;

            CoreDll = LoadLibrary("mupen64plus.dll");
            if (CoreDll == IntPtr.Zero)
            {
                throw new InvalidOperationException(string.Format("Failed to load mupen64plus.dll"));
            }

            connectFunctionPointers();

            // Start up the core
            m64p_error result = m64pCoreStartup(0x20001, "", "", "Core",
                                                null, "", IntPtr.Zero);

            // Open the core settings section in the config system
            IntPtr core_section = IntPtr.Zero;

            m64pConfigOpenSection("Core", ref core_section);

            // Set the savetype if needed
            if (DisableExpansionSlot)
            {
                int disable = 1;
                m64pConfigSetParameter(core_section, "DisableExtraMem", m64p_type.M64TYPE_INT, ref disable);
            }

            // Set the savetype if needed
            if (SaveType != 0)
            {
                m64pConfigSetParameter(core_section, "SaveType", m64p_type.M64TYPE_INT, ref SaveType);
            }

            m64pConfigSetParameter(core_section, "R4300Emulator", m64p_type.M64TYPE_INT, ref CoreType);

            // Pass the rom to the core
            result = m64pCoreDoCommandByteArray(m64p_command.M64CMD_ROM_OPEN, rom.Length, rom);

            // Open the general video settings section in the config system
            IntPtr video_section = IntPtr.Zero;

            m64pConfigOpenSection("Video-General", ref video_section);

            // Set the desired width and height for mupen64plus
            result = m64pConfigSetParameter(video_section, "ScreenWidth", m64p_type.M64TYPE_INT, ref video_settings.Width);
            result = m64pConfigSetParameter(video_section, "ScreenHeight", m64p_type.M64TYPE_INT, ref video_settings.Height);

            set_video_parameters(video_settings);

            InitSaveram();

            // Initialize event invoker
            m64pFrameCallback  = new FrameCallback(FireFrameFinishedEvent);
            result             = m64pCoreDoCommandFrameCallback(m64p_command.M64CMD_SET_FRAME_CALLBACK, 0, m64pFrameCallback);
            m64pVICallback     = new VICallback(FireVIEvent);
            result             = m64pCoreDoCommandVICallback(m64p_command.M64CMD_SET_VI_CALLBACK, 0, m64pVICallback);
            m64pRenderCallback = new RenderCallback(FireRenderEvent);
            result             = m64pCoreDoCommandRenderCallback(m64p_command.M64CMD_SET_RENDER_CALLBACK, 0, m64pRenderCallback);

            // Prepare to start the emulator in a different thread
            m64pEmulator = new Thread(ExecuteEmulator);

            AttachedCore = this;
        }
Exemple #28
0
 [DllImport("freenect2c")] private static extern void   freenect2_device_set_frame_callback(IntPtr device, FrameCallback callback);
Exemple #29
0
 [DllImport("freenect2c")] private static extern void   freenect2_device_set_frame_callback(IntPtr device, FrameCallback callback);
Exemple #30
0
 public void addPostFrameCallback(FrameCallback callback)
 {
     _postFrameCallbacks.Add(item: callback);
 }
Exemple #31
0
 internal static extern void rs2_start(SensorHandle sensor, FrameCallback on_frame, IntPtr user, out RsError error);
Exemple #32
0
 public void addPersistentFrameCallback(FrameCallback callback)
 {
     this._persistentCallbacks.Add(callback);
 }
Exemple #33
0
 public void addPostFrameCallback(FrameCallback callback)
 {
     this._postFrameCallbacks.Add(callback);
 }