switch_pcm.c File Reference

#include <switch.h>
#include <g711.h>

Include dependency graph for switch_pcm.c:

Go to the source code of this file.

Functions

 SWITCH_MODULE_LOAD_FUNCTION (core_pcm_load)
 SWITCH_MODULE_SHUTDOWN_FUNCTION (core_pcm_shutdown)
 SWITCH_MODULE_DEFINITION (CORE_PCM_MODULE, core_pcm_load, core_pcm_shutdown, NULL)
static switch_status_t switch_raw_init (switch_codec_t *codec, switch_codec_flag_t flags, const switch_codec_settings_t *codec_settings)
static switch_status_t 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)
static switch_status_t 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)
static switch_status_t switch_raw_destroy (switch_codec_t *codec)
static switch_status_t switch_proxy_init (switch_codec_t *codec, switch_codec_flag_t flags, const switch_codec_settings_t *codec_settings)
static switch_status_t 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)
static switch_status_t 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)
static switch_status_t switch_proxy_destroy (switch_codec_t *codec)
static switch_status_t switch_g711u_init (switch_codec_t *codec, switch_codec_flag_t flags, const switch_codec_settings_t *codec_settings)
static switch_status_t 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)
static switch_status_t 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)
static switch_status_t switch_g711u_destroy (switch_codec_t *codec)
static switch_status_t switch_g711a_init (switch_codec_t *codec, switch_codec_flag_t flags, const switch_codec_settings_t *codec_settings)
static switch_status_t 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)
static switch_status_t 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)
static switch_status_t switch_g711a_destroy (switch_codec_t *codec)
static void mod_g711_load (switch_loadable_module_interface_t **module_interface, switch_memory_pool_t *pool)


Function Documentation

static void mod_g711_load ( switch_loadable_module_interface_t **  module_interface,
switch_memory_pool_t pool 
) [static]

Definition at line 271 of file switch_pcm.c.

References SWITCH_ADD_CODEC, SWITCH_CODEC_TYPE_AUDIO, switch_core_codec_add_implementation(), switch_g711a_decode(), switch_g711a_destroy(), switch_g711a_encode(), switch_g711a_init(), switch_g711u_decode(), switch_g711u_destroy(), switch_g711u_encode(), and switch_g711u_init().

Referenced by SWITCH_MODULE_LOAD_FUNCTION().

00272 {
00273         switch_codec_interface_t *codec_interface;
00274         int mpf = 10000, spf = 80, bpf = 160, ebpf = 80, count;
00275 
00276         SWITCH_ADD_CODEC(codec_interface, "G.711 ulaw");
00277         for (count = 12; count > 0; count--) {
00278                 switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO,    /* enumeration defining the type of the codec */
00279                                                                                          0,     /* the IANA code number */
00280                                                                                          "PCMU",        /* the IANA code name */
00281                                                                                          NULL,  /* default fmtp to send (can be overridden by the init function) */
00282                                                                                          8000,  /* samples transferred per second */
00283                                                                                          8000,  /* actual samples transferred per second */
00284                                                                                          64000, /* bits transferred per second */
00285                                                                                          mpf * count,   /* number of microseconds per frame */
00286                                                                                          spf * count,   /* number of samples per frame */
00287                                                                                          bpf * count,   /* number of bytes per frame decompressed */
00288                                                                                          ebpf * count,  /* number of bytes per frame compressed */
00289                                                                                          1,     /* number of channels represented */
00290                                                                                          spf * count,   /* number of frames per network packet */
00291                                                                                          switch_g711u_init,     /* function to initialize a codec handle using this implementation */
00292                                                                                          switch_g711u_encode,   /* function to encode raw data into encoded data */
00293                                                                                          switch_g711u_decode,   /* function to decode encoded data into raw data */
00294                                                                                          switch_g711u_destroy); /* deinitalize a codec handle using this implementation */
00295         }
00296 
00297         SWITCH_ADD_CODEC(codec_interface, "G.711 alaw");
00298         for (count = 12; count > 0; count--) {
00299                 switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO,    /* enumeration defining the type of the codec */
00300                                                                                          8,     /* the IANA code number */
00301                                                                                          "PCMA",        /* the IANA code name */
00302                                                                                          NULL,  /* default fmtp to send (can be overridden by the init function) */
00303                                                                                          8000,  /* samples transferred per second */
00304                                                                                          8000,  /* actual samples transferred per second */
00305                                                                                          64000, /* bits transferred per second */
00306                                                                                          mpf * count,   /* number of microseconds per frame */
00307                                                                                          spf * count,   /* number of samples per frame */
00308                                                                                          bpf * count,   /* number of bytes per frame decompressed */
00309                                                                                          ebpf * count,  /* number of bytes per frame compressed */
00310                                                                                          1,     /* number of channels represented */
00311                                                                                          spf * count,   /* number of frames per network packet */
00312                                                                                          switch_g711a_init,     /* function to initialize a codec handle using this implementation */
00313                                                                                          switch_g711a_encode,   /* function to encode raw data into encoded data */
00314                                                                                          switch_g711a_decode,   /* function to decode encoded data into raw data */
00315                                                                                          switch_g711a_destroy); /* deinitalize a codec handle using this implementation */
00316         }
00317 }

