passthrough.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /*
  2. * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
  3. * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
  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. #ifndef __PJMEDIA_CODECS_PASSTHROUGH_H__
  20. #define __PJMEDIA_CODECS_PASSTHROUGH_H__
  21. /**
  22. * @file pjmedia-codec/passthrough.h
  23. * @brief Passthrough codecs.
  24. */
  25. #include <pjmedia-codec/types.h>
  26. /**
  27. * @defgroup PJMED_PASSTHROUGH_CODEC Passthrough Codecs
  28. * @ingroup PJMEDIA_CODEC_CODECS
  29. * @brief Implementation of passthrough codecs
  30. * @{
  31. *
  32. * This section describes functions to initialize and register passthrough
  33. * codecs factory to the codec manager. After the codec factory has been
  34. * registered, application can use @ref PJMEDIA_CODEC API to manipulate
  35. * the codec.
  36. *
  37. * Passthrough codecs are codecs wrapper that does NOT perform encoding
  38. * or decoding, it just PACK and PARSE encoded audio data from/into RTP
  39. * payload. This will accomodate pjmedia ports which work with encoded
  40. * audio data, e.g: encoded audio files, sound device with capability
  41. * of playing/recording encoded audio data.
  42. *
  43. * This codec factory contains various codecs, i.e: G.729, iLBC,
  44. * AMR, and G.711.
  45. *
  46. *
  47. * \section pjmedia_codec_passthrough_g729 Passthrough G.729
  48. *
  49. * G.729 supports 16-bit PCM audio signal with sampling rate 8000Hz,
  50. * frame length 10ms, and resulting in bitrate 8000bps.
  51. *
  52. * \subsection passthrough_codec_setting Codec Settings
  53. *
  54. * General codec settings for this codec such as VAD and PLC can be
  55. * manipulated through the <tt>setting</tt> field in #pjmedia_codec_param.
  56. * Please see the documentation of #pjmedia_codec_param for more info.
  57. *
  58. * Note that G.729 VAD status should be signalled in SDP, see more
  59. * description below.
  60. *
  61. * \subsubsection passthrough_g729_annexb Annex B
  62. *
  63. * The capability of VAD/DTX is specified in Annex B.
  64. *
  65. * By default, Annex B is enabled. This default setting of Annex B can
  66. * be modified using #pjmedia_codec_mgr_set_default_param().
  67. *
  68. * In #pjmedia_codec_param, Annex B is configured via VAD setting and
  69. * format parameter "annexb" in the SDP "a=fmtp" attribute in
  70. * decoding fmtp field. Valid values are "yes" and "no",
  71. * the implementation default is "yes". When this parameter is omitted
  72. * in the SDP, the value will be "yes" (RFC 4856 Section 2.1.9).
  73. *
  74. * Here is an example of modifying default setting of Annex B to
  75. * be disabled using #pjmedia_codec_mgr_set_default_param():
  76. \code
  77. pjmedia_codec_param param;
  78. pjmedia_codec_mgr_get_default_param(.., &param);
  79. ...
  80. // Set VAD
  81. param.setting.vad = 0;
  82. // Set SDP format parameter
  83. param.setting.dec_fmtp.cnt = 1;
  84. param.setting.dec_fmtp.param[0].name = pj_str("annexb");
  85. param.setting.dec_fmtp.param[0].val = pj_str("no");
  86. ...
  87. pjmedia_codec_mgr_set_default_param(.., &param);
  88. \endcode
  89. *
  90. * \note
  91. * The difference of Annex B status in SDP offer/answer may be considered as
  92. * incompatible codec in SDP negotiation.
  93. *
  94. *
  95. * \section pjmedia_codec_passthrough_ilbc Passthrough iLBC
  96. *
  97. * The iLBC codec is developed by Global IP Solutions (GIPS), formerly
  98. * Global IP Sound. The iLBC offers low bitrate and graceful audio quality
  99. * degradation on frame losses.
  100. *
  101. * The iLBC codec supports 16-bit PCM audio signal with sampling rate of
  102. * 8000Hz operating at two modes: 20ms and 30ms frame length modes, resulting
  103. * in bitrates of 15.2kbps for 20ms mode and 13.33kbps for 30ms mode.
  104. *
  105. * \subsection passthrough_ilbc_codec_setting Codec Settings
  106. *
  107. * General codec settings for this codec such as VAD and PLC can be
  108. * manipulated through the <tt>setting</tt> field in #pjmedia_codec_param.
  109. * Please see the documentation of #pjmedia_codec_param for more info.
  110. *
  111. * \subsubsection passthrough_ilbc_mode Mode
  112. *
  113. * The default mode should be set upon initialization, see
  114. * #pjmedia_codec_passthrough_init2(). After the codec is initialized, the
  115. * default mode can be modified using #pjmedia_codec_mgr_set_default_param().
  116. *
  117. * In #pjmedia_codec_param, iLBC mode can be set by specifying SDP
  118. * format parameter "mode" in the SDP "a=fmtp" attribute for decoding
  119. * direction. Valid values are "20" and "30" (for 20ms and 30ms mode
  120. * respectively).
  121. *
  122. * Here is an example to set up #pjmedia_codec_param to use mode 20ms:
  123. * \code
  124. pjmedia_codec_param param;
  125. ...
  126. // setting iLBC mode in SDP
  127. param.setting.dec_fmtp.cnt = 1;
  128. param.setting.dec_fmtp.param[0].name = pj_str("mode");
  129. param.setting.dec_fmtp.param[0].val = pj_str("20");
  130. ...
  131. \endcode
  132. *
  133. *
  134. * \section pjmedia_codec_passthrough_amr Passthrough AMR
  135. *
  136. * IPP AMR supports 16-bit PCM audio signal with sampling rate 8000Hz,
  137. * 20ms frame length and producing various bitrates that ranges from 4.75kbps
  138. * to 12.2kbps.
  139. *
  140. * \subsection passthrough_amr_codec_setting Codec Settings
  141. *
  142. * General codec settings for this codec such as VAD and PLC can be
  143. * manipulated through the <tt>setting</tt> field in #pjmedia_codec_param.
  144. * Please see the documentation of #pjmedia_codec_param for more info.
  145. *
  146. * \subsubsection passthrough_amr_bitrate Bitrate
  147. *
  148. * By default, encoding bitrate is 7400bps. This default setting can be
  149. * modified using #pjmedia_codec_mgr_set_default_param() by specifying
  150. * prefered AMR bitrate in field <tt>info::avg_bps</tt> of
  151. * #pjmedia_codec_param. Valid bitrates could be seen in
  152. * #pjmedia_codec_amrnb_bitrates.
  153. *
  154. * \subsubsection passthrough_amr_payload_format Payload Format
  155. *
  156. * There are two AMR payload format types, bandwidth-efficient and
  157. * octet-aligned. Default setting is using octet-aligned. This default payload
  158. * format can be modified using #pjmedia_codec_mgr_set_default_param().
  159. *
  160. * In #pjmedia_codec_param, payload format can be set by specifying SDP
  161. * format parameters "octet-align" in the SDP "a=fmtp" attribute for
  162. * decoding direction. Valid values are "0" (for bandwidth efficient mode)
  163. * and "1" (for octet-aligned mode).
  164. *
  165. * \subsubsection passthrough_amr_mode_set Mode-Set
  166. *
  167. * Mode-set is used for restricting AMR modes in decoding direction.
  168. *
  169. * By default, no mode-set restriction applied. This default setting can be
  170. * be modified using #pjmedia_codec_mgr_set_default_param().
  171. *
  172. * In #pjmedia_codec_param, mode-set could be specified via format parameters
  173. * "mode-set" in the SDP "a=fmtp" attribute for decoding direction. Valid
  174. * value is a comma separated list of modes from the set 0 - 7, e.g:
  175. * "4,5,6,7". When this parameter is omitted, no mode-set restrictions applied.
  176. *
  177. * Here is an example of modifying AMR default codec param:
  178. \code
  179. pjmedia_codec_param param;
  180. pjmedia_codec_mgr_get_default_param(.., &param);
  181. ...
  182. // set default encoding bitrate to the highest 12.2kbps
  183. param.info.avg_bps = 12200;
  184. // restrict decoding bitrate to 10.2kbps and 12.2kbps only
  185. param.setting.dec_fmtp.param[0].name = pj_str("mode-set");
  186. param.setting.dec_fmtp.param[0].val = pj_str("6,7");
  187. // also set to use bandwidth-efficient payload format
  188. param.setting.dec_fmtp.param[1].name = pj_str("octet-align");
  189. param.setting.dec_fmtp.param[1].val = pj_str("0");
  190. param.setting.dec_fmtp.cnt = 2;
  191. ...
  192. pjmedia_codec_mgr_set_default_param(.., &param);
  193. \endcode
  194. *
  195. *
  196. * \section pjmedia_codec_passthrough_g711 Passthrough G.711
  197. *
  198. * The G.711 is an ultra low complexity codecs and in trade-off it results
  199. * in high bitrate, i.e: 64kbps for 16-bit PCM with sampling rate 8000Hz.
  200. *
  201. * The factory contains two main compression algorithms, PCMU/u-Law and
  202. * PCMA/A-Law.
  203. *
  204. * \subsection passthrough_g711_codec_setting Codec Settings
  205. *
  206. * General codec settings for this codec such as VAD and PLC can be
  207. * manipulated through the <tt>setting</tt> field in #pjmedia_codec_param.
  208. * Please see the documentation of #pjmedia_codec_param for more info.
  209. */
  210. PJ_BEGIN_DECL
  211. /**
  212. * Codec passthrough configuration settings.
  213. */
  214. typedef struct pjmedia_codec_passthrough_setting
  215. {
  216. unsigned fmt_cnt; /**< Number of encoding formats
  217. to be enabled. */
  218. pjmedia_format *fmts; /**< Encoding formats to be
  219. enabled. */
  220. unsigned ilbc_mode; /**< iLBC default mode. */
  221. } pjmedia_codec_passthrough_setting;
  222. /**
  223. * Initialize and register passthrough codecs factory to pjmedia endpoint,
  224. * all supported encoding formats will be enabled.
  225. *
  226. * @param endpt The pjmedia endpoint.
  227. *
  228. * @return PJ_SUCCESS on success.
  229. */
  230. PJ_DECL(pj_status_t) pjmedia_codec_passthrough_init( pjmedia_endpt *endpt );
  231. /**
  232. * Initialize and register passthrough codecs factory to pjmedia endpoint
  233. * with only specified encoding formats enabled.
  234. *
  235. * @param endpt The pjmedia endpoint.
  236. * @param setting The settings.
  237. *
  238. * @return PJ_SUCCESS on success.
  239. */
  240. PJ_DECL(pj_status_t) pjmedia_codec_passthrough_init2(
  241. pjmedia_endpt *endpt,
  242. const pjmedia_codec_passthrough_setting *setting);
  243. /**
  244. * Unregister passthrough codecs factory from pjmedia endpoint.
  245. *
  246. * @return PJ_SUCCESS on success.
  247. */
  248. PJ_DECL(pj_status_t) pjmedia_codec_passthrough_deinit(void);
  249. PJ_END_DECL
  250. /**
  251. * @}
  252. */
  253. #endif /* __PJMEDIA_CODECS_PASSTHROUGH_H__ */