Don't do reinvite if both parties talk diffrent codecs
[asterisk/asterisk.git] / channels / chan_alsa.c
index be760b8..d17d1e3 100755 (executable)
@@ -71,7 +71,7 @@ static int silencethreshold = 1000;
 static char digits[80] = "";
 static char text2send[80] = "";
 
-static pthread_mutex_t usecnt_lock = AST_MUTEX_INITIALIZER;
+static ast_mutex_t usecnt_lock = AST_MUTEX_INITIALIZER;
 
 static char *type = "Console";
 static char *desc = "ALSA Console Channel Driver";
@@ -122,7 +122,7 @@ static struct chan_alsa_pvt {
        
 } alsa;
 
-static int time_has_passed()
+static int time_has_passed(void)
 {
        struct timeval tv;
        int ms;
@@ -262,7 +262,7 @@ static void *sound_thread(void *unused)
                                max = readdev;
                }
 #endif
-               res = select(max + 1, &rfds, &wfds, NULL, NULL);
+               res = ast_select(max + 1, &rfds, &wfds, NULL, NULL);
                if (res < 1) {
                        ast_log(LOG_WARNING, "select failed: %s\n", strerror(errno));
                        continue;
@@ -423,7 +423,7 @@ static snd_pcm_t *alsa_card_init(char *dev, snd_pcm_stream_t stream)
        }
 #endif
 
-       err = snd_pcm_sw_params_set_silence_threshold(handle, swparams, buffer_size);
+       err = snd_pcm_sw_params_set_silence_threshold(handle, swparams, silencethreshold);
        if (err < 0) {
                ast_log(LOG_ERROR, "Unable to set silence threshold: %s\n", snd_strerror(err));
        }
@@ -453,7 +453,7 @@ static snd_pcm_t *alsa_card_init(char *dev, snd_pcm_stream_t stream)
        return handle;
 }
 
