private async Task <object> createImageSource()
        {
            object l_source = null;

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

                    l_source = await mSourceControl.createSourceFromCaptureProcessorAsync(
                        lICaptureProcessor);
                }
            } while (false);

            return(l_source);
        }
        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;
            }
        }
        private async void lButton_Click(object sender, RoutedEventArgs e)
        {
            var lButton = (Button)sender;

            do
            {
                if (mSourceControl == null)
                {
                    return;
                }

                if (mISessions == null)
                {
                    break;
                }

                if (lButton.Tag == null)
                {
                    break;
                }

                int lIndex = (int)lButton.Tag;

                if (lButton.Content == "Stop")
                {
                    if (mISessions.ContainsKey(lIndex))
                    {
                        await mISessions[lIndex].closeSessionAsync();

                        mISessions.Remove(lIndex);

                        lButton.Content = "Start";
                    }

                    break;
                }

                ICaptureProcessor lICaptureProcessor = null;

                try
                {
                    lICaptureProcessor = IPCameraMJPEGCaptureProcessor.createCaptureProcessor(URLs[lIndex % 2]);
                }
                catch (System.Exception exc)
                {
                    MessageBox.Show(exc.Message);

                    return;
                }

                if (lICaptureProcessor == null)
                {
                    return;
                }

                object lMediaSource = await mSourceControl.createSourceFromCaptureProcessorAsync(
                    lICaptureProcessor);

                if (lMediaSource == null)
                {
                    return;
                }



                var lSourceControl = await mCaptureManager.createSourceControlAsync();

                if (lSourceControl == null)
                {
                    return;
                }


                object lPtrSourceNode = await lSourceControl.createSourceNodeFromExternalSourceWithDownStreamConnectionAsync(
                    lMediaSource,
                    0,
                    0,
                    mEVROutputNodes[lIndex]);


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

                lSourceMediaNodeList.Add(lPtrSourceNode);

                var lSessionControl = await mCaptureManager.createSessionControlAsync();

                if (lSessionControl == null)
                {
                    return;
                }

                var lISession = await lSessionControl.createSessionAsync(
                    lSourceMediaNodeList.ToArray());

                if (lISession == null)
                {
                    return;
                }


                await lISession.registerUpdateStateDelegateAsync(UpdateStateDelegate);

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

                mISessions[lIndex] = lISession;

                lButton.Content = "Stop";
            } while (false);
        }
예제 #4
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 Task <object> getCompressedMediaType(
            ICaptureProcessor a_ICaptureProcessor,
            int a_StreamIndex,
            int a_MediaTypeIndex,
            XmlNode aEncoderNode,
            XmlNode aEncoderModeNode,
            int aCompressedMediaTypeIndex)
        {
            object lresult = null;

            do
            {
                if (aCompressedMediaTypeIndex < 0)
                {
                    break;
                }

                object lMediaSource = await mSourceControl.createSourceFromCaptureProcessorAsync(a_ICaptureProcessor);

                if (lMediaSource == null)
                {
                    break;
                }

                if (a_StreamIndex < 0)
                {
                    break;
                }

                if (a_MediaTypeIndex < 0)
                {
                    break;
                }

                if (aEncoderNode == null)
                {
                    break;
                }


                if (aEncoderModeNode == null)
                {
                    break;
                }

                var lEncoderGuidAttr = aEncoderNode.Attributes["CLSID"];

                if (lEncoderGuidAttr == null)
                {
                    break;
                }

                Guid lCLSIDEncoder;

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

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

                if (lEncoderModeGuidAttr == null)
                {
                    break;
                }

                Guid lCLSIDEncoderMode;

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

                uint lStreamIndex = (uint)a_StreamIndex;

                uint lMediaTypeIndex = (uint)a_MediaTypeIndex;

                object lSourceMediaType = await mSourceControl.getSourceOutputMediaTypeFromMediaSourceAsync(
                    lMediaSource,
                    lStreamIndex,
                    lMediaTypeIndex);

                if (lSourceMediaType == null)
                {
                    break;
                }

                var lEncoderNodeFactory = await mEncoderControl.createEncoderNodeFactoryAsync(lCLSIDEncoder);

                if (lEncoderNodeFactory == null)
                {
                    break;
                }

                lresult = await lEncoderNodeFactory.createCompressedMediaTypeAsync(
                    lSourceMediaType,
                    lCLSIDEncoderMode,
                    50,
                    (uint)aCompressedMediaTypeIndex);
            } while (false);

            return(lresult);
        }