[Asterisk-code-review] translate.c: Fixed codec translator bug (asterisk[master])
N A
asteriskteam at digium.com
Thu May 27 14:36:36 CDT 2021
N A has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/15953 )
Change subject: translate.c: Fixed codec translator bug
......................................................................
translate.c: Fixed codec translator bug
If multiple codecs are available for the same
resource and the translation costs between
multiple codecs are the same, ties are
currently broken arbitrarily, which means a
lower quality codec would be used. This forces
Asterisk to explicitly use the higher quality
codec, ceteris paribus.
ASTERISK-29455
Change-Id: I4b7297e1baca7aac14fe4a3c7538e18e2dbe9fd6
---
M include/asterisk/translate.h
M main/translate.c
2 files changed, 41 insertions(+), 0 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/53/15953/1
diff --git a/include/asterisk/translate.h b/include/asterisk/translate.h
index b2da453..03b1ea9 100644
--- a/include/asterisk/translate.h
+++ b/include/asterisk/translate.h
@@ -282,6 +282,16 @@
*/
void ast_translator_deactivate(struct ast_translator *t);
+/*! \brief Determine which protocol is higher quality
+ *
+ * Given two codec identifiers, is the first codec strictly superior to the second?
+ *
+ * \param codec identifier A
+ * \param codec identifier B
+ * \return Returns 1 if codec A is positively superior to B, 0 otherwise.
+ */
+int ast_translator_better_quality(int c1, int c2);
+
/*!
* \brief Chooses the best translation path
*
diff --git a/main/translate.c b/main/translate.c
index 27e73f6..e11575f 100644
--- a/main/translate.c
+++ b/main/translate.c
@@ -1381,6 +1381,28 @@
(rate1 > rate2 ? rate1 - rate2 : rate2 - rate1); \
})
+/*! \brief Determine which protocol is higher quality */
+int ast_translator_better_quality(int c1, int c2) {
+ /* is c1 is strictly superior to c2? */
+ if (c1 == ast_format_get_codec_id(ast_format_g722)) {
+ return (
+ (c2 == ast_format_get_codec_id(ast_format_gsm)) ||
+ (c2 == ast_format_get_codec_id(ast_format_g729)) ||
+ (c2 == ast_format_get_codec_id(ast_format_ulaw)) ||
+ (c2 == ast_format_get_codec_id(ast_format_alaw)) ||
+ (c2 == ast_format_get_codec_id(ast_format_g723))
+ );
+ }
+ if (c1 == ast_format_get_codec_id(ast_format_ulaw)) {
+ return (
+ (c2 == ast_format_get_codec_id(ast_format_gsm)) ||
+ (c2 == ast_format_get_codec_id(ast_format_g729)) ||
+ (c2 == ast_format_get_codec_id(ast_format_g723))
+ );
+ }
+ return 0;
+}
+
/*! \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,
@@ -1474,6 +1496,15 @@
ao2_replace(bestdst, dst);
besttablecost = matrix_get(x, y)->table_cost;
beststeps = matrix_get(x, y)->multistep;
+ } else if (gap_current == gap_selected) {
+ if (ast_translator_better_quality(
+ ast_format_get_codec_id(src), ast_format_get_codec_id(best))) {
+ /* as good as what we had before and better */
+ ao2_replace(best, src);
+ ao2_replace(bestdst, dst);
+ besttablecost = matrix_get(x, y)->table_cost;
+ beststeps = matrix_get(x, y)->multistep;
+ }
}
}
}
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/15953
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: I4b7297e1baca7aac14fe4a3c7538e18e2dbe9fd6
Gerrit-Change-Number: 15953
Gerrit-PatchSet: 1
Gerrit-Owner: N A <mail at interlinked.x10host.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210527/4fe32453/attachment.html>
More information about the asterisk-code-review
mailing list