-static int soundcard_init()
+static int soundcard_init(void)
 {
        alsa.icard = alsa_card_init(indevname, SND_PCM_STREAM_CAPTURE);
        alsa.ocard = alsa_card_init(outdevname, SND_PCM_STREAM_PLAYBACK);
@@ -506,7 +506,7 @@ static int alsa_answer(struct ast_channel *c)
 {
        ast_verbose( " << Console call has been answered >> \n");
        answer_sound();
-       c->state = AST_STATE_UP;
+       ast_setstate(c, AST_STATE_UP);
        cursound = -1;
        return 0;
 }
@@ -518,9 +518,9 @@ static int alsa_hangup(struct ast_channel *c)
        c->pvt->pvt = NULL;
        alsa.owner = NULL;
        ast_verbose( " << Hangup on console >> \n");
-       ast_pthread_mutex_lock(&usecnt_lock);
+       ast_mutex_lock(&usecnt_lock);
        usecnt--;
-       ast_pthread_mutex_unlock(&usecnt_lock);
+       ast_mutex_unlock(&usecnt_lock);
        needhangup = 0;
        needanswer = 0;
        if (hookstate) {
@@ -646,7 +646,7 @@ static struct ast_frame *alsa_read(struct ast_channel *chan)
        
        f.frametype = AST_FRAME_NULL;
        f.subclass = 0;
-       f.timelen = 0;
+       f.samples = 0;
        f.datalen = 0;
        f.data = NULL;
        f.offset = 0;
@@ -684,7 +684,7 @@ static struct ast_frame *alsa_read(struct ast_channel *chan)
                needanswer = 0;
                f.frametype = AST_FRAME_CONTROL;
                f.subclass = AST_CONTROL_ANSWER;
-               chan->state = AST_STATE_UP;
+               ast_setstate(chan, AST_STATE_UP);
                return &f;
        }
        
@@ -722,13 +722,13 @@ static struct ast_frame *alsa_read(struct ast_channel *chan)
                /* A real frame */
                readpos = 0;
                left = FRAME_SIZE;
-               if (chan->state != AST_STATE_UP) {
+               if (chan->_state != AST_STATE_UP) {
                        /* Don't transmit unless it's up */
                        return &f;
                }
                f.frametype = AST_FRAME_VOICE;
                f.subclass = AST_FORMAT_SLINEAR;
-               f.timelen = FRAME_SIZE / 8;
+               f.samples = FRAME_SIZE;
                f.datalen = FRAME_SIZE * 2;
                f.data = buf;
                f.offset = AST_FRIENDLY_OFFSET;
@@ -806,10 +806,10 @@ static struct ast_channel *alsa_new(struct chan_alsa_pvt *p, int state)
                if (strlen(language))
                        strncpy(tmp->language, language, sizeof(tmp->language)-1);
                p->owner = tmp;
-               tmp->state = state;
-               ast_pthread_mutex_lock(&usecnt_lock);
+               ast_setstate(tmp, state);
+               ast_mutex_lock(&usecnt_lock);
                usecnt++;
-               ast_pthread_mutex_unlock(&usecnt_lock);
+               ast_mutex_unlock(&usecnt_lock);
                ast_update_use_count();
                if (state != AST_STATE_DOWN) {
                        if (ast_pbx_start(tmp)) {
@@ -905,8 +905,8 @@ static char sendtext_usage[] =
 
 static int console_sendtext(int fd, int argc, char *argv[])
 {
-       int tmparg = 1;
-       if (argc < 1)
+       int tmparg = 2;
+       if (argc < 2)
                return RESULT_SHOWUSAGE;
        if (!alsa.owner) {
                ast_cli(fd, "No one is calling us\n");
@@ -968,9 +968,11 @@ static int console_dial(int fd, int argc, char *argv[])
        mye = exten;
        myc = context;
        if (argc == 2) {
+               char *stringp=NULL;
                strncpy(tmp, argv[1], sizeof(tmp)-1);
-               strtok(tmp, "@");
-               tmp2 = strtok(NULL, "@");
+               stringp=tmp;
+               strsep(&stringp, "@");
+               tmp2 = strsep(&stringp, "@");
                if (strlen(tmp))
                        mye = tmp;
                if (tmp2 && strlen(tmp2))
@@ -995,7 +997,7 @@ static struct ast_cli_entry myclis[] = {
        { { "answer", NULL }, console_answer, "Answer an incoming console call", answer_usage },
        { { "hangup", NULL }, console_hangup, "Hangup a call on the console", hangup_usage },
        { { "dial", NULL }, console_dial, "Dial an extension on the console", dial_usage },
-       { { "send text", NULL }, console_sendtext, "Send text to the remote device", sendtext_usage },
+       { { "send", "text", NULL }, console_sendtext, "Send text to the remote device", sendtext_usage },
        { { "autoanswer", NULL }, console_autoanswer, "Sets/displays autoanswer", autoanswer_usage, autoanswer_complete }
 };
 
@@ -1004,7 +1006,7 @@ int load_module()
        int res;
        int x;
        int flags;
-       struct ast_config *cfg = ast_load(config);
+       struct ast_config *cfg;
        struct ast_variable *v;
        res = pipe(cmd);
        res = pipe(sndcmd);
@@ -1037,7 +1039,7 @@ int load_module()
        }
        for (x=0;x<sizeof(myclis)/sizeof(struct ast_cli_entry); x++)
                ast_cli_register(myclis + x);
-       if (cfg) {
+       if ((cfg = ast_load(config))) {
                v = ast_variable_browse(cfg, "general");
                while(v) {
                        if (!strcasecmp(v->name, "autoanswer"))
@@ -1087,7 +1089,7 @@ int unload_module()
                close(sndcmd[1]);
        }
        if (alsa.owner)
-               ast_softhangup(alsa.owner);
+               ast_softhangup(alsa.owner, AST_SOFTHANGUP_APPUNLOAD);
        if (alsa.owner)
                return -1;
        return 0;
@@ -1101,9 +1103,9 @@ char *description()
 int usecount()
 {
        int res;
-       ast_pthread_mutex_lock(&usecnt_lock);
+       ast_mutex_lock(&usecnt_lock);
        res = usecnt;
-       ast_pthread_mutex_unlock(&usecnt_lock);
+       ast_mutex_unlock(&usecnt_lock);
        return res;
 }