packet.h 4.52 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
25
26
27
28
29
typedef uint32_t prrtPacketLength_t;

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

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

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

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

59
typedef struct prrtPacketFeedbackPayload {
60
61
62
63
64
65
66
67
68
69
70
    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;
71
} PrrtPacketFeedbackPayload;
rna's avatar
rna committed
72
#define PRRT_PACKET_FEEDBACK_HEADER_SIZE (sizeof(PrrtPacketFeedbackPayload) - sizeof(PrrtIncompleteBlock*))
73
74

prrtPacketType_t PrrtPacket_type(PrrtPacket *packet_ptr);
75

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

prrtPacketLength_t PrrtPacket_size(PrrtPacket *packet_ptr);

80
int PrrtPacket_print(PrrtPacket *packet_ptr);
81

82
PrrtPacket *PrrtPacket_copy(PrrtPacket *original);
83

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

89
PrrtPacket *PrrtPacket_create_feedback_packet(uint8_t priority, uint8_t index, prrtSequenceNumber_t sequenceNumber,
90
                                              prrtTimedelta_t groupRTT, prrtSequenceNumber_t gapLength,
91
92
                                              prrtSequenceNumber_t gapCount, prrtSequenceNumber_t burstLength,
                                              prrtSequenceNumber_t burstCount, uint32_t bandwidth,
93
                                              uint32_t receiverAddr, prrtTimestamp_t forwardTripTime);
94

95
96
97
PrrtPacket *PrrtPacket_create_redundancy_packet(uint8_t priority, void *payloadPointer,
                                                prrtPacketLength_t payloadLength,
                                                prrtSequenceNumber_t sequenceNumber, uint8_t index,
98
                                                prrtSequenceNumber_t baseSequenceNumber, PrrtCodingParams* codingParams);
99

100
bool PrrtPacket_decode(void *srcBuffer, uint16_t srcBufferSize, PrrtPacket *targetPacket);
101

102
bool PrrtPacket_encode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr);
103

Andreas Schmidt's avatar
Andreas Schmidt committed
104
int PrrtPacket_destroy(PrrtPacket *packet);
105

rna's avatar
rna committed
106
107
#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));
108

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

Stefan Reif's avatar
Stefan Reif committed
111
112
#define PrrtPacket_byListNode(lnptr) ((PrrtPacket *) (lnptr))

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

115
#endif //PRRT_FRAME_H