⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 codec_g72x.c

📁 G.729 and G.723.1 codecs x86 (and x86_64) Linux and FreeBSD source code for Asterisk open source PBX
💻 C
📖 第 1 页 / 共 2 页
字号:
            ast_log(LOG_WARNING, "Out of buffer space\n");            return -1;        }        frametype = *((unsigned char *)f->data + x) & (short)0x0003;        framesize = g723_frame_length(frametype);        apiG723Decode(state->coder, (void *)f->data + x, badframe, dst + pvt->samples);        pvt->samples += G723_SAMPLES;        pvt->datalen += 2*G723_SAMPLES;    }    return 0;}#endifstatic int lintog72x_framein(struct ast_trans_pvt *pvt, struct ast_frame *f){    struct g72x_coder_pvt *state = pvt->pvt;    memcpy(state->buf + pvt->samples, f->data, f->datalen);    pvt->samples += f->samples;    return 0;}#if G72X_9/* length != 10 can't happen but let it be here for reference */static int g729_frame_length(int frametype){    switch (frametype) {        case 0: return 0;  /* not transmited  */        case 1: return 2;  /* SID */        case 2: return 8;  /* 729d */        case 3: return 10; /* 729, 729a */        case 4: return 15; /* 729e */    }    return 0;}#endifstatic struct ast_frame *lintog72x_frameout(struct ast_trans_pvt *pvt){    struct g72x_coder_pvt *state = pvt->pvt;    int datalen = 0;    int samples = 0;#if G72X_9    int frametype;#endif    /* We can't work on anything less than a frame in size */    if (pvt->samples < G72X_SAMPLES)        return NULL;    while (pvt->samples >= G72X_SAMPLES) {#if G72X_9        apiG729Encode(state->coder, state->buf + samples, (unsigned char *)(pvt->outbuf + datalen), G729A_CODEC, &frametype);        datalen += g729_frame_length(frametype);        /* if (frametype == 1) break; if encoding with VAD enabled terminate the frame */#else        apiG723Encode(state->coder, state->buf + samples, g723_sendrate, (void *)(pvt->outbuf + datalen));        datalen += (g723_sendrate == G723_RATE_63) ? 24 : 20;#endif        samples += G72X_SAMPLES;        pvt->samples -= G72X_SAMPLES;    }    /* Move the data at the end of the buffer to the front */    if (pvt->samples)        memmove(state->buf, state->buf + samples, pvt->samples * 2);    return ast_trans_frameout(pvt, datalen, samples);}static void g72x_destroy(struct ast_trans_pvt *pvt){    int i;    struct g72x_coder_pvt *state = pvt->pvt;    ippsFree(state->coder);    ippsFree(state->scratch_mem);    /* output the sizes of frames passed to decoder */    if (option_verbose > 2 && frame_sizes != NULL) {        ast_verbose(VERBOSE_PREFIX_3 G72X_CODEC " frames\n");        ast_verbose(VERBOSE_PREFIX_3 "length: count\n");        for (i = 0; i <= DEBUG_MAX_FRAME_SIZE; ++i) {            if (frame_sizes[i] > 0)                ast_verbose(VERBOSE_PREFIX_3 "%6d: %d\n", i, frame_sizes[i]);        }    }}static struct ast_translator g72xtolin = {    .name = G72X_CODEC "tolin",#if G72X_CALLWEAVER    .src_format = G72X_AST_FORMAT,    .dst_format = AST_FORMAT_SLINEAR,#else    .srcfmt = G72X_AST_FORMAT,    .dstfmt = AST_FORMAT_SLINEAR,#endif    .newpvt = g72xtolin_new,    .framein = g72xtolin_framein,    .destroy = g72x_destroy,    .sample = g72xtolin_sample,#if G72X_CALLWEAVER    .src_rate = 8000,    .dst_rate = 8000#elif G72X_ASTERISK >= 14    .desc_size = sizeof(struct g72x_coder_pvt) - BUFFER_SAMPLES*2, /* buffer is not needed for g723/9 -> slin */    .buf_size = SLIN_FRAME_LEN*100, /* 1 second */    .native_plc = 1#endif};static struct ast_translator lintog72x = {    .name = "linto" G72X_CODEC,#if G72X_CALLWEAVER    .src_format = AST_FORMAT_SLINEAR,    .dst_format = G72X_AST_FORMAT,#else    .srcfmt = AST_FORMAT_SLINEAR,    .dstfmt = G72X_AST_FORMAT,#endif    .newpvt = lintog72x_new,    .framein = lintog72x_framein,    .frameout = lintog72x_frameout,    .destroy = g72x_destroy,    .sample = lintog72x_sample,#if G72X_CALLWEAVER    .src_rate = 8000,    .dst_rate = 8000#elif G72X_ASTERISK >= 14    .desc_size = sizeof(struct g72x_coder_pvt), /* buffer up-to 1 second of speech */#if G72X_9    .buf_size = G729_FRAME_LEN*100 /* 1 sec of g729 */#else    .buf_size = G723_FRAME_LEN*33 /* almost 1 sec of g723 at 6.3kbps */#endif#endif};#if G72X_3static void parse_config(void){#if G72X_ASTERISK >= 15    /* XXX struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 }; */    struct ast_flags config_flags = { 0 };    struct ast_config *cfg = ast_config_load("codecs.conf", config_flags);#else    struct ast_config *cfg = ast_config_load("codecs.conf");#endif    struct ast_variable *var;    int rate;    if (cfg == NULL)        return;    for (var = ast_variable_browse(cfg, "g723"); var; var = var->next) {        if (!strcasecmp(var->name, "sendrate")) {            rate = atoi(var->value);            if (rate == 53 || rate == 63) {                if (option_verbose > 2)                    ast_verbose(VERBOSE_PREFIX_3 "G.723.1 setting sendrate to %d\n", rate);                g723_sendrate = (rate == 63) ? G723_RATE_63 : G723_RATE_53;            } else {                ast_log(LOG_ERROR, "G.723.1 sendrate must be 53 or 63\n");            }        } else {            ast_log(LOG_ERROR, "G.723.1 has only one option \"sendrate=<53|63>\" for 5.3 and 6.3Kbps respectivelly\n");        }    }    ast_config_destroy(cfg);}#endif#if G72X_ASTERISK >= 16static char* g72x_toggle_debug(int fd)#elsestatic int g72x_toggle_debug(int fd)#define CLI_SUCCESS RESULT_SUCCESS#define CLI_FAILURE RESULT_FAILURE#endif{    struct timespec delay = { 0, 100000000 }; /* 100ms */    void *tmp;    /* no locking intentionally */    if (frame_sizes != NULL) {        tmp = frame_sizes;        frame_sizes = NULL;        nanosleep(&delay, NULL); /* hope all users are gone */        ast_free(tmp);        ast_cli(fd, G72X_CODEC " debug disabled\n");    } else {        frame_sizes = (int*)ast_malloc((DEBUG_MAX_FRAME_SIZE+1)*sizeof(int));        if (frame_sizes == NULL)            return CLI_FAILURE;        memset(frame_sizes, 0, (DEBUG_MAX_FRAME_SIZE+1)*sizeof(int));        ast_cli(fd, G72X_CODEC " debug enabled\n");    }    return CLI_SUCCESS;}static char g72x_toggle_debug_desc[] = "Toggle " G72X_CODEC " codec frame size statistics";static char g72x_usage[] =    "Usage: " G72X_CODEC " debug\n"    "       Toggle " G72X_CODEC " codec frame size statistics\n";#if G72X_ASTERISK >= 16static char *handle_cli_g72x_toggle_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a){    switch (cmd) {    case CLI_INIT:        e->command = G72X_CODEC " debug";        e->usage = g72x_usage;        return NULL;    case CLI_GENERATE:        return NULL;    }    if (a->argc != 2)        return CLI_SHOWUSAGE;    g72x_toggle_debug(a->fd);    return CLI_SUCCESS;}static struct ast_cli_entry cli_g72x = AST_CLI_DEFINE(handle_cli_g72x_toggle_debug, g72x_toggle_debug_desc);#else /* 1.4 or Callweaver */static int handle_cli_g72x_toggle_debug(int fd, int argc, char **argv){    if (argc != 2)        return RESULT_SHOWUSAGE;    return g72x_toggle_debug(fd);}static struct ast_cli_entry cli_g72x = {    { G72X_CODEC, "debug", NULL }, handle_cli_g72x_toggle_debug,    g72x_toggle_debug_desc, g72x_usage, NULL};#endifstatic int load_module(void){    int res;#ifdef IPPCORE_STATIC_INIT    ippStaticInit();#endif#if G72X_3    parse_config();#endif#if G72X_9    apiG729Decoder_Alloc(G729A_CODEC, &decoder_size);    apiG729Encoder_Alloc(G729A_CODEC, &encoder_size);    apiG729Codec_ScratchMemoryAlloc(&coder_size_scratch);#else    apiG723Decoder_Alloc(&decoder_size);    apiG723Encoder_Alloc(&encoder_size);    apiG723Codec_ScratchMemoryAlloc(&coder_size_scratch);#endif    res = ast_register_translator(&g72xtolin);    if (!res)        res = ast_register_translator(&lintog72x);    else        ast_unregister_translator(&g72xtolin);    ast_cli_register(&cli_g72x);    return res;}static int unload_module(void){    int res;    res = ast_unregister_translator(&lintog72x);    res |= ast_unregister_translator(&g72xtolin);    ast_cli_unregister(&cli_g72x);    return res;}ASTERISK_FILE_VERSION(__FILE__, "1.0")#if G72X_ASTERISK >= 14/* AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, G72X_CODEC " Coder/Decoder"); */AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, G72X_DESC, .load = load_module, .unload = unload_module, .buildopt_sum = "");#else /* Asterisk 1.2 or Callweaver */static int localusecnt = 0;static char *tdesc = G72X_DESC;char *description(void) {        return tdesc;}int usecount(void) {        int res;        STANDARD_USECOUNT(res);        return res;}#if G72X_ASTERISKchar *key() {        return ASTERISK_GPL_KEY;}#endif#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -