コード例 #1
0
        public bool createStreamControlNodeFactory(ref ISpreaderNodeFactory aISpreaderNodeFactory)
        {
            bool lresult = false;

            do
            {
                try
                {
                    if (mIStreamControl == null)
                    {
                        break;
                    }

                    object lIUnknown;

                    mIStreamControl.createStreamControlNodeFactory(
                        typeof(CaptureManagerLibrary.ISpreaderNodeFactory).GUID,
                        out lIUnknown);

                    if (lIUnknown == null)
                    {
                        break;
                    }

                    var lSpreaderNodeFactory = lIUnknown as CaptureManagerLibrary.ISpreaderNodeFactory;

                    if (lSpreaderNodeFactory == null)
                    {
                        break;
                    }

                    aISpreaderNodeFactory = new SpreaderNodeFactory(lSpreaderNodeFactory);

                    lresult = true;
                }
                catch (Exception exc)
                {
                    LogManager.getInstance().write(exc.Message);
                }
            } while (false);

            return(lresult);
        }
コード例 #2
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));
        }
コード例 #3
0
        private void mLaunchButton_Click(object sender, RoutedEventArgs e)
        {
            if (mLaunchButton.Content.ToString() == "Stop")
            {
                mTimer.Stop();

                if (mISession != null)
                {
                    mISession.closeSession();
                }

                mLaunchButton.Content = "Launch";

                mTakePhotoButton.IsEnabled = false;

                return;
            }

            mTimer = new DispatcherTimer();

            mTimer.Interval = new TimeSpan(100000);

            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']/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;
            }

            lNode = lSourceNode.SelectSingleNode("MediaTypeItem[@Name='MF_MT_FRAME_SIZE']/Value.ValueParts/ValuePart[1]/@Value");

            if (lNode == null)
            {
                return;
            }

            uint lVideoWidth = 0;

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

            mVideoWidth = lVideoWidth;

            lNode = lSourceNode.SelectSingleNode("MediaTypeItem[@Name='MF_MT_FRAME_SIZE']/Value.ValueParts/ValuePart[2]/@Value");

            if (lNode == null)
            {
                return;
            }

            uint lVideoHeight = 0;

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

            mVideoHeight = lVideoHeight;

            int lWidthInBytes;

            mCaptureManager.getStrideForBitmapInfoHeader(
                MFVideoFormat_RGB32,
                lVideoWidth,
                out lWidthInBytes);

            lsampleByteSize = (uint)Math.Abs(lWidthInBytes) * lVideoHeight;

            mData = new byte[lsampleByteSize];

            var lSinkControl = mCaptureManager.createSinkControl();


            //  create Spread node

            var lStreamControl = mCaptureManager.createStreamControl();

            ISpreaderNodeFactory lSpreaderNodeFactory = null;

            if (!lStreamControl.createStreamControlNodeFactory(
                    Guid.Parse("{85DFAAA1-4CC0-4A88-AE28-8F492E552CCA}"),
                    ref lSpreaderNodeFactory))
            {
                return;
            }


            // create Sample Accumulator node factory

            ISpreaderNodeFactory lSampleAccumulatorNodeFactory = null;

            XmlNode lselectedSampleAccumulatorXml = (XmlNode)mSampleAccumulatorComboBox.SelectedItem;

            if (lselectedSampleAccumulatorXml == null)
            {
                return;
            }

            var lAttrNode = lselectedSampleAccumulatorXml.SelectSingleNode("@GUID");

            if (lAttrNode == null)
            {
                return;
            }

            if (!lStreamControl.createStreamControlNodeFactory(
                    Guid.Parse(lAttrNode.Value),
                    ref lSampleAccumulatorNodeFactory))
            {
                return;
            }

            lAttrNode = lselectedSampleAccumulatorXml.SelectSingleNode("@Samples");

            if (lAttrNode == null)
            {
                return;
            }

            if (!int.TryParse(lAttrNode.Value, out mSampleCount))
            {
                return;
            }


            string lxmldoc = "";

            XmlDocument doc = new XmlDocument();


            mCaptureManager.getCollectionOfSinks(ref lxmldoc);


            doc.LoadXml(lxmldoc);

            var lSinkNode = doc.SelectSingleNode("SinkFactories/SinkFactory[@GUID='{759D24FF-C5D6-4B65-8DDF-8A2B2BECDE39}']");

            if (lSinkNode == null)
            {
                return;
            }

            // create view output.

            var lContainerNode = lSinkNode.SelectSingleNode("Value.ValueParts/ValuePart[1]");

            if (lContainerNode == null)
            {
                return;
            }

            setContainerFormat(lContainerNode);

            lSinkControl.createSinkFactory(
                mReadMode,
                out mSinkFactory);

            lNode = lSourceNode.SelectSingleNode("MediaTypeItem[@Name='MF_MT_SUBTYPE']/SingleValue/@Value");

            if (lNode == null)
            {
                return;
            }

            Guid lMFVideoFormat = MFVideoFormat_RGB32;

            int lChannels = 4;

            if (lNode.Value == "MFVideoFormat_RGB24")
            {
                lMFVideoFormat = MFVideoFormat_RGB24;

                lChannels = 3;
            }

            mSinkFactory.createOutputNode(
                MFMediaType_Video,
                lMFVideoFormat,
                lsampleByteSize,
                out mISampleGrabberCall);

            if (mISampleGrabberCall != null)
            {
                byte[] lData = new byte[lsampleByteSize];


                mTimer.Tick += delegate
                {
                    if (mISampleGrabberCall == null)
                    {
                        return;
                    }

                    uint lByteSize = 0;

                    try
                    {
                        mISampleGrabberCall.readData(lData, out lByteSize);
                    }
                    catch (Exception)
                    {
                    }
                    finally
                    {
                        if (lByteSize > 0)
                        {
                            mDisplayImage.Source = FromArray(lData, lVideoWidth, lVideoHeight, lChannels);
                        }
                    }
                };


                // create take photo output

                lContainerNode = lSinkNode.SelectSingleNode("Value.ValueParts/ValuePart[3]");

                if (lContainerNode == null)
                {
                    return;
                }

                setContainerFormat(lContainerNode);

                ISampleGrabberCallSinkFactory lSinkFactory = null;

                lSinkControl.createSinkFactory(
                    mReadMode,
                    out lSinkFactory);

                lNode = lSourceNode.SelectSingleNode("MediaTypeItem[@Name='MF_MT_SUBTYPE']/SingleValue/@Value");

                if (lNode == null)
                {
                    return;
                }

                if (lNode.Value == "MFVideoFormat_MJPG")
                {
                    lSinkFactory.createOutputNode(
                        MFMediaType_Video,
                        MFVideoFormat_MJPG,
                        lsampleByteSize,
                        out mISampleGrabberCallPull);

                    mIsMJPG = true;
                }
                else if (lNode.Value == "MFVideoFormat_RGB24")
                {
                    mIsMJPG = false;

                    lSinkFactory.createOutputNode(
                        MFMediaType_Video,
                        MFVideoFormat_RGB24,
                        lsampleByteSize,
                        out mISampleGrabberCallPull);

                    mChannels = 3;
                }
                else
                {
                    mIsMJPG = false;

                    lSinkFactory.createOutputNode(
                        MFMediaType_Video,
                        MFVideoFormat_RGB32,
                        lsampleByteSize,
                        out mISampleGrabberCallPull);

                    mChannels = 4;
                }

                // connect take photo output with sample accumulator


                var lISampleGrabberCallPullNode = mISampleGrabberCallPull.getTopologyNode();

                if (lISampleGrabberCallPullNode == null)
                {
                    return;
                }

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

                lSampleAccumulatorList.Add(lISampleGrabberCallPullNode);

                object lSampleAccumulatorNode = null;

                lSampleAccumulatorNodeFactory.createSpreaderNode(lSampleAccumulatorList, out lSampleAccumulatorNode);


                // connect view output and take photo output with spreader node



                var lSampleGrabberCallNode = mISampleGrabberCall.getTopologyNode();

                if (lSampleGrabberCallNode == null)
                {
                    return;
                }



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

                llSpreaderNodeList.Add(lSampleAccumulatorNode);

                llSpreaderNodeList.Add(lSampleGrabberCallNode);

                object lSpreaderNode = null;

                lSpreaderNodeFactory.createSpreaderNode(llSpreaderNodeList, out lSpreaderNode);


                object lPtrSourceNode;

                var lSourceControl = mCaptureManager.createSourceControl();

                if (lSourceControl == null)
                {
                    return;
                }

                lSourceControl.createSourceNode(
                    lSymbolicLink,
                    lStreamIndex,
                    lMediaTypeIndex,
                    lSpreaderNode,
                    out lPtrSourceNode);

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

                lSourceMediaNodeList.Add(lPtrSourceNode);

                var lSessionControl = mCaptureManager.createSessionControl();

                if (lSessionControl == null)
                {
                    return;
                }

                mISession = lSessionControl.createSession(
                    lSourceMediaNodeList.ToArray());

                if (mISession == null)
                {
                    return;
                }

                if (!mISession.startSession(0, Guid.Empty))
                {
                    return;
                }

                mLaunchButton.Content = "Stop";

                mWebCamControl = lSourceControl.createWebCamControl(lSymbolicLink);

                if (mWebCamControl != null)
                {
                    string lXMLstring;

                    mWebCamControl.getCamParametrs(out lXMLstring);

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

                    if (lXmlDataProvider == null)
                    {
                        return;
                    }

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

                    ldoc.LoadXml(lXMLstring);

                    lXmlDataProvider.Document = ldoc;
                }

                mTimer.Start();

                mTakePhotoButton.IsEnabled = true;
            }
        }
コード例 #4
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));
        }