Changeset 5239


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

Fixed #1904: Support for Opus codec

Location:
pjproject/trunk
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/aconfigure

    r5199 r5239  
    624624ac_host 
    625625ac_linux_poll 
     626opus_present 
     627opus_h_present 
     628ac_no_opus 
    626629silk_present 
    627630silk_h_present 
     
    817820with_silk 
    818821enable_silk 
     822with_opus 
     823enable_opus 
    819824' 
    820825      ac_precious_vars='build_alias 
     
    14811486 
    14821487  --disable-silk          Exclude SILK support from the build (default: 
     1488                          autodetect) 
     1489 
     1490  --disable-opus          Exclude OPUS support from the build (default: 
    14831491                          autodetect) 
    14841492 
     
    15241532                          Specify alternate libvo-amrwbenc prefix 
    15251533  --with-silk=DIR         Specify alternate SILK prefix 
     1534  --with-opus=DIR         Specify alternate OPUS prefix 
    15261535 
    15271536Some influential environment variables: 
     
    82278236 
    82288237 
     8238if test "x$ac_cross_compile" != "x" -a "x$with_opus" = "xno"; then 
     8239    enable_opus=no 
     8240fi 
     8241 
     8242 
     8243# Check whether --with-opus was given. 
     8244if test "${with_opus+set}" = set; then : 
     8245  withval=$with_opus; 
     8246else 
     8247  with_opus=no 
     8248 
     8249fi 
     8250 
     8251 
     8252 
     8253# Check whether --enable-opus was given. 
     8254if test "${enable_opus+set}" = set; then : 
     8255  enableval=$enable_opus; 
     8256                if test "$enable_opus" = "no"; then 
     8257                 ac_no_opus=1 
     8258                 $as_echo "#define PJMEDIA_HAS_OPUS_CODEC 0" >>confdefs.h 
     8259 
     8260                 { $as_echo "$as_me:${as_lineno-$LINENO}: result: Checking if OPUS support is disabled... yes" >&5 
     8261$as_echo "Checking if OPUS support is disabled... yes" >&6; } 
     8262                fi 
     8263 
     8264else 
     8265 
     8266                { $as_echo "$as_me:${as_lineno-$LINENO}: result: checking for OPUS installations.." >&5 
     8267$as_echo "checking for OPUS installations.." >&6; } 
     8268                if test "x$with_opus" != "xno" -a "x$with_opus" != "x"; then 
     8269                    CFLAGS="$CFLAGS -I$with_opus/include" 
     8270                    CPPFLAGS="$CPPFLAGS -I$with_opus/include" 
     8271                    LDFLAGS="$LDFLAGS -L$with_opus/lib" 
     8272                    { $as_echo "$as_me:${as_lineno-$LINENO}: result: Using OPUS prefix... $with_opus" >&5 
     8273$as_echo "Using OPUS prefix... $with_opus" >&6; } 
     8274                fi 
     8275 
     8276 
     8277                ac_fn_c_check_header_mongrel "$LINENO" "opus/opus.h" "ac_cv_header_opus_opus_h" "$ac_includes_default" 
     8278if test "x$ac_cv_header_opus_opus_h" = xyes; then : 
     8279  opus_h_present=1 
     8280fi 
     8281 
     8282 
     8283                { $as_echo "$as_me:${as_lineno-$LINENO}: checking for opus_repacketizer_get_size in -lopus" >&5 
     8284$as_echo_n "checking for opus_repacketizer_get_size in -lopus... " >&6; } 
     8285if ${ac_cv_lib_opus_opus_repacketizer_get_size+:} false; then : 
     8286  $as_echo_n "(cached) " >&6 
     8287else 
     8288  ac_check_lib_save_LIBS=$LIBS 
     8289LIBS="-lopus  $LIBS" 
     8290cat confdefs.h - <<_ACEOF >conftest.$ac_ext 
     8291/* end confdefs.h.  */ 
     8292 
     8293/* Override any GCC internal prototype to avoid an error. 
     8294   Use char because int might match the return type of a GCC 
     8295   builtin and then its argument prototype would still apply.  */ 
     8296#ifdef __cplusplus 
     8297extern "C" 
     8298#endif 
     8299char opus_repacketizer_get_size (); 
     8300int 
     8301main () 
     8302{ 
     8303return opus_repacketizer_get_size (); 
     8304  ; 
     8305  return 0; 
     8306} 
     8307_ACEOF 
     8308if ac_fn_c_try_link "$LINENO"; then : 
     8309  ac_cv_lib_opus_opus_repacketizer_get_size=yes 
     8310else 
     8311  ac_cv_lib_opus_opus_repacketizer_get_size=no 
     8312fi 
     8313rm -f core conftest.err conftest.$ac_objext \ 
     8314    conftest$ac_exeext conftest.$ac_ext 
     8315LIBS=$ac_check_lib_save_LIBS 
     8316fi 
     8317{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_opus_opus_repacketizer_get_size" >&5 
     8318$as_echo "$ac_cv_lib_opus_opus_repacketizer_get_size" >&6; } 
     8319if test "x$ac_cv_lib_opus_opus_repacketizer_get_size" = xyes; then : 
     8320  opus_present=1 && LIBS="$LIBS -lopus" 
     8321fi 
     8322 
     8323                if test "x$opus_h_present" = "x1" -a "x$opus_present" = "x1"; then 
     8324                        { $as_echo "$as_me:${as_lineno-$LINENO}: result: OPUS library found, OPUS support enabled" >&5 
     8325$as_echo "OPUS library found, OPUS support enabled" >&6; } 
     8326                        $as_echo "#define PJMEDIA_HAS_OPUS_CODEC 1" >>confdefs.h 
     8327 
     8328                else 
     8329                        ac_no_opus=1 
     8330                        { $as_echo "$as_me:${as_lineno-$LINENO}: result: OPUS library not found, OPUS support disabled" >&5 
     8331$as_echo "OPUS library not found, OPUS support disabled" >&6; } 
     8332                        $as_echo "#define PJMEDIA_HAS_OPUS_CODEC 0" >>confdefs.h 
     8333 
     8334                fi 
     8335 
     8336fi 
     8337 
     8338 
    82298339 
    82308340 
  • pjproject/trunk/aconfigure.ac

    r5199 r5239  
    17621762              ]) 
    17631763 
     1764dnl # Do not use default OPUS installation if we are cross-compiling 
     1765if test "x$ac_cross_compile" != "x" -a "x$with_opus" = "xno"; then 
     1766    enable_opus=no 
     1767fi 
     1768 
     1769dnl # OPUS prefix 
     1770AC_ARG_WITH(opus, 
     1771    AC_HELP_STRING([--with-opus=DIR], 
     1772                   [Specify alternate OPUS prefix]), 
     1773    [], 
     1774    [with_opus=no] 
     1775    ) 
     1776 
     1777dnl # Include OPUS support 
     1778AC_SUBST(ac_no_opus) 
     1779AC_ARG_ENABLE(opus, 
     1780              AC_HELP_STRING([--disable-opus], 
     1781                             [Exclude OPUS support from the build (default: autodetect)]) 
     1782              , 
     1783              [ 
     1784                if test "$enable_opus" = "no"; then 
     1785                 [ac_no_opus=1] 
     1786                 AC_DEFINE(PJMEDIA_HAS_OPUS_CODEC,0) 
     1787                 AC_MSG_RESULT([Checking if OPUS support is disabled... yes]) 
     1788                fi 
     1789              ], 
     1790              [ 
     1791                AC_MSG_RESULT([checking for OPUS installations..]) 
     1792                if test "x$with_opus" != "xno" -a "x$with_opus" != "x"; then 
     1793                    CFLAGS="$CFLAGS -I$with_opus/include" 
     1794                    CPPFLAGS="$CPPFLAGS -I$with_opus/include" 
     1795                    LDFLAGS="$LDFLAGS -L$with_opus/lib" 
     1796                    AC_MSG_RESULT([Using OPUS prefix... $with_opus]) 
     1797                fi 
     1798                AC_SUBST(opus_h_present) 
     1799                AC_SUBST(opus_present) 
     1800                AC_CHECK_HEADER(opus/opus.h,[opus_h_present=1]) 
     1801                AC_CHECK_LIB(opus,opus_repacketizer_get_size,[opus_present=1 && LIBS="$LIBS -lopus"]) 
     1802                if test "x$opus_h_present" = "x1" -a "x$opus_present" = "x1"; then 
     1803                        AC_MSG_RESULT([OPUS library found, OPUS support enabled]) 
     1804                        AC_DEFINE(PJMEDIA_HAS_OPUS_CODEC,1) 
     1805                else 
     1806                        [ac_no_opus=1] 
     1807                        AC_MSG_RESULT([OPUS library not found, OPUS support disabled]) 
     1808                        AC_DEFINE(PJMEDIA_HAS_OPUS_CODEC,0) 
     1809                fi 
     1810              ]) 
     1811 
    17641812 
    17651813dnl ########################################## 
  • pjproject/trunk/pjmedia/build/Makefile

    r5186 r5239  
    139139                        h263_packetizer.o h264_packetizer.o \ 
    140140                        $(OS_OBJS) $(M_OBJS) $(CC_OBJS) $(HOST_OBJS) \ 
    141                         ipp_codecs.o silk.o $(CODEC_OBJS) \ 
     141                        ipp_codecs.o silk.o opus.o $(CODEC_OBJS) \ 
    142142                        g7221_sdp_match.o amr_sdp_match.o 
    143143export PJMEDIA_CODEC_CFLAGS += $(_CFLAGS) $(GSM_CFLAGS) $(SPEEX_CFLAGS) \ 
  • pjproject/trunk/pjmedia/include/pjmedia-codec.h

    r4815 r5239  
    3939#include <pjmedia-codec/passthrough.h> 
    4040#include <pjmedia-codec/silk.h> 
     41#include <pjmedia-codec/opus.h> 
    4142 
    4243 
  • pjproject/trunk/pjmedia/include/pjmedia-codec/config.h

    r4331 r5239  
    421421 
    422422/** 
     423 * Enable OPUS codec. 
     424 * 
     425 * Default: 0 
     426 */ 
     427#ifndef PJMEDIA_HAS_OPUS_CODEC 
     428#   define PJMEDIA_HAS_OPUS_CODEC                       0 
     429#endif 
     430 
     431/** 
     432 * OPUS codec sample rate. 
     433 * 
     434 * Default: 48000 
     435 */ 
     436#ifndef PJMEDIA_CODEC_OPUS_DEFAULT_SAMPLE_RATE 
     437#   define PJMEDIA_CODEC_OPUS_DEFAULT_SAMPLE_RATE       48000 
     438#endif 
     439 
     440/** 
     441 * OPUS codec default maximum average bit rate. 
     442 * 
     443 * Default: 0 (leave it to default value specified by Opus, which will 
     444 * take into account factors such as media content (speech/music), sample 
     445 * rate, channel count, etc). 
     446 */ 
     447#ifndef PJMEDIA_CODEC_OPUS_DEFAULT_BIT_RATE 
     448#   define PJMEDIA_CODEC_OPUS_DEFAULT_BIT_RATE          0 
     449#endif 
     450 
     451 
     452/** 
     453 * OPUS default encoding complexity, which is an integer from 
     454 * 0 to 10, where 0 is the lowest complexity and 10 is the highest. 
     455 * 
     456 * Default: 5 
     457 */ 
     458#ifndef PJMEDIA_CODEC_OPUS_DEFAULT_COMPLEXITY 
     459#   define PJMEDIA_CODEC_OPUS_DEFAULT_COMPLEXITY        5 
     460#endif 
     461 
     462 
     463/** 
     464 * OPUS default CBR (constant bit rate) setting 
     465 * 
     466 * Default: PJ_FALSE (which means Opus will use VBR (variable bit rate)) 
     467 */ 
     468#ifndef PJMEDIA_CODEC_OPUS_DEFAULT_CBR 
     469#   define PJMEDIA_CODEC_OPUS_DEFAULT_CBR               PJ_FALSE 
     470#endif 
     471 
     472/** 
    423473 * Specify if FFMPEG codecs are available. 
    424474 * 
  • pjproject/trunk/pjmedia/include/pjmedia-codec/config_auto.h.in

    r4331 r5239  
    8585#endif 
    8686 
     87/* OPUS codec */ 
     88#ifndef PJMEDIA_HAS_OPUS_CODEC 
     89#undef PJMEDIA_HAS_OPUS_CODEC 
     90#endif 
     91 
    8792#endif  /* __PJMEDIA_CODEC_CONFIG_AUTO_H_ */ 
    8893 
  • pjproject/trunk/pjmedia/include/pjmedia-codec/types.h

    r4264 r5239  
    8484    PJMEDIA_RTP_PT_G7221_RSV1,                  /**< G722.1 reserve         */ 
    8585    PJMEDIA_RTP_PT_G7221_RSV2,                  /**< G722.1 reserve         */ 
     86    PJMEDIA_RTP_PT_OPUS,                        /**< OPUS                   */ 
    8687    PJMEDIA_RTP_PT_L16_8KHZ_MONO,               /**< L16 @ 8KHz, mono       */ 
    8788    PJMEDIA_RTP_PT_L16_8KHZ_STEREO,             /**< L16 @ 8KHz, stereo     */ 
  • pjproject/trunk/pjmedia/include/pjmedia/config.h

    r5186 r5239  
    973973 *  - G.722      : RFC 3551 4.5.2 
    974974 *  - MPEG audio : RFC 3551 4.5.13 & RFC 3119 
     975 *  - OPUS       : RFC 7587 
    975976 * 
    976977 * Also when this feature is enabled, some handling will be performed 
  • pjproject/trunk/pjmedia/src/pjmedia-codec/audio_codecs.c

    r4335 r5239  
    122122#endif 
    123123 
     124#if PJMEDIA_HAS_OPUS_CODEC 
     125    /* Register OPUS */ 
     126    status = pjmedia_codec_opus_init(endpt); 
     127    if (status != PJ_SUCCESS) 
     128        return status; 
     129#endif 
     130 
    124131    return PJ_SUCCESS; 
    125132} 
  • pjproject/trunk/pjmedia/src/pjmedia/stream.c

    r5234 r5239  
    21102110 
    21112111    /* Open the codec. */ 
     2112 
     2113    /* The clock rate for Opus codec is not static, 
     2114     * it's negotiated in the SDP. 
     2115     */ 
     2116    if (!pj_stricmp2(&info->fmt.encoding_name, "opus")) { 
     2117        stream->codec_param.info.clock_rate = info->fmt.clock_rate; 
     2118        stream->codec_param.info.channel_cnt = info->fmt.channel_cnt; 
     2119    } 
     2120 
    21122121    status = pjmedia_codec_open(stream->codec, &stream->codec_param); 
    21132122    if (status != PJ_SUCCESS) 
     
    22242233        /* RTP clock rate = 1/2 real clock rate */ 
    22252234        stream->rtp_tx_ts_len_per_pkt >>= 1; 
     2235    } else if (!pj_stricmp2(&info->fmt.encoding_name, "opus")) { 
     2236        unsigned opus_ts_modifier = 48000 / afd->clock_rate; 
     2237        stream->rtp_rx_check_cnt = 0; 
     2238        stream->has_g722_mpeg_bug = PJ_TRUE; 
     2239        stream->rtp_tx_ts_len_per_pkt *= opus_ts_modifier; 
     2240        stream->rtp_rx_ts_len_per_frame *= opus_ts_modifier; 
    22262241    } 
    22272242#endif 
  • 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.