Пример #1
0
        private async void StartSession()
        {
            object lPtrSourceNode = null;
            var    sourceControl  = await CaptureManager.createSourceControlAsync();

            var sessionControl = await CaptureManager.createSessionControlAsync();

            _EVROutputAdapter = new EVROutputAdapter(Instance, _HWND);

            if (sessionControl != null && sessionControl != null && _EVROutputAdapter.Node != null)
            {
                Session = null;

                lPtrSourceNode = await sourceControl.createSourceNodeWithDownStreamConnectionAsync(_SymbolicLink,
                                                                                                   _StreamIndex,
                                                                                                   _MediaTypeIndex,
                                                                                                   _EVROutputAdapter.Node);

                Session = await sessionControl.createSessionAsync(new object[]
                {
                    lPtrSourceNode
                });

                if (Session != null)
                {
                    await Session.registerUpdateStateDelegateAsync(HandleSessionStateChanged);

                    await Session.startSessionAsync(0, Guid.Empty);
                }
            }
        }
        private async void MAddMicBtn_Click(object sender, RoutedEventArgs e)
        {
            if (mAddMicSession != null)
            {
                await mAddMicSession.stopSessionAsync();

                await mAddMicSession.closeSessionAsync();

                mAddMicTxtBlk.Text = "Add Mic";

                mAddMicSession = null;

                return;
            }



            var l_AudioSourceXmlNode          = m_AudioSourceComboBox.SelectedItem as XmlNode;
            var l_AudioStreamXmlNode          = m_AudioStreamComboBox.SelectedItem as XmlNode;
            var l_AudioSourceMediaTypeXmlNode = m_AudioSourceMediaTypeComboBox.SelectedItem as XmlNode;


            object lAudioSourceSourceNode = await getSourceNode(
                l_AudioSourceXmlNode,
                l_AudioStreamXmlNode,
                l_AudioSourceMediaTypeXmlNode,
                mAudioTopologyInputMixerNode);


            object[] lSourceNodes = { lAudioSourceSourceNode };

            mAddMicSession = await mISessionControl.createSessionAsync(lSourceNodes);

            if (mAddMicSession != null)
            {
                mAddMicTxtBlk.Text = "Remove Mic";
            }

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


            var lAudioMixerControl = await mCaptureManager.createAudioMixerControlAsync();

            if (lAudioMixerControl != null)
            {
                await lAudioMixerControl.setRelativeVolumeAsync(mAudioTopologyInputMixerNode, (float)m_AudioVolume.Value);
            }
        }
        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;
            }
        }
