private async void m_StopBtn_Click(object sender, RoutedEventArgs e)
        {
            if (mState != State.Stopped)
            {
                m_StopBtn.IsEnabled = false;

                m_PauseBtn.IsEnabled = false;

                mSourceGrid.IsEnabled = true;

                mState = State.Stopped;

                if (mISession == null)
                {
                    return;
                }

                mStateLabel.Visibility = System.Windows.Visibility.Collapsed;

                await mISession.stopSessionAsync();

                await mISession.closeSessionAsync();

                mISession = null;

                m_StartStopBtn.IsEnabled = true;

                m_PauseBtn.Content = "Start recording";
            }
        }
Пример #2
0
        private async void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (mLaunchButton.Content.ToString() == "Stop")
            {
                mTimer.Stop();

                if (mISession != null)
                {
                    await mISession.closeSessionAsync();
                }

                mLaunchButton.Content = "Launch";

                return;
            }
        }
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            if (mISession != null)
            {
                mStartStopTxtBlk.Text = "Start";

                await mISession.stopSessionAsync();

                await mISession.closeSessionAsync();

                mISession = null;

                return;
            }

            await init();
        }
        private async void m_StopBtn_Click(object sender, RoutedEventArgs e)
        {
            m_PauseBtn.IsEnabled = false;

            m_StopBtn.IsEnabled = false;

            if (mState != State.Stopped)
            {
                mState = State.Stopped;

                if (mISession == null)
                {
                    return;
                }

                await mISession.stopSessionAsync();

                await mISession.closeSessionAsync();

                mISession = null;

                m_StartStopBtn.IsEnabled = true;
            }
        }
        private async void mLaunchButton_Click(object sender, RoutedEventArgs e)
        {
            if (!m_socketAccessable)
            {
                return;
            }

            mLaunchButton.IsEnabled = false;

            do
            {
                if (mLaunchButton.Content == "Stop")
                {
                    if (mISession != null)
                    {
                        await mISession.closeSessionAsync();

                        mLaunchButton.Content = "Launch";
                    }

                    mISession = null;

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

                    s = null;

                    mLaunchButton.IsEnabled = true;

                    break;
                }


                string lxmldoc = await mCaptureManager.getCollectionOfSinksAsync();

                XmlDocument doc = new XmlDocument();

                doc.LoadXml(lxmldoc);

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

                if (lSinkNode == null)
                {
                    break;
                }

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

                if (lContainerNode == null)
                {
                    break;
                }

                var lReadMode = setContainerFormat(lContainerNode);

                var lSinkControl = await mCaptureManager.createSinkControlAsync();

                ISampleGrabberCallbackSinkFactoryAsync lSampleGrabberCallbackSinkFactory = await lSinkControl.createSampleGrabberCallbackSinkFactoryAsync(
                    lReadMode);

                int lIndexCount = 0;

                var lVideoStreamSourceNode = await createVideoStream(lSampleGrabberCallbackSinkFactory, lIndexCount);

                var lAudioStreamSourceNode = await 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 = await mCaptureManager.createSessionControlAsync();

                if (lSessionControl == null)
                {
                    break;
                }

                mISession = await lSessionControl.createSessionAsync(
                    lSourceMediaNodeList.ToArray());

                if (mISession == null)
                {
                    break;
                }

                startServer(l_streamMediaTypesXml.InnerXml);

                await mISession.registerUpdateStateDelegateAsync(UpdateStateDelegate);

                await mISession.startSessionAsync(0, Guid.Empty);

                mLaunchButton.Content = "Stop";
            } while (false);

            mLaunchButton.IsEnabled = true;
        }
        private async void mLaunchButton_Click(object sender, RoutedEventArgs e)
        {
            if (mLaunchButton.Content.ToString() == "Stop")
            {
                lock (this)
                {
                    mAccess = false;
                }

                if (mISession != null)
                {
                    await mISession.closeSessionAsync();
                }

                mLaunchButton.Content = "Launch";

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

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

            int lWidthInBytes = await mCaptureManager.getStrideForBitmapInfoHeaderAsync(
                MFVideoFormat_RGB24,
                lVideoWidth);

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

            mData = new byte[lsampleByteSize];

            var lSinkControl = await mCaptureManager.createSinkControlAsync();

            string lxmldoc = await mCaptureManager.getCollectionOfSinksAsync();

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

            setContainerFormat(lContainerNode);

            var lSinkFactory = await lSinkControl.createSampleGrabberCallbackSinkFactoryAsync(mReadMode);

            var lISampleGrabberCallbackAsync = await lSinkFactory.createOutputNodeAsync(
                MFMediaType_Video,
                MFVideoFormat_RGB24);

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

                lISampleGrabberCallbackAsync.mUpdateEvent += delegate
                                                             (byte[] aData, uint aLength)
                {
                    lock (this)
                    {
                        if (!mAccess)
                        {
                            return;
                        }
                    }

                    Dispatcher.Invoke(
                        DispatcherPriority.Normal,
                        new Action(() => mDisplayImage.Source = FromArray(aData, lVideoWidth, lVideoHeight, mChannels)));
                };

                var lSampleGrabberCallNode = lISampleGrabberCallbackAsync.getTopologyNode();

                if (lSampleGrabberCallNode == null)
                {
                    return;
                }



                var lSourceControl = await mCaptureManager.createSourceControlAsync();

                if (lSourceControl == null)
                {
                    return;
                }

                object lPtrSourceNode = await lSourceControl.createSourceNodeWithDownStreamConnectionAsync(
                    lSymbolicLink,
                    lStreamIndex,
                    lMediaTypeIndex,
                    lSampleGrabberCallNode);

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

                lSourceMediaNodeList.Add(lPtrSourceNode);

                var lSessionControl = await mCaptureManager.createSessionControlAsync();

                if (lSessionControl == null)
                {
                    return;
                }

                mISession = await lSessionControl.createSessionAsync(
                    lSourceMediaNodeList.ToArray());

                if (mISession == null)
                {
                    return;
                }

                await mISession.startSessionAsync(0, Guid.Empty);

                mLaunchButton.Content = "Stop";

                mWebCamControl = await lSourceControl.createWebCamControlAsync(lSymbolicLink);

                if (mWebCamControl != null)
                {
                    string lXMLstring = await mWebCamControl.getCamParametrsAsync();

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

                    if (lXmlDataProvider == null)
                    {
                        return;
                    }

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

                    ldoc.LoadXml(lXMLstring);

                    lXmlDataProvider.Document = ldoc;
                }


                lock (this)
                {
                    mAccess = true;
                }
            }
        }
        private async void mLaunchButton_Click(object sender, RoutedEventArgs e)
        {
            if (mLaunchButton.Content.ToString() == "Stop")
            {
                mTimer.Stop();

                if (mISession != null)
                {
                    await mISession.closeSessionAsync();
                }

                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 = await mCaptureManager.getStrideForBitmapInfoHeaderAsync(
                MFVideoFormat_RGB32,
                lVideoWidth);

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

            mData = new byte[lsampleByteSize];

            var lSinkControl = await mCaptureManager.createSinkControlAsync();


            //  create Spread node

            var lStreamControl = await mCaptureManager.createStreamControlAsync();

            var lSpreaderNodeFactory = await lStreamControl.createSpreaderNodeFactoryAsync(
                Guid.Parse("{85DFAAA1-4CC0-4A88-AE28-8F492E552CCA}"));


            // create Sample Accumulator node factory

            XmlNode lselectedSampleAccumulatorXml = (XmlNode)mSampleAccumulatorComboBox.SelectedItem;

            if (lselectedSampleAccumulatorXml == null)
            {
                return;
            }

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

            if (lAttrNode == null)
            {
                return;
            }

            var lSampleAccumulatorNodeFactory = await lStreamControl.createSpreaderNodeFactoryAsync(
                Guid.Parse(lAttrNode.Value));

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

            mSinkFactory = await lSinkControl.createSampleGrabberCallSinkFactoryAsync(
                mReadMode);

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

            mISampleGrabberCall = await mSinkFactory.createOutputNodeAsync(
                MFMediaType_Video,
                lMFVideoFormat,
                lsampleByteSize);

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


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

                    uint lByteSize = 0;

                    try
                    {
                        lByteSize = await mISampleGrabberCall.readDataAsync(lData);
                    }
                    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);

                var lSinkFactory = await lSinkControl.createSampleGrabberCallSinkFactoryAsync(
                    mReadMode);

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

                if (lNode == null)
                {
                    return;
                }

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

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

                    mISampleGrabberCallPull = await lSinkFactory.createOutputNodeAsync(
                        MFMediaType_Video,
                        MFVideoFormat_RGB24,
                        lsampleByteSize);

                    mChannels = 3;
                }
                else
                {
                    mIsMJPG = false;

                    mISampleGrabberCallPull = await lSinkFactory.createOutputNodeAsync(
                        MFMediaType_Video,
                        MFVideoFormat_RGB32,
                        lsampleByteSize);

                    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 = await lSampleAccumulatorNodeFactory.createSpreaderNodeAsync(lSampleAccumulatorList);


                // 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 = await lSpreaderNodeFactory.createSpreaderNodeAsync(llSpreaderNodeList);

                var lSourceControl = await mCaptureManager.createSourceControlAsync();

                if (lSourceControl == null)
                {
                    return;
                }


                object lPtrSourceNode = await lSourceControl.createSourceNodeWithDownStreamConnectionAsync(
                    lSymbolicLink,
                    lStreamIndex,
                    lMediaTypeIndex,
                    lSpreaderNode);

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

                lSourceMediaNodeList.Add(lPtrSourceNode);

                var lSessionControl = await mCaptureManager.createSessionControlAsync();

                if (lSessionControl == null)
                {
                    return;
                }

                mISession = await lSessionControl.createSessionAsync(
                    lSourceMediaNodeList.ToArray());

                if (mISession == null)
                {
                    return;
                }

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

                mLaunchButton.Content = "Stop";

                mTimer.Start();

                mTakePhotoButton.IsEnabled = true;
            }
        }
Пример #8
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            mTitleTxtBlk.IsEnabled = false;

            do
            {
                if (mISession != null)
                {
                    await mISession.stopSessionAsync();

                    await mISession.closeSessionAsync();

                    mISession = null;

                    mTitleTxtBlk.Text = "Start playing";

                    break;
                }

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

                object lSARSinkOutputNode = await mSARSinkFactory.createOutputNodeAsync();

                if (lSARSinkOutputNode == null)
                {
                    break;
                }


                var l_AudioSourceXmlNode = m_AudioSourceComboBox.SelectedItem as XmlNode;

                if (l_AudioSourceXmlNode == null)
                {
                    break;
                }

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

                if (lNode == null)
                {
                    break;
                }

                string lSymbolicLink = lNode.Value;

                object lSourceNode = await mSourceControl.createSourceNodeWithDownStreamConnectionAsync(
                    lSymbolicLink,
                    0,
                    0,
                    lSARSinkOutputNode);

                if (lSourceNode == null)
                {
                    break;
                }

                lSourceNodes.Add(lSourceNode);

                mISession = await mISessionControl.createSessionAsync(lSourceNodes.ToArray());

                if (mISession == null)
                {
                    break;
                }

                if (await mISession.startSessionAsync(0, Guid.Empty))
                {
                    mTitleTxtBlk.Text = "Stop playing";

                    uint lChannelCount = 0;

                    lChannelCount = await mISARVolumeControl.getChannelCountAsync(lSARSinkOutputNode);

                    if (lChannelCount > 0)
                    {
                        float lLevel = await mISARVolumeControl.getChannelVolumeAsync(lSARSinkOutputNode, 0);

                        mRVolume.ValueChanged += async(s, ev) => {
                            await mISARVolumeControl.setChannelVolumeAsync(lSARSinkOutputNode, 0, (float)ev.NewValue);
                        };

                        mRVolume.Value = lLevel;

                        if (lChannelCount > 1)
                        {
                            lLevel = await mISARVolumeControl.getChannelVolumeAsync(lSARSinkOutputNode, 1);

                            mLVolume.ValueChanged += async(s, ev) => {
                                await mISARVolumeControl.setChannelVolumeAsync(lSARSinkOutputNode, 1, (float)ev.NewValue);
                            };

                            mLVolume.Value = lLevel;
                        }
                    }
                }
            } while (false);

            mTitleTxtBlk.IsEnabled = true;
        }
        private async void mDo_Click(object sender, RoutedEventArgs e)
        {
            mDo.IsEnabled = false;

            do
            {
                if (mSession != null)
                {
                    await mSession.closeSessionAsync();

                    mSession = null;

                    mDo.Content = "Stopped";

                    break;
                }

                if (mSink == null)
                {
                    break;
                }

                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' or @Name='MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_AUDCAP_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;
                }

                object lOutputMediaType = await mSourceControl.getSourceOutputMediaTypeAsync(
                    lSymbolicLink,
                    lStreamIndex,
                    lMediaTypeIndex);

                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 lEncoderNodeFactory = await mEncoderControl.createEncoderNodeFactoryAsync(
                    lCLSIDEncoder);



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

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

                object lCompressedMediaType = await lEncoderNodeFactory.createCompressedMediaTypeAsync(
                    lOutputMediaType,
                    lGUIDEncodingMode,
                    70,
                    (uint)mCompressedMediaTypesComboBox.SelectedIndex);

                var lOutputNode = await mSink.getOutputNode(lCompressedMediaType);

                var lIEncoderNodeFactory = await mEncoderControl.createEncoderNodeFactoryAsync(
                    lCLSIDEncoder);

                object lEncoderNode = await lIEncoderNodeFactory.createEncoderNodeAsync(
                    lOutputMediaType,
                    lGUIDEncodingMode,
                    70,
                    (uint)mCompressedMediaTypesComboBox.SelectedIndex,
                    lOutputNode);

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

                object lSourceMediaNode = await mSourceControl.createSourceNodeWithDownStreamConnectionAsync(
                    lextendSymbolicLink,
                    lStreamIndex,
                    lMediaTypeIndex,
                    lEncoderNode);

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

                lSourcesList.Add(lSourceMediaNode);

                mSession = await mISessionControl.createSessionAsync(lSourcesList.ToArray());


                if (mSession != null && await mSession.startSessionAsync(0, Guid.Empty))
                {
                    mDo.Content = "Record is executed!!!";
                }
            } while (false);

            mDo.IsEnabled = true;
        }
