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