1 /*
2 * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
3 * Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
4 *
5 * Version: MPL 1.1
6 *
7 * The contents of this file are subject to the Mozilla Public License Version
8 * 1.1 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/
11 *
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 * for the specific language governing rights and limitations under the
15 * License.
16 *
17 * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
18 *
19 * The Initial Developer of the Original Code is
20 * Anthony Minessale II <anthm@freeswitch.org>
21 * Portions created by the Initial Developer are Copyright (C)
22 * the Initial Developer. All Rights Reserved.
23 *
24 * Contributor(s):
25 *
26 * Anthony Minessale II <anthm@freeswitch.org>
27 *
28 *
29 * switch_pcm.c -- Raw and Encoded PCM 16 bit Signed Linear
30 *
31 */
32
33 #include <switch.h>
34 #include <g711.h>
35
36 #ifdef WIN32
37 #undef SWITCH_MOD_DECLARE_DATA
38 #define SWITCH_MOD_DECLARE_DATA __declspec(dllexport)
39 #endif
40 SWITCH_MODULE_LOAD_FUNCTION(core_pcm_load);
41 SWITCH_MODULE_SHUTDOWN_FUNCTION(core_pcm_shutdown);
42 SWITCH_MODULE_DEFINITION(CORE_PCM_MODULE, core_pcm_load, core_pcm_shutdown, NULL);
43
switch_raw_init(switch_codec_t * codec,switch_codec_flag_t flags,const switch_codec_settings_t * codec_settings)44 static switch_status_t switch_raw_init(switch_codec_t *codec, switch_codec_flag_t flags, const switch_codec_settings_t *codec_settings)
45 {
46 int encoding, decoding;
47
48 encoding = (flags & SWITCH_CODEC_FLAG_ENCODE);
49 decoding = (flags & SWITCH_CODEC_FLAG_DECODE);
50
51 if (!(encoding || decoding)) {
52 return SWITCH_STATUS_FALSE;
53 } else {
54 return SWITCH_STATUS_SUCCESS;
55 }
56 }
57
switch_raw_encode(switch_codec_t * codec,switch_codec_t * other_codec,void * decoded_data,uint32_t decoded_data_len,uint32_t decoded_rate,void * encoded_data,uint32_t * encoded_data_len,uint32_t * encoded_rate,unsigned int * flag)58 static switch_status_t switch_raw_encode(switch_codec_t *codec,
59 switch_codec_t *other_codec,
60 void *decoded_data,
61 uint32_t decoded_data_len,
62 uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
63 unsigned int *flag)
64 {
65 /* NOOP indicates that the audio in is already the same as the audio out, so no conversion was necessary. */
66 if (codec && other_codec && codec->implementation && other_codec->implementation &&
67 codec->implementation->actual_samples_per_second != other_codec->implementation->actual_samples_per_second) {
68 memcpy(encoded_data, decoded_data, decoded_data_len);
69 *encoded_data_len = decoded_data_len;
70 return SWITCH_STATUS_RESAMPLE;
71 }
72 return SWITCH_STATUS_NOOP;
73 }
74
switch_raw_decode(switch_codec_t * codec,switch_codec_t * other_codec,void * encoded_data,uint32_t encoded_data_len,uint32_t encoded_rate,void * decoded_data,uint32_t * decoded_data_len,uint32_t * decoded_rate,unsigned int * flag)75 static switch_status_t switch_raw_decode(switch_codec_t *codec,
76 switch_codec_t *other_codec,
77 void *encoded_data,
78 uint32_t encoded_data_len,
79 uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate,
80 unsigned int *flag)
81 {
82 if (codec && other_codec && codec->implementation && other_codec->implementation &&
83 codec->implementation->actual_samples_per_second != other_codec->implementation->actual_samples_per_second) {
84 memcpy(decoded_data, encoded_data, encoded_data_len);
85 *decoded_data_len = encoded_data_len;
86 return SWITCH_STATUS_RESAMPLE;
87 }
88 return SWITCH_STATUS_NOOP;
89 }
90
switch_raw_destroy(switch_codec_t * codec)91 static switch_status_t switch_raw_destroy(switch_codec_t *codec)
92 {
93 return SWITCH_STATUS_SUCCESS;
94 }
95
96
97
switch_proxy_init(switch_codec_t * codec,switch_codec_flag_t flags,const switch_codec_settings_t * codec_settings)98 static switch_status_t switch_proxy_init(switch_codec_t *codec, switch_codec_flag_t flags, const switch_codec_settings_t *codec_settings)
99 {
100 return SWITCH_STATUS_SUCCESS;
101 }
102
switch_proxy_encode(switch_codec_t * codec,switch_codec_t * other_codec,void * decoded_data,uint32_t decoded_data_len,uint32_t decoded_rate,void * encoded_data,uint32_t * encoded_data_len,uint32_t * encoded_rate,unsigned int * flag)103 static switch_status_t switch_proxy_encode(switch_codec_t *codec,
104 switch_codec_t *other_codec,
105 void *decoded_data,
106 uint32_t decoded_data_len,
107 uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
108 unsigned int *flag)
109 {
110 return SWITCH_STATUS_FALSE;
111 }
112
switch_proxy_decode(switch_codec_t * codec,switch_codec_t * other_codec,void * encoded_data,uint32_t encoded_data_len,uint32_t encoded_rate,void * decoded_data,uint32_t * decoded_data_len,uint32_t * decoded_rate,unsigned int * flag)113 static switch_status_t switch_proxy_decode(switch_codec_t *codec,
114 switch_codec_t *other_codec,
115 void *encoded_data,
116 uint32_t encoded_data_len,
117 uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate,
118 unsigned int *flag)
119 {
120 return SWITCH_STATUS_FALSE;
121 }
122
switch_proxy_destroy(switch_codec_t * codec)123 static switch_status_t switch_proxy_destroy(switch_codec_t *codec)
124 {
125 return SWITCH_STATUS_SUCCESS;
126 }
127
128
switch_g711u_init(switch_codec_t * codec,switch_codec_flag_t flags,const switch_codec_settings_t * codec_settings)129 static switch_status_t switch_g711u_init(switch_codec_t *codec, switch_codec_flag_t flags, const switch_codec_settings_t *codec_settings)
130 {
131 int encoding, decoding;
132
133 encoding = (flags & SWITCH_CODEC_FLAG_ENCODE);
134 decoding = (flags & SWITCH_CODEC_FLAG_DECODE);
135
136 if (!(encoding || decoding)) {
137 return SWITCH_STATUS_FALSE;
138 } else {
139 return SWITCH_STATUS_SUCCESS;
140 }
141 }
142
switch_g711u_encode(switch_codec_t * codec,switch_codec_t * other_codec,void * decoded_data,uint32_t decoded_data_len,uint32_t decoded_rate,void * encoded_data,uint32_t * encoded_data_len,uint32_t * encoded_rate,unsigned int * flag)143 static switch_status_t switch_g711u_encode(switch_codec_t *codec,
144 switch_codec_t *other_codec,
145 void *decoded_data,
146 uint32_t decoded_data_len,
147 uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
148 unsigned int *flag)
149 {
150 short *dbuf;
151 unsigned char *ebuf;
152 uint32_t i;
153
154 dbuf = decoded_data;
155 ebuf = encoded_data;
156
157 for (i = 0; i < decoded_data_len / sizeof(short); i++) {
158 ebuf[i] = linear_to_ulaw(dbuf[i]);
159 }
160
161 *encoded_data_len = i;
162
163 return SWITCH_STATUS_SUCCESS;
164 }
165
switch_g711u_decode(switch_codec_t * codec,switch_codec_t * other_codec,void * encoded_data,uint32_t encoded_data_len,uint32_t encoded_rate,void * decoded_data,uint32_t * decoded_data_len,uint32_t * decoded_rate,unsigned int * flag)166 static switch_status_t switch_g711u_decode(switch_codec_t *codec,
167 switch_codec_t *other_codec,
168 void *encoded_data,
169 uint32_t encoded_data_len,
170 uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate,
171 unsigned int *flag)
172 {
173 short *dbuf;
174 unsigned char *ebuf;
175 uint32_t i;
176
177 dbuf = decoded_data;
178 ebuf = encoded_data;
179
180 if (*flag & SWITCH_CODEC_FLAG_SILENCE) {
181 memset(dbuf, 0, codec->implementation->decoded_bytes_per_packet);
182 *decoded_data_len = codec->implementation->decoded_bytes_per_packet;
183 } else {
184 for (i = 0; i < encoded_data_len; i++) {
185 dbuf[i] = ulaw_to_linear(ebuf[i]);
186 }
187
188 *decoded_data_len = i * 2;
189 }
190
191 return SWITCH_STATUS_SUCCESS;
192 }
193
switch_g711u_destroy(switch_codec_t * codec)194 static switch_status_t switch_g711u_destroy(switch_codec_t *codec)
195 {
196 return SWITCH_STATUS_SUCCESS;
197 }
198
199
switch_g711a_init(switch_codec_t * codec,switch_codec_flag_t flags,const switch_codec_settings_t * codec_settings)200 static switch_status_t switch_g711a_init(switch_codec_t *codec, switch_codec_flag_t flags, const switch_codec_settings_t *codec_settings)
201 {
202 int encoding, decoding;
203
204 encoding = (flags & SWITCH_CODEC_FLAG_ENCODE);
205 decoding = (flags & SWITCH_CODEC_FLAG_DECODE);
206
207 if (!(encoding || decoding)) {
208 return SWITCH_STATUS_FALSE;
209 } else {
210 return SWITCH_STATUS_SUCCESS;
211 }
212 }
213
switch_g711a_encode(switch_codec_t * codec,switch_codec_t * other_codec,void * decoded_data,uint32_t decoded_data_len,uint32_t decoded_rate,void * encoded_data,uint32_t * encoded_data_len,uint32_t * encoded_rate,unsigned int * flag)214 static switch_status_t switch_g711a_encode(switch_codec_t *codec,
215 switch_codec_t *other_codec,
216 void *decoded_data,
217 uint32_t decoded_data_len,
218 uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
219 unsigned int *flag)
220 {
221 short *dbuf;
222 unsigned char *ebuf;
223 uint32_t i;
224
225 dbuf = decoded_data;
226 ebuf = encoded_data;
227
228 for (i = 0; i < decoded_data_len / sizeof(short); i++) {
229 ebuf[i] = linear_to_alaw(dbuf[i]);
230 }
231
232 *encoded_data_len = i;
233
234 return SWITCH_STATUS_SUCCESS;
235 }
236
switch_g711a_decode(switch_codec_t * codec,switch_codec_t * other_codec,void * encoded_data,uint32_t encoded_data_len,uint32_t encoded_rate,void * decoded_data,uint32_t * decoded_data_len,uint32_t * decoded_rate,unsigned int * flag)237 static switch_status_t switch_g711a_decode(switch_codec_t *codec,
238 switch_codec_t *other_codec,
239 void *encoded_data,
240 uint32_t encoded_data_len,
241 uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate,
242 unsigned int *flag)
243 {
244 short *dbuf;
245 unsigned char *ebuf;
246 uint32_t i;
247
248 dbuf = decoded_data;
249 ebuf = encoded_data;
250
251 if (*flag & SWITCH_CODEC_FLAG_SILENCE) {
252 memset(dbuf, 0, codec->implementation->decoded_bytes_per_packet);
253 *decoded_data_len = codec->implementation->decoded_bytes_per_packet;
254 } else {
255 for (i = 0; i < encoded_data_len; i++) {
256 dbuf[i] = alaw_to_linear(ebuf[i]);
257 }
258
259 *decoded_data_len = i * 2;
260 }
261
262 return SWITCH_STATUS_SUCCESS;
263 }
264
switch_g711a_destroy(switch_codec_t * codec)265 static switch_status_t switch_g711a_destroy(switch_codec_t *codec)
266 {
267 return SWITCH_STATUS_SUCCESS;
268 }
269
270
mod_g711_load(switch_loadable_module_interface_t ** module_interface,switch_memory_pool_t * pool)271 static void mod_g711_load(switch_loadable_module_interface_t ** module_interface, switch_memory_pool_t *pool)
272 {
273 switch_codec_interface_t *codec_interface;
274 int mpf = 10000, spf = 80, bpf = 160, ebpf = 80, count;
275
276 SWITCH_ADD_CODEC(codec_interface, "G.711 ulaw");
277 for (count = 12; count > 0; count--) {
278 switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
279 0, /* the IANA code number */
280 "PCMU", /* the IANA code name */
281 NULL, /* default fmtp to send (can be overridden by the init function) */
282 8000, /* samples transferred per second */
283 8000, /* actual samples transferred per second */
284 64000, /* bits transferred per second */
285 mpf * count, /* number of microseconds per frame */
286 spf * count, /* number of samples per frame */
287 bpf * count, /* number of bytes per frame decompressed */
288 ebpf * count, /* number of bytes per frame compressed */
289 1, /* number of channels represented */
290 spf * count, /* number of frames per network packet */
291 switch_g711u_init, /* function to initialize a codec handle using this implementation */
292 switch_g711u_encode, /* function to encode raw data into encoded data */
293 switch_g711u_decode, /* function to decode encoded data into raw data */
294 switch_g711u_destroy); /* deinitalize a codec handle using this implementation */
295
296 if (count > 4) continue;
297
298 switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
299 0, /* the IANA code number */
300 "PCMU", /* the IANA code name */
301 NULL, /* default fmtp to send (can be overridden by the init function) */
302 48000, /* samples transferred per second */
303 48000, /* actual samples transferred per second */
304 64000 * 6, /* bits transferred per second */
305 mpf * count, /* number of microseconds per frame */
306 spf * count * 6, /* number of samples per frame */
307 bpf * count * 6, /* number of bytes per frame decompressed */
308 ebpf * count * 6, /* number of bytes per frame compressed */
309 1, /* number of channels represented */
310 spf * count * 6, /* number of frames per network packet */
311 switch_g711u_init, /* function to initialize a codec handle using this implementation */
312 switch_g711u_encode, /* function to encode raw data into encoded data */
313 switch_g711u_decode, /* function to decode encoded data into raw data */
314 switch_g711u_destroy); /* deinitalize a codec handle using this implementation */
315
316 switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
317 0, /* the IANA code number */
318 "PCMU", /* the IANA code name */
319 NULL, /* default fmtp to send (can be overridden by the init function) */
320 48000, /* samples transferred per second */
321 48000, /* actual samples transferred per second */
322 64000 * 6 * 2, /* bits transferred per second */
323 mpf * count, /* number of microseconds per frame */
324 spf * count * 6, /* number of samples per frame */
325 bpf * count * 6 * 2, /* number of bytes per frame decompressed */
326 ebpf * count * 6 * 2, /* number of bytes per frame compressed */
327 2, /* number of channels represented */
328 spf * count * 6 * 2, /* number of frames per network packet */
329 switch_g711u_init, /* function to initialize a codec handle using this implementation */
330 switch_g711u_encode, /* function to encode raw data into encoded data */
331 switch_g711u_decode, /* function to decode encoded data into raw data */
332 switch_g711u_destroy); /* deinitalize a codec handle using this implementation */
333 }
334
335 SWITCH_ADD_CODEC(codec_interface, "G.711 alaw");
336 for (count = 12; count > 0; count--) {
337 switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
338 8, /* the IANA code number */
339 "PCMA", /* the IANA code name */
340 NULL, /* default fmtp to send (can be overridden by the init function) */
341 8000, /* samples transferred per second */
342 8000, /* actual samples transferred per second */
343 64000, /* bits transferred per second */
344 mpf * count, /* number of microseconds per frame */
345 spf * count, /* number of samples per frame */
346 bpf * count, /* number of bytes per frame decompressed */
347 ebpf * count, /* number of bytes per frame compressed */
348 1, /* number of channels represented */
349 spf * count, /* number of frames per network packet */
350 switch_g711a_init, /* function to initialize a codec handle using this implementation */
351 switch_g711a_encode, /* function to encode raw data into encoded data */
352 switch_g711a_decode, /* function to decode encoded data into raw data */
353 switch_g711a_destroy); /* deinitalize a codec handle using this implementation */
354 }
355 }
356
SWITCH_MODULE_LOAD_FUNCTION(core_pcm_load)357 SWITCH_MODULE_LOAD_FUNCTION(core_pcm_load)
358 {
359 switch_codec_interface_t *codec_interface;
360 int mpf = 10000, spf = 80, bpf = 160, ebpf = 160, bps = 128000, rate = 8000, counta = 1, countb = 12;
361 int samples_per_frame, bytes_per_frame, ms_per_frame, x;
362
363 /* connect my internal structure to the blank pointer passed to me */
364 *module_interface = switch_loadable_module_create_module_interface(pool, modname);
365
366 SWITCH_ADD_CODEC(codec_interface, "PROXY VIDEO PASS-THROUGH");
367 switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_VIDEO, /* enumeration defining the type of the codec */
368 31, /* the IANA code number */
369 "PROXY-VID", /* the IANA code name */
370 NULL, /* default fmtp to send (can be overridden by the init function) */
371 90000, /* samples transferred per second */
372 90000, /* actual samples transferred per second */
373 0, /* bits transferred per second */
374 0, /* number of microseconds per frame */
375 0, /* number of samples per frame */
376 0, /* number of bytes per frame decompressed */
377 0, /* number of bytes per frame compressed */
378 1, /* number of channels represented */
379 1, /* number of frames per network packet */
380 switch_proxy_init, /* function to initialize a codec handle using this implementation */
381 switch_proxy_encode, /* function to encode raw data into encoded data */
382 switch_proxy_decode, /* function to encode raw data into encoded data */
383 switch_proxy_destroy); /* deinitalize a codec handle using this implementation */
384
385
386 SWITCH_ADD_CODEC(codec_interface, "PROXY PASS-THROUGH");
387 switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
388 0, /* the IANA code number */
389 "PROXY", /* the IANA code name */
390 NULL, /* default fmtp to send (can be overridden by the init function) */
391 8000, /* samples transferred per second */
392 8000, /* actual samples transferred per second */
393 0, /* bits transferred per second */
394 20000, /* number of microseconds per frame */
395 160, /* number of samples per frame */
396 320, /* number of bytes per frame decompressed */
397 0, /* number of bytes per frame compressed */
398 1, /* number of channels represented */
399 1, /* number of frames per network packet */
400 switch_proxy_init, /* function to initialize a codec handle using this implementation */
401 switch_proxy_encode, /* function to encode raw data into encoded data */
402 switch_proxy_decode, /* function to decode encoded data into raw data */
403 switch_proxy_destroy); /* deinitalize a codec handle using this implementation */
404
405
406 switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
407 0, /* the IANA code number */
408 "PROXY", /* the IANA code name */
409 NULL, /* default fmtp to send (can be overridden by the init function) */
410 8000, /* samples transferred per second */
411 8000, /* actual samples transferred per second */
412 0, /* bits transferred per second */
413 20000, /* number of microseconds per frame */
414 160, /* number of samples per frame */
415 320 * 2, /* number of bytes per frame decompressed */
416 0, /* number of bytes per frame compressed */
417 2, /* number of channels represented */
418 1, /* number of frames per network packet */
419 switch_proxy_init, /* function to initialize a codec handle using this implementation */
420 switch_proxy_encode, /* function to encode raw data into encoded data */
421 switch_proxy_decode, /* function to decode encoded data into raw data */
422 switch_proxy_destroy); /* deinitalize a codec handle using this implementation */
423
424 SWITCH_ADD_CODEC(codec_interface, "RAW Signed Linear (16 bit)");
425
426 for (counta = 1; counta <= 3; counta++) {
427 if (rate == 8000) {
428 countb = 12;
429 } else {
430 countb = 6;
431 }
432 for (; countb > 0; countb--) {
433 switch_core_codec_add_implementation(pool, codec_interface,
434 SWITCH_CODEC_TYPE_AUDIO, 100, "L16", NULL, rate, rate, bps,
435 mpf * countb, spf * countb, bpf * countb, ebpf * countb, 1, spf * countb,
436 switch_raw_init, switch_raw_encode, switch_raw_decode, switch_raw_destroy);
437
438 switch_core_codec_add_implementation(pool, codec_interface,
439 SWITCH_CODEC_TYPE_AUDIO, 100, "L16", NULL, rate, rate, bps,
440 mpf * countb, spf * countb, bpf * countb * 2, ebpf * countb, 2, spf * countb,
441 switch_raw_init, switch_raw_encode, switch_raw_decode, switch_raw_destroy);
442 }
443 rate = rate * 2;
444 bps = bps * 2;
445 spf = spf * 2;
446 bpf = bpf * 2;
447 ebpf = ebpf * 2;
448 }
449
450 samples_per_frame = 240;
451 bytes_per_frame = 480;
452 ms_per_frame = 20000;
453
454 for (x = 0; x < 5; x++) {
455 switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
456 100, /* the IANA code number */
457 "L16", /* the IANA code name */
458 NULL, /* default fmtp to send (can be overridden by the init function) */
459 12000, /* samples transferred per second */
460 12000, /* actual samples transferred per second */
461 192000, /* bits transferred per second */
462 ms_per_frame, /* number of microseconds per frame */
463 samples_per_frame, /* number of samples per frame */
464 bytes_per_frame, /* number of bytes per frame decompressed */
465 bytes_per_frame, /* number of bytes per frame compressed */
466 1, /* number of channels represented */
467 1, /* number of frames per network packet */
468 switch_raw_init, /* function to initialize a codec handle using this implementation */
469 switch_raw_encode, /* function to encode raw data into encoded data */
470 switch_raw_decode, /* function to decode encoded data into raw data */
471 switch_raw_destroy); /* deinitalize a codec handle using this implementation */
472
473 switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
474 100, /* the IANA code number */
475 "L16", /* the IANA code name */
476 NULL, /* default fmtp to send (can be overridden by the init function) */
477 12000, /* samples transferred per second */
478 12000, /* actual samples transferred per second */
479 192000 * 2, /* bits transferred per second */
480 ms_per_frame, /* number of microseconds per frame */
481 samples_per_frame, /* number of samples per frame */
482 bytes_per_frame * 2, /* number of bytes per frame decompressed */
483 bytes_per_frame * 2, /* number of bytes per frame compressed */
484 2, /* number of channels represented */
485 1, /* number of frames per network packet */
486 switch_raw_init, /* function to initialize a codec handle using this implementation */
487 switch_raw_encode, /* function to encode raw data into encoded data */
488 switch_raw_decode, /* function to decode encoded data into raw data */
489 switch_raw_destroy); /* deinitalize a codec handle using this implementation */
490
491 samples_per_frame += 240;
492 bytes_per_frame += 480;
493 ms_per_frame += 20000;
494
495 }
496
497 samples_per_frame = 480;
498 bytes_per_frame = 960;
499 ms_per_frame = 20000;
500
501 for (x = 0; x < 3; x++) {
502 switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
503 100, /* the IANA code number */
504 "L16", /* the IANA code name */
505 NULL, /* default fmtp to send (can be overridden by the init function) */
506 24000, /* samples transferred per second */
507 24000, /* actual samples transferred per second */
508 384000, /* bits transferred per second */
509 ms_per_frame, /* number of microseconds per frame */
510 samples_per_frame, /* number of samples per frame */
511 bytes_per_frame, /* number of bytes per frame decompressed */
512 bytes_per_frame, /* number of bytes per frame compressed */
513 1, /* number of channels represented */
514 1, /* number of frames per network packet */
515 switch_raw_init, /* function to initialize a codec handle using this implementation */
516 switch_raw_encode, /* function to encode raw data into encoded data */
517 switch_raw_decode, /* function to decode encoded data into raw data */
518 switch_raw_destroy); /* deinitalize a codec handle using this implementation */
519
520 switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
521 100, /* the IANA code number */
522 "L16", /* the IANA code name */
523 NULL, /* default fmtp to send (can be overridden by the init function) */
524 24000, /* samples transferred per second */
525 24000, /* actual samples transferred per second */
526 384000 * 2, /* bits transferred per second */
527 ms_per_frame, /* number of microseconds per frame */
528 samples_per_frame, /* number of samples per frame */
529 bytes_per_frame * 2, /* number of bytes per frame decompressed */
530 bytes_per_frame * 2, /* number of bytes per frame compressed */
531 2, /* number of channels represented */
532 1, /* number of frames per network packet */
533 switch_raw_init, /* function to initialize a codec handle using this implementation */
534 switch_raw_encode, /* function to encode raw data into encoded data */
535 switch_raw_decode, /* function to decode encoded data into raw data */
536 switch_raw_destroy); /* deinitalize a codec handle using this implementation */
537
538 samples_per_frame += 480;
539 bytes_per_frame += 960;
540 ms_per_frame += 20000;
541
542 }
543
544 /* these formats below are for file playing. */
545
546 samples_per_frame = 96;
547 bytes_per_frame = 192;
548 ms_per_frame = 2000;
549
550 for (x = 0; x < 5; x++) {
551 switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
552 100, /* the IANA code number */
553 "L16", /* the IANA code name */
554 NULL, /* default fmtp to send (can be overridden by the init function) */
555 48000, /* samples transferred per second */
556 48000, /* actual samples transferred per second */
557 768000, /* bits transferred per second */
558 ms_per_frame, /* number of microseconds per frame */
559 samples_per_frame, /* number of samples per frame */
560 bytes_per_frame, /* number of bytes per frame decompressed */
561 bytes_per_frame, /* number of bytes per frame compressed */
562 1, /* number of channels represented */
563 1, /* number of frames per network packet */
564 switch_raw_init, /* function to initialize a codec handle using this implementation */
565 switch_raw_encode, /* function to encode raw data into encoded data */
566 switch_raw_decode, /* function to decode encoded data into raw data */
567 switch_raw_destroy); /* deinitalize a codec handle using this implementation */
568
569 switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
570 100, /* the IANA code number */
571 "L16", /* the IANA code name */
572 NULL, /* default fmtp to send (can be overridden by the init function) */
573 48000, /* samples transferred per second */
574 48000, /* actual samples transferred per second */
575 768000 * 2, /* bits transferred per second */
576 ms_per_frame, /* number of microseconds per frame */
577 samples_per_frame, /* number of samples per frame */
578 bytes_per_frame * 2, /* number of bytes per frame decompressed */
579 bytes_per_frame * 2, /* number of bytes per frame compressed */
580 2, /* number of channels represented */
581 1, /* number of frames per network packet */
582 switch_raw_init, /* function to initialize a codec handle using this implementation */
583 switch_raw_encode, /* function to encode raw data into encoded data */
584 switch_raw_decode, /* function to decode encoded data into raw data */
585 switch_raw_destroy); /* deinitalize a codec handle using this implementation */
586
587 samples_per_frame += 96;
588 bytes_per_frame += 192;
589 ms_per_frame += 2000;
590
591 }
592
593
594 samples_per_frame = 16;
595 bytes_per_frame = 32;
596 ms_per_frame = 2000;
597
598 for (x = 0; x < 4; x++) {
599 switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
600 100, /* the IANA code number */
601 "L16", /* the IANA code name */
602 NULL, /* default fmtp to send (can be overridden by the init function) */
603 8000, /* samples transferred per second */
604 8000, /* actual samples transferred per second */
605 128000, /* bits transferred per second */
606 ms_per_frame, /* number of microseconds per frame */
607 samples_per_frame, /* number of samples per frame */
608 bytes_per_frame, /* number of bytes per frame decompressed */
609 bytes_per_frame, /* number of bytes per frame compressed */
610 1, /* number of channels represented */
611 1, /* number of frames per network packet */
612 switch_raw_init, /* function to initialize a codec handle using this implementation */
613 switch_raw_encode, /* function to encode raw data into encoded data */
614 switch_raw_decode, /* function to decode encoded data into raw data */
615 switch_raw_destroy); /* deinitalize a codec handle using this implementation */
616
617 switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
618 100, /* the IANA code number */
619 "L16", /* the IANA code name */
620 NULL, /* default fmtp to send (can be overridden by the init function) */
621 8000, /* samples transferred per second */
622 8000, /* actual samples transferred per second */
623 128000 * 2, /* bits transferred per second */
624 ms_per_frame, /* number of microseconds per frame */
625 samples_per_frame, /* number of samples per frame */
626 bytes_per_frame * 2, /* number of bytes per frame decompressed */
627 bytes_per_frame * 2, /* number of bytes per frame compressed */
628 2, /* number of channels represented */
629 1, /* number of frames per network packet */
630 switch_raw_init, /* function to initialize a codec handle using this implementation */
631 switch_raw_encode, /* function to encode raw data into encoded data */
632 switch_raw_decode, /* function to decode encoded data into raw data */
633 switch_raw_destroy); /* deinitalize a codec handle using this implementation */
634
635 samples_per_frame += 16;
636 bytes_per_frame += 32;
637 ms_per_frame += 2000;
638
639 }
640
641 samples_per_frame = 32;
642 bytes_per_frame = 64;
643 ms_per_frame = 2000;
644
645 for (x = 0; x < 4; x++) {
646 switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
647 100, /* the IANA code number */
648 "L16", /* the IANA code name */
649 NULL, /* default fmtp to send (can be overridden by the init function) */
650 16000, /* samples transferred per second */
651 16000, /* actual samples transferred per second */
652 256000, /* bits transferred per second */
653 ms_per_frame, /* number of microseconds per frame */
654 samples_per_frame, /* number of samples per frame */
655 bytes_per_frame, /* number of bytes per frame decompressed */
656 bytes_per_frame, /* number of bytes per frame compressed */
657 1, /* number of channels represented */
658 1, /* number of frames per network packet */
659 switch_raw_init, /* function to initialize a codec handle using this implementation */
660 switch_raw_encode, /* function to encode raw data into encoded data */
661 switch_raw_decode, /* function to decode encoded data into raw data */
662 switch_raw_destroy); /* deinitalize a codec handle using this implementation */
663
664 switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
665 100, /* the IANA code number */
666 "L16", /* the IANA code name */
667 NULL, /* default fmtp to send (can be overridden by the init function) */
668 16000, /* samples transferred per second */
669 16000, /* actual samples transferred per second */
670 256000 * 2, /* bits transferred per second */
671 ms_per_frame, /* number of microseconds per frame */
672 samples_per_frame, /* number of samples per frame */
673 bytes_per_frame * 2, /* number of bytes per frame decompressed */
674 bytes_per_frame * 2, /* number of bytes per frame compressed */
675 2, /* number of channels represented */
676 1, /* number of frames per network packet */
677 switch_raw_init, /* function to initialize a codec handle using this implementation */
678 switch_raw_encode, /* function to encode raw data into encoded data */
679 switch_raw_decode, /* function to decode encoded data into raw data */
680 switch_raw_destroy); /* deinitalize a codec handle using this implementation */
681
682 samples_per_frame += 32;
683 bytes_per_frame += 64;
684 ms_per_frame += 2000;
685
686 }
687
688
689 samples_per_frame = 64;
690 bytes_per_frame = 128;
691 ms_per_frame = 2000;
692
693 for (x = 0; x < 4; x++) {
694 switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
695 100, /* the IANA code number */
696 "L16", /* the IANA code name */
697 NULL, /* default fmtp to send (can be overridden by the init function) */
698 32000, /* samples transferred per second */
699 32000, /* actual samples transferred per second */
700 512000, /* bits transferred per second */
701 ms_per_frame, /* number of microseconds per frame */
702 samples_per_frame, /* number of samples per frame */
703 bytes_per_frame, /* number of bytes per frame decompressed */
704 bytes_per_frame, /* number of bytes per frame compressed */
705 1, /* number of channels represented */
706 1, /* number of frames per network packet */
707 switch_raw_init, /* function to initialize a codec handle using this implementation */
708 switch_raw_encode, /* function to encode raw data into encoded data */
709 switch_raw_decode, /* function to decode encoded data into raw data */
710 switch_raw_destroy); /* deinitalize a codec handle using this implementation */
711
712 switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
713 100, /* the IANA code number */
714 "L16", /* the IANA code name */
715 NULL, /* default fmtp to send (can be overridden by the init function) */
716 32000, /* samples transferred per second */
717 32000, /* actual samples transferred per second */
718 512000 * 2, /* bits transferred per second */
719 ms_per_frame, /* number of microseconds per frame */
720 samples_per_frame, /* number of samples per frame */
721 bytes_per_frame * 2, /* number of bytes per frame decompressed */
722 bytes_per_frame * 2, /* number of bytes per frame compressed */
723 2, /* number of channels represented */
724 1, /* number of frames per network packet */
725 switch_raw_init, /* function to initialize a codec handle using this implementation */
726 switch_raw_encode, /* function to encode raw data into encoded data */
727 switch_raw_decode, /* function to decode encoded data into raw data */
728 switch_raw_destroy); /* deinitalize a codec handle using this implementation */
729
730 samples_per_frame += 64;
731 bytes_per_frame += 128;
732 ms_per_frame += 2000;
733
734 }
735
736 samples_per_frame = 960;
737 bytes_per_frame = 1920;
738 ms_per_frame = 20000;
739 /* 10ms is already registered */
740 for (x = 0; x < 3; x++) {
741 switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
742 100, /* the IANA code number */
743 "L16", /* the IANA code name */
744 NULL, /* default fmtp to send (can be overridden by the init function) */
745 48000, /* samples transferred per second */
746 48000, /* actual samples transferred per second */
747 768000, /* bits transferred per second */
748 ms_per_frame, /* number of microseconds per frame */
749 samples_per_frame, /* number of samples per frame */
750 bytes_per_frame, /* number of bytes per frame decompressed */
751 bytes_per_frame, /* number of bytes per frame compressed */
752 1, /* number of channels represented */
753 1, /* number of frames per network packet */
754 switch_raw_init, /* function to initialize a codec handle using this implementation */
755 switch_raw_encode, /* function to encode raw data into encoded data */
756 switch_raw_decode, /* function to decode encoded data into raw data */
757 switch_raw_destroy); /* deinitalize a codec handle using this implementation */
758
759 switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
760 100, /* the IANA code number */
761 "L16", /* the IANA code name */
762 NULL, /* default fmtp to send (can be overridden by the init function) */
763 48000, /* samples transferred per second */
764 48000, /* actual samples transferred per second */
765 768000 * 2, /* bits transferred per second */
766 ms_per_frame, /* number of microseconds per frame */
767 samples_per_frame, /* number of samples per frame */
768 bytes_per_frame * 2, /* number of bytes per frame decompressed */
769 bytes_per_frame * 2, /* number of bytes per frame compressed */
770 2, /* number of channels represented */
771 1, /* number of frames per network packet */
772 switch_raw_init, /* function to initialize a codec handle using this implementation */
773 switch_raw_encode, /* function to encode raw data into encoded data */
774 switch_raw_decode, /* function to decode encoded data into raw data */
775 switch_raw_destroy); /* deinitalize a codec handle using this implementation */
776
777 samples_per_frame += 480;
778 bytes_per_frame += 960;
779 ms_per_frame += 10000;
780 }
781
782 samples_per_frame = 441;
783 bytes_per_frame = 882;
784 ms_per_frame = 10000;
785
786 for (x = 0; x < 3; x++) {
787 switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
788 100, /* the IANA code number */
789 "L16", /* the IANA code name */
790 NULL, /* default fmtp to send (can be overridden by the init function) */
791 44100, /* samples transferred per second */
792 44100, /* actual samples transferred per second */
793 705600, /* bits transferred per second */
794 ms_per_frame, /* number of microseconds per frame */
795 samples_per_frame, /* number of samples per frame */
796 bytes_per_frame, /* number of bytes per frame decompressed */
797 bytes_per_frame, /* number of bytes per frame compressed */
798 1, /* number of channels represented */
799 1, /* number of frames per network packet */
800 switch_raw_init, /* function to initialize a codec handle using this implementation */
801 switch_raw_encode, /* function to encode raw data into encoded data */
802 switch_raw_decode, /* function to decode encoded data into raw data */
803 switch_raw_destroy); /* deinitalize a codec handle using this implementation */
804
805 switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
806 100, /* the IANA code number */
807 "L16", /* the IANA code name */
808 NULL, /* default fmtp to send (can be overridden by the init function) */
809 44100, /* samples transferred per second */
810 44100, /* actual samples transferred per second */
811 705600, /* bits transferred per second */
812 ms_per_frame, /* number of microseconds per frame */
813 samples_per_frame, /* number of samples per frame */
814 bytes_per_frame * 2, /* number of bytes per frame decompressed */
815 bytes_per_frame * 2, /* number of bytes per frame compressed */
816 2, /* number of channels represented */
817 1, /* number of frames per network packet */
818 switch_raw_init, /* function to initialize a codec handle using this implementation */
819 switch_raw_encode, /* function to encode raw data into encoded data */
820 switch_raw_decode, /* function to decode encoded data into raw data */
821 switch_raw_destroy); /* deinitalize a codec handle using this implementation */
822
823 samples_per_frame += 441;
824 bytes_per_frame += 882;
825 ms_per_frame += 10000;
826
827 }
828
829
830
831 switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
832 100, /* the IANA code number */
833 "L16", /* the IANA code name */
834 NULL, /* default fmtp to send (can be overridden by the init function) */
835 22050, /* samples transferred per second */
836 22050, /* actual samples transferred per second */
837 352800, /* bits transferred per second */
838 20000, /* number of microseconds per frame */
839 441, /* number of samples per frame */
840 882, /* number of bytes per frame decompressed */
841 882, /* number of bytes per frame compressed */
842 1, /* number of channels represented */
843 1, /* number of frames per network packet */
844 switch_raw_init, /* function to initialize a codec handle using this implementation */
845 switch_raw_encode, /* function to encode raw data into encoded data */
846 switch_raw_decode, /* function to decode encoded data into raw data */
847 switch_raw_destroy); /* deinitalize a codec handle using this implementation */
848
849 switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
850 100, /* the IANA code number */
851 "L16", /* the IANA code name */
852 NULL, /* default fmtp to send (can be overridden by the init function) */
853 22050, /* samples transferred per second */
854 22050, /* actual samples transferred per second */
855 352800 * 2, /* bits transferred per second */
856 20000, /* number of microseconds per frame */
857 441, /* number of samples per frame */
858 882 * 2, /* number of bytes per frame decompressed */
859 882 * 2, /* number of bytes per frame compressed */
860 2, /* number of channels represented */
861 1, /* number of frames per network packet */
862 switch_raw_init, /* function to initialize a codec handle using this implementation */
863 switch_raw_encode, /* function to encode raw data into encoded data */
864 switch_raw_decode, /* function to decode encoded data into raw data */
865 switch_raw_destroy); /* deinitalize a codec handle using this implementation */
866
867 switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
868 100, /* the IANA code number */
869 "L16", /* the IANA code name */
870 NULL, /* default fmtp to send (can be overridden by the init function) */
871 11025, /* samples transferred per second */
872 11025, /* actual samples transferred per second */
873 176400, /* bits transferred per second */
874 40000, /* number of microseconds per frame */
875 441, /* number of samples per frame */
876 882, /* number of bytes per frame decompressed */
877 882, /* number of bytes per frame compressed */
878 1, /* number of channels represented */
879 1, /* number of frames per network packet */
880 switch_raw_init, /* function to initialize a codec handle using this implementation */
881 switch_raw_encode, /* function to encode raw data into encoded data */
882 switch_raw_decode, /* function to decode encoded data into raw data */
883 switch_raw_destroy); /* deinitalize a codec handle using this implementation */
884
885 switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
886 100, /* the IANA code number */
887 "L16", /* the IANA code name */
888 NULL, /* default fmtp to send (can be overridden by the init function) */
889 11025, /* samples transferred per second */
890 11025, /* actual samples transferred per second */
891 176400 * 2, /* bits transferred per second */
892 40000, /* number of microseconds per frame */
893 441, /* number of samples per frame */
894 882 * 2, /* number of bytes per frame decompressed */
895 882 * 2, /* number of bytes per frame compressed */
896 2, /* number of channels represented */
897 1, /* number of frames per network packet */
898 switch_raw_init, /* function to initialize a codec handle using this implementation */
899 switch_raw_encode, /* function to encode raw data into encoded data */
900 switch_raw_decode, /* function to decode encoded data into raw data */
901 switch_raw_destroy); /* deinitalize a codec handle using this implementation */
902
903
904 switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
905 100, /* the IANA code number */
906 "L16", /* the IANA code name */
907 NULL, /* default fmtp to send (can be overridden by the init function) */
908 11025, /* samples transferred per second */
909 11025, /* actual samples transferred per second */
910 176400, /* bits transferred per second */
911 32000, /* number of microseconds per frame */
912 256, /* number of samples per frame */
913 512, /* number of bytes per frame decompressed */
914 512, /* number of bytes per frame compressed */
915 1, /* number of channels represented */
916 1, /* number of frames per network packet */
917 switch_raw_init, /* function to initialize a codec handle using this implementation */
918 switch_raw_encode, /* function to encode raw data into encoded data */
919 switch_raw_decode, /* function to decode encoded data into raw data */
920 switch_raw_destroy); /* deinitalize a codec handle using this implementation */
921
922 switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
923 100, /* the IANA code number */
924 "L16", /* the IANA code name */
925 NULL, /* default fmtp to send (can be overridden by the init function) */
926 11025, /* samples transferred per second */
927 11025, /* actual samples transferred per second */
928 176400 * 2, /* bits transferred per second */
929 32000, /* number of microseconds per frame */
930 256, /* number of samples per frame */
931 512 * 2, /* number of bytes per frame decompressed */
932 512 * 2, /* number of bytes per frame compressed */
933 2, /* number of channels represented */
934 1, /* number of frames per network packet */
935 switch_raw_init, /* function to initialize a codec handle using this implementation */
936 switch_raw_encode, /* function to encode raw data into encoded data */
937 switch_raw_decode, /* function to decode encoded data into raw data */
938 switch_raw_destroy); /* deinitalize a codec handle using this implementation */
939
940 /* indicate that the module should continue to be loaded */
941
942 mod_g711_load(module_interface, pool);
943
944 return SWITCH_STATUS_SUCCESS;
945 //return SWITCH_STATUS_NOUNLOAD;
946 }
947
SWITCH_MODULE_SHUTDOWN_FUNCTION(core_pcm_shutdown)948 SWITCH_MODULE_SHUTDOWN_FUNCTION(core_pcm_shutdown)
949 {
950 return SWITCH_STATUS_NOUNLOAD;
951 }
952
953 /* For Emacs:
954 * Local Variables:
955 * mode:c
956 * indent-tabs-mode:t
957 * tab-width:4
958 * c-basic-offset:4
959 * End:
960 * For VIM:
961 * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
962 */
963