void UpdateStateDelegate(uint aCallbackEventCode, uint aSessionDescriptor)
        {
            SessionCallbackEventCode k = (SessionCallbackEventCode)aCallbackEventCode;

            switch (k)
            {
            case SessionCallbackEventCode.Unknown:
                break;

            case SessionCallbackEventCode.Error:
                break;

            case SessionCallbackEventCode.Status_Error:
                break;

            case SessionCallbackEventCode.Execution_Error:
                break;

            case SessionCallbackEventCode.ItIsReadyToStart:
                break;

            case SessionCallbackEventCode.ItIsStarted:
                break;

            case SessionCallbackEventCode.ItIsPaused:
                break;

            case SessionCallbackEventCode.ItIsStopped:
                break;

            case SessionCallbackEventCode.ItIsEnded:
                break;

            case SessionCallbackEventCode.ItIsClosed:
            {
                Dispatcher.Invoke(
                    DispatcherPriority.Normal,
                    new Action(() => mLaunchButton.Content = "Launch"));

                Dispatcher.Invoke(
                    DispatcherPriority.Normal,
                    new Action(() =>
                    {
                        if (s != null)
                        {
                            s.disconnect();
                        }

                        s = null;
                    }
                               ));
            }
            break;

            case SessionCallbackEventCode.VideoCaptureDeviceRemoved:
            {
                Dispatcher.Invoke(
                    DispatcherPriority.Normal,
                    new Action(() => mLaunchButton_Click(null, null)));
            }
            break;

            default:
                break;
            }
        }
Ejemplo n.º 2
0
        private void mLaunchButton_Click(object sender, RoutedEventArgs e)
        {
            if (!m_socketAccessable)
            {
                return;
            }

            if (mLaunchButton.Content == "Stop")
            {
                if (mISession != null)
                {
                    mISession.closeSession();

                    mLaunchButton.Content = "Launch";
                }

                mISession = null;

                if (s != null)
                {
                    s.disconnect();
                }

                s = null;

                return;
            }


            string lxmldoc = "";

            mCaptureManager.getCollectionOfSinks(ref lxmldoc);

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(lxmldoc);

            var lSinkNode = doc.SelectSingleNode("SinkFactories/SinkFactory[@GUID='{3D64C48E-EDA4-4EE1-8436-58B64DD7CF13}']");

            if (lSinkNode == null)
            {
                return;
            }

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

            if (lContainerNode == null)
            {
                return;
            }

            var lReadMode = setContainerFormat(lContainerNode);

            var lSinkControl = mCaptureManager.createSinkControl();

            ISampleGrabberCallbackSinkFactory lSampleGrabberCallbackSinkFactory = null;

            lSinkControl.createSinkFactory(
                lReadMode,
                out lSampleGrabberCallbackSinkFactory);

            int lIndexCount = 0;

            var lVideoStreamSourceNode = createVideoStream(lSampleGrabberCallbackSinkFactory, lIndexCount);

            var lAudioStreamSourceNode = createAudioStream(lSampleGrabberCallbackSinkFactory, lIndexCount);


            XmlDocument l_streamMediaTypesXml = new XmlDocument();

            XmlNode ldocNode = l_streamMediaTypesXml.CreateXmlDeclaration("1.0", "UTF-8", null);

            l_streamMediaTypesXml.AppendChild(ldocNode);

            XmlElement rootNode = l_streamMediaTypesXml.CreateElement("MediaTypes");

            l_streamMediaTypesXml.AppendChild(rootNode);


            var lAttr = l_streamMediaTypesXml.CreateAttribute("StreamName");

            lAttr.Value = mStreamNameTxtBx.Text;

            rootNode.Attributes.Append(lAttr);

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

            if (lVideoStreamSourceNode.Item1 != null)
            {
                doc = new XmlDocument();

                doc.LoadXml(lVideoStreamSourceNode.Item2);

                var lMediaType = doc.SelectSingleNode("MediaType");

                if (lMediaType != null)
                {
                    rootNode.AppendChild(l_streamMediaTypesXml.ImportNode(lMediaType, true));
                }

                lSourceMediaNodeList.Add(lVideoStreamSourceNode.Item1);
            }

            if (lAudioStreamSourceNode.Item1 != null)
            {
                doc = new XmlDocument();

                doc.LoadXml(lAudioStreamSourceNode.Item2);

                var lMediaType = doc.SelectSingleNode("MediaType");

                if (lMediaType != null)
                {
                    rootNode.AppendChild(l_streamMediaTypesXml.ImportNode(lMediaType, true));
                }

                lSourceMediaNodeList.Add(lAudioStreamSourceNode.Item1);
            }

            var lSessionControl = mCaptureManager.createSessionControl();

            if (lSessionControl == null)
            {
                return;
            }

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

            if (mISession == null)
            {
                return;
            }

            startServer(l_streamMediaTypesXml.InnerXml);

            mISession.registerUpdateStateDelegate(UpdateStateDelegate);

            mISession.startSession(0, Guid.Empty);

            mLaunchButton.Content = "Stop";
        }