13
|
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 the SSRC of the sender, presumably taken from RTPSession
|
|
36 |
* @param subtype the subtype of packet, application specific
|
|
37 |
* @param pktName byte[4] representing ASCII name of packet
|
|
38 |
* @param pktData the byte[4x] data that represents the message itself
|
|
39 |
*/
|
|
40 |
protected RtcpPktAPP(long ssrc, int subtype, byte[] pktName, byte[] pktData) {
|
|
41 |
// Fetch all the right stuff from the database
|
|
42 |
super.ssrc = ssrc;
|
|
43 |
super.packetType = 204;
|
|
44 |
super.itemCount = subtype;
|
|
45 |
this.pktName = pktName;
|
|
46 |
this.pktData = pktData;
|
|
47 |
}
|
|
48 |
|
|
49 |
/**
|
|
50 |
* Constructor that parses a received Application RTCP packet
|
|
51 |
*
|
|
52 |
* @param aRawPkt the raw packet containing the date
|
|
53 |
* @param start where in the raw packet this packet starts
|
|
54 |
*/
|
|
55 |
protected RtcpPktAPP(byte[] aRawPkt, int start) {
|
|
56 |
super.ssrc = StaticProcs.bytesToUIntLong(aRawPkt,4);
|
|
57 |
super.rawPkt = aRawPkt;
|
|
58 |
|
|
59 |
if(!super.parseHeaders(start) || packetType != 204 ) {
|
|
60 |
if(RTPSession.rtpDebugLevel > 2) {
|
|
61 |
System.out.println(" <-> RtcpPktAPP.parseHeaders() etc. problem");
|
|
62 |
}
|
|
63 |
super.problem = -204;
|
|
64 |
} else {
|
|
65 |
//System.out.println("super.length: " + super.length);
|
|
66 |
if(super.length > 1) {
|
|
67 |
pktName = new byte[4];
|
|
68 |
System.arraycopy(aRawPkt, 8, pktName, 0, 4);
|
|
69 |
}
|
|
70 |
if(super.length > 2) {
|
|
71 |
pktData = new byte[(super.length+1)*4 - 12];
|
|
72 |
System.arraycopy(aRawPkt, 12, pktData, 0, pktData.length);
|
|
73 |
}
|
|
74 |
}
|
|
75 |
}
|
|
76 |
|
|
77 |
/**
|
|
78 |
* Encode the packet into a byte[], saved in .rawPkt
|
|
79 |
*
|
|
80 |
* CompRtcpPkt will call this automatically
|
|
81 |
*/
|
|
82 |
protected void encode() {
|
|
83 |
super.rawPkt = new byte[12 + this.pktData.length];
|
|
84 |
byte[] tmp = StaticProcs.uIntLongToByteWord(super.ssrc);
|
|
85 |
System.arraycopy(tmp, 0, super.rawPkt, 4, 4);
|
|
86 |
System.arraycopy(this.pktName, 0, super.rawPkt, 8, 4);
|
|
87 |
System.arraycopy(this.pktData, 0, super.rawPkt, 12, this.pktData.length);
|
|
88 |
writeHeaders();
|
|
89 |
//System.out.println("ENCODE: " + super.length + " " + rawPkt.length + " " + pktData.length);
|
|
90 |
}
|
|
91 |
}
|