Ignore:
Timestamp:
Jan 26, 2010 3:29:23 PM (14 years ago)
Author:
nanang
Message:

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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/src/pjmedia-codec/passthrough.c

    r2997 r3074  
    2525#include <pj/assert.h> 
    2626#include <pj/log.h> 
     27#include <pj/math.h> 
    2728#include <pj/pool.h> 
    2829#include <pj/string.h> 
     
    681682        amr_settings_t *s; 
    682683        pj_uint8_t octet_align = 0; 
    683         const pj_str_t STR_FMTP_OCTET_ALIGN = {"octet-align", 11}; 
     684        pj_int8_t enc_mode; 
     685 
     686        enc_mode = pjmedia_codec_amr_get_mode(attr->info.avg_bps); 
     687        pj_assert(enc_mode >= 0 && enc_mode <= 8); 
    684688 
    685689        /* Fetch octet-align setting. It should be fine to fetch only  
     
    688692         */ 
    689693        for (i = 0; i < attr->setting.dec_fmtp.cnt; ++i) { 
     694            const pj_str_t STR_FMTP_OCTET_ALIGN = {"octet-align", 11}; 
     695 
    690696            if (pj_stricmp(&attr->setting.dec_fmtp.param[i].name,  
    691697                           &STR_FMTP_OCTET_ALIGN) == 0) 
     
    697703        } 
    698704 
     705        for (i = 0; i < attr->setting.enc_fmtp.cnt; ++i) { 
     706            /* mode-set, encoding mode is chosen based on local default mode  
     707             * setting: 
     708             * - if local default mode is included in the mode-set, use it 
     709             * - otherwise, find the closest mode to local default mode; 
     710             *   if there are two closest modes, prefer to use the higher 
     711             *   one, e.g: local default mode is 4, the mode-set param 
     712             *   contains '2,3,5,6', then 5 will be chosen. 
     713             */ 
     714            const pj_str_t STR_FMTP_MODE_SET = {"mode-set", 8}; 
     715             
     716            if (pj_stricmp(&attr->setting.enc_fmtp.param[i].name,  
     717                           &STR_FMTP_MODE_SET) == 0) 
     718            { 
     719                const char *p; 
     720                pj_size_t l; 
     721                pj_int8_t diff = 99; 
     722                 
     723                p = pj_strbuf(&attr->setting.enc_fmtp.param[i].val); 
     724                l = pj_strlen(&attr->setting.enc_fmtp.param[i].val); 
     725 
     726                while (l--) { 
     727                    if ((desc->pt==PJMEDIA_RTP_PT_AMR && *p>='0' && *p<='7') || 
     728                        (desc->pt==PJMEDIA_RTP_PT_AMRWB && *p>='0' && *p<='8')) 
     729                    { 
     730                        pj_int8_t tmp = (pj_int8_t)(*p - '0' - enc_mode); 
     731 
     732                        if (PJ_ABS(diff) > PJ_ABS(tmp) ||  
     733                            (PJ_ABS(diff) == PJ_ABS(tmp) && tmp > diff)) 
     734                        { 
     735                            diff = tmp; 
     736                            if (diff == 0) break; 
     737                        } 
     738                    } 
     739                    ++p; 
     740                } 
     741 
     742                if (diff == 99) 
     743                    return PJMEDIA_CODEC_EFAILED; 
     744 
     745                enc_mode = (pj_int8_t)(enc_mode + diff); 
     746 
     747                break; 
     748            } 
     749        } 
     750 
    699751        s = PJ_POOL_ZALLOC_T(pool, amr_settings_t); 
    700752        codec_data->codec_setting = s; 
    701753 
    702         s->enc_mode = pjmedia_codec_amr_get_mode(desc->def_bitrate); 
     754        s->enc_mode = enc_mode; 
    703755        if (s->enc_mode < 0) 
    704756            return PJMEDIA_CODEC_EINMODE; 
     
    716768                                              doesn't do sensitivity bits  
    717769                                              reordering */ 
     770 
     771        /* Return back bitrate info to application */ 
     772        attr->info.avg_bps = s->enc_setting.amr_nb? 
     773                                pjmedia_codec_amrnb_bitrates[s->enc_mode]: 
     774                                pjmedia_codec_amrwb_bitrates[s->enc_mode]; 
    718775    } 
    719776#endif 
Note: See TracChangeset for help on using the changeset viewer.