X-Git-Url: http://git.eversberg.eu/gitweb.cgi?p=lcr.git;a=blobdiff_plain;f=chan_lcr.c;h=cf711bc8b242d8d34d2ae9cde4c22481f3b9a3b7;hp=d0993b71759410051567d2c3c6e9ac604ff2f18e;hb=513e12ace547adc9c4a4eec4c15592451fb1b7b4;hpb=b0bd74e35e935aa976b68c594def4e8d2c22ef95 diff --git a/chan_lcr.c b/chan_lcr.c index d0993b7..cf711bc 100644 --- a/chan_lcr.c +++ b/chan_lcr.c @@ -223,6 +223,11 @@ struct admin_list { static struct ast_channel_tech lcr_tech; +void lock_debug(char *text) +{ + printf("%s", text); fflush(stdout); +} + /* * logging */ @@ -233,6 +238,7 @@ void chan_lcr_log(int type, const char *file, int line, const char *function, st char ast_text[128] = "NULL"; va_list args; + lock_debug("L"); ast_mutex_lock(&log_lock); va_start(args,fmt); @@ -249,6 +255,7 @@ void chan_lcr_log(int type, const char *file, int line, const char *function, st ast_log(type, file, line, function, "[call=%s ast=%s] %s", call_text, ast_text, buffer); ast_mutex_unlock(&log_lock); + lock_debug("l"); } /* @@ -496,6 +503,14 @@ void apply_opt(struct chan_call *call, char *data) if (!call->nodsp) call->nodsp = 1; break; + case 'q': + if (opt[1] == '\0') { + CERROR(call, call->ast, "Option 'q' (queue) expects parameter.\n", opt); + break; + } + CDEBUG(call, call->ast, "Option 'q' (queue).\n"); + call->nodsp_queue = atoi(opt+1); + break; case 'e': if (opt[1] == '\0') { CERROR(call, call->ast, "Option 'e' (echo cancel) expects parameter.\n", opt); @@ -591,7 +606,7 @@ void apply_opt(struct chan_call *call, char *data) /* re-open, if bchannel is created */ if (call->bchannel && call->bchannel->b_sock > -1) { bchannel_destroy(call->bchannel); - if (bchannel_create(call->bchannel, ((call->nodsp || call->faxdetect > 0)?1:0) + ((call->hdlc)?2:0))) + if (bchannel_create(call->bchannel, ((call->nodsp || call->faxdetect > 0)?1:0) + ((call->hdlc)?2:0), call->nodsp_queue)) bchannel_activate(call->bchannel, 1); } } @@ -604,6 +619,7 @@ static void send_setup_to_lcr(struct chan_call *call) { union parameter newparam; struct ast_channel *ast = call->ast; + const char *tmp; if (!call->ast || !call->ref) return; @@ -656,6 +672,9 @@ static void send_setup_to_lcr(struct chan_call *call) default: newparam.setup.callerinfo.ntype = INFO_NTYPE_UNKNOWN; } + tmp = pbx_builtin_getvar_helper(ast, "LCR_TRANSFERCAPABILITY"); + if (tmp && *tmp) + ast->transfercapability = atoi(tmp); newparam.setup.capainfo.bearer_capa = ast->transfercapability; newparam.setup.capainfo.bearer_mode = INFO_BMODE_CIRCUIT; if (call->hdlc) @@ -872,7 +891,7 @@ static void lcr_in_setup(struct chan_call *call, int message_type, union paramet if (param->setup.callerinfo.name[0]) ast->cid.cid_name = strdup(param->setup.callerinfo.name); if (param->setup.redirinfo.id[0]) - ast->cid.cid_name = strdup(numberrize_callerinfo(param->setup.callerinfo.id, param->setup.callerinfo.ntype, options.national, options.international)); + ast->cid.cid_rdnis = strdup(numberrize_callerinfo(param->setup.redirinfo.id, param->setup.redirinfo.ntype, options.national, options.international)); switch (param->setup.callerinfo.present) { case INFO_PRESENT_ALLOWED: ast->cid.cid_pres = AST_PRES_ALLOWED; @@ -1287,7 +1306,7 @@ int receive_message(int message_type, unsigned int ref, union parameter *param) bchannel_join(bchannel, call->bridge_id); } /* create only, if call exists, othewhise it bchannel is freed below... */ - if (bchannel_create(bchannel, ((call->nodsp || call->faxdetect > 0)?1:0) + ((call->hdlc)?2:0))) + if (bchannel_create(bchannel, ((call->nodsp || call->faxdetect > 0)?1:0) + ((call->hdlc)?2:0), call->nodsp_queue)) bchannel_activate(bchannel, 1); } /* acknowledge */ @@ -1652,6 +1671,7 @@ static void handle_queue() p = call->queue_string; ast = call->ast; if (*p && ast) { + lock_debug("A1"); ast_channel_lock(ast); while(*p) { switch (*p) { @@ -1709,6 +1729,7 @@ static void handle_queue() } call->queue_string[0] = '\0'; ast_channel_unlock(ast); + lock_debug("a1"); } call = call->next; } @@ -1725,12 +1746,14 @@ static int handle_retry(struct lcr_timer *timer, void *instance, int index) void lock_chan(void) { + lock_debug("C"); ast_mutex_lock(&chan_lock); } void unlock_chan(void) { ast_mutex_unlock(&chan_lock); + lock_debug("c"); } /* chan_lcr thread */ @@ -1752,6 +1775,7 @@ static void *chan_thread(void *arg) /* open socket the first time */ handle_retry(NULL, NULL, 0); + lock_debug("A2"); ast_mutex_lock(&chan_lock); while(!quit) { @@ -1770,6 +1794,7 @@ static void *chan_thread(void *arg) CERROR(NULL, NULL, "Thread exit.\n"); ast_mutex_unlock(&chan_lock); + lock_debug("a2"); return NULL; } @@ -1784,6 +1809,7 @@ struct ast_channel *lcr_request(const char *type, int format, void *data, int *c struct ast_channel *ast; struct chan_call *call; + lock_debug("A3"); ast_mutex_lock(&chan_lock); CDEBUG(NULL, NULL, "Received request from Asterisk. (data=%s)\n", (char *)data); @@ -1791,6 +1817,7 @@ struct ast_channel *lcr_request(const char *type, int format, void *data, int *c if (lcr_sock < 0) { CERROR(NULL, NULL, "Rejecting call from Asterisk, because LCR not running.\n"); ast_mutex_unlock(&chan_lock); + lock_debug("a3"); return NULL; } @@ -1799,6 +1826,7 @@ struct ast_channel *lcr_request(const char *type, int format, void *data, int *c if (!call) { /* failed to create instance */ ast_mutex_unlock(&chan_lock); + lock_debug("a3"); return NULL; } @@ -1817,6 +1845,7 @@ struct ast_channel *lcr_request(const char *type, int format, void *data, int *c free_call(call); /* failed to create instance */ ast_mutex_unlock(&chan_lock); + lock_debug("a3"); return NULL; } ast->tech = &lcr_tech; @@ -1862,6 +1891,7 @@ struct ast_channel *lcr_request(const char *type, int format, void *data, int *c apply_opt(call, (char *)opt); ast_mutex_unlock(&chan_lock); + lock_debug("a3"); return ast; } @@ -1873,6 +1903,7 @@ static int lcr_call(struct ast_channel *ast, char *dest, int timeout) union parameter newparam; struct chan_call *call; + lock_debug("A4"); ast_mutex_lock(&chan_lock); call = ast->tech_pvt; @@ -1884,6 +1915,7 @@ static int lcr_call(struct ast_channel *ast, char *dest, int timeout) if (!call) { CERROR(NULL, ast, "Received call from Asterisk, but call instance does not exist.\n"); ast_mutex_unlock(&chan_lock); + lock_debug("a4"); return -1; } @@ -1924,6 +1956,7 @@ static int lcr_call(struct ast_channel *ast, char *dest, int timeout) sizeof(call->cid_rdnis)-1); ast_mutex_unlock(&chan_lock); + lock_debug("a4"); return 0; } @@ -1981,11 +2014,13 @@ static int lcr_digit(struct ast_channel *ast, char digit) if (digit > 126 || digit < 32) return 0; + lock_debug("A5"); ast_mutex_lock(&chan_lock); call = ast->tech_pvt; if (!call) { CERROR(NULL, ast, "Received digit from Asterisk, but no call instance exists.\n"); ast_mutex_unlock(&chan_lock); + lock_debug("a5"); return -1; } @@ -2012,6 +2047,7 @@ static int lcr_digit(struct ast_channel *ast, char digit) } ast_mutex_unlock(&chan_lock); + lock_debug("a5"); #ifdef LCR_FOR_ASTERISK return 0; @@ -2023,6 +2059,7 @@ static int lcr_digit_end(struct ast_channel *ast, char digit, unsigned int durat struct chan_call *call; #endif + lock_debug("A6"); ast_mutex_lock(&chan_lock); call = ast->tech_pvt; @@ -2032,6 +2069,7 @@ static int lcr_digit_end(struct ast_channel *ast, char digit, unsigned int durat "Received digit from Asterisk, " "but no call instance exists.\n"); ast_mutex_unlock(&chan_lock); + lock_debug("a6"); return -1; } @@ -2042,6 +2080,7 @@ static int lcr_digit_end(struct ast_channel *ast, char digit, unsigned int durat } ast_mutex_unlock(&chan_lock); + lock_debug("a6"); if (inband_dtmf) { CDEBUG(call, ast, "-> sending '%c' inband.\n", digit); @@ -2056,11 +2095,13 @@ static int lcr_answer(struct ast_channel *ast) union parameter newparam; struct chan_call *call; + lock_debug("A7"); ast_mutex_lock(&chan_lock); call = ast->tech_pvt; if (!call) { CERROR(NULL, ast, "Received answer from Asterisk, but no call instance exists.\n"); ast_mutex_unlock(&chan_lock); + lock_debug("a7"); return -1; } @@ -2089,6 +2130,7 @@ static int lcr_answer(struct ast_channel *ast) // send_message(MESSAGE_ENABLEKEYPAD, call->ref, &newparam); ast_mutex_unlock(&chan_lock); + lock_debug("a7"); return 0; } @@ -2097,13 +2139,17 @@ static int lcr_hangup(struct ast_channel *ast) struct chan_call *call; pthread_t tid = pthread_self(); - if (!pthread_equal(tid, chan_tid)) + if (!pthread_equal(tid, chan_tid)) { + lock_debug("H"); ast_mutex_lock(&chan_lock); + } call = ast->tech_pvt; if (!call) { CERROR(NULL, ast, "Received hangup from Asterisk, but no call instance exists.\n"); - if (!pthread_equal(tid, chan_tid)) + if (!pthread_equal(tid, chan_tid)) { ast_mutex_unlock(&chan_lock); + lock_debug("h"); + } return -1; } @@ -2124,8 +2170,10 @@ static int lcr_hangup(struct ast_channel *ast) send_release_and_import(call, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL); /* remove call */ free_call(call); - if (!pthread_equal(tid, chan_tid)) + if (!pthread_equal(tid, chan_tid)) { ast_mutex_unlock(&chan_lock); + lock_debug("h"); + } return 0; } else { /* ref is not set, due to prepare setup or release */ @@ -2140,8 +2188,10 @@ static int lcr_hangup(struct ast_channel *ast) call->ast = NULL; } } - if (!pthread_equal(tid, chan_tid)) + if (!pthread_equal(tid, chan_tid)) { ast_mutex_unlock(&chan_lock); + lock_debug("h"); + } return 0; } @@ -2154,15 +2204,18 @@ static int lcr_write(struct ast_channel *ast, struct ast_frame *f) if (!(f->subclass & ast->nativeformats)) CDEBUG(NULL, ast, "Unexpected format.\n"); + lock_debug("A8"); ast_mutex_lock(&chan_lock); call = ast->tech_pvt; if (!call) { ast_mutex_unlock(&chan_lock); + lock_debug("a8"); return -1; } if (call->bchannel && f->samples) bchannel_transmit(call->bchannel, *((unsigned char **)&(f->data)), f->samples); ast_mutex_unlock(&chan_lock); + lock_debug("a8"); return 0; } @@ -2172,10 +2225,12 @@ static struct ast_frame *lcr_read(struct ast_channel *ast) struct chan_call *call; int len; + lock_debug("A9"); ast_mutex_lock(&chan_lock); call = ast->tech_pvt; if (!call) { ast_mutex_unlock(&chan_lock); + lock_debug("a9"); return NULL; } if (call->pipe[0] > -1) { @@ -2190,6 +2245,7 @@ static struct ast_frame *lcr_read(struct ast_channel *ast) } if (len < 0 && errno == EAGAIN) { ast_mutex_unlock(&chan_lock); + lock_debug("a9"); #ifdef LCR_FOR_ASTERISK return &ast_null_frame; @@ -2205,10 +2261,12 @@ static struct ast_frame *lcr_read(struct ast_channel *ast) call->pipe[0] = -1; global_change = 1; ast_mutex_unlock(&chan_lock); + lock_debug("a9"); return NULL; } else if (call->rebuffer && call->framepos < 160) { /* Not a complete frame, so we send a null-frame */ ast_mutex_unlock(&chan_lock); + lock_debug("a9"); return &ast_null_frame; } } @@ -2226,6 +2284,7 @@ static struct ast_frame *lcr_read(struct ast_channel *ast) call->read_fr.delivery = ast_tv(0,0); *((unsigned char **)&(call->read_fr.data)) = call->read_buff; ast_mutex_unlock(&chan_lock); + lock_debug("a9"); return &call->read_fr; } @@ -2235,12 +2294,15 @@ static int lcr_indicate(struct ast_channel *ast, int cond, const void *data, siz union parameter newparam; int res = 0; struct chan_call *call; + const struct tone_zone_sound *ts = NULL; + lock_debug("A0"); ast_mutex_lock(&chan_lock); call = ast->tech_pvt; if (!call) { CERROR(NULL, ast, "Received indicate from Asterisk, but no call instance exists.\n"); ast_mutex_unlock(&chan_lock); + lock_debug("a0"); return -1; } @@ -2256,6 +2318,9 @@ static int lcr_indicate(struct ast_channel *ast, int cond, const void *data, siz send_message(MESSAGE_DISCONNECT, call->ref, &newparam); /* change state */ call->state = CHAN_LCR_STATE_OUT_DISCONNECT; + } else { + CDEBUG(call, ast, "Using Asterisk 'busy' indication\n"); + ts = ast_get_indication_tone(ast->zone, "busy"); } break; case AST_CONTROL_CONGESTION: @@ -2268,6 +2333,9 @@ static int lcr_indicate(struct ast_channel *ast, int cond, const void *data, siz send_message(MESSAGE_DISCONNECT, call->ref, &newparam); /* change state */ call->state = CHAN_LCR_STATE_OUT_DISCONNECT; + } else { + CDEBUG(call, ast, "Using Asterisk 'congestion' indication\n"); + ts = ast_get_indication_tone(ast->zone, "congestion"); } break; case AST_CONTROL_PROCEEDING: @@ -2292,6 +2360,9 @@ static int lcr_indicate(struct ast_channel *ast, int cond, const void *data, siz send_message(MESSAGE_ALERTING, call->ref, &newparam); /* change state */ call->state = CHAN_LCR_STATE_IN_ALERTING; + } else { + CDEBUG(call, ast, "Using Asterisk 'ring' indication\n"); + ts = ast_get_indication_tone(ast->zone, "ring"); } break; case AST_CONTROL_PROGRESS: @@ -2306,6 +2377,7 @@ static int lcr_indicate(struct ast_channel *ast, int cond, const void *data, siz break; case -1: CDEBUG(call, ast, "Received indicate -1.\n"); + ast_playtones_stop(ast); res = -1; break; @@ -2344,17 +2416,24 @@ static int lcr_indicate(struct ast_channel *ast, int cond, const void *data, siz break; #ifdef AST_CONTROL_SRCUPDATE case AST_CONTROL_SRCUPDATE: +#else + case 20: +#endif CDEBUG(call, ast, "Received AST_CONTROL_SRCUPDATE from Asterisk.\n"); break; -#endif default: CERROR(call, ast, "Received indicate from Asterisk with unknown condition %d.\n", cond); res = -1; break; } + if (ts && ts->data[0]) { + ast_playtones_start(ast, 0, ts->data, 1); + } + /* return */ ast_mutex_unlock(&chan_lock); + lock_debug("a0"); return res; } @@ -2369,17 +2448,20 @@ static int lcr_fixup(struct ast_channel *oldast, struct ast_channel *ast) return -1; } + lock_debug("Af"); ast_mutex_lock(&chan_lock); call = ast->tech_pvt; if (!call) { CERROR(NULL, ast, "Received fixup from Asterisk, but no call instance exists.\n"); ast_mutex_unlock(&chan_lock); + lock_debug("af"); return -1; } CDEBUG(call, ast, "Received fixup from Asterisk.\n"); call->ast = ast; ast_mutex_unlock(&chan_lock); + lock_debug("af"); return 0; } @@ -2391,11 +2473,13 @@ static int lcr_send_text(struct ast_channel *ast, const char *text) struct chan_call *call; union parameter newparam; + lock_debug("At"); ast_mutex_lock(&chan_lock); call = ast->tech_pvt; if (!call) { CERROR(NULL, ast, "Received send_text from Asterisk, but no call instance exists.\n"); ast_mutex_unlock(&chan_lock); + lock_debug("at"); return -1; } @@ -2403,7 +2487,8 @@ static int lcr_send_text(struct ast_channel *ast, const char *text) memset(&newparam, 0, sizeof(union parameter)); strncpy(newparam.notifyinfo.display, text, sizeof(newparam.notifyinfo.display)-1); send_message(MESSAGE_NOTIFY, call->ref, &newparam); - ast_mutex_lock(&chan_lock); + ast_mutex_unlock(&chan_lock); + lock_debug("at"); return 0; } @@ -2428,12 +2513,14 @@ enum ast_bridge_result lcr_bridge(struct ast_channel *ast1, carr[1] = ast2; /* join via dsp (if the channels are currently open) */ + lock_debug("Ab"); ast_mutex_lock(&chan_lock); call1 = ast1->tech_pvt; call2 = ast2->tech_pvt; if (!call1 || !call2) { CDEBUG(NULL, NULL, "Bridge, but we don't have two call instances, exitting.\n"); ast_mutex_unlock(&chan_lock); + lock_debug("ab"); return AST_BRIDGE_COMPLETE; } @@ -2501,6 +2588,7 @@ enum ast_bridge_result lcr_bridge(struct ast_channel *ast1, } ast_mutex_unlock(&chan_lock); + lock_debug("ab"); while(1) { to = -1; @@ -2543,6 +2631,7 @@ enum ast_bridge_result lcr_bridge(struct ast_channel *ast1, CDEBUG(NULL, NULL, "Releasing bridge.\n"); /* split channels */ + lock_debug("Ab"); ast_mutex_lock(&chan_lock); call1 = ast1->tech_pvt; call2 = ast2->tech_pvt; @@ -2564,6 +2653,7 @@ enum ast_bridge_result lcr_bridge(struct ast_channel *ast1, call2->bridge_call = NULL; ast_mutex_unlock(&chan_lock); + lock_debug("ab"); return AST_BRIDGE_COMPLETE; } static struct ast_channel_tech lcr_tech = { @@ -2694,6 +2784,7 @@ static int lcr_config_exec(struct ast_channel *ast, void *data, char **argv) { struct chan_call *call; + lock_debug("Ae"); ast_mutex_lock(&chan_lock); #ifdef LCR_FOR_ASTERISK @@ -2725,6 +2816,7 @@ static int lcr_config_exec(struct ast_channel *ast, void *data, char **argv) CERROR(NULL, ast, "lcr_config app not called by chan_lcr channel.\n"); ast_mutex_unlock(&chan_lock); + lock_debug("ae"); return 0; } @@ -2734,13 +2826,14 @@ static int lcr_config_exec(struct ast_channel *ast, void *data, char **argv) int load_module(void) { u_short i; + char options_error[256]; for (i = 0; i < 256; i++) { flip_bits[i] = (i>>7) | ((i>>5)&2) | ((i>>3)&4) | ((i>>1)&8) | (i<<7) | ((i&2)<<5) | ((i&4)<<3) | ((i&8)<<1); } - if (read_options() == 0) { + if (read_options(options_error) == 0) { CERROR(NULL, NULL, "%s", options_error); #ifdef LCR_FOR_ASTERISK @@ -2802,6 +2895,8 @@ int load_module(void) " n - Don't detect dtmf tones on called channel.\n" " h - Force data call (HDLC).\n" " t - Disable mISDN_dsp features (required for fax application).\n" + " q - Add queue to make fax stream seamless (required for fax app).\n" + " Use queue size in miliseconds for optarg. (try 250)\n" " f - Adding fax detection. It it timeouts, mISDN_dsp is used.\n" " Use time to detect for optarg.\n" " c - Make crypted outgoing call, optarg is keyindex.\n" @@ -2813,6 +2908,12 @@ int load_module(void) " vt - txgain control\n" " Volume changes at factor 2 ^ optarg.\n" " k - use keypad to dial this call.\n" + "\n" + "set LCR_TRANSFERCAPABILITY to the numerical bearer capabilty in order to alter caller's capability\n" + " -> use 16 for fax (3.1k audio)\n" + "\n" + "To send a fax, you need to set LCR_TRANSFERCAPABILITY environment to 16, also you need to set\n" + "options: \"n:t:q250\" for seamless audio transmission.\n" ); @@ -2886,9 +2987,11 @@ int usecount(void) hae { int res; + lock_debug("U"); ast_mutex_lock(&usecnt_lock); res = usecnt; ast_mutex_unlock(&usecnt_lock); + lock_debug("u"); return res; } #endif