static switch_status_t 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 
) [static]

Definition at line 237 of file switch_pcm.c.

References alaw_to_linear(), switch_codec_implementation::decoded_bytes_per_packet, switch_codec::implementation, SWITCH_CODEC_FLAG_SILENCE, and SWITCH_STATUS_SUCCESS.

Referenced by mod_g711_load().

00243 {
00244         short *dbuf;
00245         unsigned char *ebuf;
00246         uint32_t i;
00247 
00248         dbuf = decoded_data;
00249         ebuf = encoded_data;
00250 
00251         if (*flag & SWITCH_CODEC_FLAG_SILENCE) {
00252                 memset(dbuf, 0, codec->implementation->decoded_bytes_per_packet);
00253                 *decoded_data_len = codec->implementation->decoded_bytes_per_packet;
00254         } else {
00255                 for (i = 0; i < encoded_data_len; i++) {
00256                         dbuf[i] = alaw_to_linear(ebuf[i]);
00257                 }
00258 
00259                 *decoded_data_len = i * 2;
00260         }
00261 
00262         return SWITCH_STATUS_SUCCESS;
00263 }

static switch_status_t switch_g711a_destroy ( switch_codec_t codec  )  [static]

Definition at line 265 of file switch_pcm.c.

References SWITCH_STATUS_SUCCESS.

Referenced by mod_g711_load().

00266 {
00267         return SWITCH_STATUS_SUCCESS;
00268 }

static switch_status_t 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 
) [static]

Definition at line 214 of file switch_pcm.c.

References linear_to_alaw(), and SWITCH_STATUS_SUCCESS.

Referenced by mod_g711_load().

00220 {
00221         short *dbuf;
00222         unsigned char *ebuf;
00223         uint32_t i;
00224 
00225         dbuf = decoded_data;
00226         ebuf = encoded_data;
00227 
00228         for (i = 0; i < decoded_data_len / sizeof(short); i++) {
00229                 ebuf[i] = linear_to_alaw(dbuf[i]);
00230         }
00231 
00232         *encoded_data_len = i;
00233 
00234         return SWITCH_STATUS_SUCCESS;
00235 }

static switch_status_t switch_g711a_init ( switch_codec_t codec,
switch_codec_flag_t  flags,
const switch_codec_settings_t codec_settings 
) [static]

Definition at line 200 of file switch_pcm.c.

References SWITCH_CODEC_FLAG_DECODE, SWITCH_CODEC_FLAG_ENCODE, SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

Referenced by mod_g711_load().

00201 {
00202         int encoding, decoding;
00203 
00204         encoding = (flags & SWITCH_CODEC_FLAG_ENCODE);
00205         decoding = (flags & SWITCH_CODEC_FLAG_DECODE);
00206 
00207         if (!(encoding || decoding)) {
00208                 return SWITCH_STATUS_FALSE;
00209         } else {
00210                 return SWITCH_STATUS_SUCCESS;
00211         }
00212 }

static switch_status_t 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 
) [static]

Definition at line 166 of file switch_pcm.c.

References switch_codec_implementation::decoded_bytes_per_packet, switch_codec::implementation, SWITCH_CODEC_FLAG_SILENCE, SWITCH_STATUS_SUCCESS, and ulaw_to_linear().

Referenced by mod_g711_load().

