private object getSourceNode(
            string aSymbolicLink,
            uint aStreamIndex,
            uint aMediaTypeIndex,
            object aOutputNode)
        {
            object lresult = null;

            do
            {
                object lSourceMediaType = null;

                if (!mSourceControl.getSourceOutputMediaType(
                        aSymbolicLink,
                        aStreamIndex,
                        aMediaTypeIndex,
                        out lSourceMediaType))
                {
                    break;
                }

                if (lSourceMediaType == null)
                {
                    break;
                }

                object lSourceNode;

                string lextendSymbolicLink = aSymbolicLink + " --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>";

                if (!mSourceControl.createSourceNode(
                        lextendSymbolicLink,
                        aStreamIndex,
                        aMediaTypeIndex,
                        aOutputNode,
                        out lSourceNode))
                {
                    break;
                }

                lresult = lSourceNode;
            } while (false);

            return(lresult);
        }
Exemple #2
0
        private object getSourceNode(
            XmlNode aSourceNode,
            XmlNode aStreamNode,
            XmlNode aMediaTypeNode,
            object aOutputNode)
        {
            object lresult = null;

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

                if (aMediaTypeNode == null)
                {
                    break;
                }


                if (aOutputNode == null)
                {
                    break;
                }


                if (aSourceNode == null)
                {
                    break;
                }

                var lNode = aSourceNode.SelectSingleNode(
                    "Source.Attributes/Attribute" +
                    "[@Name='MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK' or @Name='MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_AUDCAP_SYMBOLIC_LINK']" +
                    "/SingleValue/@Value");

                if (lNode == null)
                {
                    break;
                }

                string lSymbolicLink = lNode.Value;

                uint lStreamIndex = 0;

                if (aMediaTypeNode == null)
                {
                    break;
                }

                lNode = aMediaTypeNode.SelectSingleNode("@Index");

                if (lNode == null)
                {
                    break;
                }

                uint lMediaTypeIndex = 0;

                if (!uint.TryParse(lNode.Value, out lMediaTypeIndex))
                {
                    break;
                }

                object lSourceMediaType = null;

                if (!mSourceControl.getSourceOutputMediaType(
                        lSymbolicLink,
                        lStreamIndex,
                        lMediaTypeIndex,
                        out lSourceMediaType))
                {
                    break;
                }

                if (lSourceMediaType == null)
                {
                    break;
                }

                object lSourceNode;

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

                if (!mSourceControl.createSourceNode(
                        lextendSymbolicLink,
                        lStreamIndex,
                        lMediaTypeIndex,
                        aOutputNode,
                        out lSourceNode))
                {
                    break;
                }

                lresult = lSourceNode;
            } while (false);

            return(lresult);
        }
