Exemplo n.º 1
0
        private object getSwitcher(
            object aEncoderNode)
        {
            object lresult = null;

            do
            {
                if (aEncoderNode == null)
                {
                    break;
                }

                ISwitcherNodeFactory lSwitcherNodeFactory = null;

                if (!mStreamControl.createStreamControlNodeFactory(ref lSwitcherNodeFactory))
                {
                    break;
                }

                if (lSwitcherNodeFactory == null)
                {
                    break;
                }

                lSwitcherNodeFactory.createSwitcherNode(aEncoderNode, out lresult);
            } while (false);

            return(lresult);
        }
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            MainWindow.mISourceItems.Add(this);

            mEncoderControl = MainWindow.mCaptureManager.createEncoderControl();

            if (mEncoderControl == null)
            {
                return;
            }

            mSourceControl = MainWindow.mCaptureManager.createSourceControl();

            if (mSourceControl == null)
            {
                return;
            }



            mStreamControl = MainWindow.mCaptureManager.createStreamControl();

            if (mStreamControl == null)
            {
                return;
            }

            mStreamControl.createStreamControlNodeFactory(ref mSpreaderNodeFactory);

            if (mSpreaderNodeFactory == null)
            {
                return;
            }



            mSinkControl = MainWindow.mCaptureManager.createSinkControl();

            if (mSinkControl == null)
            {
                return;
            }

            mSinkControl.createSinkFactory(Guid.Empty, out mEVRMultiSinkFactory);

            if (mEVRMultiSinkFactory == null)
            {
                return;
            }
        }
Exemplo n.º 3
0
        private object getSwitcher()
        {
            object lresult = null;

            do
            {
                object RenderNode = null;

                List <object> lRenderOutputNodesList = new List <object>();

                if (mEVRMultiSinkFactory != null)
                {
                    mEVRMultiSinkFactory.createOutputNodes(
                        IntPtr.Zero,
                        m_EVRDisplay.Surface.texture,
                        1,
                        out lRenderOutputNodesList);
                }

                if (lRenderOutputNodesList.Count == 1)
                {
                    RenderNode = lRenderOutputNodesList[0];
                }

                ISwitcherNodeFactory lSwitcherNodeFactory = null;

                if (!mStreamControl.createStreamControlNodeFactory(ref lSwitcherNodeFactory))
                {
                    break;
                }

                if (lSwitcherNodeFactory == null)
                {
                    break;
                }

                lSwitcherNodeFactory.createSwitcherNode(RenderNode, out lresult);
            } while (false);

            return(lresult);
        }
Exemplo n.º 4
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                mCaptureManager = new CaptureManager("CaptureManager.dll");
            }
            catch (System.Exception)
            {
                try
                {
                    mCaptureManager = new CaptureManager();
                }
                catch (System.Exception)
                {
                }
            }

            m_Thumbnail.mChangeState += m_Thumbnail_mChangeState;

            LogManager.getInstance().WriteDelegateEvent += MainWindow_WriteDelegateEvent;

            if (mCaptureManager == null)
            {
                return;
            }

            mSourceControl = mCaptureManager.createSourceControl();

            if (mSourceControl == null)
            {
                return;
            }

            mSinkControl = mCaptureManager.createSinkControl();

            if (mSinkControl == null)
            {
                return;
            }

            mISessionControl = mCaptureManager.createSessionControl();

            if (mISessionControl == null)
            {
                return;
            }

            mStreamControl = mCaptureManager.createStreamControl();

            if (mStreamControl == null)
            {
                return;
            }

            mStreamControl.createStreamControlNodeFactory(ref mSpreaderNodeFactory);

            if (mSpreaderNodeFactory == null)
            {
                return;
            }

            mSinkControl.createSinkFactory(Guid.Empty, out mEVRMultiSinkFactory);

            if (mEVRMultiSinkFactory == null)
            {
                return;
            }

            mSwitcherControl = mCaptureManager.createSwitcherControl();

            if (mSwitcherControl == null)
            {
                return;
            }



            XmlDataProvider lXmlDataProvider = (XmlDataProvider)this.Resources["XmlSources"];

            if (lXmlDataProvider == null)
            {
                return;
            }

            XmlDocument doc = new XmlDocument();

            string lxmldoc = "";

            mCaptureManager.getCollectionOfSources(ref lxmldoc);

            doc.LoadXml(lxmldoc);

            lXmlDataProvider.Document = doc;

            lXmlDataProvider = (XmlDataProvider)this.Resources["XmlEncoders"];

            if (lXmlDataProvider == null)
            {
                return;
            }

            doc = new XmlDocument();

            mCaptureManager.getCollectionOfEncoders(ref lxmldoc);

            doc.LoadXml(lxmldoc);

            lXmlDataProvider.Document = doc;
        }
