コード例 #1
0
        public bool CreateCarriers(InboundRtpProtocol rtp, RtcpProtocol rtcp)
        {
            UDPCarrier pCarrier1 = null;
            UDPCarrier pCarrier2 = null;

            for (var i = 0; i < 10; i++)
            {
                if (pCarrier1 != null)
                {
                    pCarrier1.Dispose();
                    pCarrier1 = null;
                }
                if (pCarrier2 != null)
                {
                    pCarrier2.Dispose();
                    pCarrier2 = null;
                }

                pCarrier1 = UDPCarrier.Create("0.0.0.0", 0);
                if (pCarrier1 == null)
                {
                    WARN("Unable to create UDP carrier for RTP");
                    continue;
                }

                pCarrier2 = (pCarrier1.NearPort % 2) == 0 ? UDPCarrier.Create("0.0.0.0", pCarrier1.NearPort + 1) : UDPCarrier.Create("0.0.0.0", pCarrier1.NearPort - 1);

                if (pCarrier2 == null)
                {
                    WARN("Unable to create UDP carrier for RTCP");
                    continue;
                }

                if (pCarrier1.NearPort > pCarrier2.NearPort)
                {
                    WARN("Switch carriers");
                    UDPCarrier pTemp = pCarrier1;
                    pCarrier1 = pCarrier2;
                    pCarrier2 = pTemp;
                }
                pCarrier1.Protocol         = rtp.FarEndpoint;
                rtp.FarEndpoint.IOHandler  = pCarrier1;
                pCarrier2.Protocol         = rtcp.FarEndpoint;
                rtcp.FarEndpoint.IOHandler = pCarrier2;
                return(pCarrier1.StartAccept() | pCarrier2.StartAccept());
            }

            if (pCarrier1 != null)
            {
                pCarrier1.Dispose();
                pCarrier1 = null;
            }
            if (pCarrier2 != null)
            {
                pCarrier2.Dispose();
                pCarrier2 = null;
            }

            return(false);
        }
コード例 #2
0
 public void Cleanup()
 {
     _audioTrack = null;
     _videoTrack = null;
     _protocols.Clear();
     if (_rtpVideo != null)
     {
         _rtpVideo.SetStream(null, false);
         _rtpVideo.EnqueueForDelete();
         _rtpVideo = null;
     }
     if (_rtpAudio != null)
     {
         _rtpAudio.SetStream(null, true);
         _rtpAudio.EnqueueForDelete();
         _rtpAudio = null;
     }
     if (_rtcpVideo != null)
     {
         _rtcpVideo.EnqueueForDelete();
         _rtcpVideo = null;
     }
     if (_rtcpAudio != null)
     {
         _rtcpAudio.EnqueueForDelete();
         _rtcpAudio = null;
     }
 }
コード例 #3
0
        public bool AddTrack(Variant track, bool isAduio)
        {
            var _track         = isAduio ? _audioTrack : _videoTrack;
            var _oppositeTrack = isAduio ? _videoTrack : _audioTrack;

            var rr = isAduio ? _audioRR : _videoRR;

            if (_track != null)
            {
                return(false);
            }
            var application = _rtsp.Application;

            if (application == null)
            {
                FATAL("RTSP protocol not yet assigned to an application");
                return(false);
            }
            if (isAduio)
            {
                _audioTrack = track;
            }
            else
            {
                _videoTrack = track;
            }
            _track = track;
            if (_oppositeTrack != null)
            {
                if (_oppositeTrack["isTcp"] != _track["isTcp"])
                {
                    return(false);
                }
            }
            _forceTcp = _track["isTcp"];
            var dummy = new Variant();
            var rtp   = (InboundRtpProtocol)ProtocolFactoryManager.CreateProtocolChain(Defines.CONF_PROTOCOL_INBOUND_UDP_RTP, dummy);

            if (rtp == null)
            {
                FATAL("Unable to create the protocol chain");
                Cleanup();
                return(false);
            }
            if (isAduio)
            {
                _rtpAudio = rtp;
            }
            else
            {
                _rtpVideo = rtp;
            }
            var rtcp = (RtcpProtocol)ProtocolFactoryManager.CreateProtocolChain(Defines.CONF_PROTOCOL_UDP_RTCP, dummy);

            if (rtcp == null)
            {
                FATAL("Unable to create the protocol chain");
                Cleanup();
                return(false);
            }
            if (isAduio)
            {
                _rtcpAudio = rtcp;
            }
            else
            {
                _rtcpVideo = rtcp;
            }
            if (_track["isTcp"])
            {
                var dataIdx = 0u;
                var rtcpIdx = 0u;
                if (_track["portsOrChannels", "data"] && _track["portsOrChannels", "rtcp"])
                {
                    dataIdx = _track["portsOrChannels", "data"];
                    rtcpIdx = _track["portsOrChannels", "rtcp"];
                }
                else
                {
                    dataIdx = (uint)(_track["globalTrackIndex"] * 2);
                    rtcpIdx = dataIdx + 1;
                }

                if ((dataIdx >= 256) || (rtcpIdx >= 256))
                {
                    FATAL("Invalid channel numbers");
                    return(false);
                }
                if (_protocols.ContainsKey(dataIdx) || _protocols.ContainsKey(rtcpIdx))
                {
                    FATAL("Invalid channel numbers");
                    return(false);
                }
                _protocols[dataIdx] = rtp;
                _protocols[rtcpIdx] = rtcp;
                rr.Write(8, rtp.SSRC);   //SSRC of packet sender
                rr.Write(40, rtcp.SSRC); //SSRC of packet sender

                rr[1] = (byte)rtcpIdx;
            }
            else
            {
                if (!CreateCarriers(rtp, rtcp))
                {
                    FATAL("Unable to create carriers");
                    return(false);
                }
            }
            rtp.Application  = application;
            rtcp.Application = application;
            return(true);
        }
