blob: de8cfde11103c6eaa9a9ffd2d066e0ac5ef62107 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
leozwang@webrtc.org91b359e2012-02-28 17:26:14 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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 * ilbc.h
13 *
14 * This header file contains all of the API's for iLBC.
15 *
16 */
17
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#ifndef MODULES_AUDIO_CODING_CODECS_ILBC_ILBC_H_
19#define MODULES_AUDIO_CODING_CODECS_ILBC_ILBC_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000020
Peter Kastingdce40cf2015-08-24 14:52:23 -070021#include <stddef.h>
Niels Möllera12c42a2018-07-25 16:05:48 +020022#include <stdint.h>
niklase@google.com470e71d2011-07-07 08:21:25 +000023
24/*
25 * Solution to support multiple instances
26 * Customer has to cast instance to proper type
27 */
28
pbos@webrtc.orge728ee02014-12-17 13:43:55 +000029typedef struct iLBC_encinst_t_ IlbcEncoderInstance;
niklase@google.com470e71d2011-07-07 08:21:25 +000030
pbos@webrtc.orge728ee02014-12-17 13:43:55 +000031typedef struct iLBC_decinst_t_ IlbcDecoderInstance;
niklase@google.com470e71d2011-07-07 08:21:25 +000032
33/*
34 * Comfort noise constants
35 */
36
37#define ILBC_SPEECH 1
Yves Gerey665174f2018-06-19 15:03:05 +020038#define ILBC_CNG 2
niklase@google.com470e71d2011-07-07 08:21:25 +000039
40#ifdef __cplusplus
41extern "C" {
42#endif
43
Yves Gerey665174f2018-06-19 15:03:05 +020044/****************************************************************************
45 * WebRtcIlbcfix_XxxAssign(...)
46 *
47 * These functions assigns the encoder/decoder instance to the specified
48 * memory location
49 *
50 * Input:
51 * - XXX_xxxinst : Pointer to created instance that should be
52 * assigned
53 * - ILBCXXX_inst_Addr : Pointer to the desired memory space
54 * - size : The size that this structure occupies (in Word16)
55 *
56 * Return value : 0 - Ok
57 * -1 - Error
58 */
niklase@google.com470e71d2011-07-07 08:21:25 +000059
Yves Gerey665174f2018-06-19 15:03:05 +020060int16_t WebRtcIlbcfix_EncoderAssign(IlbcEncoderInstance** iLBC_encinst,
61 int16_t* ILBCENC_inst_Addr,
62 int16_t* size);
63int16_t WebRtcIlbcfix_DecoderAssign(IlbcDecoderInstance** iLBC_decinst,
64 int16_t* ILBCDEC_inst_Addr,
65 int16_t* size);
niklase@google.com470e71d2011-07-07 08:21:25 +000066
Yves Gerey665174f2018-06-19 15:03:05 +020067/****************************************************************************
68 * WebRtcIlbcfix_XxxAssign(...)
69 *
70 * These functions create a instance to the specified structure
71 *
72 * Input:
73 * - XXX_inst : Pointer to created instance that should be created
74 *
75 * Return value : 0 - Ok
76 * -1 - Error
77 */
niklase@google.com470e71d2011-07-07 08:21:25 +000078
Yves Gerey665174f2018-06-19 15:03:05 +020079int16_t WebRtcIlbcfix_EncoderCreate(IlbcEncoderInstance** iLBC_encinst);
80int16_t WebRtcIlbcfix_DecoderCreate(IlbcDecoderInstance** iLBC_decinst);
niklase@google.com470e71d2011-07-07 08:21:25 +000081
Yves Gerey665174f2018-06-19 15:03:05 +020082/****************************************************************************
83 * WebRtcIlbcfix_XxxFree(...)
84 *
85 * These functions frees the dynamic memory of a specified instance
86 *
87 * Input:
88 * - XXX_inst : Pointer to created instance that should be freed
89 *
90 * Return value : 0 - Ok
91 * -1 - Error
92 */
niklase@google.com470e71d2011-07-07 08:21:25 +000093
Yves Gerey665174f2018-06-19 15:03:05 +020094int16_t WebRtcIlbcfix_EncoderFree(IlbcEncoderInstance* iLBC_encinst);
95int16_t WebRtcIlbcfix_DecoderFree(IlbcDecoderInstance* iLBC_decinst);
niklase@google.com470e71d2011-07-07 08:21:25 +000096
Yves Gerey665174f2018-06-19 15:03:05 +020097/****************************************************************************
98 * WebRtcIlbcfix_EncoderInit(...)
99 *
100 * This function initializes a iLBC instance
101 *
102 * Input:
103 * - iLBCenc_inst : iLBC instance, i.e. the user that should receive
104 * be initialized
105 * - frameLen : The frame length of the codec 20/30 (ms)
106 *
107 * Return value : 0 - Ok
108 * -1 - Error
109 */
niklase@google.com470e71d2011-07-07 08:21:25 +0000110
Yves Gerey665174f2018-06-19 15:03:05 +0200111int16_t WebRtcIlbcfix_EncoderInit(IlbcEncoderInstance* iLBCenc_inst,
112 int16_t frameLen);
niklase@google.com470e71d2011-07-07 08:21:25 +0000113
Yves Gerey665174f2018-06-19 15:03:05 +0200114/****************************************************************************
115 * WebRtcIlbcfix_Encode(...)
116 *
117 * This function encodes one iLBC frame. Input speech length has be a
118 * multiple of the frame length.
119 *
120 * Input:
121 * - iLBCenc_inst : iLBC instance, i.e. the user that should encode
122 * a package
123 * - speechIn : Input speech vector
124 * - len : Samples in speechIn (160, 240, 320 or 480)
125 *
126 * Output:
127 * - encoded : The encoded data vector
128 *
129 * Return value : >0 - Length (in bytes) of coded data
130 * -1 - Error
131 */
niklase@google.com470e71d2011-07-07 08:21:25 +0000132
Yves Gerey665174f2018-06-19 15:03:05 +0200133int WebRtcIlbcfix_Encode(IlbcEncoderInstance* iLBCenc_inst,
134 const int16_t* speechIn,
135 size_t len,
136 uint8_t* encoded);
niklase@google.com470e71d2011-07-07 08:21:25 +0000137
Yves Gerey665174f2018-06-19 15:03:05 +0200138/****************************************************************************
139 * WebRtcIlbcfix_DecoderInit(...)
140 *
141 * This function initializes a iLBC instance with either 20 or 30 ms frames
142 * Alternatively the WebRtcIlbcfix_DecoderInit_XXms can be used. Then it's
143 * not needed to specify the frame length with a variable.
144 *
145 * Input:
146 * - IlbcDecoderInstance : iLBC decoder instance
147 * - frameLen : The frame length of the codec 20/30 (ms)
148 *
149 * Return value : 0 - Ok
150 * -1 - Error
151 */
niklase@google.com470e71d2011-07-07 08:21:25 +0000152
Yves Gerey665174f2018-06-19 15:03:05 +0200153int16_t WebRtcIlbcfix_DecoderInit(IlbcDecoderInstance* iLBCdec_inst,
154 int16_t frameLen);
155void WebRtcIlbcfix_DecoderInit20Ms(IlbcDecoderInstance* iLBCdec_inst);
156void WebRtcIlbcfix_Decoderinit30Ms(IlbcDecoderInstance* iLBCdec_inst);
niklase@google.com470e71d2011-07-07 08:21:25 +0000157
Yves Gerey665174f2018-06-19 15:03:05 +0200158/****************************************************************************
159 * WebRtcIlbcfix_Decode(...)
160 *
161 * This function decodes a packet with iLBC frame(s). Output speech length
162 * will be a multiple of 160 or 240 samples ((160 or 240)*frames/packet).
163 *
164 * Input:
165 * - iLBCdec_inst : iLBC instance, i.e. the user that should decode
166 * a packet
167 * - encoded : Encoded iLBC frame(s)
168 * - len : Bytes in encoded vector
169 *
170 * Output:
171 * - decoded : The decoded vector
172 * - speechType : 1 normal, 2 CNG
173 *
174 * Return value : >0 - Samples in decoded vector
175 * -1 - Error
176 */
niklase@google.com470e71d2011-07-07 08:21:25 +0000177
Yves Gerey665174f2018-06-19 15:03:05 +0200178int WebRtcIlbcfix_Decode(IlbcDecoderInstance* iLBCdec_inst,
179 const uint8_t* encoded,
180 size_t len,
181 int16_t* decoded,
182 int16_t* speechType);
183int WebRtcIlbcfix_Decode20Ms(IlbcDecoderInstance* iLBCdec_inst,
184 const uint8_t* encoded,
185 size_t len,
186 int16_t* decoded,
187 int16_t* speechType);
188int WebRtcIlbcfix_Decode30Ms(IlbcDecoderInstance* iLBCdec_inst,
189 const uint8_t* encoded,
190 size_t len,
191 int16_t* decoded,
192 int16_t* speechType);
niklase@google.com470e71d2011-07-07 08:21:25 +0000193
Yves Gerey665174f2018-06-19 15:03:05 +0200194/****************************************************************************
195 * WebRtcIlbcfix_DecodePlc(...)
196 *
197 * This function conducts PLC for iLBC frame(s). Output speech length
198 * will be a multiple of 160 or 240 samples.
199 *
200 * Input:
201 * - iLBCdec_inst : iLBC instance, i.e. the user that should perform
202 * a PLC
203 * - noOfLostFrames : Number of PLC frames to produce
204 *
205 * Output:
206 * - decoded : The "decoded" vector
207 *
208 * Return value : Samples in decoded PLC vector
209 */
niklase@google.com470e71d2011-07-07 08:21:25 +0000210
Yves Gerey665174f2018-06-19 15:03:05 +0200211size_t WebRtcIlbcfix_DecodePlc(IlbcDecoderInstance* iLBCdec_inst,
jmarusic@webrtc.org71b35a42015-02-17 16:02:18 +0000212 int16_t* decoded,
Yves Gerey665174f2018-06-19 15:03:05 +0200213 size_t noOfLostFrames);
niklase@google.com470e71d2011-07-07 08:21:25 +0000214
Yves Gerey665174f2018-06-19 15:03:05 +0200215/****************************************************************************
216 * WebRtcIlbcfix_NetEqPlc(...)
217 *
218 * This function updates the decoder when a packet loss has occured, but it
219 * does not produce any PLC data. Function can be used if another PLC method
220 * is used (i.e NetEq).
221 *
222 * Input:
223 * - iLBCdec_inst : iLBC instance that should be updated
224 * - noOfLostFrames : Number of lost frames
225 *
226 * Output:
227 * - decoded : The "decoded" vector (nothing in this case)
228 *
229 * Return value : Samples in decoded PLC vector
230 */
niklase@google.com470e71d2011-07-07 08:21:25 +0000231
Yves Gerey665174f2018-06-19 15:03:05 +0200232size_t WebRtcIlbcfix_NetEqPlc(IlbcDecoderInstance* iLBCdec_inst,
233 int16_t* decoded,
234 size_t noOfLostFrames);
niklase@google.com470e71d2011-07-07 08:21:25 +0000235
Yves Gerey665174f2018-06-19 15:03:05 +0200236/****************************************************************************
237 * WebRtcIlbcfix_version(...)
238 *
239 * This function returns the version number of iLBC
240 *
241 * Output:
242 * - version : Version number of iLBC (maximum 20 char)
243 */
niklase@google.com470e71d2011-07-07 08:21:25 +0000244
Yves Gerey665174f2018-06-19 15:03:05 +0200245void WebRtcIlbcfix_version(char* version);
niklase@google.com470e71d2011-07-07 08:21:25 +0000246
247#ifdef __cplusplus
248}
249#endif
250
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200251#endif // MODULES_AUDIO_CODING_CODECS_ILBC_ILBC_H_