OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 /****************************************************************** | 11 /****************************************************************** |
12 | 12 |
13 iLBC Speech Coder ANSI-C Source Code | 13 iLBC Speech Coder ANSI-C Source Code |
14 | 14 |
15 iLBCInterface.c | 15 iLBCInterface.c |
16 | 16 |
17 ******************************************************************/ | 17 ******************************************************************/ |
18 | 18 |
19 #include "ilbc.h" | 19 #include "ilbc.h" |
20 #include "defines.h" | 20 #include "defines.h" |
21 #include "init_encode.h" | 21 #include "init_encode.h" |
22 #include "encode.h" | 22 #include "encode.h" |
23 #include "init_decode.h" | 23 #include "init_decode.h" |
24 #include "decode.h" | 24 #include "decode.h" |
| 25 #include "webrtc/base/checks.h" |
25 #include <stdlib.h> | 26 #include <stdlib.h> |
26 | 27 |
27 int16_t WebRtcIlbcfix_EncoderAssign(IlbcEncoderInstance** iLBC_encinst, | 28 int16_t WebRtcIlbcfix_EncoderAssign(IlbcEncoderInstance** iLBC_encinst, |
28 int16_t* ILBCENC_inst_Addr, | 29 int16_t* ILBCENC_inst_Addr, |
29 int16_t* size) { | 30 int16_t* size) { |
30 *iLBC_encinst=(IlbcEncoderInstance*)ILBCENC_inst_Addr; | 31 *iLBC_encinst=(IlbcEncoderInstance*)ILBCENC_inst_Addr; |
31 *size=sizeof(IlbcEncoder)/sizeof(int16_t); | 32 *size=sizeof(IlbcEncoder)/sizeof(int16_t); |
32 if (*iLBC_encinst!=NULL) { | 33 if (*iLBC_encinst!=NULL) { |
33 return(0); | 34 return(0); |
34 } else { | 35 } else { |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 ((IlbcDecoder*)iLBCdec_inst), 20, | 174 ((IlbcDecoder*)iLBCdec_inst), 20, |
174 ((IlbcDecoder*)iLBCdec_inst)->use_enhancer); | 175 ((IlbcDecoder*)iLBCdec_inst)->use_enhancer); |
175 } else { | 176 } else { |
176 /* Unsupported frame length */ | 177 /* Unsupported frame length */ |
177 return(-1); | 178 return(-1); |
178 } | 179 } |
179 } | 180 } |
180 } | 181 } |
181 | 182 |
182 while ((i*((IlbcDecoder*)iLBCdec_inst)->no_of_bytes)<len) { | 183 while ((i*((IlbcDecoder*)iLBCdec_inst)->no_of_bytes)<len) { |
183 WebRtcIlbcfix_DecodeImpl( | 184 if (WebRtcIlbcfix_DecodeImpl( |
184 &decoded[i * ((IlbcDecoder*)iLBCdec_inst)->blockl], | 185 &decoded[i * ((IlbcDecoder*)iLBCdec_inst)->blockl], |
185 (const uint16_t*)&encoded | 186 (const uint16_t*)&encoded |
186 [2 * i * ((IlbcDecoder*)iLBCdec_inst)->no_of_words], | 187 [2 * i * ((IlbcDecoder*)iLBCdec_inst)->no_of_words], |
187 (IlbcDecoder*)iLBCdec_inst, 1); | 188 (IlbcDecoder*)iLBCdec_inst, 1) == -1) |
| 189 return -1; |
188 i++; | 190 i++; |
189 } | 191 } |
190 /* iLBC does not support VAD/CNG yet */ | 192 /* iLBC does not support VAD/CNG yet */ |
191 *speechType=1; | 193 *speechType=1; |
192 return (int)(i*((IlbcDecoder*)iLBCdec_inst)->blockl); | 194 return (int)(i*((IlbcDecoder*)iLBCdec_inst)->blockl); |
193 } | 195 } |
194 | 196 |
195 int WebRtcIlbcfix_Decode20Ms(IlbcDecoderInstance* iLBCdec_inst, | 197 int WebRtcIlbcfix_Decode20Ms(IlbcDecoderInstance* iLBCdec_inst, |
196 const uint8_t* encoded, | 198 const uint8_t* encoded, |
197 size_t len, | 199 size_t len, |
198 int16_t* decoded, | 200 int16_t* decoded, |
199 int16_t* speechType) | 201 int16_t* speechType) |
200 { | 202 { |
201 size_t i=0; | 203 size_t i=0; |
202 if ((len==((IlbcDecoder*)iLBCdec_inst)->no_of_bytes)|| | 204 if ((len==((IlbcDecoder*)iLBCdec_inst)->no_of_bytes)|| |
203 (len==2*((IlbcDecoder*)iLBCdec_inst)->no_of_bytes)|| | 205 (len==2*((IlbcDecoder*)iLBCdec_inst)->no_of_bytes)|| |
204 (len==3*((IlbcDecoder*)iLBCdec_inst)->no_of_bytes)) { | 206 (len==3*((IlbcDecoder*)iLBCdec_inst)->no_of_bytes)) { |
205 /* ok, do nothing */ | 207 /* ok, do nothing */ |
206 } else { | 208 } else { |
207 return(-1); | 209 return(-1); |
208 } | 210 } |
209 | 211 |
210 while ((i*((IlbcDecoder*)iLBCdec_inst)->no_of_bytes)<len) { | 212 while ((i*((IlbcDecoder*)iLBCdec_inst)->no_of_bytes)<len) { |
211 WebRtcIlbcfix_DecodeImpl( | 213 if (!WebRtcIlbcfix_DecodeImpl( |
212 &decoded[i * ((IlbcDecoder*)iLBCdec_inst)->blockl], | 214 &decoded[i * ((IlbcDecoder*)iLBCdec_inst)->blockl], |
213 (const uint16_t*)&encoded | 215 (const uint16_t*)&encoded |
214 [2 * i * ((IlbcDecoder*)iLBCdec_inst)->no_of_words], | 216 [2 * i * ((IlbcDecoder*)iLBCdec_inst)->no_of_words], |
215 (IlbcDecoder*)iLBCdec_inst, 1); | 217 (IlbcDecoder*)iLBCdec_inst, 1)) |
| 218 return -1; |
216 i++; | 219 i++; |
217 } | 220 } |
218 /* iLBC does not support VAD/CNG yet */ | 221 /* iLBC does not support VAD/CNG yet */ |
219 *speechType=1; | 222 *speechType=1; |
220 return (int)(i*((IlbcDecoder*)iLBCdec_inst)->blockl); | 223 return (int)(i*((IlbcDecoder*)iLBCdec_inst)->blockl); |
221 } | 224 } |
222 | 225 |
223 int WebRtcIlbcfix_Decode30Ms(IlbcDecoderInstance* iLBCdec_inst, | 226 int WebRtcIlbcfix_Decode30Ms(IlbcDecoderInstance* iLBCdec_inst, |
224 const uint8_t* encoded, | 227 const uint8_t* encoded, |
225 size_t len, | 228 size_t len, |
226 int16_t* decoded, | 229 int16_t* decoded, |
227 int16_t* speechType) | 230 int16_t* speechType) |
228 { | 231 { |
229 size_t i=0; | 232 size_t i=0; |
230 if ((len==((IlbcDecoder*)iLBCdec_inst)->no_of_bytes)|| | 233 if ((len==((IlbcDecoder*)iLBCdec_inst)->no_of_bytes)|| |
231 (len==2*((IlbcDecoder*)iLBCdec_inst)->no_of_bytes)|| | 234 (len==2*((IlbcDecoder*)iLBCdec_inst)->no_of_bytes)|| |
232 (len==3*((IlbcDecoder*)iLBCdec_inst)->no_of_bytes)) { | 235 (len==3*((IlbcDecoder*)iLBCdec_inst)->no_of_bytes)) { |
233 /* ok, do nothing */ | 236 /* ok, do nothing */ |
234 } else { | 237 } else { |
235 return(-1); | 238 return(-1); |
236 } | 239 } |
237 | 240 |
238 while ((i*((IlbcDecoder*)iLBCdec_inst)->no_of_bytes)<len) { | 241 while ((i*((IlbcDecoder*)iLBCdec_inst)->no_of_bytes)<len) { |
239 WebRtcIlbcfix_DecodeImpl( | 242 if (!WebRtcIlbcfix_DecodeImpl( |
240 &decoded[i * ((IlbcDecoder*)iLBCdec_inst)->blockl], | 243 &decoded[i * ((IlbcDecoder*)iLBCdec_inst)->blockl], |
241 (const uint16_t*)&encoded | 244 (const uint16_t*)&encoded |
242 [2 * i * ((IlbcDecoder*)iLBCdec_inst)->no_of_words], | 245 [2 * i * ((IlbcDecoder*)iLBCdec_inst)->no_of_words], |
243 (IlbcDecoder*)iLBCdec_inst, 1); | 246 (IlbcDecoder*)iLBCdec_inst, 1)) |
| 247 return -1; |
244 i++; | 248 i++; |
245 } | 249 } |
246 /* iLBC does not support VAD/CNG yet */ | 250 /* iLBC does not support VAD/CNG yet */ |
247 *speechType=1; | 251 *speechType=1; |
248 return (int)(i*((IlbcDecoder*)iLBCdec_inst)->blockl); | 252 return (int)(i*((IlbcDecoder*)iLBCdec_inst)->blockl); |
249 } | 253 } |
250 | 254 |
251 size_t WebRtcIlbcfix_DecodePlc(IlbcDecoderInstance* iLBCdec_inst, | 255 size_t WebRtcIlbcfix_DecodePlc(IlbcDecoderInstance* iLBCdec_inst, |
252 int16_t* decoded, | 256 int16_t* decoded, |
253 size_t noOfLostFrames) { | 257 size_t noOfLostFrames) { |
254 size_t i; | 258 size_t i; |
255 uint16_t dummy; | 259 uint16_t dummy; |
256 | 260 |
257 for (i=0;i<noOfLostFrames;i++) { | 261 for (i=0;i<noOfLostFrames;i++) { |
258 /* call decoder */ | 262 // PLC decoding shouldn't fail, because there is no external input data |
259 WebRtcIlbcfix_DecodeImpl( | 263 // that can be bad. |
| 264 RTC_CHECK(WebRtcIlbcfix_DecodeImpl( |
260 &decoded[i * ((IlbcDecoder*)iLBCdec_inst)->blockl], &dummy, | 265 &decoded[i * ((IlbcDecoder*)iLBCdec_inst)->blockl], &dummy, |
261 (IlbcDecoder*)iLBCdec_inst, 0); | 266 (IlbcDecoder*)iLBCdec_inst, 0)); |
262 } | 267 } |
263 return (noOfLostFrames*((IlbcDecoder*)iLBCdec_inst)->blockl); | 268 return (noOfLostFrames*((IlbcDecoder*)iLBCdec_inst)->blockl); |
264 } | 269 } |
265 | 270 |
266 size_t WebRtcIlbcfix_NetEqPlc(IlbcDecoderInstance* iLBCdec_inst, | 271 size_t WebRtcIlbcfix_NetEqPlc(IlbcDecoderInstance* iLBCdec_inst, |
267 int16_t* decoded, | 272 int16_t* decoded, |
268 size_t noOfLostFrames) { | 273 size_t noOfLostFrames) { |
269 /* Two input parameters not used, but needed for function pointers in NetEQ */ | 274 /* Two input parameters not used, but needed for function pointers in NetEQ */ |
270 (void)(decoded = NULL); | 275 (void)(decoded = NULL); |
271 (void)(noOfLostFrames = 0); | 276 (void)(noOfLostFrames = 0); |
272 | 277 |
273 WebRtcSpl_MemSetW16(((IlbcDecoder*)iLBCdec_inst)->enh_buf, 0, ENH_BUFL); | 278 WebRtcSpl_MemSetW16(((IlbcDecoder*)iLBCdec_inst)->enh_buf, 0, ENH_BUFL); |
274 ((IlbcDecoder*)iLBCdec_inst)->prev_enh_pl = 2; | 279 ((IlbcDecoder*)iLBCdec_inst)->prev_enh_pl = 2; |
275 | 280 |
276 return (0); | 281 return (0); |
277 } | 282 } |
278 | 283 |
279 void WebRtcIlbcfix_version(char *version) | 284 void WebRtcIlbcfix_version(char *version) |
280 { | 285 { |
281 strcpy((char*)version, "1.1.1"); | 286 strcpy((char*)version, "1.1.1"); |
282 } | 287 } |
OLD | NEW |