Workaround for "noise" problems with app_rxfax in current LCR.
[lcr.git] / chan_lcr.c
index edf38a7..f4d8378 100644 (file)
@@ -881,8 +881,11 @@ static void lcr_in_setup(struct chan_call *call, int message_type, union paramet
                strncpy(ast->context, param->setup.context, AST_MAX_CONTEXT-1);
        else
                strncpy(ast->context, param->setup.callerinfo.interface, AST_MAX_CONTEXT-1);
+       memset(&ast->cid, 0, sizeof(ast->cid));
        if (param->setup.callerinfo.id[0])
                ast->cid.cid_num = strdup(param->setup.callerinfo.id);
+       if (param->setup.callerinfo.id2[0])
+               ast->cid.cid_ani = strdup(param->setup.callerinfo.id2);
        if (param->setup.callerinfo.name[0])
                ast->cid.cid_name = strdup(param->setup.callerinfo.name);
        if (param->setup.redirinfo.id[0])
@@ -2169,24 +2172,38 @@ static int lcr_hangup(struct ast_channel *ast)
        return 0;
 }
 
-static int lcr_write(struct ast_channel *ast, struct ast_frame *f)
+static int lcr_write(struct ast_channel *ast, struct ast_frame *fr)
 {
         struct chan_call *call;
+       struct ast_frame * f = fr;
 
        if (!f->subclass)
                CDEBUG(NULL, ast, "No subclass\n");
-       if (!(f->subclass & ast->nativeformats))
-               CDEBUG(NULL, ast, "Unexpected format.\n");
+       if (!(f->subclass & ast->nativeformats)) {
+               CDEBUG(NULL, ast, 
+                      "Unexpected format. "
+                      "Activating emergency conversion...\n");
+
+               ast_set_write_format(ast, f->subclass);
+               f = (ast->writetrans) ? ast_translate(
+                       ast->writetrans, fr, 0) : fr;
+       }
        
        ast_mutex_lock(&chan_lock);
         call = ast->tech_pvt;
        if (!call) {
                ast_mutex_unlock(&chan_lock);
+               if (f != fr) {
+                       ast_frfree(f);
+               }
                return -1;
        }
        if (call->bchannel && f->samples)
                bchannel_transmit(call->bchannel, *((unsigned char **)&(f->data)), f->samples);
        ast_mutex_unlock(&chan_lock);
+       if (f != fr) {
+               ast_frfree(f);
+       }
        return 0;
 }
 
@@ -2194,7 +2211,7 @@ static int lcr_write(struct ast_channel *ast, struct ast_frame *f)
 static struct ast_frame *lcr_read(struct ast_channel *ast)
 {
         struct chan_call *call;
-       int len;
+       int len = 0;
 
        ast_mutex_lock(&chan_lock);
         call = ast->tech_pvt;