Пример #1
0
        public static string GetCodec(this SDP sdp, string MediaType)
        {
            string codec = string.Empty;

            MediaDescription description = sdp.Session.GetMediaDescriptionByName(MediaType);

            string attribute = description.GetAttributeValueByName("rtpmap");

            if (string.IsNullOrEmpty(attribute) == false)
            {
                string[] split = attribute.Split(' ');
                if (split.Length == 2)
                {
                    string[] values = split[1].Split('/');
                    codec = values[0];
                }
            }
            return(codec);
        }
Пример #2
0
        public static int GetSampleRate(this SDP sdp, string MediaType)
        {
            int result = int.MaxValue;

            MediaDescription description = sdp.Session.GetMediaDescriptionByName(MediaType);

            string attribute = description.GetAttributeValueByName("rtpmap");

            if (string.IsNullOrEmpty(attribute) == false)
            {
                string[] split = attribute.Split(' ');
                if (split.Length == 2)
                {
                    string[] values = split[1].Split('/');
                    string   str    = values[1];

                    int.TryParse(str, out result);
                }
            }

            return(result);
        }
Пример #3
0
 public static string GetControl(this SDP sdp, string MediaType)
 {
     return(sdp.Session.GetMediaDescriptionByName(MediaType).GetAttributeValueByName("control"));
 }
Пример #4
0
        public void Start()
        {
            RTSPChannelParameters videoParameters = new RTSPChannelParameters {
            };
            RTSPChannelParameters audioParameters = new RTSPChannelParameters {
            };

            rtspSession = RTSPSession.Open(this.MediaDevice.ONVIF.GetCurrentMediaProfileRtspStreamUri().AbsoluteUri);
            //rtspSession.RTSPServerResponse += new RTSPSession.RTSPResponseHandler(rtsp_RTSPServerResponse);


            // OPTIONS возвращает команды сервера
            // OPTIONS, DESCRIBE, SETUP, PLAY, PAUSE, GET_PARAMETER, TEARDOWN, SET_PARAMETER
            RTSPResponse respons = rtspSession.Options();

            // DESCRIBE возвращает SDP файл
            respons = rtspSession.Describe();

            string ContentBase = respons.ContentBase;

            // Парсим SDP пакет
            sdp = SDP.Parse(respons.Body);
            videoParameters.Codec      = sdp.GetCodec(MediaType: "video");
            videoParameters.SampleRate = sdp.GetSampleRate(MediaType: "video");

            string VideoControl = sdp.GetControl(MediaType: "video");

            audioParameters.Codec      = sdp.GetCodec(MediaType: "audio");
            audioParameters.SampleRate = sdp.GetSampleRate(MediaType: "audio");

            string AudioControl = sdp.GetControl(MediaType: "audio");

            string VideoSetupUri = String.Format("{0}{1}", ContentBase, VideoControl);
            string AudioSetupUri = String.Format("{0}{1}", ContentBase, AudioControl);

            int[] ports = GetPortRange(4);

            videoParameters.RTPPort  = ports[0];
            videoParameters.RTCPPort = ports[1];

            audioParameters.RTPPort  = ports[2];
            audioParameters.RTCPPort = ports[3];


            respons = rtspSession.Setup(VideoSetupUri, videoParameters.RTPPort, videoParameters.RTCPPort);
            rtspSession.Parameters.Session = respons.Session;

            videoParameters.SSRT = respons.SSRT;

            respons = rtspSession.Setup(AudioSetupUri, audioParameters.RTPPort, audioParameters.RTCPPort, rtspSession.Parameters.Session);

            audioParameters.SSRT = respons.SSRT;


            respons = rtspSession.Play(rtspSession.Parameters.Session);

            videoChannel = new RTSPChannel(videoParameters);
            audioChannel = new RTSPChannel(audioParameters);

            //audioChannel.DataRecieved += MediaDevice.AVProcessor.AudioDataRecieved;
            //videoChannel.DataRecieved += MediaDevice.AVProcessor.VideoDataRecieved;

            audioChannel.DataRecieved += MediaDevice.Decoder.AudioDataRecieved;
            videoChannel.DataRecieved += MediaDevice.Decoder.VideoDataRecieved;

            videoChannel.StartRecieving();
            audioChannel.StartRecieving();
        }