summaryrefslogtreecommitdiff
path: root/apps/app_festival.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/app_festival.c')
-rw-r--r--apps/app_festival.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/apps/app_festival.c b/apps/app_festival.c
index 3ccacb195..3626563c6 100644
--- a/apps/app_festival.c
+++ b/apps/app_festival.c
@@ -63,6 +63,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/lock.h"
#include "asterisk/app.h"
#include "asterisk/endian.h"
+#include "asterisk/format_cache.h"
#define FESTIVAL_CONFIG "festival.conf"
#define MAXLEN 180
@@ -177,7 +178,7 @@ static int send_waveform_to_channel(struct ast_channel *chan, char *waveform, in
int res = 0;
int fds[2];
int needed = 0;
- struct ast_format owriteformat;
+ struct ast_format *owriteformat;
struct ast_frame *f;
struct myframe {
struct ast_frame f;
@@ -187,7 +188,6 @@ static int send_waveform_to_channel(struct ast_channel *chan, char *waveform, in
.f = { 0, },
};
- ast_format_clear(&owriteformat);
if (pipe(fds)) {
ast_log(LOG_WARNING, "Unable to create pipe\n");
return -1;
@@ -199,12 +199,19 @@ static int send_waveform_to_channel(struct ast_channel *chan, char *waveform, in
ast_stopstream(chan);
ast_indicate(chan, -1);
- ast_format_copy(&owriteformat, ast_channel_writeformat(chan));
- res = ast_set_write_format_by_id(chan, AST_FORMAT_SLINEAR);
+ owriteformat = ao2_bump(ast_channel_writeformat(chan));
+ res = ast_set_write_format(chan, ast_format_slin);
if (res < 0) {
ast_log(LOG_WARNING, "Unable to set write format to signed linear\n");
+ ao2_cleanup(owriteformat);
return -1;
}
+
+ myf.f.frametype = AST_FRAME_VOICE;
+ myf.f.subclass.format = ast_format_slin;
+ myf.f.offset = AST_FRIENDLY_OFFSET;
+ myf.f.src = __PRETTY_FUNCTION__;
+ myf.f.data.ptr = myf.frdata;
res = send_waveform_to_fd(waveform, length, fds[1]);
if (res >= 0) {
@@ -240,13 +247,8 @@ static int send_waveform_to_channel(struct ast_channel *chan, char *waveform, in
}
res = read(fds[0], myf.frdata, needed);
if (res > 0) {
- myf.f.frametype = AST_FRAME_VOICE;
- ast_format_set(&myf.f.subclass.format, AST_FORMAT_SLINEAR, 0);
myf.f.datalen = res;
myf.f.samples = res / 2;
- myf.f.offset = AST_FRIENDLY_OFFSET;
- myf.f.src = __PRETTY_FUNCTION__;
- myf.f.data.ptr = myf.frdata;
if (ast_write(chan, &myf.f) < 0) {
res = -1;
ast_frfree(f);
@@ -269,8 +271,10 @@ static int send_waveform_to_channel(struct ast_channel *chan, char *waveform, in
close(fds[0]);
close(fds[1]);
- if (!res && owriteformat.id)
- ast_set_write_format(chan, &owriteformat);
+ if (!res && owriteformat)
+ ast_set_write_format(chan, owriteformat);
+ ao2_cleanup(owriteformat);
+
return res;
}