00172 {
00173         short *dbuf;
00174         unsigned char *ebuf;
00175         uint32_t i;
00176 
00177         dbuf = decoded_data;
00178         ebuf = encoded_data;
00179 
00180         if (*flag & SWITCH_CODEC_FLAG_SILENCE) {
00181                 memset(dbuf, 0, codec->implementation->decoded_bytes_per_packet);
00182                 *decoded_data_len = codec->implementation->decoded_bytes_per_packet;
00183         } else {
00184                 for (i = 0; i < encoded_data_len; i++) {
00185                         dbuf[i] = ulaw_to_linear(ebuf[i]);
00186                 }
00187 
00188                 *decoded_data_len = i * 2;
00189         }
00190 
00191         return SWITCH_STATUS_SUCCESS;
00192 }

static switch_status_t switch_g711u_destroy ( switch_codec_t codec  )  [static]

Definition at line 194 of file switch_pcm.c.

References SWITCH_STATUS_SUCCESS.

Referenced by mod_g711_load().

00195 {
00196         return SWITCH_STATUS_SUCCESS;
00197 }

static switch_status_t 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 
) [static]

Definition at line 143 of file switch_pcm.c.

References linear_to_ulaw(), and SWITCH_STATUS_SUCCESS.

Referenced by mod_g711_load().

00149 {
00150         short *dbuf;
00151         unsigned char *ebuf;
00152         uint32_t i;
00153 
00154         dbuf = decoded_data;
00155         ebuf = encoded_data;
00156 
00157         for (i = 0; i < decoded_data_len / sizeof(short); i++) {
00158                 ebuf[i] = linear_to_ulaw(dbuf[i]);
00159         }
00160 
00161         *encoded_data_len = i;
00162 
00163         return SWITCH_STATUS_SUCCESS;
00164 }

static switch_status_t switch_g711u_init ( switch_codec_t codec,
switch_codec_flag_t  flags,
const switch_codec_settings_t codec_settings 
) [static]

Definition at line 129 of file switch_pcm.c.

References SWITCH_CODEC_FLAG_DECODE, SWITCH_CODEC_FLAG_ENCODE, SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

Referenced by mod_g711_load().

00130 {
00131         int encoding, decoding;
00132 
00133         encoding = (flags & SWITCH_CODEC_FLAG_ENCODE);
00134         decoding = (flags & SWITCH_CODEC_FLAG_DECODE);
00135 
00136         if (!(encoding || decoding)) {
00137                 return SWITCH_STATUS_FALSE;
00138         } else {
00139                 return SWITCH_STATUS_SUCCESS;
00140         }
00141 }

SWITCH_MODULE_DEFINITION ( CORE_PCM_MODULE  ,
core_pcm_load  ,
core_pcm_shutdown  ,
NULL   
)

SWITCH_MODULE_LOAD_FUNCTION ( core_pcm_load   ) 

Definition at line 319 of file switch_pcm.c.

References mod_g711_load(), pool, SWITCH_ADD_CODEC, SWITCH_CODEC_TYPE_AUDIO, SWITCH_CODEC_TYPE_VIDEO, switch_core_codec_add_implementation(), switch_loadable_module_create_module_interface(), switch_proxy_decode(), switch_proxy_destroy(), switch_proxy_encode(), switch_proxy_init(), switch_raw_decode(), switch_raw_destroy(), switch_raw_encode(), switch_raw_init(), and SWITCH_STATUS_SUCCESS.

