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