Exemplo n.º 5
0
        private 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 = mCaptureManager.createSourceControl();

            if (mSourceControl == null)
            {
                return;
            }

            mEncoderControl = mCaptureManager.createEncoderControl();

            if (mEncoderControl == null)
            {
                return;
            }

            mSinkControl = mCaptureManager.createSinkControl();

            if (mSinkControl == null)
            {
                return;
            }

            mISessionControl = mCaptureManager.createSessionControl();

            if (mISessionControl == null)
            {
                return;
            }

            mStreamControl = mCaptureManager.createStreamControl();

            if (mStreamControl == null)
            {
                return;
            }

            mStreamControl.createStreamControlNodeFactory(ref mSpreaderNodeFactory);

            if (mSpreaderNodeFactory == null)
            {
                return;
            }

            mSinkControl.createSinkFactory(Guid.Empty, out mEVRMultiSinkFactory);

            if (mEVRMultiSinkFactory == null)
            {
                return;
            }


            XmlDataProvider lXmlDataProvider = (XmlDataProvider)this.Resources["XmlSources"];

            if (lXmlDataProvider == null)
            {
                return;
            }

            XmlDocument doc = new XmlDocument();

            string lxmldoc = "";

            mCaptureManager.getCollectionOfSources(ref lxmldoc);

            doc.LoadXml(lxmldoc);

            lXmlDataProvider.Document = doc;

            lXmlDataProvider = (XmlDataProvider)this.Resources["XmlEncoders"];

            if (lXmlDataProvider == null)
            {
                return;
            }

            doc = new XmlDocument();

            mCaptureManager.getCollectionOfEncoders(ref lxmldoc);

            doc.LoadXml(lxmldoc);

            lXmlDataProvider.Document = doc;



            mCaptureManager.getCollectionOfSinks(ref lxmldoc);


            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;
        }
        public MainWindow()
        {
            InitializeComponent();


            try
            {
                mCaptureManager = new CaptureManager("CaptureManager.dll");
            }
            catch (System.Exception)
            {
                try
                {
                    mCaptureManager = new CaptureManager();
                }
                catch (System.Exception)
                {
                }
            }

            LogManager.getInstance().WriteDelegateEvent += MainWindow_WriteDelegateEvent;

            mSourceControl = mCaptureManager.createSourceControl();

            mEncoderControl = mCaptureManager.createEncoderControl();

            mSinkControl = mCaptureManager.createSinkControl();

            mStreamControl = mCaptureManager.createStreamControl();

            mISessionControl = mCaptureManager.createSessionControl();


            mStreamControl.createStreamControlNodeFactory(ref mSpreaderNodeFactory);

            if (mSpreaderNodeFactory == null)
            {
                return;
            }

            XmlDataProvider lXmlDataProvider = (XmlDataProvider)this.Resources["XmlSources"];

            if (lXmlDataProvider == null)
            {
                return;
            }

            XmlDocument doc = new XmlDocument();

            string lxmldoc = "";

            mCaptureManager.getCollectionOfSources(ref lxmldoc);

            doc.LoadXml(lxmldoc);

            lXmlDataProvider.Document = doc;



            XmlDataProvider lXmlContainerTypeProvider = (XmlDataProvider)this.Resources["XmlContainerTypeProvider"];

            if (lXmlDataProvider == null)
            {
                return;
            }

            doc = new XmlDocument();

            lxmldoc = "";

            mCaptureManager.getCollectionOfSinks(ref lxmldoc);

            doc.LoadXml(lxmldoc);

            lXmlContainerTypeProvider.Document = doc;
        }
        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;
            }
        }
