-
Notifications
You must be signed in to change notification settings - Fork 65
/
rtp.h
182 lines (167 loc) · 6.1 KB
/
rtp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
* (c) 1998-2018 by Columbia University; all rights reserved
*
* SPDX-License-Identifier: BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* rtp.h -- RTP header file (RFC 1890)
*/
#include <stdint.h>
#include "sysdep.h"
/*
* Current protocol version.
*/
#define RTP_VERSION 2
typedef enum {
RTCP_SR = 200,
RTCP_RR = 201,
RTCP_SDES = 202,
RTCP_BYE = 203,
RTCP_APP = 204
} rtcp_type_t;
typedef enum {
RTCP_SDES_END = 0,
RTCP_SDES_CNAME = 1,
RTCP_SDES_NAME = 2,
RTCP_SDES_EMAIL = 3,
RTCP_SDES_PHONE = 4,
RTCP_SDES_LOC = 5,
RTCP_SDES_TOOL = 6,
RTCP_SDES_NOTE = 7,
RTCP_SDES_PRIV = 8
} rtcp_sdes_type_t;
/*
* RTP data header
*/
typedef struct {
#if RTP_BIG_ENDIAN
unsigned int version:2; /* protocol version */
unsigned int p:1; /* padding flag */
unsigned int x:1; /* header extension flag */
unsigned int cc:4; /* CSRC count */
unsigned int m:1; /* marker bit */
unsigned int pt:7; /* payload type */
#else
unsigned int cc:4; /* CSRC count */
unsigned int x:1; /* header extension flag */
unsigned int p:1; /* padding flag */
unsigned int version:2; /* protocol version */
unsigned int pt:7; /* payload type */
unsigned int m:1; /* marker bit */
#endif
unsigned int seq:16; /* sequence number */
uint32_t ts; /* timestamp */
uint32_t ssrc; /* synchronization source */
uint32_t csrc[1]; /* optional CSRC list */
} rtp_hdr_t;
/* RTP Header Extension
*/
typedef struct {
uint16_t ext_type; /* defined by profile */
uint16_t len; /* extension length in 32-bit word */
} rtp_hdr_ext_t;
/*
* RTCP common header word
*/
typedef struct {
#if RTP_BIG_ENDIAN
unsigned int version:2; /* protocol version */
unsigned int p:1; /* padding flag */
unsigned int count:5; /* varies by packet type */
#else
unsigned int count:5; /* varies by packet type */
unsigned int p:1; /* padding flag */
unsigned int version:2; /* protocol version */
#endif
unsigned int pt:8; /* RTCP packet type */
unsigned int length:16; /* pkt len in words, w/o this word */
} rtcp_common_t;
/*
* Reception report block
*/
typedef struct {
uint32_t ssrc; /* data source being reported */
unsigned int fraction:8; /* fraction lost since last SR/RR */
unsigned int lost_sb:1; /* cumul. no. pkts lost: sign */
unsigned int lost_b2:7; /* cumul. no. pkts lost: MSB */
unsigned int lost_b1:8; /* cumul. no. pkts lost: byte 1 */
unsigned int lost_b0:8; /* cumul. no. pkts lost: LSB */
uint32_t last_seq; /* extended last seq. no. received */
uint32_t jitter; /* interarrival jitter */
uint32_t lsr; /* last SR packet from this source */
uint32_t dlsr; /* delay since last SR packet */
} rtcp_rr_t;
#define _BYTE(v) ((v) & 0xff)
#define RTCP_GET_LOST(rp) ((rp)->lost_sb ? (-1) : (1) * (((rp)->lost_b2 << 16) | ((rp)->lost_b1 << 8) | (rp)->lost_b0))
#define RTCP_SET_LOST(rp, v) do { \
(rp)->lost_sb = (v) < 0 ? (1) : (0); \
(rp)->lost_b2 = _BYTE((v) >> 16); \
(rp)->lost_b1 = _BYTE((v) >> 8); \
(rp)->lost_b0 = _BYTE((v)); \
} while (0)
/*
* SDES item
*/
typedef struct {
uint8_t type; /* type of item (rtcp_sdes_type_t) */
uint8_t length; /* length of item (in octets) */
char data[1]; /* text, not null-terminated */
} rtcp_sdes_item_t;
/*
* One RTCP packet
*/
typedef struct {
rtcp_common_t common; /* common header */
union {
/* sender report (SR) */
struct {
uint32_t ssrc; /* sender generating this report */
uint32_t ntp_sec; /* NTP timestamp */
uint32_t ntp_frac;
uint32_t rtp_ts; /* RTP timestamp */
uint32_t psent; /* packets sent */
uint32_t osent; /* octets sent */
rtcp_rr_t rr[1]; /* variable-length list */
} sr;
/* reception report (RR) */
struct {
uint32_t ssrc; /* receiver generating this report */
rtcp_rr_t rr[1]; /* variable-length list */
} rr;
/* source description (SDES) */
struct rtcp_sdes {
uint32_t src; /* first SSRC/CSRC */
rtcp_sdes_item_t item[1]; /* list of SDES items */
} sdes;
/* BYE */
struct {
uint32_t src[1]; /* list of sources */
/* can't express trailing text for reason */
} bye;
} r;
} rtcp_t;
typedef struct rtcp_sdes rtcp_sdes_t;