Пример #10
0
        private async void mLaunchButton_Click(object sender, RoutedEventArgs e)
        {
            if (mLaunchButton.Content.ToString() == "Stop")
            {
                if (mISession != null)
                {
                    await mISession.closeSessionAsync();

                    mLaunchButton.Content = "Launch";
                }

                mISession = null;

                return;
            }

            if (mISourceControl == null)
            {
                return;
            }

            var lICaptureProcessor = ImageCaptureProcessor.createCaptureProcessor();

            if (lICaptureProcessor == null)
            {
                return;
            }

            object lMediaSource = await mISourceControl.createSourceFromCaptureProcessorAsync(
                lICaptureProcessor);

            if (lMediaSource == null)
            {
                return;
            }


            string lxmldoc = await mCaptureManager.getCollectionOfSinksAsync();

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(lxmldoc);

            var lSinkNode = doc.SelectSingleNode("SinkFactories/SinkFactory[@GUID='{2F34AF87-D349-45AA-A5F1-E4104D5C458E}']");

            if (lSinkNode == null)
            {
                return;
            }

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

            if (lContainerNode == null)
            {
                return;
            }

            var lSinkControl = await mCaptureManager.createSinkControlAsync();

            var lSinkFactory = await lSinkControl.createEVRSinkFactoryAsync(
                Guid.Empty);

            object lEVROutputNode = await lSinkFactory.createOutputNodeAsync(
                mVideoPanel.Handle);

            if (lEVROutputNode == null)
            {
                return;
            }

            var lSourceControl = await mCaptureManager.createSourceControlAsync();

            if (lSourceControl == null)
            {
                return;
            }

            object lPtrSourceNode = await lSourceControl.createSourceNodeFromExternalSourceWithDownStreamConnectionAsync(
                lMediaSource,
                0,
                0,
                lEVROutputNode);

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

            lSourceMediaNodeList.Add(lPtrSourceNode);

            var lSessionControl = await mCaptureManager.createSessionControlAsync();

            if (lSessionControl == null)
            {
                return;
            }

            mISession = await lSessionControl.createSessionAsync(
                lSourceMediaNodeList.ToArray());

            if (mISession == null)
            {
                return;
            }

            await mISession.registerUpdateStateDelegateAsync(UpdateStateDelegate);

            await mISession.startSessionAsync(0, Guid.Empty);

            mLaunchButton.Content = "Stop";
        }
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            m_Thumbnail.stop();

            if (mISession != null)
            {
                await mISession.stopSessionAsync();

                await mISession.closeSessionAsync();

                mISession = null;

                return;
            }

            var lThumbnailOutputNode = await m_Thumbnail.init(m_VideoSourceMediaTypeComboBox.SelectedItem as XmlNode);

            if (lThumbnailOutputNode == null)
            {
                return;
            }

            object lSwitcherNode = await getSwitcher();

            if (lSwitcherNode == null)
            {
                return;
            }

            object SpreaderNode = lSwitcherNode;


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

            lOutputNodeList.Add(lSwitcherNode);

            lOutputNodeList.Add(lThumbnailOutputNode);

            SpreaderNode = await mSpreaderNodeFactory.createSpreaderNodeAsync(
                lOutputNodeList);

            object lSourceNode = await getSourceNode(
                m_VideoSourceComboBox.SelectedItem as XmlNode,
                m_VideoStreamComboBox.SelectedItem as XmlNode,
                m_VideoSourceMediaTypeComboBox.SelectedItem as XmlNode,
                SpreaderNode);

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

            lSourceNodes.Add(lSourceNode);

            mISession = await mISessionControl.createSessionAsync(lSourceNodes.ToArray());

            if (mISession == null)
            {
                return;
            }

            await mSwitcherControl.pauseSwitchersAsync(mISession);

            mIsPausedDisplay = true;

            if (await mISession.startSessionAsync(0, Guid.Empty))
            {
                m_Thumbnail.start();
            }
        }
