Mon Oct 8 12:39:01 2012

Asterisk developer's documentation


codec_ulaw.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2005, Digium, Inc.
00005  *
00006  * Mark Spencer <markster@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*! \file
00020  *
00021  * \brief codec_ulaw.c - translate between signed linear and ulaw
00022  * 
00023  * \ingroup codecs
00024  */
00025 
00026 /*** MODULEINFO
00027    <support_level>core</support_level>
00028  ***/
00029 
00030 #include "asterisk.h"
00031 
00032 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 328209 $")
00033 
00034 #include "asterisk/module.h"
00035 #include "asterisk/config.h"
00036 #include "asterisk/translate.h"
00037 #include "asterisk/ulaw.h"
00038 #include "asterisk/utils.h"
00039 
00040 #define BUFFER_SAMPLES   8096 /* size for the translation buffers */
00041 
00042 /* Sample frame data */
00043 #include "asterisk/slin.h"
00044 #include "ex_ulaw.h"
00045 
00046 /*! \brief convert and store samples in outbuf */
00047 static int ulawtolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
00048 {
00049    int i = f->samples;
00050    unsigned char *src = f->data.ptr;
00051    int16_t *dst = pvt->outbuf.i16 + pvt->samples;
00052 
00053    pvt->samples += i;
00054    pvt->datalen += i * 2;  /* 2 bytes/sample */
00055 
00056    /* convert and copy in outbuf */
00057    while (i--)
00058       *dst++ = AST_MULAW(*src++);
00059 
00060    return 0;
00061 }
00062 
00063 /*! \brief convert and store samples in outbuf */
00064 static int lintoulaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
00065 {
00066    int i = f->samples;
00067    char *dst = pvt->outbuf.c + pvt->samples;
00068    int16_t *src = f->data.ptr;
00069 
00070    pvt->samples += i;
00071    pvt->datalen += i;   /* 1 byte/sample */
00072 
00073    while (i--)
00074       *dst++ = AST_LIN2MU(*src++);
00075 
00076    return 0;
00077 }
00078 
00079 /*!
00080  * \brief The complete translator for ulawToLin.
00081  */
00082 
00083 static struct ast_translator ulawtolin = {
00084    .name = "ulawtolin",
00085    .srcfmt = AST_FORMAT_ULAW,
00086    .dstfmt = AST_FORMAT_SLINEAR,
00087    .framein = ulawtolin_framein,
00088    .sample = ulaw_sample,
00089    .buffer_samples = BUFFER_SAMPLES,
00090    .buf_size = BUFFER_SAMPLES * 2,
00091 };
00092 
00093 static struct ast_translator testlawtolin = {
00094    .name = "testlawtolin",
00095    .srcfmt = AST_FORMAT_TESTLAW,
00096    .dstfmt = AST_FORMAT_SLINEAR,
00097    .framein = ulawtolin_framein,
00098    .sample = ulaw_sample,
00099    .buffer_samples = BUFFER_SAMPLES,
00100    .buf_size = BUFFER_SAMPLES * 2,
00101 };
00102 
00103 /*!
00104  * \brief The complete translator for LinToulaw.
00105  */
00106 
00107 static struct ast_translator lintoulaw = {
00108    .name = "lintoulaw",
00109    .srcfmt = AST_FORMAT_SLINEAR,
00110    .dstfmt = AST_FORMAT_ULAW,
00111    .framein = lintoulaw_framein,
00112    .sample = slin8_sample,
00113    .buf_size = BUFFER_SAMPLES,
00114    .buffer_samples = BUFFER_SAMPLES,
00115 };
00116 
00117 static struct ast_translator lintotestlaw = {
00118    .name = "lintotestlaw",
00119    .srcfmt = AST_FORMAT_SLINEAR,
00120    .dstfmt = AST_FORMAT_TESTLAW,
00121    .framein = lintoulaw_framein,
00122    .sample = slin8_sample,
00123    .buf_size = BUFFER_SAMPLES,
00124    .buffer_samples = BUFFER_SAMPLES,
00125 };
00126 
00127 static int reload(void)
00128 {
00129    return AST_MODULE_LOAD_SUCCESS;
00130 }
00131 
00132 static int unload_module(void)
00133 {
00134    int res;
00135 
00136    res = ast_unregister_translator(&lintoulaw);
00137    res |= ast_unregister_translator(&ulawtolin);
00138    res |= ast_unregister_translator(&testlawtolin);
00139    res |= ast_unregister_translator(&lintotestlaw);
00140 
00141    return res;
00142 }
00143 
00144 static int load_module(void)
00145 {
00146    int res;
00147 
00148    res = ast_register_translator(&ulawtolin);
00149    if (!res) {
00150       res = ast_register_translator(&lintoulaw);
00151       res |= ast_register_translator(&lintotestlaw);
00152       res |= ast_register_translator(&testlawtolin);
00153    } else
00154       ast_unregister_translator(&ulawtolin);
00155    if (res)
00156       return AST_MODULE_LOAD_FAILURE;
00157    return AST_MODULE_LOAD_SUCCESS;
00158 }
00159 
00160 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "mu-Law Coder/Decoder",
00161       .load = load_module,
00162       .unload = unload_module,
00163       .reload = reload,
00164           );

Generated on Mon Oct 8 12:39:01 2012 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7