[asterisk-commits] tilghman: trunk r49784 - /trunk/main/channel.c
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Sun Jan 7 07:32:21 MST 2007
Author: tilghman
Date: Sun Jan 7 08:32:20 2007
New Revision: 49784
URL: http://svn.digium.com/view/asterisk?view=rev&rev=49784
Log:
Reduce duplication of code (Issue 6542)
Modified:
trunk/main/channel.c
Modified: trunk/main/channel.c
URL: http://svn.digium.com/view/asterisk/trunk/main/channel.c?view=diff&rev=49784&r1=49783&r2=49784
==============================================================================
--- trunk/main/channel.c (original)
+++ trunk/main/channel.c Sun Jan 7 08:32:20 2007
@@ -3014,16 +3014,17 @@
return ast_channel_sendhtml(chan, AST_HTML_URL, url, strlen(url) + 1);
}
-int ast_channel_make_compatible(struct ast_channel *chan, struct ast_channel *peer)
+/*! \brief Set up translation from one channel to another */
+static int ast_channel_make_compatible_helper(struct ast_channel *from, struct ast_channel *to)
{
int src;
int dst;
- /* Set up translation from the chan to the peer */
- src = chan->nativeformats;
- dst = peer->nativeformats;
+ /* Set up translation from the 'from' channel to the 'to' channel */
+ src = from->nativeformats;
+ dst = to->nativeformats;
if (ast_translator_best_choice(&dst, &src) < 0) {
- ast_log(LOG_WARNING, "No path to translate from %s(%d) to %s(%d)\n", chan->name, src, peer->name, dst);
+ ast_log(LOG_WARNING, "No path to translate from %s(%d) to %s(%d)\n", from->name, src, to->name, dst);
return -1;
}
@@ -3034,39 +3035,32 @@
if ((src != dst) && ast_opt_transcode_via_slin &&
(ast_translate_path_steps(dst, src) != 1))
dst = AST_FORMAT_SLINEAR;
- if (ast_set_read_format(chan, dst) < 0) {
- ast_log(LOG_WARNING, "Unable to set read format on channel %s to %d\n", chan->name, dst);
+ if (ast_set_read_format(from, dst) < 0) {
+ ast_log(LOG_WARNING, "Unable to set read format on channel %s to %d\n", from->name, dst);
return -1;
}
- if (ast_set_write_format(peer, dst) < 0) {
- ast_log(LOG_WARNING, "Unable to set write format on channel %s to %d\n", peer->name, dst);
+ if (ast_set_write_format(to, dst) < 0) {
+ ast_log(LOG_WARNING, "Unable to set write format on channel %s to %d\n", to->name, dst);
return -1;
}
+ return 0;
+}
+
+int ast_channel_make_compatible(struct ast_channel *chan, struct ast_channel *peer)
+{
+ /* Some callers do not check return code, and we must try to set all call legs correctly */
+ int rc = 0;
+
+ /* Set up translation from the chan to the peer */
+ rc = ast_channel_make_compatible_helper(chan, peer);
+
+ if (rc < 0)
+ return rc;
/* Set up translation from the peer to the chan */
- src = peer->nativeformats;
- dst = chan->nativeformats;
- if (ast_translator_best_choice(&dst, &src) < 0) {
- ast_log(LOG_WARNING, "No path to translate from %s(%d) to %s(%d)\n", peer->name, src, chan->name, dst);
- return -1;
- }
-
- /* if the best path is not 'pass through', then
- transcoding is needed; if desired, force transcode path
- to use SLINEAR between channels, but only if there is
- no direct conversion available */
- if ((src != dst) && ast_opt_transcode_via_slin &&
- (ast_translate_path_steps(dst, src) != 1))
- dst = AST_FORMAT_SLINEAR;
- if (ast_set_read_format(peer, dst) < 0) {
- ast_log(LOG_WARNING, "Unable to set read format on channel %s to %d\n", peer->name, dst);
- return -1;
- }
- if (ast_set_write_format(chan, dst) < 0) {
- ast_log(LOG_WARNING, "Unable to set write format on channel %s to %d\n", chan->name, dst);
- return -1;
- }
- return 0;
+ rc = ast_channel_make_compatible_helper(peer, chan);
+
+ return rc;
}
int ast_channel_masquerade(struct ast_channel *original, struct ast_channel *clone)
More information about the asterisk-commits
mailing list