Exemple #3
0
        private void m_VideoEncodersComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            do
            {
                if (mEncoderControl == null)
                {
                    break;
                }

                var lselectedNode = m_VideoEncodersComboBox.SelectedItem as XmlNode;

                if (lselectedNode == null)
                {
                    break;
                }

                var lCLSIDEncoderAttr = lselectedNode.Attributes["CLSID"];

                if (lCLSIDEncoderAttr == null)
                {
                    break;
                }

                Guid lCLSIDEncoder;

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



                var lSourceNode = m_VideoSourceComboBox.SelectedItem as XmlNode;

                if (lSourceNode == null)
                {
                    return;
                }

                var lNode = lSourceNode.SelectSingleNode(
                    "Source.Attributes/Attribute" +
                    "[@Name='MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK' or @Name='MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_AUDCAP_SYMBOLIC_LINK']" +
                    "/SingleValue/@Value");

                if (lNode == null)
                {
                    return;
                }

                string lSymbolicLink = lNode.Value;

                lSourceNode = m_VideoStreamComboBox.SelectedItem as XmlNode;

                if (lSourceNode == null)
                {
                    return;
                }

                lNode = lSourceNode.SelectSingleNode("@Index");

                if (lNode == null)
                {
                    return;
                }

                uint lStreamIndex = 0;

                if (!uint.TryParse(lNode.Value, out lStreamIndex))
                {
                    return;
                }

                lSourceNode = m_VideoSourceMediaTypeComboBox.SelectedItem as XmlNode;

                if (lSourceNode == null)
                {
                    return;
                }

                lNode = lSourceNode.SelectSingleNode("@Index");

                if (lNode == null)
                {
                    return;
                }

                uint lMediaTypeIndex = 0;

                if (!uint.TryParse(lNode.Value, out lMediaTypeIndex))
                {
                    return;
                }



                object lOutputMediaType;

                if (mSourceControl == null)
                {
                    return;
                }



                lSymbolicLink = getScreenCaptureSymbolicLink(lSymbolicLink);

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

                string lMediaTypeCollection;

                if (!mEncoderControl.getMediaTypeCollectionOfEncoder(
                        lOutputMediaType,
                        lCLSIDEncoder,
                        out lMediaTypeCollection))
                {
                    break;
                }



                XmlDataProvider lXmlEncoderModeDataProvider = (XmlDataProvider)this.Resources["XmlEncoderModeProvider"];

                if (lXmlEncoderModeDataProvider == null)
                {
                    return;
                }

                XmlDocument lEncoderModedoc = new XmlDocument();

                lEncoderModedoc.LoadXml(lMediaTypeCollection);

                lXmlEncoderModeDataProvider.Document = lEncoderModedoc;
            } while (false);
        }
Exemple #4
0
        private void m_VideoEncodersComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            do
            {
                if (mEncoderControl == null)
                {
                    break;
                }

                var lselectedNode = m_VideoEncodersComboBox.SelectedItem as XmlNode;

                if (lselectedNode == null)
                {
                    break;
                }

                var lCLSIDEncoderAttr = lselectedNode.Attributes["CLSID"];

                if (lCLSIDEncoderAttr == null)
                {
                    break;
                }

                Guid lCLSIDEncoder;

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


                string lSymbolicLink = mCurrentSymbolicLink;

                uint lStreamIndex = 0;

                uint lMediaTypeIndex = 0;

                object lOutputMediaType;

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

                string lMediaTypeCollection;

                if (!mEncoderControl.getMediaTypeCollectionOfEncoder(
                        lOutputMediaType,
                        lCLSIDEncoder,
                        out lMediaTypeCollection))
                {
                    break;
                }



                XmlDataProvider lXmlEncoderModeDataProvider = (XmlDataProvider)this.Resources["XmlEncoderModeProvider"];

                if (lXmlEncoderModeDataProvider == null)
                {
                    return;
                }

                XmlDocument lEncoderModedoc = new XmlDocument();

                lEncoderModedoc.LoadXml(lMediaTypeCollection);

                lXmlEncoderModeDataProvider.Document = lEncoderModedoc;
            } while (false);
        }
