oRTP
0.24.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 #ifndef STR_UTILS_H 00021 #define STR_UTILS_H 00022 00023 00024 #include <ortp/port.h> 00025 #if defined(ORTP_TIMESTAMP) 00026 #include <time.h> 00027 #endif 00028 00029 00030 #ifndef MIN 00031 #define MIN(a,b) (((a)>(b)) ? (b) : (a)) 00032 #endif 00033 #ifndef MAX 00034 #define MAX(a,b) (((a)>(b)) ? (a) : (b)) 00035 #endif 00036 00037 #define return_if_fail(expr) if (!(expr)) {printf("%s:%i- assertion"#expr "failed\n",__FILE__,__LINE__); return;} 00038 #define return_val_if_fail(expr,ret) if (!(expr)) {printf("%s:%i- assertion" #expr "failed\n",__FILE__,__LINE__); return (ret);} 00039 00040 00041 typedef struct ortp_recv_addr { 00042 int family; 00043 union { 00044 struct in_addr ipi_addr; 00045 struct in6_addr ipi6_addr; 00046 } addr; 00047 } ortp_recv_addr_t; 00048 00049 typedef struct msgb 00050 { 00051 struct msgb *b_prev; 00052 struct msgb *b_next; 00053 struct msgb *b_cont; 00054 struct datab *b_datap; 00055 unsigned char *b_rptr; 00056 unsigned char *b_wptr; 00057 uint32_t reserved1; 00058 uint32_t reserved2; 00059 #if defined(ORTP_TIMESTAMP) 00060 struct timeval timestamp; 00061 #endif 00062 ortp_recv_addr_t recv_addr; /*contains the destination address of incoming packets, used for ICE processing*/ 00063 struct sockaddr_storage net_addr; /*source address of incoming packet, or dest address of outgoing packet, used only by simulator and modifiers*/ 00064 socklen_t net_addrlen; /*source (dest) address of incoming (outgoing) packet length used by simulator and modifiers*/ 00065 uint8_t ttl_or_hl; 00066 } mblk_t; 00067 00068 00069 00070 typedef struct datab 00071 { 00072 unsigned char *db_base; 00073 unsigned char *db_lim; 00074 void (*db_freefn)(void*); 00075 int db_ref; 00076 } dblk_t; 00077 00078 typedef struct _queue 00079 { 00080 mblk_t _q_stopper; 00081 int q_mcount; /*number of packet in the q */ 00082 } queue_t; 00083 00084 #ifdef __cplusplus 00085 extern "C" { 00086 #endif 00087 00088 ORTP_PUBLIC void qinit(queue_t *q); 00089 00090 ORTP_PUBLIC void putq(queue_t *q, mblk_t *m); 00091 00092 ORTP_PUBLIC mblk_t * getq(queue_t *q); 00093 00094 ORTP_PUBLIC void insq(queue_t *q,mblk_t *emp, mblk_t *mp); 00095 00096 ORTP_PUBLIC void remq(queue_t *q, mblk_t *mp); 00097 00098 ORTP_PUBLIC mblk_t * peekq(queue_t *q); 00099 00100 /* remove and free all messages in the q */ 00101 #define FLUSHALL 0 00102 ORTP_PUBLIC void flushq(queue_t *q, int how); 00103 00104 ORTP_PUBLIC void mblk_init(mblk_t *mp); 00105 00106 ORTP_PUBLIC void mblk_meta_copy(const mblk_t *source, mblk_t *dest); 00107 00108 /* allocates a mblk_t, that points to a datab_t, that points to a buffer of size size. */ 00109 ORTP_PUBLIC mblk_t *allocb(size_t size, int unused); 00110 #define BPRI_MED 0 00111 00112 /* allocates a mblk_t, that points to a datab_t, that points to buf; buf will be freed using freefn */ 00113 ORTP_PUBLIC mblk_t *esballoc(uint8_t *buf, size_t size, int pri, void (*freefn)(void*) ); 00114 00115 /* frees a mblk_t, and if the datab ref_count is 0, frees it and the buffer too */ 00116 ORTP_PUBLIC void freeb(mblk_t *m); 00117 00118 /* frees recursively (follow b_cont) a mblk_t, and if the datab 00119 ref_count is 0, frees it and the buffer too */ 00120 ORTP_PUBLIC void freemsg(mblk_t *mp); 00121 00122 /* duplicates a mblk_t , buffer is not duplicated*/ 00123 ORTP_PUBLIC mblk_t *dupb(mblk_t *m); 00124 00125 /* duplicates a complex mblk_t, buffer is not duplicated */ 00126 ORTP_PUBLIC mblk_t *dupmsg(mblk_t* m); 00127 00128 /* returns the size of data of a message */ 00129 ORTP_PUBLIC size_t msgdsize(const mblk_t *mp); 00130 00131 /* concatenates all fragment of a complex message*/ 00132 ORTP_PUBLIC void msgpullup(mblk_t *mp,size_t len); 00133 00134 /* duplicates a single message, but with buffer included */ 00135 ORTP_PUBLIC mblk_t *copyb(const mblk_t *mp); 00136 00137 /* duplicates a complex message with buffer included */ 00138 ORTP_PUBLIC mblk_t *copymsg(const mblk_t *mp); 00139 00140 ORTP_PUBLIC mblk_t * appendb(mblk_t *mp, const char *data, size_t size, bool_t pad); 00141 ORTP_PUBLIC void msgappend(mblk_t *mp, const char *data, size_t size, bool_t pad); 00142 00143 ORTP_PUBLIC mblk_t *concatb(mblk_t *mp, mblk_t *newm); 00144 00145 #define qempty(q) (&(q)->_q_stopper==(q)->_q_stopper.b_next) 00146 #define qfirst(q) ((q)->_q_stopper.b_next!=&(q)->_q_stopper ? (q)->_q_stopper.b_next : NULL) 00147 #define qbegin(q) ((q)->_q_stopper.b_next) 00148 #define qlast(q) ((q)->_q_stopper.b_prev!=&(q)->_q_stopper ? (q)->_q_stopper.b_prev : NULL) 00149 #define qend(q,mp) ((mp)==&(q)->_q_stopper) 00150 #define qnext(q,mp) ((mp)->b_next) 00151 00152 typedef struct _msgb_allocator{ 00153 queue_t q; 00154 }msgb_allocator_t; 00155 00156 ORTP_PUBLIC void msgb_allocator_init(msgb_allocator_t *pa); 00157 ORTP_PUBLIC mblk_t *msgb_allocator_alloc(msgb_allocator_t *pa, size_t size); 00158 ORTP_PUBLIC void msgb_allocator_uninit(msgb_allocator_t *pa); 00159 00164 typedef struct _ortp_extremum{ 00165 float current_extremum; 00166 uint64_t extremum_time; 00167 float last_stable; 00168 int period; 00169 }ortp_extremum; 00170 00171 ORTP_PUBLIC void ortp_extremum_reset(ortp_extremum *obj); 00172 ORTP_PUBLIC void ortp_extremum_init(ortp_extremum *obj, int period); 00173 ORTP_PUBLIC void ortp_extremum_record_min(ortp_extremum *obj, uint64_t curtime, float value); 00174 ORTP_PUBLIC void ortp_extremum_record_max(ortp_extremum *obj, uint64_t curtime, float value); 00175 ORTP_PUBLIC float ortp_extremum_get_current(ortp_extremum *obj); 00179 ORTP_PUBLIC float ortp_extremum_get_previous(ortp_extremum *obj); 00180 00181 #ifdef __cplusplus 00182 } 00183 #endif 00184 00185 #endif