public void Close() { lock (mutex) { if (controllerState.Equals(CMSState.Quitting)) { return; } if (CMSLogger.CanCreateLogEvent(false, false, false, "CMSLogEndEvent")) { CMSLogEndEvent endEvent = new CMSLogEndEvent(); endEvent.SetDateTime(DateTime.Now); if (endEvent != null) { CMSLogger.SendLogEvent(endEvent); } } videoSource.StopSource(); controllerState = CMSState.Quitting; CMSTrackingSuite selectedSuite = model.SelectedSuite; if (selectedSuite != null) { selectedSuite.Clean(); } videoDisplay.Quit(); controlToggler.Stop(); CMSLogger.StopLogging(); } }
public override void ProcessMouse(System.Drawing.Point p, bool leftMouseButton, int cameraNum) { if (cameraNum != 0) { return; } if (p.X < 0 || p.X >= this.imageSize.Width || p.Y < 0 || p.Y >= this.imageSize.Height) { return; } imagePoint.X = p.X; imagePoint.Y = p.Y; _current_track_points[0].x = p.X; _current_track_points[0].y = p.Y; _last_track_points[0].x = p.X; _last_track_points[0].y = p.Y; if (!validTrackPoint) { if (CMSLogger.CanCreateLogEvent(false, false, false, "CMSLogStandardStateEvent")) { CMSLogStandardStateEvent logEvent = new CMSLogStandardStateEvent(); if (logEvent != null) { logEvent.ValidTrackingPoint = true; CMSLogger.SendLogEvent(logEvent); } } } validTrackPoint = true; trackingSuiteAdapter.ToggleSetup(false); }
/******************** Other Functions ****************/ private void SetState(CMSState state) { lock (mutex) { /* * if (state.Equals(CMSState.Tracking)) * { * videoDisplay.SetTrackingControlMessage(false, ""); * } * else if (state.Equals(CMSState.ControlTracking)) * { * videoDisplay.SetTrackingControlMessage(true, ""); * } * else if (state.Equals(CMSState.Setup)) * { * videoDisplay.ReceiveMessage("", Color.Black); * //videoDisplay.SetTrackingControlMessage(false, false); * }*/ controllerState = state; CMSTrackingSuite curSuite = model.SelectedSuite; if (curSuite != null) { curSuite.StateChange(state); } if (CMSLogger.CanCreateLogEvent(false, false, false, "CMSLogStateChangeEvent")) { CMSLogStateChangeEvent stateChangeEvent = new CMSLogStateChangeEvent(); stateChangeEvent.State = state.ToString(); CMSLogger.SendLogEvent(stateChangeEvent); } } }
private void buttonSendMessage_Click(object sender, EventArgs e) { if (!CMSLogger.CanCreateLogEvent(false, false, false, "CMSLogMessageEvent")) { return; } SendMessageForm smf = new SendMessageForm(); if (!smf.ShowDialog().Equals(DialogResult.OK)) { return; } string text = smf.MessageText; if (text == null) { return; } text = text.Trim(); CMSLogMessageEvent logEvent = new CMSLogMessageEvent(); logEvent.Text = text; CMSLogger.SendLogEvent(logEvent); }
/******************** Video Source Events ***********************/ private void CameraFound() { lock (mutex) { if (CMSLogger.CanCreateLogEvent(false, false, false, "CMSLogCameraFoundEvent")) { CMSLogCameraFoundEvent cameraFoundEvent = new CMSLogCameraFoundEvent(); if (cameraFoundEvent != null) { CMSLogger.SendLogEvent(cameraFoundEvent); } } if (controllerState.Equals(CMSState.CameraNotFound)) { if (videoSource.StartSource()) { SetState(CMSState.Setup); model.CurrentMonikor = videoSource.GetCurrentMonikor(); } else { SetState(CMSState.CameraNotFound); } } else { throw new Exception("Received Camera Found in state " + controllerState.ToString()); } } }
private void SendTogglerConfigLogEvent() { if (CMSLogger.CanCreateLogEvent(false, false, false, "CMSLogTogglerConfigEvent")) { CMSLogTogglerConfigEvent togglerConfigEvent = new CMSLogTogglerConfigEvent(); togglerConfigEvent.Config = togglerConfig; CMSLogger.SendLogEvent(togglerConfigEvent); } }
public override void SendSuiteLogEvent() { if (CMSLogger.CanCreateLogEvent(false, false, false, "CMSLogEmptySuiteEvent")) { CMSLogEmptySuiteEvent logEvent = new CMSLogEmptySuiteEvent(); if (logEvent != null) { CMSLogger.SendLogEvent(logEvent); } } }
/*public override CMSTrackingSuite Clone() * { * CMSTrackingSuiteStandard trackingModule = new CMSTrackingSuiteStandard(); * trackingModule.TrackingModule = StandardTracking.Clone() as CMSTrackingModule; * trackingModule.MouseControlModule = MouseControlModule.Clone() as CMSMouseControlModule; * trackingModule.ClickControlModule = ClickControlModule.Clone() as CMSClickControlModule; * return trackingModule; * }*/ public override void SendSuiteLogEvent() { if (CMSLogger.CanCreateLogEvent(false, false, false, "CMSLogStandardSuiteEvent")) { CMSLogStandardSuiteEvent logEvent = new CMSLogStandardSuiteEvent(); if (logEvent != null) { logEvent.StandardSuite = this; CMSLogger.SendLogEvent(logEvent); } } }
private void ResizeFrame(bool maximize) { if (InvokeRequired) { Invoke(new ResizeFrameDelegate(ResizeFrame), new object[] { maximize }); } else { if (maximize) { videoDisplay.Size = new Size(CMSConstants.VIDEO_DISPLAY_MAX_WIDTH, CMSConstants.VIDEO_DISPLAY_MAX_HEIGHT); this.controlPanel.Visible = true; this.TopMost = false; this.toolTipResize.SetToolTip(this.resizeOutputbutton, CMSConstants.MINIMIZE_FORM_TOOLTIP); this.resizeOutputbutton.Image = Properties.Resources.FormMinimize; Size = new Size(CMSConstants.VIDEO_DISPLAY_MAX_WIDTH + 60, CMSConstants.VIDEO_DISPLAY_MAX_HEIGHT + 250);// Set the size of the form this.videoDisplay.Location = new Point(21, 24); } else { videoDisplay.Size = new Size(CMSConstants.VIDEO_DISPLAY_MIN_WIDTH, CMSConstants.VIDEO_DISPLAY_MIN_HEIGHT); this.controlPanel.Visible = false; this.TopMost = true; this.toolTipResize.SetToolTip(this.resizeOutputbutton, CMSConstants.MAXIMIZE_FORM_TOOLTIP); this.resizeOutputbutton.Image = Properties.Resources.FormMaximize; Size = new Size(CMSConstants.VIDEO_DISPLAY_MIN_WIDTH + 40, CMSConstants.VIDEO_DISPLAY_MIN_HEIGHT + 50 + resizeOutputbutton.Size.Height);// Set the size of the form this.videoDisplay.Location = new Point(16, 5); } viewAdapter.RatioVideoInputToOutput = new double[] { ((double)videoInputSize.Width) / ((double)videoDisplay.Width) }; int x = this.videoDisplay.Location.X + this.videoDisplay.Width - this.resizeOutputbutton.Size.Width; int y = this.videoDisplay.Location.Y + this.videoDisplay.Height + 2; this.resizeOutputbutton.Location = new Point(x, y); Invalidate(); if (CMSLogger.CanCreateLogEvent(false, false, false, "CMSLogWindowChangedEvent")) { CMSLogWindowChangedEvent windowChangedEvent = new CMSLogWindowChangedEvent(); if (windowChangedEvent != null) { windowChangedEvent.Maximized = maximize; CMSLogger.SendLogEvent(windowChangedEvent); } } } }
public static void Init(CMSLogConfig logConfig, CMSIdentificationConfig idConfig) { logger = new CMSLogger(); logger.LogConfig = logConfig; logger.IdConfig = idConfig; System.Collections.IDictionary environment = Environment.GetEnvironmentVariables(); if (environment.Contains("DateTimeSendPeriod")) { long sendPeriod = Int32.Parse(Environment.GetEnvironmentVariables()["DateTimeSendPeriod"] as string); logger.DateTimeStampWaitPeriodMillis = sendPeriod; } if (environment.Contains("NeverConnect")) { bool neverConnect = Boolean.Parse(Environment.GetEnvironmentVariables()["NeverConnect"] as string); logger.NeverConnect = neverConnect; } logger.Update(); }
private void buttonStatusUpdate_Click(object sender, EventArgs e) { if (isLoading) { return; } viewAdapter.LogConfig = logConfig; viewAdapter.SaveLogConfig(); CMSLogger.UpdateLogger(); UpdateStatus(); if (CMSLogger.CanCreateLogEvent(false, false, false, "CMSLogBehaviorEvent")) { CMSLogBehaviorEvent logEvent = new CMSLogBehaviorEvent(logConfig); CMSLogger.SendLogEvent(logEvent); } }
private void VideoInputSizesDetermined(System.Drawing.Size [] videoInputSizes) { lock (mutex) { videoDisplay.VideoInputSizeDetermined(videoInputSizes); model.FrameDims = videoInputSizes; if (CMSLogger.CanCreateLogEvent(false, false, false, "CMSLogVideoSizesDeterminedEvent")) { CMSLogVideoSizesDeterminedEvent vidSizesEvent = new CMSLogVideoSizesDeterminedEvent(); if (vidSizesEvent != null) { vidSizesEvent.Sizes = videoInputSizes; CMSLogger.SendLogEvent(vidSizesEvent); } } } }
private void CameraLost(bool containsCameras) { lock (mutex) { if (CMSLogger.CanCreateLogEvent(false, false, false, "CMSLogCameraLostEvent")) { CMSLogCameraLostEvent cameraLostEvent = new CMSLogCameraLostEvent(); if (cameraLostEvent != null) { CMSLogger.SendLogEvent(cameraLostEvent); } } if (!controllerState.Equals(CMSState.CameraNotFound)) { SetState(CMSState.CameraNotFound); if (model.SelectedSuite != null) { model.SelectedSuite.Clean(); } if (containsCameras) { if (videoSource.StartSource()) { model.CurrentMonikor = videoSource.GetCurrentMonikor(); SetState(CMSState.Setup); } else { MessageBox.Show("Camera Lost"); } } else { MessageBox.Show("Camera Lost"); } } else { throw new Exception("Received Camera Lost in state " + controllerState.ToString()); } } }
private void LeftMouseClick(int x, int y) { User32.mouse_event(2, x, y, 0, 0); //Right mouse down at x,y System.Threading.Thread.Sleep(100); User32.mouse_event(4, x, y, 0, 0); //Right mouse up at x,y if (CMSLogger.CanCreateLogEvent(false, false, false, "CMSLogClickEvent")) { CMSLogClickEvent clickEvent = new CMSLogClickEvent(); if (clickEvent != null) { clickEvent.X = x; clickEvent.Y = y; clickEvent.Width = CMSConstants.SCREEN_WIDTH; clickEvent.Height = CMSConstants.SCREEN_HEIGHT; clickEvent.ClickType = ClickType.LClk; CMSLogger.SendLogEvent(clickEvent); } } }
public void UpdateStatus() { bool isConnected = CMSLogger.IsLoggerConnected(); bool isRunning = CMSLogger.IsLoggerRunning(); Exception e = CMSLogger.GetNetworkException(); if (e != null) { labelLogStatusDetails.Text = e.Message; } else { labelLogStatusDetails.Text = ""; } bool neverConnect = false; IDictionary vars = Environment.GetEnvironmentVariables(); if (vars.Contains("NeverConnect")) { neverConnect = Boolean.Parse(vars["NeverConnect"] as string); } if (!isRunning) { labelLogStatus.Text = "System is not Running"; } else if (neverConnect) { labelLogStatus.Text = "System is Running and can never Connect"; } else if (!isConnected) { labelLogStatus.Text = "System is Running, but not Connected"; } else { labelLogStatus.Text = "System is Running and Connected"; } }
public void Start(CMSVideoSource videoSource, CMSVideoDisplay videoDisplay, CMSControlToggler controlToggler) { mutex = new object(); try { ProcessKeys[] procKeysDelegates = null; lock (mutex) { CMSConstants.Init(); controllerState = CMSState.Starting; model = new CMSModel(); model.Init("./" + CMSConstants.SUITE_LIB_DIR, "./" + CMSConstants.SUITE_CONFIG_DIR, "./" + CMSConstants.MAIN_CONFIG_FILE, "./" + CMSConstants.MAIN_CAMERA_CONFIG_FILE, "./" + CMSConstants.MAIN_LOG_CONFIG_FILE, "./" + CMSConstants.MAIN_ID_CONFIG_FILE); model.Load(); model.IncrementAndSaveSessionNum(); CMSLogger.SetUidReceivedDelegate(model.UidUpdated); CMSLogger.Init(model.LogConfig, model.IdConfig); //CMSLogger.CanCreateLogEvent( if (CMSLogger.CanCreateLogEvent(false, false, false, "CMSLogStartEvent")) { CMSLogStartEvent startEvent = new CMSLogStartEvent(); startEvent.SetDateTime(DateTime.Now); CMSLogger.SendLogEvent(startEvent); } this.videoSource = videoSource; videoSource.CameraLost += new CameraLost(CameraLost); videoSource.CameraFound += new CameraFound(CameraFound); videoSource.VideoInputSizesDetermined += new VideoInputSizesDetermined(VideoInputSizesDetermined); videoSource.ProcessFrame += new ProcessFrame(ProcessFrameFromSource); videoSource.Init(videoDisplay.GetParentForm()); this.videoDisplay = videoDisplay; videoDisplay.Init(new CMSViewAdapter(model, this, videoSource)); model.SelectedSuite.CMSTrackingSuiteAdapter = new CMSStandardTrackingSuiteAdapter(model, this, videoDisplay); string currentMoniker = model.CurrentMonikor; if (videoSource.StartSource(currentMoniker)) { string newMoniker = videoSource.GetCurrentMonikor(); model.CurrentMonikor = newMoniker; controllerState = CMSState.Setup; } else { controllerState = CMSState.CameraNotFound; } this.controlToggler = controlToggler; controlToggler.GetState = GetState; controlToggler.ToggleControl = ToggleControl; controlToggler.GetCursorPos = GetCursorPos; controlToggler.ControlTogglerConfig = model.GeneralConfig.ControlTogglerConfig; controlToggler.Start(); procKeysDelegates = new ProcessKeys[2]; procKeysDelegates[0] = ProcessKeys; procKeysDelegates[1] = controlToggler.ProcessKeys; } CMSKeyHook.initHook(procKeysDelegates); Application.Run(videoDisplay.GetParentForm()); CMSKeyHook.removeHook(); } catch (Exception e) { try { if (CMSLogger.CanCreateLogEvent(true, true, false, "CMSLogExceptionEvent")) { CMSLogExceptionEvent exceptionEvent = new CMSLogExceptionEvent(); exceptionEvent.SetException(e); CMSLogger.SendLogEvent(exceptionEvent); } } catch { } MessageBox.Show("Error occurred during startup:" + e.Message); Application.Exit(); } }
public void Init() { CMSLogger.AddLoggerStatusChangeListener(LoggingStatusUpdate); }
public void ProcessFrame(Bitmap [] frames, bool control) { lock (mutex) { PointF imagePoint = PointF.Empty; PointF screenPoint = PointF.Empty; CMSExtraTrackingInfo extraInfo = null; if (trackingModule != null) { trackingModule.Process(frames); imagePoint = trackingModule.ImagePoint; extraInfo = trackingModule.ExtraTrackingInfo; if (!trackingModule.ImagePoint.IsEmpty) { if (CMSLogger.CanCreateLogEvent(true, false, false, "CMSLogPointerEvent")) { CMSLogPointerEvent ptrEvent = new CMSLogPointerEvent(); if (ptrEvent != null) { ptrEvent.X = (int)trackingModule.ImagePoint.X; ptrEvent.Y = (int)trackingModule.ImagePoint.Y; CMSLogger.SendLogEvent(ptrEvent); } } } } if (mouseControlModule != null) { mouseControlModule.ProcessMouse(imagePoint, extraInfo, frames); screenPoint = mouseControlModule.MousePointer; } if (clickControlModule != null) { clickControlModule.ProcessClick(imagePoint, screenPoint, extraInfo, frames); } if (trackingModule != null) { trackingModule.DrawOnFrame(frames); } if (mouseControlModule != null) { mouseControlModule.DrawOnFrame(frames); } if (clickControlModule != null) { clickControlModule.DrawOnFrame(frames); } if (control) { if (CMSLogger.CanCreateLogEvent(true, false, false, "CMSLogCursorEvent")) { CMSLogCursorEvent csrEvent = new CMSLogCursorEvent(); if (csrEvent != null) { csrEvent.X = (int)mouseControlModule.MousePointer.X; csrEvent.Y = (int)mouseControlModule.MousePointer.Y; CMSLogger.SendLogEvent(csrEvent); } } } } }
void ProcessFrameFromSource(System.Drawing.Bitmap [] frames) { lock (mutex) { if (CMSLogger.CanCreateLogEvent(false, false, true, "CMSLogProcessesEvent")) { CMSLogProcessesEvent pEvent = new CMSLogProcessesEvent(); pEvent.CaptureProcesses(); CMSLogger.SendLogEvent(pEvent); } if (!controllerState.Equals(CMSState.CameraNotFound)) { foreach (Bitmap frame in frames) { frame.RotateFlip(RotateFlipType.RotateNoneFlipX); } CMSTrackingSuite currentTracker = model.SelectedSuite; if (currentTracker != null && frames != null && frames.Length > 0) { if (!currentTracker.Initialized) { Size[] sizes = new Size[frames.Length]; for (int i = 0; i < frames.Length; i++) { sizes[i] = new Size(frames[i].Width, frames[i].Height); } currentTracker.Init(sizes); } bool control = controllerState.Equals(CMSState.ControlTracking); /* * CMSLogExperimentFrameEvent logExpFrameEvent = null; * * if (ExperimentFrameSaver.IsExperimentFrameEnabled()) * { * if (ExperimentFrameSaver.CanSaveLogEvent()) * { * logExpFrameEvent = new CMSLogExperimentFrameEvent(frames[0], currentTracker.Name, 0, 0); * } * }*/ currentTracker.ProcessFrame(frames, control); /* * if (logExpFrameEvent != null) * { * if (currentTracker.TrackingModule != null) * { * PointF curPoint = currentTracker.TrackingModule.ImagePoint; * logExpFrameEvent.X = (int)curPoint.X; * logExpFrameEvent.Y = (int)curPoint.Y; * ExperimentFrameSaver.SaveLogEvent(logExpFrameEvent); * } * }*/ if (CMSLogger.CanCreateLogEvent(true, true, false, "CMSLogFrameEvent")) { CMSLogFrameEvent frameEvent = new CMSLogFrameEvent(); if (frameEvent != null) { frameEvent.SetImages(frames); CMSLogger.SendLogEvent(frameEvent); } } } videoDisplay.SetVideo(frames); } } }
public override void Process(System.Drawing.Bitmap [] frames) { Bitmap frame = frames[0]; if (frame == null) { throw new Exception("Frame is null!"); } if (frame.Width != imageSize.Width || frame.Height != imageSize.Height) { throw new Exception("Invalid frame sizes"); } _curFrame.setImage(frame); CvImageWrapper.ConvertImageColor(_curFrame, _grey, ColorConversion.BGR2GRAY); SwapPoints(ref _current_track_points[0], ref _last_track_points[0]); cvCalcOpticalFlowPyrLK(_prev_grey._rawPtr, _grey._rawPtr, _prev_pyramid._rawPtr, _pyramid._rawPtr, _last_track_points, _current_track_points, 1, _pwinsz, 3, _status, null, _criteria, _flowflags); if (validTrackPoint && _status[0] == 0) { if (CMSLogger.CanCreateLogEvent(false, false, false, "CMSLogStandardStateEvent")) { CMSLogStandardStateEvent logEvent = new CMSLogStandardStateEvent(); if (logEvent != null) { logEvent.ValidTrackingPoint = false; CMSLogger.SendLogEvent(logEvent); } } eyeLocatorTickCount = Environment.TickCount; validTrackPoint = false; imagePoint = PointF.Empty; trackingSuiteAdapter.ToggleSetup(true); trackingSuiteAdapter.SendMessage(CMSConstants.PLEASE_CLICK_TF); } LimitTPDelta(ref _current_track_points[0], _last_track_points[0]); //CvPoint2D32f p = _current_track_points[0]; SwapImages(ref _grey, ref _prev_grey); SwapImages(ref _pyramid, ref _prev_pyramid); if (validTrackPoint) { imagePoint.X = _current_track_points[0].x; imagePoint.Y = _current_track_points[0].y; DrawOnFrame(frame); } else { if (!autoStartMode.Equals(AutoStartMode.None)) { long eyeLocatorNewTickCount = Environment.TickCount; if (eyeLocatorNewTickCount - eyeLocatorTickCount > 10000) { if (!autoStartEnded) { trackingSuiteAdapter.SendMessage("Please Blink"); autoStartEnded = true; } eyeLocator.AddImage(frame); if (eyeLocator.TrackingPointsFound) { CvPoint2D32f p = new CvPoint2D32f(); if (autoStartMode.Equals(AutoStartMode.LeftEye)) { p = eyeLocator.LeftEyeTrackingPoint; } else if (autoStartMode.Equals(AutoStartMode.RightEye)) { p = eyeLocator.RightEyeTrackingPoint; } else if (autoStartMode.Equals(AutoStartMode.NoseMouth)) { p = eyeLocator.MouseTrackingPoint; } eyeLocator.Reset(); imagePoint.X = (int)p.x; imagePoint.Y = (int)p.y; _current_track_points[0].x = p.x; _current_track_points[0].y = p.y; _last_track_points[0].x = p.x; _last_track_points[0].y = p.y; validTrackPoint = true; trackingSuiteAdapter.ToggleSetup(false); trackingSuiteAdapter.ToggleControl(true); } } else { autoStartEnded = false; int second = (int)Math.Round(((double)(10000 - (eyeLocatorNewTickCount - eyeLocatorTickCount))) / 1000.0); trackingSuiteAdapter.SendMessage("Auto Start in " + second + " seconds"); } } } }
// Thread entry point public void WorkerThread() { // grabber Grabber grabber = new Grabber(this); // objects object graphObj = null; object sourceObj = null; object grabberObj = null; // interfaces IGraphBuilder graph = null; //IBaseFilter sourceBase = null; IBaseFilter grabberBase = null; ISampleGrabber sg = null; IMediaControl mc = null; try { // Get type for filter graph Type srvType = Type.GetTypeFromCLSID(Clsid.FilterGraph); if (srvType == null) { throw new ApplicationException("Failed creating filter graph"); } // create filter graph graphObj = Activator.CreateInstance(srvType); graph = (IGraphBuilder)graphObj; // ---- UCOMIBindCtx bindCtx = null; UCOMIMoniker moniker = null; int n = 0; // create bind context if (Win32.CreateBindCtx(0, out bindCtx) == 0) { // convert moniker`s string to a moniker if (Win32.MkParseDisplayName(bindCtx, source, ref n, out moniker) == 0) { // get device base filter Guid filterId = typeof(IBaseFilter).GUID; moniker.BindToObject(null, null, ref filterId, out sourceObj); Marshal.ReleaseComObject(moniker); moniker = null; } Marshal.ReleaseComObject(bindCtx); bindCtx = null; } // ---- if (sourceObj == null) { throw new ApplicationException("Failed creating device object for moniker"); } sourceBase = (IBaseFilter)sourceObj; // Get type for sample grabber srvType = Type.GetTypeFromCLSID(Clsid.SampleGrabber); if (srvType == null) { throw new ApplicationException("Failed creating sample grabber"); } // create sample grabber grabberObj = Activator.CreateInstance(srvType); sg = (ISampleGrabber)grabberObj; grabberBase = (IBaseFilter)grabberObj; // add source filter to graph graph.AddFilter(sourceBase, "source"); graph.AddFilter(grabberBase, "grabber"); // set media type AMMediaType mt = new AMMediaType(); mt.majorType = MediaType.Video; mt.subType = MediaSubType.RGB24; sg.SetMediaType(mt); // connect pins if (graph.Connect(DSTools.GetOutPin(sourceBase, 0), DSTools.GetInPin(grabberBase, 0)) < 0) { throw new ApplicationException("Failed connecting filters"); } // get media type if (sg.GetConnectedMediaType(mt) == 0) { // This is where the actual video input info is obtained VideoInfoHeader vih = (VideoInfoHeader)Marshal.PtrToStructure(mt.formatPtr, typeof(VideoInfoHeader)); //System.Diagnostics.Debug.WriteLine("width = " + vih.BmiHeader.Width + ", height = " + vih.BmiHeader.Height); grabber.Width = vih.BmiHeader.Width; grabber.Height = vih.BmiHeader.Height; mt.Dispose(); if (VideoInputSizeDetermined != null) { VideoInputSizeDetermined(this, new Size(vih.BmiHeader.Width, vih.BmiHeader.Height)); } } // render graph.Render(DSTools.GetOutPin(grabberBase, 0)); // sg.SetBufferSamples(false); sg.SetOneShot(false); sg.SetCallback(grabber, 1); // window IVideoWindow win = (IVideoWindow)graphObj; win.put_AutoShow(false); win = null; // get media control mc = (IMediaControl)graphObj; // run mc.Run(); while (!stopEvent.WaitOne(0, true)) { Thread.Sleep(100); } mc.StopWhenReady(); //mc.Stop(); } // catch any exceptions catch (Exception e) { try { if (CMSLogger.CanCreateLogEvent(true, true, false, "CMSLogExceptionEvent")) { CMSLogExceptionEvent exceptionEvent = new CMSLogExceptionEvent(); exceptionEvent.SetException(e); CMSLogger.SendLogEvent(exceptionEvent); } } catch { } } // finalization block finally { // release all objects mc = null; graph = null; sourceBase = null; grabberBase = null; sg = null; if (graphObj != null) { Marshal.ReleaseComObject(graphObj); graphObj = null; } if (sourceObj != null) { Marshal.ReleaseComObject(sourceObj); sourceObj = null; } if (grabberObj != null) { Marshal.ReleaseComObject(grabberObj); grabberObj = null; } } }