Exemple #5
0
        private void init()
        {
            string lScreenCaptureSymbolicLink = "CaptureManager///Software///Sources///ScreenCapture///ScreenCapture";

            string lAudioLoopBack = "CaptureManager///Software///Sources///AudioEndpointCapture///AudioLoopBack";


            // Video Source
            uint lVideoSourceIndexStream = 0;

            uint lVideoSourceIndexMediaType = 2;

            object lVideoSourceOutputMediaType;

            mSourceControl.getSourceOutputMediaType(lScreenCaptureSymbolicLink, lVideoSourceIndexStream, lVideoSourceIndexMediaType, out lVideoSourceOutputMediaType);



            Guid lH264Encoder = new Guid("6ca50344-051a-4ded-9779-a43305165e35");

            IEncoderNodeFactory lIEncoderNodeFactory;

            mEncoderControl.createEncoderNodeFactory(lH264Encoder, out lIEncoderNodeFactory);

            if (lIEncoderNodeFactory == null)
            {
                mCtrlBtn.Content = "Error";

                mCtrlBtn.IsEnabled = false;

                mState.Text = "H264 Encoder is not acessable";

                return;
            }

            object lCompressedMediaType;

            lIEncoderNodeFactory.createCompressedMediaType(
                lVideoSourceOutputMediaType,
                new Guid(0xee8c3745, 0xf45b, 0x42b3, 0xa8, 0xcc, 0xc7, 0xa6, 0x96, 0x44, 0x9, 0x55),
                75,
                0,
                out lCompressedMediaType);



            // Audio Source
            uint lAudioSourceIndexStream = 0;

            uint lAudioSourceIndexMediaType = 0;

            object lAudioSourceOutputMediaType;

            mSourceControl.getSourceOutputMediaType(lAudioLoopBack, lAudioSourceIndexStream, lAudioSourceIndexMediaType, out lAudioSourceOutputMediaType);



            Guid lAACEncoder = new Guid("93af0c51-2275-45d2-a35b-f2ba21caed00");

            IEncoderNodeFactory lAACIEncoderNodeFactory;

            mEncoderControl.createEncoderNodeFactory(lAACEncoder, out lAACIEncoderNodeFactory);

            if (lAACIEncoderNodeFactory == null)
            {
                mCtrlBtn.Content = "Error";

                mCtrlBtn.IsEnabled = false;

                mState.Text = "AAC Encoder is not acessable";

                return;
            }

            object lAACCompressedMediaType;

            lAACIEncoderNodeFactory.createCompressedMediaType(
                lAudioSourceOutputMediaType,
                new Guid(0xca37e2be, 0xbec0, 0x4b17, 0x94, 0x6d, 0x44, 0xfb, 0xc1, 0xb3, 0xdf, 0x55),
                0,
                0,
                out lAACCompressedMediaType);



            IByteStreamSinkFactory lSinkFactory;

            mSinkControl.createSinkFactory(new Guid("E80A6BFD-D9C2-4A1F-95DC-14685CACEF3E"), out lSinkFactory);

            if (lSinkFactory == null)
            {
                mCtrlBtn.Content = "Error";

                mCtrlBtn.IsEnabled = false;

                mState.Text = "MP4 ByteStream is not acessable";

                return;
            }

            mNetworkStreamControl = new NetworkStreamControl(lSinkFactory);

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

            lcompressesMediaTypes.Add(lAACCompressedMediaType);

            lcompressesMediaTypes.Add(lCompressedMediaType);

            var lOutputNode = mNetworkStreamControl.getOutputNode(
                lcompressesMediaTypes,
                StartSession,
                StopSession,
                WriteClientIP);

            object lVideoEncoderNode;

            lIEncoderNodeFactory.createEncoderNode(lVideoSourceOutputMediaType,
                                                   new Guid(0xee8c3745, 0xf45b, 0x42b3, 0xa8, 0xcc, 0xc7, 0xa6, 0x96, 0x44, 0x9, 0x55),
                                                   75,
                                                   0,
                                                   lOutputNode[1],
                                                   out lVideoEncoderNode);



            object lAudioEncoderNode;

            lAACIEncoderNodeFactory.createEncoderNode(
                lAudioSourceOutputMediaType,
                new Guid(0xca37e2be, 0xbec0, 0x4b17, 0x94, 0x6d, 0x44, 0xfb, 0xc1, 0xb3, 0xdf, 0x55),
                75,
                0,
                lOutputNode[0],
                out lAudioEncoderNode);


            object lVideoSourceSourceNode;

            mSourceControl.createSourceNode(
                lScreenCaptureSymbolicLink,
                lVideoSourceIndexStream,
                lVideoSourceIndexMediaType,
                lVideoEncoderNode,
                out lVideoSourceSourceNode);



            object lAudioSourceSourceNode;

            mSourceControl.createSourceNode(
                lAudioLoopBack,
                lAudioSourceIndexStream,
                lAudioSourceIndexMediaType,
                lAudioEncoderNode,
                out lAudioSourceSourceNode);


            mISessionControl = mCaptureManager.createSessionControl();

            object[] lSourceNodes = { lVideoSourceSourceNode, lAudioSourceSourceNode };

            mISession = mISessionControl.createSession(lSourceNodes);

            if (mISession != null)
            {
                mState.Text = "Ready for connection";
            }
        }
