oRTP
0.25.0
|
00001 /* 00002 The oRTP library is an RTP (Realtime Transport Protocol - rfc3550) stack. 00003 Copyright (C) 2001 Simon MORLAT simon.morlat@linphone.org 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Lesser General Public 00007 License as published by the Free Software Foundation; either 00008 version 2.1 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public 00016 License along with this library; if not, write to the Free Software 00017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 */ 00019 00020 00021 #ifndef RTP_H 00022 #define RTP_H 00023 00024 #include <ortp/port.h> 00025 #include <ortp/str_utils.h> 00026 00027 #define IPMAXLEN 20 00028 #define UDP_MAX_SIZE 1500 00029 #define RTP_FIXED_HEADER_SIZE 12 00030 #define RTP_DEFAULT_JITTER_TIME 80 /*miliseconds*/ 00031 #define RTP_DEFAULT_MULTICAST_TTL 5 /*hops*/ 00032 #define RTP_DEFAULT_MULTICAST_LOOPBACK 0 /*false*/ 00033 #define RTP_DEFAULT_DSCP 0x00 /*best effort*/ 00034 00035 00036 00037 typedef struct rtp_header 00038 { 00039 #ifdef ORTP_BIGENDIAN 00040 uint16_t version:2; 00041 uint16_t padbit:1; 00042 uint16_t extbit:1; 00043 uint16_t cc:4; 00044 uint16_t markbit:1; 00045 uint16_t paytype:7; 00046 #else 00047 uint16_t cc:4; 00048 uint16_t extbit:1; 00049 uint16_t padbit:1; 00050 uint16_t version:2; 00051 uint16_t paytype:7; 00052 uint16_t markbit:1; 00053 #endif 00054 uint16_t seq_number; 00055 uint32_t timestamp; 00056 uint32_t ssrc; 00057 uint32_t csrc[16]; 00058 } rtp_header_t; 00059 00060 00061 00062 00063 typedef struct rtp_stats 00064 { 00065 uint64_t packet_sent; /*number of outgoing packets */ 00066 uint64_t packet_dup_sent; /*number of outgoing duplicate packets */ 00067 uint64_t sent; /* outgoing total bytes (excluding IP header) */ 00068 uint64_t packet_recv; /* number of incoming packets */ 00069 uint64_t packet_dup_recv; /* number of incoming duplicate packets */ 00070 uint64_t recv; /* incoming bytes of payload and delivered in time to the application */ 00071 uint64_t hw_recv; /* incoming bytes of payload */ 00072 uint64_t outoftime; /* number of incoming packets that were received too late */ 00073 int64_t cum_packet_loss; /* cumulative number of incoming packet lost */ 00074 uint64_t bad; /* incoming packets that did not appear to be RTP */ 00075 uint64_t discarded; /* incoming packets discarded because the queue exceeds its max size */ 00076 uint64_t sent_rtcp_packets; /* outgoing RTCP packets counter (only packets that embed a report block are considered) */ 00077 } rtp_stats_t; 00078 00079 typedef struct jitter_stats 00080 { 00081 uint32_t jitter; /* interarrival jitter at last emitted sender report */ 00082 uint32_t max_jitter; /* biggest interarrival jitter (value in stream clock unit) */ 00083 uint64_t sum_jitter; /* sum of all interarrival jitter (value in stream clock unit) */ 00084 uint64_t max_jitter_ts; /* date (in ms since Epoch) of the biggest interarrival jitter */ 00085 float jitter_buffer_size_ms;/* mean jitter buffer size in milliseconds.*/ 00086 } jitter_stats_t; 00087 00088 #define RTP_TIMESTAMP_IS_NEWER_THAN(ts1,ts2) \ 00089 ((uint32_t)((uint32_t)(ts1) - (uint32_t)(ts2))< (uint32_t)(1<<31)) 00090 00091 #define RTP_TIMESTAMP_IS_STRICTLY_NEWER_THAN(ts1,ts2) \ 00092 ( ((uint32_t)((uint32_t)(ts1) - (uint32_t)(ts2))< (uint32_t)(1<<31)) && (ts1)!=(ts2) ) 00093 00094 #define RTP_SEQ_IS_STRICTLY_GREATER_THAN(seq1,seq2)\ 00095 (((uint16_t)((uint16_t)(seq1) - (uint16_t)(seq2))< (uint16_t)(1<<15)) && (seq1!=seq2)) 00096 00097 #define TIME_IS_NEWER_THAN(t1,t2) RTP_TIMESTAMP_IS_NEWER_THAN(t1,t2) 00098 00099 #define TIME_IS_STRICTLY_NEWER_THAN(t1,t2) RTP_TIMESTAMP_IS_STRICTLY_NEWER_THAN(t1,t2) 00100 00101 00102 #ifdef __cplusplus 00103 extern "C"{ 00104 #endif 00105 00106 /* packet api */ 00107 /* the first argument is a mblk_t. The header is supposed to be not splitted */ 00108 #define rtp_set_markbit(mp,value) ((rtp_header_t*)((mp)->b_rptr))->markbit=(value) 00109 #define rtp_set_seqnumber(mp,seq) ((rtp_header_t*)((mp)->b_rptr))->seq_number=(seq) 00110 #define rtp_set_timestamp(mp,ts) ((rtp_header_t*)((mp)->b_rptr))->timestamp=(ts) 00111 #define rtp_set_ssrc(mp,_ssrc) ((rtp_header_t*)((mp)->b_rptr))->ssrc=(_ssrc) 00112 ORTP_PUBLIC void rtp_add_csrc(mblk_t *mp ,uint32_t csrc); 00113 #define rtp_set_payload_type(mp,pt) ((rtp_header_t*)((mp)->b_rptr))->paytype=(pt) 00114 00115 #define rtp_get_markbit(mp) (((rtp_header_t*)((mp)->b_rptr))->markbit) 00116 #define rtp_get_extbit(mp) (((rtp_header_t*)((mp)->b_rptr))->extbit) 00117 #define rtp_get_timestamp(mp) (((rtp_header_t*)((mp)->b_rptr))->timestamp) 00118 #define rtp_get_seqnumber(mp) (((rtp_header_t*)((mp)->b_rptr))->seq_number) 00119 #define rtp_get_payload_type(mp) (((rtp_header_t*)((mp)->b_rptr))->paytype) 00120 #define rtp_get_ssrc(mp) (((rtp_header_t*)((mp)->b_rptr))->ssrc) 00121 #define rtp_get_cc(mp) (((rtp_header_t*)((mp)->b_rptr))->cc) 00122 #define rtp_get_csrc(mp, idx) (((rtp_header_t*)((mp)->b_rptr))->csrc[idx]) 00123 00124 ORTP_PUBLIC int rtp_get_payload(mblk_t *packet, unsigned char **start); 00125 ORTP_PUBLIC int rtp_get_extheader(mblk_t *packet, uint16_t *profile, uint8_t **start_ext); 00126 00127 #ifdef __cplusplus 00128 } 00129 #endif 00130 00131 #endif