static switch_status_t switch_bcg729_init(switch_codec_t *codec, switch_codec_flag_t flags, const switch_codec_settings_t *codec_settings) { struct bcg729_context *context = NULL; int encoding, decoding; encoding = (flags & SWITCH_CODEC_FLAG_ENCODE); decoding = (flags & SWITCH_CODEC_FLAG_DECODE); if (!(encoding || decoding) || (!(context = switch_core_alloc(codec->memory_pool, sizeof(struct bcg729_context))))) { return SWITCH_STATUS_FALSE; } else { if (codec->fmtp_in) { codec->fmtp_out = switch_core_strdup(codec->memory_pool, codec->fmtp_in); } if (encoding) { context->encoder_object = initBcg729EncoderChannel(); } if (decoding) { context->decoder_object = initBcg729DecoderChannel(); } codec->private_info = context; return SWITCH_STATUS_SUCCESS; } }
static void generic_plc_init(MSFilter *f) { generic_plc_struct *mgps = (generic_plc_struct*) ms_new0(generic_plc_struct, 1); #ifdef HAVE_G729B mgps->decoderChannelContext = initBcg729DecoderChannel(); /* initialize bcg729 decoder for CNG */ #endif mgps->concealer = ms_concealer_context_new(MAX_PLC_COUNT); mgps->nchannels = 1; f->data = mgps; }
static ErlDrvData codec_drv_start(ErlDrvPort port, char *buff) { codec_data* d = (codec_data*)driver_alloc(sizeof(codec_data)); d->port = port; d->estate = initBcg729EncoderChannel(); d->dstate = initBcg729DecoderChannel(); set_port_control_flags(port, PORT_CONTROL_FLAG_BINARY); return (ErlDrvData)d; }
int mgcp_transcoding_setup(struct mgcp_endpoint *endp, struct mgcp_rtp_end *dst_end, struct mgcp_rtp_end *src_end) { struct mgcp_process_rtp_state *state; enum audio_format src_fmt, dst_fmt; const struct mgcp_rtp_codec *src_codec = &src_end->codec; const struct mgcp_rtp_codec *dst_codec = &dst_end->codec; /* cleanup first */ if (dst_end->rtp_process_data) { talloc_free(dst_end->rtp_process_data); dst_end->rtp_process_data = NULL; } if (!src_end) return 0; src_fmt = get_audio_format(src_codec); dst_fmt = get_audio_format(dst_codec); LOGP(DMGCP, LOGL_ERROR, "Checking transcoding: %s (%d) -> %s (%d)\n", src_codec->subtype_name, src_codec->payload_type, dst_codec->subtype_name, dst_codec->payload_type); if (src_fmt == AF_INVALID || dst_fmt == AF_INVALID) { if (!src_codec->subtype_name || !dst_codec->subtype_name) /* Not enough info, do nothing */ return 0; if (strcmp(src_codec->subtype_name, dst_codec->subtype_name) == 0) /* Nothing to do */ return 0; LOGP(DMGCP, LOGL_ERROR, "Cannot transcode: %s codec not supported (%s -> %s).\n", src_fmt != AF_INVALID ? "destination" : "source", src_codec->audio_name, dst_codec->audio_name); return -EINVAL; } if (src_codec->rate && dst_codec->rate && src_codec->rate != dst_codec->rate) { LOGP(DMGCP, LOGL_ERROR, "Cannot transcode: rate conversion (%d -> %d) not supported.\n", src_codec->rate, dst_codec->rate); return -EINVAL; } state = talloc_zero(endp->tcfg->cfg, struct mgcp_process_rtp_state); talloc_set_destructor(state, processing_state_destructor); dst_end->rtp_process_data = state; state->src_fmt = src_fmt; switch (state->src_fmt) { case AF_L16: case AF_S16: state->src_frame_size = 80 * sizeof(short); state->src_samples_per_frame = 80; break; case AF_GSM: state->src_frame_size = sizeof(gsm_frame); state->src_samples_per_frame = 160; state->src.gsm_handle = gsm_create(); if (!state->src.gsm_handle) { LOGP(DMGCP, LOGL_ERROR, "Failed to initialize GSM decoder.\n"); return -EINVAL; } break; #ifdef HAVE_BCG729 case AF_G729: state->src_frame_size = 10; state->src_samples_per_frame = 80; state->src.g729_dec = initBcg729DecoderChannel(); if (!state->src.g729_dec) { LOGP(DMGCP, LOGL_ERROR, "Failed to initialize G.729 decoder.\n"); return -EINVAL; } break; #endif case AF_PCMA: state->src_frame_size = 80; state->src_samples_per_frame = 80; break; default: break; } state->dst_fmt = dst_fmt; switch (state->dst_fmt) { case AF_L16: case AF_S16: state->dst_frame_size = 80*sizeof(short); state->dst_samples_per_frame = 80; break; case AF_GSM: state->dst_frame_size = sizeof(gsm_frame); state->dst_samples_per_frame = 160; state->dst.gsm_handle = gsm_create(); if (!state->dst.gsm_handle) { LOGP(DMGCP, LOGL_ERROR, "Failed to initialize GSM encoder.\n"); return -EINVAL; } break; #ifdef HAVE_BCG729 case AF_G729: state->dst_frame_size = 10; state->dst_samples_per_frame = 80; state->dst.g729_enc = initBcg729EncoderChannel(); if (!state->dst.g729_enc) { LOGP(DMGCP, LOGL_ERROR, "Failed to initialize G.729 decoder.\n"); return -EINVAL; } break; #endif case AF_PCMA: state->dst_frame_size = 80; state->dst_samples_per_frame = 80; break; default: break; } if (dst_end->force_output_ptime) state->dst_packet_duration = mgcp_rtp_packet_duration(endp, dst_end); LOGP(DMGCP, LOGL_INFO, "Initialized RTP processing on: 0x%x " "conv: %d (%d, %d, %s) -> %d (%d, %d, %s)\n", ENDPOINT_NUMBER(endp), src_fmt, src_codec->payload_type, src_codec->rate, src_end->fmtp_extra, dst_fmt, dst_codec->payload_type, dst_codec->rate, dst_end->fmtp_extra); return 0; }
int main(int argc, char *argv[] ) { int i; /*** get calling argument ***/ char *filePrefix[MAX_CHANNEL_NBR]; getArgumentsMultiChannel(argc, argv, filePrefix); /* check argument and set filePrefix if needed */ /*** input and output file pointers ***/ FILE *fpInput[MAX_CHANNEL_NBR]; FILE *fpOutput[MAX_CHANNEL_NBR]; FILE *fpBinOutput[MAX_CHANNEL_NBR]; /*** input and output buffers ***/ uint16_t inputBuffer[NB_PARAMETERS+1]; /* input buffer: an array containing the 15 parameters and the frame erasure flag */ int16_t outputBuffer[L_FRAME]; /* output buffer: the reconstructed signal */ uint8_t bitStream[10]; /* binary input for the decoder */ bcg729DecoderChannelContextStruct *decoderChannelContext[MAX_CHANNEL_NBR]; /* context array, one per channel */ /*** inits ***/ for (i=0; i<argc-1; i++) { /* open the inputs file */ if ( (fpInput[i] = fopen(argv[i+1], "r")) == NULL) { printf("%s - Error: can't open file %s\n", argv[0], argv[i+1]); exit(-1); } /* create the outputs file(filename is the same than input file with the .out extension) */ char *outputFile = malloc((strlen(filePrefix[i])+15)*sizeof(char)); sprintf(outputFile, "%s.out.multi",filePrefix[i]); if ( (fpOutput[i] = fopen(outputFile, "w")) == NULL) { printf("%s - Error: can't create file %s\n", argv[i], outputFile); exit(-1); } sprintf(outputFile, "%s.multi.pcm",filePrefix[i]); if ( (fpBinOutput[i] = fopen(outputFile, "wb")) == NULL) { printf("%s - Error: can't create file %s\n", argv[0], outputFile); exit(-1); } /*** init of the tested bloc ***/ decoderChannelContext[i] = initBcg729DecoderChannel(); } /*** initialisation complete ***/ /* perf measurement */ clock_t start, end; double cpu_time_used=0.0; int framesNbr =0; /* increase LOOP_N to increase input length and perform a more accurate profiling or perf measurement */ #define LOOP_N 1 int j,k; for (j=0; j<LOOP_N; j++) { /* perf measurement */ /*** loop over inputs file ***/ int endedFilesNbr = 0; int endedFiles[MAX_CHANNEL_NBR]; for (k=0; k<argc-1; k++) { /* reset the array of boolean containing a flag for files already read */ endedFiles[k]=0; } while (endedFilesNbr<argc-1) { /* loop until the longest file is over */ for (k=0; k<argc-1; k++) { /* read one frame on each not ended file */ if (endedFiles[k]==0) { /* read only if the file is not over */ if (fscanf(fpInput[k], "%hd,%hd,%hd,%hd,%hd,%hd,%hd,%hd,%hd,%hd,%hd,%hd,%hd,%hd,%hd,%hd", &(inputBuffer[0]), &(inputBuffer[1]), &(inputBuffer[2]), &(inputBuffer[3]), &(inputBuffer[4]), &(inputBuffer[5]), &(inputBuffer[6]), &(inputBuffer[7]), &(inputBuffer[8]), &(inputBuffer[9]), &(inputBuffer[10]), &(inputBuffer[11]), &(inputBuffer[12]), &(inputBuffer[13]), &(inputBuffer[14]), &(inputBuffer[15]))==16) /* index 4 and 5 are inverted to get P0 in 4 and P1 in 5 in the array */ { /* input buffer contains the parameters and in [15] the frame erasure flag */ int i; framesNbr++; parametersArray2BitStream(inputBuffer, bitStream); start = clock(); bcg729Decoder(decoderChannelContext[k], bitStream, inputBuffer[15], outputBuffer); end = clock(); cpu_time_used += ((double) (end - start)); /* write the output to the output file */ if (j==0) { fprintf(fpOutput[k],"%d",outputBuffer[0]); for (i=1; i<L_FRAME; i++) { fprintf(fpOutput[k],",%d",outputBuffer[i]); } fprintf(fpOutput[k],"\n"); /* write the ouput to raw data file */ fwrite(outputBuffer, sizeof(int16_t), L_FRAME, fpBinOutput[k]); } } else { /* we've reach the end of the file */ endedFiles[k]=1; endedFilesNbr++; } } } } /* perf measurement */ for (k=0; k<argc-1; k++) { rewind(fpInput[k]); } } /* close decoder channels */ for (k=0; k<argc-1; k++) { closeBcg729DecoderChannel(decoderChannelContext[k]); } /* Perf measurement: uncomment next line to print cpu usage */ printf("Decode %d frames in %f seconds : %f us/frame\n", framesNbr, cpu_time_used/CLOCKS_PER_SEC, cpu_time_used*1000000/((double)framesNbr*CLOCKS_PER_SEC)); /* perf measurement */ exit (0); }