// Token: 0x0600003F RID: 63 RVA: 0x00002D24 File Offset: 0x00000F24 private void WorkerThread(bool runGraph) { ReasonToFinishPlaying reason = ReasonToFinishPlaying.StoppedByUser; bool flag = false; VideoCaptureDevice.Grabber grabber = new VideoCaptureDevice.Grabber(this, false); VideoCaptureDevice.Grabber grabber2 = new VideoCaptureDevice.Grabber(this, true); object obj = null; object obj2 = null; object obj3 = null; object obj4 = null; object obj5 = null; ICaptureGraphBuilder2 captureGraphBuilder = null; IFilterGraph2 filterGraph = null; IBaseFilter baseFilter = null; IBaseFilter baseFilter2 = null; IBaseFilter baseFilter3 = null; ISampleGrabber sampleGrabber = null; ISampleGrabber sampleGrabber2 = null; IAMVideoControl iamvideoControl = null; IPin pin = null; IAMCrossbar iamcrossbar = null; try { Type typeFromCLSID = Type.GetTypeFromCLSID(Clsid.CaptureGraphBuilder2); if (typeFromCLSID == null) { throw new ApplicationException("Failed creating capture graph builder"); } obj = Activator.CreateInstance(typeFromCLSID); captureGraphBuilder = (ICaptureGraphBuilder2)obj; Type typeFromCLSID2 = Type.GetTypeFromCLSID(Clsid.FilterGraph); if (typeFromCLSID2 == null) { throw new ApplicationException("Failed creating filter graph"); } obj2 = Activator.CreateInstance(typeFromCLSID2); filterGraph = (IFilterGraph2)obj2; captureGraphBuilder.SetFiltergraph((IGraphBuilder)filterGraph); this.sourceObject1 = FilterInfo.CreateFilter(this.deviceMoniker1); if (this.sourceObject1 == null) { throw new ApplicationException("Failed creating device object for moniker"); } baseFilter = (IBaseFilter)this.sourceObject1; try { iamvideoControl = (IAMVideoControl)this.sourceObject1; } catch { } Type typeFromCLSID3 = Type.GetTypeFromCLSID(Clsid.SampleGrabber); if (typeFromCLSID3 == null) { throw new ApplicationException("Failed creating sample grabber"); } obj3 = Activator.CreateInstance(typeFromCLSID3); sampleGrabber = (ISampleGrabber)obj3; baseFilter2 = (IBaseFilter)obj3; obj4 = Activator.CreateInstance(typeFromCLSID3); sampleGrabber2 = (ISampleGrabber)obj4; baseFilter3 = (IBaseFilter)obj4; filterGraph.AddFilter(baseFilter, "source"); filterGraph.AddFilter(baseFilter2, "grabber_video"); filterGraph.AddFilter(baseFilter3, "grabber_snapshot"); AMMediaType ammediaType = new AMMediaType(); ammediaType.MajorType = MediaType.Video1; ammediaType.SubType = MediaSubType.RGB24; sampleGrabber.SetMediaType(ammediaType); sampleGrabber2.SetMediaType(ammediaType); captureGraphBuilder.FindInterface(FindDirection.UpstreamOnly, Guid.Empty, baseFilter, typeof(IAMCrossbar).GUID, out obj5); if (obj5 != null) { iamcrossbar = (IAMCrossbar)obj5; } this.isCrossbarAvailable1 = new bool?(iamcrossbar != null); this.crossbarVideoInputs1 = this.ColletCrossbarVideoInputs(iamcrossbar); if (iamvideoControl != null) { captureGraphBuilder.FindPin(this.sourceObject1, PinDirection.Output, PinCategory.StillImage, MediaType.Video1, false, 0, out pin); if (pin != null) { VideoControlFlags videoControlFlags; iamvideoControl.GetCaps(pin, out videoControlFlags); flag = ((videoControlFlags & VideoControlFlags.ExternalTriggerEnable) > (VideoControlFlags)0); } } sampleGrabber.SetBufferSamples(false); sampleGrabber.SetOneShot(false); sampleGrabber.SetCallback(grabber, 1); sampleGrabber2.SetBufferSamples(true); sampleGrabber2.SetOneShot(false); sampleGrabber2.SetCallback(grabber2, 1); this.GetPinCapabilitiesAndConfigureSizeAndRate(captureGraphBuilder, baseFilter, PinCategory.Capture, this.videoResolution1, ref this.videoCapabilities1); if (flag) { this.GetPinCapabilitiesAndConfigureSizeAndRate(captureGraphBuilder, baseFilter, PinCategory.StillImage, this.snapshotResolution1, ref this.snapshotCapabilities1); } else { this.snapshotCapabilities1 = new VideoCapabilities[0]; } Dictionary <string, VideoCapabilities[]> obj6 = VideoCaptureDevice.cacheVideoCapabilities1; lock (obj6) { if (this.videoCapabilities1 != null && !VideoCaptureDevice.cacheVideoCapabilities1.ContainsKey(this.deviceMoniker1)) { VideoCaptureDevice.cacheVideoCapabilities1.Add(this.deviceMoniker1, this.videoCapabilities1); } } obj6 = VideoCaptureDevice.cacheSnapshotCapabilities1; lock (obj6) { if (this.snapshotCapabilities1 != null && !VideoCaptureDevice.cacheSnapshotCapabilities1.ContainsKey(this.deviceMoniker1)) { VideoCaptureDevice.cacheSnapshotCapabilities1.Add(this.deviceMoniker1, this.snapshotCapabilities1); } } if (runGraph) { captureGraphBuilder.RenderStream(PinCategory.Capture, MediaType.Video1, baseFilter, null, baseFilter2); if (sampleGrabber.GetConnectedMediaType(ammediaType) == 0) { VideoInfoHeader videoInfoHeader = (VideoInfoHeader)Marshal.PtrToStructure(ammediaType.FormatPtr, typeof(VideoInfoHeader)); grabber.Width = videoInfoHeader.BmiHeader.Width; grabber.Height = videoInfoHeader.BmiHeader.Height; ammediaType.Dispose(); } if (flag && this.provideSnapshots1) { captureGraphBuilder.RenderStream(PinCategory.StillImage, MediaType.Video1, baseFilter, null, baseFilter3); if (sampleGrabber2.GetConnectedMediaType(ammediaType) == 0) { VideoInfoHeader videoInfoHeader2 = (VideoInfoHeader)Marshal.PtrToStructure(ammediaType.FormatPtr, typeof(VideoInfoHeader)); grabber2.Width = videoInfoHeader2.BmiHeader.Width; grabber2.Height = videoInfoHeader2.BmiHeader.Height; ammediaType.Dispose(); } } IMediaControl mediaControl = (IMediaControl)obj2; IMediaEventEx mediaEventEx = (IMediaEventEx)obj2; mediaControl.Run(); if (flag && this.provideSnapshots1) { this.startTime1 = DateTime.Now; iamvideoControl.SetMode(pin, VideoControlFlags.ExternalTriggerEnable); } for (;;) { DsEvCode dsEvCode; IntPtr lParam; IntPtr lParam2; if (mediaEventEx != null && mediaEventEx.GetEvent(out dsEvCode, out lParam, out lParam2, 0) >= 0) { mediaEventEx.FreeEventParams(dsEvCode, lParam, lParam2); if (dsEvCode == DsEvCode.DeviceLost) { break; } } if (this.needToSetVideoInput1) { this.needToSetVideoInput1 = false; if (this.isCrossbarAvailable1.Value) { this.SetCurrentCrossbarInput(iamcrossbar, this.crossbarVideoInput1); this.crossbarVideoInput1 = this.GetCurrentCrossbarInput(iamcrossbar); } } if (this.needToSimulateTrigger1) { this.needToSimulateTrigger1 = false; if (flag && this.provideSnapshots1) { iamvideoControl.SetMode(pin, VideoControlFlags.Trigger); } } if (this.needToDisplayPropertyPage1) { this.needToDisplayPropertyPage1 = false; this.DisplayPropertyPage(this.parentWindowForPropertyPage1, this.sourceObject1); if (iamcrossbar != null) { this.crossbarVideoInput1 = this.GetCurrentCrossbarInput(iamcrossbar); } } if (this.needToDisplayCrossBarPropertyPage1) { this.needToDisplayCrossBarPropertyPage1 = false; if (iamcrossbar != null) { this.DisplayPropertyPage(this.parentWindowForPropertyPage1, iamcrossbar); this.crossbarVideoInput1 = this.GetCurrentCrossbarInput(iamcrossbar); } } if (this.stopEvent1.WaitOne(100, false)) { goto IL_54E; } } reason = ReasonToFinishPlaying.DeviceLost; IL_54E: mediaControl.Stop1(); } } catch (Exception ex) { if (this.VideoSourceError != null) { this.VideoSourceError(this, new VideoSourceErrorEventArgs(ex.Message)); } } finally { captureGraphBuilder = null; filterGraph = null; baseFilter = null; iamvideoControl = null; pin = null; iamcrossbar = null; baseFilter2 = null; baseFilter3 = null; sampleGrabber = null; sampleGrabber2 = null; if (obj2 != null) { Marshal.ReleaseComObject(obj2); obj2 = null; } if (this.sourceObject1 != null) { Marshal.ReleaseComObject(this.sourceObject1); this.sourceObject1 = null; } if (obj3 != null) { Marshal.ReleaseComObject(obj3); obj3 = null; } if (obj4 != null) { Marshal.ReleaseComObject(obj4); obj4 = null; } if (obj != null) { Marshal.ReleaseComObject(obj); obj = null; } if (obj5 != null) { Marshal.ReleaseComObject(obj5); obj5 = null; } } if (this.PlayingFinished != null) { this.PlayingFinished(this, reason); } }