codec_resample.c File Reference

Resample slinear audio. More...

#include "asterisk.h"
#include "speex/speex_resampler.h"
#include "asterisk/module.h"
#include "asterisk/translate.h"
#include "asterisk/slin.h"

Include dependency graph for codec_resample.c:

Go to the source code of this file.

Defines

#define OUTBUF_SIZE   8096

Functions

static void __reg_module (void)
static void __unreg_module (void)
static int load_module (void)
static void resamp_destroy (struct ast_trans_pvt *pvt)
static int resamp_framein (struct ast_trans_pvt *pvt, struct ast_frame *f)
static int resamp_new (struct ast_trans_pvt *pvt)
static int unload_module (void)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "SLIN Resampling Codec" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static struct ast_module_infoast_module_info = &__mod_info
static struct ast_codec codec_list []
static int trans_size
static struct ast_translatortranslators


Detailed Description

Resample slinear audio.

Definition in file codec_resample.c.


Define Documentation

#define OUTBUF_SIZE   8096

Definition at line 41 of file codec_resample.c.

Referenced by load_module(), and resamp_framein().


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 191 of file codec_resample.c.

static void __unreg_module ( void   )  [static]

Definition at line 191 of file codec_resample.c.

static int load_module ( void   )  [static]

Definition at line 151 of file codec_resample.c.

References ARRAY_LEN, ast_calloc, AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, ast_register_translator, ast_translator::buf_size, ast_translator::buffer_samples, ast_translator::desc_size, ast_translator::destroy, ast_translator::dst_codec, ast_translator::framein, name, ast_translator::newpvt, OUTBUF_SIZE, resamp_destroy(), resamp_framein(), resamp_new(), ast_codec::sample_rate, and unload_module.

00152 {
00153    int res = 0;
00154    int x, y, idx = 0;
00155 
00156    trans_size = ARRAY_LEN(codec_list) * (ARRAY_LEN(codec_list) - 1);
00157    if (!(translators = ast_calloc(1, sizeof(struct ast_translator) * trans_size))) {
00158       return AST_MODULE_LOAD_FAILURE;
00159    }
00160 
00161    for (x = 0; x < ARRAY_LEN(codec_list); x++) {
00162       for (y = 0; y < ARRAY_LEN(codec_list); y++) {
00163          if (x == y) {
00164             continue;
00165          }
00166          translators[idx].newpvt = resamp_new;
00167          translators[idx].destroy = resamp_destroy;
00168          translators[idx].framein = resamp_framein;
00169          translators[idx].desc_size = 0;
00170          translators[idx].buffer_samples = (OUTBUF_SIZE / sizeof(int16_t));
00171          translators[idx].buf_size = OUTBUF_SIZE;
00172          memcpy(&translators[idx].src_codec, &codec_list[x], sizeof(struct ast_codec));
00173          memcpy(&translators[idx].dst_codec, &codec_list[y], sizeof(struct ast_codec));
00174          snprintf(translators[idx].name, sizeof(translators[idx].name), "slin %ukhz -> %ukhz",
00175             translators[idx].src_codec.sample_rate, translators[idx].dst_codec.sample_rate);
00176          res |= ast_register_translator(&translators[idx]);
00177          idx++;
00178       }
00179 
00180    }
00181    /* in case ast_register_translator() failed, we call unload_module() and
00182    ast_unregister_translator won't fail.*/
00183    if (res) {
00184       unload_module();
00185       return AST_MODULE_LOAD_FAILURE;
00186    }
00187 
00188    return AST_MODULE_LOAD_SUCCESS;
00189 }

static void resamp_destroy ( struct ast_trans_pvt pvt  )  [static]

Definition at line 107 of file codec_resample.c.

References ast_trans_pvt::pvt, and speex_resampler_destroy.

Referenced by load_module().

00108 {
00109    SpeexResamplerState *resamp_pvt = pvt->pvt;
00110 
00111    speex_resampler_destroy(resamp_pvt);
00112 }

static int resamp_framein ( struct ast_trans_pvt pvt,
struct ast_frame f 
) [static]

Definition at line 114 of file codec_resample.c.

References ast_frame::data, ast_trans_pvt::datalen, ast_frame::datalen, ast_trans_pvt::i16, ast_trans_pvt::outbuf, OUTBUF_SIZE, ast_frame::ptr, ast_trans_pvt::pvt, ast_trans_pvt::samples, and speex_resampler_process_int.

Referenced by load_module().

00115 {
00116    SpeexResamplerState *resamp_pvt = pvt->pvt;
00117    unsigned int out_samples = (OUTBUF_SIZE / sizeof(int16_t)) - pvt->samples;
00118    unsigned int in_samples;
00119 
00120    if (!f->datalen) {
00121       return -1;
00122    }
00123    in_samples = f->datalen / 2;
00124 
00125    speex_resampler_process_int(resamp_pvt,
00126       0,
00127       f->data.ptr,
00128       &in_samples,
00129       pvt->outbuf.i16 + pvt->samples,
00130       &out_samples);
00131 
00132    pvt->samples += out_samples;
00133    pvt->datalen += out_samples * 2;
00134 
00135    return 0;
00136 }

static int resamp_new ( struct ast_trans_pvt pvt  )  [static]

static int unload_module ( void   )  [static]

Definition at line 138 of file codec_resample.c.

References ast_free, and ast_unregister_translator().

00139 {
00140    int res = 0;
00141    int idx;
00142 
00143    for (idx = 0; idx < trans_size; idx++) {
00144       res |= ast_unregister_translator(&translators[idx]);
00145    }
00146    ast_free(translators);
00147 
00148    return res;
00149 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "SLIN Resampling Codec" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, } [static]

Definition at line 191 of file codec_resample.c.

Definition at line 191 of file codec_resample.c.

struct ast_codec codec_list[] [static]

Definition at line 45 of file codec_resample.c.

Referenced by try_suggested_sip_codec().

int trans_size [static]

Definition at line 44 of file codec_resample.c.

struct ast_translator* translators [static]

Definition at line 43 of file codec_resample.c.


Generated on Thu Apr 16 06:30:16 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6