]> sjero.net Git - linphone/blob - linphone/mediastreamer2/include/mediastreamer2/mscommon.h
869feeff39f7306d2b873baeeb6dc700778b2bd5
[linphone] / linphone / mediastreamer2 / include / mediastreamer2 / mscommon.h
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/ortp.h>
23
24 #define ms_malloc       ortp_malloc
25 #define ms_malloc0      ortp_malloc0
26 #define ms_realloc      ortp_realloc
27 #define ms_new          ortp_new
28 #define ms_new0         ortp_new0
29 #define ms_free         ortp_free
30 #define ms_strdup       ortp_strdup
31 #define ms_strdup_printf        ortp_strdup_printf
32
33 #define ms_mutex_t              ortp_mutex_t
34 #define ms_mutex_init           ortp_mutex_init
35 #define ms_mutex_destroy        ortp_mutex_destroy
36 #define ms_mutex_lock           ortp_mutex_lock
37 #define ms_mutex_unlock         ortp_mutex_unlock
38
39 #define ms_cond_t               ortp_cond_t
40 #define ms_cond_init            ortp_cond_init
41 #define ms_cond_wait            ortp_cond_wait
42 #define ms_cond_signal          ortp_cond_signal
43 #define ms_cond_broadcast       ortp_cond_broadcast
44 #define ms_cond_destroy         ortp_cond_destroy
45
46 #ifdef WIN32
47 static inline void ms_debug(const char *fmt,...)
48 {
49   va_list args;
50   va_start (args, fmt);
51   ortp_logv(ORTP_DEBUG, fmt, args);
52   va_end (args);
53 }
54 #else
55 #ifdef DEBUG
56 static inline void ms_debug(const char *fmt,...)
57 {
58   va_list args;
59   va_start (args, fmt);
60   ortp_logv(ORTP_DEBUG, fmt, args);
61   va_end (args);
62 }
63 #else
64 #define ms_debug(...)
65 #endif  
66 #endif
67
68
69
70 #define ms_message      ortp_message
71 #define ms_warning      ortp_warning
72 #define ms_error        ortp_error
73 #define ms_fatal        ortp_fatal
74
75 #define ms_return_val_if_fail(_expr_,_ret_)\
76         if (!(_expr_)) { ms_error("assert "#_expr_ "failed"); return (_ret_);}
77
78 #define ms_return_if_fail(_expr_) \
79         if (!(_expr_)){ ms_error("assert "#_expr_ "failed"); return ;}
80
81 #define ms_thread_t             ortp_thread_t
82 #define ms_thread_create        ortp_thread_create
83 #define ms_thread_join          ortp_thread_join
84 #define ms_thread_exit          ortp_thread_exit
85
86 struct _MSList {
87         struct _MSList *next;
88         struct _MSList *prev;
89         void *data;
90 };
91
92 typedef struct _MSList MSList;
93
94
95 #define ms_list_next(elem) ((elem)->next)
96
97
98 #ifdef __cplusplus
99 extern "C"{
100 #endif
101
102 MSList * ms_list_append(MSList *elem, void * data);
103 MSList * ms_list_prepend(MSList *elem, void * data);
104 MSList * ms_list_free(MSList *elem);
105 MSList * ms_list_concat(MSList *first, MSList *second);
106 MSList * ms_list_remove(MSList *first, void *data);
107 int ms_list_size(const MSList *first);
108 void ms_list_for_each(const MSList *list, void (*func)(void *));
109 void ms_list_for_each2(const MSList *list, void (*func)(void *, void *), void *user_data);
110 MSList *ms_list_remove_link(MSList *list, MSList *elem);
111 MSList *ms_list_find(MSList *list, void *data);
112 MSList *ms_list_find_custom(MSList *list, int (*compare_func)(const void *, const void*), void *user_data);
113 void * ms_list_nth_data(const MSList *list, int index);
114 int ms_list_position(const MSList *list, MSList *elem);
115 int ms_list_index(const MSList *list, void *data);
116 MSList *ms_list_insert_sorted(MSList *list, void *data, int (*compare_func)(const void *, const void*));
117 MSList *ms_list_insert(MSList *list, MSList *before, void *data);
118 MSList *ms_list_copy(const MSList *list);
119
120 #undef MIN
121 #define MIN(a,b)        ((a)>(b) ? (b) : (a))
122 #undef MAX
123 #define MAX(a,b)        ((a)>(b) ? (a) : (b))
124
125 /**
126  * @file mscommon.h
127  * @brief mediastreamer2 mscommon.h include file
128  *
129  * This file provide the API needed to initialize
130  * and reset the mediastreamer2 library.
131  *
132  */
133
134 /**
135  * @defgroup mediastreamer2_init Init API - manage mediastreamer2 library.
136  * @ingroup mediastreamer2_api
137  * @{
138  */
139
140
141 /**
142  * Initialize the mediastreamer2 library.
143  *
144  * This must be called once before calling any other API.
145  */
146 void ms_init(void);
147
148 /**
149  * Load plugins from a specific directory.
150  * This method basically loads all libraries in the specified directory and attempts to call a C function called
151  * \<libraryname\>_init. For example if a library 'libdummy.so' or 'libdummy.dll' is found, then the loader tries to locate
152  * a C function called 'libdummy_init()' and calls it if it exists.
153  * ms_load_plugins() can be used to load non-mediastreamer2 plugins as it does not expect mediastreamer2 specific entry points.
154  *
155  * @param directory   A directory where plugins library are available.
156  *
157  * Returns: >0 if successfull, 0 if not plugins loaded, -1 otherwise.
158  */
159 int ms_load_plugins(const char *directory);
160
161 /**
162  * Release resource allocated in the mediastreamer2 library.
163  *
164  * This must be called once before closing program.
165  */
166 void ms_exit(void);
167
168 struct _MSSndCardDesc;
169
170 void ms_sleep(int seconds);
171
172 /**
173  * The max payload size allowed.
174  * Filters that generate data that can be sent through RTP should make packets
175  * whose size is below ms_get_payload_max_size().
176  * The default value is 1440 computed as the standart internet MTU minus IPv6 header,
177  * UDP header and RTP header. As IPV4 header is smaller than IPv6 header, this 
178  * value works for both.
179  * 
180 **/
181 int ms_get_payload_max_size();
182
183 void ms_set_payload_max_size(int size);
184
185 /**
186  * Returns the network Max Transmission Unit to reach destination_host.
187  * This will attempt to send one or more big packets to destination_host, to a random port.
188  * Those packets are filled with zeroes.
189 **/
190 int ms_discover_mtu(const char *destination_host);
191
192 /**
193  * Set mediastreamer default mtu, used to compute the default RTP max payload size.
194  * This function will call ms_set_payload_max_size(mtu-[ipv6 header size]).
195 **/
196 void ms_set_mtu(int mtu);
197
198 /** @} */
199
200 #ifdef __cplusplus
201 }
202 #endif
203
204 #endif