00320 {
00321         switch_codec_interface_t *codec_interface;
00322         int mpf = 10000, spf = 80, bpf = 160, ebpf = 160, bps = 128000, rate = 8000, counta = 1, countb = 12;
00323         int samples_per_frame, bytes_per_frame, ms_per_frame, x;
00324 
00325         /* connect my internal structure to the blank pointer passed to me */
00326         *module_interface = switch_loadable_module_create_module_interface(pool, modname);
00327 
00328         SWITCH_ADD_CODEC(codec_interface, "PROXY VIDEO PASS-THROUGH");
00329         switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_VIDEO,    /* enumeration defining the type of the codec */
00330                                                                                  31,    /* the IANA code number */
00331                                                                                  "PROXY-VID",   /* the IANA code name */
00332                                                                                  NULL,  /* default fmtp to send (can be overridden by the init function) */
00333                                                                                  90000, /* samples transferred per second */
00334                                                                                  90000, /* actual samples transferred per second */
00335                                                                                  0,     /* bits transferred per second */
00336                                                                                  0,     /* number of microseconds per frame */
00337                                                                                  0,     /* number of samples per frame */
00338                                                                                  0,     /* number of bytes per frame decompressed */
00339                                                                                  0,     /* number of bytes per frame compressed */
00340                                                                                  1,     /* number of channels represented */
00341                                                                                  1,     /* number of frames per network packet */
00342                                                                                  switch_proxy_init,     /* function to initialize a codec handle using this implementation */
00343                                                                                  switch_proxy_encode,   /* function to encode raw data into encoded data */
00344                                                                                  switch_proxy_decode,   /* function to encode raw data into encoded data */
00345                                                                                  switch_proxy_destroy); /* deinitalize a codec handle using this implementation */
00346 
00347 
00348         SWITCH_ADD_CODEC(codec_interface, "PROXY PASS-THROUGH");
00349         switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO,    /* enumeration defining the type of the codec */
00350                                                                                  0,     /* the IANA code number */
00351                                                                                  "PROXY",       /* the IANA code name */
00352                                                                                  NULL,  /* default fmtp to send (can be overridden by the init function) */
00353                                                                                  8000,  /* samples transferred per second */
00354                                                                                  8000,  /* actual samples transferred per second */
00355                                                                                  0,     /* bits transferred per second */
00356                                                                                  20000, /* number of microseconds per frame */
00357                                                                                  160,   /* number of samples per frame */
00358                                                                                  320,   /* number of bytes per frame decompressed */
00359                                                                                  320,   /* number of bytes per frame compressed */
00360                                                                                  1,     /* number of channels represented */
00361                                                                                  1,     /* number of frames per network packet */
00362                                                                                  switch_proxy_init,     /* function to initialize a codec handle using this implementation */
00363                                                                                  switch_proxy_encode,   /* function to encode raw data into encoded data */
00364                                                                                  switch_proxy_decode,   /* function to decode encoded data into raw data */
00365                                                                                  switch_proxy_destroy); /* deinitalize a codec handle using this implementation */
00366 
00367         SWITCH_ADD_CODEC(codec_interface, "RAW Signed Linear (16 bit)");
00368 
00369         for (counta = 1; counta <= 3; counta++) {
00370                 if (rate == 8000) {
00371                         countb = 12;
00372                 } else {
00373                         countb = 6;
00374                 }
00375                 for (; countb > 0; countb--) {
00376                         switch_core_codec_add_implementation(pool, codec_interface,
00377                                                                                                  SWITCH_CODEC_TYPE_AUDIO, 70, "L16", NULL, rate, rate, bps,
00378                                                                                                  mpf * countb, spf * countb, bpf * countb, ebpf * countb, 1, spf * countb,
00379                                                                                                  switch_raw_init, switch_raw_encode, switch_raw_decode, switch_raw_destroy);
00380                 }
00381                 rate = rate * 2;
00382                 bps = bps * 2;
00383                 spf = spf * 2;
00384                 bpf = bpf * 2;
00385                 ebpf = ebpf * 2;
00386         }
00387 
00388         samples_per_frame = 240;
00389         bytes_per_frame = 480;
00390         ms_per_frame = 20000;
00391 
00392         for (x = 0; x < 5; x++) {
00393                 switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO,    /* enumeration defining the type of the codec */
00394                                                                                          70,    /* the IANA code number */
00395                                                                                          "L16", /* the IANA code name */
00396                                                                                          NULL,  /* default fmtp to send (can be overridden by the init function) */
00397                                                                                          12000, /* samples transferred per second */
00398                                                                                          12000, /* actual samples transferred per second */
00399                                                                                          192000,        /* bits transferred per second */
00400                                                                                          ms_per_frame,  /* number of microseconds per frame */
00401                                                                                          samples_per_frame,     /* number of samples per frame */
00402                                                                                          bytes_per_frame,       /* number of bytes per frame decompressed */
00403                                                                                          bytes_per_frame,       /* number of bytes per frame compressed */
00404                                                                                          1,     /* number of channels represented */
00405                                                                                          1,     /* number of frames per network packet */
00406                                                                                          switch_raw_init,       /* function to initialize a codec handle using this implementation */
00407                                                                                          switch_raw_encode,     /* function to encode raw data into encoded data */
00408                                                                                          switch_raw_decode,     /* function to decode encoded data into raw data */
00409                                                                                          switch_raw_destroy);   /* deinitalize a codec handle using this implementation */
00410 
00411                 samples_per_frame += 240;
00412                 bytes_per_frame += 480;
00413                 ms_per_frame += 20000;
00414 
00415         }
00416 
00417         samples_per_frame = 480;
00418         bytes_per_frame = 960;
00419         ms_per_frame = 20000;
00420 
00421         for (x = 0; x < 3; x++) {
00422                 switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO,    /* enumeration defining the type of the codec */
00423                                                                                          70,    /* the IANA code number */
00424                                                                                          "L16", /* the IANA code name */
00425                                                                                          NULL,  /* default fmtp to send (can be overridden by the init function) */
00426                                                                                          24000, /* samples transferred per second */
00427                                                                                          24000, /* actual samples transferred per second */
00428                                                                                          384000,        /* bits transferred per second */
00429                                                                                          ms_per_frame,  /* number of microseconds per frame */
00430                                                                                          samples_per_frame,     /* number of samples per frame */
00431                                                                                          bytes_per_frame,       /* number of bytes per frame decompressed */
00432                                                                                          bytes_per_frame,       /* number of bytes per frame compressed */
00433                                                                                          1,     /* number of channels represented */
00434                                                                                          1,     /* number of frames per network packet */
00435                                                                                          switch_raw_init,       /* function to initialize a codec handle using this implementation */
00436                                                                                          switch_raw_encode,     /* function to encode raw data into encoded data */
00437                                                                                          switch_raw_decode,     /* function to decode encoded data into raw data */
00438                                                                                          switch_raw_destroy);   /* deinitalize a codec handle using this implementation */
00439 
00440                 samples_per_frame += 480;
00441                 bytes_per_frame += 960;
00442                 ms_per_frame += 20000;
00443 
00444         }
00445 
00446         /* these formats below are for file playing. */
00447 
00448         samples_per_frame = 96;
00449         bytes_per_frame = 192;
00450         ms_per_frame = 2000;
00451 
00452         for (x = 0; x < 5; x++) {
00453                 switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO,    /* enumeration defining the type of the codec */
00454                                                                                          70,    /* the IANA code number */
00455                                                                                          "L16", /* the IANA code name */
00456                                                                                          NULL,  /* default fmtp to send (can be overridden by the init function) */
00457                                                                                          48000, /* samples transferred per second */
00458                                                                                          48000, /* actual samples transferred per second */
00459                                                                                          768000,        /* bits transferred per second */
00460                                                                                          ms_per_frame,  /* number of microseconds per frame */
00461                                                                                          samples_per_frame,     /* number of samples per frame */
00462                                                                                          bytes_per_frame,       /* number of bytes per frame decompressed */
00463                                                                                          bytes_per_frame,       /* number of bytes per frame compressed */
00464                                                                                          1,     /* number of channels represented */
00465                                                                                          1,     /* number of frames per network packet */
00466                                                                                          switch_raw_init,       /* function to initialize a codec handle using this implementation */
00467                                                                                          switch_raw_encode,     /* function to encode raw data into encoded data */
00468                                                                                          switch_raw_decode,     /* function to decode encoded data into raw data */
00469                                                                                          switch_raw_destroy);   /* deinitalize a codec handle using this implementation */
00470 
00471                 samples_per_frame += 96;
00472                 bytes_per_frame += 192;
00473                 ms_per_frame += 2000;
00474 
00475         }
00476 
00477 
00478         samples_per_frame = 16;
00479         bytes_per_frame = 32;
00480         ms_per_frame = 2000;
00481 
00482         for (x = 0; x < 4; x++) {
00483                 switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO,    /* enumeration defining the type of the codec */
00484                                                                                          70,    /* the IANA code number */
00485                                                                                          "L16", /* the IANA code name */
00486                                                                                          NULL,  /* default fmtp to send (can be overridden by the init function) */
00487                                                                                          8000,  /* samples transferred per second */
00488                                                                                          8000,  /* actual samples transferred per second */
00489                                                                                          128000,        /* bits transferred per second */
00490                                                                                          ms_per_frame,  /* number of microseconds per frame */
00491                                                                                          samples_per_frame,     /* number of samples per frame */
00492                                                                                          bytes_per_frame,       /* number of bytes per frame decompressed */
00493                                                                                          bytes_per_frame,       /* number of bytes per frame compressed */
00494                                                                                          1,     /* number of channels represented */
00495                                                                                          1,     /* number of frames per network packet */
00496                                                                                          switch_raw_init,       /* function to initialize a codec handle using this implementation */
00497                                                                                          switch_raw_encode,     /* function to encode raw data into encoded data */
00498                                                                                          switch_raw_decode,     /* function to decode encoded data into raw data */
00499                                                                                          switch_raw_destroy);   /* deinitalize a codec handle using this implementation */
00500 
00501                 samples_per_frame += 16;
00502                 bytes_per_frame += 32;
00503                 ms_per_frame += 2000;
00504 
00505         }
00506 
00507         samples_per_frame = 32;
00508         bytes_per_frame = 64;
00509         ms_per_frame = 2000;
00510 
00511         for (x = 0; x < 4; x++) {
00512                 switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO,    /* enumeration defining the type of the codec */
00513                                                                                          70,    /* the IANA code number */
00514                                                                                          "L16", /* the IANA code name */
00515                                                                                          NULL,  /* default fmtp to send (can be overridden by the init function) */
00516                                                                                          16000, /* samples transferred per second */
00517                                                                                          16000, /* actual samples transferred per second */
00518                                                                                          256000,        /* bits transferred per second */
00519                                                                                          ms_per_frame,  /* number of microseconds per frame */
00520                                                                                          samples_per_frame,     /* number of samples per frame */
00521                                                                                          bytes_per_frame,       /* number of bytes per frame decompressed */
00522                                                                                          bytes_per_frame,       /* number of bytes per frame compressed */
00523                                                                                          1,     /* number of channels represented */
00524                                                                                          1,     /* number of frames per network packet */
00525                                                                                          switch_raw_init,       /* function to initialize a codec handle using this implementation */
00526                                                                                          switch_raw_encode,     /* function to encode raw data into encoded data */
00527                                                                                          switch_raw_decode,     /* function to decode encoded data into raw data */
00528                                                                                          switch_raw_destroy);   /* deinitalize a codec handle using this implementation */
00529 
00530                 samples_per_frame += 32;
00531                 bytes_per_frame += 64;
00532                 ms_per_frame += 2000;
00533 
00534         }
00535 
00536 
00537         samples_per_frame = 64;
00538         bytes_per_frame = 128;
00539         ms_per_frame = 2000;
00540 
00541         for (x = 0; x < 4; x++) {
00542                 switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO,    /* enumeration defining the type of the codec */
00543                                                                                          70,    /* the IANA code number */
00544                                                                                          "L16", /* the IANA code name */
00545                                                                                          NULL,  /* default fmtp to send (can be overridden by the init function) */
00546                                                                                          32000, /* samples transferred per second */
00547                                                                                          32000, /* actual samples transferred per second */
00548                                                                                          512000,        /* bits transferred per second */
00549                                                                                          ms_per_frame,  /* number of microseconds per frame */
00550                                                                                          samples_per_frame,     /* number of samples per frame */
00551                                                                                          bytes_per_frame,       /* number of bytes per frame decompressed */
00552                                                                                          bytes_per_frame,       /* number of bytes per frame compressed */
00553                                                                                          1,     /* number of channels represented */
00554                                                                                          1,     /* number of frames per network packet */
00555                                                                                          switch_raw_init,       /* function to initialize a codec handle using this implementation */
00556                                                                                          switch_raw_encode,     /* function to encode raw data into encoded data */
00557                                                                                          switch_raw_decode,     /* function to decode encoded data into raw data */
00558                                                                                          switch_raw_destroy);   /* deinitalize a codec handle using this implementation */
00559 
00560                 samples_per_frame += 64;
00561                 bytes_per_frame += 128;
00562                 ms_per_frame += 2000;
00563 
00564         }
00565 
00566         samples_per_frame = 960;
00567         bytes_per_frame = 1920;
00568         ms_per_frame = 20000;
00569         /* 10ms is already registered */
00570         for (x = 0; x < 3; x++) {
00571                 switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO,    /* enumeration defining the type of the codec */
00572                                                                                          70,    /* the IANA code number */
00573                                                                                          "L16", /* the IANA code name */
00574                                                                                          NULL,  /* default fmtp to send (can be overridden by the init function) */
00575                                                                                          48000, /* samples transferred per second */
00576                                                                                          48000, /* actual samples transferred per second */
00577                                                                                          768000,        /* bits transferred per second */
00578                                                                                          ms_per_frame,  /* number of microseconds per frame */
00579                                                                                          samples_per_frame,     /* number of samples per frame */
00580                                                                                          bytes_per_frame,       /* number of bytes per frame decompressed */
00581                                                                                          bytes_per_frame,       /* number of bytes per frame compressed */
00582                                                                                          1,     /* number of channels represented */
00583                                                                                          1,     /* number of frames per network packet */
00584                                                                                          switch_raw_init,       /* function to initialize a codec handle using this implementation */
00585                                                                                          switch_raw_encode,     /* function to encode raw data into encoded data */
00586                                                                                          switch_raw_decode,     /* function to decode encoded data into raw data */
00587                                                                                          switch_raw_destroy);   /* deinitalize a codec handle using this implementation */
00588                 samples_per_frame += 480;
00589                 bytes_per_frame += 960;
00590                 ms_per_frame += 10000;
00591         }
00592 
00593         switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO,    /* enumeration defining the type of the codec */
00594                                                                                  70,    /* the IANA code number */
00595                                                                                  "L16", /* the IANA code name */
00596                                                                                  NULL,  /* default fmtp to send (can be overridden by the init function) */
00597                                                                                  22050, /* samples transferred per second */
00598                                                                                  22050, /* actual samples transferred per second */
00599                                                                                  352800,        /* bits transferred per second */
00600                                                                                  20000, /* number of microseconds per frame */
00601                                                                                  441,   /* number of samples per frame */
00602                                                                                  882,   /* number of bytes per frame decompressed */
00603                                                                                  882,   /* number of bytes per frame compressed */
00604                                                                                  1,     /* number of channels represented */
00605                                                                                  1,     /* number of frames per network packet */
00606                                                                                  switch_raw_init,       /* function to initialize a codec handle using this implementation */
00607                                                                                  switch_raw_encode,     /* function to encode raw data into encoded data */
00608                                                                                  switch_raw_decode,     /* function to decode encoded data into raw data */
00609                                                                                  switch_raw_destroy);   /* deinitalize a codec handle using this implementation */
00610 
00611         switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO,    /* enumeration defining the type of the codec */
00612                                                                                  70,    /* the IANA code number */
00613                                                                                  "L16", /* the IANA code name */
00614                                                                                  NULL,  /* default fmtp to send (can be overridden by the init function) */
00615                                                                                  11025, /* samples transferred per second */
00616                                                                                  11025, /* actual samples transferred per second */
00617                                                                                  176400,        /* bits transferred per second */
00618                                                                                  40000, /* number of microseconds per frame */
00619                                                                                  441,   /* number of samples per frame */
00620                                                                                  882,   /* number of bytes per frame decompressed */
00621                                                                                  882,   /* number of bytes per frame compressed */
00622                                                                                  1,     /* number of channels represented */
00623                                                                                  1,     /* number of frames per network packet */
00624                                                                                  switch_raw_init,       /* function to initialize a codec handle using this implementation */
00625                                                                                  switch_raw_encode,     /* function to encode raw data into encoded data */
00626                                                                                  switch_raw_decode,     /* function to decode encoded data into raw data */
00627                                                                                  switch_raw_destroy);   /* deinitalize a codec handle using this implementation */
00628 
00629 
00630         switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO,    /* enumeration defining the type of the codec */
00631                                                                                  70,    /* the IANA code number */
00632                                                                                  "L16", /* the IANA code name */
00633                                                                                  NULL,  /* default fmtp to send (can be overridden by the init function) */
00634                                                                                  11025, /* samples transferred per second */
00635                                                                                  11025, /* actual samples transferred per second */
00636                                                                                  176400,        /* bits transferred per second */
00637                                                                                  32000, /* number of microseconds per frame */
00638                                                                                  256,   /* number of samples per frame */
00639                                                                                  512,   /* number of bytes per frame decompressed */
00640                                                                                  512,   /* number of bytes per frame compressed */
00641                                                                                  1,     /* number of channels represented */
00642                                                                                  1,     /* number of frames per network packet */
00643                                                                                  switch_raw_init,       /* function to initialize a codec handle using this implementation */
00644                                                                                  switch_raw_encode,     /* function to encode raw data into encoded data */
00645                                                                                  switch_raw_decode,     /* function to decode encoded data into raw data */
00646                                                                                  switch_raw_destroy);   /* deinitalize a codec handle using this implementation */
00647 
00648 
00649 
00650         /* indicate that the module should continue to be loaded */
00651 
00652         mod_g711_load(module_interface, pool);
00653 
00654         return SWITCH_STATUS_SUCCESS;
00655         //return SWITCH_STATUS_NOUNLOAD;
00656 }