Пример #12
0
        private async void mLaunchButton_Click(object sender, RoutedEventArgs e)
        {
            if (mLaunchButton.Content == "Stop")
            {
                if (s != null)
                {
                    s.StopListen();
                }

                s = null;

                if (mISession != null)
                {
                    await mISession.closeSessionAsync();

                    mLaunchButton.Content = "Launch";
                }

                mISession = null;

                return;
            }


            string lxmldoc = await mCaptureManager.getCollectionOfSinksAsync();

            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 = await mCaptureManager.createSinkControlAsync();

            var lSampleGrabberCallbackSinkFactory = await lSinkControl.createSampleGrabberCallbackSinkFactoryAsync(
                lReadMode);

            int lIndexCount = 120;

            var lVideoStreamSourceNode = await createVideoStream(lSampleGrabberCallbackSinkFactory, lIndexCount ++);

            var lAudioStreamSourceNode = await createAudioStream(lSampleGrabberCallbackSinkFactory, lIndexCount ++);


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

            List <Tuple <RtspServer.StreamType, int, string> > streams = new List <Tuple <RtspServer.StreamType, int, string> >();

            if (lVideoStreamSourceNode.Item1 != null)
            {
                lSourceMediaNodeList.Add(lVideoStreamSourceNode.Item1);

                streams.Add(Tuple.Create <RtspServer.StreamType, int, string>(lVideoStreamSourceNode.Item2, lVideoStreamSourceNode.Item3, lVideoStreamSourceNode.Item4));
            }

            if (lAudioStreamSourceNode.Item1 != null)
            {
                lSourceMediaNodeList.Add(lAudioStreamSourceNode.Item1);

                streams.Add(Tuple.Create <RtspServer.StreamType, int, string>(lAudioStreamSourceNode.Item2, lAudioStreamSourceNode.Item3, ""));
            }

            var lSessionControl = await mCaptureManager.createSessionControlAsync();

            if (lSessionControl == null)
            {
                return;
            }

            mISession = await lSessionControl.createSessionAsync(
                lSourceMediaNodeList.ToArray());

            if (mISession == null)
            {
                return;
            }


            await mISession.registerUpdateStateDelegateAsync(UpdateStateDelegate);

            await mISession.startSessionAsync(0, Guid.Empty);

            mLaunchButton.Content = "Stop";

            startServer(streams);
        }
