a-oRTP  5.2.0
rtp.h
1 /*
2  The oRTP library is an RTP (Realtime Transport Protocol - rfc3550) stack.
3  Copyright (C) 2001 Simon MORLAT simon.morlat@linphone.org
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 
20 #ifndef RTP_H
21 #define RTP_H
22 
23 #include <ortp/port.h>
24 #include <ortp/str_utils.h>
25 
26 #define IPMAXLEN 20
27 #define UDP_MAX_SIZE 1500
28 #define RTP_FIXED_HEADER_SIZE 12
29 #define RTP_DEFAULT_JITTER_TIME 80 /*miliseconds*/
30 #define RTP_DEFAULT_MULTICAST_TTL 5 /*hops*/
31 #define RTP_DEFAULT_MULTICAST_LOOPBACK 0 /*false*/
32 #define RTP_DEFAULT_DSCP 0x00 /*best effort*/
33 
34 typedef struct rtp_header {
35 #ifdef ORTP_BIGENDIAN
36  uint16_t version : 2;
37  uint16_t padbit : 1;
38  uint16_t extbit : 1;
39  uint16_t cc : 4;
40  uint16_t markbit : 1;
41  uint16_t paytype : 7;
42 #else
43  uint16_t cc : 4;
44  uint16_t extbit : 1;
45  uint16_t padbit : 1;
46  uint16_t version : 2;
47  uint16_t paytype : 7;
48  uint16_t markbit : 1;
49 #endif
50  uint16_t seq_number;
51  uint32_t timestamp;
52  uint32_t ssrc;
53  uint32_t csrc[16];
54 } rtp_header_t;
55 
56 #define ONE_BYTE_EXTENSION_ID 0xBEDE
57 #define ONE_BYTE_EXTENSION_SIZE 1
58 #define ONE_BYTE_EXTENSION_RESERVED_ID 15
59 #define ONE_BYTE_EXTENSION_PADDING_ID 0
60 
61 #define RTPEXT_SSRCAUDIOLEVEL 1
62 #define RTPEXT_SDESMID 2
63 #define RTPEXT_ABSOLUTESENDTIME 3
64 
65 typedef struct rtp_stats {
66  uint64_t packet_sent;
67  uint64_t sent; /* bytes sent */
68  uint64_t recv; /* bytes of payload received and delivered in time to the application */
69  uint64_t hw_recv; /* bytes of payload received */
70  uint64_t packet_recv; /* number of packets received */
71  uint64_t unavaillable; /* totally useless*/
72  uint64_t outoftime; /* number of packets that were received too late */
73  uint64_t cum_packet_loss; /* cumulative number of packet lost */
74  uint64_t bad; /* packets that did not appear to be RTP */
75  uint64_t discarded; /* incoming packets discarded because the queue exceeds its max size */
76  float average_jitter;
77 
78  uint64_t voip_metrics_loss_count;
79  uint64_t voip_metrics_discard_count;
80  uint64_t voip_metrics_pkt_received_count;
81  uint64_t gmin;
82  uint64_t voip_metrics_lost_within_current_burst;
83 
84  uint64_t c11;
85  uint64_t c14;
86  uint64_t c13;
87  uint64_t c22;
88  uint64_t c23;
89  uint64_t c31;
90  uint64_t c32;
91  uint64_t c33;
92 
93  float burst_density;
94  float gap_density;
95  uint64_t burst_length;
96  uint64_t gap_length;
97  uint64_t frameduration_ms;
98 } rtp_stats_t;
99 
100 typedef struct rtp_extended_stats {
101  double rtt; /* round trip time (sec) extracted from RTCP reports */
102  double cur_packet_loss_fraction; /* current packet loss fraction (percentage) */
103  uint16_t djb_nominal_delay; /* De-jitter buffer nominal delay (ms) */
104  uint16_t djb_max_delay; /* De-jitter buffer maximum delay (ms) */
105  uint16_t djb_nominal_delay_hwmark; /* De-jitter buffer nominal delay high-water mark (ms) */
106  uint16_t djb_max_delay_lwmark; /* De-jitter buffer nominal delay low-water mark (ms) */
107 
108  double remote_cur_packet_loss_fraction; /* current packet loss fraction (percentage) */
110 
111 #define RTP_TIMESTAMP_IS_NEWER_THAN(ts1, ts2) ((uint32_t)((uint32_t)(ts1) - (uint32_t)(ts2)) < (UINT32_C(1) << 31))
112 
113 #define RTP_TIMESTAMP_IS_STRICTLY_NEWER_THAN(ts1, ts2) (((uint32_t)((uint32_t)(ts1) - (uint32_t)(ts2)) < (UINT32_C(1) << 31)) && (ts1) != (ts2))
114 
115 #define TIME_IS_NEWER_THAN(t1, t2) RTP_TIMESTAMP_IS_NEWER_THAN(t1, t2)
116 
117 #define TIME_IS_STRICTLY_NEWER_THAN(t1, t2) RTP_TIMESTAMP_IS_STRICTLY_NEWER_THAN(t1, t2)
118 
119 #ifdef __cplusplus
120 extern "C" {
121 #endif
122 
123 /* packet api */
124 /* the first argument is a mblk_t. The header is supposed to be not splitted */
125 #define rtp_set_markbit(mp, value) ((rtp_header_t *) ((mp)->b_rptr))->markbit = (value)
126 #define rtp_set_seqnumber(mp, seq) ((rtp_header_t *) ((mp)->b_rptr))->seq_number = (seq)
127 #define rtp_set_timestamp(mp, ts) ((rtp_header_t *) ((mp)->b_rptr))->timestamp = (ts)
128 #define rtp_set_ssrc(mp, _ssrc) ((rtp_header_t *) ((mp)->b_rptr))->ssrc = (_ssrc)
129 void rtp_add_csrc(mblk_t *mp, uint32_t csrc);
130 #define rtp_set_payload_type(mp, pt) ((rtp_header_t *) ((mp)->b_rptr))->paytype = (pt)
131 #define rtp_set_extbit(mp, value) ((rtp_header_t *) ((mp)->b_rptr))->extbit = (value)
132 
133 #define rtp_get_markbit(mp) (((rtp_header_t *) ((mp)->b_rptr))->markbit)
134 #define rtp_get_timestamp(mp) (((rtp_header_t *) ((mp)->b_rptr))->timestamp)
135 #define rtp_get_seqnumber(mp) (((rtp_header_t *) ((mp)->b_rptr))->seq_number)
136 #define rtp_get_payload_type(mp) (((rtp_header_t *) ((mp)->b_rptr))->paytype)
137 #define rtp_get_ssrc(mp) (((rtp_header_t *) ((mp)->b_rptr))->ssrc)
138 #define rtp_get_cc(mp) (((rtp_header_t *) ((mp)->b_rptr))->cc)
139 #define rtp_get_csrc(mp, idx) (((rtp_header_t *) ((mp)->b_rptr))->csrc[idx])
140 #define rtp_get_extbit(mp) (((rtp_header_t *) ((mp)->b_rptr))->extbit)
141 #define rtp_get_padbit(mp) (((rtp_header_t *) ((mp)->b_rptr))->padbit)
142 
143 int rtp_get_payload(mblk_t *packet, unsigned char **start);
144 
145 #ifdef __cplusplus
146 }
147 #endif
148 
149 #endif
Definition: str_utils.h:25
Definition: rtp.h:100
Definition: rtp.h:34
Definition: rtp.h:65