aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2010-11-24 20:22:32 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2010-11-24 20:22:32 +0000
commita053af42d953c0bd7dd586ec48de05ae3564dfde (patch)
tree926e2a6d8313a09abb4efc45ea5b997f9d76babb
parentba7980f1afa6aebb50c1cb2f1a17175514f53ea7 (diff)
Fix false reporting of an error by set_format().
In the case that the native format was able to be changed to match the new requested format, the code proceeded to attempt to build a translation path, anyway. The result would be NULL, since no translation path is necessary and resulted in this function thinking an error has occurred. This case is now specifically caught and no attempt to build a translation path is attempted. Thanks to our automated tests and bamboo.asterisk.org for catching this problem and making a whole lot of noise when things started failing. :-) git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@296082 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r--main/channel.c24
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,