and_aud_mediacodec.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright (C)2020 Teluu Inc. (http://www.teluu.com)
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. #ifndef __PJMEDIA_CODEC_AND_AUD_MEDIACODEC_H__
  19. #define __PJMEDIA_CODEC_AND_AUD_MEDIACODEC_H__
  20. /**
  21. * @file and_aud_mediacodec.h
  22. * @brief Android audio MediaCodec codecs.
  23. */
  24. #include <pjmedia-codec/types.h>
  25. /**
  26. * @defgroup PJMEDIA_CODEC_AUD_MEDIACODEC Audio MediaCodec Codec
  27. * @ingroup PJMEDIA_CODEC_CODECS
  28. * @{
  29. *
  30. * Audio MediaCodec codec wrapper for Android.
  31. *
  32. * This codec wrapper contains varius codecs: i.e: AMR and AMR-WB.
  33. *
  34. * \section pjmedia_codec_mediacodec_AMR MediaCodec AMRNB/AMR-WB
  35. *
  36. * MediaCodec AMR supports 16-bit PCM audio signal with sampling rate 8000Hz,
  37. * 20ms frame length and producing various bitrates that ranges from 4.75kbps
  38. * to 12.2kbps.
  39. * \subsection and_aud_codec_setting Codec Settings
  40. *
  41. * General codec settings for this codec such as VAD and PLC can be
  42. * manipulated through the <tt>setting</tt> field in #pjmedia_codec_param.
  43. * Please see the documentation of #pjmedia_codec_param for more info.
  44. * Note that MediaCodec doesn't provide internal VAD/PLC feature, they will be
  45. * provided by PJMEDIA instead.
  46. *
  47. * \subsubsection and_aud_bitrate Bitrate
  48. *
  49. * By default, encoding bitrate is 7400bps. This default setting can be
  50. * modified using #pjmedia_codec_mgr_set_default_param() by specifying
  51. * prefered AMR bitrate in field <tt>info::avg_bps</tt> of
  52. * #pjmedia_codec_param. Valid bitrates could be seen in
  53. * #pjmedia_codec_amrnb_bitrates.
  54. *
  55. * \subsubsection and_aud_payload_format Payload Format
  56. *
  57. * There are two AMR payload format types, bandwidth-efficient and
  58. * octet-aligned. Default setting is using octet-aligned. This default payload
  59. * format can be modified using #pjmedia_codec_mgr_set_default_param().
  60. *
  61. * In #pjmedia_codec_param, payload format can be set by specifying SDP
  62. * format parameters "octet-align" in the SDP "a=fmtp" attribute for
  63. * decoding direction. Valid values are "0" (for bandwidth efficient mode)
  64. * and "1" (for octet-aligned mode).
  65. *
  66. * \subsubsection and_aud_mode_set Mode-Set
  67. *
  68. * Mode-set is used for restricting AMR modes in decoding direction.
  69. *
  70. * By default, no mode-set restriction applied. This default setting can be
  71. * be modified using #pjmedia_codec_mgr_set_default_param().
  72. *
  73. * In #pjmedia_codec_param, mode-set could be specified via format parameters
  74. * "mode-set" in the SDP "a=fmtp" attribute for decoding direction. Valid
  75. * value is a comma separated list of modes from the set 0 - 7, e.g:
  76. * "4,5,6,7". When this parameter is omitted, no mode-set restrictions applied.
  77. *
  78. * Here is an example of modifying AMR default codec param:
  79. \code
  80. pjmedia_codec_param param;
  81. pjmedia_codec_mgr_get_default_param(.., &param);
  82. ...
  83. // set default encoding bitrate to the highest 12.2kbps
  84. param.info.avg_bps = 12200;
  85. // restrict decoding bitrate to 10.2kbps and 12.2kbps only
  86. param.setting.dec_fmtp.param[0].name = pj_str("mode-set");
  87. param.setting.dec_fmtp.param[0].val = pj_str("6,7");
  88. // also set to use bandwidth-efficient payload format
  89. param.setting.dec_fmtp.param[1].name = pj_str("octet-align");
  90. param.setting.dec_fmtp.param[1].val = pj_str("0");
  91. param.setting.dec_fmtp.cnt = 2;
  92. ...
  93. pjmedia_codec_mgr_set_default_param(.., &param);
  94. \endcode
  95. */
  96. PJ_BEGIN_DECL
  97. /**
  98. * Initialize and register Android audio MediaCodec factory to pjmedia
  99. * endpoint.
  100. *
  101. * @param endpt The pjmedia endpoint.
  102. *
  103. * @return PJ_SUCCESS on success.
  104. */
  105. PJ_DECL(pj_status_t) pjmedia_codec_and_media_aud_init( pjmedia_endpt *endpt );
  106. /**
  107. * Unregister Android audio MediaCodec factory from pjmedia endpoint
  108. * and deinitialize the codec library.
  109. *
  110. * @return PJ_SUCCESS on success.
  111. */
  112. PJ_DECL(pj_status_t) pjmedia_codec_and_media_aud_deinit( void );
  113. PJ_END_DECL
  114. /**
  115. * @}
  116. */
  117. #endif /* __PJMEDIA_CODEC_AND_AUD_MEDIACODEC_H__ */