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 |
import java.net.DatagramSocket; |
|
22 |
|
|
23 |
|
|
24 |
/** |
|
25 |
* Validates the PktBuffer and associated classes. |
|
26 |
* |
|
27 |
* @author Arne Kepp |
|
28 |
* |
|
29 |
*/ |
|
30 |
public class ValidatePktBuffer { |
|
31 |
|
|
32 |
/** |
|
33 |
* Instantiates a buffer, creates some packets, adds them and sorts them. |
|
34 |
* @param args |
|
35 |
*/ |
|
36 |
public static void main(String[] args) { |
|
37 |
// TODO Auto-generated method stub |
|
38 |
DatagramSocket rtpSocket = null; |
|
39 |
DatagramSocket rtcpSocket = null; |
|
40 |
try { |
|
41 |
rtpSocket = new DatagramSocket(6002); |
|
42 |
rtcpSocket = new DatagramSocket(6003); |
|
43 |
} catch (Exception e) { |
|
44 |
System.out.println("RTPSession failed to obtain port"); |
|
45 |
} |
|
46 |
RTPSession rtpSession = new RTPSession(rtpSocket, rtcpSocket); |
|
47 |
|
|
48 |
|
|
49 |
String str1 = "ab"; |
|
50 |
String str2 = "cd"; |
|
51 |
String str3 = "ef"; |
|
52 |
String str4 = "gh"; |
|
53 |
String str5 = "ij"; |
|
54 |
String str6 = "kl"; |
|
55 |
//String str7 = "mn"; |
|
56 |
|
|
57 |
long syncSource1 = 1; |
|
58 |
int seqNumber1 = 1; |
|
59 |
//int seqNumber2 = 1; |
|
60 |
RtpPkt pkt1 = new RtpPkt(10, syncSource1, 1, 0, str1.getBytes()); |
|
61 |
RtpPkt pkt2 = new RtpPkt(20, syncSource1, 2, 0, str2.getBytes()); |
|
62 |
RtpPkt pkt3 = new RtpPkt(30, syncSource1, 3, 0, str3.getBytes()); |
|
63 |
RtpPkt pkt4 = new RtpPkt(40, syncSource1, 4, 0, str4.getBytes()); |
|
64 |
RtpPkt pkt6 = new RtpPkt(60, syncSource1, 6, 0, str5.getBytes()); |
|
65 |
RtpPkt pkt7 = new RtpPkt(70, syncSource1, 7, 0, str6.getBytes()); |
|
66 |
|
|
67 |
Participant p = new Participant(); |
|
68 |
|
|
69 |
PktBuffer pktBuf = new PktBuffer(rtpSession, p, pkt1); |
|
70 |
pktBuf.addPkt(pkt3); //2 |
|
71 |
pktBuf.addPkt(pkt2); //3 |
|
72 |
DataFrame aFrame = pktBuf.popOldestFrame(); |
|
73 |
String outStr = new String(aFrame.getConcatenatedData()); |
|
74 |
System.out.println("** 1 Data from first frame: " + outStr + ", should be ab"); |
|
75 |
pktBuf.addPkt(pkt4); //3 |
|
76 |
pktBuf.addPkt(pkt7); //4 |
|
77 |
System.out.println("** 1.5 sixth"); |
|
78 |
pktBuf.addPkt(pkt6); //5 |
|
79 |
System.out.println("** 2 Duplicate, should be dropped"); |
|
80 |
pktBuf.addPkt(pkt3); //5 |
|
81 |
// Pop second frame |
|
82 |
aFrame = pktBuf.popOldestFrame(); //4 |
|
83 |
outStr = new String(aFrame.getConcatenatedData()); |
|
84 |
System.out.println("** 3 Data from second frame: " + outStr + ", should be cd"); |
|
85 |
|
|
86 |
// Pop third frame |
|
87 |
aFrame = pktBuf.popOldestFrame(); //3 |
|
88 |
outStr = new String(aFrame.getConcatenatedData()); |
|
89 |
System.out.println("** 4 Data from third frame: " + outStr + ", should be ef"); |
|
90 |
System.out.println("** 5 pktBuf.getLength is " + pktBuf.getLength() + ", should be 3"); |
|
91 |
|
|
92 |
System.out.println("** 6 Late arrival, should be dropped"); |
|
93 |
pktBuf.addPkt(pkt2); |
|
94 |
|
|
95 |
aFrame = pktBuf.popOldestFrame(); |
|
96 |
outStr = new String(aFrame.getConcatenatedData()); |
|
97 |
System.out.println("** 7 Data from fourth frame: " + outStr + ", should be gh"); |
|
98 |
|
|
99 |
aFrame = pktBuf.popOldestFrame(); |
|
100 |
outStr = new String(aFrame.getConcatenatedData()); |
|
101 |
System.out.println("** 8 Data from fifth frame: " + outStr + ", should be ij"); |
|
102 |
|
|
103 |
aFrame = pktBuf.popOldestFrame(); |
|
104 |
outStr = new String(aFrame.getConcatenatedData()); |
|
105 |
System.out.println("** 9 Data from fifth frame: " + outStr + ", should be kl"); |
|
106 |
} |
|
107 |
|
|
108 |
} |