rebuffer option for chan_lcr (160 bytes per frame)
authorschlaile <root@asterisk.schlaile.de>
Sun, 20 Jul 2008 17:33:28 +0000 (19:33 +0200)
committerroot <root@asterisk.schlaile.de>
Sun, 20 Jul 2008 17:33:28 +0000 (19:33 +0200)
l1-link state "unknown" if not known yet.

removed root user check.

modified:   bchannel.c
modified:   bchannel.h
modified:   chan_lcr.c
modified:   chan_lcr.h
modified:   dss1.cpp
modified:   lcradmin.c
modified:   mISDN.cpp
modified:   main.c

bchannel.c
bchannel.h
chan_lcr.c
chan_lcr.h
dss1.cpp
lcradmin.c
mISDN.cpp
main.c

index 73ea2f8..346374b 100644 (file)
@@ -195,6 +195,7 @@ void bchannel_activate(struct bchannel *bchannel, int activate)
                CERROR(NULL, NULL, "Failed to send to socket %d\n", bchannel->b_sock);
 
        bchannel->b_state = (activate)?BSTATE_ACTIVATING:BSTATE_DEACTIVATING;
                CERROR(NULL, NULL, "Failed to send to socket %d\n", bchannel->b_sock);
 
        bchannel->b_state = (activate)?BSTATE_ACTIVATING:BSTATE_DEACTIVATING;
+       bchannel->rebuffer_usage = 0;
 }
 
 
 }
 
 
@@ -249,6 +250,7 @@ void bchannel_destroy(struct bchannel *bchannel)
        {
                close(bchannel->b_sock);
                bchannel->b_sock = -1;
        {
                close(bchannel->b_sock);
                bchannel->b_sock = -1;
+               bchannel->rebuffer_usage = 0;
        }
        bchannel->b_state = BSTATE_IDLE;
 }
        }
        bchannel->b_state = BSTATE_IDLE;
 }
@@ -346,17 +348,63 @@ static void bchannel_receive(struct bchannel *bchannel, unsigned char *buffer, i
                /* return, because we have no audio from port */
                return;
        }
                /* return, because we have no audio from port */
                return;
        }
-       if (bchannel->call->pipe[1] > -1)
+
+       if (bchannel->call->pipe[1] < 0)
        {
        {
+               /* nobody there */
+               return;
+       }
+
+
+       if (bchannel->call->rebuffer) {
+               int u = bchannel->rebuffer_usage;
+               unsigned char * b = bchannel->rebuffer;
+               unsigned char * d = data;
+               int l = len;
+               int fd = bchannel->call->pipe[1];
+
+               if (u > 0) {
+                       if (u + l >= 160) {
+                               memcpy(b + u, d, 160 - u);
+                               d += 160 - u;
+                               l -= 160 - u;
+                               u = 0;
+                               if (write(fd, b, 160) < 0) {
+                                       goto errout;
+                               }
+                       } else {
+                               memcpy(b + u, d, l);
+                               u += l;
+                               l = 0;
+                       }
+               }
+
+               while (l >= 160) {
+                       if (write(fd, d, 160) < 0) {
+                               goto errout;
+                       }
+                       d += 160;
+                       l -= 160;
+               }
+
+               if (l > 0) {
+                       memcpy(b, d, l);
+               } 
+               bchannel->rebuffer_usage = u + l;
+       } else {
                len = write(bchannel->call->pipe[1], data, len);
                if (len < 0)
                {
                len = write(bchannel->call->pipe[1], data, len);
                if (len < 0)
                {
-                       close(bchannel->call->pipe[1]);
-                       bchannel->call->pipe[1] = -1;
-                       CDEBUG(NULL, NULL, "broken pipe on bchannel pipe\n");
-                       return;
+                       goto errout;
                }
        }
                }
        }
+
+       return;
+ errout:
+       close(bchannel->call->pipe[1]);
+       bchannel->call->pipe[1] = -1;
+       bchannel->rebuffer_usage = 0;
+       CDEBUG(NULL, NULL, "broken pipe on bchannel pipe\n");
 }
 
 
 }
 
 
index f7b3860..267f8b7 100644 (file)
@@ -30,6 +30,8 @@ struct bchannel {
        int b_dtmf;
        int b_bf_len;
        unsigned char b_bf_key[128];
        int b_dtmf;
        int b_bf_len;
        unsigned char b_bf_key[128];
+       int rebuffer_usage;
+       unsigned char rebuffer[160];
 };
 
 
 };
 
 
index ff8da54..dc7ebed 100644 (file)
@@ -475,6 +475,14 @@ void apply_opt(struct chan_call *call, char *data)
                        if (call->bchannel)
                                bchannel_pipeline(call->bchannel, call->pipeline);
                        break;
                        if (call->bchannel)
                                bchannel_pipeline(call->bchannel, call->pipeline);
                        break;
