summaryrefslogtreecommitdiff
path: root/pjmedia/src/pjmedia-codec/passthrough.c
diff options
context:
space:
mode:
authorNanang Izzuddin <nanang@teluu.com>2010-01-26 15:29:23 +0000
committerNanang Izzuddin <nanang@teluu.com>2010-01-26 15:29:23 +0000
commit5900f75534e21f750e370ec230aec3d6cd58b850 (patch)
tree7fc83b5af3a016da146bcd3a468c1b02cbcb6522 /pjmedia/src/pjmedia-codec/passthrough.c
parent3b0e3817784670d13b0f0a62e28047e56c81042b (diff)
Ticket #1028:
- Added new API pjmedia_codec_mgr_set_default_param() to set/update default codec parameter and implemented pjsua_codec_set_param() based on it. - Added mutex in codec manager to protect states manipulations. - Modified API pjmedia_codec_mgr_init() to add pool factory param. - Added new API pjmedia_codec_mgr_destroy(). - Updated passthrough codec AMR to regard peer's mode-set setting. - Fixed VAS audio device to apply AMR encoding bitrate setting. - Fixed IPP codec codec_open() to update AMR bitrate info (for stream) when AMR encoding bitrate is not using the default, e.g: requested by peer via format param 'mode-set' in SDP. git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@3074 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjmedia/src/pjmedia-codec/passthrough.c')
-rw-r--r--pjmedia/src/pjmedia-codec/passthrough.c61
1 files changed, 59 insertions, 2 deletions
diff --git a/pjmedia/src/pjmedia-codec/passthrough.c b/pjmedia/src/pjmedia-codec/passthrough.c
index 06e4de69..f6a6e119 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>
@@ -680,13 +681,18 @@ static pj_status_t codec_open( pjmedia_codec *codec,
if (desc->pt == PJMEDIA_RTP_PT_AMR || desc->pt == PJMEDIA_RTP_PT_AMRWB) {
amr_settings_t *s;
pj_uint8_t octet_align = 0;
- const pj_str_t STR_FMTP_OCTET_ALIGN = {"octet-align", 11};
+ pj_int8_t enc_mode;
+
+ enc_mode = pjmedia_codec_amr_get_mode(attr->info.avg_bps);
+ pj_assert(enc_mode >= 0 && enc_mode <= 8);
/* Fetch octet-align setting. It should be fine to fetch only
* the decoder, since encoder & decoder must use the same setting
* (RFC 4867 section 8.3.1).
*/
for (i = 0; i < attr->setting.dec_fmtp.cnt; ++i) {
+ const pj_str_t STR_FMTP_OCTET_ALIGN = {"octet-align", 11};
+
if (pj_stricmp(&attr->setting.dec_fmtp.param[i].name,
&STR_FMTP_OCTET_ALIGN) == 0)
{
@@ -696,10 +702,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;
@@ -715,6 +767,11 @@ static pj_status_t codec_open( pjmedia_codec *codec,
s->dec_setting.reorder = PJ_FALSE; /* Note this! passthrough codec
doesn't do sensitivity bits
reordering */
+
+ /* Return back bitrate info to application */
+ attr->info.avg_bps = s->enc_setting.amr_nb?
+ pjmedia_codec_amrnb_bitrates[s->enc_mode]:
+ pjmedia_codec_amrwb_bitrates[s->enc_mode];
}
#endif