Exemple #6
0
        private void encoderComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            do
            {
                if (mEncoderControl == null)
                {
                    break;
                }



                var lSelectedEncoderItem = (ContainerItem)encoderComboBox.SelectedItem;

                if (lSelectedEncoderItem == null)
                {
                    return;
                }

                var lselectedNode = lSelectedEncoderItem.mXmlNode;

                if (lselectedNode == null)
                {
                    break;
                }

                var lEncoderNameAttr = lselectedNode.Attributes["Title"];

                if (lEncoderNameAttr == null)
                {
                    break;
                }

                var lCLSIDEncoderAttr = lselectedNode.Attributes["CLSID"];

                if (lCLSIDEncoderAttr == null)
                {
                    break;
                }

                Guid lCLSIDEncoder;

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


                var lSelectedSourceItem = (ContainerItem)sourceComboBox.SelectedItem;

                if (lSelectedSourceItem == null)
                {
                    return;
                }

                var lSourceNode = lSelectedSourceItem.mXmlNode;

                if (lSourceNode == null)
                {
                    return;
                }

                var lNode = lSourceNode.SelectSingleNode(
                    "Source.Attributes/Attribute" +
                    "[@Name='MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK' or @Name='MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_AUDCAP_SYMBOLIC_LINK']" +
                    "/SingleValue/@Value");

                if (lNode == null)
                {
                    return;
                }

                string lSymbolicLink = lNode.Value;


                uint lStreamIndex = 0;

                var lSelectedMediaTypeItem = (ContainerItem)mediaTypeComboBox.SelectedItem;

                if (lSelectedMediaTypeItem == null)
                {
                    return;
                }

                lSourceNode = lSelectedMediaTypeItem.mXmlNode;

                if (lSourceNode == null)
                {
                    return;
                }

                lNode = lSourceNode.SelectSingleNode("@Index");

                if (lNode == null)
                {
                    return;
                }

                uint lMediaTypeIndex = 0;

                if (!uint.TryParse(lNode.Value, out lMediaTypeIndex))
                {
                    return;
                }



                object lOutputMediaType;

                if (mSourceControl == null)
                {
                    return;
                }

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

                string lMediaTypeCollection;

                if (!mEncoderControl.getMediaTypeCollectionOfEncoder(
                        lOutputMediaType,
                        lCLSIDEncoder,
                        out lMediaTypeCollection))
                {
                    break;
                }


                XmlDocument lEncoderModedoc = new XmlDocument();

                lEncoderModedoc.LoadXml(lMediaTypeCollection);

                var lEncoderNodes = lEncoderModedoc.SelectNodes("EncoderMediaTypes/Group");

                encoderModeComboBox.Items.Clear();

                foreach (var item in lEncoderNodes)
                {
                    lNode = (XmlNode)item;

                    if (lNode != null)
                    {
                        var lvalueNode = lNode.SelectSingleNode("@Title");

                        ContainerItem lSourceItem = new ContainerItem()
                        {
                            mFriendlyName = lvalueNode.Value,
                            mXmlNode      = lNode
                        };

                        encoderModeComboBox.Items.Add(lSourceItem);
                    }
                }
            } while (false);
        }
        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));
        }
