Exemple #1
0
        public RTSPChannel(RTSPChannelParameters parameters)
        {
            Parameters = parameters;

            unicastUdpClient = new UnicastUdpClient(Parameters.RTPPort);
            rtpPacketHandler = new RtpPacketHandler(parameters.SSRT);

            unicastUdpClient.UdpPacketRecived += rtpPacketHandler.HandleRtpPacket;
            payloadHandler = PayloadHandlerFactory.Create(Parameters.Codec);

            rtpPacketHandler.RtpPacketRecieved += payloadHandler.HandleRtpPacket;
            payloadHandler.FrameReceived       += PayloadHandler_FrameRecived;

            rtcpReporter = new RtcpReporter(Parameters.RTCPPort, Parameters.SampleRate);

            rtpPacketHandler.RtpPacketRecieved += rtcpReporter.HandleRtpPacket;
            rtcpReporter.RtpTimeReporting      += videoRtcpClient_OnRtpTimeReporting;

            rtcpReporter.SessionTimeCorrecting += videoRtcpClient_OnRtpTimeCorrecting;
        }
Exemple #2
0
        public RTSPChannel(RTSPChannelParameters parameters)
        {
            Parameters = parameters;

            unicastUdpClient = new UnicastUdpClient(Parameters.RTPPort);
            rtpPacketHandler = new RtpPacketHandler(parameters.SSRT);

            unicastUdpClient.UdpPacketRecived += rtpPacketHandler.HandleRtpPacket;
            payloadHandler = PayloadHandlerFactory.Create(Parameters.Codec);

            rtpPacketHandler.RtpPacketRecieved += payloadHandler.HandleRtpPacket;
            payloadHandler.FrameReceived += PayloadHandler_FrameRecived;

            rtcpReporter = new RtcpReporter(Parameters.RTCPPort, Parameters.SampleRate);

            rtpPacketHandler.RtpPacketRecieved += rtcpReporter.HandleRtpPacket;
            rtcpReporter.RtpTimeReporting += videoRtcpClient_OnRtpTimeReporting;

            rtcpReporter.SessionTimeCorrecting += videoRtcpClient_OnRtpTimeCorrecting;
        }
        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();
        }
        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();
        }