summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/jabber/jingle/libjingle/talk/third_party/ortp/rtpport.h
blob: 65e48530c5646b72190c4f0c0a6fa367fb0ae0b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
/*
  The oRTP LinPhone RTP library intends to provide basics for a RTP stack.
  Copyright (C) 2001  Simon MORLAT simon.morlat@linphone.org

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/


/* this file is responsible of the portability of the stack */

#ifndef RTPPORT_H
#define RTPPORT_H

#ifdef UGLIB_H
#define HAVE_GLIB
#endif

#ifndef _WIN32	/* do not include ortp-config.h when we are on win32 */
#	ifdef _ORTP_SOURCE
#		include <ortp-config.h>
#	else
#		include <ortp-config.h>
#	endif
#else
	#include "ortp-config-win32.h"
#endif

#define INT_TO_POINTER(truc)	((gpointer)(long)(truc))
#define POINTER_TO_INT(truc)	((int)(long)(truc))

/* defines things that should be defined when we have not glib */
#ifndef HAVE_GLIB  

#include <errno.h>
#include <sys/types.h>
#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif

/* integer types */
typedef  uint64_t guint64;
typedef  uint16_t guint16;
typedef  uint32_t guint32;
typedef  signed short gint16;
typedef  int32_t gint32;
typedef  unsigned int guint;
typedef  int gint;
typedef  char gchar;
typedef  unsigned char guchar;
typedef  unsigned char guint8;
typedef  void* gpointer;
typedef int gboolean;
typedef double gdouble;
typedef float gfloat;

#define TRUE 1
#define FALSE 0


/*misc*/
#define g_return_if_fail(expr) if (!(expr)) {printf("%s:%i- assertion" #expr "failed\n",__FILE__,__LINE__); return;}
#define g_return_val_if_fail(expr,ret) if (!(expr)) {printf("%s:%i- assertion" #expr "failed\n",__FILE__,__LINE__); return (ret);}

#include <unistd.h>
#include <stdio.h>
#include <stdarg.h>

typedef enum {
	/* GLib log levels */
  G_LOG_LEVEL_ERROR             = 1 << 2,       /* always fatal */
  G_LOG_LEVEL_CRITICAL          = 1 << 3,
  G_LOG_LEVEL_WARNING           = 1 << 4,
  G_LOG_LEVEL_MESSAGE           = 1 << 5,
  G_LOG_LEVEL_MASK              = ~0

} GLogLevelFlags;

#ifndef G_LOG_DOMAIN
#define G_LOG_DOMAIN ((const gchar*)"")
#endif
#ifdef __cplusplus
extern "C" {
#endif

void g_log(const gchar *log_domain,GLogLevelFlags log_level,const gchar *format,...);
void g_logv(const gchar *log_domain,GLogLevelFlags log_level,const gchar *format,va_list args);
typedef void (*GLogFunc)  (const gchar *log_domain,
                                          GLogLevelFlags log_level,
                                           const gchar *message,
                                           gpointer user_data);
static inline void g_warning(const gchar *fmt,...)
{
  va_list args;
  va_start (args, fmt);
  g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, fmt, args);
  va_end (args);
}
static inline void g_error(const gchar *fmt,...)
{
  va_list args;
  va_start (args, fmt);
  g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, fmt, args);
  va_end (args);
}
static inline void g_message(const gchar *fmt,...)
{
  va_list args;
  va_start (args, fmt);
  g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, fmt, args);
  va_end (args);
}
/* in order to simplify, domain is ignored when using the folowing function, ie all logs will go through your handler
whatever the domain is */
void g_log_set_handler(const gchar *domain, GLogLevelFlags levels, GLogFunc func, gpointer ud);

#ifdef __cplusplus
}
#endif

#endif  /* HAVE_GLIB */


#if defined(TIME_WITH_SYS_TIME)
#include <time.h>
#include <sys/time.h>
#elif defined(HAVE_SYS_TIME_H)
#include <sys/time.h>
#endif


#ifdef HAVE_GLIB

#ifndef UGLIB_H
#include <glib.h>
#endif
#include <string.h>


#else /* not HAVE_GLIB */
/* things that in glib, but should only be defined when we are not in the HPUX kernel. */
#include <stdlib.h>
#include <pthread.h>
#include <sched.h>
#include <string.h>

#ifdef ENABLE_MEMCHECK
extern gint ortp_allocations;
#endif

