summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Traud <pabstraud@compuserve.com>2018-01-05 12:51:47 +0100
committerCorey Farrell <git@cfware.com>2018-01-09 11:37:08 -0500
commit3a7d91725607b84274c068550096307f59e6b9f8 (patch)
treee23aa2c6982447ca33310590a63ed1f45985f9e5
parent2f8ae566512897c97b3369bab3f07ff836f5ad1c (diff)
translate: Avoid absolute value on unsigned substraction.
ast_format_get_sample_rate(.) returns an unsigned type. The difference of a substraction between two unsigned types does not get implicitly converted to a signed type. Therefore, using abs(.) did not make sense. ASTERISK-27549 Change-Id: Ib904d9ee0d46b6fdd1476fbc464fbbf813304017
-rw-r--r--main/translate.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/main/translate.c b/main/translate.c
index 02717c5ed..226d0985d 100644
--- a/main/translate.c
+++ b/main/translate.c
@@ -32,7 +32,6 @@
#include <sys/time.h>
#include <sys/resource.h>
#include <math.h>
-#include <stdlib.h>
#include "asterisk/lock.h"
#include "asterisk/channel.h"
@@ -1331,6 +1330,13 @@ void ast_translator_deactivate(struct ast_translator *t)
AST_RWLIST_UNLOCK(&translators);
}
+/*! Calculate the absolute difference between sample rate of two formats. */
+#define format_sample_rate_absdiff(fmt1, fmt2) ({ \
+ unsigned int rate1 = ast_format_get_sample_rate(fmt1); \
+ unsigned int rate2 = ast_format_get_sample_rate(fmt2); \
+ (rate1 > rate2 ? rate1 - rate2 : rate2 - rate1); \
+})
+
/*! \brief Calculate our best translator source format, given costs, and a desired destination */
int ast_translator_best_choice(struct ast_format_cap *dst_cap,
struct ast_format_cap *src_cap,
@@ -1415,10 +1421,8 @@ int ast_translator_best_choice(struct ast_format_cap *dst_cap,
beststeps = matrix_get(x, y)->multistep;
} else if (matrix_get(x, y)->table_cost == besttablecost
&& matrix_get(x, y)->multistep == beststeps) {
- int gap_selected = abs(ast_format_get_sample_rate(best)
- - ast_format_get_sample_rate(bestdst));
- int gap_current = abs(ast_format_get_sample_rate(src)
- - ast_format_get_sample_rate(dst));
+ unsigned int gap_selected = format_sample_rate_absdiff(best, bestdst);
+ unsigned int gap_current = format_sample_rate_absdiff(src, dst);
if (gap_current < gap_selected) {
/* better than what we have so far */