Пример #4
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;
        }
        private async Task init()
        {
            var l_image_source = await createImageSource();

            if (l_image_source == null)
            {
                return;
            }

            var lselectedNode = m_FileFormatComboBox.SelectedItem as XmlNode;

            if (lselectedNode == null)
            {
                return;
            }

            var lSelectedAttr = lselectedNode.Attributes["Value"];

            if (lSelectedAttr == null)
            {
                return;
            }

            String limageSourceDir = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);

            SaveFileDialog lsaveFileDialog = new SaveFileDialog();

            lsaveFileDialog.InitialDirectory = limageSourceDir;

            lsaveFileDialog.DefaultExt = "." + lSelectedAttr.Value.ToLower();

            lsaveFileDialog.AddExtension = true;

            lsaveFileDialog.CheckFileExists = false;

            lsaveFileDialog.Filter = "Media file (*." + lSelectedAttr.Value.ToLower() + ")|*." + lSelectedAttr.Value.ToLower();

            var lresult = lsaveFileDialog.ShowDialog();

            if (lresult != true)
            {
                return;
            }

            var lFilename = lsaveFileDialog.FileName;

            lSelectedAttr = lselectedNode.Attributes["GUID"];

            if (lSelectedAttr == null)
            {
                return;
            }

            mFileSinkFactory = await mSinkControl.createFileSinkFactoryAsync(
                Guid.Parse(lSelectedAttr.Value));



            // Video Source
            uint lVideoSourceIndexStream = 0;

            uint lVideoSourceIndexMediaType = 0;

            int l_VideoCompressedMediaTypeSelectedIndex = 0;



            string l_EncodersXMLstring = await mEncoderControl.getCollectionOfEncodersAsync();


            XmlDocument doc = new XmlDocument();

            doc.LoadXml(l_EncodersXMLstring);

            var lAttrNode = doc.SelectSingleNode("EncoderFactories/Group[@GUID='{73646976-0000-0010-8000-00AA00389B71}']/EncoderFactory[1]/@CLSID");

            if (lAttrNode == null)
            {
                return;
            }

            Guid l_VideoEncoder = Guid.Empty;

            Guid.TryParse(lAttrNode.Value, out l_VideoEncoder);



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

            if (true)
            {
                object lCompressedMediaType = await getCompressedMediaType(
                    l_image_source,
                    lVideoSourceIndexStream,
                    lVideoSourceIndexMediaType,
                    l_VideoEncoder,
                    m_VideoEncoderMode,
                    l_VideoCompressedMediaTypeSelectedIndex);

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

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

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

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

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

            if (lEVROutputNode == null)
            {
                return;
            }


            object SpreaderNode = lEVROutputNode;

            if (true)
            {
                var lEncoderNode = await getEncoderNode(
                    l_image_source,
                    lVideoSourceIndexStream,
                    lVideoSourceIndexMediaType,
                    l_VideoEncoder,
                    m_VideoEncoderMode,
                    l_VideoCompressedMediaTypeSelectedIndex,
                    lOutputNodes[0]);

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

                lOutputNodeList.Add(lEncoderNode);

                lOutputNodeList.Add(lEVROutputNode);

                SpreaderNode = await mSpreaderNodeFactory.createSpreaderNodeAsync(
                    lOutputNodeList);
            }

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

            object lSourceNode = await mSourceControl.createSourceNodeFromExternalSourceWithDownStreamConnectionAsync(
                l_image_source,
                lVideoSourceIndexStream,
                lVideoSourceIndexMediaType,
                SpreaderNode);

            if (lSourceNode == null)
            {
                return;
            }

            lSourceNodes.Add(lSourceNode);

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

            if (mISession != null && await mISession.startSessionAsync(0, Guid.Empty))
            {
                mStartStopTxtBlk.Text = "Stop";
            }
        }
        private async void MAddCameraBtn_Click(object sender, RoutedEventArgs e)
        {
            if (mAddCameraSession != null)
            {
                await mAddCameraSession.stopSessionAsync();

                await mAddCameraSession.closeSessionAsync();

                mAddCameraSession = null;

                mAddCameraTxtBlk.Text = "Add Camera";

                mVideoTopologyInputMixerNodes.Add(mCameraVideoTopologyInputMixerNode);

                var lVideoMixerControlRelease = mCaptureManager.createVideoMixerControl();

                if (lVideoMixerControlRelease != null)
                {
                    lVideoMixerControlRelease.flush(mCameraVideoTopologyInputMixerNode);
                }

                mCameraVideoTopologyInputMixerNode = null;

                m_ImagePanel.IsEnabled = true;

                return;
            }



            var l_VideoSourceXmlNode          = m_VideoSourceComboBox.SelectedItem as XmlNode;
            var l_VideoStreamXmlNode          = m_VideoStreamComboBox.SelectedItem as XmlNode;
            var l_VideoSourceMediaTypeXmlNode = m_VideoSourceMediaTypeComboBox.SelectedItem as XmlNode;

            var lVideoTopologyInputMixerNode = mVideoTopologyInputMixerNodes[0];

            mCameraVideoTopologyInputMixerNode = lVideoTopologyInputMixerNode;

            mVideoTopologyInputMixerNodes.RemoveAt(0);

            object lVideoSourceSourceNode = await getSourceNode(
                l_VideoSourceXmlNode,
                l_VideoStreamXmlNode,
                l_VideoSourceMediaTypeXmlNode,
                lVideoTopologyInputMixerNode);


            object[] lSourceNodes = { lVideoSourceSourceNode };

            mAddCameraSession = await mISessionControl.createSessionAsync(lSourceNodes);

            if (mAddCameraSession != null)
            {
                mAddCameraTxtBlk.Text = "Remove Camera";
            }

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


            var lVideoMixerControl = mCaptureManager.createVideoMixerControl();

            if (lVideoMixerControl != null)
            {
                lVideoMixerControl.setPosition(lVideoTopologyInputMixerNode, 0.0f, 0.5f, 0.0f, 0.5f);
            }

            if (lVideoMixerControl != null)
            {
                lVideoMixerControl.setOpacity(lVideoTopologyInputMixerNode, 0.5f);
            }

            m_ImagePanel.IsEnabled = false;

            //if (lVideoMixerControl != null)
            //    lVideoMixerControl.setSrcPosition(lVideoTopologyInputMixerNode, 0.0f, 0.5f, 0.0f, 0.5f);
        }
        private async void m_StartStopBtn_Click(object sender, RoutedEventArgs e)
        {
            if (mState == State.Paused && mISession != null)
            {
                await mISession.startSessionAsync(0, Guid.Empty);

                mState = State.Started;

                m_PauseBtn.IsEnabled = true;

                m_StopBtn.IsEnabled = true;

                m_StartStopBtn.IsEnabled = false;

                return;
            }


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

            if ((bool)m_VideoStreamChkBtn.IsChecked)
            {
                object lCompressedMediaType = await getCompressedMediaType(
                    m_VideoSourceComboBox.SelectedItem as XmlNode,
                    m_VideoStreamComboBox.SelectedItem as XmlNode,
                    m_VideoSourceMediaTypeComboBox.SelectedItem as XmlNode,
                    m_VideoEncodersComboBox.SelectedItem as XmlNode,
                    m_VideoEncodingModeComboBox.SelectedItem as XmlNode,
                    m_VideoCompressedMediaTypesComboBox.SelectedIndex);

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

            if ((bool)m_AudioStreamChkBtn.IsChecked)
            {
                object lCompressedMediaType = await getCompressedMediaType(
                    m_AudioSourceComboBox.SelectedItem as XmlNode,
                    m_AudioStreamComboBox.SelectedItem as XmlNode,
                    m_AudioSourceMediaTypeComboBox.SelectedItem as XmlNode,
                    m_AudioEncodersComboBox.SelectedItem as XmlNode,
                    m_AudioEncodingModeComboBox.SelectedItem as XmlNode,
                    m_AudioCompressedMediaTypesComboBox.SelectedIndex);

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

            if ((bool)m_VideoStreamChkBtn.IsChecked && m_VideoCompressedMediaTypesComboBox.SelectedIndex > -1)
            {
                object RenderNode = null;

                if ((bool)m_VideoStreamPreviewChkBtn.IsChecked)
                {
                    if (mEVRMultiSinkFactory != null)
                    {
                        RenderNode = await mEVRMultiSinkFactory.createOutputNodeAsync(
                            mVideoPanel.Handle);
                    }
                }



                object lSourceNode = await getSourceNode(
                    m_VideoSourceComboBox.SelectedItem as XmlNode,
                    m_VideoStreamComboBox.SelectedItem as XmlNode,
                    m_VideoSourceMediaTypeComboBox.SelectedItem as XmlNode,
                    m_VideoEncodersComboBox.SelectedItem as XmlNode,
                    m_VideoEncodingModeComboBox.SelectedItem as XmlNode,
                    m_VideoCompressedMediaTypesComboBox.SelectedIndex,
                    RenderNode,
                    lOutputNodes[lOutputIndex++]);

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

            if ((bool)m_AudioStreamChkBtn.IsChecked && m_AudioCompressedMediaTypesComboBox.SelectedIndex > -1)
            {
                object lSourceNode = await getSourceNode(
                    m_AudioSourceComboBox.SelectedItem as XmlNode,
                    m_AudioStreamComboBox.SelectedItem as XmlNode,
                    m_AudioSourceMediaTypeComboBox.SelectedItem as XmlNode,
                    m_AudioEncodersComboBox.SelectedItem as XmlNode,
                    m_AudioEncodingModeComboBox.SelectedItem as XmlNode,
                    m_AudioCompressedMediaTypesComboBox.SelectedIndex,
                    null,
                    lOutputNodes[lOutputIndex++]);

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

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

            if (mISession == null)
            {
                return;
            }

            if (await mISession.startSessionAsync(0, Guid.Empty))
            {
                mState = State.Started;

                m_PauseBtn.IsEnabled = true;

                m_StopBtn.IsEnabled = true;

                m_StartStopBtn.IsEnabled = false;
            }
        }
        private async void m_StartBtn_Click(object sender, RoutedEventArgs e)
        {
            if (mState == State.Paused && mISession != null)
            {
                await mSwitcherControl.resumeSwitchersAsync(mISession);

                mState = State.Started;

                m_PauseBtn.IsEnabled = true;

                m_StopBtn.IsEnabled = true;

                m_StartStopBtn.IsEnabled = false;

                return;
            }

            mVideoSwitcherNode = null;

            mAudioSwitcherNode = null;

            object RenderNode = null;


            List <object> lRenderOutputNodesList = await mEVRMultiSinkFactory.createOutputNodesAsync(
                IntPtr.Zero,
                m_EVRDisplay.Surface.texture,
                1);

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

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

            if ((bool)m_VideoStreamChkBtn.IsChecked)
            {
                mVideoSwitcherNode = await createSwitcher(null);

                if (mVideoSwitcherNode == null)
                {
                    return;
                }

                object lSourceNode = await getSourceNode(
                    m_VideoSourceComboBox.SelectedItem as XmlNode,
                    m_VideoStreamComboBox.SelectedItem as XmlNode,
                    m_VideoSourceMediaTypeComboBox.SelectedItem as XmlNode,
                    m_VideoEncodersComboBox.SelectedItem as XmlNode,
                    m_VideoEncodingModeComboBox.SelectedItem as XmlNode,
                    m_VideoCompressedMediaTypesComboBox.SelectedIndex,
                    RenderNode,
                    mVideoSwitcherNode);

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

            if ((bool)m_AudioStreamChkBtn.IsChecked)
            {
                mAudioSwitcherNode = await createSwitcher(null);

                if (mAudioSwitcherNode == null)
                {
                    return;
                }

                object lSourceNode = await getSourceNode(
                    m_AudioSourceComboBox.SelectedItem as XmlNode,
                    m_AudioStreamComboBox.SelectedItem as XmlNode,
                    m_AudioSourceMediaTypeComboBox.SelectedItem as XmlNode,
                    m_AudioEncodersComboBox.SelectedItem as XmlNode,
                    m_AudioEncodingModeComboBox.SelectedItem as XmlNode,
                    m_AudioCompressedMediaTypesComboBox.SelectedIndex,
                    null,
                    mAudioSwitcherNode);

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

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

            if (mISession == null)
            {
                return;
            }

            if (await mISession.startSessionAsync(0, Guid.Empty))
            {
                mState = State.Started;

                mRecordingState = State.Paused;

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

                m_PauseBtn.IsEnabled = true;

                m_StopBtn.IsEnabled = true;

                m_StartStopBtn.IsEnabled = false;

                mSourceGrid.IsEnabled = false;
            }
        }
Пример #10
0
        private async void m_StartBtn_Click(object sender, RoutedEventArgs e)
        {
            if (mState == State.Paused && mISession != null)
            {
                await mSwitcherControl.resumeSwitchersAsync(mISession);

                mState = State.Started;

                m_PauseBtn.IsEnabled = true;

                m_StopBtn.IsEnabled = true;

                m_StartStopBtn.IsEnabled = false;

                return;
            }


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


            object lCompressedMediaType = await getCompressedMediaType(
                m_VideoSourceComboBox.SelectedItem as XmlNode,
                m_VideoStreamComboBox.SelectedItem as XmlNode,
                m_VideoSourceMediaTypeComboBox.SelectedItem as XmlNode,
                m_VideoEncodersComboBox.SelectedItem as XmlNode,
                m_VideoEncodingModeComboBox.SelectedItem as XmlNode,
                m_VideoCompressedMediaTypesComboBox.SelectedIndex);

            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;


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

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

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

            object lEncoderNode = await getEncoder(
                m_VideoSourceComboBox.SelectedItem as XmlNode,
                m_VideoStreamComboBox.SelectedItem as XmlNode,
                m_VideoSourceMediaTypeComboBox.SelectedItem as XmlNode,
                m_VideoEncodersComboBox.SelectedItem as XmlNode,
                m_VideoEncodingModeComboBox.SelectedItem as XmlNode,
                m_VideoCompressedMediaTypesComboBox.SelectedIndex,
                lOutputNodes[lOutputIndex++]);

            if (lEncoderNode == null)
            {
                return;
            }

            object lSwitcherNode = await getSwitcher(lEncoderNode);

            if (lSwitcherNode == null)
            {
                return;
            }

            object lSourceNode = await getSourceNode(
                m_VideoSourceComboBox.SelectedItem as XmlNode,
                m_VideoStreamComboBox.SelectedItem as XmlNode,
                m_VideoSourceMediaTypeComboBox.SelectedItem as XmlNode,
                m_VideoEncodersComboBox.SelectedItem as XmlNode,
                m_VideoEncodingModeComboBox.SelectedItem as XmlNode,
                m_VideoCompressedMediaTypesComboBox.SelectedIndex,
                RenderNode,
                lSwitcherNode);

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

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

            if (mISession == null)
            {
                return;
            }

            await mSwitcherControl.pauseSwitchersAsync(mISession);

            if (await mISession.startSessionAsync(0, Guid.Empty))
            {
                mState = State.Started;

                mRecordingState = State.Paused;

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

                m_PauseBtn.IsEnabled = true;

                m_StopBtn.IsEnabled = true;

                m_StartStopBtn.IsEnabled = false;
            }
        }
Пример #11
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);
        }
Пример #12
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)
        {
            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 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();
            }
        }
        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;
        }
Пример #17
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 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;
        }
