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
12
13 #include <stdlib.h>
14 #include <string.h>
15 #include "g722_enc_dec.h"
16 #include "g722_interface.h"
17 #include "webrtc/typedefs.h"
18
WebRtcG722_CreateEncoder(G722EncInst ** G722enc_inst)19 int16_t WebRtcG722_CreateEncoder(G722EncInst **G722enc_inst)
20 {
21 *G722enc_inst=(G722EncInst*)malloc(sizeof(G722EncoderState));
22 if (*G722enc_inst!=NULL) {
23 return(0);
24 } else {
25 return(-1);
26 }
27 }
28
WebRtcG722_EncoderInit(G722EncInst * G722enc_inst)29 int16_t WebRtcG722_EncoderInit(G722EncInst *G722enc_inst)
30 {
31 // Create and/or reset the G.722 encoder
32 // Bitrate 64 kbps and wideband mode (2)
33 G722enc_inst = (G722EncInst *) WebRtc_g722_encode_init(
34 (G722EncoderState*) G722enc_inst, 64000, 2);
35 if (G722enc_inst == NULL) {
36 return -1;
37 } else {
38 return 0;
39 }
40 }
41
WebRtcG722_FreeEncoder(G722EncInst * G722enc_inst)42 int WebRtcG722_FreeEncoder(G722EncInst *G722enc_inst)
43 {
44 // Free encoder memory
45 return WebRtc_g722_encode_release((G722EncoderState*) G722enc_inst);
46 }
47
WebRtcG722_Encode(G722EncInst * G722enc_inst,const int16_t * speechIn,size_t len,uint8_t * encoded)48 size_t WebRtcG722_Encode(G722EncInst *G722enc_inst,
49 const int16_t* speechIn,
50 size_t len,
51 uint8_t* encoded)
52 {
53 unsigned char *codechar = (unsigned char*) encoded;
54 // Encode the input speech vector
55 return WebRtc_g722_encode((G722EncoderState*) G722enc_inst, codechar,
56 speechIn, len);
57 }
58
WebRtcG722_CreateDecoder(G722DecInst ** G722dec_inst)59 int16_t WebRtcG722_CreateDecoder(G722DecInst **G722dec_inst)
60 {
61 *G722dec_inst=(G722DecInst*)malloc(sizeof(G722DecoderState));
62 if (*G722dec_inst!=NULL) {
63 return(0);
64 } else {
65 return(-1);
66 }
67 }
68
WebRtcG722_DecoderInit(G722DecInst * inst)69 void WebRtcG722_DecoderInit(G722DecInst* inst) {
70 // Create and/or reset the G.722 decoder
71 // Bitrate 64 kbps and wideband mode (2)
72 WebRtc_g722_decode_init((G722DecoderState*)inst, 64000, 2);
73 }
74
WebRtcG722_FreeDecoder(G722DecInst * G722dec_inst)75 int WebRtcG722_FreeDecoder(G722DecInst *G722dec_inst)
76 {
77 // Free encoder memory
78 return WebRtc_g722_decode_release((G722DecoderState*) G722dec_inst);
79 }
80
WebRtcG722_Decode(G722DecInst * G722dec_inst,const uint8_t * encoded,size_t len,int16_t * decoded,int16_t * speechType)81 size_t WebRtcG722_Decode(G722DecInst *G722dec_inst,
82 const uint8_t *encoded,
83 size_t len,
84 int16_t *decoded,
85 int16_t *speechType)
86 {
87 // Decode the G.722 encoder stream
88 *speechType=G722_WEBRTC_SPEECH;
89 return WebRtc_g722_decode((G722DecoderState*) G722dec_inst, decoded,
90 encoded, len);
91 }
92
WebRtcG722_Version(char * versionStr,short len)93 int16_t WebRtcG722_Version(char *versionStr, short len)
94 {
95 // Get version string
96 char version[30] = "2.0.0\n";
97 if (strlen(version) < (unsigned int)len)
98 {
99 strcpy(versionStr, version);
100 return 0;
101 }
102 else
103 {
104 return -1;
105 }
106 }
107
108