コード例 #4
0
        public override BaseProtocol SpawnProtocol(ulong type, Variant parameters)
        {
            BaseProtocol pResult = null;
            switch (type)
            {
                case ProtocolTypes.PT_TCP:
                    pResult = new TCPProtocol();
                    break;
                case ProtocolTypes.PT_UDP:
                    pResult = new UDPProtocol();
                    break;
                case ProtocolTypes.PT_INBOUND_SSL:
                    pResult = new InboundSSLProtocol();
                    break;
                case ProtocolTypes.PT_OUTBOUND_SSL:
                    pResult = new OutboundSSLProtocol();
                    break;
                case ProtocolTypes.PT_INBOUND_RTMP:
                    pResult = new InboundRTMPProtocol();
                    break;
                case ProtocolTypes.PT_INBOUND_RTMPS_DISC:
                    break;
                case ProtocolTypes.PT_OUTBOUND_RTMP:
                    pResult = new OutboundRTMPProtocol();
                    break;
                case ProtocolTypes.PT_INBOUND_RTMFP:
                    pResult = new InboundRTMFPProtocol();
                    break;
                case ProtocolTypes.PT_INBOUND_CLUSTER:
                    pResult = new InboundClusterProtocol();
                    break;
                case ProtocolTypes.PT_OUTBOUND_CLUSTER:
                    pResult = new OutboundClusterProtocol();
                    break;
                case ProtocolTypes.PT_RTSP:
                    pResult = new RtspProtocol();
                    break;
                case ProtocolTypes.PT_RTP_NAT_TRAVERSAL:
                    pResult = new NATTraversalProtocol();
                    break;
                case ProtocolTypes.PT_INBOUND_RTP:
                    pResult = new InboundRtpProtocol();
                    break;
                case ProtocolTypes.PT_RTCP:
                    pResult = new RtcpProtocol();
                    break;
                case ProtocolTypes.PT_INBOUND_WEBSOCKET:
                    pResult = new WebSocketProtocol();
                    break;
                case ProtocolTypes.PT_INBOUND_WEBRTC_SIGNAL:
                    pResult = new WebRtcSignalProtocol();
                    break;
                case ProtocolTypes.PT_INBOUND_MP4:
                    pResult = new Mp4Protocol();
                    break;
                default:
                    Logger.FATAL("Spawning protocol {0} not yet implemented",
                        type.TagToString());
                    break;
            }
            if (pResult != null)
            {
                if (!pResult.Initialize(parameters))
                {
                    Logger.FATAL("Unable to initialize protocol {0}",
                            type.TagToString());

                    pResult = null;
                }
            }
            return pResult;
        }
