private void MAddImageBtn_Click(object sender, RoutedEventArgs e) { if (mAddImageSession != null) { mAddImageSession.stopSession(); mAddImageSession.closeSession(); mAddImageSession = null; mAddImageTxtBlk.Text = "Add Image"; mVideoTopologyInputMixerNodes.Add(mImageVideoTopologyInputMixerNode); var lVideoMixerControlRelease = mCaptureManager.createVideoMixerControl(); if (lVideoMixerControlRelease != null) { lVideoMixerControlRelease.flush(mImageVideoTopologyInputMixerNode); } mImageVideoTopologyInputMixerNode = null; m_CameraPanel.IsEnabled = true; return; } var lOpenFileDialog = new Microsoft.Win32.OpenFileDialog(); lOpenFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); lOpenFileDialog.Filter = "Image files (*.png, *.gif)|*.png;*.gif"; bool l_result = (bool)lOpenFileDialog.ShowDialog(); if (l_result && File.Exists(lOpenFileDialog.FileName)) { var lICaptureProcessor = ImageCaptureProcessor.createCaptureProcessor(lOpenFileDialog.FileName); if (lICaptureProcessor == null) { return; } object lImageSourceSource = null; mSourceControl.createSourceFromCaptureProcessor( lICaptureProcessor, out lImageSourceSource); var lVideoTopologyInputMixerNode = mVideoTopologyInputMixerNodes[0]; mImageVideoTopologyInputMixerNode = lVideoTopologyInputMixerNode; mVideoTopologyInputMixerNodes.RemoveAt(0); object lImageSourceSourceNode = null; mSourceControl.createSourceNodeFromExternalSourceWithDownStreamConnection( lImageSourceSource, 0, 0, lVideoTopologyInputMixerNode, out lImageSourceSourceNode); object[] lSourceNodes = { lImageSourceSourceNode }; mAddImageSession = mISessionControl.createSession(lSourceNodes); if (mAddImageSession != null) { mAddImageTxtBlk.Text = "Remove Camera"; } mAddImageSession.startSession(0, Guid.Empty); var lVideoMixerControl = mCaptureManager.createVideoMixerControl(); if (lVideoMixerControl != null) { lVideoMixerControl.setPosition(lVideoTopologyInputMixerNode, 0.5f, 1.0f, 0.0f, 0.5f); } //if (lVideoMixerControl != null) // lVideoMixerControl.setSrcPosition(lVideoTopologyInputMixerNode, 0.0f, 0.5f, 0.0f, 0.5f); if (lVideoMixerControl != null) { lVideoMixerControl.setOpacity(lVideoTopologyInputMixerNode, 0.5f); } m_CameraPanel.IsEnabled = false; } }
private void init() { var l_image_source = 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; } mSinkControl.createSinkFactory( Guid.Parse(lSelectedAttr.Value), out mFileSinkFactory); // Video Source uint lVideoSourceIndexStream = 0; uint lVideoSourceIndexMediaType = 0; int l_VideoCompressedMediaTypeSelectedIndex = 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); List <object> lCompressedMediaTypeList = new List <object>(); if (true) { object lCompressedMediaType = getCompressedMediaType( l_image_source, lVideoSourceIndexStream, lVideoSourceIndexMediaType, l_VideoEncoder, m_VideoEncoderMode, l_VideoCompressedMediaTypeSelectedIndex); 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( 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); mSpreaderNodeFactory.createSpreaderNode( lOutputNodeList, out SpreaderNode); } List <object> lSourceNodes = new List <object>(); object lSourceNode = null; mSourceControl.createSourceNodeFromExternalSourceWithDownStreamConnection( l_image_source, lVideoSourceIndexStream, lVideoSourceIndexMediaType, SpreaderNode, out lSourceNode); if (lSourceNode == null) { return; } lSourceNodes.Add(lSourceNode); mISession = mISessionControl.createSession(lSourceNodes.ToArray()); if (mISession != null) { mStartStopTxtBlk.Text = "Stop"; mISession.startSession(0, Guid.Empty); } }