opus.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. #ifndef __PJMEDIA_CODEC_OPUS_H__
  23. #define __PJMEDIA_CODEC_OPUS_H__
  24. /**
  25. * @file opus.h
  26. * @brief Opus codec.
  27. */
  28. #include <pjmedia-codec/types.h>
  29. PJ_BEGIN_DECL
  30. /**
  31. * @defgroup PJMED_OPUS Opus Codec Family
  32. * @ingroup PJMEDIA_CODEC_CODECS
  33. * @brief Opus codec wrapper
  34. * @{
  35. *
  36. * This section describes functions to initialize and register Opus codec
  37. * factory to the codec manager. After the codec factory has been registered,
  38. * application can use @ref PJMEDIA_CODEC API to manipulate the codec.
  39. *
  40. * Opus codec uses multiple bit rates, and supports fullband (48 kHz
  41. * sampling rate), super wideband (24 kHz sampling rate), wideband (16 kHz
  42. * sampling rate), medium band (12kHz sampling rate), and narrowband
  43. * (8 kHz sampling rate).
  44. *
  45. *
  46. * \section opus_codec_setting Codec Settings
  47. *
  48. * General codec settings for this codec such as VAD and PLC can be
  49. * manipulated through the <tt>setting</tt> field in #pjmedia_codec_param
  50. * (see the documentation of #pjmedia_codec_param for more info).
  51. *
  52. * For Opus codec specific settings, such as sample rate,
  53. * channel count, bit rate, complexity, and CBR, can be configured
  54. * in #pjmedia_codec_opus_config.
  55. * The default setting of sample rate is specified in
  56. * #PJMEDIA_CODEC_OPUS_DEFAULT_SAMPLE_RATE. The default setting of
  57. * bitrate is specified in #PJMEDIA_CODEC_OPUS_DEFAULT_BIT_RATE.
  58. * And the default setting of complexity is specified in
  59. * #PJMEDIA_CODEC_OPUS_DEFAULT_COMPLEXITY.
  60. *
  61. * After modifying any of these settings, application needs to call
  62. * #pjmedia_codec_opus_set_default_param(), which will generate the
  63. * appropriate decoding fmtp attributes.
  64. *
  65. * Here is an example of modifying the codec settings:
  66. \code
  67. pjmedia_codec_param param;
  68. pjmedia_codec_opus_config opus_cfg;
  69. pjmedia_codec_mgr_get_default_param(.., &param);
  70. pjmedia_codec_opus_get_config(&opus_cfg);
  71. ...
  72. // Set VAD
  73. param.setting.vad = 1;
  74. // Set PLC
  75. param.setting.vad = 1;
  76. // Set sample rate
  77. opus_cfg.sample_rate = 16000;
  78. // Set channel count
  79. opus_cfg.channel_cnt = 2;
  80. // Set bit rate
  81. opus_cfg.bit_rate = 20000;
  82. ...
  83. pjmedia_codec_opus_set_default_param(&opus_cfg, &param);
  84. \endcode
  85. *
  86. */
  87. /**
  88. * Opus codec configuration.
  89. */
  90. typedef struct pjmedia_codec_opus_config
  91. {
  92. unsigned sample_rate; /**< Sample rate in Hz. */
  93. unsigned channel_cnt; /**< Number of channels. */
  94. unsigned frm_ptime; /**< Frame ptime in msec. */
  95. unsigned frm_ptime_denum;/**< Frame ptime denumerator, can be zero*/
  96. unsigned bit_rate; /**< Encoder bit rate in bps. */
  97. unsigned packet_loss; /**< Encoder's expected packet loss pct. */
  98. unsigned complexity; /**< Encoder complexity, 0-10(10 is highest)*/
  99. pj_bool_t cbr; /**< Constant bit rate? */
  100. } pjmedia_codec_opus_config;
  101. /**
  102. * Initialize and register Opus codec factory to pjmedia endpoint.
  103. *
  104. * @param endpt The pjmedia endpoint.
  105. *
  106. * @return PJ_SUCCESS on success.
  107. */
  108. PJ_DECL(pj_status_t) pjmedia_codec_opus_init( pjmedia_endpt *endpt );
  109. /**
  110. * Unregister Opus codec factory from pjmedia endpoint and deinitialize
  111. * the Opus codec library.
  112. *
  113. * @return PJ_SUCCESS on success.
  114. */
  115. PJ_DECL(pj_status_t) pjmedia_codec_opus_deinit( void );
  116. /**
  117. * Get the default Opus configuration.
  118. *
  119. * @param cfg Opus codec configuration.
  120. *
  121. * @return PJ_SUCCESS on success.
  122. */
  123. PJ_DECL(pj_status_t)
  124. pjmedia_codec_opus_get_config( pjmedia_codec_opus_config *cfg );
  125. /**
  126. * Set the default Opus configuration and set the default Opus codec param.
  127. * Note that the function will call #pjmedia_codec_mgr_set_default_param().
  128. *
  129. * @param cfg Opus codec configuration.
  130. * @param param On input, the default Opus codec parameter to be set.
  131. * On output, the current default Opus codec parameter
  132. * after setting. This may be different from the input
  133. * because some settings can be rejected, or overwritten
  134. * by the Opus codec configuration above.
  135. *
  136. * @return PJ_SUCCESS on success.
  137. */
  138. PJ_DECL(pj_status_t)
  139. pjmedia_codec_opus_set_default_param(const pjmedia_codec_opus_config *cfg,
  140. pjmedia_codec_param *param );
  141. PJ_END_DECL
  142. /**
  143. * @}
  144. */
  145. #endif /* __PJMEDIA_CODEC_OPUS_H__ */