Asterisk - The Open Source Telephony Project GIT-master-f36a736
Macros | Functions | Variables
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.

Macros

#define OUTBUF_SAMPLES   11520
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (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 const 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.

Macro Definition Documentation

◆ OUTBUF_SAMPLES

#define OUTBUF_SAMPLES   11520

Definition at line 39 of file codec_resample.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 189 of file codec_resample.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 189 of file codec_resample.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 189 of file codec_resample.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 149 of file codec_resample.c.

150{
151 int res = 0;
152 int x, y, idx = 0;
153
155 if (!(translators = ast_calloc(1, sizeof(struct ast_translator) * trans_size))) {
157 }
158
159 for (x = 0; x < ARRAY_LEN(codec_list); x++) {
160 for (y = 0; y < ARRAY_LEN(codec_list); y++) {
161 if (x == y) {
162 continue;
163 }
164 translators[idx].newpvt = resamp_new;
165 translators[idx].destroy = resamp_destroy;
166 translators[idx].framein = resamp_framein;
167 translators[idx].desc_size = 0;
168 translators[idx].buffer_samples = OUTBUF_SAMPLES;
169 translators[idx].buf_size = (OUTBUF_SAMPLES * sizeof(int16_t));
170 memcpy(&translators[idx].src_codec, &codec_list[x], sizeof(struct ast_codec));
171 memcpy(&translators[idx].dst_codec, &codec_list[y], sizeof(struct ast_codec));
172 snprintf(translators[idx].name, sizeof(translators[idx].name), "slin %ukhz -> %ukhz",
173 translators[idx].src_codec.sample_rate, translators[idx].dst_codec.sample_rate);
175 idx++;
176 }
177
178 }
179 /* in case ast_register_translator() failed, we call unload_module() and
180 ast_unregister_translator won't fail.*/
181 if (res) {
184 }
185
187}
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
#define OUTBUF_SAMPLES
static int resamp_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
static int trans_size
static int unload_module(void)
static void resamp_destroy(struct ast_trans_pvt *pvt)
static struct ast_codec codec_list[]
static int resamp_new(struct ast_trans_pvt *pvt)
short int16_t
Definition: db.h:59
static const char name[]
Definition: format_mp3.c:68
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
Represents a media codec within Asterisk.
Definition: codec.h:42
Descriptor of a translator.
Definition: translate.h:137
the list of translators
Definition: codec_dahdi.c:281
#define ast_register_translator(t)
See __ast_register_translator()
Definition: translate.h:258
#define ARRAY_LEN(a)
Definition: utils.h:666

References ARRAY_LEN, ast_calloc, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_register_translator, codec_list, name, OUTBUF_SAMPLES, resamp_destroy(), resamp_framein(), resamp_new(), trans_size, and unload_module().

◆ resamp_destroy()

static void resamp_destroy ( struct ast_trans_pvt pvt)
static

Definition at line 105 of file codec_resample.c.

106{
107 SpeexResamplerState *resamp_pvt = pvt->pvt;
108
109 speex_resampler_destroy(resamp_pvt);
110}
EXPORT void speex_resampler_destroy(SpeexResamplerState *st)
Definition: resample.c:849
void * pvt
Definition: translate.h:219

References ast_trans_pvt::pvt, and speex_resampler_destroy().

Referenced by load_module().

◆ resamp_framein()

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

Definition at line 112 of file codec_resample.c.

113{
114 SpeexResamplerState *resamp_pvt = pvt->pvt;
115 unsigned int out_samples = OUTBUF_SAMPLES - pvt->samples;
116 unsigned int in_samples;
117
118 if (!f->datalen) {
119 return -1;
120 }
121 in_samples = f->datalen / 2;
122
124 0,
125 f->data.ptr,
126 &in_samples,
127 pvt->outbuf.i16 + pvt->samples,
128 &out_samples);
129
130 pvt->samples += out_samples;
131 pvt->datalen += out_samples * 2;
132
133 return 0;
134}
EXPORT int speex_resampler_process_int(SpeexResamplerState *st, spx_uint32_t channel_index, const spx_int16_t *in, spx_uint32_t *in_len, spx_int16_t *out, spx_uint32_t *out_len)
Definition: resample.c:906
union ast_frame::@226 data
int datalen
actual space used in outbuf
Definition: translate.h:218
union ast_trans_pvt::@287 outbuf
int16_t * i16
Definition: translate.h:223

References ast_frame::data, ast_frame::datalen, ast_trans_pvt::datalen, ast_trans_pvt::i16, ast_trans_pvt::outbuf, OUTBUF_SAMPLES, ast_frame::ptr, ast_trans_pvt::pvt, ast_trans_pvt::samples, and speex_resampler_process_int().

Referenced by load_module().

◆ resamp_new()

static int resamp_new ( struct ast_trans_pvt pvt)
static

Definition at line 91 of file codec_resample.c.

92{
93 int err;
94
95 if (!(pvt->pvt = speex_resampler_init(1, pvt->t->src_codec.sample_rate, pvt->t->dst_codec.sample_rate, 5, &err))) {
96 return -1;
97 }
98
101
102 return 0;
103}
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition: astobj2.h:480
struct ast_format * ast_format_cache_get_slin_by_rate(unsigned int rate)
Retrieve the best signed linear format given a sample rate.
Definition: format_cache.c:512
#define NULL
Definition: resample.c:96
EXPORT SpeexResamplerState * speex_resampler_init(spx_uint32_t nb_channels, spx_uint32_t in_rate, spx_uint32_t out_rate, int quality, int *err)
Create a new resampler with integer input and output rates.
Definition: resample.c:783
unsigned int sample_rate
Sample rate (number of samples carried in a second)
Definition: codec.h:52
struct ast_format * format
struct ast_frame_subclass subclass
struct ast_frame f
Definition: translate.h:215
struct ast_translator * t
Definition: translate.h:214
struct ast_codec src_codec
Definition: translate.h:139
struct ast_codec dst_codec
Definition: translate.h:140
#define ast_assert(a)
Definition: utils.h:739

References ao2_bump, ast_assert, ast_format_cache_get_slin_by_rate(), ast_translator::dst_codec, ast_trans_pvt::f, ast_frame_subclass::format, NULL, ast_trans_pvt::pvt, ast_codec::sample_rate, speex_resampler_init(), ast_translator::src_codec, ast_frame::subclass, and ast_trans_pvt::t.

Referenced by load_module().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 136 of file codec_resample.c.

137{
138 int res = 0;
139 int idx;
140
141 for (idx = 0; idx < trans_size; idx++) {
143 }
145
146 return res;
147}
#define ast_free(a)
Definition: astmm.h:180
int ast_unregister_translator(struct ast_translator *t)
Unregister a translator Unregisters the given translator.
Definition: translate.c:1350

References ast_free, ast_unregister_translator(), and trans_size.

Referenced by load_module().

Variable Documentation

◆ __mod_info

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 189 of file codec_resample.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 189 of file codec_resample.c.

◆ codec_list

struct ast_codec codec_list[]
static

Definition at line 43 of file codec_resample.c.

Referenced by load_module().

◆ trans_size

int trans_size
static

Definition at line 42 of file codec_resample.c.

Referenced by load_module(), and unload_module().

◆ translators

struct ast_translator* translators
static

Definition at line 41 of file codec_resample.c.