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)); }
/// <summary> /// Restore the camera's last settings from the registry /// </summary> private void RestoreCameraSettings() { object setting; if (cg is VideoCaptureGraph) { VideoCaptureGraph vcg = (VideoCaptureGraph)cg; if (vcg.VideoSource.HasVideoStandards) { if ((setting = AVReg.ReadValue(DeviceKey(), AVReg.VideoStandardIndex)) != null) { vcg.VideoSource.VideoStandardIndex = (int)setting; } } } else if (cg is DVCaptureGraph) { DVCaptureGraph dvcg = (DVCaptureGraph)cg; if (dvcg.VideoSource.HasVideoStandards) { if ((setting = AVReg.ReadValue(DeviceKey(), AVReg.VideoStandardIndex)) != null) { dvcg.VideoSource.VideoStandardIndex = (int)setting; } } } if (cg.Source.HasPhysConns) { if ((setting = AVReg.ReadValue(DeviceKey(), AVReg.PhysicalConnectorIndex)) != null) { cg.Source.PhysicalConnectorIndex = (int)setting; } } }
/// <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; } }
private void DeactivateVideoCapability(FilterInfo fi) { RenderAndRunVideo(vcg, false); vcg = null; VideoCapability vc = (VideoCapability)vcs[fi]; vcs.Remove(fi); vc.DeactivateCamera(); }
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(); } }
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 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); }
// 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(); } }
/// <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()); } }
/// <summary> /// Shows the form's camera configuration dialog /// </summary> public void ShowCameraConfiguration() { if (cg is VideoCaptureGraph) { VideoCaptureGraph vcg = (VideoCaptureGraph)cg; if (vcg.VideoSource.IsVfw) { RtlAwareMessageBox.Show(null, Strings.CanNotConfigureCamera, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0); return; } if (cg != null && vcg.VideoSource.HasSourceDialog) { vcg.VideoSource.ShowSourceDialog(form.Handle); } } }
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> /// Save the camera's current settings to the registry /// </summary> public void SaveCameraSettings() { if (cg is VideoCaptureGraph) { VideoCaptureGraph vcg = (VideoCaptureGraph)cg; if (vcg.VideoSource.HasVideoStandards) { AVReg.WriteValue(DeviceKey(), AVReg.VideoStandardIndex, vcg.VideoSource.VideoStandardIndex); } } else if (cg is DVCaptureGraph) { DVCaptureGraph dvcg = (DVCaptureGraph)cg; if (dvcg.VideoSource.HasVideoStandards) //Always false for DV devices? { AVReg.WriteValue(DeviceKey(), AVReg.VideoStandardIndex, dvcg.VideoSource.VideoStandardIndex); } } SaveDeviceSettings(); }
// 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()); } }
public void RenderAndRunVideo(VideoCaptureGraph vcg) { RenderAndRunVideo(vcg, ckPlayVideo.Checked); }