Exemplo n.º 8
0
        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)
                            {
                                currentmillisecond += 1;

                                s.sendVideoData(currentmillisecond, aData, (int)aSize, aIndexCount);

                                currentmillisecond += (int)(aSampleDuration / (long)10000);
                            }
                        }
                    };

                    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[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);


                            object lVideoEncoderNode;

                            lIEncoderNodeFactory.createEncoderNode(
                                lVideoSourceOutputMediaType,
                                StreamingCBR,
                                25,
                                0,
                                lSampleGrabberCallNode,
                                out lVideoEncoderNode);

                            object lCompressedMediaType;

                            lIEncoderNodeFactory.createCompressedMediaType(
                                lVideoSourceOutputMediaType,
                                StreamingCBR,
                                25,
                                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";

                mSourceControl.createSourceNode(
                    lextendSymbolicLink,
                    lStreamIndex,
                    lMediaTypeIndex,
                    lOutputNode,
                    out result);

                if (result != null)
                {
                    index = aIndexCount;
                }
            }while (false);

            return(Tuple.Create <object, string, int>(result, lMediaType, index));
        }
Exemplo n.º 9
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            var t = new Thread(

                delegate()
            {
                try
                {
                    mCaptureManager = Program.mCaptureManager;

                    LogManager.getInstance().WriteDelegateEvent += MainWindow_WriteDelegateEvent;

                    if (mCaptureManager == null)
                    {
                        return;
                    }

                    mSourceControl = mCaptureManager.createSourceControl();

                    if (mSourceControl == null)
                    {
                        return;
                    }

                    mEncoderControl = mCaptureManager.createEncoderControl();

                    if (mEncoderControl == null)
                    {
                        return;
                    }

                    mSinkControl = mCaptureManager.createSinkControl();

                    if (mSinkControl == null)
                    {
                        return;
                    }

                    mISessionControl = mCaptureManager.createSessionControl();

                    if (mISessionControl == null)
                    {
                        return;
                    }

                    mStreamControl = mCaptureManager.createStreamControl();

                    if (mStreamControl == null)
                    {
                        return;
                    }

                    mStreamControl.createStreamControlNodeFactory(ref mSpreaderNodeFactory);

                    if (mSpreaderNodeFactory == null)
                    {
                        return;
                    }

                    mSinkControl.createSinkFactory(Guid.Empty, out mEVRMultiSinkFactory);

                    if (mEVRMultiSinkFactory == null)
                    {
                        return;
                    }

                    mSinkControl.createSinkFactory(Guid.Empty, out mEVRSinkFactory);

                    if (mEVRSinkFactory == null)
                    {
                        return;
                    }



                    XmlDataProvider lXmlDataProvider = (XmlDataProvider)this.Resources["XmlSources"];

                    if (lXmlDataProvider == null)
                    {
                        return;
                    }

                    XmlDocument doc = new XmlDocument();

                    string lxmldoc = "";

                    mCaptureManager.getCollectionOfSources(ref lxmldoc);

                    doc.LoadXml(lxmldoc);

                    lXmlDataProvider.Document = doc;

                    lXmlDataProvider = (XmlDataProvider)this.Resources["XmlEncoders"];

                    if (lXmlDataProvider == null)
                    {
                        return;
                    }

                    doc = new XmlDocument();

                    mCaptureManager.getCollectionOfEncoders(ref lxmldoc);

                    doc.LoadXml(lxmldoc);

                    lXmlDataProvider.Document = doc;



                    mCaptureManager.getCollectionOfSinks(ref lxmldoc);


                    lXmlDataProvider = (XmlDataProvider)this.Resources["XmlContainerTypeProvider"];

                    if (lXmlDataProvider == null)
                    {
                        return;
                    }

                    doc = new XmlDocument();

                    doc.LoadXml(lxmldoc);

                    lXmlDataProvider.Document = doc;
                }
                catch (Exception ex)
                {
                }
                finally
                {
                }
            });

            t.SetApartmentState(ApartmentState.MTA);

            t.Start();
        }
