g722_interface.c (2875B)
1 /* 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #include "modules/audio_coding/codecs/g722/g722_interface.h" 12 13 #include <stdlib.h> 14 #include <string.h> 15 16 #include "modules/third_party/g722/g722_enc_dec.h" 17 18 int16_t WebRtcG722_CreateEncoder(G722EncInst** G722enc_inst) { 19 *G722enc_inst = (G722EncInst*)malloc(sizeof(G722EncoderState)); 20 if (*G722enc_inst != NULL) { 21 return (0); 22 } else { 23 return (-1); 24 } 25 } 26 27 int16_t WebRtcG722_EncoderInit(G722EncInst* G722enc_inst) { 28 // Create and/or reset the G.722 encoder 29 // Bitrate 64 kbps and wideband mode (2) 30 G722enc_inst = (G722EncInst*)WebRtc_g722_encode_init( 31 (G722EncoderState*)G722enc_inst, 64000, 2); 32 if (G722enc_inst == NULL) { 33 return -1; 34 } else { 35 return 0; 36 } 37 } 38 39 int WebRtcG722_FreeEncoder(G722EncInst* G722enc_inst) { 40 // Free encoder memory 41 return WebRtc_g722_encode_release((G722EncoderState*)G722enc_inst); 42 } 43 44 size_t WebRtcG722_Encode(G722EncInst* G722enc_inst, 45 const int16_t* speechIn, 46 size_t len, 47 uint8_t* encoded) { 48 unsigned char* codechar = (unsigned char*)encoded; 49 // Encode the input speech vector 50 return WebRtc_g722_encode((G722EncoderState*)G722enc_inst, codechar, speechIn, 51 len); 52 } 53 54 int16_t WebRtcG722_CreateDecoder(G722DecInst** G722dec_inst) { 55 *G722dec_inst = (G722DecInst*)malloc(sizeof(G722DecoderState)); 56 if (*G722dec_inst != NULL) { 57 return (0); 58 } else { 59 return (-1); 60 } 61 } 62 63 void WebRtcG722_DecoderInit(G722DecInst* inst) { 64 // Create and/or reset the G.722 decoder 65 // Bitrate 64 kbps and wideband mode (2) 66 WebRtc_g722_decode_init((G722DecoderState*)inst, 64000, 2); 67 } 68 69 int WebRtcG722_FreeDecoder(G722DecInst* G722dec_inst) { 70 // Free encoder memory 71 return WebRtc_g722_decode_release((G722DecoderState*)G722dec_inst); 72 } 73 74 size_t WebRtcG722_Decode(G722DecInst* G722dec_inst, 75 const uint8_t* encoded, 76 size_t len, 77 int16_t* decoded, 78 int16_t* speechType) { 79 // Decode the G.722 encoder stream 80 *speechType = G722_WEBRTC_SPEECH; 81 return WebRtc_g722_decode((G722DecoderState*)G722dec_inst, decoded, encoded, 82 len); 83 } 84 85 int16_t WebRtcG722_Version(char* versionStr, short len) { 86 // Get version string 87 char version[30] = "2.0.0\n"; 88 if (strlen(version) < (unsigned int)len) { 89 strcpy(versionStr, version); 90 return 0; 91 } else { 92 return -1; 93 } 94 }