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