UniMRCP  1.7.0
mpf_rtcp_packet.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008-2015 Arsen Chaloyan
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MPF_RTCP_PACKET_H
18 #define MPF_RTCP_PACKET_H
19 
20 /**
21  * @file mpf_rtcp_packet.h
22  * @brief RTCP Packet Definition
23  */
24 
25 #include "mpf_rtp_stat.h"
26 
28 
29 
30 /** RTCP payload (packet) types */
31 typedef enum {
32  RTCP_SR = 200,
33  RTCP_RR = 201,
34  RTCP_SDES = 202,
35  RTCP_BYE = 203,
36  RTCP_APP = 204
37 } rtcp_type_e;
38 
39 /** RTCP SDES types */
40 typedef enum {
41  RTCP_SDES_END = 0,
42  RTCP_SDES_CNAME = 1,
43  RTCP_SDES_NAME = 2,
44  RTCP_SDES_EMAIL = 3,
45  RTCP_SDES_PHONE = 4,
46  RTCP_SDES_LOC = 5,
47  RTCP_SDES_TOOL = 6,
48  RTCP_SDES_NOTE = 7,
49  RTCP_SDES_PRIV = 8
51 
52 /** RTCP header declaration */
54 /** RTCP packet declaration */
56 /** SDES item declaration*/
58 
59 
60 /** RTCP header */
61 struct rtcp_header_t {
62 #if (APR_IS_BIGENDIAN == 1)
63  /** protocol version */
64  unsigned int version: 2;
65  /** padding flag */
66  unsigned int padding: 1;
67  /** varies by packet type */
68  unsigned int count: 5;
69  /** packet type */
70  unsigned int pt: 8;
71 #else
72  /** varies by packet type */
73  unsigned int count: 5;
74  /** padding flag */
75  unsigned int padding: 1;
76  /** protocol version */
77  unsigned int version: 2;
78  /** packet type */
79  unsigned int pt: 8;
80 #endif
81 
82  /** packet length in words, w/o this word */
83  unsigned int length: 16;
84 };
85 
86 /** SDES item */
88  /** type of item (rtcp_sdes_type_t) */
89  apr_byte_t type;
90  /** length of item (in octets) */
91  apr_byte_t length;
92  /** text, not null-terminated */
93  char data[1];
94 };
95 
96 /** RTCP packet */
97 struct rtcp_packet_t {
98  /** common header */
100  /** union of RTCP reports */
101  union {
102  /** sender report (SR) */
103  struct {
104  /** sr stat */
106  /** variable-length list rr stats */
107  rtcp_rr_stat_t rr_stat[1];
108  } sr;
109 
110  /** reception report (RR) */
111  struct {
112  /** receiver generating this report */
113  apr_uint32_t ssrc;
114  /** variable-length list rr stats */
115  rtcp_rr_stat_t rr_stat[1];
116  } rr;
117 
118  /** source description (SDES) */
119  struct {
120  /** first SSRC/CSRC */
121  apr_uint32_t ssrc;
122  /** list of SDES items */
124  } sdes;
125 
126  /** BYE */
127  struct {
128  /** list of sources */
129  apr_uint32_t ssrc[1];
130  /* optional length of reason string (in octets) */
131  apr_byte_t length;
132  /* optional reason string, not null-terminated */
133  char data[1];
134  } bye;
135  } r;
136 };
137 
138 /** Initialize RTCP header */
139 static APR_INLINE void rtcp_header_init(rtcp_header_t *header, rtcp_type_e pt)
140 {
141  header->version = RTP_VERSION;
142  header->padding = 0;
143  header->count = 0;
144  header->pt = pt;
145  header->length = 0;
146 }
147 
148 static APR_INLINE void rtcp_header_length_set(rtcp_header_t *header, apr_size_t length)
149 {
150  header->length = htons((apr_uint16_t)length / 4 - 1);
151 }
152 
153 static APR_INLINE void rtcp_sr_hton(rtcp_sr_stat_t *sr_stat)
154 {
155  sr_stat->ssrc = htonl(sr_stat->ssrc);
156  sr_stat->ntp_sec = htonl(sr_stat->ntp_sec);
157  sr_stat->ntp_frac = htonl(sr_stat->ntp_frac);
158  sr_stat->rtp_ts = htonl(sr_stat->rtp_ts);
159  sr_stat->sent_packets = htonl(sr_stat->sent_packets);
160  sr_stat->sent_octets = htonl(sr_stat->sent_octets);
161 }
162 
163 static APR_INLINE void rtcp_sr_ntoh(rtcp_sr_stat_t *sr_stat)
164 {
165  sr_stat->ssrc = ntohl(sr_stat->ssrc);
166  sr_stat->ntp_sec = ntohl(sr_stat->ntp_sec);
167  sr_stat->ntp_frac = ntohl(sr_stat->ntp_frac);
168  sr_stat->rtp_ts = ntohl(sr_stat->rtp_ts);
169  sr_stat->sent_packets = ntohl(sr_stat->sent_packets);
170  sr_stat->sent_octets = ntohl(sr_stat->sent_octets);
171 }
172 
173 static APR_INLINE void rtcp_rr_hton(rtcp_rr_stat_t *rr_stat)
174 {
175  rr_stat->ssrc = htonl(rr_stat->ssrc);
176  rr_stat->last_seq = htonl(rr_stat->last_seq);
177  rr_stat->jitter = htonl(rr_stat->jitter);
178 
179 #if (APR_IS_BIGENDIAN == 0)
180  rr_stat->lost = ((rr_stat->lost >> 16) & 0x000000ff) |
181  (rr_stat->lost & 0x0000ff00) |
182  ((rr_stat->lost << 16) & 0x00ff0000);
183 #endif
184 }
185 
186 static APR_INLINE void rtcp_rr_ntoh(rtcp_rr_stat_t *rr_stat)
187 {
188  rr_stat->ssrc = ntohl(rr_stat->ssrc);
189  rr_stat->last_seq = ntohl(rr_stat->last_seq);
190  rr_stat->jitter = ntohl(rr_stat->jitter);
191 
192 #if (APR_IS_BIGENDIAN == 0)
193  rr_stat->lost = ((rr_stat->lost >> 16) & 0x000000ff) |
194  (rr_stat->lost & 0x0000ff00) |
195  ((rr_stat->lost << 16) & 0x00ff0000);
196 #endif
197 }
198 
200 
201 #endif /* MPF_RTCP_PACKET_H */
apr_byte_t type
Definition: mpf_rtcp_packet.h:89
apr_int32_t lost
Definition: mpf_rtp_stat.h:80
Definition: mpf_rtp_stat.h:58
rtcp_type_e
Definition: mpf_rtcp_packet.h:31
unsigned int version
Definition: mpf_rtcp_packet.h:77
unsigned int pt
Definition: mpf_rtcp_packet.h:79
#define APT_END_EXTERN_C
Definition: apt.h:38
rtcp_sdes_type_e
Definition: mpf_rtcp_packet.h:40
apr_byte_t length
Definition: mpf_rtcp_packet.h:91
apr_uint32_t ssrc
Definition: mpf_rtp_stat.h:76
apr_uint32_t rtp_ts
Definition: mpf_rtp_stat.h:66
apr_uint32_t ntp_frac
Definition: mpf_rtp_stat.h:64
rtcp_sr_stat_t sr_stat
Definition: mpf_rtcp_packet.h:105
#define RTP_VERSION
Definition: mpf_rtp_header.h:30
#define APT_BEGIN_EXTERN_C
Definition: apt.h:36
rtcp_header_t header
Definition: mpf_rtcp_packet.h:99
apr_uint32_t ssrc
Definition: mpf_rtcp_packet.h:113
Definition: mpf_rtcp_packet.h:61
RTP/RTCP Statistics.
Definition: mpf_rtp_stat.h:74
apr_uint32_t jitter
Definition: mpf_rtp_stat.h:84
Definition: mpf_rtcp_packet.h:97
Definition: mpf_rtcp_packet.h:87
unsigned int count
Definition: mpf_rtcp_packet.h:73
apr_uint32_t ntp_sec
Definition: mpf_rtp_stat.h:62
apr_uint32_t ssrc
Definition: mpf_rtp_stat.h:60
unsigned int padding
Definition: mpf_rtcp_packet.h:75
apr_uint32_t sent_octets
Definition: mpf_rtp_stat.h:70
unsigned int length
Definition: mpf_rtcp_packet.h:83
apr_uint32_t sent_packets
Definition: mpf_rtp_stat.h:68
apr_uint32_t last_seq
Definition: mpf_rtp_stat.h:82