1 | /* |
2 | mediastreamer2 library - modular sound and video processing and streaming |
3 | Copyright (C) 2006 Simon MORLAT (simon.morlat@linphone.org) |
4 | |
5 | This program is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU General Public License |
7 | as published by the Free Software Foundation; either version 2 |
8 | of the License, or (at your option) any later version. |
9 | |
10 | This program 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 |
13 | GNU General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | */ |
19 | #ifndef mscommon_h |
20 | #define mscommon_h |
21 | |
22 | #include <ortp/logging.h> |
23 | #include <ortp/port.h> |
24 | #include <ortp/str_utils.h> |
25 | #include <ortp/payloadtype.h> |
26 | #include <time.h> |
27 | #if defined(__APPLE__) |
28 | #include "TargetConditionals.h" |
29 | #endif |
30 | |
31 | #define MS_UNUSED(x) ((void)(x)) |
32 | |
33 | #define ms_malloc ortp_malloc |
34 | #define ms_malloc0 ortp_malloc0 |
35 | #define ms_realloc ortp_realloc |
36 | #define ms_new ortp_new |
37 | #define ms_new0 ortp_new0 |
38 | #define ms_free ortp_free |
39 | #define ms_strdup ortp_strdup |
40 | #define ms_strdup_printf ortp_strdup_printf |
41 | |
42 | #define ms_mutex_t ortp_mutex_t |
43 | #define ms_mutex_init ortp_mutex_init |
44 | #define ms_mutex_destroy ortp_mutex_destroy |
45 | #define ms_mutex_lock ortp_mutex_lock |
46 | #define ms_mutex_unlock ortp_mutex_unlock |
47 | |
48 | #define ms_cond_t ortp_cond_t |
49 | #define ms_cond_init ortp_cond_init |
50 | #define ms_cond_wait ortp_cond_wait |
51 | #define ms_cond_signal ortp_cond_signal |
52 | #define ms_cond_broadcast ortp_cond_broadcast |
53 | #define ms_cond_destroy ortp_cond_destroy |
54 | |
55 | #if defined(_MSC_VER) |
56 | #define MS2_PUBLIC __declspec(dllexport) |
57 | #else |
58 | #define MS2_PUBLIC |
59 | #endif |
60 | |
61 | #if defined(_WIN32_WCE) |
62 | time_t ms_time (time_t *t); |
63 | #else |
64 | #define ms_time time |
65 | #endif |
66 | |
67 | #ifdef WIN32 |
68 | static inline void ms_debug(const char *fmt,...) |
69 | { |
70 | va_list args; |
71 | va_start (args, fmt); |
72 | ortp_logv(ORTP_DEBUG, fmt, args); |
73 | va_end (args); |
74 | } |
75 | #else |
76 | #ifdef DEBUG |
77 | static inline void ms_debug(const char *fmt,...) |
78 | { |
79 | va_list args; |
80 | va_start (args, fmt); |
81 | ortp_logv(ORTP_DEBUG, fmt, args); |
82 | va_end (args); |
83 | } |
84 | #else |
85 | #define ms_debug(...) |
86 | #endif |
87 | #endif |
88 | |
89 | #define ms_message ortp_message |
90 | #define ms_warning ortp_warning |
91 | #define ms_error ortp_error |
92 | #define ms_fatal ortp_fatal |
93 | |
94 | #define ms_return_val_if_fail(_expr_,_ret_)\ |
95 | if (!(_expr_)) { ms_error("assert "#_expr_ "failed"); return (_ret_);} |
96 | |
97 | #define ms_return_if_fail(_expr_) \ |
98 | if (!(_expr_)){ ms_error("assert "#_expr_ "failed"); return ;} |
99 | |
100 | #define ms_thread_t ortp_thread_t |
101 | #define ms_thread_create ortp_thread_create |
102 | #define ms_thread_join ortp_thread_join |
103 | |
104 | typedef ortpTimeSpec MSTimeSpec; |
105 | |
106 | #define ms_get_cur_time ortp_get_cur_time |
107 | |
108 | struct _MSList { |
109 | struct _MSList *next; |
110 | struct _MSList *prev; |
111 | void *data; |
112 | }; |
113 | |
114 | typedef struct _MSList MSList; |
115 | |
116 | |
117 | #define ms_list_next(elem) ((elem)->next) |
118 | |
119 | |
120 | typedef int (*MSCompareFunc)(const void *a, const void *b); |
121 | typedef void (*MSIterateFunc)(void *a); |
122 | typedef void (*MSIterate2Func)(void *a, void *b); |
123 | |
124 | #ifdef __cplusplus |
125 | extern "C" { |
126 | #endif |
127 | |
128 | MS2_PUBLIC void ms_thread_exit(void* ret_val); |
129 | MS2_PUBLIC MSList * ms_list_append(MSList *elem, void * data); |
130 | MS2_PUBLIC MSList *ms_list_append_link(MSList *elem, MSList *new_elem); |
131 | MS2_PUBLIC MSList * ms_list_prepend(MSList *elem, void * data); |
132 | MS2_PUBLIC MSList * ms_list_free(MSList *elem); |
133 | MS2_PUBLIC MSList * ms_list_concat(MSList *first, MSList *second); |
134 | MS2_PUBLIC MSList * ms_list_remove(MSList *first, void *data); |
135 | MS2_PUBLIC int ms_list_size(const MSList *first); |
136 | MS2_PUBLIC void ms_list_for_each(const MSList *list, MSIterateFunc iterate_func); |
137 | MS2_PUBLIC void ms_list_for_each2(const MSList *list, MSIterate2Func iterate_func, void *user_data); |
138 | MS2_PUBLIC MSList *ms_list_remove_link(MSList *list, MSList *elem); |
139 | MS2_PUBLIC MSList *ms_list_find(MSList *list, void *data); |
140 | MS2_PUBLIC MSList *ms_list_find_custom(MSList *list, MSCompareFunc compare_func, const void *user_data); |
141 | MS2_PUBLIC void * ms_list_nth_data(const MSList *list, int index); |
142 | MS2_PUBLIC int ms_list_position(const MSList *list, MSList *elem); |
143 | MS2_PUBLIC int ms_list_index(const MSList *list, void *data); |
144 | MS2_PUBLIC MSList *ms_list_insert_sorted(MSList *list, void *data, MSCompareFunc compare_func); |
145 | MS2_PUBLIC MSList *ms_list_insert(MSList *list, MSList *before, void *data); |
146 | MS2_PUBLIC MSList *ms_list_copy(const MSList *list); |
147 | |
148 | #undef MIN |
149 | #define MIN(a,b) ((a)>(b) ? (b) : (a)) |
150 | #undef MAX |
151 | #define MAX(a,b) ((a)>(b) ? (a) : (b)) |
152 | |
153 | /** |
154 | * @file mscommon.h |
155 | * @brief mediastreamer2 mscommon.h include file |
156 | * |
157 | * This file provide the API needed to initialize |
158 | * and reset the mediastreamer2 library. |
159 | * |
160 | */ |
161 | |
162 | /** |
163 | * @defgroup mediastreamer2_init Init API - manage mediastreamer2 library. |
164 | * @ingroup mediastreamer2_api |
165 | * @{ |
166 | */ |
167 | |
168 | |
169 | /** |
170 | * Helper macro for backward compatibility. |
171 | * Use ms_base_init() and ms_voip_init() instead. |
172 | */ |
173 | #define ms_init() ms_base_init(), ms_voip_init(), ms_plugins_init() |
174 | |
175 | /** |
176 | * Helper macro for backward compatibility. |
177 | * Use ms_base_exit() and ms_voip_exit() instead. |
178 | */ |
179 | #define ms_exit() ms_voip_exit(), ms_base_exit() |
180 | |
181 | |
182 | /** |
183 | * Initialize the mediastreamer2 base library. |
184 | * |
185 | * This must be called once before calling any other API. |
186 | */ |
187 | MS2_PUBLIC void ms_base_init(void); |
188 | |
189 | /** |
190 | * Initialize the mediastreamer2 VoIP library. |
191 | * |
192 | * This must be called one before calling any other API. |
193 | */ |
194 | MS2_PUBLIC void ms_voip_init(void); |
195 | |
196 | /** |
197 | * Load the plugins from the default plugin directory. |
198 | * |
199 | * This is just a wrapper around ms_load_plugins(). |
200 | * This must be called after ms_base_init() and after ms_voip_init(). |
201 | */ |
202 | MS2_PUBLIC void ms_plugins_init(void); |
203 | |
204 | /** |
205 | * Set the directory from where the plugins are to be loaded when calling ms_plugins_init(). |
206 | * @param[in] path The path to the plugins directory. |
207 | */ |
208 | MS2_PUBLIC void ms_set_plugins_dir(const char *path); |
209 | |
210 | /** |
211 | * Load plugins from a specific directory. |
212 | * This method basically loads all libraries in the specified directory and attempts to call a C function called |
213 | * \<libraryname\>_init. For example if a library 'libdummy.so' or 'libdummy.dll' is found, then the loader tries to locate |
214 | * a C function called 'libdummy_init()' and calls it if it exists. |
215 | * ms_load_plugins() can be used to load non-mediastreamer2 plugins as it does not expect mediastreamer2 specific entry points. |
216 | * |
217 | * @param directory A directory where plugins library are available. |
218 | * |
219 | * Returns: >0 if successfull, 0 if not plugins loaded, -1 otherwise. |
220 | */ |
221 | MS2_PUBLIC int ms_load_plugins(const char *directory); |
222 | |
223 | /** |
224 | * Release resource allocated in the mediastreamer2 base library. |
225 | * |
226 | * This must be called once before closing program. |
227 | */ |
228 | MS2_PUBLIC void ms_base_exit(void); |
229 | |
230 | /** |
231 | * Release resource allocated in the mediastreamer2 VoIP library. |
232 | * |
233 | * This must be called once before closing program. |
234 | */ |
235 | MS2_PUBLIC void ms_voip_exit(void); |
236 | |
237 | struct _MSSndCardDesc; |
238 | |
239 | MS2_PUBLIC void ms_sleep(int seconds); |
240 | |
241 | MS2_PUBLIC void ms_usleep(uint64_t usec); |
242 | |
243 | /** |
244 | * The max payload size allowed. |
245 | * Filters that generate data that can be sent through RTP should make packets |
246 | * whose size is below ms_get_payload_max_size(). |
247 | * The default value is 1440 computed as the standard internet MTU minus IPv6 header, |
248 | * UDP header and RTP header. As IPV4 header is smaller than IPv6 header, this |
249 | * value works for both. |
250 | * |
251 | **/ |
252 | MS2_PUBLIC int ms_get_payload_max_size(); |
253 | |
254 | MS2_PUBLIC void ms_set_payload_max_size(int size); |
255 | |
256 | /** |
257 | * Returns the network Max Transmission Unit to reach destination_host. |
258 | * This will attempt to send one or more big packets to destination_host, to a random port. |
259 | * Those packets are filled with zeroes. |
260 | **/ |
261 | MS2_PUBLIC int ms_discover_mtu(const char *destination_host); |
262 | |
263 | /** |
264 | * Set mediastreamer default mtu, used to compute the default RTP max payload size. |
265 | * This function will call ms_set_payload_max_size(mtu-[ipv6 header size]). |
266 | **/ |
267 | MS2_PUBLIC void ms_set_mtu(int mtu); |
268 | |
269 | |
270 | /** |
271 | * Get mediastreamer default mtu, used to compute the default RTP max payload size. |
272 | **/ |
273 | MS2_PUBLIC int ms_get_mtu(void); |
274 | |
275 | /** |
276 | * Declare how many cpu (cores) are available on the platform |
277 | */ |
278 | MS2_PUBLIC void ms_set_cpu_count(unsigned int c); |
279 | |
280 | MS2_PUBLIC unsigned int ms_get_cpu_count(); |
281 | |
282 | /** @} */ |
283 | |
284 | #ifdef __cplusplus |
285 | } |
286 | #endif |
287 | |
288 | #ifdef MS2_INTERNAL |
289 | # ifdef HAVE_CONFIG_H |
290 | # include "mediastreamer-config.h" /*necessary to know if ENABLE_NLS is there*/ |
291 | # endif |
292 | |
293 | #ifdef WIN32 |
294 | #include <malloc.h> //for alloca |
295 | #ifdef _MSC_VER |
296 | #define alloca _alloca |
297 | #endif |
298 | #endif |
299 | |
300 | # if defined(ENABLE_NLS) |
301 | # include <libintl.h> |
302 | # define _(String) dgettext (GETTEXT_PACKAGE, String) |
303 | # else |
304 | # define _(String) (String) |
305 | # endif // ENABLE_NLS |
306 | #define N_(String) (String) |
307 | #endif // MS2_INTERNAL |
308 | |
309 | #ifdef ANDROID |
310 | #include "mediastreamer2/msjava.h" |
311 | #endif |
312 | #endif |
313 | |
314 | |