public frmVideoSettings(VideoCapability vc, frmAVDevices frmAV) { InitializeComponent(); Debug.Assert(vc != null); Debug.Assert(vc.VideoCaptureGraph != null); Debug.Assert(frmAV != null); this.vc = vc; this.vcg = vc.VideoCaptureGraph; this.frmAV = frmAV; }
private void cklbCameras_ItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e) { if(e.NewValue == CheckState.Checked) { // We only support one device at a time for this sample UncheckAllDevices(); // CF1 Select camera // CF2 Initialize - Create filter and internal graph vcg = new VideoCaptureGraph((FilterInfo)cklbCameras.SelectedItem); vcg.RenderLocal(); // CF3 Connect all the filters VideoWindow(); // CF4 Set video window (if you like) vcg.Run(); // CF5 Start graph -> Show video } else // Unchecked { Cleanup(); } }
/// <summary> /// Creates the actual FilgraphManager with the chosen camera /// </summary> private void CreateVideoGraph(FilterInfo fi) { Debug.Assert(vcg == null); // Create the graph, which creates the source filter cg = new VideoCaptureGraph(fi); Log(vcg.VideoSource.Dump()); }
// CF2 private void DisposeDevice() { if(vcg != null) { vcg.Stop(); vcg.Dispose(); vcg = null; } }
// CF2 (with some changes for network) private void cklbCameras_ItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e) { if(e.NewValue == CheckState.Checked) { UncheckAllDevices(); vcg = new VideoCaptureGraph((FilterInfo)cklbCameras.SelectedItem); // Create filter and internal graph vcg.RenderNetwork(rtpSender); // Add network filter, connect all filters vcg.Run(); // Send data to network } else // Unchecked { DisposeDevice(); } }
private void Cleanup() { if(vcg != null) { vcg.Dispose(); // CF6 Dispose device when done (clean up internal filtergraph) vcg = null; // This shouldn't be necessary, but there seems to be some kind // of outstanding reference count that is taken care of here GC.Collect(); } }
/// <summary> /// Creates the actual FilgraphManager with the chosen camera /// </summary> private void CreateVideoGraph(FilterInfo fi) { Debug.Assert(cg == null); // Create the graph, which creates the source filter if (DVSource.IsDVSourceWithAudio(fi)) { cg = DVCaptureGraph.GetInstance(fi); Log(((DVCaptureGraph)cg).VideoSource.Dump()); } else { cg = new VideoCaptureGraph(fi); Log(((VideoCaptureGraph)cg).VideoSource.Dump()); } }
private void DeactivateVideoCapability(FilterInfo fi) { RenderAndRunVideo(vcg, false); vcg = null; VideoCapability vc = (VideoCapability)vcs[fi]; vcs.Remove(fi); vc.DeactivateCamera(); }
// CF2 (with some changes for network) private void cklbCameras_ItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e) { if(e.NewValue == CheckState.Checked) { UncheckAllDevices(); // Create the graph for the device vcg = new VideoCaptureGraph((FilterInfo)cklbCameras.SelectedItem); // Add a compressor and configure it vcg.AddCompressor(VideoCompressor.DefaultFilterInfo()); vcg.VideoCompressor.QualityInfo = VideoCompressor.DefaultQualityInfo; // Add network filter vcg.RenderNetwork(rtpSender); // Send data to network vcg.Run(); } else // Unchecked { DisposeDevice(); } }
private void clbCameras_SelectedIndexChanged(object sender, System.EventArgs e) { try { ClearVideoBox(); vc = (VideoCapability)vcs[(FilterInfo)clbCameras.SelectedItem]; vcg = vc != null ? vc.VideoCaptureGraph : null; if(clbCameras.GetItemChecked(clbCameras.SelectedIndex)) { UpdateVideoBox(); } } catch(COMException ex) { Log(DShowError._AMGetErrorText(ex.ErrorCode)); Log(ex.ToString()); } catch(Exception ex) { Log(ex.ToString()); } }
private void ActivateVideoCapability(FilterInfo fi) { Debug.Assert(!vcs.Contains(fi)); vc = new VideoCapability(fi); vcs.Add(fi, vc); vc.SetLogger(new AVLogger(Log)); vc.ActivateCamera(); vcg = vc.VideoCaptureGraph; RenderAndRunVideo(vcg); }
public void RenderAndRunVideo(VideoCaptureGraph vcg, bool playIt) { if(playIt) { Log("Playing video (render and run graph) - " + vcg.Source.FriendlyName); vcg.RenderLocal(); VideoCapability.DisableDXVA(vcg.FilgraphManager); // Set device name in the video window and turn off the system menu IVideoWindow iVW = (IVideoWindow)vcg.FilgraphManager; iVW.Caption = vcg.Source.FriendlyName; iVW.WindowStyle &= ~0x00080000; // WS_SYSMENU vcg.Run(); } else { Log("Stop video (stop and unrender graph) - " + vcg.Source.FriendlyName); vcg.Stop(); vcg.RemoveRenderer(); // I have no idea why the video window stays up but this fixes it GC.Collect(); } Log(FilterGraph.Debug(vcg.IFilterGraph)); }
public void RenderAndRunVideo(VideoCaptureGraph vcg) { RenderAndRunVideo(vcg, ckPlayVideo.Checked); }
private void MDShowInteropForm_Load(object sender, System.EventArgs e) { this.Text = Strings.DirectShowSample; // CF1 Add video devices to UI foreach (FilterInfo fi in VideoSource.Sources()) { cklbCameras.Items.Add(fi); } vcg = new VideoCaptureGraph(VideoSource.Sources()[0]); vcg.RenderLocal(); // CF3 Connect all the filters VideoWindow(); // CF4 Set video window (if you like) vcg.Run(); }