-
Notifications
You must be signed in to change notification settings - Fork 295
/
RTPSource.h
159 lines (129 loc) · 2.78 KB
/
RTPSource.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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: RTPSource.h
* Author: Sergio
*
* Created on 13 de julio de 2018, 11:49
*/
#ifndef RTPSOURCE_H
#define RTPSOURCE_H
#include "config.h"
#include "acumulator.h"
#include "use.h"
#include "rtp/RTCPSenderReport.h"
#include "rtp/RTCPCompoundPacket.h"
struct LayerSource : LayerInfo
{
DWORD numPackets = 0;
DWORD totalBytes = 0;
DWORD bitrate;
Acumulator acumulator;
LayerSource() : acumulator(1000)
{
}
LayerSource(const LayerInfo& layerInfo) : acumulator(1000)
{
spatialLayerId = layerInfo.spatialLayerId;
temporalLayerId = layerInfo.temporalLayerId;
}
void Update(QWORD now, DWORD size)
{
//Increase stats
numPackets++;
totalBytes += size;
//Update bitrate acumulator
acumulator.Update(now,size);
//Update bitrate in bps
bitrate = acumulator.GetInstant()*8;
}
};
struct RTPSource : public Mutex
{
DWORD ssrc;
DWORD extSeqNum;
DWORD cycles;
DWORD jitter;
DWORD numPackets;
DWORD numRTCPPackets;
DWORD totalBytes;
DWORD totalRTCPBytes;
DWORD bitrate;
Acumulator acumulator;
RTPSource() : acumulator(1000)
{
ssrc = 0;
extSeqNum = 0;
cycles = 0;
numPackets = 0;
numRTCPPackets = 0;
totalBytes = 0;
totalRTCPBytes = 0;
jitter = 0;
bitrate = 0;
}
virtual ~RTPSource()
{
}
RTCPCompoundPacket::shared CreateSenderReport();
WORD SetSeqNum(WORD seqNum)
{
//Check if we have a sequence wrap
if (seqNum<0x0FFF && (extSeqNum & 0xFFFF)>0xF000)
//Increase cycles
cycles++;
//Get ext seq
DWORD extSeqNum = ((DWORD)cycles)<<16 | seqNum;
//If we have a not out of order pacekt
if (extSeqNum > this->extSeqNum || !numPackets)
//Update seq num
this->extSeqNum = extSeqNum;
//Return seq cycles count
return cycles;
}
void SetExtSeqNum(DWORD extSeqNum )
{
//Updte seqNum and cycles
this->extSeqNum = extSeqNum;
cycles = extSeqNum >>16;
}
/*
* Get seq num cycles from a past sequence numer
*/
WORD RecoverSeqNum(WORD osn)
{
//Check secuence wrap
if ((extSeqNum & 0xFFFF)<0x0FFF && (osn>0xF000))
//It is from the past cycle
return cycles - 1;
//It is from current cyle
return cycles;
}
virtual void Update(QWORD now, DWORD seqNum,DWORD size)
{
//Increase stats
numPackets++;
totalBytes += size;
//Update bitrate acumulator
acumulator.Update(now,size);
//Get bitrate in bps
bitrate = acumulator.GetInstant()*8;
}
virtual void Reset()
{
extSeqNum = 0;
cycles = 0;
numPackets = 0;
numRTCPPackets = 0;
totalBytes = 0;
totalRTCPBytes = 0;
jitter = 0;
bitrate = 0;
//Reset accumulators
acumulator.Reset(0);
}
};
#endif /* RTPSOURCE_H */