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

#include <stdint.h>
5
6
#include "../../util/pipe.h"
#include "../codingParams.h"
7
#include <stdbool.h>
8
#include <netinet/in.h>
9

Stefan Reif's avatar
Stefan Reif committed
10

11
12
13
14
15
16
17
18
19
20
21
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;
22
23
24
25
typedef uint32_t prrtTimestamp_t; // microsecond
typedef uint32_t prrtTimedelta_t; // microsecond
typedef int32_t prrtTimeDifference_t; // microsecond
typedef uint32_t prrtPacketLength_t; // bytes
Andreas Schmidt's avatar
Andreas Schmidt committed
26
typedef float prrtPacketLossRate_t;
27
28
29
typedef uint32_t prrtDeliveryRate_t; // bits per second
typedef uint32_t prrtByteCount_t;

30
31
32
33
34

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

36
typedef struct prrtPacket {
Andreas Schmidt's avatar
Andreas Schmidt committed
37
    ListNode asListNode;
38
    uint8_t type_priority;
39
40
41
42
    prrtIndex_t index;
    prrtSequenceNumber_t sequenceNumber;
    void *payload;
    prrtPacketLength_t payloadLength;
43
44
45
46
47
48
49
50

    // Packet State field that are not put into the packet on the wire
    prrtByteCount_t delivered;
    prrtTimestamp_t delivered_time;
    prrtTimestamp_t first_sent_time;
    bool is_app_limited;
    prrtTimestamp_t sent_time;
    prrtTimedelta_t rtt;
51
52

    struct sockaddr_in sender_addr;
53
} PrrtPacket;
54
#define PRRT_PACKET_GENERAL_HEADER_SIZE 8
55
#define PRRT_PACKET_ENCODED_GENERAL_HEADER_LENGTH 4
56

57
typedef struct prrtPacketDataPayload {
58
    prrtPacketLength_t dataLength;
59
    prrtTimestamp_t timestamp;
60
    prrtTimedelta_t groupRTprop_us;
61
    prrtTimestamp_t packetTimeout_us;
62
} PrrtPacketDataPayload;
63
#define PRRT_PACKET_DATA_HEADER_SIZE sizeof(PrrtPacketDataPayload)
64

65
typedef struct prrtPacketRedundancyPayload {
66
    prrtSequenceNumber_t baseSequenceNumber;
67
    prrtTimestamp_t timestamp;
68
69
70
    uint8_t n;
    uint8_t k;
} PrrtPacketRedundancyPayload;
71
#define PRRT_PACKET_REDUNDANCY_HEADER_SIZE sizeof(PrrtPacketRedundancyPayload)
72

73
typedef struct prrtPacketFeedbackPayload {
74
75
76
77
78
79
80
81
    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;
82
83
    prrtSequenceNumber_t ackSequenceNumber;
    prrtPacketType_t ackPacketType;
84
    PrrtIncompleteBlock *incompleteBlocks;
85
} PrrtPacketFeedbackPayload;
rna's avatar
rna committed
86
#define PRRT_PACKET_FEEDBACK_HEADER_SIZE (sizeof(PrrtPacketFeedbackPayload) - sizeof(PrrtIncompleteBlock*))
87
88

prrtPacketType_t PrrtPacket_type(PrrtPacket *packet_ptr);
89

90
uint8_t PrrtPacket_priority(PrrtPacket *packet_ptr);
91
92
93

prrtPacketLength_t PrrtPacket_size(PrrtPacket *packet_ptr);

94
int PrrtPacket_print(PrrtPacket *packet_ptr);
95

96
PrrtPacket *PrrtPacket_copy(PrrtPacket *original);
97

98
PrrtPacket *PrrtPacket_create_data_packet(uint8_t priority, const void *payloadPointer,
rna's avatar
rna committed
99
                                          prrtPacketLength_t dataLength, prrtSequenceNumber_t sequenceNumber,
100
                                          prrtTimedelta_t targetDelay);
101

102
103
104
105
106
107
108
109
110
111
PrrtPacket *PrrtPacket_reconstruct_data_packet(PrrtPacketDataPayload *payload, prrtIndex_t index,
                                               prrtSequenceNumber_t sequenceNumber);

PrrtPacket *
PrrtPacket_create_feedback_packet(uint8_t priority, prrtSequenceNumber_t sequenceNumber, prrtTimedelta_t groupRTT,
                                  prrtSequenceNumber_t gapLength, prrtSequenceNumber_t gapCount,
                                  prrtSequenceNumber_t burstLength, prrtSequenceNumber_t burstCount,
                                  prrtTimestamp_t forwardTripTime, prrtSequenceNumber_t erasureCount,
                                  prrtSequenceNumber_t packetCount, prrtSequenceNumber_t ackSequenceNumber,
                                  prrtPacketType_t ackPacketType);
112

113
114
115
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
116
                                                prrtSequenceNumber_t baseSequenceNumber,
117
                                                PrrtCodingConfiguration *codingParams);
118

119
bool PrrtPacket_decode(void *srcBuffer, uint16_t srcBufferSize, PrrtPacket *targetPacket);
120

121
bool PrrtPacket_encode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr);
122

Andreas Schmidt's avatar
Andreas Schmidt committed
123
int PrrtPacket_destroy(PrrtPacket *packet);
124

rna's avatar
rna committed
125
126
#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));
127

Andreas Schmidt's avatar
Andreas Schmidt committed
128
#define PrrtPacket_get_data_timestamp(packet) ((PrrtPacketDataPayload*) packet->payload)->timestamp;
129
#define PrrtPacket_get_redundancy_timestamp(packet) ((PrrtPacketRedundancyPayload*) packet->payload)->timestamp;
130

Stefan Reif's avatar
Stefan Reif committed
131
132
#define PrrtPacket_byListNode(lnptr) ((PrrtPacket *) (lnptr))

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

135
#endif //PRRT_FRAME_H