Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Audio support data for ISDN4Linux.
0003  *
0004  * Copyright 2002/2003 by Andreas Eversberg (jolly@eversberg.eu)
0005  *
0006  * This software may be used and distributed according to the terms
0007  * of the GNU General Public License, incorporated herein by reference.
0008  *
0009  */
0010 
0011 #define DEBUG_DSP_CTRL      0x0001
0012 #define DEBUG_DSP_CORE      0x0002
0013 #define DEBUG_DSP_DTMF      0x0004
0014 #define DEBUG_DSP_CMX       0x0010
0015 #define DEBUG_DSP_TONE      0x0020
0016 #define DEBUG_DSP_BLOWFISH  0x0040
0017 #define DEBUG_DSP_DELAY     0x0100
0018 #define DEBUG_DSP_CLOCK     0x0200
0019 #define DEBUG_DSP_DTMFCOEFF 0x8000 /* heavy output */
0020 
0021 /* options may be:
0022  *
0023  * bit 0 = use ulaw instead of alaw
0024  * bit 1 = enable hfc hardware acceleration for all channels
0025  *
0026  */
0027 #define DSP_OPT_ULAW        (1 << 0)
0028 #define DSP_OPT_NOHARDWARE  (1 << 1)
0029 
0030 #include <linux/timer.h>
0031 #include <linux/workqueue.h>
0032 
0033 #include "dsp_ecdis.h"
0034 
0035 extern int dsp_options;
0036 extern int dsp_debug;
0037 extern int dsp_poll;
0038 extern int dsp_tics;
0039 extern spinlock_t dsp_lock;
0040 extern struct work_struct dsp_workq;
0041 extern u32 dsp_poll_diff; /* calculated fix-comma corrected poll value */
0042 
0043 /***************
0044  * audio stuff *
0045  ***************/
0046 
0047 extern s32 dsp_audio_alaw_to_s32[256];
0048 extern s32 dsp_audio_ulaw_to_s32[256];
0049 extern s32 *dsp_audio_law_to_s32;
0050 extern u8 dsp_audio_s16_to_law[65536];
0051 extern u8 dsp_audio_alaw_to_ulaw[256];
0052 extern u8 dsp_audio_mix_law[65536];
0053 extern u8 dsp_audio_seven2law[128];
0054 extern u8 dsp_audio_law2seven[256];
0055 extern void dsp_audio_generate_law_tables(void);
0056 extern void dsp_audio_generate_s2law_table(void);
0057 extern void dsp_audio_generate_seven(void);
0058 extern void dsp_audio_generate_mix_table(void);
0059 extern void dsp_audio_generate_ulaw_samples(void);
0060 extern void dsp_audio_generate_volume_changes(void);
0061 extern u8 dsp_silence;
0062 
0063 
0064 /*************
0065  * cmx stuff *
0066  *************/
0067 
0068 #define MAX_POLL    256 /* maximum number of send-chunks */
0069 
0070 #define CMX_BUFF_SIZE   0x8000  /* must be 2**n (0x1000 about 1/2 second) */
0071 #define CMX_BUFF_HALF   0x4000  /* CMX_BUFF_SIZE / 2 */
0072 #define CMX_BUFF_MASK   0x7fff  /* CMX_BUFF_SIZE - 1 */
0073 
0074 /* how many seconds will we check the lowest delay until the jitter buffer
0075    is reduced by that delay */
0076 #define MAX_SECONDS_JITTER_CHECK 5
0077 
0078 extern struct timer_list dsp_spl_tl;
0079 
0080 /* the datatype need to match jiffies datatype */
0081 extern unsigned long dsp_spl_jiffies;
0082 
0083 /* the structure of conferences:
0084  *
0085  * each conference has a unique number, given by user space.
0086  * the conferences are linked in a chain.
0087  * each conference has members linked in a chain.
0088  * each dsplayer points to a member, each member points to a dsplayer.
0089  */
0090 
0091 /* all members within a conference (this is linked 1:1 with the dsp) */
0092 struct dsp;
0093 struct dsp_conf_member {
0094     struct list_head    list;
0095     struct dsp      *dsp;
0096 };
0097 
0098 /* the list of all conferences */
0099 struct dsp_conf {
0100     struct list_head    list;
0101     u32         id;
0102     /* all cmx stacks with the same ID are
0103        connected */
0104     struct list_head    mlist;
0105     int         software; /* conf is processed by software */
0106     int         hardware; /* conf is processed by hardware */
0107     /* note: if both unset, has only one member */
0108 };
0109 
0110 
0111 /**************
0112  * DTMF stuff *
0113  **************/
0114 
0115 #define DSP_DTMF_NPOINTS 102
0116 
0117 #define ECHOCAN_BUFF_SIZE 0x400 /* must be 2**n */
0118 #define ECHOCAN_BUFF_MASK 0x3ff /* -1 */
0119 
0120 struct dsp_dtmf {
0121     int     enable; /* dtmf is enabled */
0122     int     treshold; /* above this is dtmf (square of) */
0123     int     software; /* dtmf uses software decoding */
0124     int     hardware; /* dtmf uses hardware decoding */
0125     int     size; /* number of bytes in buffer */
0126     signed short    buffer[DSP_DTMF_NPOINTS];
0127     /* buffers one full dtmf frame */
0128     u8      lastwhat, lastdigit;
0129     int     count;
0130     u8      digits[16]; /* dtmf result */
0131 };
0132 
0133 
0134 /******************
0135  * pipeline stuff *
0136  ******************/
0137 struct dsp_pipeline {
0138     rwlock_t  lock;
0139     struct list_head list;
0140     int inuse;
0141 };
0142 
0143 /***************
0144  * tones stuff *
0145  ***************/
0146 
0147 struct dsp_tone {
0148     int     software; /* tones are generated by software */
0149     int     hardware; /* tones are generated by hardware */
0150     int     tone;
0151     void        *pattern;
0152     int     count;
0153     int     index;
0154     struct timer_list tl;
0155 };
0156 
0157 /***************
0158  * echo stuff *
0159  ***************/
0160 
0161 struct dsp_echo {
0162     int     software; /* echo is generated by software */
0163     int     hardware; /* echo is generated by hardware */
0164 };
0165 
0166 /*****************
0167  * general stuff *
0168  *****************/
0169 
0170 struct dsp {
0171     struct list_head list;
0172     struct mISDNchannel ch;
0173     struct mISDNchannel *up;
0174     unsigned char   name[64];
0175     int     b_active;
0176     struct dsp_echo echo;
0177     int     rx_disabled; /* what the user wants */
0178     int     rx_is_off; /* what the card is */
0179     int     tx_mix;
0180     struct dsp_tone tone;
0181     struct dsp_dtmf dtmf;
0182     int     tx_volume, rx_volume;
0183 
0184     /* queue for sending frames */
0185     struct work_struct  workq;
0186     struct sk_buff_head sendq;
0187     int     hdlc;   /* if mode is hdlc */
0188     int     data_pending;   /* currently an unconfirmed frame */
0189 
0190     /* conference stuff */
0191     u32     conf_id;
0192     struct dsp_conf *conf;
0193     struct dsp_conf_member
0194     *member;
0195 
0196     /* buffer stuff */
0197     int     rx_W; /* current write pos for data without timestamp */
0198     int     rx_R; /* current read pos for transmit clock */
0199     int     rx_init; /* if set, pointers will be adjusted first */
0200     int     tx_W; /* current write pos for transmit data */
0201     int     tx_R; /* current read pos for transmit clock */
0202     int     rx_delay[MAX_SECONDS_JITTER_CHECK];
0203     int     tx_delay[MAX_SECONDS_JITTER_CHECK];
0204     u8      tx_buff[CMX_BUFF_SIZE];
0205     u8      rx_buff[CMX_BUFF_SIZE];
0206     int     last_tx; /* if set, we transmitted last poll interval */
0207     int     cmx_delay; /* initial delay of buffers,
0208                       or 0 for dynamic jitter buffer */
0209     int     tx_dejitter; /* if set, dejitter tx buffer */
0210     int     tx_data; /* enables tx-data of CMX to upper layer */
0211 
0212     /* hardware stuff */
0213     struct dsp_features features;
0214     int     features_rx_off; /* set if rx_off is featured */
0215     int     features_fill_empty; /* set if fill_empty is featured */
0216     int     pcm_slot_rx; /* current PCM slot (or -1) */
0217     int     pcm_bank_rx;
0218     int     pcm_slot_tx;
0219     int     pcm_bank_tx;
0220     int     hfc_conf; /* unique id of current conference (or -1) */
0221 
0222     /* encryption stuff */
0223     int     bf_enable;
0224     u32     bf_p[18];
0225     u32     bf_s[1024];
0226     int     bf_crypt_pos;
0227     u8      bf_data_in[9];
0228     u8      bf_crypt_out[9];
0229     int     bf_decrypt_in_pos;
0230     int     bf_decrypt_out_pos;
0231     u8      bf_crypt_inring[16];
0232     u8      bf_data_out[9];
0233     int     bf_sync;
0234 
0235     struct dsp_pipeline
0236     pipeline;
0237 };
0238 
0239 /* functions */
0240 
0241 extern void dsp_change_volume(struct sk_buff *skb, int volume);
0242 
0243 extern struct list_head dsp_ilist;
0244 extern struct list_head conf_ilist;
0245 extern void dsp_cmx_debug(struct dsp *dsp);
0246 extern void dsp_cmx_hardware(struct dsp_conf *conf, struct dsp *dsp);
0247 extern int dsp_cmx_conf(struct dsp *dsp, u32 conf_id);
0248 extern void dsp_cmx_receive(struct dsp *dsp, struct sk_buff *skb);
0249 extern void dsp_cmx_hdlc(struct dsp *dsp, struct sk_buff *skb);
0250 extern void dsp_cmx_send(void *arg);
0251 extern void dsp_cmx_transmit(struct dsp *dsp, struct sk_buff *skb);
0252 extern int dsp_cmx_del_conf_member(struct dsp *dsp);
0253 extern int dsp_cmx_del_conf(struct dsp_conf *conf);
0254 
0255 extern void dsp_dtmf_goertzel_init(struct dsp *dsp);
0256 extern void dsp_dtmf_hardware(struct dsp *dsp);
0257 extern u8 *dsp_dtmf_goertzel_decode(struct dsp *dsp, u8 *data, int len,
0258                     int fmt);
0259 
0260 extern int dsp_tone(struct dsp *dsp, int tone);
0261 extern void dsp_tone_copy(struct dsp *dsp, u8 *data, int len);
0262 extern void dsp_tone_timeout(struct timer_list *t);
0263 
0264 extern void dsp_bf_encrypt(struct dsp *dsp, u8 *data, int len);
0265 extern void dsp_bf_decrypt(struct dsp *dsp, u8 *data, int len);
0266 extern int dsp_bf_init(struct dsp *dsp, const u8 *key, unsigned int keylen);
0267 extern void dsp_bf_cleanup(struct dsp *dsp);
0268 
0269 extern int  dsp_pipeline_module_init(void);
0270 extern void dsp_pipeline_module_exit(void);
0271 extern int  dsp_pipeline_init(struct dsp_pipeline *pipeline);
0272 extern void dsp_pipeline_destroy(struct dsp_pipeline *pipeline);
0273 extern int  dsp_pipeline_build(struct dsp_pipeline *pipeline, const char *cfg);
0274 extern void dsp_pipeline_process_tx(struct dsp_pipeline *pipeline, u8 *data,
0275                     int len);
0276 extern void dsp_pipeline_process_rx(struct dsp_pipeline *pipeline, u8 *data,
0277                     int len, unsigned int txlen);