Exemplo n.º 10
0
        private Tuple <object, RtspServer.StreamType, int, string> createVideoStream(ISampleGrabberCallbackSinkFactory aISampleGrabberCallbackSinkFactory, int aIndexCount)
        {
            object result = null;

            RtspServer.StreamType type = RtspServer.StreamType.Video;

            int index = 0;

            string format = "";

            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;
                }

                Guid lVideoFormat = Guid.Empty;

                var lVideoCompressedNode = mVideoMediaTypeComboBox.SelectedItem as XmlNode;

                if (lVideoCompressedNode != null)
                {
                    var lGUID = lVideoCompressedNode.SelectSingleNode("MediaTypeItem[@Name='MF_MT_SUBTYPE']/SingleValue/@GUID");

                    if (lGUID != null)
                    {
                        Guid.TryParse(lGUID.Value, out lVideoFormat);
                    }


                    var lvalue = lVideoCompressedNode.SelectSingleNode("MediaTypeItem[@Name='MF_MT_SUBTYPE']/SingleValue/@Value");

                    if (lvalue != null && lvalue.Value != null)
                    {
                        var lsplit = lvalue.Value.Split(new char[] { '_' });

                        if (lsplit != null && lsplit.Length == 2)
                        {
                            format = lsplit[1];
                        }

                        if (format == "HEVC")
                        {
                            format = "H265";
                        }
                    }
                }



                ISampleGrabberCallback lSampleGrabberCallback = null;

                aISampleGrabberCallbackSinkFactory.createOutputNode(
                    MFMediaType_Video,
                    lVideoFormat,
                    out lSampleGrabberCallback);

                object lOutputNode = lEVROutputNode;

                if (lSampleGrabberCallback != null)
                {
                    lSampleGrabberCallback.mUpdateFullEvent += delegate
                                                               (uint aSampleFlags, long aSampleTime, long aSampleDuration, byte[] aData, uint aLength)
                    {
                        if (s != null)
                        {
                            lock (s)
                            {
                                currentmillisecond += 1;

                                s.sendData(aIndexCount, (int)type, currentmillisecond * 90, aData);

                                currentmillisecond += 20;
                            }
                        }
                    };

                    var lSampleGrabberCallNode = lSampleGrabberCallback.getTopologyNode();

                    if (lSampleGrabberCallNode != null)
                    {
                        IStreamControl       streamControl       = mCaptureManager.createStreamControl();
                        ISpreaderNodeFactory spreaderNodeFactory = null;
                        object        spreaderNode   = null;
                        List <object> outputNodeList = new List <object>();



                        var mEncoderControl = mCaptureManager.createEncoderControl();

                        var lEncoderNode = mVideoEncoderComboBox.SelectedItem as XmlNode;

                        if (lEncoderNode == null)
                        {
                            break;
                        }

                        lNode = lEncoderNode.SelectSingleNode("@CLSID");

                        if (lNode == null)
                        {
                            break;
                        }

                        Guid lCLSIDEncoder;

                        if (!Guid.TryParse(lNode.Value, out lCLSIDEncoder))
                        {
                            break;
                        }



                        var lBitRate = (uint)mBitRateComboBox.SelectedItem;



                        IEncoderNodeFactory lIEncoderNodeFactory;

                        mEncoderControl.createEncoderNodeFactory(lCLSIDEncoder, out lIEncoderNodeFactory);

                        if (lIEncoderNodeFactory != null)
                        {
                            object lVideoSourceOutputMediaType;

                            if (mSourceControl == null)
                            {
                                break;
                            }

                            mSourceControl.getSourceOutputMediaType(
                                lSymbolicLink,
                                lStreamIndex,
                                lMediaTypeIndex,
                                out lVideoSourceOutputMediaType);


                            object lVideoEncoderNode;

                            lIEncoderNodeFactory.createEncoderNode(lVideoSourceOutputMediaType,
                                                                   StreamingCBR,
                                                                   lBitRate,
                                                                   0,
                                                                   lSampleGrabberCallNode,
                                                                   out lVideoEncoderNode);


                            streamControl.createStreamControlNodeFactory(ref spreaderNodeFactory);
                            outputNodeList.Add(lEVROutputNode);
                            outputNodeList.Add(lVideoEncoderNode);
                            spreaderNodeFactory.createSpreaderNode(outputNodeList,
                                                                   out spreaderNode);


                            if (spreaderNode != null)
                            {
                                lOutputNode = spreaderNode;
                            }
                        }
                    }
                }

                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";

                mSourceControl.createSourceNode(
                    lextendSymbolicLink,
                    lStreamIndex,
                    lMediaTypeIndex,
                    lOutputNode,
                    out result);

                if (result != null)
                {
                    index = aIndexCount;
                }
            }while (false);

            return(Tuple.Create <object, RtspServer.StreamType, int, string>(result, type, index, format));
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                mCaptureManager = Program.mCaptureManager;

                App.mHotKeyHost = new HotKeyHost((HwndSource)HwndSource.FromVisual(App.Current.MainWindow));

                App.mHotKeyHost.AddHotKey(new CustomHotKey("Record",
                                                           new Action(() =>
                {
                    App.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, (ThreadStart) delegate()
                    {
                        mStartStop_Click(null, null);
                    });
                }
                                                                      ), Key.P, ModifierKeys.Control | ModifierKeys.Shift, true));
            }
            catch (System.Exception)
            {
                try
                {
                    mCaptureManager = new CaptureManager();
                }
                catch (System.Exception)
                {
                }
            }

            LogManager.getInstance().WriteDelegateEvent += MainWindow_WriteDelegateEvent;

            if (mCaptureManager == null)
            {
                return;
            }


            var t = new Thread(

                delegate()
            {
                try
                {
                    mSourceControl = mCaptureManager.createSourceControl();

                    if (mSourceControl == null)
                    {
                        return;
                    }

                    mEncoderControl = mCaptureManager.createEncoderControl();

                    if (mEncoderControl == null)
                    {
                        return;
                    }

                    mSinkControl = mCaptureManager.createSinkControl();

                    if (mSinkControl == null)
                    {
                        return;
                    }

                    mISessionControl = mCaptureManager.createSessionControl();

                    if (mISessionControl == null)
                    {
                        return;
                    }

                    mStreamControl = mCaptureManager.createStreamControl();

                    if (mStreamControl == null)
                    {
                        return;
                    }

                    mStreamControl.createStreamControlNodeFactory(ref mSpreaderNodeFactory);

                    if (mSpreaderNodeFactory == null)
                    {
                        return;
                    }

                    mSinkControl.createSinkFactory(Guid.Empty, out mEVRMultiSinkFactory);

                    if (mEVRMultiSinkFactory == null)
                    {
                        return;
                    }


                    XmlDataProvider lXmlDataProvider = (XmlDataProvider)this.Resources["XmlSources"];

                    if (lXmlDataProvider == null)
                    {
                        return;
                    }

                    XmlDocument doc = new XmlDocument();

                    string lxmldoc = "";

                    mCaptureManager.getCollectionOfSources(ref lxmldoc);

                    doc.LoadXml(lxmldoc);

                    lXmlDataProvider.Document = doc;

                    lXmlDataProvider = (XmlDataProvider)this.Resources["XmlEncoders"];

                    if (lXmlDataProvider == null)
                    {
                        return;
                    }

                    doc = new XmlDocument();

                    mCaptureManager.getCollectionOfEncoders(ref lxmldoc);

                    doc.LoadXml(lxmldoc);

                    lXmlDataProvider.Document = doc;



                    mCaptureManager.getCollectionOfSinks(ref lxmldoc);


                    lXmlDataProvider = (XmlDataProvider)this.Resources["XmlContainerTypeProvider"];

                    if (lXmlDataProvider == null)
                    {
                        return;
                    }

                    doc = new XmlDocument();

                    doc.LoadXml(lxmldoc);

                    lXmlDataProvider.Document = doc;
                }
                catch (Exception)
                {
                }
                finally
                {
                }
            });

            t.SetApartmentState(ApartmentState.MTA);

            t.Start();
        }