Merge "app_dial.c: Force COLP update if outgoing channel name changed."
authorMatt Jordan <mjordan@digium.com>
Tue, 29 Sep 2015 12:26:20 +0000 (07:26 -0500)
committerGerrit Code Review <gerrit2@gerrit.digium.api>
Tue, 29 Sep 2015 12:26:20 +0000 (07:26 -0500)
Makefile
apps/app_dial.c
codecs/codec_gsm.c
codecs/codec_ilbc.c
codecs/codec_lpc10.c
codecs/codec_speex.c
contrib/scripts/astversion [new file with mode: 0755]
main/translate.c
res/res_stasis.c

index f6a3d1f..bfa1ad9 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -578,6 +578,7 @@ main-bininstall:
        +@DESTDIR="$(DESTDIR)" ASTSBINDIR="$(ASTSBINDIR)" ASTLIBDIR="$(ASTLIBDIR)" $(SUBMAKE) -C main bininstall
 
 bininstall: _all installdirs $(SUBDIRS_INSTALL) main-bininstall
+       $(INSTALL) -m 755 contrib/scripts/astversion "$(DESTDIR)$(ASTSBINDIR)/"
        $(INSTALL) -m 755 contrib/scripts/astgenkey "$(DESTDIR)$(ASTSBINDIR)/"
        $(INSTALL) -m 755 contrib/scripts/autosupport "$(DESTDIR)$(ASTSBINDIR)/"
        if [ ! -f /sbin/launchd ]; then \