/* memory allocation functions */
static inline void * g_malloc(int sz) 
{
	void *p=malloc(sz);
	if (p==NULL) {
		printf("g_malloc: Failed to allocate %i bytes: %s.\n",sz,strerror(errno));
		abort();
	}
#ifdef ENABLE_MEMCHECK
	ortp_allocations++;
#endif
	return p;
}

static inline void * g_malloc0(int sz) 
{
	void *p=malloc(sz);
	if (p==NULL) {
		printf("g_malloc: Failed to allocate %i bytes: %s.\n",sz,strerror(errno));
		abort();
	}
	memset(p,0,sz);
#ifdef ENABLE_MEMCHECK
	ortp_allocations++;
#endif
	return p;
}

#define g_new(type,count)   (type *)g_malloc(sizeof(type)*(count))
#define g_new0(type, count)	(type *)g_malloc0(sizeof(type)*(count))
#define g_realloc(p,sz) realloc((p),(sz))
static inline void g_free(void *p)
{
#ifdef ENABLE_MEMCHECK
	ortp_allocations--;
#endif
	free(p);
}

#define g_strdup(machin)	strdup(machin)

typedef pthread_mutex_t GMutex;
static inline GMutex * g_mutex_new()
{
	pthread_mutex_t *mutex=g_new(pthread_mutex_t,1);
	pthread_mutex_init(mutex,NULL);
	return mutex;
}
typedef enum
{
  G_THREAD_PRIORITY_LOW,
  G_THREAD_PRIORITY_NORMAL,
  G_THREAD_PRIORITY_HIGH,
  G_THREAD_PRIORITY_URGENT
} GThreadPriority;
typedef pthread_t GThread;
typedef gpointer (*GThreadFunc)(gpointer data);
static inline GThread *g_thread_create(GThreadFunc func, gpointer data, gboolean joinable, void **error){
	GThread *thread=g_new(GThread,1);
	pthread_create(thread,NULL,func,data);
	return thread;
}

static inline void g_thread_join(GThread *thread){
	pthread_join(*thread,NULL);
	g_free(thread);
}

static inline void g_thread_set_priority(GThread *thread,GThreadPriority prio){
	if (prio>G_THREAD_PRIORITY_NORMAL){
		/* this is unsupported on HPUX */
		/*
		struct sched_param param;
		param.sched_priority=1;
		sched_setscheduler(*thread,SCHED_RR,&param);
		*/
	}
}

#define g_mutex_lock(mutex)	  pthread_mutex_lock((mutex))
#define g_mutex_unlock(mutex)  pthread_mutex_unlock((mutex))
#define g_mutex_free(mutex)		pthread_mutex_destroy((mutex));g_free((mutex))

typedef pthread_cond_t GCond;
static inline GCond * g_cond_new()
{
	pthread_cond_t *cond=g_new(pthread_cond_t,1);
	pthread_cond_init(cond,NULL);
	return cond;
}
#define g_cond_wait(cond,mutex)	pthread_cond_wait((cond),(mutex))
#define g_cond_signal(cond)		pthread_cond_signal((cond))
#define g_cond_broadcast(cond)	pthread_cond_broadcast((cond))
#define g_cond_free(cond)		pthread_cond_destroy((cond)); g_free((cond))

#define g_thread_init(vtable)
#define g_thread_supported()	(1)

#endif /* HAVE_GLIB */


#ifndef RTP_DEBUG
#define ortp_debug(...)	
#else
#define ortp_debug	g_message
#endif

#ifdef _WIN32
extern char *getSocketError();
#define getSocketErrorCode()	WSAGetLastError ()
#else
#define getSocketError() strerror(errno)
#define getSocketErrorCode() (errno)
#endif

#ifdef UGLIB_H
#undef HAVE_GLIB
#endif

#undef MIN
#define MIN(a,b) (((a)>(b)) ? (b) : (a))
#undef MAX
#define MAX(a,b) (((a)>(b)) ? (a) : (b))

typedef struct _dwsplit_t{
#ifdef WORDS_BIGENDIAN
	guint16 hi;
	guint16 lo;
#else
	guint16 lo;
	guint16 hi;
#endif
} dwsplit_t;

typedef union{
	dwsplit_t split;
	guint32 one;
} poly32_t;

#ifdef WORDS_BIGENDIAN
#define hton24(x) (x)
#else
#define hton24(x) ((( (x) & 0x00ff0000) >>16) | (( (x) & 0x000000ff) <<16) | ( (x) & 0x0000ff00) )
#endif
#define ntoh24(x) hton24(x)

#endif /*RTPPORT_H*/