| 6 |
| #define TGVOIP_PACKETREASSEMBLER_H |
| 7 |
| 8 | #include <vector> |
| 9 | #include <functional> |
| 10 | #include <unordered_map> |
| 11 |
| 12 | #include "Buffers.h" |
| 13 |
| 14 | namespace tgvoip { |
| 15 | class PacketReassembler{ |
| 16 | public: |
| 17 | PacketReassembler(); |
| 18 | virtual ~PacketReassembler(); |
| 19 |
| 20 | void Reset(); |
| 21 | void AddFragment(Buffer pkt, unsigned int fragmentIndex, unsigned int fragmentCount, uint32_t pts, bool keyframe, uint16_t rotation); |
| 22 | void SetCallback(std::function<void(Buffer packet, uint32_t pts, bool keyframe, uint16_t rotation)> callback); |
| 23 |
| 24 | private: |
| 25 | struct Packet{ |
| 26 | uint32_t timestamp; |
| 27 | uint32_t partCount; |
| 28 | uint32_t receivedPartCount; |
| 29 | bool isKeyframe; |
| 30 | uint16_t rotation; |
| 31 | Buffer* parts; |
| 32 |
| 33 | TGVOIP_DISALLOW_COPY_AND_ASSIGN(Packet); |
| 34 |
| 35 | Packet(Packet&& other) : timestamp(other.timestamp), partCount(other.partCount), receivedPartCount(other.receivedPartCount), isKeyframe(other.isKeyframe), rotation(other.rotation){ |
| 36 | parts=other.parts; |
| 37 | other.parts=NULL; |
| 38 | } |
| 39 | Packet& operator=(Packet&& other){ |
| 40 | if(&other!=this){ |
| 41 | if(parts) |
| 42 | delete[] parts; |
| 43 | parts=other.parts; |
| 44 | other.parts=NULL; |
| 45 | timestamp=other.timestamp; |
| 46 | partCount=other.partCount; |
| 47 | receivedPartCount=other.receivedPartCount; |
| 48 | isKeyframe=other.isKeyframe; |
| 49 | rotation=other.rotation; |
| 50 | } |
| 51 | return *this; |
| 52 | } |
| 53 |
| 54 | Packet(uint32_t partCount) : partCount(partCount){ |
| 55 | parts=new Buffer[partCount]; |
| 56 | } |
| 57 | ~Packet(){ |
| 58 | if(parts) |
| 59 | delete[] parts; |
| 60 | } |
| 61 |
| 62 |
| 63 | void AddFragment(Buffer pkt, uint32_t fragmentIndex); |
| 64 | Buffer Reassemble(); |
| 65 | }; |
| 66 | std::function<void(Buffer, uint32_t, bool, uint16_t)> callback; |
| 67 | std::vector<Packet> packets; |
| 68 | uint32_t maxTimestamp=0; |
| 69 | }; |
| 70 | } |
| 71 |
| 72 | #endif //TGVOIP_PACKETREASSEMBLER_H |
| 73 |