index 6461c40..f3f5276 100644 (file)
@@ -2724,7 +2724,7 @@ static int dial_exec_full(struct ast_channel *chan, const char *data, struct ast
                        chans[0] = chan;
                        chans[1] = peer;
 
-                       /* we need to stream the announcment while monitoring the caller for a hangup */
+                       /* we need to stream the announcement while monitoring the caller for a hangup */
 
                        /* stream the file */
                        res = ast_streamfile(peer, opt_args[OPT_ARG_ANNOUNCE], ast_channel_language(peer));
@@ -2803,7 +2803,6 @@ static int dial_exec_full(struct ast_channel *chan, const char *data, struct ast
                        if (ast_pbx_start(peer)) {
                                ast_autoservice_chan_hangup_peer(chan, peer);
                        }
-                       hanguptree(&out_chans, NULL, ast_test_flag64(&opts, OPT_CANCEL_ELSEWHERE) ? 1 : 0);
                        if (continue_exec)
                                *continue_exec = 1;
                        res = 0;
index 4660048..f80c955 100644 (file)
@@ -39,6 +39,7 @@ ASTERISK_REGISTER_FILE()
 #include "asterisk/config.h"
 #include "asterisk/module.h"
 #include "asterisk/utils.h"
+#include "asterisk/linkedlists.h"
 
 #ifdef HAVE_GSM_HEADER
 #include "gsm.h"
@@ -139,25 +140,35 @@ static int lintogsm_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
 static struct ast_frame *lintogsm_frameout(struct ast_trans_pvt *pvt)
 {
        struct gsm_translator_pvt *tmp = pvt->pvt;
-       int datalen = 0;
-       int samples = 0;
+       struct ast_frame *result = NULL;
+       struct ast_frame *last = NULL;
+       int samples = 0; /* output samples */
 
-       /* We can't work on anything less than a frame in size */
-       if (pvt->samples < GSM_SAMPLES)
-               return NULL;
        while (pvt->samples >= GSM_SAMPLES) {
+               struct ast_frame *current;
+
                /* Encode a frame of data */
-               gsm_encode(tmp->gsm, tmp->buf + samples, (gsm_byte *) pvt->outbuf.c + datalen);
-               datalen += GSM_FRAME_LEN;
+               gsm_encode(tmp->gsm, tmp->buf + samples, (gsm_byte *) pvt->outbuf.c);
                samples += GSM_SAMPLES;
                pvt->samples -= GSM_SAMPLES;
+
+               current = ast_trans_frameout(pvt, GSM_FRAME_LEN, GSM_SAMPLES);
+               if (!current) {
+                       continue;
+               } else if (last) {
+                       AST_LIST_NEXT(last, frame_list) = current;
+               } else {
+                       result = current;
+               }
+               last = current;
        }
 
        /* Move the data at the end of the buffer to the front */
-       if (pvt->samples)
+       if (samples) {
                memmove(tmp->buf, tmp->buf + samples, pvt->samples * 2);
+       }
 
-       return ast_trans_frameout(pvt, datalen, samples);
+       return result;
 }
 
 static void gsm_destroy_stuff(struct ast_trans_pvt *pvt)
index 8247f24..3e480e8 100644 (file)
@@ -37,6 +37,7 @@ ASTERISK_REGISTER_FILE()
 #include "asterisk/translate.h"
 #include "asterisk/module.h"
 #include "asterisk/utils.h"
+#include "asterisk/linkedlists.h"
 
 #ifdef ILBC_WEBRTC
 #include <ilbc.h>
@@ -150,31 +151,40 @@ static int lintoilbc_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
 static struct ast_frame *lintoilbc_frameout(struct ast_trans_pvt *pvt)
 {
        struct ilbc_coder_pvt *tmp = pvt->pvt;
-       int datalen = 0;
-       int samples = 0;
+       struct ast_frame *result = NULL;
+       struct ast_frame *last = NULL;
+       int samples = 0; /* output samples */
 
-       /* We can't work on anything less than a frame in size */
-       if (pvt->samples < ILBC_SAMPLES)
-               return NULL;
        while (pvt->samples >= ILBC_SAMPLES) {
+               struct ast_frame *current;
                ilbc_block tmpf[ILBC_SAMPLES];
                int i;
 
                /* Encode a frame of data */
                for (i = 0 ; i < ILBC_SAMPLES ; i++)
                        tmpf[i] = tmp->buf[samples + i];
-               iLBC_encode( (ilbc_bytes*)pvt->outbuf.BUF_TYPE + datalen, tmpf, &tmp->enc);
+               iLBC_encode((ilbc_bytes *) pvt->outbuf.BUF_TYPE, tmpf, &tmp->enc);
 
-               datalen += ILBC_FRAME_LEN;
                samples += ILBC_SAMPLES;
                pvt->samples -= ILBC_SAMPLES;
+
+               current = ast_trans_frameout(pvt, ILBC_FRAME_LEN, ILBC_SAMPLES);
+               if (!current) {
+                       continue;
+               } else if (last) {
+                       AST_LIST_NEXT(last, frame_list) = current;
+               } else {
+                       result = current;
+               }
+               last = current;
        }
 
        /* Move the data at the end of the buffer to the front */
-       if (pvt->samples)
+       if (samples) {
                memmove(tmp->buf, tmp->buf + samples, pvt->samples * 2);
+       }
 
-       return ast_trans_frameout(pvt, datalen, samples);
+       return result;
 }
 
 static struct ast_translator ilbctolin = {
index 49df8f7..e6dcf8c 100644 (file)
@@ -39,6 +39,7 @@ ASTERISK_REGISTER_FILE()
 #include "asterisk/config.h"
 #include "asterisk/module.h"
 #include "asterisk/utils.h"
+#include "asterisk/linkedlists.h"
 
 #include "lpc10/lpc10.h"
 
@@ -160,31 +161,45 @@ static int lintolpc10_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
 static struct ast_frame *lintolpc10_frameout(struct ast_trans_pvt *pvt)
 {
        struct lpc10_coder_pvt *tmp = pvt->pvt;
-       int x;
-       int datalen = 0;        /* output frame */
-       int samples = 0;        /* output samples */
-       float tmpbuf[LPC10_SAMPLES_PER_FRAME];
-       INT32 bits[LPC10_BITS_IN_COMPRESSED_FRAME];     /* XXX what ??? */
-       /* We can't work on anything less than a frame in size */
-       if (pvt->samples < LPC10_SAMPLES_PER_FRAME)
-               return NULL;
-       while (pvt->samples >=  LPC10_SAMPLES_PER_FRAME) {
+       struct ast_frame *result = NULL;
+       struct ast_frame *last = NULL;
+       int samples = 0; /* output samples */
+
+       while (pvt->samples >= LPC10_SAMPLES_PER_FRAME) {
+               struct ast_frame *current;
+               float tmpbuf[LPC10_SAMPLES_PER_FRAME];
+               INT32 bits[LPC10_BITS_IN_COMPRESSED_FRAME];     /* XXX what ??? */
+               int x;
+
                /* Encode a frame of data */
                for (x=0;x<LPC10_SAMPLES_PER_FRAME;x++)
                        tmpbuf[x] = (float)tmp->buf[x + samples] / 32768.0;
                lpc10_encode(tmpbuf, bits, tmp->lpc10.enc);
-               build_bits(pvt->outbuf.uc + datalen, bits);
-               datalen += LPC10_BYTES_IN_COMPRESSED_FRAME;
+               build_bits(pvt->outbuf.uc, bits);
+
                samples += LPC10_SAMPLES_PER_FRAME;
                pvt->samples -= LPC10_SAMPLES_PER_FRAME;
                /* Use one of the two left over bits to record if this is a 22 or 23 ms frame...
                   important for IAX use */
                tmp->longer = 1 - tmp->longer;
+
+               current = ast_trans_frameout(pvt, LPC10_BYTES_IN_COMPRESSED_FRAME, LPC10_SAMPLES_PER_FRAME);
+               if (!current) {
+                       continue;
+               } else if (last) {
+                       AST_LIST_NEXT(last, frame_list) = current;
+               } else {
+                       result = current;
+               }
+               last = current;
        }
+
        /* Move the data at the end of the buffer to the front */
-       if (pvt->samples)
+       if (samples) {
                memmove(tmp->buf, tmp->buf + samples, pvt->samples * 2);
-       return ast_trans_frameout(pvt, datalen, samples);
+       }
+
+       return result;
 }
 
 
index c61f7c4..ca48eae 100644 (file)
@@ -54,6 +54,8 @@ ASTERISK_REGISTER_FILE()
 #include "asterisk/module.h"
 #include "asterisk/config.h"
 #include "asterisk/utils.h"
+#include "asterisk/frame.h"
+#include "asterisk/linkedlists.h"
 
 /* codec variables */
 static int quality = 3;
@@ -259,15 +261,16 @@ static int lintospeex_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
 static struct ast_frame *lintospeex_frameout(struct ast_trans_pvt *pvt)
 {
        struct speex_coder_pvt *tmp = pvt->pvt;
-       int is_speech=1;
-       int datalen = 0;        /* output bytes */
-       int samples = 0;        /* output samples */
+       struct ast_frame *result = NULL;
+       struct ast_frame *last = NULL;
+       int samples = 0; /* output samples */
 
-       /* We can't work on anything less than a frame in size */
-       if (pvt->samples < tmp->framesize)
-               return NULL;
-       speex_bits_reset(&tmp->bits);
        while (pvt->samples >= tmp->framesize) {
+               struct ast_frame *current;
+               int is_speech = 1;
+
+               speex_bits_reset(&tmp->bits);
+
 #ifdef _SPEEX_TYPES_H
                /* Preprocess audio */
                if (preproc)
@@ -293,18 +296,18 @@ static struct ast_frame *lintospeex_frameout(struct ast_trans_pvt *pvt)
 #endif
                samples += tmp->framesize;
                pvt->samples -= tmp->framesize;
-       }
 
-       /* Move the data at the end of the buffer to the front */
-       if (pvt->samples)
-               memmove(tmp->buf, tmp->buf + samples, pvt->samples * 2);
-
-       /* Use AST_FRAME_CNG to signify the start of any silence period */
-       if (is_speech) {
-               tmp->silent_state = 0;
-       } else {
-               if (tmp->silent_state) {
-                       return NULL;
+               /* Use AST_FRAME_CNG to signify the start of any silence period */
+               if (is_speech) {
+                       int datalen = 0; /* output bytes */
+
+                       tmp->silent_state = 0;
+                       /* Terminate bit stream */
+                       speex_bits_pack(&tmp->bits, 15, 5);
+                       datalen = speex_bits_write(&tmp->bits, pvt->outbuf.c, pvt->t->buf_size);
+                       current = ast_trans_frameout(pvt, datalen, tmp->framesize);
+               } else if (tmp->silent_state) {
+                       current = NULL;
                } else {
                        struct ast_frame frm = {
                                .frametype = AST_FRAME_CNG,
@@ -320,14 +323,25 @@ static struct ast_frame *lintospeex_frameout(struct ast_trans_pvt *pvt)
                        tmp->silent_state = 1;
 
                        /* XXX what now ? format etc... */
-                       return ast_frisolate(&frm);
+                       current = ast_frisolate(&frm);
                }
+
+               if (!current) {
+                       continue;
+               } else if (last) {
+                       AST_LIST_NEXT(last, frame_list) = current;
+               } else {
+                       result = current;
+               }
+               last = current;
+       }
+
+       /* Move the data at the end of the buffer to the front */
+       if (samples) {
+               memmove(tmp->buf, tmp->buf + samples, pvt->samples * 2);
        }
 
-       /* Terminate bit stream */
-       speex_bits_pack(&tmp->bits, 15, 5);
-       datalen = speex_bits_write(&tmp->bits, pvt->outbuf.c, pvt->t->buf_size);
-       return ast_trans_frameout(pvt, datalen, samples);
+       return result;
 }
 
 static void speextolin_destroy(struct ast_trans_pvt *arg)
diff --git a/contrib/scripts/astversion b/contrib/scripts/astversion
new file mode 100755 (executable)
index 0000000..a17c696
--- /dev/null
@@ -0,0 +1,536 @@
+#!/bin/bash
+#
+# astversion - determine version/source of components
+#
+# use: astverion {options}
+#
+# options:
+#         --prefix=PATH  - specify prefix from build
+#         --exec=PATH    - specify asterisk executable
+#         --lib=PATH     - specify asterisk library path
+#         --src=PATH     - specify source path to search
+#
+# Copyright (c) 2015, Digium, Inc.
+#
+# Written by Scott Griepentrog <sgriepentrog@digium.com>
+#
+# Distributed under the terms of the GNU General Public License
+
+# condense list of files when more than X in a set
+CONDENSE=3
+
+# libraries to provide the source/version of
+LIBRARIES=(
+       libasteriskssl.so.1
+       libspandsp.so.2
+       libpjsip.so.2
+       libpri.so.1.4
+)
+
+# possible library locations
+LIB_PATHS=(
+       /usr/lib
+       /usr/lib64
+       /lib
+       /lib64
+       /usr/local/lib
+       /usr/local/lib64
+       /opt/lib
+       /opt/lib64
+)
+
+# collection of files to search for
+FILES=()
+
+# source directories to search
+SRC_DIRS=()
+
+main()
+{
+       TMPFILE="/tmp/astversion.$$"
+
+       sanity_check
+       locate_files "$@"
+       locate_libraries
+       locate_modules
+
+       echo "Checking Asterisk versions on $HOSTNAME at $(date)"
+       check_asterisk_version
+       check_dahdi_version
+
+       gather_packages
+       if [ ! -z "$DISTRO" ]
+       then
+               search_packages
+       else
+               echo "WARNING: Unable to determine distro, skipping package search"
+       fi
+       search_source
+       show_unknown_files
+
+       rm -f $TMPFILE
+}
+
+sanity_check()
+{
+       # insure that needed tools are present
+       TOOLS=(uname basename fgrep cut head readlink find)
+       # making assumption that rpm and dpkg always exist on their platforms
+
+       for TOOL in ${TOOLS[@]}
+       do
+               if ! which $TOOL > /dev/null
+               then
+                       echo "ERROR: please install package for $TOOL"
+                       exit 1
+               fi
+       done
+}
+
+locate_files()
+{
+       # guess prefix from executable path
+       SCRIPT_PREFIX="$(readlink -f ${0%/sbin/astversion} 2>/dev/null)"
+       if [ -x $SCRIPT_PREFIX/sbin/asterisk ]
+       then
+               PREFIX=$SCRIPT_PREFIX
+               ASTERISK_PATH=$SCRIPT_PREFIX/sbin/asterisk
+       fi
+       if [ -z "$ASTERISK_PATH" ]
+       then
+               ASTERISK_PATH=$(readlink -f $(which asterisk 2>/dev/null) 2>/dev/null)
+               PREFIX=${ASTERISK_PATH%/sbin/asterisk}
+       fi
+
+       # parse user supplied information
+       USER_PREFIX=""
+       USER_EXEC=""
+       for opt in "$@"
+       do
+               case "$opt" in
+               -h|--help)
+                       echo "Use: astversion {--prefix=PATH} {--exec=PATH} {--lib=PATH}"
+                       exit 0
+                       ;;
+               --prefix=*)
+                       USER_PREFIX=${opt:9}
+                       ;;
+               --exec=*)
+                       USER_EXEC=${opt:7}
+                       ;;
+               --lib=*)
+                       LIBDIR=${opt:6}
+                       ;;
+               --src=*)
+                       SRC_DIRS+=${opt:6}
+                       ;;
+               *)
+                       echo "ERROR: Unknown option: $opt"
+                       exit 1
+                       ;;
+               esac
+       done
+
+       # apply user supplied values
+       if [ ! -z "$USER_PREFIX" ]
+       then
+               PREFIX="$USER_PREFIX"
+               ASTERISK_PATH=""
+       fi
+       if [ ! -z "$USER_EXEC" ]
+       then
+               ASTERISK_PATH="$USER_EXEC"
+       fi
+
+       # locate asterisk executable
+       if [ -z "$ASTERISK_PATH" ]
+       then
+               ASTERISK_PATH="$PREFIX/sbin/asterisk"
+       fi
+       if [ ! -x "$ASTERISK_PATH" ]
+       then
+               echo "ERROR: the Asterisk executable is not found or not executable at $ASTERISK_PATH"
+               exit 1
+       fi
+       FILES+=($ASTERISK_PATH)
+
+       # locate dahdi_cfg executable
+       DAHDI_CFG_PATH=$(readlink -f $(which dahdi_cfg 2>/dev/null) 2>/dev/null)
+       if [ ! -z "$DAHDI_CFG_PATH" ]
+       then
+               FILES+=($DAHDI_CFG_PATH)
+       fi
+
+       # locate asterisk libdir
+       if [ -z "$LIBDIR" ]
+       then
+               LIBDIR="$PREFIX/lib"
+               if [ `uname -m` = "x86_64" -a -d "$PREFIX/lib64" ]
+               then
+                       LIBDIR="$PREFIX/lib64"
+               fi
+       fi
+
+       if [ ! -d "$LIBDIR/asterisk/modules" ]
+       then
+               echo "ERROR: asterisk module directory not found at $LIBDIR"
+               exit 1
+       fi
+}
+
+locate_libraries()
+{
+       # LIBDIR should contain libasteriskssl, but others may be elsewhere
+
+       # add LIBDIR to path list
+       if ! [[ " ${LIB_PATHS[@]} " =~ " $LIBDIR " ]]
+       then
+               LIB_PATHS+=($LIBDIR)
+       fi
+
+       for LIBRARY in ${LIBRARIES[@]}
+       do
+               FOUND_LIB=()
+               for LIB_PATH in ${LIB_PATHS[@]}
+               do
+                       FULL_PATH="$LIB_PATH/$LIBRARY"
+                       if [ ! -L $LIB_PATH -a -f $FULL_PATH ]
+                       then
+                               FOUND_LIB+=($FULL_PATH)
+                               FILES+=($FULL_PATH)
+                       fi
+               done
+
+               if [ ${#FOUND_LIB[@]} -gt 1 ]
+               then
+                       echo "### WARNING: duplicate libraries found: ${FOUND_LIB[@]}"
+               fi
+       done
+}
+
+check_asterisk_version()
+{
+       # get the version that the executable says it is
+       echo "Using Asterisk executable: $ASTERISK_PATH"
+       AST_EXEC_VER=$($ASTERISK_PATH -V)
+       if [ -z "$AST_EXEC_VER" ]
+       then
+               echo "### ERROR: Unable to find Asterisk version from executable"
+               exit 1
+       fi
+       if [ "${AST_EXEC_VER:0:9}" != "Asterisk " ]
+       then
+               echo "### ERROR: Unexpected version from executable: $AST_EXEC_VER"
+               exit 1
+       fi
+
+       # compare with the version that is running
+       if ! $ASTERISK_PATH -rx "core show version" > $TMPFILE 2>/dev/null
+       then
+               echo "Installed version: $AST_EXEC_VER"
+               echo "Asterisk is not running - more details are available when running."
+               AST_RUN_VER=""
+       else
+               AST_RUN_VER=$(grep '^Asterisk [^e][^n][^d]' < $TMPFILE)
+               if [ -z "$AST_RUN_VER" ]
+               then
+                       echo "### ERROR: Unable to find Asterisk version from running instance"
+                       exit 1
+               fi
+
+               # is it running the same version? (note: space is significant!)
+               if ! fgrep "$AST_EXEC_VER " < $TMPFILE > /dev/null
+               then
+                       echo "Installed version: $AST_EXEC_VER"
+                       echo "### WARNING: Asterisk is running different version:"
+               fi
+               echo "$AST_RUN_VER"
+       fi
+}
+
+check_dahdi_version()
+{
+       if [ ! -f /sys/module/dahdi/version ]
+       then
+               echo "Dahdi kernel module is not installed"
+       else
+               DAHDI_KERNEL=$(cat /sys/module/dahdi/version)
+               echo "Dahdi kernel module version: $DAHDI_KERNEL"
+       fi
+
+       if ! which dahdi_cfg >&/dev/null
+       then
+               echo "Dahdi tools are not installed"
+       else
+               DAHDI_TOOLS=$(dahdi_cfg -v |& head -1)
+               echo "$DAHDI_TOOLS"
+       fi
+
+       if $ASTERISK_PATH -rx "dahdi show version" > $TMPFILE 2>/dev/null
+       then
+               DAHDI_CLI=$(grep ^DAHDI $TMPFILE)
+               # may be empty if dahdi not installed
+               if [ ! -z "$DAHDI_CLI" ]
+               then
+                       echo "Asterisk reports: $DAHDI_CLI"
+               else
+                       echo "Asterisk reports that Dahdi is not available"
+               fi
+       fi
+}
+
+scan_package_redhat()
+{
+       PKGNAME="$1"
+
+       if ! rpm -q $PKGNAME > /tmp/astversion-$PKGNAME-version
+       then
+               rm -f /tmp/astversion-$PKGNAME-version
+               return 2
+       fi
+
+       rpm -ql $PKGNAME > /tmp/astversion-$PKGNAME-files
+       rpm -V $PKGNAME > /tmp/astversion-$PKGNAME-verify
+       return 0
+}
+
+scan_package_debian()
+{
+       PKGNAME="$1"
+
+       if ! dpkg -s $PKGNAME > $TMPFILE
+       then
+               rm -f /tmp/astversion-$PKGNAME-version
+               return 2
+       fi
+
+       # prefix the version with the package name to mimic rpm
+       echo -n "$PKGNAME " > /tmp/astversion-$PKGNAME-version
+       cat $TMPFILE | fgrep Version |cut -d ' ' -f2 >> /tmp/astversion-$PKGNAME-version
+
+       dpkg -L $PKGNAME > /tmp/astversion-$PKGNAME-files
+       dpkg -V $PKGNAME > /tmp/astversion-$PKGNAME-verify
+}
+
+package_has_file()
+{
+       PKGNAME="$1"
+       PKGFILE="$2"
+
+       if [ ! -f /tmp/astversion-$PKGNAME-version ]
+       then
+               return 1
+       fi
+
+       if [ ! -f /tmp/astversion-$PKGNAME-files ]
+       then
+               return 2
+       fi
+
+       if ! fgrep "$PKGFILE" /tmp/astversion-$PKGNAME-files >/dev/null
+       then
+               # package doesn't have that file
+               return 3
+       fi
+
+       if fgrep "$PKGFILE" /tmp/astversion-$PKGNAME-verify >/dev/null
+       then
+               # file does not match package
+               return 4
+       fi
+
+       return 0
+}
+
+
+gather_packages()
+{
+       # build a list of installed packages that are likely to contain files of interest
+       PACKAGES=()
+       SEARCH=(asterisk dahdi libpri pjproject spandsp)
+       DISTRO=""
+
+       if [ -f /etc/redhat-release ]
+       then
+               DISTRO="redhat"
+               for NAME in ${SEARCH[@]}
+               do
+                       PACKAGES+=($(rpm -qa |fgrep $NAME))
+               done
+       fi
+
+       if [ -f /etc/debian_version ]
+       then
+               DISTRO="debian"
+               for NAME in ${SEARCH[@]}
+               do
+                       PACKAGES+=($(dpkg --get-selections |cut -f1 |fgrep $NAME))
+               done
+       fi
+}
+
+locate_modules()
+{
+       # build a list of files that need to be located
+       MODULES=($LIBDIR/asterisk/modules/*.so)
+
+       # add libraries and binaries that exist to the files list
+       for MODULE in ${MODULES[@]}
+       do
+               FILES+=($MODULE)
+       done
+}
+
+search_packages()
+{
+       # search each package and report files that match
+       for PACKAGE in ${PACKAGES[@]}
+       do
+               scan_package_$DISTRO "$PACKAGE"
+               PKGVERSION=$(cat /tmp/astversion-$PKGNAME-version)
+
+               FOUND=()
+               for FILE in ${FILES[@]}
+               do
+                       if package_has_file "$PACKAGE" "$FILE"
+                       then
+                               FOUND+=($FILE)
+                               FILES=(${FILES[@]/$FILE/})
+                       fi
+               done
+
+               if [ ! -z "$FOUND" ]
+               then
+                       if [ ${#FOUND[@]} -le $CONDENSE ]
+                       then
+                               for FILEFOUND in ${FOUND[@]}
+                               do
+                                       echo "Matched $FILEFOUND to package $PKGVERSION"
+                               done
+                       else
+                               echo "Matched ${#FOUND[@]} files to package $PKGVERSION"
+                       fi
+               fi
+
+               rm -f /tmp/astversion-$PKGNAME-version
+               rm -f /tmp/astversion-$PKGNAME-files
+               rm -f /tmp/astversion-$PKGNAME-verify
+       done
+}
+
+search_source()
+{
+       # look for source path locally (compiled on this machine)
+       # - scan elfs for compilation directory
+       # - compare the file to confirm match
+       if [ -z "$FILES" ]
+       then
+               return
+       fi
+
+       # skip this check when without readelf tool (fedora 22)
+       if ! which readelf >& /dev/null
+       then
+               echo "Warning: skipping source detection because readelf utility is not available"
+               return
+       fi
+
+       # build a list of source paths
+       DIRS=()
+       for FILE in ${FILES[@]}
+       do
+               DEBUG_ELF=$(readelf -wi $FILE |fgrep DW_AT_comp_dir |head -1)
+               COMP_DIR=${DEBUG_ELF##* }
+               DIR=${COMP_DIR//[[:space:]]/}
+               if [ -d $DIR ]
+               then
+                       if ! [[ " ${DIRS[@]} " =~ " $DIR " ]]
+                       then
+                               DIRS+=($DIR)
+                       fi
+               fi
+       done
+
+       # add in user specified directories last
+       for DIR in ${SRC_DIRS[@]}
+       do
+               if ! [[ " ${DIRS[@]} " =~ " $DIR " ]]
+               then
+                       DIRS+=($DIR)
+               fi
+       done
+
+       # for each source path, look for target file
+       for DIR in ${DIRS[@]}
+       do
+               FOUND=()
+               for FILE in ${FILES[@]}
+               do
+                       BINARY_FILE=$(basename $FILE)
+                       BINARY_PATH="$DIR/$BINARY_FILE"
+                       if [ ! -f "$BINARY_PATH" ]
+                       then
+                               # it may be hiding somewhere
+                               FIND_BINARY=$(find $DIR -name $BINARY_FILE |head -1)
+                               if [ ! -z "$FIND_BINARY" ]
+                               then
+                                       BINARY_PATH=$FIND_BINARY
+                               fi
+                       fi
+                       if [ -f "$BINARY_PATH" ]
+                       then
+                               if cmp $BINARY_PATH $FILE >/dev/null
+                               then
+                                       FOUND+=($FILE)
+                                       FILES=(${FILES[@]/$FILE/})
+                               fi
+                       fi
+               done
+
+               if [ ! -z "$FOUND" ]
+               then
+                       if [ ${#FOUND[@]} -le $CONDENSE ]
+                       then
+                               for FILEFOUND in ${FOUND[@]}
+                               do
+                                       echo "Located $FILEFOUND compiled from $DIR"
+                               done
+                       else
+                               echo "Located ${#FOUND[@]} files compiled from $DIR"
+                       fi
+               fi
+       done
+}
+
+show_unknown_files()
+{
+       # show a warning for any remaining files unaccounted for
+       if [ -z "$FILES" ]
+       then
+               echo "Success: all files accounted for."
+       else
+               echo ""
+               echo "WARNING: source of the following files was not found:"
+               if ! which readelf >& /dev/null
+               then
+                       for FILE in ${FILES[@]}
+                       do
+                               echo "     ### $FILE"
+                       done
+               else
+                       for FILE in ${FILES[@]}
+                       do
+                               DEBUG_ELF=$(readelf -wi $FILE |fgrep DW_AT_comp_dir |head -1)
+                               if [ -z "$DEBUG_ELF" ]
+                               then
+                                       COMP_DIR="(no debug info)"
+                               else
+                                       COMP_DIR=${DEBUG_ELF##* }
+                               fi
+                               echo "     ### $FILE - $COMP_DIR"
+                       done
+               fi
+       fi
+}
+
+main "$@"
index f13ecf4..334d3b5 100644 (file)
@@ -44,6 +44,7 @@ ASTERISK_REGISTER_FILE()
 #include "asterisk/cli.h"
 #include "asterisk/term.h"
 #include "asterisk/format.h"
+#include "asterisk/linkedlists.h"
 
 /*! \todo
  * TODO: sample frames for each supported input format.
@@ -547,7 +548,12 @@ struct ast_frame *ast_translate(struct ast_trans_pvt *path, struct ast_frame *f,
        }
        delivery = f->delivery;
        for (out = f; out && p ; p = p->next) {
-               framein(p, out);
+               struct ast_frame *current = out;
+
+               do {
+                       framein(p, current);
+                       current = AST_LIST_NEXT(current, frame_list);
+               } while (current);
                if (out != f) {
                        ast_frfree(out);
                }
@@ -556,22 +562,33 @@ struct ast_frame *ast_translate(struct ast_trans_pvt *path, struct ast_frame *f,
        if (out) {
                /* we have a frame, play with times */
                if (!ast_tvzero(delivery)) {
-                       /* Regenerate prediction after a discontinuity */
-                       if (ast_tvzero(path->nextout)) {
-                               path->nextout = ast_tvnow();
-                       }
+                       struct ast_frame *current = out;
 
-                       /* Use next predicted outgoing timestamp */
-                       out->delivery = path->nextout;
+                       do {
+                               /* Regenerate prediction after a discontinuity */
+                               if (ast_tvzero(path->nextout)) {
+                                       path->nextout = ast_tvnow();
+                               }
 
-                       /* Predict next outgoing timestamp from samples in this
-                          frame. */
-                       path->nextout = ast_tvadd(path->nextout, ast_samp2tv(
-                                out->samples, ast_format_get_sample_rate(out->subclass.format)));
-                       if (f->samples != out->samples && ast_test_flag(out, AST_FRFLAG_HAS_TIMING_INFO)) {
-                               ast_debug(4, "Sample size different %d vs %d\n", f->samples, out->samples);
-                               ast_clear_flag(out, AST_FRFLAG_HAS_TIMING_INFO);
-                       }
+                               /* Use next predicted outgoing timestamp */
+                               current->delivery = path->nextout;
+
+                               /* Invalidate prediction if we're entering a silence period */
+                               if (current->frametype == AST_FRAME_CNG) {
+                                       path->nextout = ast_tv(0, 0);
+                               /* Predict next outgoing timestamp from samples in this
+                                  frame. */
+                               } else {
+                                       path->nextout = ast_tvadd(path->nextout, ast_samp2tv(
+                                               current->samples, ast_format_get_sample_rate(current->subclass.format)));
+                               }
+
+                               if (f->samples != current->samples && ast_test_flag(current, AST_FRFLAG_HAS_TIMING_INFO)) {
+                                       ast_debug(4, "Sample size different %d vs %d\n", f->samples, current->samples);
+                                       ast_clear_flag(current, AST_FRFLAG_HAS_TIMING_INFO);
+                               }
+                               current = AST_LIST_NEXT(current, frame_list);
+                       } while (current);
                } else {
                        out->delivery = ast_tv(0, 0);
                        ast_set2_flag(out, has_timing_info, AST_FRFLAG_HAS_TIMING_INFO);
@@ -580,10 +597,10 @@ struct ast_frame *ast_translate(struct ast_trans_pvt *path, struct ast_frame *f,
                                out->len = len;
                                out->seqno = seqno;
                        }
-               }
-               /* Invalidate prediction if we're entering a silence period */
-               if (out->frametype == AST_FRAME_CNG) {
-                       path->nextout = ast_tv(0, 0);
+                       /* Invalidate prediction if we're entering a silence period */
+                       if (out->frametype == AST_FRAME_CNG) {
+                               path->nextout = ast_tv(0, 0);
+                       }
                }
        }
        if (consume) {
index 69e9b93..abca895 100644 (file)
@@ -1294,7 +1294,9 @@ int stasis_app_exec(struct ast_channel *chan, const char *app_name, int argc,
 
                if (bridge != last_bridge) {
                        app_unsubscribe_bridge(app, last_bridge);
-                       app_subscribe_bridge(app, bridge);
+                       if (bridge) {
+                               app_subscribe_bridge(app, bridge);
+                       }
                }
 
                if (bridge) {