packet.h 4.72 KB
Newer Older
1
2
3
4
#ifndef PRRT_FRAME_H
#define PRRT_FRAME_H

#include <stdint.h>
Andreas Schmidt's avatar
Andreas Schmidt committed
5
#include "codingParams.h"
6
#include <stdbool.h>
7

Stefan Reif's avatar
Stefan Reif committed
8
9
#include "../util/pipe.h"

10
11
12
13
14
15
16
17
18
19
20
21
22
typedef enum {
    PACKET_TYPE_DATA = 0,
    PACKET_TYPE_REPETITION = 1,
    PACKET_TYPE_REDUNDANCY = 2,
    PACKET_TYPE_FEEDBACK = 3,
    PACKET_TYPE_PRESENT_REDUNDANCY = 4,
    PACKET_TYPE_CHANNEL_FEEDBACK = 5
} prrtPacketType_t;

typedef uint16_t prrtSequenceNumber_t;
typedef uint8_t prrtIndex_t;
typedef uint32_t prrtTimestamp_t;
typedef uint32_t prrtTimedelta_t;
Andreas Schmidt's avatar
Andreas Schmidt committed
23
typedef int32_t prrtTimeDifference_t;
24
typedef uint32_t prrtPacketLength_t;
Andreas Schmidt's avatar
Andreas Schmidt committed
25
typedef float prrtPacketLossRate_t;
26
27
28
29
30

typedef struct prrtIncompleteBlock {
    prrtSequenceNumber_t sequenceNumberBase;
    uint16_t repairCycleIndex;
} PrrtIncompleteBlock;
31

32
typedef struct prrtPacket {
Andreas Schmidt's avatar
Andreas Schmidt committed
33
    ListNode asListNode;
34
    uint8_t type_priority;
35
36
37
38
    prrtIndex_t index;
    prrtSequenceNumber_t sequenceNumber;
    void *payload;
    prrtPacketLength_t payloadLength;
39
} PrrtPacket;
40
#define PRRT_PACKET_GENERAL_HEADER_SIZE 8
41
#define PRRT_PACKET_ENCODED_GENERAL_HEADER_LENGTH 4
42

43
typedef struct prrtPacketDataPayload {
rna's avatar
rna committed
44
	prrtPacketLength_t dataLength;
45
    prrtTimestamp_t timestamp;
46
    prrtTimedelta_t groupRTprop_us;
47
48
49
    prrtTimestamp_t packetTimeout_us;
    prrtTimestamp_t decodingTimeout_us;
    prrtTimedelta_t feedbackTimer_us;
50
} PrrtPacketDataPayload;
51
#define PRRT_PACKET_DATA_HEADER_SIZE sizeof(PrrtPacketDataPayload)
52

53
typedef struct prrtPacketRedundancyPayload {
54
    prrtSequenceNumber_t baseSequenceNumber;
55
56
57
    uint8_t n;
    uint8_t k;
} PrrtPacketRedundancyPayload;
58
#define PRRT_PACKET_REDUNDANCY_HEADER_SIZE sizeof(PrrtPacketRedundancyPayload)
59

60
typedef struct prrtPacketFeedbackPayload {
61
62
63
64
65
66
67
68
69
70
71
    uint32_t receiverAddress;
    prrtTimedelta_t groupRTT_us;
    prrtTimestamp_t forwardTripTimestamp_us;
    prrtSequenceNumber_t erasureCount;
    prrtSequenceNumber_t packetCount;
    prrtSequenceNumber_t gapLength;
    prrtSequenceNumber_t gapCount;
    prrtSequenceNumber_t burstLength;
    prrtSequenceNumber_t burstCount;
    uint32_t bandwidthEstimate;
    PrrtIncompleteBlock *incompleteBlocks;
72
} PrrtPacketFeedbackPayload;
rna's avatar
rna committed
73
#define PRRT_PACKET_FEEDBACK_HEADER_SIZE (sizeof(PrrtPacketFeedbackPayload) - sizeof(PrrtIncompleteBlock*))
74
75

prrtPacketType_t PrrtPacket_type(PrrtPacket *packet_ptr);
76

77
uint8_t PrrtPacket_priority(PrrtPacket *packet_ptr);
78
79
80

prrtPacketLength_t PrrtPacket_size(PrrtPacket *packet_ptr);

81
int PrrtPacket_print(PrrtPacket *packet_ptr);
82

83
PrrtPacket *PrrtPacket_copy(PrrtPacket *original);
84

85
PrrtPacket *PrrtPacket_create_data_packet(uint8_t priority, const void *payloadPointer,
rna's avatar
rna committed
86
                                          prrtPacketLength_t dataLength, prrtSequenceNumber_t sequenceNumber,
87
                                          prrtTimedelta_t targetDelay);
rna's avatar
rna committed
88
PrrtPacket* PrrtPacket_reconstruct_data_packet(PrrtPacketDataPayload* payload, prrtIndex_t index, prrtSequenceNumber_t sequenceNumber);
89

90
PrrtPacket *PrrtPacket_create_feedback_packet(uint8_t priority, uint8_t index, prrtSequenceNumber_t sequenceNumber,
91
                                              prrtTimedelta_t groupRTT, prrtSequenceNumber_t gapLength,
92
93
                                              prrtSequenceNumber_t gapCount, prrtSequenceNumber_t burstLength,
                                              prrtSequenceNumber_t burstCount, uint32_t bandwidth,
Andreas Schmidt's avatar
Andreas Schmidt committed
94
95
                                              uint32_t receiverAddr, prrtTimestamp_t forwardTripTime,
                                              prrtSequenceNumber_t erasureCount, prrtSequenceNumber_t packetCount);
96

97
98
99
PrrtPacket *PrrtPacket_create_redundancy_packet(uint8_t priority, void *payloadPointer,
                                                prrtPacketLength_t payloadLength,
                                                prrtSequenceNumber_t sequenceNumber, uint8_t index,
Andreas Schmidt's avatar
Andreas Schmidt committed
100
101
                                                prrtSequenceNumber_t baseSequenceNumber,
                                                PrrtCodingParams *codingParams);
102

103
bool PrrtPacket_decode(void *srcBuffer, uint16_t srcBufferSize, PrrtPacket *targetPacket);
104

105
bool PrrtPacket_encode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr);
106

Andreas Schmidt's avatar
Andreas Schmidt committed
107
int PrrtPacket_destroy(PrrtPacket *packet);
108

rna's avatar
rna committed
109
110
#define PrrtPacket_copy_payload_to_buffer(dst, packet, header_size) memcpy(dst, (packet)->payload + (header_size), (packet)->payloadLength - (header_size));
#define PrrtPacket_copy_buffer_to_payload(packet, src, header_size) memcpy((packet)->payload + (header_size), src, (packet)->payloadLength - (header_size));
111

Andreas Schmidt's avatar
Andreas Schmidt committed
112
#define PrrtPacket_get_data_timestamp(packet) ((PrrtPacketDataPayload*) packet->payload)->timestamp;
113

Stefan Reif's avatar
Stefan Reif committed
114
115
#define PrrtPacket_byListNode(lnptr) ((PrrtPacket *) (lnptr))

rna's avatar
rna committed
116
#define PrrtDataPacket_packet_timeout(packet) ((PrrtPacketDataPayload*) (packet)->payload)->packetTimeout_us
117

118
#endif //PRRT_FRAME_H