-
Notifications
You must be signed in to change notification settings - Fork 15
/
packetQueue.h
173 lines (168 loc) · 4.59 KB
/
packetQueue.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#ifndef INCLUDED_PACKETQUEUE_H
#define INCLUDED_PACKETQUEUE_H
#include <iostream>
#include <stdint.h>
#include <string.h>
#include "packetParser.h"
using namespace std;
class node {
public:
//////////////////////////////////
int dataSize;
int dataUsed;
unsigned char *dataBuffer;
node *next;
//////////////////////////////////
node() {
dataSize = 2048;
dataUsed = 0;
next = NULL;
dataBuffer = (unsigned char*) malloc(2048 * sizeof(uint8_t));
}
~node() {};
uint32_t getTS() {
if(dataUsed == 0) {
return 0;
}
else {
rtpPacket_ *rtpPacket = (rtpPacket_ *) dataBuffer;
return ntohl(rtpPacket -> rtpHeader.ts);
}
}
uint16_t getSN() {
if(dataUsed == 0) {
return 0;
}
else {
rtpPacket_ *rtpPacket = (rtpPacket_ *) dataBuffer;
return ntohs(rtpPacket -> rtpHeader.sequenceNum);
}
}
uint16_t getSNBase() {
if(dataUsed != 1344) {
printf("getSNBase: %d\n" , dataUsed);
exit(1);
}
else {
fecPacket_ *fecPacket = (fecPacket_ *) dataBuffer;
return ntohs(fecPacket -> fecHeader.SNBase);
}
}
uint8_t getOffset() {
if(dataUsed != 1344) {
printf("getOffset\n");
exit(1);
}
else {
fecPacket_ *fecPacket = (fecPacket_ *) dataBuffer;
return fecPacket -> fecHeader.offset;
}
}
uint8_t getNA() {
if(dataUsed != 1344) {
printf("getNA\n");
exit(1);
}
else {
fecPacket_ *fecPacket = (fecPacket_ *) dataBuffer;
return fecPacket -> fecHeader.NA;
}
}
int isTsToolate(uint32_t currentTS , int maxTimeRange) {
if(currentTS == 0) {
return 0;
}
else {
uint32_t thisTS = this -> getTS();
if(thisTS + maxTimeRange < currentTS) {
return 1;
}
else {
return 0;
}
}
}
int isPacketToolate(uint32_t currentTS , int maxTimeRange) {
if(dataUsed > 0) {
printf("gg: isPacketToolate()\n");
exit(1);
}
else {
int counter = 1;
node *temp = this;
while(temp -> next) {
temp = temp -> next;
if(temp -> dataUsed > 0) {
if(temp -> isTsToolate(currentTS , maxTimeRange)) { //bug resolved!
return counter;
}
else {
return 0;
}
}
else {
counter++;
}
}
printf("fucked up\n");
exit(1);
}
}
};
class queue {
public:
//////////////////////////////////
node *head , *tail;
int size;
//////////////////////////////////
queue() {
head = NULL;
tail = NULL;
size = 0;
}
~queue() {};
int isEmpty() {
if(size == 0) {
return 1;
}
else {
return 0;
}
}
void enqueue(node *target) {
if(target == NULL) {
printf("target is NULL\n");
exit(1);
}
else {
target -> next = NULL;
if(isEmpty()) {
head = target;
}
else {
tail -> next = target;
}
tail = target;
size++;
return;
}
}
node *dequeue() {
if(isEmpty()) {
return NULL;
}
else {
node* res = head;
if(head -> next) {
head = head -> next;
}
else {
head = NULL;
}
size--;
res -> next = NULL;
return res;
}
}
};
#endif