src/jlibrtp/CompRtcpPkt.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
import java.util.*;
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
 * Compound RTCP packet class.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    25
 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    26
 * It basically holds a list of packets. This list can either be constructed
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    27
 * by providing a byte[] of a compound packet, or by adding individual packets.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    28
 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    29
 * Upon encode(), the packet will call encode on all the added packets.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    30
 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    31
 * problem == 0 indicates the parsing succeeded.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    32
 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    33
 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    34
 * @author Arne Kepp
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    35
 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    36
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    37
public class CompRtcpPkt {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    38
	/** Problem indicator, negative values denote packet type that cause problem */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    39
	protected int problem = 0;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    40
	/** Stores the different subclasses of RtcpPkt that make up the compound packet */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    41
	protected LinkedList<RtcpPkt> rtcpPkts = new LinkedList<RtcpPkt>();
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    42
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    43
	/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    44
	 * Instantiates an empty Compound RTCP packet to which you can add RTCP packets
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    45
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    46
	protected CompRtcpPkt() {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    47
		// Will have to add packets directly to rtcpPkts.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    48
		if(RTPSession.rtpDebugLevel > 7) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    49
			System.out.println("<-> CompRtcpPkt()");
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    50
		}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    51
	}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    52
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    53
	/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    54
	 * Add a RTCP packet to the compound packet. Pakcets are added in order,
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    55
	 * so you have to ensure that a Sender Report or Receiver Report is 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    56
	 * added first.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    57
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    58
	 * @param aPkt the packet to be added
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    59
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    60
	protected void addPacket(RtcpPkt aPkt) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    61
		if(RTPSession.rtpDebugLevel > 11) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    62
			System.out.println("  <-> CompRtcpPkt.addPacket( "+ aPkt.getClass() + " )");
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    63
		}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    64
		
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    65
		if(aPkt.problem == 0) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    66
			rtcpPkts.add(aPkt);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    67
		} else {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    68
			this.problem = aPkt.problem;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    69
		}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    70
	}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    71
	
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    72
	/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    73
	 * Picks a received Compound RTCP packet apart.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    74
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    75
	 * Only SDES packets are processed directly, other packets are
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    76
	 * parsed and put into aComptRtcpPkt.rtcpPkts, but not 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    77
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    78
	 * Check the aComptRtcpPkt.problem , if the value is non-zero
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    79
	 * the packets should probably be discarded.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    80
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    81
	 * @param rawPkt the byte array received from the socket
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    82
	 * @param packetSize the actual number of used bytes
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    83
	 * @param adr the socket address from which the packet was received
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    84
	 * @param rtpSession the RTPSession with the participant database
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    85
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    86
	protected CompRtcpPkt(byte[] rawPkt, int packetSize, InetSocketAddress adr, RTPSession rtpSession) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    87
		if(RTPSession.rtcpDebugLevel > 7) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    88
			System.out.println("-> CompRtcpPkt(" + rawPkt.getClass() + ", size " + packetSize + ", from " + adr.toString() + ", " + rtpSession.getClass() + ")");
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    89
		}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    90
		//System.out.println("rawPkt.length:" + rawPkt.length + " packetSize:" + packetSize);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    91
		
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    92
		// Chop it up
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    93
		int start = 0;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    94
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    95
		while(start < packetSize && problem == 0) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    96
			int length = (StaticProcs.bytesToUIntInt(rawPkt, start + 2)) + 1;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    97
			
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    98
			if(length*4 + start > rawPkt.length) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
    99
				System.out.println("!!!! CompRtcpPkt.(rawPkt,..,..) length ("+ (length*4+start)
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   100
						+ ") exceeds size of raw packet ("+rawPkt.length+") !");
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   101
				this.problem = -3;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   102
			}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   103
			
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   104
			int pktType = (int) rawPkt[start + 1];
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   105
			
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   106
			if(pktType < 0) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   107
				pktType += 256;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   108
			}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   109
			
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   110
			
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   111
			if(start == 0) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   112
				// Compound packets need to start with SR or RR
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   113
				if(pktType != 200 && pktType != 201 ) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   114
					if(RTPSession.rtcpDebugLevel > 3) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   115
						System.out.println("!!!! CompRtcpPkt(rawPkt...) packet did not start with SR or RR");
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   116
					}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   117
					this.problem = -1;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   118
				}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   119
				
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   120
				// Padding bit should be zero for the first packet
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   121
				if(((rawPkt[start] & 0x20) >>> 5) == 1) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   122
					if(RTPSession.rtcpDebugLevel > 3) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   123
						System.out.println("!!!! CompRtcpPkt(rawPkt...) first packet was padded");
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   124
					}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   125
					this.problem = -2;
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
			
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   129
			//System.out.println("start: " + start + "   pktType: " + pktType + "  length:" + length );			
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   130
			if(pktType == 200) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   131
				addPacket(new RtcpPktSR(rawPkt,start,length*4));
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   132
			} else if(pktType == 201 ) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   133
				addPacket(new RtcpPktRR(rawPkt,start, -1));
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   134
			} else if(pktType == 202) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   135
				addPacket(new RtcpPktSDES(rawPkt,start, adr, rtpSession.partDb));
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   136
			} else if(pktType == 203 ) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   137
				addPacket(new RtcpPktBYE(rawPkt,start));
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   138
			} else if(pktType == 204) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   139
				addPacket(new RtcpPktAPP(rawPkt,start));
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   140
			} else if(pktType == 205) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   141
				addPacket(new RtcpPktRTPFB(rawPkt,start, rtpSession));
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   142
			} else if(pktType == 206) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   143
				addPacket(new RtcpPktPSFB(rawPkt,start,rtpSession));
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   144
			} else {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   145
				System.out.println("!!!! CompRtcpPkt(byte[] rawPkt, int packetSize...) "
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   146
						+"UNKNOWN RTCP PACKET TYPE:" + pktType);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   147
			}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   148
			
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   149
			//System.out.println(" start:" + start + "  pktType:" + pktType + " length:" + length);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   150
			
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   151
			start += length*4;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   152
			
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   153
			if(RTPSession.rtcpDebugLevel > 12) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   154
				System.out.println(" start:"+start+"  parsing pktType "+pktType+" length: "+length);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   155
			}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   156
		}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   157
		if(RTPSession.rtcpDebugLevel > 7) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   158
			System.out.println("<- CompRtcpPkt(rawPkt....)");
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
	/**
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   163
	 * Encode combines the RTCP packets in this.rtcpPkts into a byte[]
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   164
	 * by calling the encode() function on each of them individually.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   165
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   166
	 * The order of rtcpPkts is preserved, so a RR or SR packet must be first.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   167
	 * 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   168
	 * @return the trimmed byte[] representation of the packet, ready to go into a UDP packet.
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   169
	 */
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   170
	protected byte[] encode() {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   171
		if(RTPSession.rtpDebugLevel > 9) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   172
			System.out.println(" <- CompRtcpPkt.encode()");
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   173
		}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   174
		
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   175
		ListIterator<RtcpPkt>  iter = rtcpPkts.listIterator();
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   176
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   177
		byte[] rawPkt = new byte[1500];
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   178
		int index = 0;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   179
		
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   180
		while(iter.hasNext()) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   181
			RtcpPkt aPkt = (RtcpPkt) iter.next();
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   182
			
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   183
			if(aPkt.packetType == 200) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   184
				RtcpPktSR pkt = (RtcpPktSR) aPkt;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   185
				pkt.encode();
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   186
				System.arraycopy(pkt.rawPkt, 0, rawPkt, index, pkt.rawPkt.length);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   187
				index += pkt.rawPkt.length;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   188
			} else if(aPkt.packetType == 201 ) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   189
				RtcpPktRR pkt = (RtcpPktRR) aPkt;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   190
				pkt.encode();
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   191
				System.arraycopy(pkt.rawPkt, 0, rawPkt, index, pkt.rawPkt.length);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   192
				index += pkt.rawPkt.length;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   193
			} else if(aPkt.packetType == 202) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   194
				RtcpPktSDES pkt = (RtcpPktSDES) aPkt;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   195
				pkt.encode();
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   196
				//System.out.println(" ENCODE SIZE: " + pkt.rawPkt.length);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   197
				System.arraycopy(pkt.rawPkt, 0, rawPkt, index, pkt.rawPkt.length);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   198
				index += pkt.rawPkt.length;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   199
			} else if(aPkt.packetType == 203) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   200
				RtcpPktBYE pkt = (RtcpPktBYE) aPkt;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   201
				pkt.encode();
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   202
				System.arraycopy(pkt.rawPkt, 0, rawPkt, index, pkt.rawPkt.length);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   203
				index += pkt.rawPkt.length;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   204
			} else if(aPkt.packetType == 204) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   205
				RtcpPktAPP pkt = (RtcpPktAPP) aPkt;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   206
				pkt.encode();
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   207
				System.arraycopy(pkt.rawPkt, 0, rawPkt, index, pkt.rawPkt.length);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   208
				index += pkt.rawPkt.length;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   209
			} else if(aPkt.packetType == 205) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   210
				RtcpPktRTPFB pkt = (RtcpPktRTPFB) aPkt;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   211
				pkt.encode();
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   212
				System.arraycopy(pkt.rawPkt, 0, rawPkt, index, pkt.rawPkt.length);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   213
				index += pkt.rawPkt.length;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   214
			} else if(aPkt.packetType == 206) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   215
				RtcpPktPSFB pkt = (RtcpPktPSFB) aPkt;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   216
				pkt.encode();
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   217
				System.arraycopy(pkt.rawPkt, 0, rawPkt, index, pkt.rawPkt.length);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   218
				index += pkt.rawPkt.length;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   219
			} else {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   220
				System.out.println("CompRtcpPkt aPkt.packetType:" + aPkt.packetType);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   221
			}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   222
			//System.out.println(" packetType:" + aPkt.packetType + " length:" + aPkt.rawPkt.length + " index:" + index);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   223
		} 
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   224
		
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   225
		byte[] output = new byte[index];
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   226
		
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   227
		System.arraycopy(rawPkt, 0, output, 0, index);
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   228
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   229
		if(RTPSession.rtpDebugLevel > 9) {
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   230
			System.out.println(" -> CompRtcpPkt.encode()");
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   231
		}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   232
		return output;
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   233
	}
e684f11070d5 ajout de jlibrtp
nikita@nikita-rack
parents:
diff changeset
   234
}