Exemple #8
0
        private void m_VideoEncodersComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            do
            {
                if (mEncoderControl == null)
                {
                    break;
                }

                var lselectedNode = m_VideoEncodersComboBox.SelectedItem as XmlNode;

                if (lselectedNode == null)
                {
                    break;
                }

                var lCLSIDEncoderAttr = lselectedNode.Attributes["CLSID"];

                if (lCLSIDEncoderAttr == null)
                {
                    break;
                }

                Guid lCLSIDEncoder;

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



                var lSourceNode = m_VideoSourceComboBox.SelectedItem as XmlNode;

                if (lSourceNode == null)
                {
                    return;
                }

                var lNode = lSourceNode.SelectSingleNode(
                    "Source.Attributes/Attribute" +
                    "[@Name='MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK' or @Name='MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_AUDCAP_SYMBOLIC_LINK']" +
                    "/SingleValue/@Value");

                if (lNode == null)
                {
                    return;
                }

                string lSymbolicLink = lNode.Value;

                lSourceNode = m_VideoStreamComboBox.SelectedItem as XmlNode;

                if (lSourceNode == null)
                {
                    return;
                }

                lNode = lSourceNode.SelectSingleNode("@Index");

                if (lNode == null)
                {
                    return;
                }

                uint lStreamIndex = 0;

                if (!uint.TryParse(lNode.Value, out lStreamIndex))
                {
                    return;
                }

                lSourceNode = m_VideoSourceMediaTypeComboBox.SelectedItem as XmlNode;

                if (lSourceNode == null)
                {
                    return;
                }

                lNode = lSourceNode.SelectSingleNode("@Index");

                if (lNode == null)
                {
                    return;
                }

                uint lMediaTypeIndex = 0;

                if (!uint.TryParse(lNode.Value, out lMediaTypeIndex))
                {
                    return;
                }



                object lOutputMediaType;

                if (mSourceControl == null)
                {
                    return;
                }

                var t = new Thread(

                    delegate()
                {
                    try
                    {
                        Dispatcher.Invoke(
                            DispatcherPriority.Normal,
                            new Action(() => {
                            m_VideoEncodingModeComboBox.IsEnabled = false;
                        }));

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

                        string lMediaTypeCollection;

                        if (!mEncoderControl.getMediaTypeCollectionOfEncoder(
                                lOutputMediaType,
                                lCLSIDEncoder,
                                out lMediaTypeCollection))
                        {
                            return;
                        }



                        XmlDataProvider lXmlEncoderModeDataProvider = (XmlDataProvider)this.Resources["XmlEncoderModeProvider"];

                        if (lXmlEncoderModeDataProvider == null)
                        {
                            return;
                        }

                        XmlDocument lEncoderModedoc = new XmlDocument();

                        lEncoderModedoc.LoadXml(lMediaTypeCollection);

                        lXmlEncoderModeDataProvider.Document = lEncoderModedoc;


                        Dispatcher.Invoke(
                            DispatcherPriority.Normal,
                            new Action(() => {
                            m_VideoEncodingModeComboBox.IsEnabled = true;
                        }));
                    }
                    catch (Exception ex)
                    {
                    }
                    finally
                    {
                    }
                });
                t.SetApartmentState(ApartmentState.MTA);

                t.Start();
            } while (false);
        }
