Main Page   Compound List   File List   Compound Members   File Members  

speakfree.h

Go to the documentation of this file.
00001 /*
00002 
00003             Speak Freely for Unix definitions
00004 
00005 */
00006 
00007 #define RTP_SUPPORT
00008 #define PUSH_TO_TALK
00009 #define FACE_SET_GEOMETRY
00010 #define NAT_LAUNCH
00011 
00012 #if defined(sun) && !defined(Solaris)
00013 #define BSD_like
00014 #endif
00015 
00016 #ifdef __FreeBSD__
00017 #define BSD_like
00018 #endif
00019 
00020 #ifdef sgi
00021 #define _BSD_SIGNALS
00022 #endif
00023 
00024 #include <stdio.h>
00025 #include <stdlib.h>
00026 #include <fcntl.h>
00027 #include <assert.h>
00028 #include <string.h>
00029 #include <ctype.h>
00030 #include <time.h>
00031 #ifdef PUSH_TO_TALK
00032 #include <curses.h>
00033 #endif
00034 #include <sys/types.h>
00035 #include <sys/time.h>
00036 #include <sys/wait.h>
00037 #include <sys/stat.h>
00038 #include <unistd.h>
00039 #ifdef BSD_like
00040 #include <sys/timeb.h>
00041 #endif
00042 #ifdef Solaris
00043 #include <sys/systeminfo.h>
00044 #endif
00045 #ifdef sgi
00046 #include <dmedia/audio.h>
00047 #include <limits.h>
00048 #endif
00049 #include <errno.h>
00050 #include <signal.h>
00051 #include <sys/socket.h>
00052 #include <netinet/in.h>
00053 #include <arpa/inet.h>
00054 #include <netdb.h>
00055 #ifdef LINUX_FPU_FIX
00056 #include <fpu_control.h>
00057 #endif
00058 
00059 #define NOLONGLONG
00060 #include "types.h"
00061 
00062 #ifndef NOCRYPTO
00063 #define CRYPTO
00064 #endif
00065 
00066 #ifdef CRYPTO
00067 #include "aes.h"
00068 #define AES_BLOCK_SIZE    BLOCK_SIZE
00069 #include "blowfish.h"
00070 #include "des.h"
00071 #include "des_sf.h"
00072 #include "idea.h"
00073 #endif
00074 
00075 #include "ulaw2linear.h"
00076 #include "adpcm-u.h"
00077 #include "celp.h"
00078 #include "lpc.h"
00079 #include "gsm.h"
00080 #include "lpc10.h"
00081 #include "md5.h"
00082 #include "rtp.h"
00083 #include "rtpacket.h"
00084 #include "audio_descr.h"
00085 #include "common.h"
00086 
00087 #define SAMPLE_RATE     8000          /* Audio sample rate in sound packets */
00088 
00089 #define TINY_PACKETS    512           /* Ideal tiny packet size */
00090 
00091 #define FACEDIR "/tmp/"               /* Directory where you'd like to keep face files */
00092 
00093 #define BUFL    8000
00094 
00095 #define LONG    long
00096 
00097 /*  AUDIO_DEVICE_FILE enables code for platforms which support
00098     audio via one or more device files, such as /dev/audio.
00099     Platforms which do not implement audio in this manner,
00100     for example SGI and Hewlett-Packard Unix workstations,
00101     should #undef AUDIO_DEVICE_FILE in the lines below.  */
00102 
00103 #define AUDIO_DEVICE_FILE
00104 /* Platform-specific undefines for non-device-file audio. */
00105 #ifdef sgi
00106 #undef AUDIO_DEVICE_FILE
00107 #endif
00108 #ifdef HEWLETT_PACKARD
00109 #undef AUDIO_DEVICE_FILE
00110 #endif
00111 #ifdef LINUX_ALSA
00112 #undef AUDIO_DEVICE_FILE
00113 #endif
00114 
00115 /* Binary block and signal functions for fanatic ex-BSD platforms. */
00116 
00117 #ifdef Solaris
00118 #define bcmp(a, b, n)   memcmp(a, b, n)
00119 #define bcopy(a, b, n)  memmove(b, a, n)
00120 #define bzero(a, n)     memset(a, 0, n)
00121 
00122 typedef void (*signalFUNC)(int);
00123 #define signal(a, b)    sigset(a, (signalFUNC) b)
00124 #define signalFUNCreturn (signalFUNC)
00125 #endif
00126 
00127 #ifndef signalFUNCreturn
00128 #define signalFUNCreturn
00129 #endif
00130 
00131 /* Auto-configure multicast support */
00132 
00133 #ifdef IP_ADD_MEMBERSHIP
00134 #define MULTICAST
00135 #endif
00136 
00137 #define LPC_FRAME_SIZE      160       /* Frame size for LPC compression */
00138 
00139 struct soundbuf {
00140         LONG compression;
00141         char sendinghost[16];
00142         struct {
00143                 LONG buffer_len;
00144                 char buffer_val[BUFL];
00145         } buffer;
00146 };
00147 typedef struct soundbuf soundbuf;
00148 
00149 struct sbhead {
00150         LONG compression;
00151         char sendinghost[16];
00152         struct {
00153                 LONG buffer_len;
00154                 char buffer_val[16];
00155         } buffer;
00156 };
00157 typedef struct sbhead sbhead;
00158 
00159 #ifndef TRUE
00160 #define TRUE    1
00161 #endif
00162 #ifndef FALSE
00163 #define FALSE   0
00164 #endif
00165 
00166 #define V       (void)
00167 
00168 #define ELEMENTS(array) (sizeof(array)/sizeof((array)[0]))
00169 
00170 /* Packet mode flags. */
00171 
00172 #define fComp2X     1                 /* Simple 2 to 1 compression */
00173 #define fDebug      2                 /* Debug mode */
00174 #define fSetDest    4                 /* Set sound output destination */
00175 #define fDestSpkr   0                 /* Destination: speaker */
00176 #define fDestJack   8                 /* Destination: audio output jack */
00177 #define fLoopBack   16                /* Loopback packets for testing */
00178 #define fCompGSM    32                /* GSM compression */
00179 #define fEncDES     64                /* DES encrypted */
00180 #define fEncOTP     128               /* One-time pad encrypted */
00181 #define fEncIDEA    256               /* IDEA encrypted */
00182 #define fCompADPCM  512               /* ADPCM compressed */
00183 #define fEncPGP     1024              /* PGP encrypted */
00184 #define fKeyPGP     2048              /* Buffer contains PGP-encrypted session key */
00185 #define fCompLPC    4096              /* LPC compressed */
00186 #define fFaceData   8192              /* Request/reply for face data */
00187 #define fFaceOffer  16384             /* Offer face image to remote host */
00188 #define fCompVOX    0x10000           /* VOX compressed */
00189 #define fCompLPC10  0x20000           /* LPC-10 compressed */
00190 #define fCompRobust 0x40000           /* Robust packet replication ? */
00191 #define fEncBF      0x80000           /* Blowfish encrypted */
00192 #define fCompCELP   0x100000          /* CELP compressed */
00193 #define fEncAES     0x200000          /* AES encrypted */
00194 #define fProtocol   0x40000000        /* Speak Freely protocol flag */
00195 
00196 /* Special definitions for face data packets (which have fFaceData set). */
00197 
00198 #define faceRequest 1                 /* Face data request */
00199 #define faceReply   2                 /* Face data reply */
00200 #define faceLess    4                 /* No face available */
00201 
00202 /* Mask to extract packet modes. */
00203 
00204 #define fCompressionModes   (fComp2X | fCompGSM | fCompADPCM | fCompLPC | fCompLPC10 | fCompCELP)
00205 #define isEncrypted(x)      (((x) & (fEncDES | fEncOTP | fEncOTP | fEncPGP)) != 0)
00206 
00207 /* Special definitions for half-duplex control packets. */
00208 
00209 #define fHalfDuplex 0x10000000        /* Local half-duplex transition */
00210 #ifdef HALF_DUPLEX
00211 #define fHalfDuplexMute      1        /* Mute audio output to allow input */
00212 #define fHalfDuplexResume    2        /* Resume audio output */
00213 #endif
00214 
00215 /* Test if a packet actually contains sound. */
00216 
00217 #define isSoundPacket(c)    (((c) & (fFaceData | fKeyPGP | fHalfDuplex)) == 0)
00218 
00219 /* Open connection state. */
00220 
00221 struct connection {
00222     struct connection *con_next;      /* Next connection */
00223     struct in_addr con_addr;          /* Host Internet address */
00224     char pgpkey[17];                  /* PGP key for connection */
00225     char keymd5[16];                  /* Digest of key file */
00226     long con_timeout;                 /* Connection timeout */
00227     long con_busy;                    /* Connection busy timeout */
00228     char con_hostname[264];           /* Host name */
00229 #ifdef NAT_LAUNCH
00230     struct {
00231         int dport;
00232         int cport;
00233     } con_ports;                      /* Ports for NAT connected host */
00234     int sfmike_pid;                   /* PID of launched sfmike for NAT connection */
00235 #endif
00236     long con_compmodes;               /* Last compression modes */
00237 #ifdef NAT_LAUNCH
00238     long con_compression;             /* Last compression modes */
00239 #endif
00240     short con_protocol;               /* Transmission protocol */
00241     int con_reply_current;            /* Reply file current ? */
00242 #ifndef CRYPTO
00243     int con_crypt_warning;            /* Encryption warning sent ? */
00244 #endif
00245     char con_session[4];              /* VAT/RTP session identifier */
00246     lpcstate_t lpcc;                  /* LPC decoder state */
00247     int con_rseq;                     /* Robust mode sequence number */
00248 
00249     char con_uname[4096];             /* User name */
00250     char con_email[256];              /* User E-mail address, if known */
00251 
00252     char face_filename[300];          /* Face temporary file name */
00253     FILE *face_file;                  /* Face file, when open */
00254     pid_t face_viewer;                /* Face file viewer PID */
00255     int face_stat;                    /* Face retrieval status */
00256     long face_address;                /* Address of current block request */
00257     int face_retry;                   /* Timeout retry count */
00258     int face_timeout;                 /* Timeout interval */
00259 };
00260 
00261 /* Face retrieval status values for face_stat. */
00262 
00263 #define FSinit      0                 /* Nothing requested yet */
00264 #define FSrequest   1                 /* Request sent, awaiting reply */
00265 #define FSreply     2                 /* Reply received, ready for next request */
00266 #define FScomplete  3                 /* Face file reception complete */
00267 #define FSabandoned 4                 /* Face file retrieval abandoned */
00268 
00269 /* Face retrieval configuration parameters. */
00270 
00271 #define FaceFetchInterval   250000    /* Interval between block requests, usec */
00272                                       /* Resend block request after this time */
00273 #define FaceTimeout         (FaceFetchInterval * 20)
00274 #define FaceMaxRetries      10        /* Maximum retries to obtain face data */
00275 
00276 /* Protocol types for con_protocol. */
00277 
00278 #define PROTOCOL_SPEAKFREE  0         /* Speak Freely protocol */
00279 #define PROTOCOL_VAT        1         /* VAT protocol */
00280 #define PROTOCOL_RTP        2         /* RTP protocol */
00281 #define PROTOCOL_VATRTP_CRYPT 3       /* Probably encrypted VAT or RTP message */
00282 #define PROTOCOL_UNKNOWN    4         /* No evidence as to protocol yet */
00283 
00284 /* RTCP APP packet identifiers. */
00285 
00286 #define RTCP_APP_TEXT_CHAT  "SFtc"    /* Text chat message */
00287 
00288 /* Look Who's Listening parameters. */
00289 
00290 #define LWL_MAX_SITES       5         /* Maximum LWL servers a user can publish on */
00291 
00292 #ifdef MYDOMAIN
00293 #define getdomainname(s, n)     strncpy(s, MYDOMAIN, n)
00294 #endif
00295 
00296 /*  From CODECS.C  */
00297 
00298 extern void adpcmdecomp(struct soundbuf *sb);
00299 
00300 /*  From COMMON.C  */
00301 
00302 extern char *StrReplace(char *Str, char *OldStr, char *NewStr);
00303 
00304 /*  From DESKEY.C  */
00305 
00306 extern void string_DES_key(char *key, unsigned char des_key[8], char algorithm[16]);
00307 
00308 /*  From G711.C  */
00309 
00310 #ifdef NEEDED_LINEAR
00311 extern unsigned char linear2alaw(int pcm_val);
00312 extern int alaw2linear(unsigned char a_val);
00313 extern unsigned char linear2ulaw(int pcm_val);
00314 extern int ulaw2linear(unsigned char u_val);
00315 extern unsigned char ulaw2alaw(unsigned char uval);
00316 #endif
00317 extern unsigned char alaw2ulaw(unsigned char aval);
00318 
00319 /*  From HTML.C  */
00320 
00321 extern void outHTML(FILE *fp, char *s);
00322 
00323 /*  From RATE.C  */
00324 
00325 extern void rate_start(int inrate, int outrate);
00326 extern void rate_flow(unsigned char *ibuf, unsigned char *obuf, int *isamp, int *osamp);
00327 
00328 /*  From RTPACKET.C  */
00329 
00330 extern int isrtp(unsigned char *pkt, int len);
00331 extern int isValidRTCPpacket(unsigned char *p, int len);
00332 extern int isRTCPByepacket(unsigned char *p, int len);
00333 extern int isRTCPAPPpacket(unsigned char *p, int len, char *name, unsigned char **app_ptr);
00334 extern int rtp_make_sdes(char **pkt, unsigned long ssrc_i, int port, int strict);
00335 extern int rtp_make_bye(unsigned char *p, unsigned long ssrc_i, char *raison, int strict);
00336 extern int rtp_make_app(unsigned char *p, unsigned long ssrc_i, int strict, char *type, char *content);
00337 extern int rtpout(soundbuf *sb, unsigned long ssrc_i, unsigned long timestamp_i,
00338                   unsigned short seq_i, int spurt);
00339 extern int parseSDES(unsigned char *packet, struct rtcp_sdes_request *r);
00340 extern void copySDESitem(char *s, char *d);
00341 
00342 /*  From SOUNDBYTE.C  */
00343 
00344 extern void setaubufsize(int size);
00345 extern int soundinit(int iomode);
00346 extern void soundterm(void);
00347 extern void sound_open_file_descriptors(int *audio_io, int *audio_ctl);
00348 extern void soundplay(int len, unsigned char *buf);
00349 extern void soundplayvol(int value);
00350 extern void soundrecgain(int value);
00351 extern void sounddest(int where);
00352 extern int soundgrab(char *buf, int len);
00353 extern void soundflush(void);
00354 
00355 /*  From TEMPFILE.C  */
00356 
00357 extern FILE *create_tempfile(char *temp_filename_pattern, const int uMask, const int unLink);
00358 extern FILE *create_tempfile_in_tempdir(const char *tag, char **genName, const int uMask, const int unLink);
00359 
00360 /*  From USLEEP.C  */
00361 
00362 extern void sf_usleep(unsigned t);
00363 
00364 /*  From VATPKT.C  */
00365 
00366 extern int isvat(unsigned char *pkt, int len);
00367 extern int vatout(soundbuf *sb, unsigned long ssrc_i, unsigned long timestamp_i, int spurt);
00368 extern int makeVATid(char **vp, unsigned long ssrc_i);
00369 extern int makevatdone(char *v, unsigned long ssrc_i);
00370 
00371 /*  From VOX.C  */
00372 
00373 #include "vox.h"
00374 
00375 /*  From XDSUB.C  */
00376 
00377 #ifdef HEXDUMP
00378 extern void xd(FILE *out, void *buf, int bufl, int dochar);
00379 #endif

Generated on Tue Feb 10 08:44:18 2004 for Speak-FreelyforUnix by doxygen1.2.18