示例#1
0
        /// <summary>
        /// Processes specified RTP packet thorugh this stream.
        /// </summary>
        /// <param name="packet">RTP packet.</param>
        /// <param name="size">RTP packet size in bytes.</param>
        /// <exception cref="ArgumentNullException">Is raised when <b>packet</b> is null reference.</exception>
        internal void Process(RTP_Packet packet, int size)
        {
            if (packet == null)
            {
                throw new ArgumentNullException("packet");
            }

            m_BytesReceived += size;

            if (UpdateSeq(packet.SeqNo))
            {
                OnPacketReceived(packet);

                /* RFC 3550 A.8 Estimating the Interarrival Jitter.
                 *  The code fragments below implement the algorithm given in Section
                 *  6.4.1 for calculating an estimate of the statistical variance of the
                 *  RTP data interarrival time to be inserted in the interarrival jitter
                 *  field of reception reports.  The inputs are r->ts, the timestamp from
                 *  the incoming packet, and arrival, the current time in the same units.
                 *  Here s points to state for the source; s->transit holds the relative
                 *  transit time for the previous packet, and s->jitter holds the
                 *  estimated jitter.  The jitter field of the reception report is
                 *  measured in timestamp units and expressed as an unsigned integer, but
                 *  the jitter estimate is kept in a floating point.  As each data packet
                 *  arrives, the jitter estimate is updated:
                 *
                 *      int transit = arrival - r->ts;
                 *      int d = transit - s->transit;
                 *      s->transit = transit;
                 *      if (d < 0) d = -d;
                 *      s->jitter += (1./16.) * ((double)d - s->jitter);
                 *
                 *  When a reception report block (to which rr points) is generated for
                 *  this member, the current jitter estimate is returned:
                 *
                 *      rr->jitter = (u_int32) s->jitter;
                 *
                 */
                uint arrival = RTP_Utils.DateTimeToNTP32(DateTime.Now);
                int  transit = (int)(arrival - packet.Timestamp);
                int  d       = transit - m_Transit;
                m_Transit = transit;
                if (d < 0)
                {
                    d = -d;
                }
                m_Jitter += (1.0 / 16.0) * ((double)d - m_Jitter);
            }
            // else Packet not valid, skip it.
        }
示例#2
0
 /// <summary>
 /// Generates new SSRC value. This must be called only if SSRC collision of local source.
 /// </summary>
 internal void GenerateNewSSRC()
 {
     m_SSRC = RTP_Utils.GenerateSSRC();
 }