private void OnGrabberDocked(Dock port, Grabber grabber) { if(port == output && outputOverflow != null) { grabber.Dispatch(outputOverflow, port); outputOverflow = null; } else if(inputA.DockedGrabbers.Count > 0 && inputB.DockedGrabbers.Count > 0 && output.DockedGrabbers.Count > 0) { Crate inCrateA = inputA.DockedGrabbers[0].HeldCrate; Crate inCrateB = inputB.DockedGrabbers[0].HeldCrate; int featuresMoved = Mathf.Min (Crate.MaxFeatures - inCrateA.Features.Count, inCrateB.Features.Count); for(int i = 0; i < featuresMoved; i++) { inCrateA.Features.Add(inCrateB.Features[i]); } if(featuresMoved < inCrateB.Features.Count) { inCrateB.Features.RemoveRange (0, featuresMoved); outputOverflow = inCrateB; } inputA.DockedGrabbers[0].Dispatch(null, inputA); inputB.DockedGrabbers[0].Dispatch(null, inputB); output.DockedGrabbers[0].Dispatch(inCrateA, output); } }
void GrabberDocked(Dock dock, Grabber grabber) { if (grabber.HeldCrate == null) { Quantity--; grabber.Dispatch(new Crate(Crate), dock); } }
public void DestroyGrabInstance(Grabber grabber) { GrabInstance gi = grabInstances.Find(item => item.grabber.Equals(grabber)); if (gi != null) { DestroyGrabInstance(gi); } }
public virtual void OnTriggerStay(Collider c) { Grabber grabber = c.gameObject.GetComponent <Grabber>(); if (grabber != null && !grabbersToKeep.Contains(grabber)) { grabbersToKeep.AddLast(grabber); } }
private void Start() { personAnimator = GetComponent <PersonAnimator>(); move = GetComponent <MoveTo>(); grabber = GetComponent <Grabber>(); grabber.HoldOffset = holdOffset; grabber.SortingOffset = heldSortingOffset; }
private void OnRelease(Grabber grabber) { EnableGrabPoint(false); for (int i = 0; i < grabbedItens.Count; i++) { grabbedItens[i].rigidbody.isKinematic = false; } }
public ServerManager(ILogger <ServerManager> logger, Grabber grabber, FFmpegAsProcess transcoder) { _grabber = grabber; _transcoder = transcoder; _logger = logger; TranscoderCache = _transcoder.TranscoderCache; CheckTranscodingCache().Start(); _logger.LogInformation($"{nameof(ServerManager)} initialized"); }
public override void PickUp(Grabber picker) { base.PickUp(picker); AttachToPicker(picker); // calling any events connected to this box pickup OnPickUp(); }
private void FaceMonitoring(object sender, EventArgs e) { try { // Get the current frame form capture device CurrentFrame = Grabber.QueryFrame().Resize(320, 240, INTER.CV_INTER_CUBIC); //Video.Serve(CurrentFrame.Bytes); //System.Diagnostics.Debug.Print(Convert.ToBase64String(CurrentFrame.Bytes)); // Convert it to Grayscale Gray = CurrentFrame.Convert <Gray, byte>(); // Face Detector MCvAvgComp[][] facesDetected = Gray.DetectHaarCascade(Face, 1.2, 10, HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(20, 20)); if (facesDetected == null) { return; } // Action for each element detected foreach (MCvAvgComp face in facesDetected[0]) { Result = CurrentFrame.Copy(face.rect).Convert <Gray, byte>().Resize(100, 100, INTER.CV_INTER_CUBIC); // Draw the face detected in the 0th (gray) channel with blue color CurrentFrame.Draw(face.rect, new Bgr(Color.Red), 2); // Check if there is trained images to find a match if (TrainingImages.ToArray().Length != 0) { var eigenDistanceThreshold = 3000; var eps = 0.001; // TermCriteria for face recognition with numbers of trained images like maxIteration MCvTermCriteria termCrit = new MCvTermCriteria(TrainedFacesCounter, eps); // Eigen face recognizer FaceRecognitionEngine recognizer = new FaceRecognitionEngine(TrainingImages.ToArray(), LabelList.ToArray(), eigenDistanceThreshold, ref termCrit); var imgLabel = recognizer.Recognize(Result); LogStats($"{imgLabel} - Recognized"); // Draw the label for each face detected and recognized // CurrentFrame.Draw(imgLabel, ref Font, new Point(face.rect.X - 2, face.rect.Y - 2), new Bgr(Color.White)); MethodInvoker inv = delegate { lblLabelName.Text = imgLabel.Replace("_", " ").ToUpper(); }; Invoke(inv); } } // Show the face procesed and recognized imageBoxFrameGrabber.Image = CurrentFrame; } catch { } }
public void GetMetaInfoTest() { // Prepare var mock = new Mock <ICommandRunner>(); Options options = new Options() { SubpathToTrunk = "subpath", IncludeMetaData = true, NoBranches = false, NoTags = false, RootIsTrunk = false, Exclude = new List <string>() { "ex1", "ex2" }, Tags = new List <string>() { "tag1", "tag2" }, Branches = new List <string>() { "branch1", "branch2" } }; var standardOutput = "*branch1"; mock.Setup(f => f.Run("git", "branch -l --no-color", out standardOutput)) .Returns(0); standardOutput = "svn/tags/branch2"; mock.Setup(f => f.Run("git", "branch -r --no-color", out standardOutput)) .Returns(0); IGrabber grabber = new Grabber(_testSvnUrl, options, mock.Object, "", null, null); // Act grabber.FetchBranches(); var actual = grabber.GetMetaInfo(); // Assert Assert.Equal(new List <string>() { "svn/tags/branch2" }, actual.Tags); Assert.Equal(new List <string>() { "branch1" }, actual.LocalBranches); Assert.Equal(new List <string>() { "svn/tags/branch2" }, actual.RemoteBranches); }
private void OnEnable() { grill = Gameplay_Manager.Instance.grill; player = Gameplay_Manager.Instance.player.GetComponentInChildren <Grabber>(); initPos = transform.position; SelectNewTarget(); }
// Use this for initialization void Start() { sender = GetComponent <RayCastSender>(); avatar = GetComponentInParent <OvrAvatar>(); grabber = GetComponentInParent <Grabber>(); otherToggler = GetComponentInParent <ToggleRayCastOnGrabbable>(); controller = marker.controller; ConnectController(controller); }
private void OnTriggerEnter(Collider other) { if (other.GetComponent <Grabber>()) { Debug.LogError("Trigger grabber"); currentHand = other.GetComponent <Grabber>(); ControllerButtonHints.ShowButtonHint(currentHand, testction); } }
public void Released() { transform.parent = null; ReferenceOffset.parent = transform; Collider.isTrigger = wasTrigger; Rigidbody.isKinematic = wasKinematic; Rigidbody.useGravity = usedGravity; CurrentGrabber = null; }
public virtual void OnGrab(Grabber grabber) { // Child this object to the grabber transform.SetParent(grabber.transform); // Turn off physics // Was: GetComponent<Rigidbody>().useGravity = false; rigidBody.useGravity = false; rigidBody.isKinematic = true; }
public GrabInstance Grab(Grabber grabber, GrabZone grabZone) { GrabInstance grabInstance = grabZone.gameObject.AddComponent <GrabInstance>(); grabInstance.Init(this, grabber, grabZone); grabInstance.OnGrabButtonReleased += Instance_GrabButtonReleased; grabInstances.Add(grabInstance); CreateGrabHandler(grabInstance); return(grabInstance); }
void Start() { gameAreaCollider = GetComponent <BoxCollider>(); grabber = FindObjectOfType <Grabber>(); BlocksOutsidePlayArea = new List <Block>(); state = TurnState.START; gameStateText.text = "Game Starting"; currentBlockInPlay = null; StartCoroutine(StartFirstRound()); }
public virtual void PickUp(Grabber picker) { // cannot be picked up more than once if (IsPickedUp) { return; } IsPickedUp = true; }
public virtual void GrabEnd(Vector3 linearVelocity, Vector3 angularVelocity) { Rigidbody rb = gameObject.GetComponent <Rigidbody>(); rb.isKinematic = _grabbedKinematic; rb.velocity = linearVelocity; rb.angularVelocity = angularVelocity; _grabbedBy = null; _grabbedCollider = null; }
void Start() { LeftGrabber = GameObject.Find("LeftController").GetComponentInChildren <Grabber>(); gitLeft = LeftGrabber.GetComponent <GrabbablesInTrigger>(); RightGrabber = GameObject.Find("RightController").GetComponentInChildren <Grabber>(); gitRight = RightGrabber.GetComponent <GrabbablesInTrigger>(); requestedGrabbables = new Dictionary <int, double>(); }
/// <summary> /// Callback function to release a controller if already registered /// </summary> /// <param name="c"></param> /// <param name="e"></param> public virtual void ReleaseController(Grabber g, ControllerComponentArgs e) { if (activeGrabbers.Contains(g)) { activeGrabbers.Remove(g); //c.SendHapticEvent(1, 1, 0.5f); OnReleaseController(g); } IsGrabbed = false; }
protected override void OnPickup(Grabber who, GameObject root) { base.OnPickup(who, root); var model = root.GetComponentInChildren <PGIModel>(); if (model != null) { model.Pickup(GetComponent <PGISlotItem>()); } }
StateData(OVRPlayerController OVRPlayer, OVRInput.Controller hand, OVRInput.Controller hand2, Grabber grabber, PocketInventoryManager pocketInventory, CanvasInventoryManager canvasInventory, FileBrowserMenu fileBrowser) { this.OVRPlayer = OVRPlayer; this.hand = hand; this.hand2 = hand2; this.grabber = grabber; this.pocketInventory = pocketInventory; this.canvasInventory = canvasInventory; this.fileBrowser = fileBrowser; }
private void Start() { move = GetComponent <MoveTo>(); grabber = GetComponent <Grabber>(); grabber.HoldOffset = holdOffset; grabber.HoldRotation = holdRotation; grabber.SortingOffset = heldSortingOffset; grabber.SpriteWillFlip = heldSpriteWillFlip; }
public void ChangeCollisionDetectionfItem(Grabber item, bool enable) { for (int i = 0; i < colliders.Length; i++) { for (int j = 0; j < item.colliders.Length; j++) { Physics.IgnoreCollision(colliders[i], item.colliders[j], enable); } } }
public void OnDrop(Grabber hand) { handedness = Handedness.None; myHand = null; hand.grabbedTransform = null; rb.isKinematic = false; transform.parent = null; onSpecialDrop?.Invoke(); }
public new OptionsElement[] InterfaceElement() { return(new OptionsElement[] { new OptionsCheckbox(FeatureName, (bool)Value, value => Value = value), new OptionsCheckbox("Auto Harvest Flowers on the 28th", Flowers, value => { Flowers = value; Grabber.Update(); }) }); }
void Start() { if (VRManager.IsVREnabled()) { Destroy(this); return; } grabHandler = GetComponent <AGrabHandler>(); grabber = FindObjectOfType <Grabber>(); }
IEnumerator GoUp() { while (Grabber.GetComponent <DistanceJoint2D>().distance >= GrabberYInit) { Grabber.GetComponent <DistanceJoint2D>().distance -= 0.1f; yield return(new WaitForSeconds(0.01f)); } isup = true; GetComponent <AudioSource>().Stop(); //StopCoroutine(GoUp()); }
void Start() { _attack = GetComponent <Attack>(); timeToConsiderHeld = .7f; heldComplete = false; _movement = GetComponent <Movement>(); _jump = GetComponent <Jump>(); _grab = GetComponent <Grabber>(); _throw = GetComponent <Throw>(); _motor = GetComponent <PlayerMotor>(); }
public virtual void OnEndDrag(PointerEventData eventData) { if (m_eventGrabberSet == null) { return; } Grabber grabber; if (!m_eventGrabberSet.TryGetValue(eventData, out grabber)) { return; } RemoveGrabber(grabber); m_eventGrabberSet.Remove(eventData); Grabber.Release(grabber); }
public virtual void OnTriggerEnter(Collider c) { Grabber grabber = c.gameObject.GetComponent <Grabber>(); if (grabber != null && !potentialGrabbers.Contains(grabber)) { potentialGrabbers.AddLast(grabber); grabber.AddGrippable(this); } }
private void Awake() { manager = GameObject.Find("Manager").GetComponent <GameManager>(); grabObj = GameObject.FindGameObjectWithTag("Grabber").GetComponent <Grabber>(); controls = new PlayerControls(); controls.Gameplay.Shoot.performed += ctx => Shoot(); controls.Gameplay.Aim_RS.performed += ctx => aim = ctx.ReadValue <Vector2>(); controls.Gameplay.Aim_RS.canceled += ctx => aim = Vector2.zero; }
public VideoCaptureDevice() { fDesiredWidth = -1; fDesiredHeight = -1; fGrabber = new Grabber(); fGrabber.NewMediaBuffer += OnNewBuffer; fVideoCapsList = null; AcquireInterfaces(); }
void GrabberDocked(Dock dock, Grabber grabber) { if (grabber.HeldCrate != null && grabber.HeldCrate.Features.Count == Crate.Features.Count) { for (int i = 0; i < grabber.HeldCrate.Features.Count; i++) { if (grabber.HeldCrate.Features[i] != Crate.Features[i]) { return; } } Quantity--; grabber.Dispatch(null, dock); } }
public void Grabbed(Grabber pGrabber) { _OriginalWorldPos = transform.position; _OriginalWorldOri = transform.rotation; ReferenceOffset.parent = null; transform.parent = ReferenceOffset; ReferenceOffset.parent = pGrabber.GrabPoint; ReferenceOffset.localPosition = Vector3.zero; ReferenceOffset.localRotation = Quaternion.identity; wasTrigger = Collider.isTrigger; wasKinematic = Rigidbody.isKinematic; usedGravity = Rigidbody.useGravity; Rigidbody.useGravity = false; Rigidbody.isKinematic = true; Collider.isTrigger = true; CurrentGrabber = pGrabber; }
public void Process(Dock port, Grabber grabber) { Crate crate = grabber.HeldCrate; bool match = true; if(crate.Features.Count == filter.Features.Count) { for(int i = 0; i < crate.Features.Count; i++) { if(crate.Features[i] != filter.Features[i]) { match = false; } } } else { match = false; } if(match) { grabber.Dispatch(null, port); } }
private void OnGrabberDocked(Dock port, Grabber grabber) { if(input.DockedGrabbers.Count > 0 && outputSingle.DockedGrabbers.Count > 0 && (input.DockedGrabbers[0].HeldCrate.Features.Count == 1 || outputRemainder.DockedGrabbers.Count > 0)) { Crate inCrate = input.DockedGrabbers[0].HeldCrate; if(inCrate.Features.Count == 1) { outputSingle.DockedGrabbers[0].Dispatch(inCrate, outputSingle); input.DockedGrabbers[0].Dispatch(null, input); } else { Crate single = new Crate(); int last = inCrate.Features.Count - 1; single.Features = new List<CrateFeature>(){inCrate.Features[last]}; inCrate.Features.RemoveAt (last); input.DockedGrabbers[0].Dispatch(null, input); outputSingle.DockedGrabbers[0].Dispatch(single, outputSingle); outputRemainder.DockedGrabbers[0].Dispatch(inCrate, outputRemainder); } } }
// 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) { 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(); } // 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(); } // catch any exceptions catch (Exception e) { System.Diagnostics.Debug.WriteLine("----: " + e.Message); } // 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; } } }
private void WorkerThread( bool runGraph ) { ReasonToFinishPlaying reasonToStop = ReasonToFinishPlaying.StoppedByUser; bool isSapshotSupported = false; // grabber Grabber videoGrabber = new Grabber( this, false ); Grabber snapshotGrabber = new Grabber( this, true ); // objects object captureGraphObject = null; object graphObject = null; object videoGrabberObject = null; object snapshotGrabberObject = null; object crossbarObject = null; // interfaces ICaptureGraphBuilder2 captureGraph = null; IFilterGraph2 graph = null; IBaseFilter sourceBase = null; IBaseFilter videoGrabberBase = null; IBaseFilter snapshotGrabberBase = null; ISampleGrabber videoSampleGrabber = null; ISampleGrabber snapshotSampleGrabber = null; IMediaControl mediaControl = null; IAMVideoControl videoControl = null; IMediaEventEx mediaEvent = null; IPin pinStillImage = null; IAMCrossbar crossbar = null; try { // get type of capture graph builder Type type = Type.GetTypeFromCLSID( Clsid.CaptureGraphBuilder2 ); if ( type == null ) throw new ApplicationException( "Failed creating capture graph builder" ); // create capture graph builder captureGraphObject = Activator.CreateInstance( type ); captureGraph = (ICaptureGraphBuilder2) captureGraphObject; // get type of filter graph type = Type.GetTypeFromCLSID( Clsid.FilterGraph ); if ( type == null ) throw new ApplicationException( "Failed creating filter graph" ); // create filter graph graphObject = Activator.CreateInstance( type ); graph = (IFilterGraph2) graphObject; // set filter graph to the capture graph builder captureGraph.SetFiltergraph( (IGraphBuilder) graph ); // create source device's object sourceObject = FilterInfo.CreateFilter( deviceMoniker ); if ( sourceObject == null ) throw new ApplicationException( "Failed creating device object for moniker" ); // get base filter interface of source device sourceBase = (IBaseFilter) sourceObject; // get video control interface of the device try { videoControl = (IAMVideoControl) sourceObject; } catch { // some camera drivers may not support IAMVideoControl interface } // get type of sample grabber type = Type.GetTypeFromCLSID( Clsid.SampleGrabber ); if ( type == null ) throw new ApplicationException( "Failed creating sample grabber" ); // create sample grabber used for video capture videoGrabberObject = Activator.CreateInstance( type ); videoSampleGrabber = (ISampleGrabber) videoGrabberObject; videoGrabberBase = (IBaseFilter) videoGrabberObject; // create sample grabber used for snapshot capture snapshotGrabberObject = Activator.CreateInstance( type ); snapshotSampleGrabber = (ISampleGrabber) snapshotGrabberObject; snapshotGrabberBase = (IBaseFilter) snapshotGrabberObject; // add source and grabber filters to graph graph.AddFilter( sourceBase, "source" ); graph.AddFilter( videoGrabberBase, "grabber_video" ); graph.AddFilter( snapshotGrabberBase, "grabber_snapshot" ); // set media type AMMediaType mediaType = new AMMediaType( ); mediaType.MajorType = MediaType.Video; mediaType.SubType = MediaSubType.RGB24; videoSampleGrabber.SetMediaType( mediaType ); snapshotSampleGrabber.SetMediaType( mediaType ); // get crossbar object to to allows configuring pins of capture card captureGraph.FindInterface( FindDirection.UpstreamOnly, Guid.Empty, sourceBase, typeof( IAMCrossbar ).GUID, out crossbarObject ); if ( crossbarObject != null ) { crossbar = (IAMCrossbar) crossbarObject; } isCrossbarAvailable = ( crossbar != null ); crossbarVideoInputs = ColletCrossbarVideoInputs( crossbar ); if ( videoControl != null ) { // find Still Image output pin of the vedio device captureGraph.FindPin( sourceObject, PinDirection.Output, PinCategory.StillImage, MediaType.Video, false, 0, out pinStillImage ); // check if it support trigger mode if ( pinStillImage != null ) { VideoControlFlags caps; videoControl.GetCaps( pinStillImage, out caps ); isSapshotSupported = ( ( caps & VideoControlFlags.ExternalTriggerEnable ) != 0 ); } } // configure video sample grabber videoSampleGrabber.SetBufferSamples( false ); videoSampleGrabber.SetOneShot( false ); videoSampleGrabber.SetCallback( videoGrabber, 1 ); // configure snapshot sample grabber snapshotSampleGrabber.SetBufferSamples( true ); snapshotSampleGrabber.SetOneShot( false ); snapshotSampleGrabber.SetCallback( snapshotGrabber, 1 ); // configure pins GetPinCapabilitiesAndConfigureSizeAndRate( captureGraph, sourceBase, PinCategory.Capture, desiredFrameSize, desiredFrameRate, ref videoCapabilities ); if ( isSapshotSupported ) { GetPinCapabilitiesAndConfigureSizeAndRate( captureGraph, sourceBase, PinCategory.StillImage, desiredSnapshotSize, 0, ref snapshotCapabilities ); } else { snapshotCapabilities = new VideoCapabilities[0]; } // put video/snapshot capabilities into cache lock ( cacheVideoCapabilities ) { if ( ( videoCapabilities != null ) && ( !cacheVideoCapabilities.ContainsKey( deviceMoniker ) ) ) { cacheVideoCapabilities.Add( deviceMoniker, videoCapabilities ); } } lock ( cacheSnapshotCapabilities ) { if ( ( snapshotCapabilities != null ) && ( !cacheSnapshotCapabilities.ContainsKey( deviceMoniker ) ) ) { cacheSnapshotCapabilities.Add( deviceMoniker, snapshotCapabilities ); } } if ( runGraph ) { // render capture pin captureGraph.RenderStream( PinCategory.Capture, MediaType.Video, sourceBase, null, videoGrabberBase ); if ( videoSampleGrabber.GetConnectedMediaType( mediaType ) == 0 ) { VideoInfoHeader vih = (VideoInfoHeader) Marshal.PtrToStructure( mediaType.FormatPtr, typeof( VideoInfoHeader ) ); videoGrabber.Width = vih.BmiHeader.Width; videoGrabber.Height = vih.BmiHeader.Height; mediaType.Dispose( ); } if ( ( isSapshotSupported ) && ( provideSnapshots ) ) { // render snapshot pin captureGraph.RenderStream( PinCategory.StillImage, MediaType.Video, sourceBase, null, snapshotGrabberBase ); if ( snapshotSampleGrabber.GetConnectedMediaType( mediaType ) == 0 ) { VideoInfoHeader vih = (VideoInfoHeader) Marshal.PtrToStructure( mediaType.FormatPtr, typeof( VideoInfoHeader ) ); snapshotGrabber.Width = vih.BmiHeader.Width; snapshotGrabber.Height = vih.BmiHeader.Height; mediaType.Dispose( ); } } // get media control mediaControl = (IMediaControl) graphObject; // get media events' interface mediaEvent = (IMediaEventEx) graphObject; IntPtr p1, p2; DsEvCode code; // run mediaControl.Run( ); if ( ( isSapshotSupported ) && ( provideSnapshots ) ) { startTime = DateTime.Now; videoControl.SetMode( pinStillImage, VideoControlFlags.ExternalTriggerEnable ); } do { if ( mediaEvent != null ) { if ( mediaEvent.GetEvent( out code, out p1, out p2, 0 ) >= 0 ) { mediaEvent.FreeEventParams( code, p1, p2 ); if ( code == DsEvCode.DeviceLost ) { reasonToStop = ReasonToFinishPlaying.DeviceLost; break; } } } if ( needToSetVideoInput ) { needToSetVideoInput = false; // set/check current input type of a video card (frame grabber) if ( isCrossbarAvailable.Value ) { SetCurrentCrossbarInput( crossbar, crossbarVideoInput ); crossbarVideoInput = GetCurrentCrossbarInput( crossbar ); } } if ( needToSimulateTrigger ) { needToSimulateTrigger = false; if ( ( isSapshotSupported ) && ( provideSnapshots ) ) { videoControl.SetMode( pinStillImage, VideoControlFlags.Trigger ); } } if ( needToDisplayPropertyPage ) { needToDisplayPropertyPage = false; DisplayPropertyPage( parentWindowForPropertyPage, sourceObject ); if ( crossbar != null ) { crossbarVideoInput = GetCurrentCrossbarInput( crossbar ); } } if ( needToDisplayCrossBarPropertyPage ) { needToDisplayCrossBarPropertyPage = false; if ( crossbar != null ) { DisplayPropertyPage( parentWindowForPropertyPage, crossbar ); crossbarVideoInput = GetCurrentCrossbarInput( crossbar ); } } } while ( !stopEvent.WaitOne( 100, false ) ); mediaControl.Stop( ); } } catch ( Exception exception ) { // provide information to clients if ( VideoSourceError != null ) { VideoSourceError( this, new VideoSourceErrorEventArgs( exception.Message ) ); } } finally { // release all objects captureGraph = null; graph = null; sourceBase = null; mediaControl = null; videoControl = null; mediaEvent = null; pinStillImage = null; crossbar = null; videoGrabberBase = null; snapshotGrabberBase = null; videoSampleGrabber = null; snapshotSampleGrabber = null; if ( graphObject != null ) { Marshal.ReleaseComObject( graphObject ); graphObject = null; } if ( sourceObject != null ) { Marshal.ReleaseComObject( sourceObject ); sourceObject = null; } if ( videoGrabberObject != null ) { Marshal.ReleaseComObject( videoGrabberObject ); videoGrabberObject = null; } if ( snapshotGrabberObject != null ) { Marshal.ReleaseComObject( snapshotGrabberObject ); snapshotGrabberObject = null; } if ( captureGraphObject != null ) { Marshal.ReleaseComObject( captureGraphObject ); captureGraphObject = null; } if ( crossbarObject != null ) { Marshal.ReleaseComObject( crossbarObject ); crossbarObject = null; } } if ( PlayingFinished != null ) { PlayingFinished( this, reasonToStop ); } }
public void Init() { rubbishItem = GetRubbishItem("Rubbish Item"); toolGrabber = new Grabber(); grabber = new Grabber(); }
void Start() { // // foreach (DraggableInstruction draggableInstruction in draggableInstructions) // { // draggableInstruction.button.IsDraggable = GameManager.instance.gameState == GameManager.State.Construction; // } // foreach (EmptyInstructionSlot emptyInstructionSlot in emptyInstructions) // { // emptyInstructionSlot.button.IsDraggable = GameManager.instance.gameState == GameManager.State.Construction; // } // }; emptyInstructions = new EmptyInstructionSlot[Grabber.maximumInstuctions]; for (int i = 0 ; i < Grabber.maximumInstuctions ; i++) { emptyInstructions[i] = ObjectPoolManager.GetObject(emptyInstructionPrefab); emptyInstructions[i].gameObject.name = "Instruction "+i; emptyInstructions[i].transform.parent = emptyInstructionsRoot.transform; emptyInstructions[i].transform.localPosition = Vector3.zero + (Vector3.down*60f*i); emptyInstructions[i].instructionIndex = i; emptyInstructions[i].draggableInstructions = draggableInstructions.ConvertAll<DraggableInstruction>( (di) => { var clone = di.GetClone(); clone.transform.parent = emptyInstructions[i].transform; clone.transform.localPosition = Vector3.zero - Vector3.forward; SetupDragDropBehaviour(clone); clone.occupiedSlot = emptyInstructions[i]; return clone; }); emptyInstructions[i].CurrentInstruction = Grabber.Instruction.None; } InputManager.instance.OnSelectionChange += (selectedPlacables) => { if (!LevelEditorGUI.hasActiveInstance && selectedPlacables.Count == 1 && selectedPlacables[0] is Grabber) { selectedGrabber = selectedPlacables[0] as Grabber; RefreshEmptyInstructions(); } else { HideUI(); } }; selectionIcon.transform.localScale = Vector3.zero; LevelManager.instance.GameStateChangedEvent += () => { selectionIcon.transform.localScale = Vector3.one*(LevelManager.instance.gameState == LevelManager.State.Construction ? 0f : 1f); }; LevelManager.instance.InstructionStartedEvent += () => { // Debug.LogWarning("Instruction Step!"); if (selectedGrabber != null) { selectionIcon.transform.localPosition = new Vector3(0, -60*selectedGrabber.InstructionCounter, 0); } }; foreach (var db in draggableInstructions) SetupDragDropBehaviour(db); HideUI(); }
// Thread entry point public void WorkerThread() { bool failed = false; // 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; IFileSourceFilter fileSource = null; IMediaControl mc = null; IMediaEventEx mediaEvent = null; int code, param1, param2; while ((!failed) && (!stopEvent.WaitOne(0, true))) { 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; // Get type for windows media source filter srvType = Type.GetTypeFromCLSID(Clsid.WindowsMediaSource); if (srvType == null) throw new ApplicationException("Failed creating WM source"); // create windows media source filter sourceObj = Activator.CreateInstance(srvType); 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); // load file fileSource = (IFileSourceFilter) sourceObj; fileSource.Load(this.source, null); // 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) { VideoInfoHeader vih = (VideoInfoHeader) Marshal.PtrToStructure(mt.formatPtr, typeof(VideoInfoHeader)); grabber.Width = vih.BmiHeader.Width; grabber.Height = vih.BmiHeader.Height; mt.Dispose(); } // 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 events interface mediaEvent = (IMediaEventEx) graphObj; // get media control mc = (IMediaControl) graphObj; // run mc.Run(); while (!stopEvent.WaitOne(0, true)) { Thread.Sleep(100); // get an event if (mediaEvent.GetEvent(out code, out param1, out param2, 0) == 0) { // release params mediaEvent.FreeEventParams(code, param1, param2); // if (code == (int) EventCode.Complete) { break; } } } mc.StopWhenReady(); } // catch any exceptions catch (Exception e) { System.Diagnostics.Debug.WriteLine("----: " + e.Message); failed = true; } // finalization block finally { // release all objects mediaEvent = null; mc = null; fileSource = 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; } } } }
private void WorkerThread(bool runGraph) { VideoSourceFinishedReasonType reasonToStop = VideoSourceFinishedReasonType.StoppedByUser; bool isSapshotSupported = false; // grabber Grabber videoGrabber = new Grabber(this, false); Grabber snapshotGrabber = new Grabber(this, true); // objects object captureGraphObject = null; object graphObject = null; object videoGrabberObject = null; object snapshotGrabberObject = null; // interfaces ICaptureGraphBuilder2 captureGraph = null; IFilterGraph2 graph = null; IBaseFilter sourceBase = null; IBaseFilter videoGrabberBase = null; IBaseFilter snapshotGrabberBase = null; ISampleGrabber videoSampleGrabber = null; ISampleGrabber snapshotSampleGrabber = null; IMediaControl mediaControl = null; IAMVideoControl videoControl = null; IMediaEventEx mediaEvent = null; IPin pinStillImage = null; try { // get type of capture graph builder Type type = Type.GetTypeFromCLSID(Clsid.CaptureGraphBuilder2); if (type == null) throw new ApplicationException("Failed creating capture graph builder"); // create capture graph builder captureGraphObject = Activator.CreateInstance(type); captureGraph = (ICaptureGraphBuilder2)captureGraphObject; // get type of filter graph type = Type.GetTypeFromCLSID(Clsid.FilterGraph); if (type == null) throw new ApplicationException("Failed creating filter graph"); // create filter graph graphObject = Activator.CreateInstance(type); graph = (IFilterGraph2)graphObject; // set filter graph to the capture graph builder captureGraph.SetFiltergraph((IGraphBuilder)graph); // create source device's object sourceObject = FilterInfo.CreateFilter(deviceMoniker); if (sourceObject == null) throw new ApplicationException("Failed creating device object for moniker"); // get base filter interface of source device sourceBase = (IBaseFilter)sourceObject; // get video control interface of the device try { videoControl = (IAMVideoControl)sourceObject; } catch { // some camera drivers may not support IAMVideoControl interface } // get type of sample grabber type = Type.GetTypeFromCLSID(Clsid.SampleGrabber); if (type == null) throw new ApplicationException("Failed creating sample grabber"); // create sample grabber used for video capture videoGrabberObject = Activator.CreateInstance(type); videoSampleGrabber = (ISampleGrabber)videoGrabberObject; videoGrabberBase = (IBaseFilter)videoGrabberObject; // create sample grabber used for snapshot capture snapshotGrabberObject = Activator.CreateInstance(type); snapshotSampleGrabber = (ISampleGrabber)snapshotGrabberObject; snapshotGrabberBase = (IBaseFilter)snapshotGrabberObject; // add source and grabber filters to graph graph.AddFilter(sourceBase, "source"); graph.AddFilter(videoGrabberBase, "grabber_video"); graph.AddFilter(snapshotGrabberBase, "grabber_snapshot"); // set media type AMMediaType mediaType = new AMMediaType(); mediaType.MajorType = MediaType.Video; mediaType.SubType = MediaSubType.RGB24; videoSampleGrabber.SetMediaType(mediaType); snapshotSampleGrabber.SetMediaType(mediaType); if (videoControl != null) { // find Still Image output pin of the vedio device captureGraph.FindPin(sourceObject, PinDirection.Output, PinCategory.StillImage, MediaType.Video, false, 0, out pinStillImage); // check if it support trigger mode if (pinStillImage != null) { VideoControlFlags caps; videoControl.GetCaps(pinStillImage, out caps); isSapshotSupported = ((caps & VideoControlFlags.ExternalTriggerEnable) != 0); } } // configure video sample grabber videoSampleGrabber.SetBufferSamples(false); videoSampleGrabber.SetOneShot(false); videoSampleGrabber.SetCallback(videoGrabber, 1); // configure snapshot sample grabber snapshotSampleGrabber.SetBufferSamples(true); snapshotSampleGrabber.SetOneShot(false); snapshotSampleGrabber.SetCallback(snapshotGrabber, 1); // configure pins GetPinCapabilitiesAndConfigureSizeAndRate(captureGraph, sourceBase, PinCategory.Capture, desiredFrameSize, desiredFrameRate, ref videoCapabilities); if (isSapshotSupported) { GetPinCapabilitiesAndConfigureSizeAndRate(captureGraph, sourceBase, PinCategory.StillImage, desiredSnapshotSize, 0, ref snapshotCapabilities); } else { snapshotCapabilities = new VideoCapabilities[0]; } if (runGraph) { // render capture pin captureGraph.RenderStream(PinCategory.Capture, MediaType.Video, sourceBase, null, videoGrabberBase); if (videoSampleGrabber.GetConnectedMediaType(mediaType) == 0) { VideoInfoHeader vih = (VideoInfoHeader)Marshal.PtrToStructure(mediaType.FormatPtr, typeof(VideoInfoHeader)); videoGrabber.Width = vih.BmiHeader.Width; videoGrabber.Height = vih.BmiHeader.Height; mediaType.Dispose(); } if ((isSapshotSupported) && (provideSnapshots)) { // render snapshot pin captureGraph.RenderStream(PinCategory.StillImage, MediaType.Video, sourceBase, null, snapshotGrabberBase); if (snapshotSampleGrabber.GetConnectedMediaType(mediaType) == 0) { VideoInfoHeader vih = (VideoInfoHeader)Marshal.PtrToStructure(mediaType.FormatPtr, typeof(VideoInfoHeader)); snapshotGrabber.Width = vih.BmiHeader.Width; snapshotGrabber.Height = vih.BmiHeader.Height; mediaType.Dispose(); } } // get media control mediaControl = (IMediaControl)graphObject; // get media events' interface mediaEvent = (IMediaEventEx)graphObject; IntPtr p1, p2; DsEvCode code; // run mediaControl.Run(); if ((isSapshotSupported) && (provideSnapshots)) { startTime = DateTime.Now; videoControl.SetMode(pinStillImage, VideoControlFlags.ExternalTriggerEnable); } while (!stopEvent.WaitOne(0, false)) { Thread.Sleep(100); if (mediaEvent != null) { if (mediaEvent.GetEvent(out code, out p1, out p2, 0) >= 0) { mediaEvent.FreeEventParams(code, p1, p2); if (code == DsEvCode.DeviceLost) { reasonToStop = VideoSourceFinishedReasonType.DeviceLost; break; } } } if (needToSimulateTrigger) { needToSimulateTrigger = false; if ((isSapshotSupported) && (provideSnapshots)) { videoControl.SetMode(pinStillImage, VideoControlFlags.Trigger); } } if (needToDisplayPropertyPage) { needToDisplayPropertyPage = false; try { // retrieve ISpecifyPropertyPages interface of the device ISpecifyPropertyPages pPropPages = (ISpecifyPropertyPages)sourceObject; // get property pages from the property bag CAUUID caGUID; pPropPages.GetPages(out caGUID); // get filter info FilterInfo filterInfo = new FilterInfo(deviceMoniker); // create and display the OlePropertyFrame Win32.OleCreatePropertyFrame(parentWindowForPropertyPage, 0, 0, filterInfo.Name, 1, ref sourceObject, caGUID.cElems, caGUID.pElems, 0, 0, IntPtr.Zero); // release COM objects Marshal.FreeCoTaskMem(caGUID.pElems); } catch { } } } mediaControl.Stop(); } } catch (Exception exception) { // provide information to clients if (VideoSourceException != null) { VideoSourceException(this, new VideoSourceExceptionEventArgs(exception.Message)); } } finally { // release all objects captureGraph = null; graph = null; sourceBase = null; mediaControl = null; videoControl = null; mediaEvent = null; pinStillImage = null; videoGrabberBase = null; snapshotGrabberBase = null; videoSampleGrabber = null; snapshotSampleGrabber = null; if (graphObject != null) { Marshal.ReleaseComObject(graphObject); graphObject = null; } if (sourceObject != null) { Marshal.ReleaseComObject(sourceObject); sourceObject = null; } if (videoGrabberObject != null) { Marshal.ReleaseComObject(videoGrabberObject); videoGrabberObject = null; } if (snapshotGrabberObject != null) { Marshal.ReleaseComObject(snapshotGrabberObject); snapshotGrabberObject = null; } if (captureGraphObject != null) { Marshal.ReleaseComObject(captureGraphObject); captureGraphObject = null; } } if (VideoSourceFinished != null) { VideoSourceFinished(this, new VideoSourceFinishedEventArgs(reasonToStop)); } }
private void WorkerThread( bool runGraph ) { // grabber Grabber grabber = new Grabber( this ); // objects object captureGraphObject = null; object graphObject = null; object grabberObject = null; // interfaces ICaptureGraphBuilder2 captureGraph = null; IFilterGraph2 graph = null; IBaseFilter sourceBase = null; IBaseFilter grabberBase = null; ISampleGrabber sampleGrabber = null; IMediaControl mediaControl = null; try { // get type of capture graph builder Type type = Type.GetTypeFromCLSID( Clsid.CaptureGraphBuilder2 ); if ( type == null ) throw new ApplicationException( "Failed creating capture graph builder" ); // create capture graph builder captureGraphObject = Activator.CreateInstance( type ); captureGraph = (ICaptureGraphBuilder2) captureGraphObject; // get type of filter graph type = Type.GetTypeFromCLSID( Clsid.FilterGraph ); if ( type == null ) throw new ApplicationException( "Failed creating filter graph" ); // create filter graph graphObject = Activator.CreateInstance( type ); graph = (IFilterGraph2) graphObject; // set filter graph to the capture graph builder captureGraph.SetFiltergraph( (IGraphBuilder) graph ); // create source device's object sourceObject = FilterInfo.CreateFilter( deviceMoniker ); if ( sourceObject == null ) throw new ApplicationException( "Failed creating device object for moniker" ); // get base filter interface of source device sourceBase = (IBaseFilter) sourceObject; // get type of sample grabber type = Type.GetTypeFromCLSID( Clsid.SampleGrabber ); if ( type == null ) throw new ApplicationException( "Failed creating sample grabber" ); // create sample grabber grabberObject = Activator.CreateInstance( type ); sampleGrabber = (ISampleGrabber) grabberObject; grabberBase = (IBaseFilter) grabberObject; // add source and grabber filters to graph graph.AddFilter( sourceBase, "source" ); graph.AddFilter( grabberBase, "grabber" ); // set media type AMMediaType mediaType = new AMMediaType( ); mediaType.MajorType = MediaType.Video; mediaType.SubType = MediaSubType.RGB24; sampleGrabber.SetMediaType( mediaType ); // configure sample grabber sampleGrabber.SetBufferSamples( false ); sampleGrabber.SetOneShot( false ); sampleGrabber.SetCallback( grabber, 1 ); // check if it is required to change capture settings if ( ( desiredFrameRate != 0 ) || ( ( desiredFrameSize.Width != 0 ) && ( desiredFrameSize.Height != 0 ) ) ) { object streamConfigObject; // get stream configuration object captureGraph.FindInterface( PinCategory.Capture, MediaType.Video, sourceBase, typeof( IAMStreamConfig ).GUID, out streamConfigObject ); if ( streamConfigObject != null ) { IAMStreamConfig streamConfig = (IAMStreamConfig) streamConfigObject; if ( videoCapabilities == null ) { // get all video capabilities try { videoCapabilities = AForge.Video.DirectShow.VideoCapabilities.FromStreamConfig( streamConfig ); } catch { } } // get current format streamConfig.GetFormat( out mediaType ); VideoInfoHeader infoHeader = (VideoInfoHeader) Marshal.PtrToStructure( mediaType.FormatPtr, typeof( VideoInfoHeader ) ); // change frame size if required if ( ( desiredFrameSize.Width != 0 ) && ( desiredFrameSize.Height != 0 ) ) { infoHeader.BmiHeader.Width = desiredFrameSize.Width; infoHeader.BmiHeader.Height = desiredFrameSize.Height; } // change frame rate if required if ( desiredFrameRate != 0 ) { infoHeader.AverageTimePerFrame = 10000000 / desiredFrameRate; } // copy the media structure back Marshal.StructureToPtr( infoHeader, mediaType.FormatPtr, false ); // set the new format streamConfig.SetFormat( mediaType ); mediaType.Dispose( ); } } else { if ( videoCapabilities == null ) { object streamConfigObject; // get stream configuration object captureGraph.FindInterface( PinCategory.Capture, MediaType.Video, sourceBase, typeof( IAMStreamConfig ).GUID, out streamConfigObject ); if ( streamConfigObject != null ) { IAMStreamConfig streamConfig = (IAMStreamConfig) streamConfigObject; // get all video capabilities try { videoCapabilities = AForge.Video.DirectShow.VideoCapabilities.FromStreamConfig( streamConfig ); } catch { } } } } if ( runGraph ) { // render source device on sample grabber captureGraph.RenderStream( PinCategory.Capture, MediaType.Video, sourceBase, null, grabberBase ); // get media type if ( sampleGrabber.GetConnectedMediaType( mediaType ) == 0 ) { VideoInfoHeader vih = (VideoInfoHeader) Marshal.PtrToStructure( mediaType.FormatPtr, typeof( VideoInfoHeader ) ); grabber.Width = vih.BmiHeader.Width; grabber.Height = vih.BmiHeader.Height; mediaType.Dispose( ); } // get media control mediaControl = (IMediaControl) graphObject; // run mediaControl.Run( ); while ( !stopEvent.WaitOne( 0, true ) ) { Thread.Sleep( 100 ); if ( needToDisplayPropertyPage ) { needToDisplayPropertyPage = false; try { // retrieve ISpecifyPropertyPages interface of the device ISpecifyPropertyPages pPropPages = (ISpecifyPropertyPages) sourceObject; // get property pages from the property bag CAUUID caGUID; pPropPages.GetPages( out caGUID ); // get filter info FilterInfo filterInfo = new FilterInfo( deviceMoniker ); // create and display the OlePropertyFrame Win32.OleCreatePropertyFrame( parentWindowForPropertyPage, 0, 0, filterInfo.Name, 1, ref sourceObject, caGUID.cElems, caGUID.pElems, 0, 0, IntPtr.Zero ); // release COM objects Marshal.FreeCoTaskMem( caGUID.pElems ); } catch { } } } mediaControl.StopWhenReady( ); } } catch ( Exception exception ) { // provide information to clients if ( VideoSourceError != null ) { VideoSourceError( this, new VideoSourceErrorEventArgs( exception.Message ) ); } } finally { // release all objects captureGraph = null; graph = null; sourceBase = null; grabberBase = null; sampleGrabber = null; mediaControl = null; if ( graphObject != null ) { Marshal.ReleaseComObject( graphObject ); graphObject = null; } if ( sourceObject != null ) { Marshal.ReleaseComObject( sourceObject ); sourceObject = null; } if ( grabberObject != null ) { Marshal.ReleaseComObject( grabberObject ); grabberObject = null; } if ( captureGraphObject != null ) { Marshal.ReleaseComObject( captureGraphObject ); captureGraphObject = null; } } if ( PlayingFinished != null ) { PlayingFinished( this, ReasonToFinishPlaying.StoppedByUser ); } }
//Todo: This could explode if grabber can round-trip in one time step public void Process(Dock port, Grabber grabber) { if(inPort.DockedGrabbers.Count > 0 && outPort.DockedGrabbers.Count > 0) { Grabber inGrabber = inPort.DockedGrabbers[0]; Grabber outGrabber = outPort.DockedGrabbers[0]; Crate crate = inGrabber.HeldCrate; DoMatchReplace(crate); outGrabber.Dispatch(crate, outPort); inGrabber.Dispatch(null, inPort); } }
/// <summary> /// Worker thread. /// </summary> /// private void WorkerThread( ) { ReasonToFinishPlaying reasonToStop = ReasonToFinishPlaying.StoppedByUser; // grabber Grabber grabber = new Grabber( this ); // objects object graphObject = null; object grabberObject = null; // interfaces IGraphBuilder graph = null; IBaseFilter sourceBase = null; IBaseFilter grabberBase = null; ISampleGrabber sampleGrabber = null; IMediaControl mediaControl = null; IMediaEventEx mediaEvent = null; try { // get type for filter graph Type type = Type.GetTypeFromCLSID( Clsid.FilterGraph ); if ( type == null ) throw new ApplicationException( "Failed creating filter graph" ); // create filter graph graphObject = Activator.CreateInstance( type ); graph = (IGraphBuilder) graphObject; // create source device's object graph.AddSourceFilter( fileName, "source", out sourceBase ); if ( sourceBase == null ) throw new ApplicationException( "Failed creating source filter" ); // get type for sample grabber type = Type.GetTypeFromCLSID( Clsid.SampleGrabber ); if ( type == null ) throw new ApplicationException( "Failed creating sample grabber" ); // create sample grabber grabberObject = Activator.CreateInstance( type ); sampleGrabber = (ISampleGrabber) grabberObject; grabberBase = (IBaseFilter) grabberObject; // add grabber filters to graph graph.AddFilter( grabberBase, "grabber" ); // set media type AMMediaType mediaType = new AMMediaType( ); mediaType.MajorType = MediaType.Video; mediaType.SubType = MediaSubType.RGB24; sampleGrabber.SetMediaType( mediaType ); // connect pins int pinToTry = 0; IPin inPin = Tools.GetInPin( grabberBase, 0 ); IPin outPin = null; // find output pin acceptable by sample grabber while ( true ) { outPin = Tools.GetOutPin( sourceBase, pinToTry ); if ( outPin == null ) { Marshal.ReleaseComObject( inPin ); throw new ApplicationException( "Did not find acceptable output video pin in the given source" ); } if ( graph.Connect( outPin, inPin ) < 0 ) { Marshal.ReleaseComObject( outPin ); outPin = null; pinToTry++; } else { break; } } Marshal.ReleaseComObject( outPin ); Marshal.ReleaseComObject( inPin ); // get media type if ( sampleGrabber.GetConnectedMediaType( mediaType ) == 0 ) { VideoInfoHeader vih = (VideoInfoHeader) Marshal.PtrToStructure( mediaType.FormatPtr, typeof( VideoInfoHeader ) ); grabber.Width = vih.BmiHeader.Width; grabber.Height = vih.BmiHeader.Height; mediaType.Dispose( ); } // let's do rendering, if we don't need to prevent freezing if ( !preventFreezing ) { // render pin graph.Render( Tools.GetOutPin( grabberBase, 0 ) ); // configure video window IVideoWindow window = (IVideoWindow) graphObject; window.put_AutoShow( false ); window = null; } // configure sample grabber sampleGrabber.SetBufferSamples( false ); sampleGrabber.SetOneShot( false ); sampleGrabber.SetCallback( grabber, 1 ); // disable clock, if someone requested it if ( !referenceClockEnabled ) { IMediaFilter mediaFilter = (IMediaFilter) graphObject; mediaFilter.SetSyncSource( null ); } // get media control mediaControl = (IMediaControl) graphObject; // get media events' interface mediaEvent = (IMediaEventEx) graphObject; IntPtr p1, p2; DsEvCode code; // run mediaControl.Run( ); do { if ( mediaEvent != null ) { if ( mediaEvent.GetEvent( out code, out p1, out p2, 0 ) >= 0 ) { mediaEvent.FreeEventParams( code, p1, p2 ); if ( code == DsEvCode.Complete ) { reasonToStop = ReasonToFinishPlaying.EndOfStreamReached; break; } } } } while ( !stopEvent.WaitOne( 100, false ) ); mediaControl.Stop( ); } catch ( Exception exception ) { // provide information to clients if ( VideoSourceError != null ) { VideoSourceError( this, new VideoSourceErrorEventArgs( exception.Message ) ); } } finally { // release all objects graph = null; grabberBase = null; sampleGrabber = null; mediaControl = null; mediaEvent = null; if ( graphObject != null ) { Marshal.ReleaseComObject( graphObject ); graphObject = null; } if ( sourceBase != null ) { Marshal.ReleaseComObject( sourceBase ); sourceBase = null; } if ( grabberObject != null ) { Marshal.ReleaseComObject( grabberObject ); grabberObject = null; } } if ( PlayingFinished != null ) { PlayingFinished( this, reasonToStop ); } }
public void UndockGrabber(Grabber grabber) { dockedGrabbers.Remove(grabber); if(OnGrabberUndocked != null) { OnGrabberUndocked(this, grabber); } }
public void DockGrabber(Grabber grabber) { dockedGrabbers.Add(grabber); if(OnGrabberDocked != null){ OnGrabberDocked(this, grabber); } }
public void Process(Dock port, Grabber grabber) { grabber.Dispatch(null, port); }
public void TestAddTool() { Assert.Null(player1.CurrentTool); Assert.That(player1.Tools.Count == 0); Tool grabber1 = new Grabber(); player1.AddTool(grabber1); Assert.NotNull(player1.CurrentTool); Assert.That(player1.Tools.Count == 1); Assert.That(player1.CurrentTool == grabber1); }
private void Process(Dock port, Grabber grabber) { grabber.Dispatch(new Crate(Production), port); }
public void AddGrabber() { Grabber newGrabber = new Grabber(this, Simulation); newGrabber.Pipe = this; grabbers.Add (newGrabber);; }
// Thread entry point public void WorkerThread() { int hr; Guid cat; Guid med; // grabber Grabber grabber = new Grabber(this); // objects object graphObj = null; object grabberObj = null; // interfaces IGraphBuilder graphBuilder = null; ICaptureGraphBuilder2 captureGraphBuilder = null; IBaseFilter videoDeviceFilter = null; IBaseFilter grabberFilter = null; ISampleGrabber sg = null; IMediaControl mc = null; try { // Make a new filter graph graphObj = Activator.CreateInstance( Type.GetTypeFromCLSID(Clsid.FilterGraph, true)); graphBuilder = (IGraphBuilder)graphObj; // Get the Capture Graph Builder Guid clsid = Clsid.CaptureGraphBuilder2; Guid riid = typeof(ICaptureGraphBuilder2).GUID; captureGraphBuilder = (ICaptureGraphBuilder2) TempFix.CreateDsInstance(ref clsid, ref riid); // Link the CaptureGraphBuilder to the filter graph hr = captureGraphBuilder.SetFiltergraph(graphBuilder); if (hr < 0) Marshal.ThrowExceptionForHR(hr); // Get the video device and add it to the filter graph if (source != null) { videoDeviceFilter = (IBaseFilter) Marshal.BindToMoniker(source); hr = graphBuilder.AddFilter(videoDeviceFilter, "Video Capture Device"); if (hr < 0) Marshal.ThrowExceptionForHR(hr); } // create sample grabber, object and filter grabberObj = Activator.CreateInstance( Type.GetTypeFromCLSID(Clsid.SampleGrabber, true)); grabberFilter = (IBaseFilter)grabberObj; sg = (ISampleGrabber)grabberObj; // add sample grabber filter to filter graph hr = graphBuilder.AddFilter(grabberFilter, "grabber"); if (hr < 0) Marshal.ThrowExceptionForHR(hr); // Try looking for an video device interleaved media type IBaseFilter testFilter = videoDeviceFilter; // grabberFilter (not supported) object o; cat = PinCategory.Capture; med = MediaType.Interleaved; Guid iid = typeof(IAMStreamConfig).GUID; hr = captureGraphBuilder.FindInterface( ref cat, ref med, testFilter, ref iid, out o); if (hr != 0) { // If not found, try looking for a video media type med = MediaType.Video; hr = captureGraphBuilder.FindInterface( ref cat, ref med, testFilter, ref iid, out o); if (hr != 0) o = null; } // Set the video stream configuration to data member videoStreamConfig = o as IAMStreamConfig; o = null; // Experimental testing: Try to set the Frame Size & Rate // Results: When enabled, the grabber video breaks up into // several duplicate frames (6 frames) bool bdebug = true; if (bdebug) { BitmapInfoHeader bmiHeader; bmiHeader = (BitmapInfoHeader) getStreamConfigSetting(videoStreamConfig, "BmiHeader"); bmiHeader.Width = framesize.Width; bmiHeader.Height = framesize.Height; setStreamConfigSetting(videoStreamConfig, "BmiHeader", bmiHeader); long avgTimePerFrame = (long)(10000000 / framerate); setStreamConfigSetting(videoStreamConfig, "AvgTimePerFrame", avgTimePerFrame); } // connect pins (Turns on the video device) if (graphBuilder.Connect(DSTools.GetOutPin( videoDeviceFilter, 0), DSTools.GetInPin(grabberFilter, 0)) < 0) throw new ApplicationException( "Failed connecting filters"); // Set the sample grabber media type settings AMMediaType mt = new AMMediaType(); mt.majorType = MediaType.Video; mt.subType = MediaSubType.RGB24; sg.SetMediaType(mt); // get media type if (sg.GetConnectedMediaType(mt) == 0) { 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(); } // render graphBuilder.Render(DSTools.GetOutPin(grabberFilter, 0)); // Set various sample grabber properties sg.SetBufferSamples(false); sg.SetOneShot(false); sg.SetCallback(grabber, 1); // Do not show active (source) 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(); } // catch any exceptions catch (Exception e) { System.Diagnostics.Debug.WriteLine("----: " + e.Message); } // finalization block finally { // release all objects mc = null; graphBuilder = null; captureGraphBuilder = null; videoDeviceFilter = null; grabberFilter = null; sg = null; if (graphObj != null) { Marshal.ReleaseComObject(graphObj); graphObj = null; } if (grabberObj != null) { Marshal.ReleaseComObject(grabberObj); grabberObj = null; } } }