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