src/jlibrtp/Participant.java
author Da Risk <darisk972@gmail.com>
Tue, 14 Apr 2009 16:56:20 +0200
changeset 105 c6e4728ac9f7
parent 13 e684f11070d5
permissions -rw-r--r--
Passage sous cupcake :) Peu de modification de code, il faut juste creer des fichier aidl pour les classes parcelables. Sinon les fichier de build.xml ont ete completement modifiés, j'ai remplacé par les nouveaux. (il doit y avoir un manque de precision dans le fichier build.properties)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
     1
/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
     2
 * Java RTP Library (jlibrtp)
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
     3
 * Copyright (C) 2006 Arne Kepp
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
     4
 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
     5
 * This library is free software; you can redistribute it and/or
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
     6
 * modify it under the terms of the GNU Lesser General Public
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
     7
 * License as published by the Free Software Foundation; either
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
     8
 * version 2.1 of the License, or (at your option) any later version.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
     9
 *
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    10
 * This library is distributed in the hope that it will be useful,
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    13
 * Lesser General Public License for more details.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    14
 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    15
 * You should have received a copy of the GNU Lesser General Public
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    16
 * License along with this library; if not, write to the Free Software
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    18
 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    19
package jlibrtp;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    20
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    21
import java.net.InetSocketAddress;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    22
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    23
/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    24
 * A participant represents a peer in an RTPSession. Based on the information stored on 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    25
 * these objects, packets are processed and statistics generated for RTCP.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    26
 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    27
