forked from grishka/libtgvoip
-
Notifications
You must be signed in to change notification settings - Fork 49
/
PacketReassembler.h
70 lines (58 loc) · 1.61 KB
/
PacketReassembler.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
//
// Created by Grishka on 19.03.2018.
//
#ifndef TGVOIP_PACKETREASSEMBLER_H
#define TGVOIP_PACKETREASSEMBLER_H
#include <vector>
#include <functional>
#include <unordered_map>
#include "Buffers.h"
namespace tgvoip {
class PacketReassembler{
public:
PacketReassembler();
virtual ~PacketReassembler();
void Reset();
void AddFragment(Buffer pkt, unsigned int fragmentIndex, unsigned int fragmentCount, uint32_t pts, bool keyframe);
void SetCallback(std::function<void(Buffer packet, uint32_t pts, bool keyframe)> callback);
private:
struct Packet{
uint32_t timestamp;
uint32_t partCount;
uint32_t receivedPartCount;
bool isKeyframe;
Buffer* parts;
TGVOIP_DISALLOW_COPY_AND_ASSIGN(Packet);
Packet(Packet&& other) : timestamp(other.timestamp), partCount(other.partCount), receivedPartCount(other.receivedPartCount), isKeyframe(other.isKeyframe){
parts=other.parts;
other.parts=NULL;
}
Packet& operator=(Packet&& other){
if(&other!=this){
if(parts)
delete[] parts;
parts=other.parts;
other.parts=NULL;
timestamp=other.timestamp;
partCount=other.partCount;
receivedPartCount=other.receivedPartCount;
isKeyframe=other.isKeyframe;
}
return *this;
}
Packet(uint32_t partCount) : partCount(partCount){
parts=new Buffer[partCount];
}
~Packet(){
if(parts)
delete[] parts;
}
void AddFragment(Buffer pkt, uint32_t fragmentIndex);
Buffer Reassemble();
};
std::function<void(Buffer, uint32_t, bool)> callback;
std::vector<Packet> packets;
uint32_t maxTimestamp=0;
};
}
#endif //TGVOIP_PACKETREASSEMBLER_H