SWITCH_MODULE_SHUTDOWN_FUNCTION ( core_pcm_shutdown   ) 

Definition at line 658 of file switch_pcm.c.

References SWITCH_STATUS_NOUNLOAD.

00659 {
00660         return SWITCH_STATUS_NOUNLOAD;
00661 }

static switch_status_t 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 
) [static]

Definition at line 113 of file switch_pcm.c.

References SWITCH_STATUS_FALSE.

Referenced by SWITCH_MODULE_LOAD_FUNCTION().

00119 {
00120         return SWITCH_STATUS_FALSE;
00121 }

static switch_status_t switch_proxy_destroy ( switch_codec_t codec  )  [static]

Definition at line 123 of file switch_pcm.c.

References SWITCH_STATUS_SUCCESS.

Referenced by SWITCH_MODULE_LOAD_FUNCTION().

00124 {
00125         return SWITCH_STATUS_SUCCESS;
00126 }

static switch_status_t 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 
) [static]

Definition at line 103 of file switch_pcm.c.

References SWITCH_STATUS_FALSE.

Referenced by SWITCH_MODULE_LOAD_FUNCTION().

00109 {
00110         return SWITCH_STATUS_FALSE;
00111 }

static switch_status_t switch_proxy_init ( switch_codec_t codec,
switch_codec_flag_t  flags,
const switch_codec_settings_t codec_settings 
) [static]

