summaryrefslogtreecommitdiff
path: root/pjmedia/include
diff options
context:
space:
mode:
authorLiong Sauw Ming <ming@teluu.com>2016-02-04 06:11:58 +0000
committerLiong Sauw Ming <ming@teluu.com>2016-02-04 06:11:58 +0000
commit56f6e91963bbd507c300e4f2a806a8db2935566d (patch)
treee0ab33100a9c31f1c7872ddc22787011a04b64c3 /pjmedia/include
parente6a13543eb90a73b095c4aa84038753d31ff2b39 (diff)
Fixed #1904: Support for Opus codec
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@5239 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjmedia/include')
-rw-r--r--pjmedia/include/pjmedia-codec.h1
-rw-r--r--pjmedia/include/pjmedia-codec/config.h50
-rw-r--r--pjmedia/include/pjmedia-codec/config_auto.h.in5
-rw-r--r--pjmedia/include/pjmedia-codec/opus.h155
-rw-r--r--pjmedia/include/pjmedia-codec/types.h1
-rw-r--r--pjmedia/include/pjmedia/config.h1
6 files changed, 213 insertions, 0 deletions
diff --git a/pjmedia/include/pjmedia-codec.h b/pjmedia/include/pjmedia-codec.h
index a35c8540..082c5db7 100644
--- a/pjmedia/include/pjmedia-codec.h
+++ b/pjmedia/include/pjmedia-codec.h
@@ -38,6 +38,7 @@
#include <pjmedia-codec/openh264.h>
#include <pjmedia-codec/passthrough.h>
#include <pjmedia-codec/silk.h>
+#include <pjmedia-codec/opus.h>
#endif /* __PJMEDIA_CODEC_PJMEDIA_CODEC_H__ */
diff --git a/pjmedia/include/pjmedia-codec/config.h b/pjmedia/include/pjmedia-codec/config.h
index 875c821a..9a69099f 100644
--- a/pjmedia/include/pjmedia-codec/config.h
+++ b/pjmedia/include/pjmedia-codec/config.h
@@ -420,6 +420,56 @@
/**
+ * Enable OPUS codec.
+ *
+ * Default: 0
+ */
+#ifndef PJMEDIA_HAS_OPUS_CODEC
+# define PJMEDIA_HAS_OPUS_CODEC 0
+#endif
+
+/**
+ * OPUS codec sample rate.
+ *
+ * Default: 48000
+ */
+#ifndef PJMEDIA_CODEC_OPUS_DEFAULT_SAMPLE_RATE
+# define PJMEDIA_CODEC_OPUS_DEFAULT_SAMPLE_RATE 48000
+#endif
+
+/**
+ * OPUS codec default maximum average bit rate.
+ *
+ * Default: 0 (leave it to default value specified by Opus, which will
+ * take into account factors such as media content (speech/music), sample
+ * rate, channel count, etc).
+ */
+#ifndef PJMEDIA_CODEC_OPUS_DEFAULT_BIT_RATE
+# define PJMEDIA_CODEC_OPUS_DEFAULT_BIT_RATE 0
+#endif
+
+
+/**
+ * OPUS default encoding complexity, which is an integer from
+ * 0 to 10, where 0 is the lowest complexity and 10 is the highest.
+ *
+ * Default: 5
+ */
+#ifndef PJMEDIA_CODEC_OPUS_DEFAULT_COMPLEXITY
+# define PJMEDIA_CODEC_OPUS_DEFAULT_COMPLEXITY 5
+#endif
+
+
+/**
+ * OPUS default CBR (constant bit rate) setting
+ *
+ * Default: PJ_FALSE (which means Opus will use VBR (variable bit rate))
+ */
+#ifndef PJMEDIA_CODEC_OPUS_DEFAULT_CBR
+# define PJMEDIA_CODEC_OPUS_DEFAULT_CBR PJ_FALSE
+#endif
+
+/**
* Specify if FFMPEG codecs are available.
*
* Default: PJMEDIA_HAS_LIBAVCODEC
diff --git a/pjmedia/include/pjmedia-codec/config_auto.h.in b/pjmedia/include/pjmedia-codec/config_auto.h.in
index 746c1fc7..909d4d74 100644
--- a/pjmedia/include/pjmedia-codec/config_auto.h.in
+++ b/pjmedia/include/pjmedia-codec/config_auto.h.in
@@ -84,6 +84,11 @@
#undef PJMEDIA_HAS_SILK_CODEC
#endif
+/* OPUS codec */
+#ifndef PJMEDIA_HAS_OPUS_CODEC
+#undef PJMEDIA_HAS_OPUS_CODEC
+#endif
+
#endif /* __PJMEDIA_CODEC_CONFIG_AUTO_H_ */
diff --git a/pjmedia/include/pjmedia-codec/opus.h b/pjmedia/include/pjmedia-codec/opus.h
new file mode 100644
index 00000000..6f1e8ef5
--- /dev/null
+++ b/pjmedia/include/pjmedia-codec/opus.h
@@ -0,0 +1,155 @@
+/* $Id$ */
+/*
+ * Copyright (C) 2015-2016 Teluu Inc. (http://www.teluu.com)
+ * Copyright (C) 2012-2015 Zaark Technology AB
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+/* This file is the header of Opus codec wrapper and was contributed by
+ * Zaark Technology AB
+ */
+
+#ifndef __PJMEDIA_CODEC_OPUS_H__
+#define __PJMEDIA_CODEC_OPUS_H__
+
+/**
+ * @file opus.h
+ * @brief Opus codec.
+ */
+
+#include <pjmedia-codec/types.h>
+
+PJ_BEGIN_DECL
+
+/**
+ * @defgroup PJMED_OPUS Opus Codec Family
+ * @ingroup PJMEDIA_CODEC_CODECS
+ * @brief Opus codec wrapper
+ * @{
+ *
+ * This section describes functions to initialize and register Opus codec
+ * factory to the codec manager. After the codec factory has been registered,
+ * application can use @ref PJMEDIA_CODEC API to manipulate the codec.
+ *
+ * Opus codec uses multiple bit rates, and supports fullband (48 kHz
+ * sampling rate), super wideband (24 kHz sampling rate), wideband (16 kHz
+ * sampling rate), medium band (12kHz sampling rate), and narrowband
+ * (8 kHz sampling rate).
+ *
+ *
+ * \section codec_setting Codec Settings
+ *
+ * General codec settings for this codec such as VAD and PLC can be
+ * manipulated through the <tt>setting</tt> field in #pjmedia_codec_param
+ * (see the documentation of #pjmedia_codec_param for more info).
+ *
+ * For Opus codec specific settings, such as sample rate,
+ * channel count, bit rate, complexity, and CBR, can be configured
+ * in #pjmedia_codec_opus_config.
+ * The default setting of sample rate is specified in
+ * #PJMEDIA_CODEC_OPUS_DEFAULT_SAMPLE_RATE. The default setting of
+ * bitrate is specified in #PJMEDIA_CODEC_OPUS_DEFAULT_BIT_RATE.
+ * And the default setting of complexity is specified in
+ * #PJMEDIA_CODEC_OPUS_DEFAULT_COMPLEXITY.
+ *
+ * After modifying any of these settings, application needs to call
+ * #pjmedia_codec_opus_set_default_param(), which will generate the
+ * appropriate decoding fmtp attributes.
+ *
+ * Here is an example of modifying the codec settings:
+ \code
+ pjmedia_codec_param param;
+ pjmedia_codec_opus_config opus_cfg;
+
+ pjmedia_codec_mgr_get_default_param(.., &param);
+ pjmedia_codec_opus_get_config(&opus_cfg);
+ ...
+ // Set VAD
+ param.setting.vad = 1;
+ // Set PLC
+ param.setting.vad = 1;
+ // Set sample rate
+ opus_cfg.sample_rate = 16000;
+ // Set channel count
+ opus_cfg.channel_cnt = 2;
+ // Set bit rate
+ opus_cfg.bit_rate = 20000;
+ ...
+ pjmedia_codec_opus_set_default_param(&opus_cfg, &param);
+ \endcode
+ *
+ */
+
+/**
+ * Opus codec configuration.
+ */
+typedef struct pjmedia_codec_opus_config
+{
+ unsigned sample_rate; /**< Sample rate in Hz. */
+ unsigned channel_cnt; /**< Number of channels. */
+ unsigned bit_rate; /**< Encoder bit rate in bps. */
+ unsigned packet_loss; /**< Encoder's expected packet loss pct. */
+ unsigned complexity; /**< Encoder complexity, 0-10(10 is highest)*/
+ pj_bool_t cbr; /**< Constant bit rate? */
+} pjmedia_codec_opus_config;
+
+
+/**
+ * Initialize and register Opus codec factory to pjmedia endpoint.
+ *
+ * @param endpt The pjmedia endpoint.
+ *
+ * @return PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) pjmedia_codec_opus_init( pjmedia_endpt *endpt );
+
+/**
+ * Unregister Opus codec factory from pjmedia endpoint and deinitialize
+ * the Opus codec library.
+ *
+ * @return PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) pjmedia_codec_opus_deinit( void );
+
+/**
+ * Get the default Opus configuration.
+ *
+ * @param cfg Opus codec configuration.
+ *
+ * @return PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t)
+pjmedia_codec_opus_get_config( pjmedia_codec_opus_config *cfg );
+
+/**
+ * Set the default Opus configuration and set the default Opus codec param.
+ * Note that the function will call #pjmedia_codec_mgr_set_default_param().
+ *
+ * @param cfg Opus codec configuration.
+ * @param param The new default Opus codec parameter.
+ *
+ * @return PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t)
+pjmedia_codec_opus_set_default_param(const pjmedia_codec_opus_config *cfg,
+ pjmedia_codec_param *param );
+
+PJ_END_DECL
+
+/**
+ * @}
+ */
+
+#endif /* __PJMEDIA_CODEC_OPUS_H__ */
diff --git a/pjmedia/include/pjmedia-codec/types.h b/pjmedia/include/pjmedia-codec/types.h
index d0549f5e..98368eff 100644
--- a/pjmedia/include/pjmedia-codec/types.h
+++ b/pjmedia/include/pjmedia-codec/types.h
@@ -83,6 +83,7 @@ enum pjmedia_audio_pt
PJMEDIA_RTP_PT_G7221C_48, /**< G722.1 Annex C (48Kbps)*/
PJMEDIA_RTP_PT_G7221_RSV1, /**< G722.1 reserve */
PJMEDIA_RTP_PT_G7221_RSV2, /**< G722.1 reserve */
+ PJMEDIA_RTP_PT_OPUS, /**< OPUS */
PJMEDIA_RTP_PT_L16_8KHZ_MONO, /**< L16 @ 8KHz, mono */
PJMEDIA_RTP_PT_L16_8KHZ_STEREO, /**< L16 @ 8KHz, stereo */
//PJMEDIA_RTP_PT_L16_11KHZ_MONO, /**< L16 @ 11KHz, mono */
diff --git a/pjmedia/include/pjmedia/config.h b/pjmedia/include/pjmedia/config.h
index f2f8e829..8d739d2a 100644
--- a/pjmedia/include/pjmedia/config.h
+++ b/pjmedia/include/pjmedia/config.h
@@ -972,6 +972,7 @@
* See:
* - G.722 : RFC 3551 4.5.2
* - MPEG audio : RFC 3551 4.5.13 & RFC 3119
+ * - OPUS : RFC 7587
*
* Also when this feature is enabled, some handling will be performed
* to deal with clock rate incompatibilities of some phones.