| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
#include "asterisk.h" |
| 31 |
|
| 32 |
#include "asterisk/logger.h" |
| 33 |
#include "asterisk/astobj2.h" |
| 34 |
#include "asterisk/codec.h" |
| 35 |
#include "asterisk/format.h" |
| 36 |
#include "asterisk/format_compatibility.h" |
| 37 |
#include "asterisk/format_cache.h" |
| 38 |
|
| 39 |
uint64_t ast_format_compatibility_format2bitfield(const struct ast_format *format) |
| 40 |
{ |
| 41 |
if (ast_format_cmp(format, ast_format_g723) == AST_FORMAT_CMP_EQUAL) { |
| 42 |
return AST_FORMAT_G723; |
| 43 |
} else if (ast_format_cmp(format, ast_format_gsm) == AST_FORMAT_CMP_EQUAL) { |
| 44 |
return AST_FORMAT_GSM; |
| 45 |
} else if (ast_format_cmp(format, ast_format_ulaw) == AST_FORMAT_CMP_EQUAL) { |
| 46 |
return AST_FORMAT_ULAW; |
| 47 |
} else if (ast_format_cmp(format, ast_format_alaw) == AST_FORMAT_CMP_EQUAL) { |
| 48 |
return AST_FORMAT_ALAW; |
| 49 |
} else if (ast_format_cmp(format, ast_format_g726_aal2) == AST_FORMAT_CMP_EQUAL) { |
| 50 |
return AST_FORMAT_G726_AAL2; |
| 51 |
} else if (ast_format_cmp(format, ast_format_adpcm) == AST_FORMAT_CMP_EQUAL) { |
| 52 |
return AST_FORMAT_ADPCM; |
| 53 |
} else if (ast_format_cmp(format, ast_format_slin) == AST_FORMAT_CMP_EQUAL) { |
| 54 |
return AST_FORMAT_SLIN; |
| 55 |
} else if (ast_format_cmp(format, ast_format_lpc10) == AST_FORMAT_CMP_EQUAL) { |
| 56 |
return AST_FORMAT_LPC10; |
| 57 |
} else if (ast_format_cmp(format, ast_format_g729) == AST_FORMAT_CMP_EQUAL) { |
| 58 |
return AST_FORMAT_G729; |
| 59 |
} else if (ast_format_cmp(format, ast_format_speex) == AST_FORMAT_CMP_EQUAL) { |
| 60 |
return AST_FORMAT_SPEEX; |
| 61 |
} else if (ast_format_cmp(format, ast_format_ilbc) == AST_FORMAT_CMP_EQUAL) { |
| 62 |
return AST_FORMAT_ILBC; |
| 63 |
} else if (ast_format_cmp(format, ast_format_g726) == AST_FORMAT_CMP_EQUAL) { |
| 64 |
return AST_FORMAT_G726; |
| 65 |
} else if (ast_format_cmp(format, ast_format_g722) == AST_FORMAT_CMP_EQUAL) { |
| 66 |
return AST_FORMAT_G722; |
| 67 |
} else if (ast_format_cmp(format, ast_format_siren7) == AST_FORMAT_CMP_EQUAL) { |
| 68 |
return AST_FORMAT_SIREN7; |
| 69 |
} else if (ast_format_cmp(format, ast_format_siren14) == AST_FORMAT_CMP_EQUAL) { |
| 70 |
return AST_FORMAT_SIREN14; |
| 71 |
} else if (ast_format_cmp(format, ast_format_slin16) == AST_FORMAT_CMP_EQUAL) { |
| 72 |
return AST_FORMAT_SLIN16; |
| 73 |
} else if (ast_format_cmp(format, ast_format_g719) == AST_FORMAT_CMP_EQUAL) { |
| 74 |
return AST_FORMAT_G719; |
| 75 |
} else if (ast_format_cmp(format, ast_format_speex16) == AST_FORMAT_CMP_EQUAL) { |
| 76 |
return AST_FORMAT_SPEEX16; |
| 77 |
} else if (ast_format_cmp(format, ast_format_opus) == AST_FORMAT_CMP_EQUAL) { |
| 78 |
return AST_FORMAT_OPUS; |
| 79 |
} else if (ast_format_cmp(format, ast_format_h261) == AST_FORMAT_CMP_EQUAL) { |
| 80 |
return AST_FORMAT_H261; |
| 81 |
} else if (ast_format_cmp(format, ast_format_h263) == AST_FORMAT_CMP_EQUAL) { |
| 82 |
return AST_FORMAT_H263; |
| 83 |
} else if (ast_format_cmp(format, ast_format_h263p) == AST_FORMAT_CMP_EQUAL) { |
| 84 |
return AST_FORMAT_H263P; |
| 85 |
} else if (ast_format_cmp(format, ast_format_h264) == AST_FORMAT_CMP_EQUAL) { |
| 86 |
return AST_FORMAT_H264; |
| 87 |
} else if (ast_format_cmp(format, ast_format_mp4) == AST_FORMAT_CMP_EQUAL) { |
| 88 |
return AST_FORMAT_MP4; |
| 89 |
} else if (ast_format_cmp(format, ast_format_vp8) == AST_FORMAT_CMP_EQUAL) { |
| 90 |
return AST_FORMAT_VP8; |
| 91 |
} else if (ast_format_cmp(format, ast_format_jpeg) == AST_FORMAT_CMP_EQUAL) { |
| 92 |
return AST_FORMAT_JPEG; |
| 93 |
} else if (ast_format_cmp(format, ast_format_png) == AST_FORMAT_CMP_EQUAL) { |
| 94 |
return AST_FORMAT_PNG; |
| 95 |
} else if (ast_format_cmp(format, ast_format_t140_red) == AST_FORMAT_CMP_EQUAL) { |
| 96 |
return AST_FORMAT_T140_RED; |
| 97 |
} else if (ast_format_cmp(format, ast_format_t140) == AST_FORMAT_CMP_EQUAL) { |
| 98 |
return AST_FORMAT_T140; |
| 99 |
} |
| 100 |
|
| 101 |
return 0; |
| 102 |
} |
| 103 |
|
| 104 |
uint64_t ast_format_compatibility_codec2bitfield(const struct ast_codec *codec) |
| 105 |
{ |
| 106 |
if (codec->id == ast_format_get_codec_id(ast_format_g723)) { |
| 107 |
return AST_FORMAT_G723; |
| 108 |
} else if (codec->id == ast_format_get_codec_id(ast_format_gsm)) { |
| 109 |
return AST_FORMAT_GSM; |
| 110 |
} else if (codec->id == ast_format_get_codec_id(ast_format_ulaw)) { |
| 111 |
return AST_FORMAT_ULAW; |
| 112 |
} else if (codec->id == ast_format_get_codec_id(ast_format_alaw)) { |
| 113 |
return AST_FORMAT_ALAW; |
| 114 |
} else if (codec->id == ast_format_get_codec_id(ast_format_g726_aal2)) { |
| 115 |
return AST_FORMAT_G726_AAL2; |
| 116 |
} else if (codec->id == ast_format_get_codec_id(ast_format_adpcm)) { |
| 117 |
return AST_FORMAT_ADPCM; |
| 118 |
} else if (codec->id == ast_format_get_codec_id(ast_format_slin)) { |
| 119 |
return AST_FORMAT_SLIN; |
| 120 |
} else if (codec->id == ast_format_get_codec_id(ast_format_lpc10)) { |
| 121 |
return AST_FORMAT_LPC10; |
| 122 |
} else if (codec->id == ast_format_get_codec_id(ast_format_g729)) { |
| 123 |
return AST_FORMAT_G729; |
| 124 |
} else if (codec->id == ast_format_get_codec_id(ast_format_speex)) { |
| 125 |
return AST_FORMAT_SPEEX; |
| 126 |
} else if (codec->id == ast_format_get_codec_id(ast_format_ilbc)) { |
| 127 |
return AST_FORMAT_ILBC; |
| 128 |
} else if (codec->id == ast_format_get_codec_id(ast_format_g726)) { |
| 129 |
return AST_FORMAT_G726; |
| 130 |
} else if (codec->id == ast_format_get_codec_id(ast_format_g722)) { |
| 131 |
return AST_FORMAT_G722; |
| 132 |
} else if (codec->id == ast_format_get_codec_id(ast_format_siren7)) { |
| 133 |
return AST_FORMAT_SIREN7; |
| 134 |
} else if (codec->id == ast_format_get_codec_id(ast_format_siren14)) { |
| 135 |
return AST_FORMAT_SIREN14; |
| 136 |
} else if (codec->id == ast_format_get_codec_id(ast_format_slin16)) { |
| 137 |
return AST_FORMAT_SLIN16; |
| 138 |
} else if (codec->id == ast_format_get_codec_id(ast_format_g719)) { |
| 139 |
return AST_FORMAT_G719; |
| 140 |
} else if (codec->id == ast_format_get_codec_id(ast_format_speex16)) { |
| 141 |
return AST_FORMAT_SPEEX16; |
| 142 |
} else if (codec->id == ast_format_get_codec_id(ast_format_opus)) { |
| 143 |
return AST_FORMAT_OPUS; |
| 144 |
} else if (codec->id == ast_format_get_codec_id(ast_format_h261)) { |
| 145 |
return AST_FORMAT_H261; |
| 146 |
} else if (codec->id == ast_format_get_codec_id(ast_format_h263)) { |
| 147 |
return AST_FORMAT_H263; |
| 148 |
} else if (codec->id == ast_format_get_codec_id(ast_format_h263p)) { |
| 149 |
return AST_FORMAT_H263P; |
| 150 |
} else if (codec->id == ast_format_get_codec_id(ast_format_h264)) { |
| 151 |
return AST_FORMAT_H264; |
| 152 |
} else if (codec->id == ast_format_get_codec_id(ast_format_mp4)) { |
| 153 |
return AST_FORMAT_MP4; |
| 154 |
} else if (codec->id == ast_format_get_codec_id(ast_format_vp8)) { |
| 155 |
return AST_FORMAT_VP8; |
| 156 |
} else if (codec->id == ast_format_get_codec_id(ast_format_jpeg)) { |
| 157 |
return AST_FORMAT_JPEG; |
| 158 |
} else if (codec->id == ast_format_get_codec_id(ast_format_png)) { |
| 159 |
return AST_FORMAT_PNG; |
| 160 |
} else if (codec->id == ast_format_get_codec_id(ast_format_t140_red)) { |
| 161 |
return AST_FORMAT_T140_RED; |
| 162 |
} else if (codec->id == ast_format_get_codec_id(ast_format_t140)) { |
| 163 |
return AST_FORMAT_T140; |
| 164 |
} |
| 165 |
|
| 166 |
return 0; |
| 167 |
} |
| 168 |
|
| 169 |
struct ast_format *ast_format_compatibility_bitfield2format(uint64_t bitfield) |
| 170 |
{ |
| 171 |
switch (bitfield) { |
| 172 |
|
| 173 |
case AST_FORMAT_G723: |
| 174 |
return ast_format_g723; |
| 175 |
|
| 176 |
case AST_FORMAT_GSM: |
| 177 |
return ast_format_gsm; |
| 178 |
|
| 179 |
case AST_FORMAT_ULAW: |
| 180 |
return ast_format_ulaw; |
| 181 |
|
| 182 |
case AST_FORMAT_ALAW: |
| 183 |
return ast_format_alaw; |
| 184 |
|
| 185 |
case AST_FORMAT_G726_AAL2: |
| 186 |
return ast_format_g726_aal2; |
| 187 |
|
| 188 |
case AST_FORMAT_ADPCM: |
| 189 |
return ast_format_adpcm; |
| 190 |
|
| 191 |
case AST_FORMAT_SLIN: |
| 192 |
return ast_format_slin; |
| 193 |
|
| 194 |
case AST_FORMAT_LPC10: |
| 195 |
return ast_format_lpc10; |
| 196 |
|
| 197 |
case AST_FORMAT_G729: |
| 198 |
return ast_format_g729; |
| 199 |
|
| 200 |
case AST_FORMAT_SPEEX: |
| 201 |
return ast_format_speex; |
| 202 |
|
| 203 |
case AST_FORMAT_ILBC: |
| 204 |
return ast_format_ilbc; |
| 205 |
|
| 206 |
case AST_FORMAT_G726: |
| 207 |
return ast_format_g726; |
| 208 |
|
| 209 |
case AST_FORMAT_G722: |
| 210 |
return ast_format_g722; |
| 211 |
|
| 212 |
case AST_FORMAT_SIREN7: |
| 213 |
return ast_format_siren7; |
| 214 |
|
| 215 |
case AST_FORMAT_SIREN14: |
| 216 |
return ast_format_siren14; |
| 217 |
|
| 218 |
case AST_FORMAT_SLIN16: |
| 219 |
return ast_format_slin16; |
| 220 |
|
| 221 |
case AST_FORMAT_G719: |
| 222 |
return ast_format_g719; |
| 223 |
|
| 224 |
case AST_FORMAT_SPEEX16: |
| 225 |
return ast_format_speex16; |
| 226 |
|
| 227 |
case AST_FORMAT_OPUS: |
| 228 |
return ast_format_opus; |
| 229 |
|
| 230 |
|
| 231 |
case AST_FORMAT_H261: |
| 232 |
return ast_format_h261; |
| 233 |
|
| 234 |
case AST_FORMAT_H263: |
| 235 |
return ast_format_h263; |
| 236 |
|
| 237 |
case AST_FORMAT_H263P: |
| 238 |
return ast_format_h263p; |
| 239 |
|
| 240 |
case AST_FORMAT_H264: |
| 241 |
return ast_format_h264; |
| 242 |
|
| 243 |
case AST_FORMAT_MP4: |
| 244 |
return ast_format_mp4; |
| 245 |
|
| 246 |
case AST_FORMAT_VP8: |
| 247 |
return ast_format_vp8; |
| 248 |
|
| 249 |
|
| 250 |
case AST_FORMAT_JPEG: |
| 251 |
return ast_format_jpeg; |
| 252 |
|
| 253 |
case AST_FORMAT_PNG: |
| 254 |
return ast_format_png; |
| 255 |
|
| 256 |
|
| 257 |
case AST_FORMAT_T140_RED: |
| 258 |
return ast_format_t140_red; |
| 259 |
|
| 260 |
case AST_FORMAT_T140: |
| 261 |
return ast_format_t140; |
| 262 |
} |
| 263 |
return NULL; |
| 264 |
} |