2018-06-04 21:37:43 +02:00
|
|
|
//
|
|
|
|
// Created by Grishka on 19.03.2018.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef TGVOIP_PACKETREASSEMBLER_H
|
|
|
|
#define TGVOIP_PACKETREASSEMBLER_H
|
|
|
|
|
2018-11-09 16:44:01 +01:00
|
|
|
#include <vector>
|
|
|
|
#include <functional>
|
2019-02-05 12:41:00 +01:00
|
|
|
#include <unordered_map>
|
2018-11-09 16:44:01 +01:00
|
|
|
|
|
|
|
#include "Buffers.h"
|
2018-06-04 21:37:43 +02:00
|
|
|
|
|
|
|
namespace tgvoip {
|
2018-11-09 16:44:01 +01:00
|
|
|
class PacketReassembler{
|
2018-06-04 21:37:43 +02:00
|
|
|
public:
|
|
|
|
PacketReassembler();
|
|
|
|
virtual ~PacketReassembler();
|
|
|
|
|
|
|
|
void Reset();
|
2019-02-05 12:41:00 +01:00
|
|
|
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);
|
2018-06-04 21:37:43 +02:00
|
|
|
|
|
|
|
private:
|
2019-03-10 23:12:09 +01:00
|
|
|
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();
|
|
|
|
};
|
2019-02-05 12:41:00 +01:00
|
|
|
std::function<void(Buffer, uint32_t, bool)> callback;
|
2019-03-10 23:12:09 +01:00
|
|
|
std::vector<Packet> packets;
|
|
|
|
uint32_t maxTimestamp=0;
|
2018-06-04 21:37:43 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif //TGVOIP_PACKETREASSEMBLER_H
|