1 /*****************************************************************************
2 * rtcp.h: RTP/RTCP headerfile
3 *****************************************************************************
4 * Copyright (C) 2005-2007 M2X
8 * Authors: Jean-Paul Saman <jpsaman #_at_# videolan dot org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
28 /* RTCP packet types */
34 /* End of RTCP packet types */
37 #define RTCP_SDES_CNAME 1
38 #define RTCP_SDES_NAME 2
39 #define RTCP_SDES_EMAIL 3
40 #define RTCP_SDES_PHONE 4
41 #define RTCP_SDES_LOC 5
42 #define RTCP_SDES_TOOL 6
43 #define RTCP_SDES_NOTE 7
44 #define RTCP_SDES_PRIV 8
45 /* End of SDES type */
47 #define RTCP_HEADER_LEN 3
49 typedef enum rtcp_event_enum
58 uint32_t ntp_timestampH;
59 uint32_t ntp_timestampL;
60 uint32_t rtp_timestamp;
62 uint32_t u_octet_count;
71 typedef struct SDES_item_t
73 uint32_t i_index; /*< index */
74 uint8_t u_type; /*< type field */
75 char *psz_data; /*< null terminated string */
81 uint32_t u_length; /*< length of packet */
82 uint32_t u_items; /*< number of SDES_items */
83 rtcp_SDES_item_t **pp_items; /*< list of SDES_items */
89 uint32_t u_length; /*< length of packet */
95 uint32_t u_length; /*< length of packet */
96 uint32_t u_prefix_len; /*< length of prefix data */
97 unsigned char *psz_prefix;/*< prefix string (null terminated) */
98 unsigned char *psz_data; /*< data string (null terminated) */
103 * structure rtcp_stats_t
107 uint32_t u_RR_received; /*< RR records received */
108 uint32_t u_SR_received; /*< SR records received */
109 uint64_t l_dest_SSRC; /*< SSRC of first source */
110 uint32_t u_pkt_count; /*< count of packets received */
111 uint32_t u_octet_count; /*< ? */
112 uint32_t u_pkt_lost; /*< cumulative count of packets lost */
113 uint8_t u_fraction_lost; /*< count of fractional packets lost */
114 uint32_t u_highest_seq_no;/*< highest sequence number found */
115 uint32_t u_jitter; /*< inter arrival jitter calculated */
116 uint32_t u_last_SR; /*< last SR record received */
117 uint32_t u_last_RR; /*< last RR record received */
118 mtime_t u_delay_since_last_SR; /*< delay since last SR record received */
119 mtime_t u_delay_since_last_RR; /*< delay since last RR record received */
121 uint64_t u_avg_pkt_size; /*< average RTCP packet size */
122 uint64_t u_sent_pkt_size; /*< RTCP packet size sent */
128 uint32_t u_version; /*< RTCP version number */
129 vlc_bool_t b_padding; /*< indicates if packets has padding */
130 uint32_t u_report; /*< reception packet count */
131 uint32_t u_payload_type; /*< type of RTCP payload */
132 uint32_t u_length; /*< length of packet */
133 uint32_t u_ssrc; /*< channel name this packet belongs to */
136 rtcp_SR_t sr; /*< SR record */
137 rtcp_RR_t rr; /*< RR record */
138 rtcp_SDES_t sdes; /*< SDES record */
139 rtcp_BYE_t bye; /*< BYE record */
140 rtcp_APP_t app; /*< APP record */
145 typedef struct rtcp_client_t
147 int fd; /*< socket descriptor of rtcp stream */
150 uint32_t u_ssrc; /*< channel name */
151 vlc_bool_t b_deleted; /*< channel deleted ? */
152 mtime_t i_timeout; /*< remove timeout before real deletion,
153 * this is recommended by RFC 3550 at
154 * page 27 to ignore out-of-order packets.
156 rtcp_stats_t *p_stats; /*< RTCP statistics */
158 uint32_t i_items; /*< count of SDES item structures */
159 rtcp_SDES_item_t **pp_sdes; /*< SDES client items */
164 * This structure is a VLC_OBJECT and holds RTCP statistical information.
166 typedef struct rtcp_t
170 uint32_t u_clients; /*< number of clients connected */
171 uint32_t u_active; /*< number of active senders */
172 uint32_t u_members; /*< number of clients in previous interval */
174 mtime_t i_date; /*< current RTCP packet interval */
175 mtime_t i_last_date; /*< previous RTCP packet interval */
176 mtime_t i_next_date; /*< next scheduled transmision time
179 uint32_t i_clients; /*< count of clients structures */
180 rtcp_client_t **pp_clients; /*< RTCP clients */
182 /* bitstream data pointer used for decoding */
183 bs_t *bs; /*< bitstream decoding data pointer */
186 int (*pf_add_client)( vlc_object_t *p_this, uint32_t u_ssrc, uint32_t *i_pos );
187 int (*pf_del_client)( vlc_object_t *p_this, uint32_t u_ssrc );
188 int (*pf_find_client)( vlc_object_t *p_this, uint32_t u_ssrc, uint32_t *i_pos );
189 int (*pf_cleanup_clients)( vlc_object_t *p_this );
190 int (*pf_destroy_clients)( vlc_object_t *p_this );
193 int rtcp_add_client( vlc_object_t *p_this, uint32_t u_ssrc, uint32_t *i_pos );
194 int rtcp_del_client( vlc_object_t *p_this, uint32_t u_ssrc );
195 /* Should be called with vlc_mutex_lock( &p_this->objec_lock ) held */
196 int rtcp_find_client( vlc_object_t *p_this, uint32_t u_ssrc, uint32_t *i_pos );
197 int rtcp_cleanup_clients( vlc_object_t *p_this );
198 int rtcp_destroy_clients( vlc_object_t *p_this );
201 * rtcp_cleanup_clients - Permanently remove clients from the list
202 * Permanently delete struct rtcp_client_t from member list when it is there
203 * time to be removed. RFC 3550 recommends a grace period of five times the
204 * RTCP packet send/receive interval before permanent removal of session. This
205 * is to ignore out of order packets for the same SSRC that arrive after the
206 * BYE report for that SSRC has been received.
208 * \param p_this VLC_OBJECT_T of type rtcp_t
210 int rtcp_cleanup_clients( vlc_object_t *p_this );
211 //VLC_EXPORT( int, rtcp_cleanup_clients, ( vlc_object_t * ) );
214 * rtcp_pkt_decode - Decode RTCP packet
215 * Decode incoming RTCP packet and inspect the records types.
221 int rtcp_pkt_decode( vlc_object_t *p_this, rtcp_pkt_t *p_pkt, block_t *p_block );
222 //VLC_EXPORT( int, rtcp_decode, ( rtcp_pkt_t *, block_t * ) );
225 * rtcp_pkt_new - Encode RTCP packet
226 * Create a new RTCP packet of type 'type'
228 * \param type type of RTCP packet @see
230 rtcp_pkt_t *rtcp_pkt_new( vlc_object_t *p_this, int type );
231 //VLC_EXPORT( block_t* , rtcp_encode, ( vlc_object_t *, int ) );
232 void rtcp_pkt_del( vlc_object_t *p_this, rtcp_pkt_t *pkt );
234 block_t *rtcp_encode_SR( vlc_object_t *p_this, rtcp_pkt_t *p_pkt );
235 block_t *rtcp_encode_RR( vlc_object_t *p_this, rtcp_pkt_t *p_pkt );
236 block_t *rtcp_encode_SDES( vlc_object_t *p_this, rtcp_pkt_t *p_pkt );
237 block_t *rtcp_encode_BYE( vlc_object_t *p_this, rtcp_pkt_t *p_pkt, char *psz_reason );
241 * Calculate the interval at which RTCP compound packets are going to be
244 * \param p_this VLC_OBJECT of type rtcp_t
245 * \param u_bandwith bandwidth of RTP connection
246 * \param u_ssrc client to sent or receive from
247 * \param b_sender are we the sender or the receiver
248 * \param b_first the first time this function is called use only half
249 * of the initial waiting time
251 uint64_t rtcp_interval( vlc_object_t *p_this, uint64_t u_bandwidth, uint32_t u_ssrc,
252 vlc_bool_t b_sender, vlc_bool_t b_first );
256 * Decides to sent an RTCP report or a BYE record
258 * \param p_this VLC_OBJECT of type rtcp_t
259 * \param u_bandwith bandwidth of RTP connection
260 * \param u_ssrc client to sent or receive from
261 * \param rtcp_event type of event received
262 * \param b_sender are we the sender or the receiver
263 * \param *b_first the first time this function is called use only half
264 * of the initial waiting time. If b_first is VLC_TRUE, then
265 * it will return *b_first = VLC_FALSE;
267 void rtcp_expire( vlc_object_t *p_this, rtcp_event_t rtcp_event, uint64_t u_bandwidth,
268 uint32_t u_ssrc, vlc_bool_t b_sender, vlc_bool_t *b_first );
272 * Determine what to do on the received Sender Report, decode it
273 * or leave the channel (BYE record).
275 * \param p_this VLC_OBJECT of type rtcp_t
276 * \param p_pkt RTCP packet that was received
277 * \param rtcp_event type of event received
279 void rtcp_received( vlc_object_t *p_this, rtcp_pkt_t *pkt,
280 rtcp_event_t rtcp_event );