Workaround for "noise" problems with app_rxfax in current LCR.
authorPeter Schlaile <peter@schlaile.de>
Tue, 7 Dec 2010 11:06:14 +0000 (12:06 +0100)
committerroot <peter@schlaile.de>
Tue, 7 Dec 2010 11:06:14 +0000 (12:06 +0100)
The problem: for some reason, asterisk silently switches write_format
from SLINEAR to ALAW when using app_rxfax, thereby effectively disabling
automatic conversion SLINEAR->ALAW and thereby breaking app_rxfax after
the first call to ast_write(). Read: instantly, after the first data frame.

Older versions of LCR work flawlessly, until we find out, what really triggers
the problem, we at least switch the channel back, since it never makes
sense to send something different than ALAW to chan_lcr.

chan_lcr.c

index 25515d0..f4d8378 100644 (file)
@@ -2172,24 +2172,38 @@ static int lcr_hangup(struct ast_channel *ast)
        return 0;
 }
 
        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 chan_call *call;
+       struct ast_frame * f = fr;
 
        if (!f->subclass)
                CDEBUG(NULL, ast, "No subclass\n");
 
        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);
        
        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);
                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;
 }
 
        return 0;
 }