Ejemplo n.º 1
0
        /// <summary>
        /// Sends specified RTP packet to the session remote party.
        /// </summary>
        /// <param name="stream">RTP packet sending stream.</param>
        /// <param name="packet">RTP packet.</param>
        /// <returns>Returns packet size in bytes.</returns>
        /// <exception cref="ObjectDisposedException">Is raised when this class is Disposed and this method is accessed.</exception>
        /// <exception cref="ArgumentNullException">Is raised when <b>stream</b> or <b>packet</b> is null reference.</exception>
        internal int SendRtpPacket(RTP_SendStream stream, RTP_Packet packet)
        {
            if (m_IsDisposed)
            {
                throw new ObjectDisposedException(GetType().Name);
            }
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            if (packet == null)
            {
                throw new ArgumentNullException("packet");
            }

            // Check that we are in members table (because SSRC has timed out), add itself to senders table.
            lock (m_pMembers)
            {
                if (!m_pMembers.ContainsKey(stream.Source.SSRC))
                {
                    m_pMembers.Add(stream.Source.SSRC, stream.Source);
                }
            }

            // If we are not in sender table (because SSRC has timed out), add itself to senders table.
            lock (m_pSenders)
            {
                if (!m_pSenders.ContainsKey(stream.Source.SSRC))
                {
                    m_pSenders.Add(stream.Source.SSRC, stream.Source);
                }
            }

            byte[] packetBytes = new byte[m_MTU];
            int count = 0;
            packet.ToByte(packetBytes, ref count);

            // Send packet to each remote target.
            foreach (RTP_Address target in Targets)
            {
                try
                {
                    m_pRtpSocket.SendTo(packetBytes, count, SocketFlags.None, target.RtpEP);

                    m_RtpPacketsSent++;
                    m_RtpBytesSent += packetBytes.Length;
                }
                catch
                {
                    m_RtpFailedTransmissions++;
                }
            }

            return count;
        }