codec_dahdi: Cannot use struct ast_translator.core_{src,src}_codec.
[asterisk/asterisk.git] / apps / app_dictate.c
index 6b20017..53718d1 100644 (file)
@@ -43,6 +43,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/module.h"
 #include "asterisk/say.h"
 #include "asterisk/app.h"
+#include "asterisk/format_cache.h"
 
 /*** DOCUMENTATION
        <application name="Dictate" language="en_US">
@@ -108,8 +109,7 @@ static int dictate_exec(struct ast_channel *chan, const char *data)
                len = 0,
                maxlen = 0,
                mode = 0;
-       struct ast_format oldr;
-       ast_format_clear(&oldr);
+       struct ast_format *oldr;
 
        snprintf(dftbase, sizeof(dftbase), "%s/dictate", ast_config_AST_SPOOL_DIR);
        if (!ast_strlen_zero(data)) {
@@ -126,13 +126,14 @@ static int dictate_exec(struct ast_channel *chan, const char *data)
        if (args.argc > 1 && args.filename) {
                filename = args.filename;
        }
-       ast_format_copy(&oldr, &chan->readformat);
-       if ((res = ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR)) < 0) {
+       oldr = ao2_bump(ast_channel_readformat(chan));
+       if ((res = ast_set_read_format(chan, ast_format_slin)) < 0) {
                ast_log(LOG_WARNING, "Unable to set to linear mode.\n");
+               ao2_cleanup(oldr);
                return -1;
        }
 
-       if (chan->_state != AST_STATE_UP) {
+       if (ast_channel_state(chan) != AST_STATE_UP) {
                ast_answer(chan);
        }
        ast_safe_sleep(chan, 200);
@@ -150,7 +151,7 @@ static int dictate_exec(struct ast_channel *chan, const char *data)
                ast_mkdir(base, 0755);
                len = strlen(base) + strlen(filein) + 2;
                if (!path || len > maxlen) {
-                       path = alloca(len);
+                       path = ast_alloca(len);
                        memset(path, 0, len);
                        maxlen = len;
                } else {
@@ -278,7 +279,7 @@ static int dictate_exec(struct ast_channel *chan, const char *data)
                                                        if (!(fs = ast_openstream(chan, path, ast_channel_language(chan))))
                                                                break;
                                                        ast_seekstream(fs, samples, SEEK_SET);
-                                                       chan->stream = NULL;
+                                                       ast_channel_stream_set(chan, NULL);
                                                }
                                                lastop = DMODE_PLAY;
                                        }
@@ -335,8 +336,9 @@ static int dictate_exec(struct ast_channel *chan, const char *data)
                        ast_frfree(f);
                }
        }
-       if (oldr.id) {
-               ast_set_read_format(chan, &oldr);
+       if (oldr) {
+               ast_set_read_format(chan, oldr);
+               ao2_ref(oldr, -1);
        }
        return 0;
 }
@@ -353,4 +355,5 @@ static int load_module(void)
        return ast_register_application_xml(app, dictate_exec);
 }
 
-AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Virtual Dictation Machine");
+AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Virtual Dictation Machine");
+