diff options
Diffstat (limited to 'main/channel.c')
-rw-r--r-- | main/channel.c | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/main/channel.c b/main/channel.c index 8630ded01..175c0bd5e 100644 --- a/main/channel.c +++ b/main/channel.c @@ -3403,13 +3403,23 @@ static int set_format(struct ast_channel *chan, int fmt, int *rawformat, int *fo if (*trans) ast_translator_free_path(*trans); /* Build a translation path from the raw format to the desired format */ - if (!direction) - /* reading */ - *trans = ast_translator_build_path(*format, *rawformat); - else - /* writing */ - *trans = ast_translator_build_path(*rawformat, *format); - res = *trans ? 0 : -1; + if (*format == *rawformat) { + /* + * If we were able to swap the native format to the format that + * has been requested, then there is no need to try to build + * a translation path. + */ + res = 0; + } else { + if (!direction) { + /* reading */ + *trans = ast_translator_build_path(*format, *rawformat); + } else { + /* writing */ + *trans = ast_translator_build_path(*rawformat, *format); + } + res = *trans ? 0 : -1; + } ast_channel_unlock(chan); if (option_debug) ast_log(LOG_DEBUG, "Set channel %s to %s format %s\n", chan->name, |