packet.h 2.58 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 <src/prrt/coding_params.h>
6

7
#define PACKET_TYPE_DATA 0
8
#define PACKET_TYPE_REPETITION 1
9
#define PACKET_TYPE_REDUNDANCY 2
10
#define PACKET_TYPE_FEEDBACK 3
11
12
#define PACKET_TYPE_PRE_REDUNDANCY 4
#define PACKET_TYPE_CHANNEL_FEEDBACK 5
13

14
#define PRRT_PACKET_GENERAL_HEADER_SIZE 4
15
16
17
18
19
20
typedef struct {
    uint8_t type_priority;
    uint8_t index;
    uint16_t seqno;
    void* payload;
    uint32_t payload_len;
21
} PrrtPacket;
22

23
#define SEQNO_SPACE 65536 // 2**16 as seqno is uint16_t
24

25
#define PRRT_PACKET_DATA_HEADER_SIZE 12
26
27
typedef struct {
    uint32_t timestamp;
28
    uint16_t group_round_trip_time;
29
30
    uint16_t packet_timeout;
    uint16_t decoding_timeout;
31
    uint16_t feedback_timeout;
32
} PrrtPacketDataPayload;
33

34
35
36
37
38
39
40
#define PRRT_PACKET_REDUNDANCY_HEADER_SIZE 4
typedef struct {
    uint16_t base_seqno;
    uint8_t n;
    uint8_t k;
} PrrtPacketRedundancyPayload;

Andreas Schmidt's avatar
Andreas Schmidt committed
41
# define PRRT_PACKET_FEEDBACK_HEADER_SIZE 32
42
typedef struct {
43
44
45
    uint32_t receiver_addr;
    uint32_t group_round_trip_time;
    uint32_t forward_trip_time;
46
    uint32_t packet_loss_rate;
47
48
49
50
    uint16_t gap;
    uint16_t ngap;
    uint16_t burst;
    uint16_t nburst;
51
    uint32_t bandwidth_estimate;
52
    uint32_t buffer_feedback;
53
} PrrtPacketFeedbackPayload;
54

55
56
57
58
uint8_t PrrtPacket_type(PrrtPacket *packet_ptr);
uint8_t PrrtPacket_priority(PrrtPacket *packet_ptr);
uint16_t PrrtPacket_size(PrrtPacket *packet_ptr);
int PrrtPacket_print(PrrtPacket *packet_ptr);
59

60
61
62
// CREATE: PRRT_PACKET
// ENCODE: PRRT_PACKET -> BYTES
// DECODE: BYTES -> PRRT_PACKET
63
// DESTROY:
64
65


66
int PrrtPacket_create_data_packet(PrrtPacket *packet_ptr, uint8_t priority, const void *data_ptr,
67
                                  uint32_t  data_len, int seqno);
68

69
70
71
72
PrrtPacket *PrrtPacket_create_feedback_packet(uint8_t priority, uint8_t index, uint16_t seqno, uint32_t round_trip_time,
                                              uint32_t forward_trip_time, uint32_t packet_loss_rate, uint16_t gap,
                                              uint16_t ngap, uint16_t burst, uint16_t nburst, uint32_t bandwidth,
                                              uint32_t buffer_feedback);
73

74
75
76
PrrtPacket *PrrtPacket_create_redundancy_packet(uint8_t priority, void *data_ptr, uint32_t  data_len,
                                                uint16_t seqno, uint8_t index, uint16_t base_seqno, PrrtCodingParams codingParams);

77
78
79
int PrrtPacket_decode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr);
int PrrtPacket_encode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr);
int PrrtPacket_destroy(PrrtPacket *packet_ptr);
80
81

#endif //PRRT_FRAME_H