private async Task init() { var lselectedNode = m_FileFormatComboBox.SelectedItem as XmlNode; if (lselectedNode == null) { return; } var lSelectedAttr = lselectedNode.Attributes["Value"]; if (lSelectedAttr == null) { return; } String limageSourceDir = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); SaveFileDialog lsaveFileDialog = new SaveFileDialog(); lsaveFileDialog.InitialDirectory = limageSourceDir; lsaveFileDialog.DefaultExt = "." + lSelectedAttr.Value.ToLower(); lsaveFileDialog.AddExtension = true; lsaveFileDialog.CheckFileExists = false; lsaveFileDialog.Filter = "Media file (*." + lSelectedAttr.Value.ToLower() + ")|*." + lSelectedAttr.Value.ToLower(); var lresult = lsaveFileDialog.ShowDialog(); if (lresult != true) { return; } var lFilename = lsaveFileDialog.FileName; lSelectedAttr = lselectedNode.Attributes["GUID"]; if (lSelectedAttr == null) { return; } mFileSinkFactory = await mSinkControl.createFileSinkFactoryAsync(Guid.Parse(lSelectedAttr.Value)); string lScreenCaptureSymbolicLink = "CaptureManager///Software///Sources///ScreenCapture///ScreenCapture"; string lAudioLoopBack = "CaptureManager///Software///Sources///AudioEndpointCapture///AudioLoopBack"; // Video Source uint lVideoSourceIndexStream = 0; uint lVideoSourceIndexMediaType = 2; int l_VideoCompressedMediaTypeSelectedIndex = 0; // Audio Source uint lAudioSourceIndexStream = 0; uint lAudioSourceIndexMediaType = 0; int l_AudioCompressedMediaTypeSelectedIndex = 0; string l_EncodersXMLstring = await mEncoderControl.getCollectionOfEncodersAsync(); XmlDocument doc = new XmlDocument(); doc.LoadXml(l_EncodersXMLstring); var lAttrNode = doc.SelectSingleNode("EncoderFactories/Group[@GUID='{73646976-0000-0010-8000-00AA00389B71}']/EncoderFactory[1]/@CLSID"); if (lAttrNode == null) { return; } Guid l_VideoEncoder = Guid.Empty; Guid.TryParse(lAttrNode.Value, out l_VideoEncoder); lAttrNode = doc.SelectSingleNode("EncoderFactories/Group[@GUID='{73647561-0000-0010-8000-00AA00389B71}']/EncoderFactory[1]/@CLSID"); if (lAttrNode == null) { return; } Guid l_AudioEncoder = Guid.Empty; Guid.TryParse(lAttrNode.Value, out l_AudioEncoder); List <object> lCompressedMediaTypeList = new List <object>(); if (true) { object lCompressedMediaType = await getCompressedMediaType( lScreenCaptureSymbolicLink, lVideoSourceIndexStream, lVideoSourceIndexMediaType, l_VideoEncoder, m_VideoEncoderMode, l_VideoCompressedMediaTypeSelectedIndex); if (lCompressedMediaType != null) { lCompressedMediaTypeList.Add(lCompressedMediaType); } } if (true) { object lCompressedMediaType = await getCompressedMediaType( lAudioLoopBack, lAudioSourceIndexStream, lAudioSourceIndexMediaType, l_AudioEncoder, m_AudioEncoderMode, l_AudioCompressedMediaTypeSelectedIndex); if (lCompressedMediaType != null) { lCompressedMediaTypeList.Add(lCompressedMediaType); } } List <object> lOutputNodes = await getOutputNodes(lCompressedMediaTypeList, lFilename); if (lOutputNodes == null || lOutputNodes.Count == 0) { return; } var lSinkFactory = await mSinkControl.createEVRSinkFactoryAsync( Guid.Empty); object lEVROutputNode = await lSinkFactory.createOutputNodeAsync( mVideoPanel.Handle); if (lEVROutputNode == null) { return; } object SpreaderNode = lEVROutputNode; if (true) { var lEncoderNode = await getEncoderNode( lScreenCaptureSymbolicLink, lVideoSourceIndexStream, lVideoSourceIndexMediaType, l_VideoEncoder, m_VideoEncoderMode, l_VideoCompressedMediaTypeSelectedIndex, lOutputNodes[0]); List <object> lOutputNodeList = new List <object>(); lOutputNodeList.Add(lEncoderNode); lOutputNodeList.Add(lEVROutputNode); SpreaderNode = await mSpreaderNodeFactory.createSpreaderNodeAsync( lOutputNodeList); //SpreaderNode = lEncoderNode; } var lMixerNodeFactory = await mStreamControl.createMixerNodeFactoryAsync(); List <object> lVideoTopologyInputMixerNodes = await lMixerNodeFactory.createMixerNodesAsync( SpreaderNode, 2); if (lVideoTopologyInputMixerNodes.Count == 0) { return; } for (int i = 1; i < lVideoTopologyInputMixerNodes.Count; i++) { mVideoTopologyInputMixerNodes.Add(lVideoTopologyInputMixerNodes[i]); } object lAudioEncoderNode = null; if (true) { lAudioEncoderNode = await getEncoderNode( lAudioLoopBack, lAudioSourceIndexStream, lAudioSourceIndexMediaType, l_AudioEncoder, m_AudioEncoderMode, l_AudioCompressedMediaTypeSelectedIndex, lOutputNodes[1]); } List <object> lAudioTopologyInputMixerNodes = await lMixerNodeFactory.createMixerNodesAsync( lAudioEncoderNode, 2); if (lAudioTopologyInputMixerNodes.Count == 0) { return; } mAudioTopologyInputMixerNode = lAudioTopologyInputMixerNodes[1]; List <object> lSourceNodes = new List <object>(); if (true) { object lSourceNode = await getSourceNode( lScreenCaptureSymbolicLink, lVideoSourceIndexStream, lVideoSourceIndexMediaType, lVideoTopologyInputMixerNodes[0]); if (lSourceNodes != null) { lSourceNodes.Add(lSourceNode); } } if (true) { object lSourceNode = await getSourceNode( lAudioLoopBack, lAudioSourceIndexStream, lAudioSourceIndexMediaType, lAudioTopologyInputMixerNodes[0]); if (lSourceNodes != null) { lSourceNodes.Add(lSourceNode); } } mISession = await mISessionControl.createSessionAsync(lSourceNodes.ToArray()); if (mISession != null) { mStartStopTxtBlk.Text = "Stop"; await mISession.startSessionAsync(0, Guid.Empty); mSourcesPanel.IsEnabled = true; } }
private async Task init() { var l_image_source = await createImageSource(); if (l_image_source == null) { return; } var lselectedNode = m_FileFormatComboBox.SelectedItem as XmlNode; if (lselectedNode == null) { return; } var lSelectedAttr = lselectedNode.Attributes["Value"]; if (lSelectedAttr == null) { return; } String limageSourceDir = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); SaveFileDialog lsaveFileDialog = new SaveFileDialog(); lsaveFileDialog.InitialDirectory = limageSourceDir; lsaveFileDialog.DefaultExt = "." + lSelectedAttr.Value.ToLower(); lsaveFileDialog.AddExtension = true; lsaveFileDialog.CheckFileExists = false; lsaveFileDialog.Filter = "Media file (*." + lSelectedAttr.Value.ToLower() + ")|*." + lSelectedAttr.Value.ToLower(); var lresult = lsaveFileDialog.ShowDialog(); if (lresult != true) { return; } var lFilename = lsaveFileDialog.FileName; lSelectedAttr = lselectedNode.Attributes["GUID"]; if (lSelectedAttr == null) { return; } mFileSinkFactory = await mSinkControl.createFileSinkFactoryAsync( Guid.Parse(lSelectedAttr.Value)); // Video Source uint lVideoSourceIndexStream = 0; uint lVideoSourceIndexMediaType = 0; int l_VideoCompressedMediaTypeSelectedIndex = 0; string l_EncodersXMLstring = await mEncoderControl.getCollectionOfEncodersAsync(); XmlDocument doc = new XmlDocument(); doc.LoadXml(l_EncodersXMLstring); var lAttrNode = doc.SelectSingleNode("EncoderFactories/Group[@GUID='{73646976-0000-0010-8000-00AA00389B71}']/EncoderFactory[1]/@CLSID"); if (lAttrNode == null) { return; } Guid l_VideoEncoder = Guid.Empty; Guid.TryParse(lAttrNode.Value, out l_VideoEncoder); List <object> lCompressedMediaTypeList = new List <object>(); if (true) { object lCompressedMediaType = await getCompressedMediaType( l_image_source, lVideoSourceIndexStream, lVideoSourceIndexMediaType, l_VideoEncoder, m_VideoEncoderMode, l_VideoCompressedMediaTypeSelectedIndex); if (lCompressedMediaType != null) { lCompressedMediaTypeList.Add(lCompressedMediaType); } } List <object> lOutputNodes = await getOutputNodes(lCompressedMediaTypeList, lFilename); if (lOutputNodes == null || lOutputNodes.Count == 0) { return; } var lSinkFactory = await mSinkControl.createEVRSinkFactoryAsync( Guid.Empty); object lEVROutputNode = await lSinkFactory.createOutputNodeAsync( mVideoPanel.Handle); if (lEVROutputNode == null) { return; } object SpreaderNode = lEVROutputNode; if (true) { var lEncoderNode = await getEncoderNode( l_image_source, lVideoSourceIndexStream, lVideoSourceIndexMediaType, l_VideoEncoder, m_VideoEncoderMode, l_VideoCompressedMediaTypeSelectedIndex, lOutputNodes[0]); List <object> lOutputNodeList = new List <object>(); lOutputNodeList.Add(lEncoderNode); lOutputNodeList.Add(lEVROutputNode); SpreaderNode = await mSpreaderNodeFactory.createSpreaderNodeAsync( lOutputNodeList); } List <object> lSourceNodes = new List <object>(); object lSourceNode = await mSourceControl.createSourceNodeFromExternalSourceWithDownStreamConnectionAsync( l_image_source, lVideoSourceIndexStream, lVideoSourceIndexMediaType, SpreaderNode); if (lSourceNode == null) { return; } lSourceNodes.Add(lSourceNode); mISession = await mISessionControl.createSessionAsync(lSourceNodes.ToArray()); if (mISession != null && await mISession.startSessionAsync(0, Guid.Empty)) { mStartStopTxtBlk.Text = "Stop"; } }
private async void Window_Loaded(object sender, RoutedEventArgs e) { try { mCaptureManager = new CaptureManager("CaptureManager.dll"); } catch (System.Exception) { try { mCaptureManager = new CaptureManager(); } catch (System.Exception) { } } LogManager.getInstance().WriteDelegateEvent += MainWindow_WriteDelegateEvent; if (mCaptureManager == null) { return; } mSourceControl = await mCaptureManager.createSourceControlAsync(); if (mSourceControl == null) { return; } mEncoderControl = await mCaptureManager.createEncoderControlAsync(); if (mEncoderControl == null) { return; } mSinkControl = await mCaptureManager.createSinkControlAsync(); if (mSinkControl == null) { return; } mISessionControl = await mCaptureManager.createSessionControlAsync(); if (mISessionControl == null) { return; } mStreamControl = await mCaptureManager.createStreamControlAsync(); if (mStreamControl == null) { return; } mSpreaderNodeFactory = await mStreamControl.createSpreaderNodeFactoryAsync(); if (mSpreaderNodeFactory == null) { return; } mEVRMultiSinkFactory = await mSinkControl.createEVRSinkFactoryAsync(Guid.Empty); if (mEVRMultiSinkFactory == null) { return; } XmlDataProvider lXmlDataProvider = (XmlDataProvider)this.Resources["XmlSources"]; if (lXmlDataProvider == null) { return; } XmlDocument doc = new XmlDocument(); string lxmldoc = await mCaptureManager.getCollectionOfSourcesAsync(); doc.LoadXml(lxmldoc); lXmlDataProvider.Document = doc; lXmlDataProvider = (XmlDataProvider)this.Resources["XmlEncoders"]; if (lXmlDataProvider == null) { return; } doc = new XmlDocument(); lxmldoc = await mCaptureManager.getCollectionOfEncodersAsync(); doc.LoadXml(lxmldoc); lXmlDataProvider.Document = doc; lxmldoc = await mCaptureManager.getCollectionOfSinksAsync(); lXmlDataProvider = (XmlDataProvider)this.Resources["XmlContainerTypeProvider"]; if (lXmlDataProvider == null) { return; } doc = new XmlDocument(); doc.LoadXml(lxmldoc); lXmlDataProvider.Document = doc; ProcessPriorityClass lpriority = Process.GetCurrentProcess().PriorityClass; Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.RealTime; }