Definition at line 98 of file switch_pcm.c.

References SWITCH_STATUS_SUCCESS.

Referenced by SWITCH_MODULE_LOAD_FUNCTION().

00099 {
00100         return SWITCH_STATUS_SUCCESS;
00101 }

static switch_status_t 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 
) [static]

Definition at line 75 of file switch_pcm.c.

References switch_codec_implementation::actual_samples_per_second, switch_codec::implementation, SWITCH_STATUS_NOOP, and SWITCH_STATUS_RESAMPLE.

Referenced by SWITCH_MODULE_LOAD_FUNCTION().

00081 {
00082         if (codec && other_codec && codec->implementation && other_codec->implementation &&
00083                 codec->implementation->actual_samples_per_second != other_codec->implementation->actual_samples_per_second) {
00084                 memcpy(decoded_data, encoded_data, encoded_data_len);
00085                 *decoded_data_len = encoded_data_len;
00086                 return SWITCH_STATUS_RESAMPLE;
00087         }
00088         return SWITCH_STATUS_NOOP;
00089 }

static switch_status_t switch_raw_destroy ( switch_codec_t codec  )  [static]

Definition at line 91 of file switch_pcm.c.

References SWITCH_STATUS_SUCCESS.

Referenced by SWITCH_MODULE_LOAD_FUNCTION().

