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#ifndef MODULES_AUDIO_CODING_CODECS_G711_MAIN_INTERFACE_G711_INTERFACE_H_
12#define MODULES_AUDIO_CODING_CODECS_G711_MAIN_INTERFACE_G711_INTERFACE_H_
13
14#include "webrtc/typedefs.h"
15
16// Comfort noise constants
17#define G711_WEBRTC_SPEECH 1
18#define G711_WEBRTC_CNG 2
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24/****************************************************************************
25 * WebRtcG711_EncodeA(...)
26 *
27 * This function encodes a G711 A-law frame and inserts it into a packet.
28 * Input speech length has be of any length.
29 *
30 * Input:
31 *      - state              : Dummy state to make this codec look more like
32 *                             other codecs
33 *      - speechIn           : Input speech vector
34 *      - len                : Samples in speechIn
35 *
36 * Output:
37 *      - encoded            : The encoded data vector
38 *
39 * Return value              : >0 - Length (in bytes) of coded data
40 *                             -1 - Error
41 */
42
43int16_t WebRtcG711_EncodeA(void* state,
44                           int16_t* speechIn,
45                           int16_t len,
46                           int16_t* encoded);
47
48/****************************************************************************
49 * WebRtcG711_EncodeU(...)
50 *
51 * This function encodes a G711 U-law frame and inserts it into a packet.
52 * Input speech length has be of any length.
53 *
54 * Input:
55 *      - state              : Dummy state to make this codec look more like
56 *                             other codecs
57 *      - speechIn           : Input speech vector
58 *      - len                : Samples in speechIn
59 *
60 * Output:
61 *      - encoded            : The encoded data vector
62 *
63 * Return value              : >0 - Length (in bytes) of coded data
64 *                             -1 - Error
65 */
66
67int16_t WebRtcG711_EncodeU(void* state,
68                           int16_t* speechIn,
69                           int16_t len,
70                           int16_t* encoded);
71
72/****************************************************************************
73 * WebRtcG711_DecodeA(...)
74 *
75 * This function decodes a packet G711 A-law frame.
76 *
77 * Input:
78 *      - state              : Dummy state to make this codec look more like
79 *                             other codecs
80 *      - encoded            : Encoded data
81 *      - len                : Bytes in encoded vector
82 *
83 * Output:
84 *      - decoded            : The decoded vector
85 *      - speechType         : 1 normal, 2 CNG (for G711 it should
86 *                             always return 1 since G711 does not have a
87 *                             built-in DTX/CNG scheme)
88 *
89 * Return value              : >0 - Samples in decoded vector
90 *                             -1 - Error
91 */
92
93int16_t WebRtcG711_DecodeA(void* state,
94                           int16_t* encoded,
95                           int16_t len,
96                           int16_t* decoded,
97                           int16_t* speechType);
98
99/****************************************************************************
100 * WebRtcG711_DecodeU(...)
101 *
102 * This function decodes a packet G711 U-law frame.
103 *
104 * Input:
105 *      - state              : Dummy state to make this codec look more like
106 *                             other codecs
107 *      - encoded            : Encoded data
108 *      - len                : Bytes in encoded vector
109 *
110 * Output:
111 *      - decoded            : The decoded vector
112 *      - speechType         : 1 normal, 2 CNG (for G711 it should
113 *                             always return 1 since G711 does not have a
114 *                             built-in DTX/CNG scheme)
115 *
116 * Return value              : >0 - Samples in decoded vector
117 *                             -1 - Error
118 */
119
120int16_t WebRtcG711_DecodeU(void* state,
121                           int16_t* encoded,
122                           int16_t len,
123                           int16_t* decoded,
124                           int16_t* speechType);
125
126/****************************************************************************
127 * WebRtcG711_DurationEst(...)
128 *
129 * This function estimates the duration of a G711 packet in samples.
130 *
131 * Input:
132 *      - state              : Dummy state to make this codec look more like
133 *                             other codecs
134 *      - payload            : Encoded data
135 *      - payloadLengthBytes : Bytes in encoded vector
136 *
137 * Return value              : The duration of the packet in samples, which is
138 *                             just payload_length_bytes, since G.711 uses one
139 *                             byte per sample.
140 */
141
142int WebRtcG711_DurationEst(void* state,
143                           const uint8_t* payload,
144                           int payload_length_bytes);
145
146/**********************************************************************
147* WebRtcG711_Version(...)
148*
149* This function gives the version string of the G.711 codec.
150*
151* Input:
152*      - lenBytes:     the size of Allocated space (in Bytes) where
153*                      the version number is written to (in string format).
154*
155* Output:
156*      - version:      Pointer to a buffer where the version number is
157*                      written to.
158*
159*/
160
161int16_t WebRtcG711_Version(char* version, int16_t lenBytes);
162
163#ifdef __cplusplus
164}
165#endif
166
167#endif /* MODULES_AUDIO_CODING_CODECS_G711_MAIN_INTERFACE_G711_INTERFACE_H_ */
168