Debian Codegraph @

Xpjproject/pjmedia/include/pjmedia-codec/opus.h

raw symbols SCIP
1 /*
2 * Copyright (C) 2015-2016 Teluu Inc. (http://www.teluu.com)
3 * Copyright (C) 2012-2015 Zaark Technology AB
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 /* This file is the header of Opus codec wrapper and was contributed by
20 * Zaark Technology AB
21 */
22
23 #ifndef __PJMEDIA_CODEC_OPUS_H__
24 #define __PJMEDIA_CODEC_OPUS_H__
25
26 /**
27 * @file opus.h
28 * @brief Opus codec.
29 */
30
31 #include <pjmedia-codec/types.h>
32
33 PJ_BEGIN_DECL
34
35 /**
36 * @defgroup PJMED_OPUS Opus Codec Family
37 * @ingroup PJMEDIA_CODEC_CODECS
38 * @brief Opus codec wrapper
39 * @{
40 *
41 * This section describes functions to initialize and register Opus codec
42 * factory to the codec manager. After the codec factory has been registered,
43 * application can use @ref PJMEDIA_CODEC API to manipulate the codec.
44 *
45 * Opus codec uses multiple bit rates, and supports fullband (48 kHz
46 * sampling rate), super wideband (24 kHz sampling rate), wideband (16 kHz
47 * sampling rate), medium band (12kHz sampling rate), and narrowband
48 * (8 kHz sampling rate).
49 *
50 *
51 * \section opus_codec_setting Codec Settings
52 *
53 * General codec settings for this codec such as VAD and PLC can be
54 * manipulated through the <tt>setting</tt> field in #pjmedia_codec_param
55 * (see the documentation of #pjmedia_codec_param for more info).
56 *
57 * For Opus codec specific settings, such as sample rate,
58 * channel count, bit rate, complexity, and CBR, can be configured
59 * in #pjmedia_codec_opus_config.
60 * The default setting of sample rate is specified in
61 * #PJMEDIA_CODEC_OPUS_DEFAULT_SAMPLE_RATE. The default setting of
62 * bitrate is specified in #PJMEDIA_CODEC_OPUS_DEFAULT_BIT_RATE.
63 * And the default setting of complexity is specified in
64 * #PJMEDIA_CODEC_OPUS_DEFAULT_COMPLEXITY.
65 *
66 * After modifying any of these settings, application needs to call
67 * #pjmedia_codec_opus_set_default_param(), which will generate the
68 * appropriate decoding fmtp attributes.
69 *
70 * Here is an example of modifying the codec settings:
71 *
72 \code
73 pjmedia_codec_param param;
74 pjmedia_codec_opus_config opus_cfg;
75
76 pjmedia_codec_mgr_get_default_param(.., &param);
77 pjmedia_codec_opus_get_config(&opus_cfg);
78 ...
79 // Set VAD
80 param.setting.vad = 1;
81 // Set PLC
82 param.setting.vad = 1;
83 // Set sample rate
84 opus_cfg.sample_rate = 16000;
85 // Set channel count
86 opus_cfg.channel_cnt = 2;
87 // Set bit rate
88 opus_cfg.bit_rate = 20000;
89 ...
90 pjmedia_codec_opus_set_default_param(&opus_cfg, &param);
91 \endcode
92 *
93 *
94 * \section opus_windows_linking Windows Linking
95 *
96 * On MSVC, the codec source automatically links to the Opus library using
97 * \a \#pragma \a comment(lib,...). The default library name is \a "opus.lib",
98 * which is the standard convention for MSVC builds of the Opus library.
99 *
100 * If the Opus library has a different name (e.g., when built with MinGW
101 * producing \a "libopus.a"), define #PJMEDIA_CODEC_OPUS_LIB_NAME in
102 * \a config_site.h before enabling the codec:
103 *
104 \code
105 // In config_site.h
106 #define PJMEDIA_CODEC_OPUS_LIB_NAME "libopus.a"
107 #define PJMEDIA_HAS_OPUS_CODEC 1
108 \endcode
109 *
110 */
111
112 /**
113 * Opus codec configuration.
114 */
115 typedef struct pjmedia_codec_opus_config
116 {
117 unsigned sample_rate; /**< Sample rate in Hz. */
118 unsigned channel_cnt; /**< Number of channels. */
119 unsigned frm_ptime; /**< Frame ptime in msec. */
120 unsigned frm_ptime_denum;/**< Frame ptime denumerator, can be zero*/
121 unsigned bit_rate; /**< Encoder bit rate in bps. */
122 unsigned packet_loss; /**< Encoder's expected packet loss pct. */
123 unsigned complexity; /**< Encoder complexity, 0-10(10 is highest)*/
124 pj_bool_t cbr; /**< Constant bit rate? */
125 } pjmedia_codec_opus_config;
126
127
128 /**
129 * Initialize and register Opus codec factory to pjmedia endpoint.
130 *
131 * @param endpt The pjmedia endpoint.
132 *
133 * @return PJ_SUCCESS on success.
134 */
135 PJ_DECL(pj_status_t) pjmedia_codec_opus_init( pjmedia_endpt *endpt );
136
137 /**
138 * Unregister Opus codec factory from pjmedia endpoint and deinitialize
139 * the Opus codec library.
140 *
141 * @return PJ_SUCCESS on success.
142 */
143 PJ_DECL(pj_status_t) pjmedia_codec_opus_deinit( void );
144
145 /**
146 * Get the default Opus configuration.
147 *
148 * @param cfg Opus codec configuration.
149 *
150 * @return PJ_SUCCESS on success.
151 */
152 PJ_DECL(pj_status_t)
153 pjmedia_codec_opus_get_config( pjmedia_codec_opus_config *cfg );
154
155 /**
156 * Set the default Opus configuration and set the default Opus codec param.
157 * Note that the function will call #pjmedia_codec_mgr_set_default_param().
158 *
159 * @param cfg Opus codec configuration.
160 * @param param On input, the default Opus codec parameter to be set.
161 * On output, the current default Opus codec parameter
162 * after setting. This may be different from the input
163 * because some settings can be rejected, or overwritten
164 * by the Opus codec configuration above.
165 *
166 * @return PJ_SUCCESS on success.
167 */
168 PJ_DECL(pj_status_t)
169 pjmedia_codec_opus_set_default_param(const pjmedia_codec_opus_config *cfg,
170 pjmedia_codec_param *param );
171
172 PJ_END_DECL
173
174 /**
175 * @}
176 */
177
178 #endif /* __PJMEDIA_CODEC_OPUS_H__ */