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