-
Notifications
You must be signed in to change notification settings - Fork 15
/
client.cpp
126 lines (106 loc) · 3.59 KB
/
client.cpp
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
#include <iostream>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <pthread.h>
#include "socketConnection.h"
#include "packetQueue.h"
#include "packetBuffer.h"
#include "monitor.h"
#define RECVBUFLEN 1500
using namespace std;
void *threadproc(void *arg);
packetBuffer *myPacketBuffer = new packetBuffer(2048);
monitor *myMonitor = new monitor();
int main(int argc, char *argv[]) {
string mediaIP;
string mediaPort;
string fecTimes;
string maxDelay;
string outputIP;
string outputPort;
unsigned char *sockRecvBuf = (unsigned char*)malloc(RECVBUFLEN * sizeof(unsigned char));
mediaIP = "239.255.0.1";
mediaPort = "20000";
outputIP = "127.0.0.1";
outputPort = "8000";
maxDelay = "500";
if(argc == 2) {
maxDelay = argv[1];
}
else if(argc == 3) {
mediaIP = argv[1];
mediaPort = argv[2];
}
else if(argc == 4) {
mediaIP = argv[1];
mediaPort = argv[2];
maxDelay = argv[5];
}
else if(argc == 5) {
mediaIP = argv[1];
mediaPort = argv[2];
outputIP = argv[3];
outputPort = argv[4];
}
else if(argc == 6) {
mediaIP = argv[1];
mediaPort = argv[2];
outputIP = argv[3];
outputPort = argv[4];
maxDelay = argv[5];
}
socketUtility *mySocketUtility = new socketUtility(mediaIP.c_str() , mediaPort.c_str(), outputIP.c_str() , outputPort.c_str());
fd_set master;
fd_set read_fds;
FD_ZERO(&master);
FD_ZERO(&read_fds);
FD_SET(mySocketUtility -> media_Sockfd , &master);
FD_SET(mySocketUtility -> fecRow_Sockfd , &master);
FD_SET(mySocketUtility -> fecCol_Sockfd , &master);
read_fds = master;
pthread_t tid;
pthread_create(&tid , NULL , &threadproc , NULL);
for(;;) {
myPacketBuffer -> updateFecQueue();
myPacketBuffer -> fecRecovery();
myPacketBuffer -> updateMediaQueue( mySocketUtility -> output_Sockfd , stoi(maxDelay) * 100 );
myPacketBuffer -> updateMinSN();
myMonitor -> updateRecovered(myPacketBuffer -> recovered);
read_fds = master;
struct timeval tv = {0 , 50};
select( (mySocketUtility -> fdmax)+1 , &read_fds , NULL , NULL , &tv);
if(FD_ISSET(mySocketUtility -> media_Sockfd , &read_fds)) {
int bytes = 0;
if((bytes = recv(mySocketUtility -> media_Sockfd , sockRecvBuf , RECVBUFLEN , 0)) < 0)
mySocketUtility -> ~socketUtility();
myMonitor -> media -> updateStatus(sockRecvBuf);
myPacketBuffer -> newMediaPacket(sockRecvBuf , bytes);
}
if(FD_ISSET(mySocketUtility -> fecRow_Sockfd , &read_fds)) {
int bytes = 0;
if((bytes = recv(mySocketUtility -> fecRow_Sockfd , sockRecvBuf , RECVBUFLEN , 0)) < 0)
mySocketUtility -> ~socketUtility();
myMonitor -> fecRow -> updateStatus(sockRecvBuf);
myPacketBuffer -> newFecPacket(sockRecvBuf , bytes);
}
if(FD_ISSET(mySocketUtility -> fecCol_Sockfd , &read_fds)) {
int bytes = 0;
if((bytes = recv(mySocketUtility -> fecCol_Sockfd , sockRecvBuf , RECVBUFLEN , 0)) < 0)
mySocketUtility -> ~socketUtility();
myMonitor -> fecCol -> updateStatus(sockRecvBuf);
myPacketBuffer -> newFecPacket(sockRecvBuf , bytes);
}
}
return 0; //never reached
}
void *threadproc(void *arg) {
while(1) {
sleep(5);
myPacketBuffer -> bufferMonitor();
myMonitor -> printMonitor();
}
return 0;
}