Exemple #9
0
        public MainWindow()
        {
            InitializeComponent();

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

            if (mCaptureManager == null)
            {
                return;
            }

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

            if (lXmlDataProvider == null)
            {
                return;
            }

            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();

            string lxmldoc = "";

            mCaptureManager.getCollectionOfSources(ref lxmldoc);

            doc.LoadXml(lxmldoc);

            lXmlDataProvider.Document = doc;

            mSourceControl = mCaptureManager.createSourceControl();



            mCaptureManager.getCollectionOfSinks(ref lxmldoc);


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

            if (lXmlDataProvider == null)
            {
                return;
            }

            doc = new System.Xml.XmlDocument();

            doc.LoadXml(lxmldoc);

            lXmlDataProvider.Document = doc;


            mISessionControl = mCaptureManager.createSessionControl();

            mSinkControl = mCaptureManager.createSinkControl();

            mEncoderControl = mCaptureManager.createEncoderControl();

            mEncodersComboBox.SelectionChanged += delegate
            {
                do
                {
                    if (mEncoderControl == null)
                    {
                        break;
                    }

                    var lselectedNode = mEncodersComboBox.SelectedItem as XmlNode;

                    if (lselectedNode == null)
                    {
                        break;
                    }

                    var lEncoderNameAttr = lselectedNode.Attributes["Title"];

                    if (lEncoderNameAttr == null)
                    {
                        break;
                    }

                    var lCLSIDEncoderAttr = lselectedNode.Attributes["CLSID"];

                    if (lCLSIDEncoderAttr == null)
                    {
                        break;
                    }

                    Guid lCLSIDEncoder;

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



                    var lSourceNode = mSourcesComboBox.SelectedItem as XmlNode;

                    if (lSourceNode == null)
                    {
                        return;
                    }

                    var lNode = lSourceNode.SelectSingleNode(
                        "Source.Attributes/Attribute" +
                        "[@Name='MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK' or @Name='MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_AUDCAP_SYMBOLIC_LINK']" +
                        "/SingleValue/@Value");

                    if (lNode == null)
                    {
                        return;
                    }

                    string lSymbolicLink = lNode.Value;

                    lSourceNode = mStreamsComboBox.SelectedItem as XmlNode;

                    if (lSourceNode == null)
                    {
                        return;
                    }

                    lNode = lSourceNode.SelectSingleNode("@Index");

                    if (lNode == null)
                    {
                        return;
                    }

                    uint lStreamIndex = 0;

                    if (!uint.TryParse(lNode.Value, out lStreamIndex))
                    {
                        return;
                    }

                    lSourceNode = mMediaTypesComboBox.SelectedItem as XmlNode;

                    if (lSourceNode == null)
                    {
                        return;
                    }

                    lNode = lSourceNode.SelectSingleNode("@Index");

                    if (lNode == null)
                    {
                        return;
                    }

                    uint lMediaTypeIndex = 0;

                    if (!uint.TryParse(lNode.Value, out lMediaTypeIndex))
                    {
                        return;
                    }



                    object lOutputMediaType;

                    if (mSourceControl == null)
                    {
                        return;
                    }

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

                    string lMediaTypeCollection;

                    if (!mEncoderControl.getMediaTypeCollectionOfEncoder(
                            lOutputMediaType,
                            lCLSIDEncoder,
                            out lMediaTypeCollection))
                    {
                        break;
                    }



                    XmlDataProvider lXmlEncoderModeDataProvider = (XmlDataProvider)this.Resources["XmlEncoderModeProvider"];

                    if (lXmlEncoderModeDataProvider == null)
                    {
                        return;
                    }

                    XmlDocument lEncoderModedoc = new XmlDocument();

                    lEncoderModedoc.LoadXml(lMediaTypeCollection);

                    lXmlEncoderModeDataProvider.Document = lEncoderModedoc;
                } while (false);
            };


            mEncodingModeComboBox.SelectionChanged += delegate
            {
                do
                {
                    if (mEncoderControl == null)
                    {
                        break;
                    }

                    var lselectedNode = mEncodingModeComboBox.SelectedItem as XmlNode;

                    if (lselectedNode == null)
                    {
                        break;
                    }

                    var lGUIDEncodingModeAttr = lselectedNode.Attributes["GUID"];

                    if (lGUIDEncodingModeAttr == null)
                    {
                        break;
                    }

                    Guid lGUIDEncodingMode;

                    if (!Guid.TryParse(lGUIDEncodingModeAttr.Value, out lGUIDEncodingMode))
                    {
                        break;
                    }

                    var lConstantMode = Guid.Parse("{CA37E2BE-BEC0-4B17-946D-44FBC1B3DF55}");

                    XmlDataProvider lXmlMediaTypeProvider = (XmlDataProvider)this.Resources["XmlMediaTypesCollectionProvider"];

                    if (lXmlMediaTypeProvider == null)
                    {
                        return;
                    }

                    XmlDocument lMediaTypedoc = new XmlDocument();

                    var lClonedMediaTypesNode = lMediaTypedoc.ImportNode(lselectedNode, true);

                    lMediaTypedoc.AppendChild(lClonedMediaTypesNode);

                    lXmlMediaTypeProvider.Document = lMediaTypedoc;
                } while (false);
            };

            mSinkFactoryComboBox.SelectionChanged += delegate
            {
                do
                {
                    if (mEncoderControl == null)
                    {
                        break;
                    }

                    var lselectedNode = mSinkFactoryComboBox.SelectedItem as XmlNode;

                    if (lselectedNode == null)
                    {
                        break;
                    }

                    var lAttr = lselectedNode.Attributes["GUID"];

                    if (lAttr == null)
                    {
                        throw new System.Exception("GUID is empty");
                    }

                    mContainerTypeComboBox.IsEnabled = false;

                    mSinkType = SinkType.Node;

                    if (lAttr.Value == "{D6E342E3-7DDD-4858-AB91-4253643864C2}")
                    {
                        mContainerTypeComboBox.IsEnabled = true;

                        mSinkType = SinkType.File;
                    }
                    else if (lAttr.Value == "{2E891049-964A-4D08-8F36-95CE8CB0DE9B}")
                    {
                        mContainerTypeComboBox.IsEnabled = true;

                        mSinkType = SinkType.BitStream;
                    }
                    else if (lAttr.Value == "{759D24FF-C5D6-4B65-8DDF-8A2B2BECDE39}")
                    {
                    }
                    else if (lAttr.Value == "{3D64C48E-EDA4-4EE1-8436-58B64DD7CF13}")
                    {
                    }
                    else if (lAttr.Value == "{2F34AF87-D349-45AA-A5F1-E4104D5C458E}")
                    {
                    }

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

                    if (lXmlMediaTypeProvider == null)
                    {
                        return;
                    }

                    XmlDocument lMediaTypedoc = new XmlDocument();

                    var lClonedMediaTypesNode = lMediaTypedoc.ImportNode(lselectedNode, true);

                    lMediaTypedoc.AppendChild(lClonedMediaTypesNode);

                    lXmlMediaTypeProvider.Document = lMediaTypedoc;
                } while (false);
            };
        }
