-
Notifications
You must be signed in to change notification settings - Fork 15
/
monitor.h
70 lines (63 loc) · 2.05 KB
/
monitor.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
#ifndef INCLUDED_MONITOR_H
#define INCLUDED_MONITOR_H
#include <iostream>
#include <stdint.h>
#include <string.h>
#include <arpa/inet.h>
#include "packetParser.h"
using namespace std;
class streamCounter {
public:
int recvd;
int lost;
uint16_t latestSN;
streamCounter() {
recvd = 0;
lost = 0;
latestSN = 0;
}
~streamCounter(){};
void printStatus() {
printf(" recvd: %d , lost: %d , loss rate: %lf\n", recvd , lost , ( 100*lost / (double)(lost + recvd)));
}
void updateStatus(const void *buffer) {
rtpHeader_ *rtpHeader = (rtpHeader_ *)buffer;
uint16_t thisSN = ntohs(rtpHeader -> sequenceNum);
if( latestSN > 0 && (thisSN - 1) > latestSN ) {
int lostCounter = (thisSN - latestSN) - 1;
lost+= lostCounter;
}
recvd++;
latestSN = thisSN;
return;
}
};
class monitor {
public:
streamCounter *media;
streamCounter *fecRow;
streamCounter *fecCol;
int recovered;
monitor() {
media = new streamCounter();
fecRow = new streamCounter();
fecCol = new streamCounter();
recovered = 0;
}
~monitor(){};
void updateRecovered(int newRecovered) {
recovered = newRecovered;
}
void printMonitor() {
printf("media stream:\n");
media -> printStatus();
printf(" recovered/lost: %d/%d = %lf\n" , recovered , media -> lost , (100 * recovered / (double)media -> lost));
printf(" loss rate after recovery: %d/%d = %lf\n" , (media -> lost - recovered) , (media -> recvd + media -> lost) , ( 100 * (media -> lost - recovered) / (double)(media -> recvd + media -> lost) ) );
printf("fecRow stream:\n");
fecRow -> printStatus();
printf("fecCol stream:\n");
fecCol -> printStatus();
printf("\n");
}
};
#endif