Пример #13
0
        private async void mLaunchButton_Click(object sender, RoutedEventArgs e)
        {
            if (mLaunchButton.Content == "Stop")
            {
                if (mISession != null)
                {
                    await mISession.closeSessionAsync();

                    mLaunchButton.Content = "Launch";
                }

                mISession = null;

                //mEVROutputNode = 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']/SingleValue/@Value");

            if (lNode == null)
            {
                return;
            }

            string lSymbolicLink = lNode.Value;

            uint lStreamIndex = 0;

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


            string lxmldoc = await mCaptureManager.getCollectionOfSinksAsync();

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(lxmldoc);

            var lSinkNode = doc.SelectSingleNode("SinkFactories/SinkFactory[@GUID='{2F34AF87-D349-45AA-A5F1-E4104D5C458E}']");

            if (lSinkNode == null)
            {
                return;
            }

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

            if (lContainerNode == null)
            {
                return;
            }

            var lSinkControl = await mCaptureManager.createSinkControlAsync();

            var lSinkFactory = await lSinkControl.createEVRMultiSinkFactoryAsync(
                Guid.Empty);

            if (mEVROutputNode == null)
            {
                List <object> ltemp = await lSinkFactory.createOutputNodesAsync(
                    //IntPtr.Zero,
                    //mVideoPanel.SharedResource.texture,
                    mVideoPanel.Handle,
                    1);

                mEVROutputNode = ltemp[0];
            }

            if (mEVROutputNode == null)
            {
                return;
            }

            var lSourceControl = await mCaptureManager.createSourceControlAsync();

            if (lSourceControl == null)
            {
                return;
            }

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

            object lPtrSourceNode = await lSourceControl.createSourceNodeWithDownStreamConnectionAsync(
                lextendSymbolicLink,
                lStreamIndex,
                lMediaTypeIndex,
                mEVROutputNode);



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

            lSourceMediaNodeList.Add(lPtrSourceNode);

            var lSessionControl = await mCaptureManager.createSessionControlAsync();

            if (lSessionControl == null)
            {
                return;
            }

            mISession = await lSessionControl.createSessionAsync(
                lSourceMediaNodeList.ToArray());

            if (mISession == null)
            {
                return;
            }

            await mISession.registerUpdateStateDelegateAsync(UpdateStateDelegate);

            await mISession.startSessionAsync(0, Guid.Empty);

            mLaunchButton.Content = "Stop";
        }
        private async void mStartStop_Click(object sender, RoutedEventArgs e)
        {
            m_VideoSymbolicLink = getVideoSybolicLink();

            bool l_is_VideoStreamPreview = (bool)m_VideoStreamPreviewChkBtn.IsChecked;

            mStartStop.IsEnabled = false;


            if (mState == State.Started)
            {
                await mISession.stopSessionAsync();

                await mISession.closeSessionAsync();

                mISession = null;

                mState = State.Stopped;

                mStartStop.Content = "Start";

                mStartStop.IsEnabled = true;

                return;
            }

            getEncoderInfo();

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

            object lCompressedMediaType = await getVideoCompressedMediaType();

            if (lCompressedMediaType != null)
            {
                lCompressedMediaTypeList.Add(lCompressedMediaType);
            }

            lCompressedMediaType = await getAudioCompressedMediaType();

            if (lCompressedMediaType != null)
            {
                lCompressedMediaTypeList.Add(lCompressedMediaType);
            }

            List <object> lOutputNodes = await getOutputNodes(lCompressedMediaTypeList);

            if (lOutputNodes == null || lOutputNodes.Count == 0)
            {
                return;
            }

            int lOutputIndex = 0;

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


            object RenderNode = null;

            if (l_is_VideoStreamPreview)
            {
                List <object> lRenderOutputNodesList = new List <object>();

                if (mEVRMultiSinkFactory != null)
                {
                    lRenderOutputNodesList = await mEVRMultiSinkFactory.createOutputNodesAsync(
                        m_EVRDisplay.Handle,
                        null,
                        1);
                }

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



            object lSourceNode = await getVideoSourceNode(
                RenderNode,
                lOutputNodes[lOutputIndex++]);

            if (lSourceNodes != null)
            {
                lSourceNodes.Add(lSourceNode);
            }


            lSourceNode = await getAudioSourceNode(
                lOutputNodes[lOutputIndex++]);

            if (lSourceNodes != null)
            {
                lSourceNodes.Add(lSourceNode);
            }

            mISession = await mISessionControl.createSessionAsync(lSourceNodes.ToArray());

            if (mISession == null)
            {
                return;
            }

            var lisStarted = await mISession.startSessionAsync(0, Guid.Empty);

            if (lisStarted)
            {
                mState = State.Started;

                mStartStop.Content = "Stop";

                mStartStop.IsEnabled = true;
            }
        }
        private async void mLaunchButton_Click(object sender, RoutedEventArgs e)
        {
            mLaunchButton.IsEnabled = false;

            do
            {
                if (mLaunchButton.Content.ToString() == "Stop")
                {
                    if (mISession != null)
                    {
                        await mISession.stopSessionAsync();

                        await mISession.closeSessionAsync();

                        mLaunchButton.Content = "Launch";
                    }

                    mISession = null;

                    break;
                }

                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;

                uint lStreamIndex = 0;

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


                string lxmldoc = await mCaptureManager.getCollectionOfSinksAsync();

                XmlDocument doc = new XmlDocument();

                doc.LoadXml(lxmldoc);

                var lSinkNode = doc.SelectSingleNode("SinkFactories/SinkFactory[@GUID='{2F34AF87-D349-45AA-A5F1-E4104D5C458E}']");

                if (lSinkNode == null)
                {
                    break;
                }

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

                if (lContainerNode == null)
                {
                    break;
                }

                var lSinkControl = await mCaptureManager.createSinkControlAsync();

                var lSinkFactory = await lSinkControl.createEVRSinkFactoryAsync(
                    Guid.Empty);

                if (mEVROutputNode == null)
                {
                    mEVROutputNode = await lSinkFactory.createOutputNodeAsync(
                        mVideoPanel.Handle);
                }

                if (mEVROutputNode == null)
                {
                    break;
                }

                var lSourceControl = await mCaptureManager.createSourceControlAsync();

                if (lSourceControl == null)
                {
                    break;
                }

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

                if ((bool)mNormalizeChkBtn.IsChecked)
                {
                    lextendSymbolicLink += " --normalize=Landscape";
                }

                object lPtrSourceNode = await lSourceControl.createSourceNodeWithDownStreamConnectionAsync(
                    lextendSymbolicLink,
                    lStreamIndex,
                    lMediaTypeIndex,
                    mEVROutputNode);


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

                lSourceMediaNodeList.Add(lPtrSourceNode);

                var lSessionControl = await mCaptureManager.createSessionControlAsync();

                if (lSessionControl == null)
                {
                    break;
                }

                mISession = await lSessionControl.createSessionAsync(
                    lSourceMediaNodeList.ToArray());

                if (mISession == null)
                {
                    break;
                }

                foreach (var item in lSourceMediaNodeList)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(item);
                }

                await mISession.registerUpdateStateDelegateAsync(UpdateStateDelegate);

                await mISession.startSessionAsync(0, Guid.Empty);

                mLaunchButton.Content = "Stop";


                if (_ThumbnailTimer == null)
                {
                    ThumbnailTimer.Start();
                }
            } while (false);

            mLaunchButton.IsEnabled = true;
        }
Пример #16
0
        //void mTimer_Tick(object sender, EventArgs e)
        //{
        //    if (mISampleGrabber == null)
        //        return;

        //    uint lByteSize = (uint)mData.Length;

        //    try
        //    {

        //        mISampleGrabber.readData(mData, out lByteSize);
        //    }
        //    catch (Exception exc)
        //    {

        //    }
        //    finally
        //    {

        //        updateDisplayImage(this, mData, lByteSize);
        //    }
        //}

        private async void mLaunchButton_Click(object sender, RoutedEventArgs e)
        {
            if (mLaunchButton.Content.ToString() == "Stop")
            {
                //mTimer.Stop();

                if (mISession != null)
                {
                    await mISession.closeSessionAsync();
                }

                mLaunchButton.Content = "Launch";

                mTakePhotoButton.IsEnabled = false;

                if (mISampleGrabberCall != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(mISampleGrabberCall.getTopologyNode());
                }

                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']/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 = await mCaptureManager.getStrideForBitmapInfoHeaderAsync(
                MFVideoFormat_RGB32,
                lVideoWidth);

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

            var lSinkControl = await mCaptureManager.createSinkControlAsync();

            string lxmldoc = await mCaptureManager.getCollectionOfSinksAsync();

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(lxmldoc);

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

            if (lSinkNode == null)
            {
                return;
            }

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

            if (lContainerNode == null)
            {
                return;
            }

            setContainerFormat(lContainerNode);

            ISampleGrabberCallSinkFactoryAsync mSinkFactory = await lSinkControl.createSampleGrabberCallSinkFactoryAsync(
                mReadMode);

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

            if (lNode == null)
            {
                return;
            }

            if (lNode.Value == "MFVideoFormat_MJPG")
            {
                mISampleGrabberCall = await mSinkFactory.createOutputNodeAsync(
                    MFMediaType_Video,
                    MFVideoFormat_MJPG,
                    m_sampleByteSize);

                mIsMJPG = true;
            }
            else
            {
                mISampleGrabberCall = await mSinkFactory.createOutputNodeAsync(
                    MFMediaType_Video,
                    MFVideoFormat_RGB32,
                    m_sampleByteSize);
            }

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

                var lSampleGrabberCallNode = mISampleGrabberCall.getTopologyNode();

                if (lSampleGrabberCallNode == null)
                {
                    return;
                }

                var lSourceControl = await mCaptureManager.createSourceControlAsync();

                if (lSourceControl == null)
                {
                    return;
                }

                object lPtrSourceNode = await lSourceControl.createSourceNodeWithDownStreamConnectionAsync(
                    lSymbolicLink,
                    lStreamIndex,
                    lMediaTypeIndex,
                    lSampleGrabberCallNode);

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

                lSourceMediaNodeList.Add(lPtrSourceNode);

                var lSessionControl = await mCaptureManager.createSessionControlAsync();

                if (lSessionControl == null)
                {
                    return;
                }

                mISession = await lSessionControl.createSessionAsync(
                    lSourceMediaNodeList.ToArray());

                if (mISession == null)
                {
                    return;
                }

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

                mLaunchButton.Content = "Stop";

                mTakePhotoButton.IsEnabled = true;
            }
        }
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            mStartStopBtn.IsEnabled = false;

            do
            {
                if (mISession != null)
                {
                    mStartStopTxtBlk.Text = "Start";

                    await mISession.stopSessionAsync();

                    await mISession.closeSessionAsync();

                    mISession = null;

                    mSourcesPanel.IsEnabled = false;

                    if (mAddCameraSession != null)
                    {
                        await mAddCameraSession.stopSessionAsync();

                        await mAddCameraSession.closeSessionAsync();

                        mAddCameraSession = null;

                        mAddCameraTxtBlk.Text = "Add Camera";

                        mVideoTopologyInputMixerNodes.Add(mCameraVideoTopologyInputMixerNode);

                        mCameraVideoTopologyInputMixerNode = null;
                    }

                    if (mAddImageSession != null)
                    {
                        await mAddImageSession.stopSessionAsync();

                        await mAddImageSession.closeSessionAsync();

                        mAddImageSession = null;

                        mAddImageTxtBlk.Text = "Add Image";

                        mVideoTopologyInputMixerNodes.Add(mImageVideoTopologyInputMixerNode);

                        mImageVideoTopologyInputMixerNode = null;
                    }

                    if (mAddMicSession != null)
                    {
                        await mAddMicSession.stopSessionAsync();

                        await mAddMicSession.closeSessionAsync();

                        mAddMicSession = null;
                    }

                    System.Runtime.InteropServices.Marshal.ReleaseComObject(mAudioTopologyInputMixerNode);

                    mAudioTopologyInputMixerNode = null;

                    foreach (var item in mVideoTopologyInputMixerNodes)
                    {
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(item);
                    }

                    mVideoTopologyInputMixerNodes.Clear();

                    break;
                }

                await init();
            } while (false);

            mStartStopBtn.IsEnabled = true;
        }
