--- audiohook.c 2010-04-29 14:09:43.000000000 +0200 +++ audiohook.c.orig 2010-04-29 11:19:21.000000000 +0200 @@ -166,7 +166,7 @@ return 0; } -static struct ast_frame *audiohook_read_frame_single(struct ast_audiohook *audiohook, size_t samples, enum ast_audiohook_direction direction, int format) +static struct ast_frame *audiohook_read_frame_single(struct ast_audiohook *audiohook, size_t samples, enum ast_audiohook_direction direction) { struct ast_slinfactory *factory = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->read_factory : &audiohook->write_factory); int vol = (direction == AST_AUDIOHOOK_DIRECTION_READ ? audiohook->options.read_volume : audiohook->options.write_volume); @@ -178,9 +178,7 @@ .datalen = sizeof(buf), .samples = samples, }; - if(ast_format_rate(format) == 16000) { - frame.subclass = AST_FORMAT_SLINEAR16; - } + /* Ensure the factory is able to give us the samples we want */ if (samples > ast_slinfactory_available(factory)) return NULL; @@ -196,7 +194,7 @@ return ast_frdup(&frame); } -static struct ast_frame *audiohook_read_frame_both(struct ast_audiohook *audiohook, size_t samples, int format) +static struct ast_frame *audiohook_read_frame_both(struct ast_audiohook *audiohook, size_t samples) { int i = 0, usable_read, usable_write; short buf1[samples], buf2[samples], *read_buf = NULL, *write_buf = NULL, *final_buf = NULL, *data1 = NULL, *data2 = NULL; @@ -207,9 +205,7 @@ .datalen = sizeof(buf1), .samples = samples, }; - if(ast_format_rate(format) == 16000) { - frame.subclass = AST_FORMAT_SLINEAR16; - } + /* Make sure both factories have the required samples */ usable_read = (ast_slinfactory_available(&audiohook->read_factory) >= samples ? 1 : 0); usable_write = (ast_slinfactory_available(&audiohook->write_factory) >= samples ? 1 : 0); @@ -300,11 +296,11 @@ { struct ast_frame *read_frame = NULL, *final_frame = NULL; - if (!(read_frame = (direction == AST_AUDIOHOOK_DIRECTION_BOTH ? audiohook_read_frame_both(audiohook, samples, format) : audiohook_read_frame_single(audiohook, samples, direction, format)))) + if (!(read_frame = (direction == AST_AUDIOHOOK_DIRECTION_BOTH ? audiohook_read_frame_both(audiohook, samples) : audiohook_read_frame_single(audiohook, samples, direction)))) return NULL; /* If they don't want signed linear back out, we'll have to send it through the translation path */ - if (format != read_frame->subclass) { + if (format != AST_FORMAT_SLINEAR) { /* Rebuild translation path if different format then previously */ if (audiohook->format != format) { if (audiohook->trans_pvt) { @@ -312,11 +308,10 @@ audiohook->trans_pvt = NULL; } /* Setup new translation path for this format... if we fail we can't very well return signed linear so free the frame and return nothing */ - if (!(audiohook->trans_pvt = ast_translator_build_path(format, read_frame->subclass))) { + if (!(audiohook->trans_pvt = ast_translator_build_path(format, AST_FORMAT_SLINEAR))) { ast_frfree(read_frame); return NULL; } - audiohook->format = format; } /* Convert to requested format, and allow the read in frame to be freed */ final_frame = ast_translate(audiohook->trans_pvt, read_frame, 1); @@ -591,18 +586,14 @@ struct ast_frame *start_frame = frame, *middle_frame = frame, *end_frame = frame; struct ast_audiohook *audiohook = NULL; int samples = frame->samples; + /* If the frame coming in is not signed linear we have to send it through the in_translate path */ if (frame->subclass != AST_FORMAT_SLINEAR) { if (in_translate->format != frame->subclass) { if (in_translate->trans_pvt) ast_translator_free_path(in_translate->trans_pvt); - if(ast_format_rate(frame->subclass) == 16000) { - if (!(in_translate->trans_pvt = ast_translator_build_path(AST_FORMAT_SLINEAR16, frame->subclass))) - return frame; - } else { - if (!(in_translate->trans_pvt = ast_translator_build_path(AST_FORMAT_SLINEAR, frame->subclass))) - return frame; - } + if (!(in_translate->trans_pvt = ast_translator_build_path(AST_FORMAT_SLINEAR, frame->subclass))) + return frame; in_translate->format = frame->subclass; } if (!(middle_frame = ast_translate(in_translate->trans_pvt, frame, 0))) @@ -683,18 +674,10 @@ if (out_translate->format != start_frame->subclass) { if (out_translate->trans_pvt) ast_translator_free_path(out_translate->trans_pvt); - if(ast_format_rate(frame->subclass) == 16000) { - if (!(out_translate->trans_pvt = ast_translator_build_path(start_frame->subclass, AST_FORMAT_SLINEAR16))) { - /* We can't transcode this... drop our middle frame and return the original */ - ast_frfree(middle_frame); - return start_frame; - } - } else { - if (!(out_translate->trans_pvt = ast_translator_build_path(start_frame->subclass, AST_FORMAT_SLINEAR))) { - /* We can't transcode this... drop our middle frame and return the original */ - ast_frfree(middle_frame); - return start_frame; - } + if (!(out_translate->trans_pvt = ast_translator_build_path(start_frame->subclass, AST_FORMAT_SLINEAR))) { + /* We can't transcode this... drop our middle frame and return the original */ + ast_frfree(middle_frame); + return start_frame; } out_translate->format = start_frame->subclass; }