static public ICaptureProcessor createCaptureProcessor(string a_URL)
        {
            string lPresentationDescriptor = "<?xml version='1.0' encoding='UTF-8'?>" +
                                             "<PresentationDescriptor StreamCount='1'>" +
                                             "<PresentationDescriptor.Attributes Title='Attributes of Presentation'>" +
                                             "<Attribute Name='MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK' GUID='{58F0AAD8-22BF-4F8A-BB3D-D2C4978C6E2F}' Title='The symbolic link for a video capture driver.' Description='Contains the unique symbolic link for a video capture driver.'>" +
                                             "<SingleValue Value='RTSPCaptureProcessor' />" +
                                             "</Attribute>" +
                                             "<Attribute Name='MF_DEVSOURCE_ATTRIBUTE_FRIENDLY_NAME' GUID='{60D0E559-52F8-4FA2-BBCE-ACDB34A8EC01}' Title='The display name for a device.' Description='The display name is a human-readable string, suitable for display in a user interface.'>" +
                                             "<SingleValue Value='RTSP Capture Processor' />" +
                                             "</Attribute>" +
                                             "</PresentationDescriptor.Attributes>" +
                                             "<StreamDescriptor Index='0' MajorType='MFMediaType_Video' MajorTypeGUID='{73646976-0000-0010-8000-00AA00389B71}'>" +
                                             "<MediaTypes TypeCount='1'>" +
                                             "<MediaType Index='0'>" +
                                             "<MediaTypeItem Name='MF_MT_MAJOR_TYPE' GUID='{48EBA18E-F8C9-4687-BF11-0A74C9F96A8F}' Title='Major type GUID for a media type.' Description='The major type defines the overall category of the media data.'>" +
                                             "<SingleValue Value='MFMediaType_Video' GUID='{73646976-0000-0010-8000-00AA00389B71}' />" +
                                             "</MediaTypeItem>" +
                                             "<MediaTypeItem Name='CM_DIRECT_CALL' GUID='{DD0570F7-0D02-4897-A55E-F65BFACA1955}' Title='Independent of samples.' Description='Specifies for a media type whether each sample is independent of the other samples in the stream.'>" +
                                             "<SingleValue Value='True' />" +
                                             "</MediaTypeItem>" +
                                             "<MediaTypeItem Name='MF_MT_SUBTYPE' GUID='{F7E34C9A-42E8-4714-B74B-CB29D72C35E5}' Title='Subtype GUID for a media type.' Description='The subtype GUID defines a specific media format type within a major type.'>" +
                                             "<SingleValue GUID='{Temp_SubTypeGUID}' />" +
                                             "</MediaTypeItem>" +
                                             "</MediaType>" +
                                             "</MediaTypes>" +
                                             "</StreamDescriptor>" +
                                             "</PresentationDescriptor>";

            RTSPCaptureProcessor lICaptureProcessor = new RTSPCaptureProcessor();

            lICaptureProcessor.mURL = a_URL;


            // The SPS/PPS comes from the SDP data
            // or it is the first SPS/PPS from the H264 video stream
            lICaptureProcessor.m_client.Received_SPS_PPS += (byte[] sps, byte[] pps) =>
            {
                if (lICaptureProcessor.mISourceRequestResult != null)
                {
                    lICaptureProcessor.m_proxyMemory.Position = 0;

                    lICaptureProcessor.m_proxyMemory.Write(new byte[] { 0x00, 0x00, 0x00, 0x01 }, 0, 4);  // Write Start Code
                    lICaptureProcessor.m_proxyMemory.Write(sps, 0, sps.Length);
                    lICaptureProcessor.m_proxyMemory.Write(new byte[] { 0x00, 0x00, 0x00, 0x01 }, 0, 4);  // Write Start Code
                    lICaptureProcessor.m_proxyMemory.Write(pps, 0, pps.Length);

                    var ldata = lICaptureProcessor.m_proxyMemory.ToArray();

                    IntPtr lptrData = Marshal.AllocHGlobal(ldata.Length);

                    Marshal.Copy(ldata, 0, lptrData, ldata.Length);

                    lICaptureProcessor.mISourceRequestResult.setData(lptrData, (uint)ldata.Length, 1);

                    Marshal.FreeHGlobal(lptrData);
                }

                Thread.Sleep(250);
            };

            // Video NALs. May also include the SPS and PPS in-band for H264
            lICaptureProcessor.m_client.Received_NALs += (List <byte[]> nal_units) =>
            {
                foreach (byte[] nal_unit in nal_units)
                {
                    lICaptureProcessor.write(nal_unit);

                    lICaptureProcessor.mLockWrite.WaitOne();

                    lICaptureProcessor.mLockWrite.Reset();

                    if (lICaptureProcessor.mISourceRequestResult == null)
                    {
                        break;
                    }
                }
            };


            lPresentationDescriptor = lPresentationDescriptor.Replace("Temp_SubTypeGUID", MFVideoFormat_H264.ToString());

            lICaptureProcessor.mPresentationDescriptor = lPresentationDescriptor;

            return(lICaptureProcessor);
        }
Exemplo n.º 2
0
        private async void mLaunchButton_Click(object sender, RoutedEventArgs e)
        {
            mLaunchButton.IsEnabled = false;

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

                        mLaunchButton.Content = "Launch";
                    }

                    mISession = null;

                    break;
                }

                if (mISourceControl == null)
                {
                    break;
                }

                ICaptureProcessor lICaptureProcessor = null;

                try
                {
                    lICaptureProcessor = RTSPCaptureProcessor.createCaptureProcessor(mRTSPSourceComboBox.Text);
                }
                catch (System.Exception exc)
                {
                    MessageBox.Show(exc.Message);

                    break;
                }

                if (lICaptureProcessor == null)
                {
                    break;
                }

                object lMediaSource = await mISourceControl.createSourceFromCaptureProcessorAsync(
                    lICaptureProcessor);

                if (lMediaSource == null)
                {
                    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.createSourceNodeFromExternalSourceWithDownStreamConnectionAsync(
                    lMediaSource,
                    0,
                    0,
                    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.registerUpdateStateDelegateAsync(UpdateStateDelegate);

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

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

            mLaunchButton.IsEnabled = true;
        }