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 WEBRTC_MODULES_AUDIO_CODING_CODECS_G711_G711_INTERFACE_H_
12#define WEBRTC_MODULES_AUDIO_CODING_CODECS_G711_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 *      - speechIn           : Input speech vector
32 *      - len                : Samples in speechIn
33 *
34 * Output:
35 *      - encoded            : The encoded data vector
36 *
37 * Return value              : Length (in bytes) of coded data.
38 *                             Always equal to len input parameter.
39 */
40
41size_t WebRtcG711_EncodeA(const int16_t* speechIn,
42                          size_t len,
43                          uint8_t* encoded);
44
45/****************************************************************************
46 * WebRtcG711_EncodeU(...)
47 *
48 * This function encodes a G711 U-law frame and inserts it into a packet.
49 * Input speech length has be of any length.
50 *
51 * Input:
52 *      - speechIn           : Input speech vector
53 *      - len                : Samples in speechIn
54 *
55 * Output:
56 *      - encoded            : The encoded data vector
57 *
58 * Return value              : Length (in bytes) of coded data.
59 *                             Always equal to len input parameter.
60 */
61
62size_t WebRtcG711_EncodeU(const int16_t* speechIn,
63                          size_t len,
64                          uint8_t* encoded);
65
66/****************************************************************************
67 * WebRtcG711_DecodeA(...)
68 *
69 * This function decodes a packet G711 A-law frame.
70 *
71 * Input:
72 *      - encoded            : Encoded data
73 *      - len                : Bytes in encoded vector
74 *
75 * Output:
76 *      - decoded            : The decoded vector
77 *      - speechType         : 1 normal, 2 CNG (for G711 it should
78 *                             always return 1 since G711 does not have a
79 *                             built-in DTX/CNG scheme)
80 *
81 * Return value              : >0 - Samples in decoded vector
82 *                             -1 - Error
83 */
84
85size_t WebRtcG711_DecodeA(const uint8_t* encoded,
86                          size_t len,
87                          int16_t* decoded,
88                          int16_t* speechType);
89
90/****************************************************************************
91 * WebRtcG711_DecodeU(...)
92 *
93 * This function decodes a packet G711 U-law frame.
94 *
95 * Input:
96 *      - encoded            : Encoded data
97 *      - len                : Bytes in encoded vector
98 *
99 * Output:
100 *      - decoded            : The decoded vector
101 *      - speechType         : 1 normal, 2 CNG (for G711 it should
102 *                             always return 1 since G711 does not have a
103 *                             built-in DTX/CNG scheme)
104 *
105 * Return value              : >0 - Samples in decoded vector
106 *                             -1 - Error
107 */
108
109size_t WebRtcG711_DecodeU(const uint8_t* encoded,
110                          size_t len,
111                          int16_t* decoded,
112                          int16_t* speechType);
113
114/**********************************************************************
115* WebRtcG711_Version(...)
116*
117* This function gives the version string of the G.711 codec.
118*
119* Input:
120*      - lenBytes:     the size of Allocated space (in Bytes) where
121*                      the version number is written to (in string format).
122*
123* Output:
124*      - version:      Pointer to a buffer where the version number is
125*                      written to.
126*
127*/
128
129int16_t WebRtcG711_Version(char* version, int16_t lenBytes);
130
131#ifdef __cplusplus
132}
133#endif
134
135#endif  // WEBRTC_MODULES_AUDIO_CODING_CODECS_G711_G711_INTERFACE_H_
136