|
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 import java.util.*; |
|
22 import java.net.*; |
|
23 |
|
24 public class ValidateRtcpPkt { |
|
25 |
|
26 public static void main(String[] args) { |
|
27 DatagramSocket rtpSock = null; |
|
28 DatagramSocket rtcpSock = null; |
|
29 |
|
30 try { |
|
31 rtpSock = new DatagramSocket(1233); |
|
32 rtcpSock = new DatagramSocket(1234); |
|
33 } catch (Exception e) { |
|
34 //do nothing |
|
35 } |
|
36 RTPSession rtpSession = new RTPSession(rtpSock, rtcpSock); |
|
37 |
|
38 System.out.println("************************** SSRC: " + rtpSession.ssrc + " **************************"); |
|
39 ParticipantDatabase partDb = new ParticipantDatabase(rtpSession); |
|
40 //InetAddress test = InetAddress.getByName("127.0.0.1"); |
|
41 Participant part1 = new Participant("127.0.0.1",12, 34); |
|
42 Participant part2 = new Participant("127.0.0.2",56, 78); |
|
43 |
|
44 part1.ssrc = 123; |
|
45 part2.ssrc = 345; |
|
46 |
|
47 InetSocketAddress testadr = null; |
|
48 |
|
49 try { |
|
50 testadr = InetSocketAddress.createUnresolved("localhost", 12371); |
|
51 } catch (Exception e) { |
|
52 // Do nothing |
|
53 } |
|
54 |
|
55 part1.cname = "test3"; |
|
56 part2.cname = "test2"; |
|
57 part1.loc = "1231231231"; |
|
58 part2.loc = "Asker"; |
|
59 part1.phone = "+452 1231231"; |
|
60 part2.phone = "aasdasda.asdasdas"; |
|
61 part1.lastSeqNumber = 111; |
|
62 part2.lastSeqNumber = 222; |
|
63 part1.timeStampLSR = 111111; |
|
64 part2.timeStampLSR = 222222; |
|
65 partDb.addParticipant(0,part1); |
|
66 partDb.addParticipant(0,part2); |
|
67 |
|
68 Participant[] partArray = new Participant[2]; |
|
69 partArray[0] = part1; |
|
70 partArray[1] = part2; |
|
71 |
|
72 RtcpPktRR rrpkt = new RtcpPktRR(partArray,123456789); |
|
73 RtcpPktSR srpkt = new RtcpPktSR(rtpSession.ssrc,12,21,rrpkt); |
|
74 //RtcpPktSR srpkt2 = new RtcpPktSR(rtpSession.ssrc,12,21,null); |
|
75 //rrpkt = new RtcpPktRR(partArray,1234512311); |
|
76 |
|
77 //srpkt.debugPrint(); |
|
78 //rrpkt.debugPrint(); |
|
79 |
|
80 CompRtcpPkt compkt = new CompRtcpPkt(); |
|
81 compkt.addPacket(srpkt); |
|
82 compkt.addPacket(rrpkt); |
|
83 compkt.addPacket(rrpkt); |
|
84 |
|
85 byte[] test2 = compkt.encode(); |
|
86 //System.out.print(StaticProcs.bitsOfBytes(test)); |
|
87 System.out.println("****************************** DONE ENCODING *******************************"); |
|
88 CompRtcpPkt decomppkt = new CompRtcpPkt(test2,test2.length,testadr,rtpSession); |
|
89 System.out.println("****************************** DONE DECODING *******************************"); |
|
90 System.out.println("Problem code:" + decomppkt.problem); |
|
91 |
|
92 ListIterator iter = decomppkt.rtcpPkts.listIterator(); |
|
93 int i = 0; |
|
94 |
|
95 while(iter.hasNext()) { |
|
96 System.out.println(" i:" + i + " "); |
|
97 i++; |
|
98 |
|
99 Object aPkt = iter.next(); |
|
100 if( aPkt.getClass() == RtcpPktRR.class) { |
|
101 RtcpPktRR pkt = (RtcpPktRR) aPkt; |
|
102 pkt.debugPrint(); |
|
103 } else if(aPkt.getClass() == RtcpPktSR.class) { |
|
104 RtcpPktSR pkt = (RtcpPktSR) aPkt; |
|
105 pkt.debugPrint(); |
|
106 } |
|
107 } |
|
108 |
|
109 System.out.println("****************************** BYE *******************************"); |
|
110 long[] tempArray = {rtpSession.ssrc}; |
|
111 byte[] tempReason = "tas".getBytes(); |
|
112 RtcpPktBYE byepkt = new RtcpPktBYE(tempArray,tempReason); |
|
113 //byepkt.debugPrint(); |
|
114 byepkt.encode(); |
|
115 byte[] rawpktbye = byepkt.rawPkt; |
|
116 |
|
117 RtcpPktBYE byepkt2 = new RtcpPktBYE(rawpktbye,0); |
|
118 byepkt2.debugPrint(); |
|
119 |
|
120 System.out.println("****************************** SDES *******************************"); |
|
121 RtcpPktSDES sdespkt = new RtcpPktSDES(true,rtpSession,null); |
|
122 rtpSession.cname = "cname123@localhost"; |
|
123 //rtpSession.loc = "right here"; |
|
124 sdespkt.encode(); |
|
125 //rtpSession.cname = "cname124@localhost"; |
|
126 //rtpSession.loc = "right hera"; |
|
127 byte[] rawpktsdes = sdespkt.rawPkt; |
|
128 InetSocketAddress tmpAdr = (InetSocketAddress) rtpSock.getLocalSocketAddress(); |
|
129 RtcpPktSDES decsdespkt = new RtcpPktSDES(rawpktsdes, 0, (InetSocketAddress) rtpSock.getLocalSocketAddress() , partDb); |
|
130 decsdespkt.debugPrint(); |
|
131 //partDb.debugPrint(); |
|
132 |
|
133 CompRtcpPkt compkt2 = new CompRtcpPkt(); |
|
134 compkt2.addPacket(srpkt); |
|
135 compkt2.addPacket(sdespkt); |
|
136 byte[] compkt2Raw = compkt.encode(); |
|
137 |
|
138 CompRtcpPkt compkt3 = new CompRtcpPkt(compkt2Raw,compkt2Raw.length,tmpAdr,rtpSession); |
|
139 } |
|
140 } |