src/jlibrtp/RtcpPktAPP.java
changeset 823 2036ebfaccda
equal deleted inserted replaced
536:537ddd8aa407 823:2036ebfaccda
       
     1 /**
       
     2  * Java RTP Library (jlibrtp)
       
     3  * Copyright (C) 2006 Arne Kepp
       
     4  * 
       
     5  * This library is free software; you can redistribute it and/or
       
     6  * modify it under the terms of the GNU Lesser General Public
       
     7  * License as published by the Free Software Foundation; either
       
     8  * version 2.1 of the License, or (at your option) any later version.
       
     9  *
       
    10  * This library is distributed in the hope that it will be useful,
       
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    13  * Lesser General Public License for more details.
       
    14  * 
       
    15  * You should have received a copy of the GNU Lesser General Public
       
    16  * License along with this library; if not, write to the Free Software
       
    17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
       
    18  */
       
    19 package jlibrtp;
       
    20 
       
    21 /**
       
    22  * Application specific RTCP packets
       
    23  * 
       
    24  * @author Arne Kepp
       
    25  */
       
    26 public class RtcpPktAPP extends RtcpPkt {
       
    27 	/** Name of packet, 4 bytes ASCII */
       
    28 	protected byte[] pktName = null;
       
    29 	/** Data of packet */
       
    30 	protected byte[] pktData = null;
       
    31 
       
    32 	/**
       
    33 	 * Constructor for a new Application RTCP packet
       
    34 	 * 
       
    35 	 * @param ssrc
       
    36 	 *            the SSRC of the sender, presumably taken from RTPSession
       
    37 	 * @param subtype
       
    38 	 *            the subtype of packet, application specific
       
    39 	 * @param pktName
       
    40 	 *            byte[4] representing ASCII name of packet
       
    41 	 * @param pktData
       
    42 	 *            the byte[4x] data that represents the message itself
       
    43 	 */
       
    44 	protected RtcpPktAPP(long ssrc, int subtype, byte[] pktName, byte[] pktData) {
       
    45 		// Fetch all the right stuff from the database
       
    46 		super.ssrc = ssrc;
       
    47 		super.packetType = 204;
       
    48 		super.itemCount = subtype;
       
    49 		this.pktName = pktName;
       
    50 		this.pktData = pktData;
       
    51 	}
       
    52 
       
    53 	/**
       
    54 	 * Constructor that parses a received Application RTCP packet
       
    55 	 * 
       
    56 	 * @param aRawPkt
       
    57 	 *            the raw packet containing the date
       
    58 	 * @param start
       
    59 	 *            where in the raw packet this packet starts
       
    60 	 */
       
    61 	protected RtcpPktAPP(byte[] aRawPkt, int start) {
       
    62 		super.ssrc = StaticProcs.bytesToUIntLong(aRawPkt, 4);
       
    63 		super.rawPkt = aRawPkt;
       
    64 
       
    65 		if (!super.parseHeaders(start) || packetType != 204) {
       
    66 			if (RTPSession.rtpDebugLevel > 2) {
       
    67 				System.out
       
    68 						.println(" <-> RtcpPktAPP.parseHeaders() etc. problem");
       
    69 			}
       
    70 			super.problem = -204;
       
    71 		} else {
       
    72 			// System.out.println("super.length:  " + super.length);
       
    73 			if (super.length > 1) {
       
    74 				pktName = new byte[4];
       
    75 				System.arraycopy(aRawPkt, 8, pktName, 0, 4);
       
    76 			}
       
    77 			if (super.length > 2) {
       
    78 				pktData = new byte[(super.length + 1) * 4 - 12];
       
    79 				System.arraycopy(aRawPkt, 12, pktData, 0, pktData.length);
       
    80 			}
       
    81 		}
       
    82 	}
       
    83 
       
    84 	/**
       
    85 	 * Encode the packet into a byte[], saved in .rawPkt
       
    86 	 * 
       
    87 	 * CompRtcpPkt will call this automatically
       
    88 	 */
       
    89 	protected void encode() {
       
    90 		super.rawPkt = new byte[12 + this.pktData.length];
       
    91 		byte[] tmp = StaticProcs.uIntLongToByteWord(super.ssrc);
       
    92 		System.arraycopy(tmp, 0, super.rawPkt, 4, 4);
       
    93 		System.arraycopy(this.pktName, 0, super.rawPkt, 8, 4);
       
    94 		System
       
    95 				.arraycopy(this.pktData, 0, super.rawPkt, 12,
       
    96 						this.pktData.length);
       
    97 		writeHeaders();
       
    98 		// System.out.println("ENCODE: " + super.length + " " + rawPkt.length +
       
    99 		// " " + pktData.length);
       
   100 	}
       
   101 }