From 2a91da66138d909c6cd379634cca989bbfe7ab46 Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Thu, 17 Jan 2008 22:50:13 +0000 Subject: Merged revisions 99004 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r99004 | russell | 2008-01-17 16:37:22 -0600 (Thu, 17 Jan 2008) | 10 lines Have IAX2 optimize the codec translation path just like chan_sip does it. If the caller's codec is in our codec list, move it to the top to avoid transcoding. (closes issue #10500) Reported by: stevedavies Patches: iax-prefer-current-codec.patch uploaded by stevedavies (license 184) iax-prefer-current-codec.1.4.patch uploaded by stevedavies (license 184) Tested by: stevedavies, pj, sheldonh ........ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@99006 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- main/frame.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'main') diff --git a/main/frame.c b/main/frame.c index 9b7d15087..d46dd239c 100644 --- a/main/frame.c +++ b/main/frame.c @@ -1025,7 +1025,7 @@ void ast_codec_pref_remove(struct ast_codec_pref *pref, int format) /*! \brief Append codec to list */ int ast_codec_pref_append(struct ast_codec_pref *pref, int format) { - int x, newindex = -1; + int x, newindex = 0; ast_codec_pref_remove(pref, format); @@ -1048,6 +1048,42 @@ int ast_codec_pref_append(struct ast_codec_pref *pref, int format) return x; } +/*! \brief Prepend codec to list */ +void ast_codec_pref_prepend(struct ast_codec_pref *pref, int format, int only_if_existing) +{ + int x, newindex = 0; + + /* First step is to get the codecs "index number" */ + for (x = 0; x < ARRAY_LEN(AST_FORMAT_LIST); x++) { + if (AST_FORMAT_LIST[x].bits == format) { + newindex = x + 1; + break; + } + } + /* Done if its unknown */ + if (!newindex) + return; + + /* Now find any existing occurrence, or the end */ + for (x = 0; x < 32; x++) { + if (!pref->order[x] || pref->order[x] == newindex) + break; + } + + if (only_if_existing && !pref->order[x]) + return; + + /* Move down to make space to insert - either all the way to the end, + or as far as the existing location (which will be overwritten) */ + for (; x > 0; x--) { + pref->order[x] = pref->order[x - 1]; + pref->framing[x] = pref->framing[x - 1]; + } + + /* And insert the new entry */ + pref->order[0] = newindex; + pref->framing[0] = 0; /* ? */ +} /*! \brief Set packet size for codec */ int ast_codec_pref_setsize(struct ast_codec_pref *pref, int format, int framems) -- cgit v1.2.3