diff options
author | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-01-17 22:50:13 +0000 |
---|---|---|
committer | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-01-17 22:50:13 +0000 |
commit | 00e3ed0886658844b724186619425c31d411332b (patch) | |
tree | 1539459a1717b4f338b88661ab3d3155f81c01fe /main/frame.c | |
parent | 7806e71ba879aa650bcfefe29223ba088f4a7094 (diff) |
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: http://svn.digium.com/svn/asterisk/trunk@99006 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/frame.c')
-rw-r--r-- | main/frame.c | 38 |
1 files changed, 37 insertions, 1 deletions
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) |