Пример #18
0
        private async void start_stopBtn_Click(object sender, EventArgs e)
        {
            start_stopBtn.Enabled = false;

            do
            {
                if (start_stopBtn.Text == "Stop")
                {
                    if (mISession != null)
                    {
                        await mISession.closeSessionAsync();

                        start_stopBtn.Text = "Start";
                    }

                    mISession = null;

                    break;
                }

                var lSelectedSourceItem = (ContainerItem)sourceComboBox.SelectedItem;

                if (lSelectedSourceItem == null)
                {
                    break;
                }

                var lSourceNode = lSelectedSourceItem.mXmlNode;

                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;

                uint lStreamIndex = 0;

                var lMediaTypeItem = (ContainerItem)mediaTypeComboBox.SelectedItem;

                if (lMediaTypeItem == null)
                {
                    break;
                }

                lSourceNode = lMediaTypeItem.mXmlNode;

                if (lSourceNode == null)
                {
                    break;
                }

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

                if (lNode == null)
                {
                    break;
                }

                uint lMediaTypeIndex = 0;

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


                string lxmldoc = await mCaptureManager.getCollectionOfSinksAsync();

                XmlDocument doc = new XmlDocument();

                doc.LoadXml(lxmldoc);

                var lSinkNode = doc.SelectSingleNode("SinkFactories/SinkFactory[@GUID='{2F34AF87-D349-45AA-A5F1-E4104D5C458E}']");

                if (lSinkNode == null)
                {
                    break;
                }

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

                if (lContainerNode == null)
                {
                    break;
                }

                var lSinkControl = await mCaptureManager.createSinkControlAsync();

                var lSinkFactory = await lSinkControl.createEVRSinkFactoryAsync(Guid.Empty);

                object lEVROutputNode = await lSinkFactory.createOutputNodeAsync(
                    mVideoPanel.Handle);

                if (lEVROutputNode == null)
                {
                    break;
                }

                var lSourceControl = await mCaptureManager.createSourceControlAsync();

                if (lSourceControl == null)
                {
                    break;
                }

                object lPtrSourceNode = await lSourceControl.createSourceNodeWithDownStreamConnectionAsync(
                    lSymbolicLink,
                    lStreamIndex,
                    lMediaTypeIndex,
                    lEVROutputNode);

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

                lSourceMediaNodeList.Add(lPtrSourceNode);

                var lSessionControl = await mCaptureManager.createSessionControlAsync();

                if (lSessionControl == null)
                {
                    break;
                }

                mISession = await lSessionControl.createSessionAsync(
                    lSourceMediaNodeList.ToArray());

                if (mISession == null)
                {
                    break;
                }

                await mISession.startSessionAsync(0, Guid.Empty);

                start_stopBtn.Text = "Stop";
            } while (false);

            start_stopBtn.Enabled = true;
        }
