src/jlibrtp/DataFrame.java
author nikita@nikita-rack
Thu, 09 Apr 2009 20:26:58 +0200
changeset 99 8de21ac527ce
parent 13 e684f11070d5
permissions -rw-r--r--
revert pour refaire un push propre
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
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    22
/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    23
 * Data structure to hold a complete frame if frame reconstruction
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    24
 * is enabled, or the data from an individual packet if it is not
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    25
 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    26
 * It also contains most of the data from the individual packets 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    27
 * that it is based on.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    28
 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    29
 * @author Arne Kepp
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    30
 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    31
public class DataFrame {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    32
	/** The share RTP timestamp */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    33
	private long rtpTimestamp;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    34
	/** The calculated UNIX timestamp, guessed after 2 Sender Reports */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    35
	private long timestamp = -1;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    36
	/** the SSRC from which this frame originated */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    37
	private long SSRC;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    38
	/** contributing CSRCs, only read from the first packet */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    39
	private long[] CSRCs;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    40
	/** RTP payload type */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    41
	private int payloadType;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    42
	/** The marks on individual packets, ordered */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    43
	private boolean[] marks;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    44
	/** Whether any packets were marked or not */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    45
	private boolean anyMarked = false;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    46
	/** Whether the frame contains the expected number of packets */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    47
	private int isComplete = 0;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    48
	//private int dataLength;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    49
	/** The data from the individual packets, ordered */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    50
	private byte[][] data;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    51
	/** The sequence numbers of the individual packets, ordered */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    52
	private int[] seqNum;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    53
	/** The total amount of data bytes in this frame */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    54
	private int totalLength = 0;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    55
	/** The last sequence number in this frame */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    56
	protected int lastSeqNum;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    57
	/** The first sequence number in this frame */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    58
	protected int firstSeqNum;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    59
	/** The number of packets expected for a complete frame */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    60
	protected int noPkts;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    61
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    62
	/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    63
	 * The usual way to construct a frame is by giving it a PktBufNode,
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    64
	 * which contains links to all the other pkts that make it up.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    65
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    66
	protected DataFrame(PktBufNode aBufNode, Participant p, int noPkts) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    67
		if(RTPSession.rtpDebugLevel > 6) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    68
			System.out.println("-> DataFrame(PktBufNode, noPkts = " + noPkts +")");
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    69
		}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    70
		this.noPkts = noPkts;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    71
		RtpPkt aPkt = aBufNode.pkt;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    72
		int pktCount = aBufNode.pktCount;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    73
		firstSeqNum = aBufNode.pktCount;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    74
		
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    75
		// All this data should be shared, so we just get it from the first one
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    76
		this.rtpTimestamp = aBufNode.timeStamp;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    77
		SSRC = aPkt.getSsrc();
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    78
		CSRCs = aPkt.getCsrcArray();
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    79
		
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    80
		// Check whether we can compute an NTPish timestamp? Requires two SR reports 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    81
		if(p.ntpGradient > 0) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    82
			//System.out.print(Long.toString(p.ntpOffset)+" " 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    83
			timestamp =  p.ntpOffset + (long) (p.ntpGradient*(double)(this.rtpTimestamp-p.lastSRRtpTs));
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    84
		}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    85
		
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    86
		// Make data the right length
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    87
		int payloadLength = aPkt.getPayloadLength();
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    88
		//System.out.println("aBufNode.pktCount " + aBufNode.pktCount);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    89
		data = new byte[aBufNode.pktCount][payloadLength];
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    90
		seqNum = new int[aBufNode.pktCount];
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    91
		marks = new boolean[aBufNode.pktCount];
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    92
		
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    93
		// Concatenate the data of the packets
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    94
		int i;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    95
		for(i=0; i< pktCount; i++) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    96
			aPkt = aBufNode.pkt;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    97
			byte[] temp = aPkt.getPayload();
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    98
			totalLength += temp.length;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    99
			if(temp.length == payloadLength) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   100
				data[i] = temp;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   101
			} else if(temp.length < payloadLength){
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   102
				System.arraycopy(temp, 0, data[i], 0, temp.length);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   103
			} else {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   104
				System.out.println("DataFrame() received node structure with increasing packet payload size.");
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   105
			}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   106
			//System.out.println("i " + i + " seqNum[i] " + seqNum[i] + " aBufNode"  + aBufNode);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   107
			seqNum[i] = aBufNode.seqNum;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   108
			marks[i] = aBufNode.pkt.isMarked();
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   109
			if(marks[i])
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   110
				anyMarked = true;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   111
			
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   112
			// Get next node
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   113
			aBufNode = aBufNode.nextFrameNode;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   114
		}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   115
		
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   116
		lastSeqNum = seqNum[i - 1];
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   117
		
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   118
		if(noPkts > 0) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   119
			int seqDiff = firstSeqNum - lastSeqNum;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   120
			if(seqDiff < 0)
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   121
				seqDiff = (Integer.MAX_VALUE - firstSeqNum)  + lastSeqNum;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   122
			if(seqDiff == pktCount && pktCount == noPkts)
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   123
				isComplete = 1;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   124
		} else {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   125
			isComplete = -1;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   126
		}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   127
		
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   128
		if(RTPSession.rtpDebugLevel > 6) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   129
			System.out.println("<- DataFrame(PktBufNode, noPkt), data length: " + data.length);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   130
		}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   131
	}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   132
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   133
	/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   134
	 * Returns a two dimensial array where the first dimension represents individual
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   135
	 * packets, from which the frame is made up, in order of increasing sequence number. 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   136
	 * These indeces can be matched to the sequence numbers returned by sequenceNumbers().
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   137
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   138
	 * @return 2-dim array with raw data from packets
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   139
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   140
	public byte[][] getData() {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   141
		return this.data;
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
	/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   145
	 * Returns a concatenated version of the data from getData()
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   146
	 * It ignores missing sequence numbers, but then isComplete()
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   147
	 * will return false provided that RTPAppIntf.frameSize()
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   148
	 * provides a non-negative number for this payload type.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   149
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   150
	 * @return byte[] with all the data concatenated
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   151
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   152
	public byte[] getConcatenatedData() {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   153
		if(this.noPkts < 2) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   154
			byte[] ret = new byte[this.totalLength];
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   155
			int pos = 0;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   156
		
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   157
			for(int i=0; i<data.length; i++) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   158
				int length = data[i].length;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   159
				
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   160
				// Last packet may be shorter
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   161
				if(pos + length > totalLength) 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   162
					length = totalLength - pos;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   163
				
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   164
				System.arraycopy(data[i], 0, ret, pos, length);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   165
				pos += data[i].length;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   166
			}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   167
			return ret;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   168
		} else {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   169
			return data[0];
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
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   173
	/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   174
	 * If two SR packet have been received jlibrtp will attempt to calculate 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   175
	 * the local UNIX timestamp (in milliseconds) of all packets received.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   176
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   177
	 * This value should ideally correspond to the local time when the 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   178
	 * SSRC sent the packet. Note that the source may not be reliable.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   179
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   180
	 * Returns -1 if less than two SRs have been received
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   181
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   182
	 * @return the UNIX timestamp, similar to System.currentTimeMillis() or -1;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   183
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   184
	public long timestamp() {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   185
		return this.timestamp;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   186
		
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   187
	}
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
	 * Returns the RTP timestamp of all the packets in the frame.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   191
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   192
	 * @return unmodified RTP timestamp
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   193
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   194
	public long rtpTimestamp() {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   195
		return this.rtpTimestamp;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   196
	}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   197
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   198
	/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   199
	 * Returns the payload type of the packets
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   200
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   201
	 * @return the payload type of the packets
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   202
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   203
	public int payloadType() {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   204
		return this.payloadType;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   205
	}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   206
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   207
	/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   208
	 * Returns an array whose values, for the same index, correpond to the 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   209
	 * sequence number of the packet from which the data came.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   210
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   211
	 * This information can be valuable in conjunction with getData(), 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   212
	 * to identify what parts of a frame are missing.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   213
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   214
	 * @return array with sequence numbers
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   215
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   216
	public int[] sequenceNumbers() {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   217
		return seqNum;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   218
	}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   219
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   220
	/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   221
	 * Returns an array whose values, for the same index, correpond to 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   222
	 * whether the data was marked or not. 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   223
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   224
	 * This information can be valuable in conjunction with getData().
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   225
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   226
	 * @return array of booleans
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   227
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   228
	public boolean[] marks() {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   229
		return this.marks;
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
	/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   233
	 * Returns true if any packet in the frame was marked.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   234
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   235
	 * This function should be used if all your frames fit
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   236
	 * into single packets.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   237
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   238
	 * @return true if any packet was marked, false otherwise
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   239
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   240
	public boolean marked() {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   241
		return this.anyMarked;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   242
	}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   243
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   244
	/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   245
	 * The SSRC associated with this frame.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   246
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   247
	 * @return the ssrc that created this frame
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   248
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   249
	public long ssrc() {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   250
		return this.SSRC;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   251
	}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   252
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   253
	/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   254
	 * The SSRCs that contributed to this frame
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   255
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   256
	 * @return an array of contributing SSRCs, or null
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   257
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   258
	public long[] csrcs() {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   259
		return this.CSRCs;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   260
	}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   261
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   262
	/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   263
	 * Checks whether the difference in sequence numbers corresponds
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   264
	 * to the number of packets received for the current timestamp,
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   265
	 * and whether this value corresponds to the expected number of
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   266
	 * packets.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   267
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   268
	 * @return true if the right number of packets make up the frame
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   269
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   270
	public int complete() {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   271
		return this.isComplete;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   272
	}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   273
}