aboutsummaryrefslogtreecommitdiffstats
path: root/main/frame.c
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2008-01-17 22:37:22 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2008-01-17 22:37:22 +0000
commit37d625d3a31eeff735c2f1d983dc38d8d438f8e4 (patch)
tree276f918e8a4600b6170a2d6cd02cae91c27b8232 /main/frame.c
parentdedde188e696656e16d157fa2ed2f5c04e2ce5f7 (diff)
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/branches/1.4@99004 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/frame.c')
-rw-r--r--main/frame.c38
1 files changed, 37 insertions, 1 deletions
diff --git a/main/frame.c b/main/frame.c
index 88f6b4e76..9ac309fa3 100644
--- a/main/frame.c
+++ b/main/frame.c
@@ -1149,7 +1149,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);
@@ -1172,6 +1172,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)