| 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 | |
| 19 | #ifndef __PJMEDIA_CODEC_AND_AUD_MEDIACODEC_H__ |
| 20 | #define __PJMEDIA_CODEC_AND_AUD_MEDIACODEC_H__ |
| 21 | |
| 22 | /** |
| 23 | * @file and_aud_mediacodec.h |
| 24 | * @brief Android audio MediaCodec codecs. |
| 25 | */ |
| 26 | |
| 27 | #include <pjmedia-codec/types.h> |
| 28 | |
| 29 | /** |
| 30 | * @defgroup PJMEDIA_CODEC_AUD_MEDIACODEC Audio MediaCodec Codec |
| 31 | * @ingroup PJMEDIA_CODEC_CODECS |
| 32 | * @{ |
| 33 | * |
| 34 | * Audio MediaCodec codec wrapper for Android. |
| 35 | * |
| 36 | * This codec wrapper contains varius codecs: i.e: AMR and AMR-WB. |
| 37 | * |
| 38 | * \section pjmedia_codec_mediacodec_AMR MediaCodec AMRNB/AMR-WB |
| 39 | * |
| 40 | * MediaCodec AMR supports 16-bit PCM audio signal with sampling rate 8000Hz, |
| 41 | * 20ms frame length and producing various bitrates that ranges from 4.75kbps |
| 42 | * to 12.2kbps. |
| 43 | * \subsection and_aud_codec_setting Codec Settings |
| 44 | * |
| 45 | * General codec settings for this codec such as VAD and PLC can be |
| 46 | * manipulated through the <tt>setting</tt> field in #pjmedia_codec_param. |
| 47 | * Please see the documentation of #pjmedia_codec_param for more info. |
| 48 | * Note that MediaCodec doesn't provide internal VAD/PLC feature, they will be |
| 49 | * provided by PJMEDIA instead. |
| 50 | * |
| 51 | * \subsubsection and_aud_bitrate Bitrate |
| 52 | * |
| 53 | * By default, encoding bitrate is 7400bps. This default setting can be |
| 54 | * modified using #pjmedia_codec_mgr_set_default_param() by specifying |
| 55 | * prefered AMR bitrate in field <tt>info::avg_bps</tt> of |
| 56 | * #pjmedia_codec_param. Valid bitrates could be seen in |
| 57 | * #pjmedia_codec_amrnb_bitrates. |
| 58 | * |
| 59 | * \subsubsection and_aud_payload_format Payload Format |
| 60 | * |
| 61 | * There are two AMR payload format types, bandwidth-efficient and |
| 62 | * octet-aligned. Default setting is using octet-aligned. This default payload |
| 63 | * format can be modified using #pjmedia_codec_mgr_set_default_param(). |
| 64 | * |
| 65 | * In #pjmedia_codec_param, payload format can be set by specifying SDP |
| 66 | * format parameters "octet-align" in the SDP "a=fmtp" attribute for |
| 67 | * decoding direction. Valid values are "0" (for bandwidth efficient mode) |
| 68 | * and "1" (for octet-aligned mode). |
| 69 | * |
| 70 | * \subsubsection and_aud_mode_set Mode-Set |
| 71 | * |
| 72 | * Mode-set is used for restricting AMR modes in decoding direction. |
| 73 | * |
| 74 | * By default, no mode-set restriction applied. This default setting can be |
| 75 | * be modified using #pjmedia_codec_mgr_set_default_param(). |
| 76 | * |
| 77 | * In #pjmedia_codec_param, mode-set could be specified via format parameters |
| 78 | * "mode-set" in the SDP "a=fmtp" attribute for decoding direction. Valid |
| 79 | * value is a comma separated list of modes from the set 0 - 7, e.g: |
| 80 | * "4,5,6,7". When this parameter is omitted, no mode-set restrictions applied. |
| 81 | * |
| 82 | * Here is an example of modifying AMR default codec param: |
| 83 | \code |
| 84 | pjmedia_codec_param param; |
| 85 | |
| 86 | pjmedia_codec_mgr_get_default_param(.., ¶m); |
| 87 | ... |
| 88 | // set default encoding bitrate to the highest 12.2kbps |
| 89 | param.info.avg_bps = 12200; |
| 90 | |
| 91 | // restrict decoding bitrate to 10.2kbps and 12.2kbps only |
| 92 | param.setting.dec_fmtp.param[0].name = pj_str("mode-set"); |
| 93 | param.setting.dec_fmtp.param[0].val = pj_str("6,7"); |
| 94 | |
| 95 | // also set to use bandwidth-efficient payload format |
| 96 | param.setting.dec_fmtp.param[1].name = pj_str("octet-align"); |
| 97 | param.setting.dec_fmtp.param[1].val = pj_str("0"); |
| 98 | |
| 99 | param.setting.dec_fmtp.cnt = 2; |
| 100 | ... |
| 101 | pjmedia_codec_mgr_set_default_param(.., ¶m); |
| 102 | \endcode |
| 103 | */ |
| 104 | |
| 105 | PJ_BEGIN_DECL |
| 106 | |
| 107 | /** |
| 108 | * Initialize and register Android audio MediaCodec factory to pjmedia |
| 109 | * endpoint. |
| 110 | * |
| 111 | * @param endpt The pjmedia endpoint. |
| 112 | * |
| 113 | * @return PJ_SUCCESS on success. |
| 114 | */ |
| 115 | PJ_DECL(pj_status_t) pjmedia_codec_and_media_aud_init( pjmedia_endpt *endpt ); |
| 116 | |
| 117 | /** |
| 118 | * Unregister Android audio MediaCodec factory from pjmedia endpoint |
| 119 | * and deinitialize the codec library. |
| 120 | * |
| 121 | * @return PJ_SUCCESS on success. |
| 122 | */ |
| 123 | PJ_DECL(pj_status_t) pjmedia_codec_and_media_aud_deinit( void ); |
| 124 | |
| 125 | PJ_END_DECL |
| 126 | |
| 127 | /** |
| 128 | * @} |
| 129 | */ |
| 130 | |
| 131 | #endif /* __PJMEDIA_CODEC_AND_AUD_MEDIACODEC_H__ */ |