00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef _iaxclient_lib_h
00017 #define _iaxclient_lib_h
00018
00019 #ifdef __cplusplus
00020 extern "C" {
00021 #endif
00022
00023
00024
00025
00026
00027 #ifdef HAVE_CONFIG_H
00028 #include "config.h"
00029 #endif
00030
00031 #include <stdio.h>
00032 #include <string.h>
00033
00034 #if defined(WIN32) || defined(_WIN32_WCE)
00035 void gettimeofday(struct timeval *tv, void *tz);
00036 #include <winsock.h>
00037 #if !defined(_WIN32_WCE)
00038 #include <process.h>
00039 #endif
00040 #include <stddef.h>
00041 #include <time.h>
00042
00043 #else
00044 #include <sys/types.h>
00045 #include <sys/socket.h>
00046 #include <netinet/in.h>
00047 #include <sys/time.h>
00048 #include <pthread.h>
00049 #endif
00050
00051 #ifdef USE_FFMPEG
00052
00053 #include "codec_ffmpeg.h"
00054 #endif
00055
00056 #include <stdlib.h>
00057 #include <math.h>
00058 #include "spandsp/plc.h"
00059
00060
00061
00062
00063 #if defined(WIN32) || defined(_WIN32_WCE)
00064 #define THREAD HANDLE
00065 #define THREADID unsigned
00066 #define THREADCREATE(func, args, thread, id) \
00067 (thread = (HANDLE)_beginthreadex(NULL, 0, func, (PVOID)args, 0, &id))
00068 #define THREADCREATE_ERROR NULL
00069 #define THREADFUNCDECL(func) unsigned __stdcall func(PVOID args)
00070 #define THREADFUNCRET(r) int r = 0
00071 #define THREADJOIN(t)
00072
00073
00074 #define MUTEX CRITICAL_SECTION
00075 #define MUTEXINIT(m) InitializeCriticalSection(m)
00076 #define MUTEXLOCK(m) EnterCriticalSection(m)
00077 #define MUTEXTRYLOCK(m) (!TryEnterCriticalSection(m))
00078 #define MUTEXUNLOCK(m) LeaveCriticalSection(m)
00079 #define MUTEXDESTROY(m) DeleteCriticalSection(m)
00080
00081 #else
00082 #define THREAD pthread_t
00083 #define THREADID unsigned
00084 #define THREADCREATE(func, args, thread, id) \
00085 pthread_create(&thread, NULL, func, args)
00086 #define THREADCREATE_ERROR -1
00087 #define THREADFUNCDECL(func) void * func(void *args)
00088 #define THREADFUNCRET(r) void * r = 0
00089 #define THREADJOIN(t) pthread_join(t, 0)
00090 #define MUTEX pthread_mutex_t
00091 #define MUTEXINIT(m) pthread_mutex_init(m, NULL) //TODO: check error
00092 #define MUTEXLOCK(m) pthread_mutex_lock(m)
00093 #define MUTEXTRYLOCK(m) pthread_mutex_trylock(m)
00094 #define MUTEXUNLOCK(m) pthread_mutex_unlock(m)
00095 #define MUTEXDESTROY(m) pthread_mutex_destroy(m)
00096 #endif
00097
00098 #ifdef MACOSX
00099 #include <mach/mach_init.h>
00100 #include <mach/thread_policy.h>
00101 #include <sched.h>
00102 #include <sys/sysctl.h>
00103 #endif
00104
00105 #define MAXARGS 10
00106 #define MAXARG 256
00107 #define MAX_SESSIONS 4
00108 #define OUT_INTERVAL 20
00109
00110
00111 #define IAXC_CALL_TIMEOUT 30000
00112
00113
00114 void os_init(void);
00115 void iaxci_usermsg(int type, const char *fmt, ...);
00116 void iaxci_do_levels_callback(float input, float output);
00117 void iaxci_do_audio_callback(int callNo, unsigned int ts, int remote,
00118 int encoded, int format, int size, unsigned char *data);
00119
00120 #include "iaxclient.h"
00121
00122 struct iaxc_audio_driver {
00123
00124 char *name;
00125 struct iaxc_audio_device *devices;
00126 int nDevices;
00127 void *priv;
00128
00129
00130 int (*initialize)(struct iaxc_audio_driver *d, int sample_rate);
00131 int (*destroy)(struct iaxc_audio_driver *d);
00132 int (*select_devices)(struct iaxc_audio_driver *d, int input, int output, int ring);
00133 int (*selected_devices)(struct iaxc_audio_driver *d, int *input, int *output, int *ring);
00134
00135
00136
00137
00138
00139
00140 int (*start)(struct iaxc_audio_driver *d);
00141 int (*stop)(struct iaxc_audio_driver *d);
00142 int (*output)(struct iaxc_audio_driver *d, void *samples, int nSamples);
00143 int (*input)(struct iaxc_audio_driver *d, void *samples, int *nSamples);
00144
00145
00146 float (*input_level_get)(struct iaxc_audio_driver *d);
00147 float (*output_level_get)(struct iaxc_audio_driver *d);
00148 int (*input_level_set)(struct iaxc_audio_driver *d, float level);
00149 int (*output_level_set)(struct iaxc_audio_driver *d, float level);
00150
00151
00152 int (*play_sound)(struct iaxc_sound *s, int ring);
00153 int (*stop_sound)(int id);
00154
00155
00156 int (*mic_boost_get)(struct iaxc_audio_driver *d ) ;
00157 int (*mic_boost_set)(struct iaxc_audio_driver *d, int enable);
00158 };
00159
00160 struct iaxc_audio_codec {
00161 char name[256];
00162 int format;
00163 int minimum_frame_size;
00164 void *encstate;
00165 void *decstate;
00166 int (*encode) ( struct iaxc_audio_codec *codec, int *inlen, short *in, int *outlen, unsigned char *out );
00167 int (*decode) ( struct iaxc_audio_codec *codec, int *inlen, unsigned char *in, int *outlen, short *out );
00168 void (*destroy) ( struct iaxc_audio_codec *codec);
00169 };
00170
00171 #define MAX_TRUNK_LEN (1<<16)
00172 #define MAX_NO_SLICES 32
00173
00174 struct slice_set_t
00175 {
00176 int num_slices;
00177 int key_frame;
00178 int size[MAX_NO_SLICES];
00179 char data[MAX_NO_SLICES][MAX_TRUNK_LEN];
00180 };
00181
00182 struct iaxc_video_codec {
00183 char name[256];
00184 int format;
00185 int width;
00186 int height;
00187 int framerate;
00188 int bitrate;
00189 int fragsize;
00190 int params_changed;
00191 void *encstate;
00192 void *decstate;
00193 struct iaxc_video_stats video_stats;
00194 int (*encode) ( struct iaxc_video_codec *codec, int inlen, char *in, struct slice_set_t *out );
00195 int (*decode) ( struct iaxc_video_codec *codec, int inlen, char *in, int *outlen, char *out );
00196 void (*destroy) ( struct iaxc_video_codec *codec);
00197 };
00198
00199
00200
00201 struct iaxc_call {
00202
00203 struct iaxc_audio_codec *encoder;
00204 struct iaxc_audio_codec *decoder;
00205 struct iaxc_video_codec *vencoder;
00206 struct iaxc_video_codec *vdecoder;
00207 int vformat;
00208
00209
00210 int state;
00211 char remote[IAXC_EVENT_BUFSIZ];
00212 char remote_name[IAXC_EVENT_BUFSIZ];
00213 char local[IAXC_EVENT_BUFSIZ];
00214 char local_context[IAXC_EVENT_BUFSIZ];
00215
00216
00217 char callerid_name[IAXC_EVENT_BUFSIZ];
00218 char callerid_number[IAXC_EVENT_BUFSIZ];
00219
00220
00221 struct timeval last_activity;
00222 struct timeval last_ping;
00223
00224
00225 int format;
00226
00227
00228 int tx_silent;
00229
00230 struct iax_session *session;
00231 };
00232
00233 extern int iaxci_audio_output_mode;
00234
00235 int iaxci_post_event_callback(iaxc_event e);
00236
00237
00238 void iaxci_post_event(iaxc_event e);
00239
00240
00241 extern void * post_event_handle;
00242 extern int post_event_id;
00243
00244
00245 extern int iaxci_prioboostbegin(void);
00246 extern int iaxci_prioboostend(void);
00247
00248 long iaxci_usecdiff(struct timeval *t0, struct timeval *t1);
00249 long iaxci_msecdiff(struct timeval *t0, struct timeval *t1);
00250
00251 #ifdef __cplusplus
00252 }
00253 #endif
00254 #endif