Пример #19
0
        private async void mDo_Click(object sender, EventArgs e)
        {
            mDo.Enabled = false;

            do
            {
                if (mSession != null)
                {
                    await mSession.closeSessionAsync();

                    mSession = null;

                    mDo.Text = "Stopped";

                    break;
                }

                if (mSink == null)
                {
                    break;
                }

                var lSelectedSourceItem = (ContainerItem)sourceComboBox.SelectedItem;

                if (lSelectedSourceItem == null)
                {
                    break;
                }

                var lSourceNode = lSelectedSourceItem.mXmlNode;

                if (lSourceNode == null)
                {
                    break;
                }

                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)
                {
                    break;
                }

                string lSymbolicLink = lNode.Value;

                uint lStreamIndex = 0;

                var lSelectedMediaTypeItem = (ContainerItem)mediaTypeComboBox.SelectedItem;

                if (lSelectedMediaTypeItem == null)
                {
                    break;
                }

                lSourceNode = lSelectedMediaTypeItem.mXmlNode;

                if (lSourceNode == null)
                {
                    break;
                }

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

                if (lNode == null)
                {
                    break;
                }

                uint lMediaTypeIndex = 0;

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

                object lOutputMediaType = await mSourceControl.getSourceOutputMediaTypeAsync(
                    lSymbolicLink,
                    lStreamIndex,
                    lMediaTypeIndex);


                var lSelectedEncoderItem = (ContainerItem)encoderComboBox.SelectedItem;

                if (lSelectedEncoderItem == null)
                {
                    break;
                }


                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 lEncoderNodeFactory = await mEncoderControl.createEncoderNodeFactoryAsync(
                    lCLSIDEncoder);



                var lSelectedEncoderModeItem = (ContainerItem)encoderModeComboBox.SelectedItem;

                if (lSelectedEncoderModeItem == null)
                {
                    break;
                }

                lselectedNode = lSelectedEncoderModeItem.mXmlNode;

                if (lselectedNode == null)
                {
                    break;
                }

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

                if (lGUIDEncodingModeAttr == null)
                {
                    break;
                }

                Guid lGUIDEncodingMode;

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


                if (compressedMediaTypeComboBox.SelectedIndex < 0)
                {
                    break;
                }

                object lCompressedMediaType = await lEncoderNodeFactory.createCompressedMediaTypeAsync(
                    lOutputMediaType,
                    lGUIDEncodingMode,
                    70,
                    (uint)compressedMediaTypeComboBox.SelectedIndex);

                var lOutputNode = await mSink.getOutputNodeAsync(lCompressedMediaType);

                var lIEncoderNodeFactory = await mEncoderControl.createEncoderNodeFactoryAsync(
                    lCLSIDEncoder);

                object lEncoderNode = await lIEncoderNodeFactory.createEncoderNodeAsync(
                    lOutputMediaType,
                    lGUIDEncodingMode,
                    70,
                    (uint)compressedMediaTypeComboBox.SelectedIndex,
                    lOutputNode);

                object lSourceMediaNode = await mSourceControl.createSourceNodeWithDownStreamConnectionAsync(
                    lSymbolicLink,
                    lStreamIndex,
                    lMediaTypeIndex,
                    lEncoderNode);

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

                lSourcesList.Add(lSourceMediaNode);

                mSession = await mISessionControl.createSessionAsync(lSourcesList.ToArray());

                if (mSession == null)
                {
                    break;
                }

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

                mDo.Text = "Record is executed!!!";
            } while (false);

            mDo.Enabled = true;
        }
