1 /** 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef AUDIO_AMRFMT_H_INCLUDED 18 #define AUDIO_AMRFMT_H_INCLUDED 19 20 #include <ImsMediaDefine.h> 21 #include <stdint.h> 22 23 #define IMSAMR_FRAME_BYTES 34 24 25 #define EVS_COMPACT_PRIMARY_PAYLOAD_NUM 13 26 #define EVS_COMPACT_AMRWBIO_PAYLOAD_NUM 10 27 #define EVS_COMPACT_PAYLOAD_MAX_NUM 32 28 29 #define AUDIO_STOP_TIMEOUT 1000 30 31 enum kImsAudioFrameEntype 32 { 33 kImsAudioFrameGsmSid = 0, /* GSM HR, FR or EFR : silence descriptor */ 34 kImsAudioFrameGsmSpeechGood, /* GSM HR, FR or EFR : good speech frame */ 35 kImsAudioFrameGsmBfi, /* GSM HR, FR or EFR : bad frame indicator */ 36 kImsAudioFrameGsmInvalidSid, /* GSM HR : invalid SID frame */ 37 kImsAudioFrameAmrSpeechGood, /* AMR : good speech frame */ 38 kImsAudioFrameAmrSpeechDegraded, /* AMR : degraded speech frame */ 39 kImsAudioFrameAmrOnSet, /* AMR : onset */ 40 kImsAudioFrameAmrSpeechBad, /* AMR : bad speech frame */ 41 kImsAudioFrameAmrSidFirst, /* AMR : first silence descriptor */ 42 kImsAudioFrameAmrSidUpdate, /* AMR : successive silence descriptor */ 43 kImsAudioFrameAmrSidBad, /* AMR : bad silence descriptor frame */ 44 kImsAudioFrameAmrNoData, /* AMR : Nothing to Transmit */ 45 kImsAudioFrameAmrSpeechLost, /* downlink speech lost */ 46 kImsAudioFrameMax 47 }; 48 49 enum kImsAudioAmrMode 50 { 51 kImsAudioAmrMode475 = 0, /* 4.75 kbit/s */ 52 kImsAudioAmrMode515 = 1, /* 5.15 kbit/s */ 53 kImsAudioAmrMode590 = 2, /* 5.90 kbit/s */ 54 kImsAudioAmrMode670 = 3, /* 6.70 kbit/s */ 55 kImsAudioAmrMode740 = 4, /* 7.40 kbit/s */ 56 kImsAudioAmrMode795 = 5, /* 7.95 kbit/s */ 57 kImsAudioAmrMode1020 = 6, /* 10.20 kbit/s */ 58 kImsAudioAmrMode1220 = 7, /* 12.20 kbit/s, also used for GSM EFR */ 59 kImsAudioAmrModeSID = 8, /* AMR SID */ 60 /* 9~13: for future use */ 61 kImsAudioAmrModeSPL = 14, /* Speech Lost frame */ 62 kImsAudioAmrModeNoData = 15, /* No Data */ 63 kImsAudioAmrModeMax 64 }; 65 66 enum kImsAudioAmrWbMode 67 { 68 kImsAudioAmrWbMode660 = 0, /* 6.60 kbit/s */ 69 kImsAudioAmrWbMode885 = 1, /* 8.85 kbit/s */ 70 kImsAudioAmrWbMode1265 = 2, /* 12.65 kbit/s */ 71 kImsAudioAmrWbMode1425 = 3, /* 14.25 kbit/s */ 72 kImsAudioAmrWbMode1585 = 4, /* 15.85 kbit/s */ 73 kImsAudioAmrWbMode1825 = 5, /* 18.25 kbit/s */ 74 kImsAudioAmrWbMode1985 = 6, /* 19.85 kbit/s */ 75 kImsAudioAmrWbMode2305 = 7, /* 23.05 kbit/s */ 76 kImsAudioAmrWbMode2385 = 8, /* 23.85 kbit/s */ 77 kImsAudioAmrWbModeSID = 9, /* AMRWB SID */ 78 /* 10~13: for future use */ 79 kImsAudioAmrWbModeSPL = 14, /* AMRWB Speech Lost frame */ 80 kImsAudioAmrWbModeNoData = 15, /* AMRWB No Data */ 81 kImsAudioAmrWbModeMax 82 }; 83 84 enum kImsAudioEvsMode 85 { 86 kImsAudioEvsAmrWbIoMode660 = 0, /* 6.60 kbps AMR-IO*/ 87 kImsAudioEvsAmrWbIoMode885 = 1, /* 8.85 kbps AMR-IO*/ 88 kImsAudioEvsAmrWbIoMode1265 = 2, /* 12.65 kbps AMR-IO */ 89 kImsAudioEvsAmrWbIoMode1425 = 3, /* 14.25 kbps AMR-IO */ 90 kImsAudioEvsAmrWbIoMode1585 = 4, /* 15.85 kbps AMR-IO */ 91 kImsAudioEvsAmrWbIoMode1825 = 5, /* 18.25 kbps AMR-IO */ 92 kImsAudioEvsAmrWbIoMode1985 = 6, /* 19.85 kbps AMR-IO */ 93 kImsAudioEvsAmrWbIoMode2305 = 7, /* 23.05 kbps AMR-IO */ 94 kImsAudioEvsAmrWbIoMode2385 = 8, /* 23.85 kbps AMR-IO */ 95 kImsAudioEvsPrimaryMode5900 = 9, /* 5.9 kbps, EVS Primary */ 96 kImsAudioEvsPrimaryMode7200 = 10, /* 7.2 kbps, EVS Primary */ 97 kImsAudioEvsPrimaryMode8000 = 11, /* 8.0 kbps, EVS Primary */ 98 kImsAudioEvsPrimaryMode9600 = 12, /* 9.6 kbps, EVS Primary */ 99 kImsAudioEvsPrimaryMode13200 = 13, /* 13.2 kbps, EVS Primary */ 100 kImsAudioEvsPrimaryMode16400 = 14, /* 16.4 kbps, EVS Primary */ 101 kImsAudioEvsPrimaryMode24400 = 15, /* 24.4 kbps, EVS Primary */ 102 kImsAudioEvsPrimaryMode32000 = 16, /* 32.0 kbps, EVS Primary */ 103 kImsAudioEvsPrimaryMode48000 = 17, /* 48.0 kbps, EVS Primary */ 104 kImsAudioEvsPrimaryMode64000 = 18, /* 64.0 kbps, EVS Primary */ 105 kImsAudioEvsPrimaryMode96000 = 19, /* 96.0 kbps, EVS Primary */ 106 kImsAudioEvsPrimaryMode128000 = 20, /* 128.0 kbps, EVS Primary */ 107 kImsAudioEvsPrimaryModeSID = 21, /* 2.4 kbps, EVS Primary SID */ 108 kImsAudioEvsPrimaryModeSpeechLost = 22, /* SPEECH LOST */ 109 kImsAudioEvsPrimaryModeNoData = 23, /* NO DATA */ 110 kImsAudioEvsModeMax 111 }; 112 113 // TODO: need to remove this with respective changes 114 enum kImsAudioEvsAmrWbIoMode 115 { 116 kImsAudioEvsAmrWbIoMode0660 = 0, /* 6.60 kbit/s */ 117 kImsAudioEvsAmrWbIoMode0885 = 1, /* 8.85 kbit/s */ 118 kImsAudioEvsAmrWbIoMode01265 = 2, /* 12.65 kbit/s */ 119 kImsAudioEvsAmrWbIoMode01425 = 3, /* 14.25 kbit/s */ 120 kImsAudioEvsAmrWbIoMode01585 = 4, /* 15.85 kbit/s */ 121 kImsAudioEvsAmrWbIoMode01825 = 5, /* 18.25 kbit/s */ 122 kImsAudioEvsAmrWbIoMode01985 = 6, /* 19.85 kbit/s */ 123 kImsAudioEvsAmrWbIoMode02305 = 7, /* 23.05 kbit/s */ 124 kImsAudioEvsAmrWbIoMode02385 = 8, /* 23.85 kbit/s */ 125 kImsAudioEvsAmrWbIoModeSID = 9, /* AMRWB SID */ 126 /* 10~13: for future use */ 127 kImsAudioEvsAmrWbIoModeSPL = 14, /* AMRWB Speech Lost frame */ 128 kImsAudioEvsAmrWbIoModeNoData = 15, /* AMRWB No Data */ 129 kImsAudioEvsAmrWbIoModeMax 130 }; 131 132 class ImsMediaAudioUtil 133 { 134 public: 135 static int32_t ConvertCodecType(int32_t type); 136 static int32_t ConvertEvsCodecMode(int32_t evsMode); 137 static uint32_t ConvertAmrModeToLen(uint32_t mode); 138 static uint32_t ConvertAmrModeToBitLen(uint32_t mode); 139 static uint32_t ConvertLenToAmrMode(uint32_t nLen); 140 static void ConvertEvsBandwidthToStr(kEvsBandwidth bandwidth, char* nBandwidth, uint32_t nLen); 141 static uint32_t ConvertAmrWbModeToLen(uint32_t mode); 142 static uint32_t ConvertAmrWbModeToBitLen(uint32_t mode); 143 static uint32_t ConvertLenToAmrWbMode(uint32_t nLen); 144 static uint32_t ConvertLenToEVSAudioMode(uint32_t nLen); 145 static uint32_t ConvertLenToEVSAMRIOAudioMode(uint32_t nLen); 146 static uint32_t ConvertEVSAudioModeToBitLen(uint32_t mode); 147 static uint32_t ConvertEVSAMRIOAudioModeToBitLen(uint32_t mode); 148 static uint32_t ConvertAmrModeToBitrate(uint32_t mode); 149 static uint32_t ConvertAmrWbModeToBitrate(uint32_t mode); 150 static uint32_t GetMaximumAmrMode(int32_t codecType, int32_t bitmask); 151 static uint32_t GetMaximumEvsMode(int32_t bitmask); 152 static uint32_t GetBitrateEVS(int mode); 153 static kRtpPayloadHeaderMode ConvertEVSPayloadMode( 154 uint32_t nDataSize, kEvsCodecMode* pEVSCodecMode, uint32_t* pEVSCompactId); 155 static kEvsCodecMode CheckEVSCodecMode(const uint32_t nAudioFrameLength); 156 static int32_t ConvertEVSModeToBitRate(const int32_t mode); 157 static kEvsBandwidth FindMaxEvsBandwidthFromRange(const int32_t EvsBandwidthRange); 158 static bool CheckEVSPrimaryHeaderFullModeFromSize(uint32_t size); 159 static ImsMediaSubType GetAmrFrameType( 160 const int32_t codecType, const uint32_t frameTypeIndex, const uint32_t size); 161 }; 162 163 #endif // AUDIO_AMRFMT_H_INCLUDED 164