private void 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; } mSinkControl.createSinkFactory( Guid.Parse(lSelectedAttr.Value), out mFileSinkFactory); 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 = ""; mEncoderControl.getCollectionOfEncoders(out l_EncodersXMLstring); 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 = getCompressedMediaType( lScreenCaptureSymbolicLink, lVideoSourceIndexStream, lVideoSourceIndexMediaType, l_VideoEncoder, m_VideoEncoderMode, l_VideoCompressedMediaTypeSelectedIndex); if (lCompressedMediaType != null) { lCompressedMediaTypeList.Add(lCompressedMediaType); } } if (true) { object lCompressedMediaType = getCompressedMediaType( lAudioLoopBack, lAudioSourceIndexStream, lAudioSourceIndexMediaType, l_AudioEncoder, m_AudioEncoderMode, l_AudioCompressedMediaTypeSelectedIndex); if (lCompressedMediaType != null) { lCompressedMediaTypeList.Add(lCompressedMediaType); } } List <object> lOutputNodes = getOutputNodes(lCompressedMediaTypeList, lFilename); if (lOutputNodes == null || lOutputNodes.Count == 0) { return; } IEVRSinkFactory lSinkFactory; mSinkControl.createSinkFactory( Guid.Empty, out lSinkFactory); object lEVROutputNode = null; lSinkFactory.createOutputNode( mVideoPanel.Handle, out lEVROutputNode); if (lEVROutputNode == null) { return; } object SpreaderNode = lEVROutputNode; if (true) { var lEncoderNode = getEncoderNode( lScreenCaptureSymbolicLink, lVideoSourceIndexStream, lVideoSourceIndexMediaType, l_VideoEncoder, m_VideoEncoderMode, l_VideoCompressedMediaTypeSelectedIndex, lOutputNodes[0]); List <object> lOutputNodeList = new List <object>(); lOutputNodeList.Add(lEncoderNode); lOutputNodeList.Add(lEVROutputNode); mSpreaderNodeFactory.createSpreaderNode( lOutputNodeList, out SpreaderNode); //SpreaderNode = lEncoderNode; } IMixerNodeFactory lMixerNodeFactory = null; mStreamControl.createStreamControlNodeFactory(ref lMixerNodeFactory); List <object> lVideoTopologyInputMixerNodes; lMixerNodeFactory.createMixerNodes( SpreaderNode, 2, out lVideoTopologyInputMixerNodes); if (lVideoTopologyInputMixerNodes.Count == 0) { return; } for (int i = 1; i < lVideoTopologyInputMixerNodes.Count; i++) { mVideoTopologyInputMixerNodes.Add(lVideoTopologyInputMixerNodes[i]); } object lAudioEncoderNode = null; if (true) { lAudioEncoderNode = getEncoderNode( lAudioLoopBack, lAudioSourceIndexStream, lAudioSourceIndexMediaType, l_AudioEncoder, m_AudioEncoderMode, l_AudioCompressedMediaTypeSelectedIndex, lOutputNodes[1]); } List <object> lAudioTopologyInputMixerNodes; lMixerNodeFactory.createMixerNodes( lAudioEncoderNode, 2, out lAudioTopologyInputMixerNodes); if (lAudioTopologyInputMixerNodes.Count == 0) { return; } mAudioTopologyInputMixerNode = lAudioTopologyInputMixerNodes[1]; List <object> lSourceNodes = new List <object>(); if (true) { object lSourceNode = getSourceNode( lScreenCaptureSymbolicLink, lVideoSourceIndexStream, lVideoSourceIndexMediaType, lVideoTopologyInputMixerNodes[0]); if (lSourceNodes != null) { lSourceNodes.Add(lSourceNode); } } if (true) { object lSourceNode = getSourceNode( lAudioLoopBack, lAudioSourceIndexStream, lAudioSourceIndexMediaType, lAudioTopologyInputMixerNodes[0]); if (lSourceNodes != null) { lSourceNodes.Add(lSourceNode); } } mISession = mISessionControl.createSession(lSourceNodes.ToArray()); if (mISession != null) { mStartStopTxtBlk.Text = "Stop"; mISession.startSession(0, Guid.Empty); mSourcesPanel.IsEnabled = true; } }
private Tuple <object, string, int> createVideoStream(ISampleGrabberCallbackSinkFactory aISampleGrabberCallbackSinkFactory, int aIndexCount) { object result = null; int index = 0; string lMediaType = ""; do { var lSourceNode = mSourcesComboBox.SelectedItem as XmlNode; if (lSourceNode == null) { break; } var lNode = lSourceNode.SelectSingleNode("Source.Attributes/Attribute[@Name='MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK']/SingleValue/@Value"); if (lNode == null) { break; } string lSymbolicLink = lNode.Value; lSourceNode = mStreamsComboBox.SelectedItem as XmlNode; if (lSourceNode == null) { break; } lNode = lSourceNode.SelectSingleNode("@Index"); if (lNode == null) { break; } uint lStreamIndex = 0; if (!uint.TryParse(lNode.Value, out lStreamIndex)) { break; } lSourceNode = mMediaTypesComboBox.SelectedItem as XmlNode; if (lSourceNode == null) { break; } lNode = lSourceNode.SelectSingleNode("@Index"); if (lNode == null) { break; } uint lMediaTypeIndex = 0; if (!uint.TryParse(lNode.Value, out lMediaTypeIndex)) { break; } IEVRSinkFactory lSinkFactory; var lSinkControl = mCaptureManager.createSinkControl(); lSinkControl.createSinkFactory( Guid.Empty, out lSinkFactory); object lEVROutputNode = null; lSinkFactory.createOutputNode( mVideoPanel.Handle, out lEVROutputNode); if (lEVROutputNode == null) { break; } ISampleGrabberCallback lH264SampleGrabberCallback; aISampleGrabberCallbackSinkFactory.createOutputNode( MFMediaType_Video, MFVideoFormat_H264, out lH264SampleGrabberCallback); object lOutputNode = lEVROutputNode; if (lH264SampleGrabberCallback != null) { lH264SampleGrabberCallback.mUpdateNativeFullEvent += delegate (uint aSampleFlags, long aSampleTime, long aSampleDuration, IntPtr aData, uint aSize) { if (s != null) { lock (s) { Console.WriteLine("aSampleFlags: {0}", aSampleFlags); currentmillisecond += 1; s.sendVideoData(currentmillisecond, aData, (int)aSize, aSampleFlags, aIndexCount); currentmillisecond += 33; } } }; var lSampleGrabberCallNode = lH264SampleGrabberCallback.getTopologyNode(); if (lSampleGrabberCallNode != null) { IStreamControl streamControl = mCaptureManager.createStreamControl(); ISpreaderNodeFactory spreaderNodeFactory = null; object spreaderNode = null; List <object> outputNodeList = new List <object>(); var mEncoderControl = mCaptureManager.createEncoderControl(); string lxmldoc = ""; XmlDocument doc = new XmlDocument(); mCaptureManager.getCollectionOfEncoders(ref lxmldoc); doc.LoadXml(lxmldoc); var l_VideoEncoderNode = doc.SelectSingleNode("EncoderFactories/Group[@GUID='{73646976-0000-0010-8000-00AA00389B71}']/EncoderFactory[@IsStreaming='TRUE'][1]/@CLSID"); if (l_VideoEncoderNode == null) { break; } Guid lCLSIDVideoEncoder; if (!Guid.TryParse(l_VideoEncoderNode.Value, out lCLSIDVideoEncoder)) { break; } IEncoderNodeFactory lIEncoderNodeFactory; mEncoderControl.createEncoderNodeFactory(lCLSIDVideoEncoder, out lIEncoderNodeFactory); if (lIEncoderNodeFactory != null) { object lVideoSourceOutputMediaType; if (mSourceControl == null) { break; } mSourceControl.getSourceOutputMediaType( lSymbolicLink, lStreamIndex, lMediaTypeIndex, out lVideoSourceOutputMediaType); string lxmlDoc; mEncoderControl.getMediaTypeCollectionOfEncoder( lVideoSourceOutputMediaType, lCLSIDVideoEncoder, out lxmlDoc); doc = new System.Xml.XmlDocument(); doc.LoadXml(lxmlDoc); var lGroup = doc.SelectSingleNode("EncoderMediaTypes/Group[@GUID='{8F6FF1B6-534E-49C0-B2A8-16D534EAF135}']"); uint lMaxBitRate = 0; if (lGroup != null) { var lAttr = lGroup.SelectSingleNode("@MaxBitRate"); if (lAttr != null) { uint.TryParse(lAttr.Value, out lMaxBitRate); } } lMaxBitRate = 1000000; object lVideoEncoderNode; lIEncoderNodeFactory.createEncoderNode( lVideoSourceOutputMediaType, StreamingCBR, lMaxBitRate, 0, lSampleGrabberCallNode, out lVideoEncoderNode); object lCompressedMediaType; lIEncoderNodeFactory.createCompressedMediaType( lVideoSourceOutputMediaType, StreamingCBR, lMaxBitRate, 0, out lCompressedMediaType); streamControl.createStreamControlNodeFactory(ref spreaderNodeFactory); outputNodeList.Add(lEVROutputNode); outputNodeList.Add(lVideoEncoderNode); spreaderNodeFactory.createSpreaderNode(outputNodeList, out spreaderNode); if (spreaderNode != null) { lOutputNode = spreaderNode; } mCaptureManager.parseMediaType(lCompressedMediaType, out lMediaType); } } } string lextendSymbolicLink = lSymbolicLink + " --options=" + "<?xml version='1.0' encoding='UTF-8'?>" + "<Options>" + "<Option Type='Cursor' Visiblity='True'>" + "<Option.Extensions>" + "<Extension Type='BackImage' Height='100' Width='100' Fill='0x7055ff55' />" + "</Option.Extensions>" + "</Option>" + "</Options>"; lextendSymbolicLink += " --normalize=Landscape"; IStreamControl lstreamControl = mCaptureManager.createStreamControl(); IMixerNodeFactory lMixerNodeFactory = null; lstreamControl.createStreamControlNodeFactory(ref lMixerNodeFactory); List <object> lVideoTopologyInputMixerNodes; lMixerNodeFactory.createMixerNodes( lOutputNode, 2, out lVideoTopologyInputMixerNodes); if (lVideoTopologyInputMixerNodes.Count == 0) { break; } lOutputNode = lVideoTopologyInputMixerNodes[0]; mSourceControl.createSourceNode( lextendSymbolicLink, lStreamIndex, lMediaTypeIndex, lOutputNode, out result); if (result != null) { index = aIndexCount; } }while (false); return(Tuple.Create <object, string, int>(result, lMediaType, index)); }