コード例 #5
0
        public bool AddTrack(Variant track, bool isAduio)
        {
            var _track = isAduio ? _audioTrack : _videoTrack;
            var _oppositeTrack = isAduio ? _videoTrack : _audioTrack;
            
            var rr = isAduio ? _audioRR : _videoRR;
            if (_track != null) return false;
            var application = _rtsp.Application;
            if (application == null)
            {
                FATAL("RTSP protocol not yet assigned to an application");
                return false;
            }
            if (isAduio)  _audioTrack = track;
            else  _videoTrack= track;
            _track = track;
            if (_oppositeTrack != null)
            {
                if (_oppositeTrack["isTcp"] != _track["isTcp"])
                    return false;
            }
            _forceTcp = _track["isTcp"];
            var dummy = new Variant();
            var rtp = (InboundRtpProtocol)ProtocolFactoryManager.CreateProtocolChain(Defines.CONF_PROTOCOL_INBOUND_UDP_RTP, dummy);
            if (rtp == null)
            {
                FATAL("Unable to create the protocol chain");
                Cleanup();
                return false;
            }
            if (isAduio) _rtpAudio = rtp;
            else _rtpVideo = rtp;
            var rtcp = (RtcpProtocol)ProtocolFactoryManager.CreateProtocolChain(Defines.CONF_PROTOCOL_UDP_RTCP, dummy);
            if (rtcp == null)
            {
                FATAL("Unable to create the protocol chain");
                Cleanup();
                return false;
            }
            if (isAduio) _rtcpAudio = rtcp;
            else _rtcpVideo = rtcp;
            if (_track["isTcp"])
            {
                var dataIdx = 0u;
                var rtcpIdx = 0u;
                if (_track["portsOrChannels", "data"] && _track["portsOrChannels", "rtcp"])
                {
                    dataIdx = _track["portsOrChannels", "data"];
                    rtcpIdx = _track["portsOrChannels", "rtcp"];
                }
                else
                {
                    dataIdx =(uint) (_track["globalTrackIndex"]*2);
                    rtcpIdx = dataIdx + 1;
                }

                if ((dataIdx >= 256) || (rtcpIdx >= 256))
                {
                    FATAL("Invalid channel numbers");
                    return false;
                }
                if (_protocols.ContainsKey(dataIdx) || _protocols.ContainsKey(rtcpIdx))
                {
                    FATAL("Invalid channel numbers");
                    return false;
                }
                _protocols[dataIdx] = rtp;
                _protocols[rtcpIdx] = rtcp;
                rr.Write(8, rtp.SSRC);//SSRC of packet sender
                rr.Write(40, rtcp.SSRC); //SSRC of packet sender
             
                rr[1] = (byte) rtcpIdx;
            }
            else
            {
                if (!CreateCarriers(rtp, rtcp))
                {
                    FATAL("Unable to create carriers");
                    return false;
                }
            }
            rtp.Application = application;
            rtcp.Application = application;
            return true;
        }
コード例 #6
0
        public bool CreateCarriers(InboundRtpProtocol rtp, RtcpProtocol rtcp)
        {
            UDPCarrier pCarrier1 = null;
            UDPCarrier pCarrier2 = null;
            for (var i = 0; i < 10; i++)
            {
                if (pCarrier1 != null)
                {
                    pCarrier1.Dispose();
                    pCarrier1 = null;
                }
                if (pCarrier2 != null)
                {
                    pCarrier2.Dispose();
                       pCarrier2 = null;
                }

                pCarrier1 = UDPCarrier.Create("0.0.0.0", 0);
                if (pCarrier1 == null)
                {
                    WARN("Unable to create UDP carrier for RTP");
                    continue;
                }

                pCarrier2 = (pCarrier1.NearPort % 2) == 0 ? UDPCarrier.Create("0.0.0.0",pCarrier1.NearPort + 1) : UDPCarrier.Create("0.0.0.0", pCarrier1.NearPort - 1);

                if (pCarrier2 == null)
                {
                    WARN("Unable to create UDP carrier for RTCP");
                    continue;
                }

                if (pCarrier1.NearPort > pCarrier2.NearPort)
                {
                    WARN("Switch carriers");
                    UDPCarrier pTemp = pCarrier1;
                    pCarrier1 = pCarrier2;
                    pCarrier2 = pTemp;
                }
                pCarrier1.Protocol = rtp.FarEndpoint;
                rtp.FarEndpoint.IOHandler = pCarrier1;
                pCarrier2.Protocol = rtcp.FarEndpoint;
                rtcp.FarEndpoint.IOHandler = pCarrier2;
                return pCarrier1.StartAccept() | pCarrier2.StartAccept();
            }

            if (pCarrier1 != null)
            {
                pCarrier1.Dispose();
                pCarrier1 = null;
            }
            if (pCarrier2 != null)
            {
                pCarrier2.Dispose();
                pCarrier2 = null;
            }

            return false;
        }
コード例 #7
0
 public void Cleanup()
 {
     _audioTrack = null;
     _videoTrack = null;
     _protocols.Clear();
     if (_rtpVideo != null)
     {
         _rtpVideo.SetStream(null, false);
         _rtpVideo.EnqueueForDelete();
         _rtpVideo = null;
     }
     if (_rtpAudio != null)
     {
         _rtpAudio.SetStream(null, true);
         _rtpAudio.EnqueueForDelete();
         _rtpAudio = null;
     }
     if (_rtcpVideo != null)
     {
         _rtcpVideo.EnqueueForDelete();
         _rtcpVideo = null;
     }
     if (_rtcpAudio != null)
     {
         _rtcpAudio.EnqueueForDelete();
         _rtcpAudio = null;
     }
 }