Пример #19
0
        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";

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

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

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

            if (lNode == null)
            {
                return;
            }

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

            int lWidthInBytes = await mCaptureManager.getStrideForBitmapInfoHeaderAsync(
                MFVideoFormat_RGB32,
                mVideoWidth);

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

            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='{759D24FF-C5D6-4B65-8DDF-8A2B2BECDE39}']");

            if (lSinkNode == null)
            {
                return;
            }

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

            if (lContainerNode == null)
            {
                return;
            }

            setContainerFormat(lContainerNode);

            mSinkFactory = await lSinkControl.createSampleGrabberCallSinkFactoryAsync(mReadMode);

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

            if (mISampleGrabberCall != null)
            {
                var lSampleGrabberCallNode = mISampleGrabberCall.getTopologyNode();

                if (lSampleGrabberCallNode == null)
                {
                    return;
                }

                object lPtrSourceNode;

                var lSourceControl = await mCaptureManager.createSourceControlAsync();

                if (lSourceControl == null)
                {
                    return;
                }

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

                    if (!string.IsNullOrWhiteSpace(lXMLstring))
                    {
                        ldoc.LoadXml(lXMLstring);
                    }

                    lXmlDataProvider.Document = ldoc;
                }

                mTimer.Start();
            }
        }
        private async void MAddImageBtn_Click(object sender, RoutedEventArgs e)
        {
            if (mAddImageSession != null)
            {
                await mAddImageSession.stopSessionAsync();

                await mAddImageSession.closeSessionAsync();

                mAddImageSession = null;

                mAddImageTxtBlk.Text = "Add Image";

                mVideoTopologyInputMixerNodes.Add(mImageVideoTopologyInputMixerNode);

                var lVideoMixerControlRelease = mCaptureManager.createVideoMixerControl();

                if (lVideoMixerControlRelease != null)
                {
                    lVideoMixerControlRelease.flush(mImageVideoTopologyInputMixerNode);
                }

                mImageVideoTopologyInputMixerNode = null;

                m_CameraPanel.IsEnabled = true;

                return;
            }

            var lOpenFileDialog = new Microsoft.Win32.OpenFileDialog();

            lOpenFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            lOpenFileDialog.Filter = "Image files (*.png, *.gif)|*.png;*.gif";

            bool l_result = (bool)lOpenFileDialog.ShowDialog();

            if (l_result &&
                File.Exists(lOpenFileDialog.FileName))
            {
                var lICaptureProcessor = ImageCaptureProcessor.createCaptureProcessor(lOpenFileDialog.FileName);

                if (lICaptureProcessor == null)
                {
                    return;
                }

                object lImageSourceSource = await mSourceControl.createSourceFromCaptureProcessorAsync(
                    lICaptureProcessor);

                var lVideoTopologyInputMixerNode = mVideoTopologyInputMixerNodes[0];

                mImageVideoTopologyInputMixerNode = lVideoTopologyInputMixerNode;

                mVideoTopologyInputMixerNodes.RemoveAt(0);

                object lImageSourceSourceNode = await mSourceControl.createSourceNodeFromExternalSourceWithDownStreamConnectionAsync(
                    lImageSourceSource,
                    0,
                    0,
                    lVideoTopologyInputMixerNode);


                object[] lSourceNodes = { lImageSourceSourceNode };

                mAddImageSession = await mISessionControl.createSessionAsync(lSourceNodes);

                if (mAddImageSession != null)
                {
                    mAddImageTxtBlk.Text = "Remove Camera";
                }

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


                var lVideoMixerControl = mCaptureManager.createVideoMixerControl();

                if (lVideoMixerControl != null)
                {
                    lVideoMixerControl.setPosition(lVideoTopologyInputMixerNode, 0.5f, 1.0f, 0.0f, 0.5f);
                }

                //if (lVideoMixerControl != null)
                //    lVideoMixerControl.setSrcPosition(lVideoTopologyInputMixerNode, 0.0f, 0.5f, 0.0f, 0.5f);

                if (lVideoMixerControl != null)
                {
                    lVideoMixerControl.setOpacity(lVideoTopologyInputMixerNode, 0.5f);
                }

                m_CameraPanel.IsEnabled = false;
            }
        }
