Exemplo n.º 1
0
        //public double MaxSendRate { get; protected set; }

        //Fix

        public void SendData(byte[] data)
        {
            if (RtpClient != null)
            {
                RtpClient.OnRtpPacketReceieved(new Rtp.RtpPacket(data, 0));
            }
        }
Exemplo n.º 2
0
 public void SendReports()
 {
     if (RtpClient != null)
     {
         RtpClient.SendReports();
     }
 }
Exemplo n.º 3
0
 public VoiceIn(CodecInfo codec, RtpClient client, TransmitPredicate predicate)
 {
     _codec     = codec;
     _client    = client;
     _predicate = predicate;
     this.InitAudio();
 }
Exemplo n.º 4
0
        public void SendData(byte[] data, int offset = 0, int length = -1)
        {
            if (Common.IDisposedExtensions.IsNullOrDisposed(RtpClient))
            {
                return;
            }

            RtpClient.OnRtpPacketReceieved(new Rtp.RtpPacket(data, offset, length >= 0 ? length : data.Length - offset));
        }
Exemplo n.º 5
0
        public void SendReports()
        {
            if (Common.IDisposedExtensions.IsNullOrDisposed(RtpClient))
            {
                return;
            }

            RtpClient.SendReports();
        }
Exemplo n.º 6
0
 public override void Dispose()
 {
     if (IsDisposed)
     {
         return;
     }
     base.Dispose();
     if (RtpClient != null)
     {
         RtpClient.Dispose();
     }
 }
Exemplo n.º 7
0
        //

        public void SendPacket(Common.IPacket packet)
        {
            if (RtpClient != null)
            {
                if (packet is Rtp.RtpPacket)
                {
                    RtpClient.OnRtpPacketReceieved(packet as Rtp.RtpPacket);
                }
                else if (packet is Rtcp.RtcpPacket)
                {
                    RtpClient.OnRtcpPacketReceieved(packet as Rtcp.RtcpPacket);
                }
            }
        }
Exemplo n.º 8
0
        public override void Stop()
        {
            //Remove handler
            if (State == StreamState.Started)
            {
                if (RtpClient != null)
                {
                    RtpClient.Disconnect();
                }

                base.Ready = false;

                base.Stop();
            }
        }
Exemplo n.º 9
0
        public override void Start()
        {
            //Add handler for frame events
            if (State == StreamState.Stopped)
            {
                if (RtpClient != null)
                {
                    RtpClient.Activate();

                    base.Ready = true;

                    base.Start();
                }
            }
        }
Exemplo n.º 10
0
        public void SendPacket(Common.IPacket packet)
        {
            if (Common.IDisposedExtensions.IsNullOrDisposed(RtpClient) ||
                Common.IDisposedExtensions.IsNullOrDisposed(packet))
            {
                return;
            }

            if (packet is Rtp.RtpPacket)
            {
                RtpClient.OnRtpPacketReceieved(packet as Rtp.RtpPacket);
            }
            else if (packet is Rtcp.RtcpPacket)
            {
                RtpClient.OnRtcpPacketReceieved(packet as Rtcp.RtcpPacket);
            }
        }
Exemplo n.º 11
0
        //Todo, cleanup and allow existing Rtp and Rtcp socket.

        /// <summary>
        /// Will create a <see cref="RtpClient"/> based on the given parameters
        /// </summary>
        /// <param name="sessionDescription"></param>
        /// <param name="sharedMemory"></param>
        /// <param name="incomingEvents"></param>
        /// <param name="rtcpEnabled"></param>
        /// <returns></returns>
        public static RtpClient FromSessionDescription(Sdp.SessionDescription sessionDescription, Common.MemorySegment sharedMemory = null, bool incomingEvents = true, bool rtcpEnabled = true, System.Net.Sockets.Socket existingSocket = null, int?rtpPort = null, int?rtcpPort = null, int remoteSsrc = 0, int minimumSequentialRtpPackets = 2, bool connect = true, System.Action <System.Net.Sockets.Socket> configure = null)
        {
            if (Common.IDisposedExtensions.IsNullOrDisposed(sessionDescription))
            {
                throw new System.ArgumentNullException("sessionDescription");
            }

            Sdp.Lines.SessionConnectionLine connectionLine = new Sdp.Lines.SessionConnectionLine(sessionDescription.ConnectionLine);

            System.Net.IPAddress remoteIp = System.Net.IPAddress.Parse(connectionLine.Host), localIp;

            System.Net.NetworkInformation.NetworkInterface localInterface;

            //If the socket is NOT null and IS BOUND use the localIp of the same address family
            if (object.ReferenceEquals(existingSocket, null).Equals(false) && existingSocket.IsBound)
            {
                //If the socket is IP based
                if (existingSocket.LocalEndPoint is System.Net.IPEndPoint)
                {
                    //Take the localIp from the LocalEndPoint
                    localIp = (existingSocket.LocalEndPoint as System.Net.IPEndPoint).Address;
                }
                else
                {
                    throw new System.NotSupportedException("Please create an issue for your use case.");
                }
            }
            else // There is no socket existing.
            {
                //If the remote address is the broadcast address or the remote address is multicast
                if (System.Net.IPAddress.Broadcast.Equals(remoteIp) || Common.Extensions.IPAddress.IPAddressExtensions.IsMulticast(remoteIp))
                {
                    //This interface should be the interface you plan on using for the Rtp communication
                    localIp = Media.Common.Extensions.Socket.SocketExtensions.GetFirstMulticastIPAddress(remoteIp.AddressFamily, out localInterface);
                }
                else
                {
                    //This interface should be the interface you plan on using for the Rtp communication
                    localIp = Media.Common.Extensions.Socket.SocketExtensions.GetFirstUnicastIPAddress(remoteIp.AddressFamily, out localInterface);
                }
            }

            RtpClient client = new RtpClient(sharedMemory, incomingEvents);

            byte lastChannel = 0;

            //Todo, check for session level ssrc
            //if (remoteSsrc.Equals(0))
            //{
            //    //Sdp.SessionDescriptionLine ssrcLine = sessionDescription.SsrcGroupLine; // SsrcLine @ the session level could imply Group
            //}

            //For each MediaDescription in the SessionDescription
            foreach (Media.Sdp.MediaDescription md in sessionDescription.MediaDescriptions)
            {
                //Make a RtpClient.TransportContext from the MediaDescription being parsed.
                TransportContext tc = TransportContext.FromMediaDescription(sessionDescription, lastChannel++, lastChannel++, md,
                                                                            rtcpEnabled, remoteSsrc, minimumSequentialRtpPackets,
                                                                            localIp, remoteIp, //The localIp and remoteIp
                                                                            rtpPort, rtcpPort, //The remote ports to receive data from
                                                                            connect, existingSocket, configure);

                //Try to add the context
                try
                {
                    client.AddContext(tc);
                }
                catch (System.Exception ex)
                {
                    Media.Common.TaggedExceptionExtensions.RaiseTaggedException(tc, "See Tag, Could not add the created TransportContext.", ex);
                }
            }

            //Return the participant
            return(client);
        }