+               case 'r':
+                       if (opt[1] == '\0') {
+                               CERROR(call, call->ast, "Option 'r' (re-buffer 160 bytes) expects no parameter.\n", opt);
+                               break;
+                       }
+                       CDEBUG(call, call->ast, "Option 'r' (re-buffer 160 bytes)");
+                       call->rebuffer = 1;
+                       break;
 #if 0
                case 's':
                        if (opt[1] != '\0') {
 #if 0
                case 's':
                        if (opt[1] != '\0') {
index 69d4dc5..bc61c07 100644 (file)
@@ -53,6 +53,8 @@ struct chan_call {
                                        /* shall dtmf be enabled */
        int                     no_dtmf;
                                        /* dtmf disabled by option */
                                        /* shall dtmf be enabled */
        int                     no_dtmf;
                                        /* dtmf disabled by option */
+        int                     rebuffer; /* send only 160 bytes frames
+                                            to asterisk */
        char                    pipeline[256];
                                        /* echo cancel pipeline by option */
        int                     tx_gain, rx_gain;
        char                    pipeline[256];
                                        /* echo cancel pipeline by option */
        int                     tx_gain, rx_gain;
index d4e90e6..06bb203 100644 (file)
--- a/dss1.cpp
+++ b/dss1.cpp
@@ -1193,14 +1193,17 @@ void Pdss1::release_complete_ind(unsigned int cmd, unsigned int pid, struct l3_m
        
        l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_IND, DIRECTION_IN);
        /* in case layer 2 is down during setup, we send cause 27 loc 5 */
        
        l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_IND, DIRECTION_IN);
        /* in case layer 2 is down during setup, we send cause 27 loc 5 */
-       if (p_state == PORT_STATE_OUT_SETUP && !p_m_mISDNport->l1link)
+       if (p_state == PORT_STATE_OUT_SETUP && p_m_mISDNport->l1link == 0)
        {
                cause = 27;
                location = 5;
        } else
        {
                dec_ie_cause(l3m, &location, &cause);
        {
                cause = 27;
                location = 5;
        } else
        {
                dec_ie_cause(l3m, &location, &cause);
-               add_trace("layer 1", NULL, (p_m_mISDNport->l1link)?"up":"down");
+               if (p_m_mISDNport->l1link < 0)
+                       add_trace("layer 1", NULL, "unknown");
+               else
+                       add_trace("layer 1", NULL, (p_m_mISDNport->l1link)?"up":"down");
        }
        end_trace();
        if (location == LOCATION_PRIVATE_LOCAL)
        }
        end_trace();
        if (location == LOCATION_PRIVATE_LOCAL)
index fbd0015..288bebd 100644 (file)
@@ -679,8 +679,11 @@ char *admin_state(int sock, char *argv[])
                                        color((m[i].u.i.l2link)?green:red);
                                        addstr((m[i].u.i.l2link)?"  L2 UP":"  L2 down");
                                }
                                        color((m[i].u.i.l2link)?green:red);
                                        addstr((m[i].u.i.l2link)?"  L2 UP":"  L2 down");
                                }
-                               color((m[i].u.i.l1link)?green:blue);
-                               addstr((m[i].u.i.l1link)?"  L1 ACTIVE":"  L1 inactive");
+                               color((m[i].u.i.l1link > 0)?green:blue);
+                               if (m[i].u.i.l1link < 0)
+                                       addstr("  L1 unknown");
+                               else
+                                       addstr((m[i].u.i.l1link)?"  L1 ACTIVE":"  L1 inactive");
                                if (m[i].u.i.los)
                                {
                                        color(red);
                                if (m[i].u.i.los)
                                {
                                        color(red);
index 20ec026..e8a71cc 100644 (file)
--- a/mISDN.cpp
+++ b/mISDN.cpp
@@ -2215,6 +2215,7 @@ struct mISDNport *mISDNport_open(int port, int ptp, int force_nt, int l2hold, st
        while(*mISDNportp)
                mISDNportp = &((*mISDNportp)->next);
        mISDNport = (struct mISDNport *)MALLOC(sizeof(struct mISDNport));
        while(*mISDNportp)
                mISDNportp = &((*mISDNportp)->next);
        mISDNport = (struct mISDNport *)MALLOC(sizeof(struct mISDNport));
+       mISDNport->l1link = -1;
        pmemuse++;
        *mISDNportp = mISDNport;
 
        pmemuse++;
        *mISDNportp = mISDNport;
 
diff --git a/main.c b/main.c
index 49d7fe4..cf6be07 100644 (file)
--- a/main.c
+++ b/main.c
@@ -226,13 +226,6 @@ int main(int argc, char *argv[])
        /* init crc */
        crc_init();
 
        /* init crc */
        crc_init();
 
-       /* check for root (real or effective) */
-       if (getuid() && geteuid())
-       {
-               fprintf(stderr, "Please run %s as super-user.\n", NAME);
-               goto free;
-       }
-
        /* the mutex init */
        if (pthread_mutex_init(&mutexd, NULL))
        {
        /* the mutex init */
        if (pthread_mutex_init(&mutexd, NULL))
        {