/* decode encoded audio; return the number of bytes decoded * negative indicates error */ int audio_decode_audio(struct iaxc_call * call, void * out, void * data, int len, int format, int * samples) { int insize = len; int outsize = *samples; timeLastOutput = iax_tvnow(); if ( format == 0 ) { fprintf(stderr, "audio_decode_audio: Format is zero (should't happen)!\n"); return -1; } /* destroy decoder if it is incorrect type */ if ( call->decoder && call->decoder->format != format ) { call->decoder->destroy(call->decoder); call->decoder = NULL; } /* create decoder if necessary */ if ( !call->decoder ) { call->decoder = create_codec(format); } if ( !call->decoder ) { fprintf(stderr, "ERROR: Codec could not be created: %d\n", format); return -1; } if ( call->decoder->decode(call->decoder, &insize, (unsigned char *)data, &outsize, (short *)out) ) { fprintf(stderr, "ERROR: decode error: %d\n", format); return -1; } output_postprocess(out, *samples - outsize); *samples = outsize; return len - insize; }
/* decode encoded audio; return the number of bytes decoded * negative indicates error */ int decode_audio(struct iaxc_call *call, void *out, void *data, int len, int format, int *samples) { int insize = len; int outsize = *samples; //fprintf(stderr, "in decode_audio, format=%d\n", format); /* update last output timestamp */ gettimeofday( &timeLastOutput, NULL ) ; //if(len == 0) fprintf(stderr, "Interpolation voice frame\n"); if(format == 0) { fprintf(stderr, "decode_audio: Format is zero (should't happen)!\n"); return -1; } /* destroy decoder if it is incorrect type */ if(call->decoder && call->decoder->format != format) { call->decoder->destroy(call->decoder); call->decoder = NULL; } /* create encoder if necessary */ if(!call->decoder) { call->decoder = create_codec(format); } if(!call->decoder) { /* ERROR: no codec */ fprintf(stderr, "ERROR: Codec could not be created: %d\n", format); return -1; } if(call->decoder->decode(call->decoder, &insize, data, &outsize, out)) { /* ERROR: codec error */ fprintf(stderr, "ERROR: decode error: %d\n", format); return -1; } output_postprocess(out, *samples-outsize); *samples = outsize; return len-insize; }