summaryrefslogtreecommitdiff
path: root/pjmedia/src/pjmedia-codec/passthrough.c
diff options
context:
space:
mode:
authorNanang Izzuddin <nanang@teluu.com>2010-01-27 11:48:31 +0000
committerNanang Izzuddin <nanang@teluu.com>2010-01-27 11:48:31 +0000
commitb4363f43a76411dcdbe60917d6ffe2d168cec3a2 (patch)
tree40bf7ba236ca1456a5d47360b711936d87d44011 /pjmedia/src/pjmedia-codec/passthrough.c
parent67983fb24f15e72df308c0e52f7055f38c09615c (diff)
Ticket #1028: Recommit r3074 with updated codec.h.
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@3078 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjmedia/src/pjmedia-codec/passthrough.c')
-rw-r--r--pjmedia/src/pjmedia-codec/passthrough.c49
1 files changed, 48 insertions, 1 deletions
diff --git a/pjmedia/src/pjmedia-codec/passthrough.c b/pjmedia/src/pjmedia-codec/passthrough.c
index 06e4de69..bcd8f81a 100644
--- a/pjmedia/src/pjmedia-codec/passthrough.c
+++ b/pjmedia/src/pjmedia-codec/passthrough.c
@@ -24,6 +24,7 @@
#include <pjmedia/port.h>
#include <pj/assert.h>
#include <pj/log.h>
+#include <pj/math.h>
#include <pj/pool.h>
#include <pj/string.h>
#include <pj/os.h>
@@ -696,10 +697,56 @@ static pj_status_t codec_open( pjmedia_codec *codec,
}
}
+ for (i = 0; i < attr->setting.enc_fmtp.cnt; ++i) {
+ /* mode-set, encoding mode is chosen based on local default mode
+ * setting:
+ * - if local default mode is included in the mode-set, use it
+ * - otherwise, find the closest mode to local default mode;
+ * if there are two closest modes, prefer to use the higher
+ * one, e.g: local default mode is 4, the mode-set param
+ * contains '2,3,5,6', then 5 will be chosen.
+ */
+ const pj_str_t STR_FMTP_MODE_SET = {"mode-set", 8};
+
+ if (pj_stricmp(&attr->setting.enc_fmtp.param[i].name,
+ &STR_FMTP_MODE_SET) == 0)
+ {
+ const char *p;
+ pj_size_t l;
+ pj_int8_t diff = 99;
+
+ p = pj_strbuf(&attr->setting.enc_fmtp.param[i].val);
+ l = pj_strlen(&attr->setting.enc_fmtp.param[i].val);
+
+ while (l--) {
+ if ((desc->pt==PJMEDIA_RTP_PT_AMR && *p>='0' && *p<='7') ||
+ (desc->pt==PJMEDIA_RTP_PT_AMRWB && *p>='0' && *p<='8'))
+ {
+ pj_int8_t tmp = (pj_int8_t)(*p - '0' - enc_mode);
+
+ if (PJ_ABS(diff) > PJ_ABS(tmp) ||
+ (PJ_ABS(diff) == PJ_ABS(tmp) && tmp > diff))
+ {
+ diff = tmp;
+ if (diff == 0) break;
+ }
+ }
+ ++p;
+ }
+
+ if (diff == 99)
+ return PJMEDIA_CODEC_EFAILED;
+
+ enc_mode = (pj_int8_t)(enc_mode + diff);
+
+ break;
+ }
+ }
+
s = PJ_POOL_ZALLOC_T(pool, amr_settings_t);
codec_data->codec_setting = s;
- s->enc_mode = pjmedia_codec_amr_get_mode(desc->def_bitrate);
+ s->enc_mode = enc_mode;
if (s->enc_mode < 0)
return PJMEDIA_CODEC_EINMODE;