oRTP
0.18.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; 00066 uint64_t sent; /* bytes sent */ 00067 uint64_t recv; /* bytes of payload received and delivered in time to the application */ 00068 uint64_t hw_recv; /* bytes of payload received */ 00069 uint64_t packet_recv; /* number of packets received */ 00070 uint64_t outoftime; /* number of packets that were received too late */ 00071 uint64_t cum_packet_loss; /* cumulative number of packet lost */ 00072 uint64_t bad; /* packets that did not appear to be RTP */ 00073 uint64_t discarded; /* incoming packets discarded because the queue exceeds its max size */ 00074 uint64_t sent_rtcp_packets; /* sent RTCP packets counter (only packets that embed a report block are considered) */ 00075 } rtp_stats_t; 00076 00077 typedef struct jitter_stats 00078 { 00079 uint32_t jitter; /* interarrival jitter at last emitted sender report */ 00080 uint32_t max_jitter; /* biggest interarrival jitter (value in stream clock unit) */ 00081 uint64_t sum_jitter; /* sum of all interarrival jitter (value in stream clock unit) */ 00082 uint64_t max_jitter_ts; /* date (in ms since Epoch) of the biggest interarrival jitter */ 00083 } jitter_stats_t; 00084 00085 #define RTP_TIMESTAMP_IS_NEWER_THAN(ts1,ts2) \ 00086 ((uint32_t)((uint32_t)(ts1) - (uint32_t)(ts2))< (uint32_t)(1<<31)) 00087 00088 #define RTP_TIMESTAMP_IS_STRICTLY_NEWER_THAN(ts1,ts2) \ 00089 ( ((uint32_t)((uint32_t)(ts1) - (uint32_t)(ts2))< (uint32_t)(1<<31)) && (ts1)!=(ts2) ) 00090 00091 #define TIME_IS_NEWER_THAN(t1,t2) RTP_TIMESTAMP_IS_NEWER_THAN(t1,t2) 00092 00093 #define TIME_IS_STRICTLY_NEWER_THAN(t1,t2) RTP_TIMESTAMP_IS_STRICTLY_NEWER_THAN(t1,t2) 00094 00095 00096 #ifdef __cplusplus 00097 extern "C"{ 00098 #endif 00099 00100 /* packet api */ 00101 /* the first argument is a mblk_t. The header is supposed to be not splitted */ 00102 #define rtp_set_markbit(mp,value) ((rtp_header_t*)((mp)->b_rptr))->markbit=(value) 00103 #define rtp_set_seqnumber(mp,seq) ((rtp_header_t*)((mp)->b_rptr))->seq_number=(seq) 00104 #define rtp_set_timestamp(mp,ts) ((rtp_header_t*)((mp)->b_rptr))->timestamp=(ts) 00105 #define rtp_set_ssrc(mp,_ssrc) ((rtp_header_t*)((mp)->b_rptr))->ssrc=(_ssrc) 00106 void rtp_add_csrc(mblk_t *mp ,uint32_t csrc); 00107 #define rtp_set_payload_type(mp,pt) ((rtp_header_t*)((mp)->b_rptr))->paytype=(pt) 00108 00109 #define rtp_get_markbit(mp) (((rtp_header_t*)((mp)->b_rptr))->markbit) 00110 #define rtp_get_extbit(mp) (((rtp_header_t*)((mp)->b_rptr))->extbit) 00111 #define rtp_get_timestamp(mp) (((rtp_header_t*)((mp)->b_rptr))->timestamp) 00112 #define rtp_get_seqnumber(mp) (((rtp_header_t*)((mp)->b_rptr))->seq_number) 00113 #define rtp_get_payload_type(mp) (((rtp_header_t*)((mp)->b_rptr))->paytype) 00114 #define rtp_get_ssrc(mp) (((rtp_header_t*)((mp)->b_rptr))->ssrc) 00115 #define rtp_get_cc(mp) (((rtp_header_t*)((mp)->b_rptr))->cc) 00116 #define rtp_get_csrc(mp, idx) (((rtp_header_t*)((mp)->b_rptr))->csrc[idx]) 00117 00118 int rtp_get_payload(mblk_t *packet, unsigned char **start); 00119 int rtp_get_extheader(mblk_t *packet, uint16_t *profile, uint8_t **start_ext); 00120 00121 #ifdef __cplusplus 00122 } 00123 #endif 00124 00125 #endif