Пример #21
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 Task init()
        {
            var lselectedNode = m_FileFormatComboBox.SelectedItem as XmlNode;

            if (lselectedNode == null)
            {
                return;
            }

            var lSelectedAttr = lselectedNode.Attributes["Value"];

            if (lSelectedAttr == null)
            {
                return;
            }

            String limageSourceDir = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);

            SaveFileDialog lsaveFileDialog = new SaveFileDialog();

            lsaveFileDialog.InitialDirectory = limageSourceDir;

            lsaveFileDialog.DefaultExt = "." + lSelectedAttr.Value.ToLower();

            lsaveFileDialog.AddExtension = true;

            lsaveFileDialog.CheckFileExists = false;

            lsaveFileDialog.Filter = "Media file (*." + lSelectedAttr.Value.ToLower() + ")|*." + lSelectedAttr.Value.ToLower();

            var lresult = lsaveFileDialog.ShowDialog();

            if (lresult != true)
            {
                return;
            }

            var lFilename = lsaveFileDialog.FileName;

            lSelectedAttr = lselectedNode.Attributes["GUID"];

            if (lSelectedAttr == null)
            {
                return;
            }

            mFileSinkFactory = await mSinkControl.createFileSinkFactoryAsync(Guid.Parse(lSelectedAttr.Value));



            string lScreenCaptureSymbolicLink = "CaptureManager///Software///Sources///ScreenCapture///ScreenCapture";

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


            // Video Source
            uint lVideoSourceIndexStream = 0;

            uint lVideoSourceIndexMediaType = 2;

            int l_VideoCompressedMediaTypeSelectedIndex = 0;



            // Audio Source
            uint lAudioSourceIndexStream = 0;

            uint lAudioSourceIndexMediaType = 0;


            int l_AudioCompressedMediaTypeSelectedIndex = 0;


            string l_EncodersXMLstring = await mEncoderControl.getCollectionOfEncodersAsync();


            XmlDocument doc = new XmlDocument();

            doc.LoadXml(l_EncodersXMLstring);

            var lAttrNode = doc.SelectSingleNode("EncoderFactories/Group[@GUID='{73646976-0000-0010-8000-00AA00389B71}']/EncoderFactory[1]/@CLSID");

            if (lAttrNode == null)
            {
                return;
            }

            Guid l_VideoEncoder = Guid.Empty;

            Guid.TryParse(lAttrNode.Value, out l_VideoEncoder);


            lAttrNode = doc.SelectSingleNode("EncoderFactories/Group[@GUID='{73647561-0000-0010-8000-00AA00389B71}']/EncoderFactory[1]/@CLSID");

            if (lAttrNode == null)
            {
                return;
            }

            Guid l_AudioEncoder = Guid.Empty;

            Guid.TryParse(lAttrNode.Value, out l_AudioEncoder);



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

            if (true)
            {
                object lCompressedMediaType = await getCompressedMediaType(
                    lScreenCaptureSymbolicLink,
                    lVideoSourceIndexStream,
                    lVideoSourceIndexMediaType,
                    l_VideoEncoder,
                    m_VideoEncoderMode,
                    l_VideoCompressedMediaTypeSelectedIndex);

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


            if (true)
            {
                object lCompressedMediaType = await getCompressedMediaType(
                    lAudioLoopBack,
                    lAudioSourceIndexStream,
                    lAudioSourceIndexMediaType,
                    l_AudioEncoder,
                    m_AudioEncoderMode,
                    l_AudioCompressedMediaTypeSelectedIndex);

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


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

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

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

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

            if (lEVROutputNode == null)
            {
                return;
            }


            object SpreaderNode = lEVROutputNode;

            if (true)
            {
                var lEncoderNode = await getEncoderNode(
                    lScreenCaptureSymbolicLink,
                    lVideoSourceIndexStream,
                    lVideoSourceIndexMediaType,
                    l_VideoEncoder,
                    m_VideoEncoderMode,
                    l_VideoCompressedMediaTypeSelectedIndex,
                    lOutputNodes[0]);

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

                lOutputNodeList.Add(lEncoderNode);

                lOutputNodeList.Add(lEVROutputNode);

                SpreaderNode = await mSpreaderNodeFactory.createSpreaderNodeAsync(
                    lOutputNodeList);

                //SpreaderNode = lEncoderNode;
            }



            var lMixerNodeFactory = await mStreamControl.createMixerNodeFactoryAsync();

            List <object> lVideoTopologyInputMixerNodes = await lMixerNodeFactory.createMixerNodesAsync(
                SpreaderNode,
                2);

            if (lVideoTopologyInputMixerNodes.Count == 0)
            {
                return;
            }

            for (int i = 1; i < lVideoTopologyInputMixerNodes.Count; i++)
            {
                mVideoTopologyInputMixerNodes.Add(lVideoTopologyInputMixerNodes[i]);
            }



            object lAudioEncoderNode = null;

            if (true)
            {
                lAudioEncoderNode = await getEncoderNode(
                    lAudioLoopBack,
                    lAudioSourceIndexStream,
                    lAudioSourceIndexMediaType,
                    l_AudioEncoder,
                    m_AudioEncoderMode,
                    l_AudioCompressedMediaTypeSelectedIndex,
                    lOutputNodes[1]);
            }


            List <object> lAudioTopologyInputMixerNodes = await lMixerNodeFactory.createMixerNodesAsync(
                lAudioEncoderNode,
                2);

            if (lAudioTopologyInputMixerNodes.Count == 0)
            {
                return;
            }

            mAudioTopologyInputMixerNode = lAudioTopologyInputMixerNodes[1];



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

            if (true)
            {
                object lSourceNode = await getSourceNode(
                    lScreenCaptureSymbolicLink,
                    lVideoSourceIndexStream,
                    lVideoSourceIndexMediaType,
                    lVideoTopologyInputMixerNodes[0]);

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



            if (true)
            {
                object lSourceNode = await getSourceNode(
                    lAudioLoopBack,
                    lAudioSourceIndexStream,
                    lAudioSourceIndexMediaType,
                    lAudioTopologyInputMixerNodes[0]);

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


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

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

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

                mSourcesPanel.IsEnabled = true;
            }
        }
Пример #23
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;
        }
Пример #24
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;
        }
Пример #25
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);
                    }
                }
            }
        }