Exemple #10
0
        private void mDo_Click(object sender, RoutedEventArgs e)
        {
            if (mSession != null)
            {
                mSession.closeSession();

                mSession = null;

                mDo.Content = "Stopped";

                return;
            }

            if (mSink == null)
            {
                return;
            }

            var lSourceNode = mSourcesComboBox.SelectedItem as XmlNode;

            if (lSourceNode == null)
            {
                return;
            }

            var lNode = lSourceNode.SelectSingleNode(
                "Source.Attributes/Attribute" +
                "[@Name='MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK' or @Name='MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_AUDCAP_SYMBOLIC_LINK']" +
                "/SingleValue/@Value");

            if (lNode == null)
            {
                return;
            }

            string lSymbolicLink = lNode.Value;

            lSourceNode = mStreamsComboBox.SelectedItem as XmlNode;

            if (lSourceNode == null)
            {
                return;
            }

            lNode = lSourceNode.SelectSingleNode("@Index");

            if (lNode == null)
            {
                return;
            }

            uint lStreamIndex = 0;

            if (!uint.TryParse(lNode.Value, out lStreamIndex))
            {
                return;
            }

            lSourceNode = mMediaTypesComboBox.SelectedItem as XmlNode;

            if (lSourceNode == null)
            {
                return;
            }

            lNode = lSourceNode.SelectSingleNode("@Index");

            if (lNode == null)
            {
                return;
            }

            uint lMediaTypeIndex = 0;

            if (!uint.TryParse(lNode.Value, out lMediaTypeIndex))
            {
                return;
            }

            object lOutputMediaType;

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

            var lselectedNode = mEncodersComboBox.SelectedItem as XmlNode;

            if (lselectedNode == null)
            {
                return;
            }

            var lEncoderNameAttr = lselectedNode.Attributes["Title"];

            if (lEncoderNameAttr == null)
            {
                return;
            }

            var lCLSIDEncoderAttr = lselectedNode.Attributes["CLSID"];

            if (lCLSIDEncoderAttr == null)
            {
                return;
            }

            Guid lCLSIDEncoder;

            if (!Guid.TryParse(lCLSIDEncoderAttr.Value, out lCLSIDEncoder))
            {
                return;
            }

            IEncoderNodeFactory lEncoderNodeFactory;

            mEncoderControl.createEncoderNodeFactory(
                lCLSIDEncoder,
                out lEncoderNodeFactory);



            lselectedNode = mEncodingModeComboBox.SelectedItem as XmlNode;

            if (lselectedNode == null)
            {
                return;
            }

            var lGUIDEncodingModeAttr = lselectedNode.Attributes["GUID"];

            if (lGUIDEncodingModeAttr == null)
            {
                return;
            }

            Guid lGUIDEncodingMode;

            if (!Guid.TryParse(lGUIDEncodingModeAttr.Value, out lGUIDEncodingMode))
            {
                return;
            }

            if (mCompressedMediaTypesComboBox.SelectedIndex < 0)
            {
                return;
            }

            object lCompressedMediaType;

            lEncoderNodeFactory.createCompressedMediaType(
                lOutputMediaType,
                lGUIDEncodingMode,
                70,
                (uint)mCompressedMediaTypesComboBox.SelectedIndex,
                out lCompressedMediaType);

            var lOutputNode = mSink.getOutputNode(lCompressedMediaType);

            IEncoderNodeFactory lIEncoderNodeFactory;

            mEncoderControl.createEncoderNodeFactory(
                lCLSIDEncoder,
                out lIEncoderNodeFactory);

            object lEncoderNode;

            lIEncoderNodeFactory.createEncoderNode(
                lOutputMediaType,
                lGUIDEncodingMode,
                70,
                (uint)mCompressedMediaTypesComboBox.SelectedIndex,
                lOutputNode,
                out lEncoderNode);

            object lSourceMediaNode;

            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='0x7000ff55' />" +
                                         "</Option.Extensions>" +
                                         "</Option>" +
                                         "</Options>";

            mSourceControl.createSourceNode(
                lextendSymbolicLink,
                lStreamIndex,
                lMediaTypeIndex,
                lEncoderNode,
                out lSourceMediaNode);

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

            lSourcesList.Add(lSourceMediaNode);

            mSession = mISessionControl.createSession(lSourcesList.ToArray());


            if (mSession != null)
            {
                mSession.startSession(0, Guid.Empty);
            }

            mDo.Content = "Record is executed!!!";
        }
