rtcp.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * rtcp.h: RTP/RTCP headerfile
00003  *****************************************************************************
00004  * Copyright (C) 2005-2007 M2X
00005  *
00006  * $Id$
00007  *
00008  * Authors: Jean-Paul Saman <jpsaman #_at_# videolan dot org>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00023  *****************************************************************************/
00024 
00025 #ifndef _RTCP_H
00026 #define _RTCP_H 1
00027 
00028 /* RTCP packet types */
00029 #define RTCP_SR     200
00030 #define RTCP_RR     201
00031 #define RTCP_SDES   202
00032 #define RTCP_BYE    203
00033 #define RTCP_APP    204
00034 /* End of RTCP packet types */
00035 
00036 /* SDES type */
00037 #define RTCP_SDES_CNAME 1
00038 #define RTCP_SDES_NAME  2
00039 #define RTCP_SDES_EMAIL 3
00040 #define RTCP_SDES_PHONE 4
00041 #define RTCP_SDES_LOC   5
00042 #define RTCP_SDES_TOOL  6
00043 #define RTCP_SDES_NOTE  7
00044 #define RTCP_SDES_PRIV  8
00045 /* End of SDES type */
00046 
00047 #define RTCP_HEADER_LEN 3
00048 
00049 typedef enum rtcp_event_enum
00050 {
00051     EVENT_BYE,
00052     EVENT_REPORT
00053 
00054 } rtcp_event_t;
00055 
00056 typedef struct
00057 {
00058     uint32_t ntp_timestampH;
00059     uint32_t ntp_timestampL;
00060     uint32_t rtp_timestamp;
00061     uint32_t u_pkt_count;
00062     uint32_t u_octet_count;
00063 
00064 } rtcp_SR_t;
00065 
00066 typedef struct
00067 {
00068 
00069 } rtcp_RR_t;
00070 
00071 typedef struct SDES_item_t
00072 {
00073     uint32_t       i_index;     /*< index */
00074     uint8_t        u_type;      /*< type field */
00075     char           *psz_data;    /*< null terminated string */
00076 
00077 } rtcp_SDES_item_t;
00078 
00079 typedef struct
00080 {
00081     uint32_t    u_length;        /*< length of packet */
00082     uint32_t    u_items;         /*< number of SDES_items */
00083     rtcp_SDES_item_t **pp_items; /*< list of SDES_items */
00084 
00085 } rtcp_SDES_t;
00086 
00087 typedef struct
00088 {
00089     uint32_t u_length;        /*< length of packet */
00090 
00091 } rtcp_BYE_t;
00092 
00093 typedef struct
00094 {
00095     uint32_t u_length;        /*< length of packet */
00096     uint32_t u_prefix_len;    /*< length of prefix data */
00097     unsigned char *psz_prefix;/*< prefix string (null terminated) */
00098     unsigned char *psz_data;  /*< data string (null terminated) */
00099 
00100 } rtcp_APP_t;
00101 
00102 /**
00103  * structure rtcp_stats_t
00104  */
00105 typedef struct
00106 {
00107     uint32_t  u_RR_received;   /*< RR records received */
00108     uint32_t  u_SR_received;   /*< SR records received */
00109     uint64_t  l_dest_SSRC;     /*< SSRC of first source */
00110     uint32_t  u_pkt_count;     /*< count of packets received */
00111     uint32_t  u_octet_count;   /*< ? */
00112     uint32_t  u_pkt_lost;      /*< cumulative count of packets lost */
00113     uint8_t   u_fraction_lost; /*< count of fractional packets lost */
00114     uint32_t  u_highest_seq_no;/*< highest sequence number found */
00115     uint32_t  u_jitter;        /*< inter arrival jitter calculated */
00116     uint32_t  u_last_SR;       /*< last SR record received */
00117     uint32_t  u_last_RR;       /*< last RR record received */
00118     mtime_t   u_delay_since_last_SR; /*< delay since last SR record received */
00119     mtime_t   u_delay_since_last_RR; /*< delay since last RR record received */
00120 
00121     uint64_t  u_avg_pkt_size;  /*< average RTCP packet size */
00122     uint64_t  u_sent_pkt_size; /*< RTCP packet size sent */
00123 
00124 } rtcp_stats_t;
00125 
00126 typedef struct
00127 {
00128     uint32_t u_version;        /*< RTCP version number */
00129     bool b_padding;      /*< indicates if packets has padding */
00130     uint32_t u_report;         /*< reception packet count */
00131     uint32_t u_payload_type;   /*< type of RTCP payload */
00132     uint32_t u_length;         /*< length of packet */
00133     uint32_t u_ssrc;           /*< channel name this packet belongs to */
00134 
00135     union {
00136         rtcp_SR_t sr;                /*< SR record */
00137         rtcp_RR_t rr;                /*< RR record */
00138         rtcp_SDES_t sdes;            /*< SDES record */
00139         rtcp_BYE_t bye;              /*< BYE record */
00140         rtcp_APP_t app;              /*< APP record */
00141     } report;
00142 
00143 } rtcp_pkt_t;
00144 
00145 typedef struct rtcp_client_t
00146 {
00147     int fd;                        /*< socket descriptor of rtcp stream */
00148 
00149     uint32_t    i_index;
00150     uint32_t    u_ssrc;            /*< channel name */
00151     bool  b_deleted;         /*< channel deleted ? */
00152     mtime_t     i_timeout;         /*< remove timeout before real deletion,
00153                                     * this is recommended by RFC 3550 at
00154                                     * page 27 to ignore out-of-order packets.
00155                                     */
00156     rtcp_stats_t *p_stats;         /*< RTCP statistics */
00157 
00158     uint32_t         i_items;      /*< count of SDES item structures */
00159     rtcp_SDES_item_t **pp_sdes;    /*< SDES client items */
00160 } rtcp_client_t;
00161 
00162 /**
00163  * structure rtcp_t
00164  * This structure is a VLC_OBJECT and holds RTCP statistical information.
00165  */
00166 typedef struct rtcp_t
00167 {
00168     VLC_COMMON_MEMBERS
00169 
00170     uint32_t u_clients;            /*< number of clients connected */
00171     uint32_t u_active;             /*< number of active senders */
00172     uint32_t u_members;            /*< number of clients in previous interval */
00173 
00174     mtime_t i_date;                 /*< current RTCP packet interval */
00175     mtime_t i_last_date;            /*< previous RTCP packet interval */
00176     mtime_t i_next_date;            /*< next scheduled transmision time
00177                                         of RTCP packet */
00178 
00179     uint32_t i_clients;            /*< count of clients structures */
00180     rtcp_client_t **pp_clients;    /*< RTCP clients */
00181 
00182     /* bitstream data pointer used for decoding */
00183     bs_t    *bs;                   /*< bitstream decoding data pointer */
00184 
00185     /* functions */
00186     int (*pf_add_client)( vlc_object_t *p_this, uint32_t u_ssrc, uint32_t *i_pos );
00187     int (*pf_del_client)( vlc_object_t *p_this, uint32_t u_ssrc );
00188     int (*pf_find_client)( vlc_object_t *p_this, uint32_t u_ssrc, uint32_t *i_pos );
00189     int (*pf_cleanup_clients)( vlc_object_t *p_this );
00190     int (*pf_destroy_clients)( vlc_object_t *p_this );
00191 } rtcp_t;
00192 
00193 int rtcp_add_client( vlc_object_t *p_this, uint32_t u_ssrc, uint32_t *i_pos );
00194 int rtcp_del_client( vlc_object_t *p_this, uint32_t u_ssrc );
00195 /* Should be called with vlc_mutex_lock( &p_this->objec_lock ) held */
00196 int rtcp_find_client( vlc_object_t *p_this, uint32_t u_ssrc, uint32_t *i_pos );
00197 int rtcp_cleanup_clients( vlc_object_t *p_this );
00198 int rtcp_destroy_clients( vlc_object_t *p_this );
00199 
00200 /**
00201  * rtcp_cleanup_clients - Permanently remove clients from the list
00202  * Permanently delete struct rtcp_client_t from member list when it is there
00203  * time to be removed. RFC 3550 recommends a grace period of five times the
00204  * RTCP packet send/receive interval before permanent removal of session. This
00205  * is to ignore out of order packets for the same SSRC that arrive after the
00206  * BYE report for that SSRC has been received.
00207  * Arguments:
00208  * \param p_this    VLC_OBJECT_T of type rtcp_t
00209  */
00210 int rtcp_cleanup_clients( vlc_object_t *p_this );
00211 //VLC_EXPORT( int, rtcp_cleanup_clients, ( vlc_object_t * ) );
00212 
00213 /**
00214  * rtcp_pkt_decode - Decode RTCP packet
00215  * Decode incoming RTCP packet and inspect the records types.
00216  * Arguments:
00217  * \param p_this
00218  * \param p_pkt
00219  * \param p_block
00220  */
00221 int rtcp_pkt_decode( vlc_object_t *p_this, rtcp_pkt_t *p_pkt, block_t *p_block );
00222 //VLC_EXPORT( int, rtcp_decode, ( rtcp_pkt_t *, block_t * ) );
00223 
00224 /**
00225  * rtcp_pkt_new - Encode RTCP packet
00226  * Create a new RTCP packet of type 'type'
00227  * Arguments:
00228  * \param type  type of RTCP packet @see
00229  */
00230 rtcp_pkt_t *rtcp_pkt_new( vlc_object_t *p_this, int type );
00231 //VLC_EXPORT( block_t* , rtcp_encode, ( vlc_object_t *, int ) );
00232 void rtcp_pkt_del( vlc_object_t *p_this, rtcp_pkt_t *pkt );
00233 
00234 block_t *rtcp_encode_SR( vlc_object_t *p_this, rtcp_pkt_t *p_pkt );
00235 block_t *rtcp_encode_RR( vlc_object_t *p_this, rtcp_pkt_t *p_pkt );
00236 block_t *rtcp_encode_SDES( vlc_object_t *p_this, rtcp_pkt_t *p_pkt );
00237 block_t *rtcp_encode_BYE( vlc_object_t *p_this, rtcp_pkt_t *p_pkt, char *psz_reason );
00238 
00239 /**
00240  * rtcp_interval
00241  * Calculate the interval at which RTCP compound packets are going to be
00242  * sent or received.
00243  * Arguments:
00244  * \param p_this        VLC_OBJECT of type rtcp_t
00245  * \param u_bandwith    bandwidth of RTP connection
00246  * \param u_ssrc        client to sent or receive from
00247  * \param b_sender      are we the sender or the receiver
00248  * \param b_first       the first time this function is called use only half
00249  *                      of the initial waiting time
00250  */
00251 uint64_t rtcp_interval( vlc_object_t *p_this, uint64_t u_bandwidth, uint32_t u_ssrc,
00252                         bool b_sender, bool b_first );
00253 
00254 /**
00255  * rtcp_expire
00256  * Decides to sent an RTCP report or a BYE record
00257  * Arguments:
00258  * \param p_this        VLC_OBJECT of type rtcp_t
00259  * \param u_bandwith    bandwidth of RTP connection
00260  * \param u_ssrc        client to sent or receive from
00261  * \param rtcp_event    type of event received
00262  * \param b_sender      are we the sender or the receiver
00263  * \param *b_first      the first time this function is called use only half
00264  *                      of the initial waiting time. If b_first is true, then
00265  *                      it will return *b_first = false;
00266  */
00267 void rtcp_expire( vlc_object_t *p_this, rtcp_event_t rtcp_event, uint64_t u_bandwidth,
00268                   uint32_t u_ssrc, bool b_sender, bool *b_first );
00269 
00270 /**
00271  * rtcp_received
00272  * Determine what to do on the received Sender Report, decode it
00273  * or leave the channel (BYE record).
00274  * Arguments:
00275  * \param p_this        VLC_OBJECT of type rtcp_t
00276  * \param p_pkt         RTCP packet that was received
00277  * \param rtcp_event    type of event received
00278  */
00279 void rtcp_received( vlc_object_t *p_this, rtcp_pkt_t *pkt,
00280                     rtcp_event_t rtcp_event );
00281 
00282 #endif /* RTCP_H */

Generated on Wed Aug 13 08:02:38 2008 for VLC by  doxygen 1.5.1