Пример #20
0
        private async void mControlBtn_Click(object sender, RoutedEventArgs e)
        {
            if (mIsStarted)
            {
                mIsStarted = false;

                if (mISession == null)
                {
                    return;
                }

                await mISession.stopSessionAsync();

                await mISession.closeSessionAsync();

                mISession = null;

                m_StartStopBtn.Content = "Start";

                foreach (var item in mISourceItems)
                {
                    var lsourceitem = (ISource)item;

                    if (lsourceitem != null)
                    {
                        lsourceitem.access(true);
                    }
                }

                return;
            }
            else
            {
                var lFileSinkFactory = await mSinkControl.createFileSinkFactoryAsync(
                    Guid.Parse("A2A56DA1-EB84-460E-9F05-FEE51D8C81E3"));

                if (lFileSinkFactory == null)
                {
                    return;
                }

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

                foreach (var item in mISources)
                {
                    var lCompressedMediaType = await item.getCompressedMediaType();

                    if (lCompressedMediaType != null)
                    {
                        lCompressedMediaTypeList.Add(lCompressedMediaType);
                    }
                }

                List <object> lOutputNodes = await getOutputNodes(lCompressedMediaTypeList, lFileSinkFactory);

                if (lOutputNodes == null || lOutputNodes.Count == 0)
                {
                    return;
                }

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

                for (int i = 0; i < lOutputNodes.Count; i++)
                {
                    var lSourceNode = await mISources[i].getSourceNode(lOutputNodes[i]);

                    if (lSourceNode != null)
                    {
                        lSourceNodes.Add(lSourceNode);
                    }
                }

                mISession = await mISessionControl.createSessionAsync(lSourceNodes.ToArray());

                if (mISession == null)
                {
                    return;
                }

                if (await mISession.startSessionAsync(0, Guid.Empty))
                {
                    m_StartStopBtn.Content = "Stop";
                }

                mIsStarted = true;

                foreach (var item in mISourceItems)
                {
                    var lsourceitem = (ISource)item;

                    if (lsourceitem != null)
                    {
                        lsourceitem.access(false);
                    }
                }
            }
        }