oRTP  0.24.0
str_utils.h
1 /*
2  The oRTP library is an RTP (Realtime Transport Protocol - rfc3550) stack.
3  Copyright (C) 2001 Simon MORLAT simon.morlat@linphone.org
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 
20 #ifndef STR_UTILS_H
21 #define STR_UTILS_H
22 
23 
24 #include <ortp/port.h>
25 #if defined(ORTP_TIMESTAMP)
26 #include <time.h>
27 #endif
28 
29 
30 #ifndef MIN
31 #define MIN(a,b) (((a)>(b)) ? (b) : (a))
32 #endif
33 #ifndef MAX
34 #define MAX(a,b) (((a)>(b)) ? (a) : (b))
35 #endif
36 
37 #define return_if_fail(expr) if (!(expr)) {printf("%s:%i- assertion"#expr "failed\n",__FILE__,__LINE__); return;}
38 #define return_val_if_fail(expr,ret) if (!(expr)) {printf("%s:%i- assertion" #expr "failed\n",__FILE__,__LINE__); return (ret);}
39 
40 
41 typedef struct ortp_recv_addr {
42  int family;
43  union {
44  struct in_addr ipi_addr;
45  struct in6_addr ipi6_addr;
46  } addr;
48 
49 typedef struct msgb
50 {
51  struct msgb *b_prev;
52  struct msgb *b_next;
53  struct msgb *b_cont;
54  struct datab *b_datap;
55  unsigned char *b_rptr;
56  unsigned char *b_wptr;
57  uint32_t reserved1;
58  uint32_t reserved2;
59 #if defined(ORTP_TIMESTAMP)
60  struct timeval timestamp;
61 #endif
62  ortp_recv_addr_t recv_addr; /*contains the destination address of incoming packets, used for ICE processing*/
63  struct sockaddr_storage net_addr; /*source address of incoming packet, or dest address of outgoing packet, used only by simulator and modifiers*/
64  socklen_t net_addrlen; /*source (dest) address of incoming (outgoing) packet length used by simulator and modifiers*/
65  uint8_t ttl_or_hl;
66 } mblk_t;
67 
68 
69 
70 typedef struct datab
71 {
72  unsigned char *db_base;
73  unsigned char *db_lim;
74  void (*db_freefn)(void*);
75  int db_ref;
76 } dblk_t;
77 
78 typedef struct _queue
79 {
80  mblk_t _q_stopper;
81  int q_mcount; /*number of packet in the q */
82 } queue_t;
83 
84 #ifdef __cplusplus
85 extern "C" {
86 #endif
87 
88 ORTP_PUBLIC void qinit(queue_t *q);
89 
90 ORTP_PUBLIC void putq(queue_t *q, mblk_t *m);
91 
92 ORTP_PUBLIC mblk_t * getq(queue_t *q);
93 
94 ORTP_PUBLIC void insq(queue_t *q,mblk_t *emp, mblk_t *mp);
95 
96 ORTP_PUBLIC void remq(queue_t *q, mblk_t *mp);
97 
98 ORTP_PUBLIC mblk_t * peekq(queue_t *q);
99 
100 /* remove and free all messages in the q */
101 #define FLUSHALL 0
102 ORTP_PUBLIC void flushq(queue_t *q, int how);
103 
104 ORTP_PUBLIC void mblk_init(mblk_t *mp);
105 
106 ORTP_PUBLIC void mblk_meta_copy(const mblk_t *source, mblk_t *dest);
107 
108 /* allocates a mblk_t, that points to a datab_t, that points to a buffer of size size. */
109 ORTP_PUBLIC mblk_t *allocb(size_t size, int unused);
110 #define BPRI_MED 0
111 
112 /* allocates a mblk_t, that points to a datab_t, that points to buf; buf will be freed using freefn */
113 ORTP_PUBLIC mblk_t *esballoc(uint8_t *buf, size_t size, int pri, void (*freefn)(void*) );
114 
115 /* frees a mblk_t, and if the datab ref_count is 0, frees it and the buffer too */
116 ORTP_PUBLIC void freeb(mblk_t *m);
117 
118 /* frees recursively (follow b_cont) a mblk_t, and if the datab
119 ref_count is 0, frees it and the buffer too */
120 ORTP_PUBLIC void freemsg(mblk_t *mp);
121 
122 /* duplicates a mblk_t , buffer is not duplicated*/
123 ORTP_PUBLIC mblk_t *dupb(mblk_t *m);
124 
125 /* duplicates a complex mblk_t, buffer is not duplicated */
126 ORTP_PUBLIC mblk_t *dupmsg(mblk_t* m);
127 
128 /* returns the size of data of a message */
129 ORTP_PUBLIC size_t msgdsize(const mblk_t *mp);
130 
131 /* concatenates all fragment of a complex message*/
132 ORTP_PUBLIC void msgpullup(mblk_t *mp,size_t len);
133 
134 /* duplicates a single message, but with buffer included */
135 ORTP_PUBLIC mblk_t *copyb(const mblk_t *mp);
136 
137 /* duplicates a complex message with buffer included */
138 ORTP_PUBLIC mblk_t *copymsg(const mblk_t *mp);
139 
140 ORTP_PUBLIC mblk_t * appendb(mblk_t *mp, const char *data, size_t size, bool_t pad);
141 ORTP_PUBLIC void msgappend(mblk_t *mp, const char *data, size_t size, bool_t pad);
142 
143 ORTP_PUBLIC mblk_t *concatb(mblk_t *mp, mblk_t *newm);
144 
145 #define qempty(q) (&(q)->_q_stopper==(q)->_q_stopper.b_next)
146 #define qfirst(q) ((q)->_q_stopper.b_next!=&(q)->_q_stopper ? (q)->_q_stopper.b_next : NULL)
147 #define qbegin(q) ((q)->_q_stopper.b_next)
148 #define qlast(q) ((q)->_q_stopper.b_prev!=&(q)->_q_stopper ? (q)->_q_stopper.b_prev : NULL)
149 #define qend(q,mp) ((mp)==&(q)->_q_stopper)
150 #define qnext(q,mp) ((mp)->b_next)
151 
152 typedef struct _msgb_allocator{
153  queue_t q;
155 
156 ORTP_PUBLIC void msgb_allocator_init(msgb_allocator_t *pa);
157 ORTP_PUBLIC mblk_t *msgb_allocator_alloc(msgb_allocator_t *pa, size_t size);
158 ORTP_PUBLIC void msgb_allocator_uninit(msgb_allocator_t *pa);
159 
164 typedef struct _ortp_extremum{
165  float current_extremum;
166  uint64_t extremum_time;
167  float last_stable;
168  int period;
170 
171 ORTP_PUBLIC void ortp_extremum_reset(ortp_extremum *obj);
172 ORTP_PUBLIC void ortp_extremum_init(ortp_extremum *obj, int period);
173 ORTP_PUBLIC void ortp_extremum_record_min(ortp_extremum *obj, uint64_t curtime, float value);
174 ORTP_PUBLIC void ortp_extremum_record_max(ortp_extremum *obj, uint64_t curtime, float value);
175 ORTP_PUBLIC float ortp_extremum_get_current(ortp_extremum *obj);
179 ORTP_PUBLIC float ortp_extremum_get_previous(ortp_extremum *obj);
180 
181 #ifdef __cplusplus
182 }
183 #endif
184 
185 #endif
Definition: str_utils.h:41
Definition: str_utils.h:49
Definition: str_utils.h:78
Definition: str_utils.h:70
Definition: str_utils.h:152
Definition: str_utils.h:164