src/jlibrtp/RtcpPktAPP.java
author Philippe Lago <lago_p@epitech.net>
Thu, 23 Apr 2009 12:41:13 +0200
changeset 143 6f6f5838aef9
parent 13 e684f11070d5
permissions -rw-r--r--
skin skin skin joli pas beau
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
 * Application specific RTCP packets
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    23
 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    24
 * @author Arne Kepp
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    25
 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    26
public class RtcpPktAPP extends RtcpPkt {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    27
	/** Name of packet, 4 bytes ASCII */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    28
	protected byte[] pktName = null;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    29
	/** Data of packet */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    30
	protected byte[] pktData = null;	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    31
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    32
	/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    33
	 * Constructor for a new Application RTCP packet
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    34
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    35
	 * @param ssrc the SSRC of the sender, presumably taken from RTPSession
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    36
	 * @param subtype the subtype of packet, application specific
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    37
	 * @param pktName byte[4] representing ASCII name of packet
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    38
	 * @param pktData the byte[4x] data that represents the message itself
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    39
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    40
	protected RtcpPktAPP(long ssrc, int subtype, byte[] pktName, byte[] pktData) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    41
		// Fetch all the right stuff from the database
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    42
		super.ssrc = ssrc;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    43
		super.packetType = 204;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    44
		super.itemCount = subtype;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    45
		this.pktName = pktName;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    46
		this.pktData = pktData;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    47
	}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    48
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    49
	/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    50
	 * Constructor that parses a received Application RTCP packet
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    51
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    52
	 * @param aRawPkt the raw packet containing the date
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    53
	 * @param start where in the raw packet this packet starts
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    54
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    55
	protected RtcpPktAPP(byte[] aRawPkt, int start) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    56
		super.ssrc = StaticProcs.bytesToUIntLong(aRawPkt,4);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    57
		super.rawPkt = aRawPkt;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    58
		
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    59
		if(!super.parseHeaders(start) || packetType != 204 ) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    60
			if(RTPSession.rtpDebugLevel > 2) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    61
				System.out.println(" <-> RtcpPktAPP.parseHeaders() etc. problem");
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    62
			}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    63
			super.problem = -204;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    64
		} else {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    65
			//System.out.println("super.length:  " + super.length);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    66
			if(super.length > 1) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    67
				pktName = new byte[4];
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    68
				System.arraycopy(aRawPkt, 8, pktName, 0, 4);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    69
			}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    70
			if(super.length > 2) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    71
				pktData = new byte[(super.length+1)*4 - 12];
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    72
				System.arraycopy(aRawPkt, 12, pktData, 0, pktData.length);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    73
			}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    74
		}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    75
	}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    76
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    77
	/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    78
	 * Encode the packet into a byte[], saved in .rawPkt
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    79
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    80
	 * CompRtcpPkt will call this automatically
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    81
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    82
	protected void encode() {	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    83
		super.rawPkt = new byte[12 + this.pktData.length];
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    84
		byte[] tmp = StaticProcs.uIntLongToByteWord(super.ssrc);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    85
		System.arraycopy(tmp, 0, super.rawPkt, 4, 4);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    86
		System.arraycopy(this.pktName, 0, super.rawPkt, 8, 4);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    87
		System.arraycopy(this.pktData, 0, super.rawPkt, 12, this.pktData.length);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    88
		writeHeaders();
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    89
		//System.out.println("ENCODE: " + super.length + " " + rawPkt.length + " " + pktData.length);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    90
	}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    91
}