static struct ast_filestream *g723_open(int fd) { /* We don't have any header to read or anything really, but if we did, it would go here. We also might want to check and be sure it's a valid file. */ struct ast_filestream *tmp; if ((tmp = malloc(sizeof(struct ast_filestream)))) { if (ast_mutex_lock(&g723_lock)) { ast_log(LOG_WARNING, "Unable to lock g723 list\n"); free(tmp); return NULL; } tmp->fd = fd; tmp->fr = (struct ast_frame *)tmp->buf; tmp->fr->data = tmp->buf + sizeof(struct ast_frame); tmp->fr->frametype = AST_FRAME_VOICE; tmp->fr->subclass = AST_FORMAT_G723_1; /* datalen will vary for each frame */ tmp->fr->src = name; tmp->fr->mallocd = 0; tmp->lasttimeout = -1; tmp->orig.tv_usec = 0; tmp->orig.tv_sec = 0; glistcnt++; ast_mutex_unlock(&g723_lock); ast_update_use_count(); } return tmp; }
static struct ast_filestream *gsm_open(FILE *f) { /* We don't have any header to read or anything really, but if we did, it would go here. We also might want to check and be sure it's a valid file. */ struct ast_filestream *tmp; if ((tmp = malloc(sizeof(struct ast_filestream)))) { memset(tmp, 0, sizeof(struct ast_filestream)); if (ast_mutex_lock(&gsm_lock)) { ast_log(LOG_WARNING, "Unable to lock gsm list\n"); free(tmp); return NULL; } tmp->f = f; tmp->fr.data = tmp->gsm; tmp->fr.frametype = AST_FRAME_VOICE; tmp->fr.subclass = AST_FORMAT_GSM; /* datalen will vary for each frame */ tmp->fr.src = name; tmp->fr.mallocd = 0; glistcnt++; ast_mutex_unlock(&gsm_lock); ast_update_use_count(); } return tmp; }
static void aopen_incusecnt(void) { ast_mutex_lock(&usecnt_lock); usecnt++; ast_mutex_unlock(&usecnt_lock); ast_update_use_count(); }
static struct ast_filestream *wav_rewrite(int fd, char *comment) { /* We don't have any header to read or anything really, but if we did, it would go here. We also might want to check and be sure it's a valid file. */ struct ast_filestream *tmp; if ((tmp = malloc(sizeof(struct ast_filestream)))) { memset(tmp, 0, sizeof(struct ast_filestream)); if (write_header(fd)) { free(tmp); return NULL; } if (ast_mutex_lock(&wav_lock)) { ast_log(LOG_WARNING, "Unable to lock wav list\n"); free(tmp); return NULL; } tmp->fd = fd; glistcnt++; ast_mutex_unlock(&wav_lock); ast_update_use_count(); } else ast_log(LOG_WARNING, "Out of memory\n"); return tmp; }
static struct ast_filestream *h263_open(FILE *f) { /* We don't have any header to read or anything really, but if we did, it would go here. We also might want to check and be sure it's a valid file. */ struct ast_filestream *tmp; unsigned int ts; int res; if ((res = fread(&ts, 1, sizeof(ts), f)) < sizeof(ts)) { ast_log(LOG_WARNING, "Empty file!\n"); return NULL; } if ((tmp = malloc(sizeof(struct ast_filestream)))) { memset(tmp, 0, sizeof(struct ast_filestream)); if (ast_mutex_lock(&h263_lock)) { ast_log(LOG_WARNING, "Unable to lock h263 list\n"); free(tmp); return NULL; } tmp->f = f; tmp->fr.data = tmp->h263; tmp->fr.frametype = AST_FRAME_VIDEO; tmp->fr.subclass = AST_FORMAT_H263; /* datalen will vary for each frame */ tmp->fr.src = name; tmp->fr.mallocd = 0; glistcnt++; ast_mutex_unlock(&h263_lock); ast_update_use_count(); } return tmp; }
static struct ast_filestream *g723_rewrite(int fd, char *comment) { /* We don't have any header to read or anything really, but if we did, it would go here. We also might want to check and be sure it's a valid file. */ struct ast_filestream *tmp; if ((tmp = malloc(sizeof(struct ast_filestream)))) { if (ast_mutex_lock(&g723_lock)) { ast_log(LOG_WARNING, "Unable to lock g723 list\n"); free(tmp); return NULL; } tmp->fd = fd; tmp->owner = NULL; tmp->fr = NULL; tmp->lasttimeout = -1; tmp->orig.tv_usec = 0; tmp->orig.tv_sec = 0; glistcnt++; ast_mutex_unlock(&g723_lock); ast_update_use_count(); } else ast_log(LOG_WARNING, "Out of memory\n"); return tmp; }
static void i4l_decusecnt(void) { ast_mutex_lock(&usecnt_lock); usecnt++; ast_mutex_unlock(&usecnt_lock); ast_update_use_count(); }
static void g723_close(struct ast_filestream *s) { struct ast_filestream *tmp, *tmpl = NULL; if (ast_mutex_lock(&g723_lock)) { ast_log(LOG_WARNING, "Unable to lock g723 list\n"); return; } tmp = glist; while(tmp) { if (tmp == s) { if (tmpl) tmpl->next = tmp->next; else glist = tmp->next; break; } tmpl = tmp; tmp = tmp->next; } glistcnt--; if (s->owner) { s->owner->stream = NULL; if (s->owner->streamid > -1) ast_sched_del(s->owner->sched, s->owner->streamid); s->owner->streamid = -1; } ast_mutex_unlock(&g723_lock); ast_update_use_count(); if (!tmp) ast_log(LOG_WARNING, "Freeing a filestream we don't seem to own\n"); close(s->fd); free(s); s = NULL; }
static int phone_hangup(struct ast_channel *ast) { struct phone_pvt *p; p = ast->pvt->pvt; if (option_debug) ast_log(LOG_DEBUG, "phone_hangup(%s)\n", ast->name); if (!ast->pvt->pvt) { ast_log(LOG_WARNING, "Asked to hangup channel not connected\n"); return 0; } /* XXX Is there anything we can do to really hang up except stop recording? */ ast_setstate(ast, AST_STATE_DOWN); if (ioctl(p->fd, PHONE_REC_STOP)) ast_log(LOG_WARNING, "Failed to stop recording\n"); if (ioctl(p->fd, PHONE_PLAY_STOP)) ast_log(LOG_WARNING, "Failed to stop playing\n"); if (ioctl(p->fd, PHONE_RING_STOP)) ast_log(LOG_WARNING, "Failed to stop ringing\n"); if (ioctl(p->fd, PHONE_CPT_STOP)) ast_log(LOG_WARNING, "Failed to stop sounds\n"); /* If it's an FXO, hang them up */ if (p->mode == MODE_FXO) { if (ioctl(p->fd, PHONE_PSTN_SET_STATE, PSTN_ON_HOOK)) ast_log(LOG_DEBUG, "ioctl(PHONE_PSTN_SET_STATE) failed on %s (%s)\n",ast->name, strerror(errno)); } /* If they're off hook, give a busy signal */ if (ioctl(p->fd, PHONE_HOOKSTATE)) { if (option_debug) ast_log(LOG_DEBUG, "Got hunghup, giving busy signal\n"); ioctl(p->fd, PHONE_BUSY); p->cpt = 1; } p->lastformat = -1; p->lastinput = -1; p->ministate = 0; p->obuflen = 0; p->dialtone = 0; memset(p->ext, 0, sizeof(p->ext)); ((struct phone_pvt *)(ast->pvt->pvt))->owner = NULL; ast_mutex_lock(&usecnt_lock); usecnt--; if (usecnt < 0) ast_log(LOG_WARNING, "Usecnt < 0???\n"); ast_mutex_unlock(&usecnt_lock); ast_update_use_count(); if (option_verbose > 2) ast_verbose( VERBOSE_PREFIX_3 "Hungup '%s'\n", ast->name); ast->pvt->pvt = NULL; ast_setstate(ast, AST_STATE_DOWN); restart_monitor(); return 0; }
static void gsm_close(struct ast_filestream *s) { if (ast_mutex_lock(&gsm_lock)) { ast_log(LOG_WARNING, "Unable to lock gsm list\n"); return; } glistcnt--; ast_mutex_unlock(&gsm_lock); ast_update_use_count(); fclose(s->f); free(s); }
static void exit_now(GtkWidget *widget, gpointer data) { ast_loader_unregister(mod_update); gtk_main_quit(); inuse--; ast_update_use_count(); ast_unregister_verbose(verboser); ast_unload_resource("pbx_gtkconsole", 0); if (option_verbose > 1) ast_verbose(VERBOSE_PREFIX_2 "GTK Console Monitor Exiting\n"); /* XXX Trying to quit after calling this makes asterisk segfault XXX */ }
static int g729tolin_new(struct ast_trans_pvt *pvt) { int i; struct g729_coder_pvt *tmp = pvt->pvt; //tmp = malloc(sizeof(struct g729_coder_pvt)); if(tmp) { USC_CODEC_Fxns->std.GetInfo((USC_Handle)NULL, &(tmp->pInfo)); ((USC_Option*)tmp->pInfo.params)->modes.bitrate = 0; ((USC_Option*)tmp->pInfo.params)->modes.truncate = 1; ((USC_Option*)tmp->pInfo.params)->direction = 1; /* tmp->bitstream_buf = ippsMalloc_8s(size); */ USC_CODEC_Fxns->std.NumAlloc(tmp->pInfo.params, &tmp->nbanks); if(!(tmp->pBanks = (USC_MemBank*)ippsMalloc_8u(sizeof(USC_MemBank)*(tmp->nbanks)))) { ast_log(LOG_WARNING, "ippsMalloc_8u failed allocating %d bytes", sizeof(USC_MemBank)*(tmp->nbanks)); return 1; } USC_CODEC_Fxns->std.MemAlloc(tmp->pInfo.params, tmp->pBanks); for(i=0; i<tmp->nbanks;i++) { if(!(tmp->pBanks[i].pMem = ippsMalloc_8u(tmp->pBanks->nbytes))) { ast_log(LOG_WARNING, "ippsMalloc_8u failed allocating %d bytes", sizeof(USC_MemBank)*(tmp->nbanks)); /* printf("\nLow memory: %d bytes not allocated\n", tmp->pBanks->nbytes); */ return 1; } } tmp->outFrameSize = getOutFrameSize(); /* pcm_buf ippsMalloc_8s(getOutFrameSize()); */ tmp->maxbitsize = tmp->pInfo.maxbitsize; USC_CODEC_Fxns->std.Init(tmp->pInfo.params, tmp->pBanks, &(tmp->codec)); #ifndef IPPCORE_NO_SSE ippCoreSetFlushToZero( 1, NULL ); #endif tmp->bitStream.nbytes = tmp->maxbitsize; tmp->bitStream.bitrate = 0; tmp->bitStream.frametype = 3; tmp->pcmStream.pBuffer = tmp->pcm_buf; tmp->pcmStream.pcmType.bitPerSample = 0; tmp->pcmStream.pcmType.sample_frequency = 0; USC_CODEC_Fxns->std.Reinit(&((USC_Option*)tmp->pInfo.params)->modes, tmp->codec); tmp->tail = 0; localusecnt++; ast_update_use_count(); } return 0; }
static struct ast_translator_pvt *g723tolin_new(void) { struct g723_decoder_pvt *tmp; tmp = malloc(sizeof(struct g723_decoder_pvt)); if (tmp) { Init_Decod(&tmp->dec); Init_Dec_Cng(&tmp->dec); tmp->tail = 0; localusecnt++; ast_update_use_count(); } return (struct ast_translator_pvt *)tmp; }
static void vox_close(struct ast_filestream *s) { if (ast_mutex_lock(&vox_lock)) { ast_log(LOG_WARNING, "Unable to lock vox list\n"); return; } glistcnt--; ast_mutex_unlock(&vox_lock); ast_update_use_count(); close(s->fd); free(s); s = NULL; }
static struct ast_channel *phone_new(struct phone_pvt *i, int state, char *context) { struct ast_channel *tmp; tmp = ast_channel_alloc(1); if (tmp) { snprintf(tmp->name, sizeof(tmp->name), "Phone/%s", i->dev + 5); tmp->type = type; tmp->fds[0] = i->fd; /* XXX Switching formats silently causes kernel panics XXX */ tmp->nativeformats = prefformat; tmp->pvt->rawreadformat = prefformat; tmp->pvt->rawwriteformat = prefformat; ast_setstate(tmp, state); if (state == AST_STATE_RING) tmp->rings = 1; tmp->pvt->pvt = i; tmp->pvt->send_digit = phone_digit; tmp->pvt->call = phone_call; tmp->pvt->hangup = phone_hangup; tmp->pvt->answer = phone_answer; tmp->pvt->read = phone_read; tmp->pvt->write = phone_write; tmp->pvt->exception = phone_exception; strncpy(tmp->context, context, sizeof(tmp->context)-1); if (strlen(i->ext)) strncpy(tmp->exten, i->ext, sizeof(tmp->exten)-1); else strncpy(tmp->exten, "s", sizeof(tmp->exten) - 1); if (strlen(i->language)) strncpy(tmp->language, i->language, sizeof(tmp->language)-1); if (strlen(i->callerid)) tmp->callerid = strdup(i->callerid); i->owner = tmp; ast_mutex_lock(&usecnt_lock); usecnt++; ast_mutex_unlock(&usecnt_lock); ast_update_use_count(); if (state != AST_STATE_DOWN) { if (state == AST_STATE_RING) { ioctl(tmp->fds[0], PHONE_RINGBACK); i->cpt = 1; } if (ast_pbx_start(tmp)) { ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name); ast_hangup(tmp); } } } else ast_log(LOG_WARNING, "Unable to allocate channel structure\n"); return tmp; }
void* ooh323c_call_thread(void* dummy) { struct callthread* mycthread = (struct callthread *)dummy; struct pollfd pfds[1]; char c; int res = 0; do { ooMonitorCallChannels((ooCallData*)mycthread->call); mycthread->call = NULL; mycthread->prev = NULL; mycthread->inUse = FALSE; ast_mutex_lock(&callThreadsLock); mycthread->next = callThreads; callThreads = mycthread; if (mycthread->next) mycthread->next->prev = mycthread; ast_mutex_unlock(&callThreadsLock); pfds[0].fd = mycthread->thePipe[0]; pfds[0].events = POLLIN; ooSocketPoll(pfds, 1, SEC_TO_HOLD_THREAD * 1000); if (ooPDRead(pfds, 1, mycthread->thePipe[0])) res = read(mycthread->thePipe[0], &c, 1); ast_mutex_lock(&callThreadsLock); ast_mutex_lock(&mycthread->lock); if (mycthread->prev) mycthread->prev->next = mycthread->next; else callThreads = mycthread->next; if (mycthread->next) mycthread->next->prev = mycthread->prev; ast_mutex_unlock(&mycthread->lock); ast_mutex_unlock(&callThreadsLock); } while (mycthread->call != NULL && res >= 0); ast_mutex_destroy(&mycthread->lock); close(mycthread->thePipe[0]); close(mycthread->thePipe[1]); ast_free(mycthread); ast_module_unref(myself); ast_update_use_count(); return NULL; }
static void g729_release(struct ast_trans_pvt *pvt) { struct g729_coder_pvt *tmp = pvt->pvt; int i; for(i = 0; i < tmp->nbanks; i++) { if(tmp->pBanks[i].pMem) ippsFree(tmp->pBanks[i].pMem); tmp->pBanks[i].pMem=NULL; } if(tmp->pBanks) ippsFree(tmp->pBanks); //free(tmp); localusecnt--; ast_update_use_count(); }
static void g723_release(struct ast_trans_pvt *pvt) { struct g723_coder_pvt *tmp = pvt->pvt; int i; if(tmp->encoder != NULL) { /* Free an encoder instance */ ippsFree(tmp->encoder); } else { /* Free a decoder instance */ ippsFree(tmp->decoder); } //free(pvt); localusecnt--; ast_update_use_count(); }
static struct ast_translator_pvt *lintog723_new(void) { struct g723_encoder_pvt *tmp; tmp = malloc(sizeof(struct g723_encoder_pvt)); if (tmp) { Init_Coder(&tmp->cod); /* Init Comfort Noise Functions */ if( UseVx ) { Init_Vad(&tmp->cod); Init_Cod_Cng(&tmp->cod); } localusecnt++; ast_update_use_count(); tmp->tail = 0; } return (struct ast_translator_pvt *)tmp; }
static void wav_close(struct ast_filestream *s) { char zero = 0; if (ast_mutex_lock(&wav_lock)) { ast_log(LOG_WARNING, "Unable to lock wav list\n"); return; } glistcnt--; ast_mutex_unlock(&wav_lock); ast_update_use_count(); /* Pad to even length */ if (s->bytes & 0x1) write(s->fd, &zero, 1); close(s->fd); free(s); s = NULL; }
static int g723tolin_new(struct ast_trans_pvt *pvt) { int i; struct g723_coder_pvt *tmp = pvt->pvt; int dSize; //tmp = malloc(sizeof(struct g723_coder_pvt)); if(tmp) { apiG723Decoder_Alloc(&dSize); tmp->encoder = NULL; tmp->decoder = (G723Decoder_Obj *)ippsMalloc_8u(dSize); apiG723Decoder_Init(tmp->decoder, 0); tmp->tail = 0; localusecnt++; ast_update_use_count(); } return 0; }
static int lintog723_new(struct ast_trans_pvt *pvt) { int i; struct g723_coder_pvt *tmp = pvt->pvt; int eSize; //tmp = malloc(sizeof(struct g723_coder_pvt)); if(tmp) { apiG723Encoder_Alloc(&eSize); tmp->encoder = (G723Encoder_Obj*)ippsMalloc_8u(eSize); tmp->decoder = NULL; tmp->sendRate = defaultSendRate; // Init, no VAD or silence compression apiG723Encoder_Init(tmp->encoder, 0); tmp->tail = 0; localusecnt++; ast_update_use_count(); } return 0; }
int load_module(void) { if (pipe(clipipe)) { ast_log(LOG_WARNING, "Unable to create CLI pipe\n"); return -1; } g_thread_init(NULL); if (gtk_init_check(NULL, NULL)) { if (!show_console()) { inuse++; ast_update_use_count(); if (option_verbose > 1) ast_verbose( VERBOSE_PREFIX_2 "Launched GTK Console monitor\n"); } else ast_log(LOG_WARNING, "Unable to start GTK console\n"); } else { if (option_debug) ast_log(LOG_DEBUG, "Unable to start GTK console monitor -- ignoring\n"); else if (option_verbose > 1) ast_verbose( VERBOSE_PREFIX_2 "GTK is not available -- skipping monitor\n"); } return 0; }
static struct ast_filestream *pcm_rewrite(FILE *f, const char *comment) { /* We don't have any header to read or anything really, but if we did, it would go here. We also might want to check and be sure it's a valid file. */ struct ast_filestream *tmp; if ((tmp = malloc(sizeof(struct ast_filestream)))) { memset(tmp, 0, sizeof(struct ast_filestream)); if (ast_mutex_lock(&pcm_lock)) { ast_log(LOG_WARNING, "Unable to lock pcm list\n"); free(tmp); return NULL; } tmp->f = f; #ifdef REALTIME_WRITE tmp->start_time = get_time(); #endif glistcnt++; ast_mutex_unlock(&pcm_lock); ast_update_use_count(); } else ast_log(LOG_WARNING, "Out of memory\n"); return tmp; }
static void g723_destroy(struct ast_translator_pvt *pvt) { free(pvt); localusecnt--; ast_update_use_count(); }
static void phone_check_exception(struct phone_pvt *i) { int offhook=0; char digit[2] = {0 , 0}; union telephony_exception phonee; /* XXX Do something XXX */ #if 0 ast_log(LOG_DEBUG, "Exception!\n"); #endif phonee.bytes = ioctl(i->fd, PHONE_EXCEPTION); if (phonee.bits.dtmf_ready) { digit[0] = ioctl(i->fd, PHONE_GET_DTMF_ASCII); if (i->mode == MODE_DIALTONE) { ioctl(i->fd, PHONE_PLAY_STOP); ioctl(i->fd, PHONE_REC_STOP); ioctl(i->fd, PHONE_CPT_STOP); i->dialtone = 0; if (strlen(i->ext) < AST_MAX_EXTENSION - 1) strncat(i->ext, digit, sizeof(i->ext) - strlen(i->ext) - 1); if (ast_exists_extension(NULL, i->context, i->ext, 1, i->callerid)) { /* It's a valid extension in its context, get moving! */ phone_new(i, AST_STATE_RING, i->context); /* No need to restart monitor, we are the monitor */ if (i->owner) { ast_mutex_lock(&usecnt_lock); usecnt--; ast_mutex_unlock(&usecnt_lock); ast_update_use_count(); } } else if (!ast_canmatch_extension(NULL, i->context, i->ext, 1, i->callerid)) { /* There is nothing in the specified extension that can match anymore. Try the default */ if (ast_exists_extension(NULL, "default", i->ext, 1, i->callerid)) { /* Check the default, too... */ phone_new(i, AST_STATE_RING, "default"); if (i->owner) { ast_mutex_lock(&usecnt_lock); usecnt--; ast_mutex_unlock(&usecnt_lock); ast_update_use_count(); } /* XXX This should probably be justified better XXX */ } else if (!ast_canmatch_extension(NULL, "default", i->ext, 1, i->callerid)) { /* It's not a valid extension, give a busy signal */ if (option_debug) ast_log(LOG_DEBUG, "%s can't match anything in %s or default\n", i->ext, i->context); ioctl(i->fd, PHONE_BUSY); i->cpt = 1; } } #if 0 ast_verbose("Extension is %s\n", i->ext); #endif } } if (phonee.bits.hookstate) { offhook = ioctl(i->fd, PHONE_HOOKSTATE); if (offhook) { if (i->mode == MODE_IMMEDIATE) { phone_new(i, AST_STATE_RING, i->context); } else if (i->mode == MODE_DIALTONE) { ast_mutex_lock(&usecnt_lock); usecnt++; ast_mutex_unlock(&usecnt_lock); ast_update_use_count(); /* Reset the extension */ i->ext[0] = '\0'; /* Play the dialtone */ i->dialtone++; ioctl(i->fd, PHONE_PLAY_STOP); ioctl(i->fd, PHONE_PLAY_CODEC, ULAW); ioctl(i->fd, PHONE_PLAY_START); i->lastformat = -1; } } else { if (i->dialtone) { ast_mutex_lock(&usecnt_lock); usecnt--; ast_mutex_unlock(&usecnt_lock); ast_update_use_count(); } memset(i->ext, 0, sizeof(i->ext)); if (i->cpt) { ioctl(i->fd, PHONE_CPT_STOP); i->cpt = 0; } ioctl(i->fd, PHONE_PLAY_STOP); ioctl(i->fd, PHONE_REC_STOP); i->dialtone = 0; i->lastformat = -1; } } if (phonee.bits.pstn_ring) { ast_verbose("Unit is ringing\n"); phone_new(i, AST_STATE_RING, i->context); } if (phonee.bits.caller_id) ast_verbose("We have caller ID\n"); }