Ignore:
Timestamp:
Feb 4, 2016 6:11:58 AM (8 years ago)
Author:
ming
Message:

Fixed #1904: Support for Opus codec

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/src/pjmedia/stream_info.c

    r4930 r5239  
    3434static const pj_str_t ID_TELEPHONE_EVENT = { "telephone-event", 15 }; 
    3535 
     36static void get_opus_channels_and_clock_rate(const pjmedia_codec_fmtp *enc_fmtp, 
     37                                             const pjmedia_codec_fmtp *dec_fmtp, 
     38                                             unsigned *channel_cnt, 
     39                                             unsigned *clock_rate) 
     40{ 
     41    unsigned i; 
     42    unsigned enc_channel_cnt = 0, local_channel_cnt = 0; 
     43    unsigned enc_clock_rate = 0, local_clock_rate = 0; 
     44 
     45    for (i = 0; i < dec_fmtp->cnt; ++i) { 
     46        if (!pj_stricmp2(&dec_fmtp->param[i].name, "sprop-maxcapturerate")) { 
     47            local_clock_rate = (unsigned)pj_strtoul(&dec_fmtp->param[i].val); 
     48        } else if (!pj_stricmp2(&dec_fmtp->param[i].name, "sprop-stereo")) { 
     49            local_channel_cnt = (unsigned)pj_strtoul(&dec_fmtp->param[i].val); 
     50            local_channel_cnt = (local_channel_cnt > 0) ? 2 : 1; 
     51        } 
     52    } 
     53    if (!local_clock_rate) local_clock_rate = *clock_rate; 
     54    if (!local_channel_cnt) local_channel_cnt = *channel_cnt; 
     55 
     56    for (i = 0; i < enc_fmtp->cnt; ++i) { 
     57        if (!pj_stricmp2(&enc_fmtp->param[i].name, "maxplaybackrate")) { 
     58            enc_clock_rate = (unsigned)pj_strtoul(&enc_fmtp->param[i].val); 
     59        } else if (!pj_stricmp2(&enc_fmtp->param[i].name, "stereo")) { 
     60            enc_channel_cnt = (unsigned)pj_strtoul(&enc_fmtp->param[i].val); 
     61            enc_channel_cnt = (enc_channel_cnt > 0) ? 2 : 1; 
     62        } 
     63    } 
     64    /* The default is a standard mono session with 48000 Hz clock rate 
     65     * (RFC 7587, section 7) 
     66     */ 
     67    if (!enc_clock_rate) enc_clock_rate = 48000; 
     68    if (!enc_channel_cnt) enc_channel_cnt = 1; 
     69 
     70    *clock_rate = (enc_clock_rate < local_clock_rate) ? enc_clock_rate : 
     71                  local_clock_rate; 
     72 
     73    *channel_cnt = (enc_channel_cnt < local_channel_cnt) ? enc_channel_cnt : 
     74                   local_channel_cnt; 
     75} 
     76 
    3677/* 
    3778 * Internal function for collecting codec info and param from the SDP media. 
     
    218259    pjmedia_stream_info_parse_fmtp(pool, local_m, si->rx_pt, 
    219260                                   &si->param->setting.dec_fmtp); 
     261 
     262    if (!pj_stricmp2(&si->fmt.encoding_name, "opus")) { 
     263        get_opus_channels_and_clock_rate(&si->param->setting.enc_fmtp, 
     264                                         &si->param->setting.dec_fmtp, 
     265                                         &si->fmt.channel_cnt, 
     266                                         &si->fmt.clock_rate); 
     267    } 
     268 
    220269 
    221270    /* Get the remote ptime for our encoder. */ 
Note: See TracChangeset for help on using the changeset viewer.