00092 {
00093         return SWITCH_STATUS_SUCCESS;
00094 }

static switch_status_t 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 
) [static]

Definition at line 58 of file switch_pcm.c.

References switch_codec_implementation::actual_samples_per_second, switch_codec::implementation, SWITCH_STATUS_NOOP, and SWITCH_STATUS_RESAMPLE.

Referenced by SWITCH_MODULE_LOAD_FUNCTION().

00064 {
00065         /* NOOP indicates that the audio in is already the same as the audio out, so no conversion was necessary. */
00066         if (codec && other_codec && codec->implementation && other_codec->implementation &&
00067                 codec->implementation->actual_samples_per_second != other_codec->implementation->actual_samples_per_second) {
00068                 memcpy(encoded_data, decoded_data, decoded_data_len);
00069                 *encoded_data_len = decoded_data_len;
00070                 return SWITCH_STATUS_RESAMPLE;
00071         }
00072         return SWITCH_STATUS_NOOP;
00073 }

static switch_status_t switch_raw_init ( switch_codec_t codec,
switch_codec_flag_t  flags,
const switch_codec_settings_t codec_settings 
) [static]

Definition at line 44 of file switch_pcm.c.

References SWITCH_CODEC_FLAG_DECODE, SWITCH_CODEC_FLAG_ENCODE, SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

Referenced by SWITCH_MODULE_LOAD_FUNCTION().

00045 {
00046         int encoding, decoding;
00047 
00048         encoding = (flags & SWITCH_CODEC_FLAG_ENCODE);
00049         decoding = (flags & SWITCH_CODEC_FLAG_DECODE);
00050 
00051         if (!(encoding || decoding)) {
00052                 return SWITCH_STATUS_FALSE;
00053         } else {
00054                 return SWITCH_STATUS_SUCCESS;
00055         }
00056 }


Generated on Sun May 20 04:00:13 2012 for FreeSWITCH API Documentation by  doxygen 1.4.7