GNU Radio's RTP Package
rtp.h
Go to the documentation of this file.
1#ifndef _RTP_H
2#define _RTP_H 1
3
4#include <stdint.h>
5#include <stddef.h>
6
7#define DEFAULT_MCAST_PORT ((uint16_t)5004)
8#define DEFAULT_RTP_PORT ((uint16_t)5004)
9#define DEFAULT_RTCP_PORT ((uint16_t)5005)
10#define DEFAULT_STAT_PORT ((uint16_t)5006)
11
12#define NTP_EPOCH 2208988800UL // Seconds between Jan 1 1900 and Jan 1 1970
13
14#define RTP_MIN_SIZE 12 // min size of RTP header
15#define RTP_VERS 2U
16#define RTP_MARKER 0x80 // Marker flag in mpt field
17
18#define OPUS_SAMPRATE (48000)
19#define PKTSIZE 65536 // Largest possible IP datagram, in case we use jumbograms
20
22 char *str;
23 int value;
24};
25
34 OPUS_VOIP, // Opus with APPLICATION_VOIP
39 UNUSED_ENCODING, // Sentinel, not used
40};
41
42struct pt_table {
46};
47
48// Internal representation of RTP header -- NOT what's on wire!
49struct rtp_header {
51 uint8_t type;
52 uint16_t seq;
53 uint32_t timestamp;
54 uint32_t ssrc;
55 bool marker:1;
56 bool pad:1;
57 bool extension:1;
58 int cc;
59 uint32_t csrc[15];
60};
61
62// RTP sender/receiver state
63struct rtp_state {
64 uint32_t ssrc;
65 uint8_t type;
66 bool init;
67 uint16_t seq;
68 uint16_t odd_seq;
70 uint32_t timestamp;
71 uint64_t packets;
72 uint64_t bytes;
73 uint64_t drops;
74 uint64_t dupes;
75};
76
77// Internal format of sender report segment
78struct rtcp_sr {
79 uint32_t ssrc;
81 unsigned int rtp_timestamp;
82 unsigned int packet_count;
83 unsigned int byte_count;
84};
85
86// Internal format of receiver report segment
87struct rtcp_rr {
88 uint32_t ssrc;
92 int jitter;
93 int lsr; // Last SR
94 int dlsr; // Delay since last SR
95};
96
97// Internal format of RTCP source description
108
109// Individual source description item
110struct rtcp_sdes {
112 uint32_t ssrc;
113 size_t mlen;
114 char message[256];
115};
116
117// Incoming RTP packets
118// This should probably be extracted into a more general RTP library
119struct packet {
120 struct packet *next;
122 uint8_t const *data; // Don't modify a packet through this pointer
123 size_t len;
124 uint8_t content[PKTSIZE];
125};
126
127// Convert between internal and wire representations of RTP header
128void const *ntoh_rtp(struct rtp_header *,void const *);
129void *hton_rtp(void *, struct rtp_header const *);
130
131int add_pt(int type, int samprate, int channels, enum encoding encoding);
132// Function to process incoming RTP packet headers
133// Returns number of samples dropped or skipped by silence suppression, if any
134int rtp_process(struct rtp_state *state,struct rtp_header const *rtp,size_t samples);
135
136// Generate RTCP source description segment
137uint8_t *gen_sdes(uint8_t *output,size_t bufsize,uint32_t ssrc,struct rtcp_sdes const *sdes,int sc);
138// Generate RTCP bye segment
139uint8_t *gen_bye(uint8_t *output,size_t bufsize,uint32_t const *ssrcs,int sc);
140// Generate RTCP sender report segment
141uint8_t *gen_sr(uint8_t *output,size_t bufsize,struct rtcp_sr const *sr,struct rtcp_rr const *rr,int rc);
142// Generate RTCP receiver report segment
143uint8_t *gen_rr(uint8_t *output,size_t bufsize,uint32_t ssrc,struct rtcp_rr const *rr,int rc);
144
145extern struct pt_table PT_table[];
146extern int const Opus_pt; // Allow dynamic setting in the future
147extern int const AX25_pt;
148
149// Allowable Opus block durations, millisec * 10
150extern int Opus_blocksizes[];
151extern int Opus_samprates[];
152// Codec helpers
153extern struct string_table Opus_application[];
154extern struct string_table Opus_signal[];
155
156int opus_bandwidth(char const **str,int code);
157char const *opus_application_string(int);
159bool legal_opus_size(int n);
161
162int samprate_from_pt(int type);
163int channels_from_pt(int type);
165int pt_from_info(int samprate,int channels,enum encoding);
166char const *encoding_string(enum encoding);
167enum encoding parse_encoding(char const *str);
168uint8_t float_to_mulaw(float fsample);
169float mulaw_to_float(uint8_t ulaw);
170uint8_t float_to_alaw(float fsample);
171float alaw_to_float(uint8_t alaw);
172
173#endif
uint8_t float_to_mulaw(float fsample)
int channels_from_pt(int type)
int const Opus_pt
bool legal_opus_samprate(int n)
char const * encoding_string(enum encoding)
struct string_table Opus_application[]
uint8_t * gen_sdes(uint8_t *output, size_t bufsize, uint32_t ssrc, struct rtcp_sdes const *sdes, int sc)
uint8_t * gen_bye(uint8_t *output, size_t bufsize, uint32_t const *ssrcs, int sc)
float mulaw_to_float(uint8_t ulaw)
float alaw_to_float(uint8_t alaw)
struct pt_table PT_table[]
int pt_from_info(int samprate, int channels, enum encoding)
bool legal_opus_size(int n)
void const * ntoh_rtp(struct rtp_header *, void const *)
int Opus_blocksizes[]
int samprate_from_pt(int type)
uint8_t * gen_rr(uint8_t *output, size_t bufsize, uint32_t ssrc, struct rtcp_rr const *rr, int rc)
sdes_type
Definition rtp.h:98
@ NOTE
Definition rtp.h:105
@ NAME
Definition rtp.h:100
@ PRIV
Definition rtp.h:106
@ EMAIL
Definition rtp.h:101
@ CNAME
Definition rtp.h:99
@ TOOL
Definition rtp.h:104
@ PHONE
Definition rtp.h:102
@ LOC
Definition rtp.h:103
uint8_t float_to_alaw(float fsample)
int const AX25_pt
int add_pt(int type, int samprate, int channels, enum encoding encoding)
int rtp_process(struct rtp_state *state, struct rtp_header const *rtp, size_t samples)
encoding
Definition rtp.h:26
@ F16LE
Definition rtp.h:33
@ F16BE
Definition rtp.h:36
@ S16BE
Definition rtp.h:29
@ F32BE
Definition rtp.h:35
@ OPUS_VOIP
Definition rtp.h:34
@ MULAW
Definition rtp.h:37
@ NO_ENCODING
Definition rtp.h:27
@ ALAW
Definition rtp.h:38
@ AX25
Definition rtp.h:32
@ F32LE
Definition rtp.h:31
@ S16LE
Definition rtp.h:28
@ OPUS
Definition rtp.h:30
@ UNUSED_ENCODING
Definition rtp.h:39
char const * opus_application_string(int)
int Opus_samprates[]
enum encoding encoding_from_pt(int type)
#define PKTSIZE
Definition rtp.h:19
struct string_table Opus_signal[]
uint8_t * gen_sr(uint8_t *output, size_t bufsize, struct rtcp_sr const *sr, struct rtcp_rr const *rr, int rc)
int opus_bandwidth_to_code(int bw)
int opus_bandwidth(char const **str, int code)
void * hton_rtp(void *, struct rtp_header const *)
Definition rtp.h:119
uint8_t const * data
Definition rtp.h:122
struct packet * next
Definition rtp.h:120
size_t len
Definition rtp.h:123
struct rtp_header rtp
Definition rtp.h:121
uint8_t content[PKTSIZE]
Definition rtp.h:124
Definition rtp.h:42
int channels
Definition rtp.h:44
enum encoding encoding
Definition rtp.h:45
int samprate
Definition rtp.h:43
Definition rtp.h:87
int highest_seq
Definition rtp.h:91
int lost_packets
Definition rtp.h:90
int lost_fract
Definition rtp.h:89
int jitter
Definition rtp.h:92
uint32_t ssrc
Definition rtp.h:88
int dlsr
Definition rtp.h:94
int lsr
Definition rtp.h:93
Definition rtp.h:110
enum sdes_type type
Definition rtp.h:111
char message[256]
Definition rtp.h:114
size_t mlen
Definition rtp.h:113
uint32_t ssrc
Definition rtp.h:112
Definition rtp.h:78
int64_t ntp_timestamp
Definition rtp.h:80
unsigned int rtp_timestamp
Definition rtp.h:81
uint32_t ssrc
Definition rtp.h:79
unsigned int byte_count
Definition rtp.h:83
unsigned int packet_count
Definition rtp.h:82
Definition rtp.h:49
int version
Definition rtp.h:50
uint16_t seq
Definition rtp.h:52
uint32_t timestamp
Definition rtp.h:53
uint8_t type
Definition rtp.h:51
uint32_t csrc[15]
Definition rtp.h:59
bool pad
Definition rtp.h:56
bool marker
Definition rtp.h:55
uint32_t ssrc
Definition rtp.h:54
bool extension
Definition rtp.h:57
int cc
Definition rtp.h:58
Definition rtp.h:63
uint64_t packets
Definition rtp.h:71
uint64_t bytes
Definition rtp.h:72
bool odd_seq_set
Definition rtp.h:69
uint64_t dupes
Definition rtp.h:74
uint32_t timestamp
Definition rtp.h:70
uint64_t drops
Definition rtp.h:73
uint8_t type
Definition rtp.h:65
uint16_t seq
Definition rtp.h:67
uint16_t odd_seq
Definition rtp.h:68
uint32_t ssrc
Definition rtp.h:64
bool init
Definition rtp.h:66
Definition rtp.h:21
int value
Definition rtp.h:23
char * str
Definition rtp.h:22