Exemple #11
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));
        }
Exemple #12
0
        private Guid getEncoderMode()
        {
            Guid lEncoderMode = Guid.Empty;

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

                string lSymbolicLink = getSybolicLink();

                uint lStreamIndex = Settings.Default.SourceStream;

                uint lMediaTypeIndex = Settings.Default.SourceMediaType;

                object lOutputMediaType;

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

                string lMediaTypeCollection;

                if (!mEncoderControl.getMediaTypeCollectionOfEncoder(
                        lOutputMediaType,
                        mCLSIDEncoder,
                        out lMediaTypeCollection))
                {
                    break;
                }


                XmlDocument lEncoderModedoc = new XmlDocument();

                lEncoderModedoc.LoadXml(lMediaTypeCollection);

                var lNodes = lEncoderModedoc.SelectNodes("EncoderMediaTypes/Group");

                var lXmlNode = lNodes.Item((int)Settings.Default.EncoderMode);

                if (lXmlNode == null)
                {
                    break;
                }

                var lEncoderModeGuidAttr = lXmlNode.Attributes["GUID"];

                if (lEncoderModeGuidAttr == null)
                {
                    break;
                }

                Guid lCLSIDEncoderMode;

                if (!Guid.TryParse(lEncoderModeGuidAttr.Value, out lCLSIDEncoderMode))
                {
                    break;
                }

                lEncoderMode = lCLSIDEncoderMode;
            } while (false);

            return(lEncoderMode);
        }