Merged revisions 378322 via svnmerge from
[asterisk/asterisk.git] / funcs / func_speex.c
index 4b8b3a3..7467c23 100644 (file)
  *
  * \ingroup functions
  *
- * \extref The Speex 1.2 library - http://www.speex.org
+ * The Speex 1.2 library - http://www.speex.org
  * \note Requires the 1.2 version of the Speex library (which might not be what you find in Linux packages)
  */
 
 /*** MODULEINFO
        <depend>speex</depend>
        <depend>speex_preprocess</depend>
-       <use>speexdsp</use>
+       <use type="external">speexdsp</use>
+       <support_level>core</support_level>
  ***/
 
 #include "asterisk.h"
@@ -105,6 +106,7 @@ struct speex_direction_info {
 
 struct speex_info {
        struct ast_audiohook audiohook;
+       int lastrate;
        struct speex_direction_info *tx, *rx;
 };
 
@@ -163,12 +165,13 @@ static int speex_callback(struct ast_audiohook *audiohook, struct ast_channel *c
                return -1;
        }
 
-       if (sdi->samples != frame->samples) {
+       if ((sdi->samples != frame->samples) || (ast_format_rate(&frame->subclass.format) != si->lastrate)) {
+               si->lastrate = ast_format_rate(&frame->subclass.format);
                if (sdi->state) {
                        speex_preprocess_state_destroy(sdi->state);
                }
 
-               if (!(sdi->state = speex_preprocess_state_init((sdi->samples = frame->samples), 8000))) {
+               if (!(sdi->state = speex_preprocess_state_init((sdi->samples = frame->samples), si->lastrate))) {
                        return -1;
                }
 
@@ -199,6 +202,11 @@ static int speex_write(struct ast_channel *chan, const char *cmd, char *data, co
        struct speex_direction_info **sdi = NULL;
        int is_new = 0;
 
+       if (strcasecmp(data, "rx") && strcasecmp(data, "tx")) {
+               ast_log(LOG_ERROR, "Invalid argument provided to the %s function\n", cmd);
+               return -1;
+       }
+
        ast_channel_lock(chan);
        if (!(datastore = ast_channel_datastore_find(chan, &speex_datastore, NULL))) {
                ast_channel_unlock(chan);
@@ -212,9 +220,9 @@ static int speex_write(struct ast_channel *chan, const char *cmd, char *data, co
                        return 0;
                }
 
-               ast_audiohook_init(&si->audiohook, AST_AUDIOHOOK_TYPE_MANIPULATE, "speex");
+               ast_audiohook_init(&si->audiohook, AST_AUDIOHOOK_TYPE_MANIPULATE, "speex", AST_AUDIOHOOK_MANIPULATE_ALL_RATES);
                si->audiohook.manipulate_callback = speex_callback;
-
+               si->lastrate = 8000;
                is_new = 1;
        } else {
                ast_channel_unlock(chan);
@@ -223,15 +231,8 @@ static int speex_write(struct ast_channel *chan, const char *cmd, char *data, co
 
        if (!strcasecmp(data, "rx")) {
                sdi = &si->rx;
-       } else if (!strcasecmp(data, "tx")) {
-               sdi = &si->tx;
        } else {
-               ast_log(LOG_ERROR, "Invalid argument provided to the %s function\n", cmd);
-
-               if (is_new) {
-                       ast_datastore_free(datastore);
-                       return -1;
-               }
+               sdi = &si->tx;
        }
 
        if (!*sdi) {