| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#ifndef _iaxclient_lib_h |
| 17 |
#define _iaxclient_lib_h |
| 18 |
|
| 19 |
#ifdef __cplusplus |
| 20 |
extern "C" { |
| 21 |
#endif |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
#ifdef HAVE_CONFIG_H |
| 28 |
#include "config.h" |
| 29 |
#endif |
| 30 |
|
| 31 |
#include <stdio.h> |
| 32 |
#include <string.h> |
| 33 |
|
| 34 |
#if defined(WIN32) || defined(_WIN32_WCE) |
| 35 |
#include "winpoop.h" |
| 36 |
#if !defined(_WIN32_WCE) |
| 37 |
#include <process.h> |
| 38 |
#endif |
| 39 |
#include <stddef.h> |
| 40 |
#include <time.h> |
| 41 |
|
| 42 |
#else |
| 43 |
#include <sys/types.h> |
| 44 |
#include <sys/socket.h> |
| 45 |
#include <netinet/in.h> |
| 46 |
#include <sys/time.h> |
| 47 |
#include <pthread.h> |
| 48 |
#endif |
| 49 |
|
| 50 |
#ifdef USE_FFMPEG |
| 51 |
|
| 52 |
#include "codec_ffmpeg.h" |
| 53 |
#endif |
| 54 |
|
| 55 |
#include <stdlib.h> |
| 56 |
#include <math.h> |
| 57 |
#include "spandsp/plc.h" |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
#if defined(WIN32) || defined(_WIN32_WCE) |
| 63 |
#define THREAD HANDLE |
| 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 |
| 70 |
#define THREADJOIN(t) |
| 71 |
|
| 72 |
|
| 73 |
#ifndef _WIN32_WINNT |
| 74 |
extern WINBASEAPI BOOL WINAPI TryEnterCriticalSection( LPCRITICAL_SECTION lpCriticalSection ); |
| 75 |
#endif |
| 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) |
| 82 |
|
| 83 |
#else |
| 84 |
#define THREAD pthread_t |
| 85 |
#define THREADID unsigned |
| 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) |
| 98 |
#endif |
| 99 |
|
| 100 |
#ifdef MACOSX |
| 101 |
#include <mach/mach_init.h> |
| 102 |
#include <mach/thread_policy.h> |
| 103 |
#include <sched.h> |
| 104 |
#include <sys/sysctl.h> |
| 105 |
#endif |
| 106 |
|
| 107 |
#define MAXARGS 10 |
| 108 |
#define MAXARG 256 |
| 109 |
#define MAX_SESSIONS 4 |
| 110 |
#define OUT_INTERVAL 20 |
| 111 |
|
| 112 |
|
| 113 |
#define IAXC_CALL_TIMEOUT 30000 |
| 114 |
|
| 115 |
|
| 116 |
void os_init(void); |
| 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); |
| 121 |
|
| 122 |
#include "iaxclient.h" |
| 123 |
|
| 124 |
struct iaxc_audio_driver { |
| 125 |
|
| 126 |
char *name; |
| 127 |
struct iaxc_audio_device *devices; |
| 128 |
int nDevices; |
| 129 |
void *priv; |
| 130 |
|
| 131 |
|
| 132 |
int (*initialize)(struct iaxc_audio_driver *d, int sample_rate); |
| 133 |
int (*destroy)(struct iaxc_audio_driver *d); |
| 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); |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 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); |
| 146 |
|
| 147 |
|
| 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); |
| 152 |
|
| 153 |
|
| 154 |
int (*play_sound)(struct iaxc_sound *s, int ring); |
| 155 |
int (*stop_sound)(int id); |
| 156 |
|
| 157 |
|
| 158 |
int (*mic_boost_get)(struct iaxc_audio_driver *d ) ; |
| 159 |
int (*mic_boost_set)(struct iaxc_audio_driver *d, int enable); |
| 160 |
}; |
| 161 |
|
| 162 |
struct iaxc_audio_codec { |
| 163 |
char name[256]; |
| 164 |
int format; |
| 165 |
int minimum_frame_size; |
| 166 |
void *encstate; |
| 167 |
void *decstate; |
| 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); |
| 171 |
}; |
| 172 |
|
| 173 |
#define MAX_TRUNK_LEN (1<<16) |
| 174 |
#define MAX_NO_SLICES 32 |
| 175 |
|
| 176 |
struct slice_set_t |
| 177 |
{ |
| 178 |
int num_slices; |
| 179 |
int key_frame; |
| 180 |
int size[MAX_NO_SLICES]; |
| 181 |
char data[MAX_NO_SLICES][MAX_TRUNK_LEN]; |
| 182 |
}; |
| 183 |
|
| 184 |
struct iaxc_video_codec { |
| 185 |
char name[256]; |
| 186 |
int format; |
| 187 |
int width; |
| 188 |
int height; |
| 189 |
int framerate; |
| 190 |
int bitrate; |
| 191 |
int fragsize; |
| 192 |
int params_changed; |
| 193 |
void *encstate; |
| 194 |
void *decstate; |
| 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); |
| 201 |
}; |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
struct iaxc_call { |
| 206 |
|
| 207 |
struct iaxc_audio_codec *encoder; |
| 208 |
struct iaxc_audio_codec *decoder; |
| 209 |
struct iaxc_video_codec *vencoder; |
| 210 |
struct iaxc_video_codec *vdecoder; |
| 211 |
int vformat; |
| 212 |
|
| 213 |
|
| 214 |
int state; |
| 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]; |
| 219 |
|
| 220 |
|
| 221 |
char callerid_name[IAXC_EVENT_BUFSIZ]; |
| 222 |
char callerid_number[IAXC_EVENT_BUFSIZ]; |
| 223 |
|
| 224 |
|
| 225 |
struct timeval last_activity; |
| 226 |
struct timeval last_ping; |
| 227 |
|
| 228 |
|
| 229 |
int format; |
| 230 |
|
| 231 |
|
| 232 |
int tx_silent; |
| 233 |
|
| 234 |
struct iax_session *session; |
| 235 |
}; |
| 236 |
|
| 237 |
#include "audio_encode.h" |
| 238 |
|
| 239 |
#ifdef AUDIO_PA |
| 240 |
#include "audio_portaudio.h" |
| 241 |
#endif |
| 242 |
|
| 243 |
#include "audio_file.h" |
| 244 |
|
| 245 |
extern int iaxci_audio_output_mode; |
| 246 |
|
| 247 |
int iaxci_post_event_callback(iaxc_event e); |
| 248 |
|
| 249 |
|
| 250 |
void iaxci_post_event(iaxc_event e); |
| 251 |
|
| 252 |
|
| 253 |
extern void * post_event_handle; |
| 254 |
extern int post_event_id; |
| 255 |
|
| 256 |
|
| 257 |
extern int iaxci_prioboostbegin(void); |
| 258 |
extern int iaxci_prioboostend(void); |
| 259 |
|
| 260 |
long iaxci_usecdiff(struct timeval *t0, struct timeval *t1); |
| 261 |
long iaxci_msecdiff(struct timeval *t0, struct timeval *t1); |
| 262 |
|
| 263 |
#ifdef __cplusplus |
| 264 |
} |
| 265 |
#endif |
| 266 |
#endif |