2 * iaxclient: a cross-platform IAX softphone library
5 * Copyright (C) 2003-2006, Horizon Wimba, Inc.
6 * Copyright (C) 2007, Wimba, Inc.
9 * Steve Kann <stevek@stevek.com>
10 * Michael Van Donselaar <mvand@vandonselaar.org>
11 * Shawn Lawrence <shawn.lawrence@terracecomm.com>
13 * This program is free software, distributed under the terms of
14 * the GNU Lesser (Library) General Public License.
16 #ifndef _iaxclient_lib_h
17 #define _iaxclient_lib_h
24 /* This is the internal include file for IAXCLIENT -- externally
25 * accessible APIs should be declared in iaxclient.h */
34 #if defined(WIN32) || defined(_WIN32_WCE)
36 #if !defined(_WIN32_WCE)
43 #include <sys/types.h>
44 #include <sys/socket.h>
45 #include <netinet/in.h>
51 // To access to check_ff function
52 #include "codec_ffmpeg.h"
57 #include "spandsp/plc.h"
61 /* os-dependent macros, etc */
62 #if defined(WIN32) || defined(_WIN32_WCE)
64 #define THREADID unsigned
65 #define THREADCREATE(func, args, thread, id) \
66 (thread = (HANDLE)_beginthreadex(NULL, 0, func, (PVOID)args, 0, &id))
67 #define THREADCREATE_ERROR NULL
68 #define THREADFUNCDECL(func) unsigned __stdcall func(PVOID args)
69 #define THREADFUNCRET(r) int r = 0
71 /* causes deadlock with wx GUI on MSW */
72 /* #define THREADJOIN(t) WaitForSingleObject(t, INFINITE) */
74 extern WINBASEAPI BOOL WINAPI TryEnterCriticalSection( LPCRITICAL_SECTION lpCriticalSection );
76 #define MUTEX CRITICAL_SECTION
77 #define MUTEXINIT(m) InitializeCriticalSection(m)
78 #define MUTEXLOCK(m) EnterCriticalSection(m)
79 #define MUTEXTRYLOCK(m) (!TryEnterCriticalSection(m))
80 #define MUTEXUNLOCK(m) LeaveCriticalSection(m)
81 #define MUTEXDESTROY(m) DeleteCriticalSection(m)
84 #define THREAD pthread_t
85 #define THREADID unsigned /* unused for Posix Threads */
86 #define THREADCREATE(func, args, thread, id) \
87 pthread_create(&thread, NULL, func, args)
88 #define THREADCREATE_ERROR -1
89 #define THREADFUNCDECL(func) void * func(void *args)
90 #define THREADFUNCRET(r) void * r = 0
91 #define THREADJOIN(t) pthread_join(t, 0)
92 #define MUTEX pthread_mutex_t
93 #define MUTEXINIT(m) pthread_mutex_init(m, NULL) //TODO: check error
94 #define MUTEXLOCK(m) pthread_mutex_lock(m)
95 #define MUTEXTRYLOCK(m) pthread_mutex_trylock(m)
96 #define MUTEXUNLOCK(m) pthread_mutex_unlock(m)
97 #define MUTEXDESTROY(m) pthread_mutex_destroy(m)
101 #include <mach/mach_init.h>
102 #include <mach/thread_policy.h>
104 #include <sys/sysctl.h>
109 #define MAX_SESSIONS 4
110 #define OUT_INTERVAL 20
112 /* millisecond interval to time out calls */
113 #define IAXC_CALL_TIMEOUT 30000
117 void iaxci_usermsg(int type, const char *fmt, ...);
118 void iaxci_do_levels_callback(float input, float output);
119 void iaxci_do_audio_callback(int callNo, unsigned int ts, int remote,
120 int encoded, int format, int size, unsigned char *data);
122 #include "iaxclient.h"
124 struct iaxc_audio_driver {
126 char *name; /* driver name */
127 struct iaxc_audio_device *devices; /* list of devices */
128 int nDevices; /* count of devices */
129 void *priv; /* pointer to private data */
132 int (*initialize)(struct iaxc_audio_driver *d, int sample_rate);
133 int (*destroy)(struct iaxc_audio_driver *d); /* free resources */
134 int (*select_devices)(struct iaxc_audio_driver *d, int input, int output, int ring);
135 int (*selected_devices)(struct iaxc_audio_driver *d, int *input, int *output, int *ring);
142 int (*start)(struct iaxc_audio_driver *d);
143 int (*stop)(struct iaxc_audio_driver *d);
144 int (*output)(struct iaxc_audio_driver *d, void *samples, int nSamples);
145 int (*input)(struct iaxc_audio_driver *d, void *samples, int *nSamples);
148 float (*input_level_get)(struct iaxc_audio_driver *d);
149 float (*output_level_get)(struct iaxc_audio_driver *d);
150 int (*input_level_set)(struct iaxc_audio_driver *d, float level);
151 int (*output_level_set)(struct iaxc_audio_driver *d, float level);
154 int (*play_sound)(struct iaxc_sound *s, int ring);
155 int (*stop_sound)(int id);
158 int (*mic_boost_get)(struct iaxc_audio_driver *d ) ;
159 int (*mic_boost_set)(struct iaxc_audio_driver *d, int enable);
162 struct iaxc_audio_codec {
165 int minimum_frame_size;
168 int (*encode) ( struct iaxc_audio_codec *codec, int *inlen, short *in, int *outlen, unsigned char *out );
169 int (*decode) ( struct iaxc_audio_codec *codec, int *inlen, unsigned char *in, int *outlen, short *out );
170 void (*destroy) ( struct iaxc_audio_codec *codec);
173 #define MAX_TRUNK_LEN (1<<16)
174 #define MAX_NO_SLICES 32
180 int size[MAX_NO_SLICES];
181 char data[MAX_NO_SLICES][MAX_TRUNK_LEN];
184 struct iaxc_video_codec {
195 struct iaxc_video_stats video_stats;
196 int (*encode)(struct iaxc_video_codec * codec, int inlen,
197 const char * in, struct slice_set_t * out);
198 int (*decode)(struct iaxc_video_codec * codec, int inlen,
199 const char * in, int * outlen, char * out);
200 void (*destroy)(struct iaxc_video_codec * codec);
206 /* to be replaced with codec-structures, with codec-private data */
207 struct iaxc_audio_codec *encoder;
208 struct iaxc_audio_codec *decoder;
209 struct iaxc_video_codec *vencoder;
210 struct iaxc_video_codec *vdecoder;
213 /* the "state" of this call */
215 char remote[IAXC_EVENT_BUFSIZ];
216 char remote_name[IAXC_EVENT_BUFSIZ];
217 char local[IAXC_EVENT_BUFSIZ];
218 char local_context[IAXC_EVENT_BUFSIZ];
220 /* Outbound CallerID */
221 char callerid_name[IAXC_EVENT_BUFSIZ];
222 char callerid_number[IAXC_EVENT_BUFSIZ];
224 /* reset whenever we receive packets from remote */
225 struct timeval last_activity;
226 struct timeval last_ping;
228 /* our negotiated format */
231 /* we've sent a silent frame since the last audio frame */
234 struct iax_session *session;
237 #include "audio_encode.h"
240 #include "audio_portaudio.h"
243 #include "audio_file.h"
246 #include "audio_openal.h"
249 extern int iaxci_audio_output_mode;
251 int iaxci_post_event_callback(iaxc_event e);
253 /* post an event to the application */
254 void iaxci_post_event(iaxc_event e);
256 /* parameters for callback */
257 extern void * post_event_handle;
258 extern int post_event_id;
260 /* Priority boost support */
261 extern int iaxci_prioboostbegin(void);
262 extern int iaxci_prioboostend(void);
264 long iaxci_usecdiff(struct timeval *t0, struct timeval *t1);
265 long iaxci_msecdiff(struct timeval *t0, struct timeval *t1);