public class Participant {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    28
	/** Whether the participant is unexpected, e.g. arrived through unicast with SDES */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    29
	protected boolean unexpected = false;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    30
	/** Where to send RTP packets (unicast)*/
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    31
	protected InetSocketAddress rtpAddress = null; 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    32
	/** Where to send RTCP packets (unicast) */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    33
	protected InetSocketAddress rtcpAddress = null;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    34
	/** Where the first RTP packet was received from */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    35
	protected InetSocketAddress rtpReceivedFromAddress = null;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    36
	/** Where the first RTCP packet was received from */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    37
	protected InetSocketAddress rtcpReceivedFromAddress = null;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    38
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    39
	/** SSRC of participant */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    40
	protected long ssrc = -1;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    41
	/** SDES CNAME */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    42
	protected String cname = null;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    43
	/** SDES The participant's real name */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    44
	protected String name = null;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    45
	/** SDES The participant's email */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    46
	protected String email = null;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    47
	/** SDES The participant's phone number */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    48
	protected String phone = null;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    49
	/** SDES The participant's location*/
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    50
	protected String loc = null;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    51
	/** SDES The tool the participants is using */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    52
	protected String tool = null;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    53
	/** SDES A note */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    54
	protected String note = null;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    55
	/** SDES A priv string, loosely defined */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    56
	protected String priv = null;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    57
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    58
	// Receiver Report Items
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    59
	/** RR First sequence number */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    60
	protected int firstSeqNumber = -1;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    61
	/** RR Last sequence number */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    62
	protected int lastSeqNumber = 0;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    63
	/** RR Number of times sequence number has rolled over */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    64
	protected long seqRollOverCount = 0;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    65
	/** RR Number of packets received */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    66
	protected long receivedPkts = 0;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    67
	/** RR Number of octets received */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    68
	protected long receivedOctets = 0;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    69
	/** RR Number of packets received since last SR */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    70
	protected int receivedSinceLastSR = 0;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    71
	/** RR Sequence number associated with last SR */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    72
	protected int lastSRRseqNumber = 0;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    73
	/** RR Interarrival jitter */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    74
	protected double interArrivalJitter = -1.0;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    75
	/** RR Last received RTP Timestamp */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    76
	protected long lastRtpTimestamp = 0;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    77
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    78
	/** RR Middle 32 bits of the NTP timestamp in the last SR */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    79
	protected long timeStampLSR = 0;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    80
	/** RR The time when we actually got the last SR */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    81
	protected long timeReceivedLSR = 0;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    82
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    83
	/** Gradient where UNIX timestamp = ntpGradient*RTPTimestamp * ntpOffset */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    84
	protected double ntpGradient = -1;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    85
	/** Offset where UNIX timestamp = ntpGradient*RTPTimestamp * ntpOffset */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    86
	protected long ntpOffset = -1;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    87
	/** Last NTP received in SR packet, MSB */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    88
	protected long lastNtpTs1 = 0; //32 bits
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    89
	/** Last NTP received in SR packet, LSB */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    90
	protected long lastNtpTs2 = 0; //32 bits
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    91
	/** RTP Timestamp in last SR packet */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    92
	protected long lastSRRtpTs = 0; //32 bits
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    93
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    94
	/** UNIX time when a BYE was received from this participant, for pruning */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    95
	protected long timestampBYE = -1;	// The user said BYE at this time
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    96
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    97
	/** Store the packets received from this participant */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    98
	protected PktBuffer pktBuffer = null;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    99
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   100
	/** UNIX time of last RTP packet, to check whether this participant has sent anything recently */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   101
	protected long lastRtpPkt = -1; //Time of last RTP packet
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   102
	/** UNIX time of last RTCP packet, to check whether this participant has sent anything recently */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   103
	protected long lastRtcpPkt = -1; //Time of last RTCP packet
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   104
	/** UNIX time this participant was added by application, to check whether we ever heard back */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   105
	protected long addedByApp = -1; //Time the participant was added by application
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   106
	/** UNIX time of last time we sent an RR to this user */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   107
	protected long lastRtcpRRPkt = -1; //Timestamp of last time we sent this person an RR packet
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   108
	/** Unix time of second to last time we sent and RR to this user */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   109
	protected long secondLastRtcpRRPkt = -1; //Timestamp of 2nd to last time we sent this person an RR Packet
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   110
		
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   111
	/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   112
	 * Create a basic participant. If this is a <b>unicast</b> session you must provide network address (ipv4 or ipv6) and ports for RTP and RTCP, 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   113
	 * as well as a cname for this contact. These things should be negotiated through SIP or a similar protocol.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   114
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   115
	 * jlibrtp will listen for RTCP packets to obtain a matching SSRC for this participant, based on cname.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   116
	 * @param networkAddress string representation of network address (ipv4 or ipv6). Use "127.0.0.1" for multicast session.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   117
	 * @param rtpPort port on which peer expects RTP packets. Use 0 if this is a sender-only, or this is a multicast session.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   118
	 * @param rtcpPort port on which peer expects RTCP packets. Use 0 if this is a sender-only, or this is a multicast session.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   119
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   120
	public Participant(String networkAddress, int rtpPort, int rtcpPort) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   121
		if(RTPSession.rtpDebugLevel > 6) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   122
			System.out.println("Creating new participant: " + networkAddress);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   123
		}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   124
		
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   125
		// RTP
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   126
		if(rtpPort > 0) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   127
			try {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   128
				rtpAddress = new InetSocketAddress(networkAddress, rtpPort);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   129
			} catch (Exception e) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   130
				System.out.println("Couldn't resolve " + networkAddress);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   131
			}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   132
			//isReceiver = true;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   133
		}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   134
		
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   135
		// RTCP 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   136
		if(rtcpPort > 0) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   137
			try {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   138
				rtcpAddress = new InetSocketAddress(networkAddress, rtcpPort);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   139
			} catch (Exception e) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   140
				System.out.println("Couldn't resolve " + networkAddress);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   141
			}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   142
		}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   143
		
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   144
		//By default this is a sender
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   145
		//isSender = true;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   146
	}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   147
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   148
	// We got a packet, but we don't know this person yet.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   149
	protected Participant(InetSocketAddress rtpAdr, InetSocketAddress rtcpAdr, long SSRC) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   150
		rtpReceivedFromAddress = rtpAdr;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   151
		rtcpReceivedFromAddress = rtcpAdr;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   152
		ssrc = SSRC;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   153
		unexpected = true;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   154
	}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   155
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   156
	// Dummy constructor to ease testing
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   157
	protected Participant() {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   158
		System.out.println("Don't use the Participan(void) Constructor!");
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   159
	}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   160
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   161
	/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   162
	 * RTP Address registered with this participant.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   163
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   164
	 * @return address of participant
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   165
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   166
	InetSocketAddress getRtpSocketAddress() {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   167
		return rtpAddress;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   168
	}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   169
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   170
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   171
	/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   172
	 * RTCP Address registered with this participant.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   173
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   174
	 * @return address of participant
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   175
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   176
	InetSocketAddress getRtcpSocketAddress() {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   177
		return rtcpAddress;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   178
	}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   179
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   180
	/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   181
	 * InetSocketAddress this participant has used to
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   182
	 * send us RTP packets.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   183
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   184
	 * @return address of participant
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   185
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   186
	InetSocketAddress getRtpReceivedFromAddress() {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   187
		return rtpAddress;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   188
	}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   189
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   190
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   191
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   192
	/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   193
	 * InetSocketAddress this participant has used to
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   194
	 * send us RTCP packets.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   195
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   196
	 * @return address of participant
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   197
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   198
	InetSocketAddress getRtcpReceivedFromAddress() {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   199
		return rtcpAddress;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   200
	}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   201
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   202
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   203
	/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   204
	 * CNAME registered for this participant.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   205
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   206
	 * @return the cname
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   207
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   208
	public String getCNAME() {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   209
		return cname;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   210
	}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   211
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   212
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   213
	/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   214
	 * NAME registered for this participant.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   215
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   216
	 * @return the name
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   217
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   218
	public String getNAME() {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   219
		return name;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   220
	}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   221
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   222
	/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   223
	 * EMAIL registered for this participant.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   224
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   225
	 * @return the email address
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   226
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   227
	public String getEmail() {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   228
		return email;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   229
	}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   230
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   231
	/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   232
	 * PHONE registered for this participant.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   233
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   234
	 * @return the phone number
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   235
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   236
	public String getPhone() {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   237
		return phone;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   238
	}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   239
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   240
	/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   241
	 * LOCATION registered for this participant.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   242
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   243
	 * @return the location
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   244
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   245
	public String getLocation() {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   246
		return loc;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   247
	}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   248
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   249
	/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   250
	 * NOTE registered for this participant.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   251
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   252
	 * @return the note
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   253
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   254
	public String getNote() {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   255
		return note;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   256
	}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   257
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   258
	/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   259
	 * PRIVATE something registered for this participant.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   260
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   261
	 * @return the private-string
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   262
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   263
	public String getPriv() {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   264
		return priv;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   265
	}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   266
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   267
	/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   268
	 * TOOL something registered for this participant.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   269
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   270
	 * @return the tool
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   271
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   272
	public String getTool() {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   273
		return tool;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   274
	}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   275
		
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   276
	/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   277
	 * SSRC for participant, determined through RTCP SDES
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   278
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   279
	 * @return SSRC (32 bit unsigned integer as long)
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   280
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   281
	public long getSSRC() {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   282
		return this.ssrc;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   283
	}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   284
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   285
	/** 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   286
	 * Updates the participant with information for receiver reports.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   287
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   288
	 * @param packetLength to keep track of received octets
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   289
	 * @param pkt the most recently received packet
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   290
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   291
	protected void updateRRStats(int packetLength, RtpPkt pkt) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   292
		int curSeqNum = pkt.getSeqNumber();
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   293
		
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   294
		if(firstSeqNumber < 0) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   295
			firstSeqNumber = curSeqNum;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   296
		}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   297
		
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   298
		receivedOctets += packetLength;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   299
		receivedSinceLastSR++;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   300
		receivedPkts++;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   301
		
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   302
		long curTime =  System.currentTimeMillis();
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   303
		
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   304
		if( this.lastSeqNumber < curSeqNum ) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   305
			//In-line packet, best thing you could hope for
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   306
			this.lastSeqNumber = curSeqNum;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   307
						
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   308
		} else if(this.lastSeqNumber - this.lastSeqNumber < -100) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   309
			//Sequence counter rolled over
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   310
			this.lastSeqNumber = curSeqNum;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   311
			seqRollOverCount++;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   312
			
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   313
		} else {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   314
			//This was probably a duplicate or a late arrival.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   315
		}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   316
		
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   317
		// Calculate jitter
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   318
		if(this.lastRtpPkt > 0) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   319
			
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   320
			long D = (pkt.getTimeStamp() - curTime) - (this.lastRtpTimestamp - this.lastRtpPkt);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   321
			if(D < 0)
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   322
				D = (-1)*D;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   323
			
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   324
			this.interArrivalJitter += ((double)D - this.interArrivalJitter) / 16.0;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   325
		}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   326
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   327
		lastRtpPkt = curTime;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   328
		lastRtpTimestamp = pkt.getTimeStamp();
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   329
	}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   330
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   331
	/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   332
	 * Calculates the extended highest sequence received by adding 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   333
	 * the last sequence number to 65536 times the number of times 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   334
	 * the sequence counter has rolled over.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   335
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   336
	 * @return extended highest sequence
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   337
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   338
	protected long getExtHighSeqRecv() {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   339
		return (65536*seqRollOverCount + lastSeqNumber);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   340
	}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   341
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   342
	/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   343
	 * Get the fraction of lost packets, calculated as described
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   344
	 * in RFC 3550 as a fraction of 256.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   345
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   346
	 * @return the fraction of lost packets since last SR received
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   347
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   348
	protected int getFractionLost() {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   349
		int expected = (lastSeqNumber - lastSRRseqNumber);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   350
		if(expected < 0)
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   351
			expected = 65536 + expected;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   352
                
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   353
		int fraction = 256 * (expected - receivedSinceLastSR);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   354
		if(expected > 0) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   355
			fraction = (fraction / expected);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   356
		} else {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   357
			fraction = 0;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   358
		}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   359
		
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   360
		//Clear counters 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   361
		receivedSinceLastSR = 0;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   362
		lastSRRseqNumber = lastSeqNumber;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   363
		
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   364
		return fraction;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   365
	}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   366
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   367
	/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   368
	 * The total number of packets lost during the session.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   369
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   370
	 * Returns zero if loss is negative, i.e. duplicates have been received.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   371
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   372
	 * @return number of lost packets, or zero.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   373
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   374
	protected long getLostPktCount() {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   375
		long lost = (this.getExtHighSeqRecv() - this.firstSeqNumber) - receivedPkts;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   376
		
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   377
		if(lost < 0)
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   378
			lost = 0;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   379
		return lost;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   380
	}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   381
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   382
	/** 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   383
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   384
	 * @return the interArrivalJitter, calculated continuously
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   385
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   386
	protected double getInterArrivalJitter() {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   387
		return this.interArrivalJitter;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   388
	}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   389
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   390
	/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   391
	 * Set the timestamp for last sender report
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   392
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   393
	 * @param ntp1 high order bits
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   394
	 * @param ntp2 low order bits
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   395
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   396
	protected void setTimeStampLSR(long ntp1, long ntp2) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   397
		// Use what we've got
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   398
		byte[] high = StaticProcs.uIntLongToByteWord(ntp1);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   399
		byte[] low = StaticProcs.uIntLongToByteWord(ntp2);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   400
		low[3] = low[1];
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   401
		low[2] = low[0];
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   402
		low[1] = high[3];
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   403
		low[0] = high[2];
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   404
		
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   405
		this.timeStampLSR = StaticProcs.bytesToUIntLong(low, 0);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   406
	}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   407
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   408
	/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   409
	 * Calculate the delay between the last received sender report
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   410
	 * and now.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   411
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   412
	 * @return the delay in units of 1/65.536ms
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   413
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   414
	protected long delaySinceLastSR() {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   415
		if(this.timeReceivedLSR < 1) 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   416
			return 0;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   417
			
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   418
		long delay = System.currentTimeMillis() - this.timeReceivedLSR;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   419
		
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   420
		//Convert ms into 1/65536s = 1/65.536ms
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   421
		return (long) ((double)delay * 65.536);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   422
	}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   423
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   424
	/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   425
	 * Only for debugging purposes
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   426
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   427
	public void debugPrint() {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   428
		System.out.print(" Participant.debugPrint() SSRC:"+this.ssrc+" CNAME:"+this.cname);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   429
		if(this.rtpAddress != null)
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   430
			System.out.print(" RTP:"+this.rtpAddress.toString());
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   431
		if(this.rtcpAddress != null)
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   432
			System.out.print(" RTCP:"+this.rtcpAddress.toString());
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   433
		System.out.println("");
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   434
		
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   435
		System.out.println("                          Packets received:"+this.receivedPkts);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   436
	}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   437
}