2 * iLBC Plugin codec for OpenH323/OPAL
4 * Copyright (C) 2004 Post Increment, All Rights Reserved
6 * The contents of this file are subject to the Mozilla Public License
7 * Version 1.0 (the "License"); you may not use this file except in
8 * compliance with the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS"
12 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
13 * the License for the specific language governing rights and limitations
16 * The Original Code is Open H323 Library.
18 * The Initial Developer of the Original Code is Post Increment
20 * Contributor(s): ______________________________________.
23 * Revision 1.5 2007/09/05 07:49:07 csoutheren
24 * Set output buffers correctly and check input buffers correctly
26 * Revision 1.4 2007/09/05 06:22:32 rjongbloed
27 * Update iLBC plug in to latest API so get FMTP parameter for mode.
29 * Revision 1.3 2006/08/28 01:21:54 csoutheren
32 * Revision 1.2 2006/07/31 09:09:19 csoutheren
33 * Checkin of validated codec used during development
35 * Revision 1.1.2.2 2006/04/08 06:09:09 rjongbloed
36 * Fix correct directory for OPAL headers
38 * Revision 1.1.2.1 2006/04/06 01:20:05 csoutheren
39 * Ported audio codec plugins from OpenH323 to OPAL
41 * Revision 1.8 2005/07/15 10:09:00 rogerhardiman
42 * Fix SF bug 1237507. Windows uses malloc.h. Linux and FreeBSD uses stdlib.h
43 * Wrap #include with _WIN32 to be consistent with malloc.h in pwlib.
45 * Revision 1.7 2004/12/20 23:18:01 csoutheren
46 * Added stdlib.h to all plugins to keep FreeBSD happy
47 * Thanks to Kevin Oberman
49 * Revision 1.6 2004/11/29 06:29:58 csoutheren
50 * Added flag to reuse RTP payload types rather than allocaing new ones for each codec
53 * Revision 1.5 2004/06/17 22:04:57 csoutheren
54 * Changed codec version number to be sensible rather than string $Ver$
56 * Revision 1.4 2004/04/09 12:24:19 csoutheren
57 * Renamed h323plugin.h to opalplugin.h, and modified everything else
60 * Revision 1.3 2004/04/04 12:43:59 csoutheren
61 * Added file headers and fixd formatting
65 #include <codec/opalplugin.h>
69 #define _CRT_SECURE_NO_DEPRECATE
71 #define STRCMPI _strcmpi
73 #define STRCMPI strcasecmp
76 #include "iLBC/iLBC_encode.h"
77 #include "iLBC/iLBC_decode.h"
78 #include "iLBC/iLBC_define.h"
80 #define SPEED_30MS NO_OF_BYTES_30MS*8*8000/BLOCKL_30MS
81 #define SPEED_20MS NO_OF_BYTES_20MS*8*8000/BLOCKL_20MS
84 /////////////////////////////////////////////////////////////////////////////
86 static void * create_encoder(const struct PluginCodec_Definition
* codec
)
88 struct iLBC_Enc_Inst_t_
* context
= (struct iLBC_Enc_Inst_t_
*)malloc((unsigned)sizeof(struct iLBC_Enc_Inst_t_
));
89 initEncode(context
, (codec
->bitsPerSec
) == SPEED_30MS
? 30 : 20);
93 static void * create_decoder(const struct PluginCodec_Definition
* codec
)
95 struct iLBC_Dec_Inst_t_
* context
= (struct iLBC_Dec_Inst_t_
*)malloc((unsigned)sizeof(struct iLBC_Dec_Inst_t_
));
96 initDecode(context
, (codec
->bitsPerSec
) == SPEED_30MS
? 30 : 20, 0);
100 static void destroy_context(const struct PluginCodec_Definition
* codec
, void * context
)
105 static int codec_encoder(const struct PluginCodec_Definition
* codec
,
113 float block
[BLOCKL_MAX
];
116 struct iLBC_Enc_Inst_t_
* encoder
= (struct iLBC_Enc_Inst_t_
*)context
;
117 const short * sampleBuffer
= (const short *)from
;
119 if ((*fromLen
)/2 < (unsigned)encoder
->blockl
)
122 /* convert signal to float */
123 for (i
= 0; i
< encoder
->blockl
; i
++)
124 block
[i
] = (float)sampleBuffer
[i
];
126 /* do the actual encoding */
127 iLBC_encode(to
, block
, encoder
);
130 *toLen
= encoder
->no_of_bytes
;
135 static int codec_decoder(const struct PluginCodec_Definition
* codec
,
144 float block
[BLOCKL_MAX
];
146 struct iLBC_Dec_Inst_t_
* decoder
= (struct iLBC_Dec_Inst_t_
*)context
;
147 short * sampleBuffer
= (short *)to
;
149 if (*fromLen
< (unsigned)decoder
->no_of_bytes
)
152 /* do actual decoding of block */
153 iLBC_decode(block
, (unsigned char *)from
, decoder
, 1);
155 if (*toLen
< (unsigned)decoder
->blockl
*2)
158 /* convert to short */
159 for (i
= 0; i
< decoder
->blockl
; i
++) {
160 float tmp
= block
[i
];
161 if (tmp
< MIN_SAMPLE
)
163 else if (tmp
> MAX_SAMPLE
)
165 sampleBuffer
[i
] = (short)tmp
;
168 *toLen
= decoder
->blockl
*2;
173 static int valid_for_h323(
174 const struct PluginCodec_Definition
* codec
,
180 if (parmLen
== NULL
|| parm
== NULL
|| *parmLen
!= sizeof(char *))
183 return (STRCMPI((const char *)parm
, "h.323") == 0 ||
184 STRCMPI((const char *)parm
, "h323") == 0) ? 1 : 0;
188 static int valid_for_sip_or_h323(
189 const struct PluginCodec_Definition
* codec
,
195 if (parmLen
== NULL
|| parm
== NULL
|| *parmLen
!= sizeof(char *))
198 return (STRCMPI((const char *)parm
, "sip") == 0 ||
199 STRCMPI((const char *)parm
, "h.323") == 0 ||
200 STRCMPI((const char *)parm
, "h323") == 0) ? 1 : 0;
203 static struct PluginCodec_Option
const PreferredMode
=
204 { PluginCodec_IntegerOption
, "Preferred Mode", 0, PluginCodec_NoMerge
, "30", "mode", NULL
, 0, "0", "30" };
206 static struct PluginCodec_Option
const * const OptionTable
[] = {
211 static int get_codec_options(const struct PluginCodec_Definition
* defn
,
217 if (parm
== NULL
|| parmLen
== NULL
|| *parmLen
!= sizeof(struct PluginCodec_Option
**))
220 *(struct PluginCodec_Option
const * const * *)parm
= OptionTable
;
225 static int set_codec_options(const struct PluginCodec_Definition
* defn
,
231 const char * const * option
;
232 struct iLBC_Enc_Inst_t_
* encoder
;
234 if (context
== NULL
|| parm
== NULL
|| parmLen
== NULL
|| *parmLen
!= sizeof(const char **))
237 encoder
= (struct iLBC_Enc_Inst_t_
*)context
;
239 for (option
= (const char * const *)parm
; *option
!= NULL
; option
+= 2) {
240 if (STRCMPI(option
[0], "Preferred Mode") == 0)
241 initEncode(context
, atoi(option
[1]) == SPEED_30MS
? 30 : 20);
248 static struct PluginCodec_ControlDefn h323CoderControls
[] = {
249 { "valid_for_protocol", valid_for_h323
},
250 { "get_codec_options", get_codec_options
},
251 { "set_codec_options", set_codec_options
},
255 static struct PluginCodec_ControlDefn h323AndSIPCoderControls
[] = {
256 { "valid_for_protocol", valid_for_sip_or_h323
},
257 { "get_codec_options", get_codec_options
},
258 { "set_codec_options", set_codec_options
},
263 /////////////////////////////////////////////////////////////////////////////
265 static struct PluginCodec_information licenseInfo
= {
266 //1073187324, // timestamp = Sun 04 Jan 2004 03:35:24 AM UTC =
267 1101695533, // Mon 29 Nov 2004 12:32:13 PM EST
269 "Craig Southeren, Post Increment", // source code author
270 "1.1", // source code version
271 "craigs@postincrement.com", // source code email
272 "http://www.postincrement.com", // source code URL
273 "Copyright (C) 2004 by Post Increment, All Rights Reserved", // source code copyright
274 "MPL 1.0", // source code license
275 PluginCodec_License_MPL
, // source code license
277 "iLBC (internet Low Bitrate Codec)", // codec description
278 "Global IP Sound, Inc.", // codec author
279 NULL
, // codec version
280 "info@globalipsound.com", // codec email
281 "http://www.ilbcfreeware.org", // codec URL
282 "Global IP Sound AB. Portions Copyright (C) 1999-2002, All Rights Reserved", // codec copyright information
283 "Global IP Sound iLBC Freeware Public License, IETF Version, Limited Commercial Use", // codec license
284 PluginCodec_License_Freeware
// codec license code
287 static const char L16Desc
[] = { "L16" };
289 static const char iLBC13k3
[] = { "iLBC-13k3" };
290 static const char iLBC15k2
[] = { "iLBC-15k2" };
292 static const char sdpILBC
[] = { "iLBC" };
294 #define EQUIVALENCE_COUNTRY_CODE 9
295 #define EQUIVALENCE_EXTENSION_CODE 0
296 #define EQUIVALENCE_MANUFACTURER_CODE 61
298 static struct PluginCodec_H323NonStandardCodecData ilbc13k3Cap
=
301 EQUIVALENCE_COUNTRY_CODE
,
302 EQUIVALENCE_EXTENSION_CODE
,
303 EQUIVALENCE_MANUFACTURER_CODE
,
304 iLBC13k3
, sizeof(iLBC13k3
)-1,
308 static struct PluginCodec_H323NonStandardCodecData ilbc15k2Cap
=
311 EQUIVALENCE_COUNTRY_CODE
,
312 EQUIVALENCE_EXTENSION_CODE
,
313 EQUIVALENCE_MANUFACTURER_CODE
,
314 iLBC15k2
, sizeof(iLBC15k2
)-1,
318 static struct PluginCodec_Definition iLBCCodecDefn
[4] = {
322 PLUGIN_CODEC_VERSION_OPTIONS
, // codec API version
323 &licenseInfo
, // license information
325 PluginCodec_MediaTypeAudio
| // audio codec
326 PluginCodec_InputTypeRaw
| // raw input data
327 PluginCodec_OutputTypeRaw
| // raw output data
328 PluginCodec_RTPTypeShared
| // share RTP code
329 PluginCodec_RTPTypeDynamic
, // dynamic RTP type
331 iLBC13k3
, // text decription
332 L16Desc
, // source format
333 iLBC13k3
, // destination format
335 (void *)NULL
, // user data
337 8000, // samples per second
338 SPEED_30MS
, // raw bits per second
339 30000, // nanoseconds per frame
340 BLOCKL_30MS
, // samples per frame
341 NO_OF_BYTES_30MS
, // bytes per frame
342 1, // recommended number of frames per packet
343 1, // maximum number of frames per packe
344 0, // IANA RTP payload code
345 sdpILBC
, // RTP payload name
347 create_encoder
, // create codec function
348 destroy_context
, // destroy codec
349 codec_encoder
, // encode/decode
350 h323AndSIPCoderControls
, // codec controls
352 PluginCodec_H323Codec_nonStandard
, // h323CapabilityType
353 &ilbc13k3Cap
// h323CapabilityData
358 PLUGIN_CODEC_VERSION_OPTIONS
, // codec API version
359 &licenseInfo
, // license information
361 PluginCodec_MediaTypeAudio
| // audio codec
362 PluginCodec_InputTypeRaw
| // raw input data
363 PluginCodec_OutputTypeRaw
| // raw output data
364 PluginCodec_RTPTypeShared
| // share RTP code
365 PluginCodec_RTPTypeDynamic
, // dynamic RTP type
367 iLBC13k3
, // text decription
368 iLBC13k3
, // source format
369 L16Desc
, // destination format
371 (const void *)NULL
, // user data
373 8000, // samples per second
374 SPEED_30MS
, // raw bits per second
375 30000, // nanoseconds per frame
376 BLOCKL_30MS
, // samples per frame
377 NO_OF_BYTES_30MS
, // bytes per frame
378 1, // recommended number of frames per packet
379 1, // maximum number of frames per packe
380 0, // IANA RTP payload code
381 sdpILBC
, // RTP payload name
383 create_decoder
, // create codec function
384 destroy_context
, // destroy codec
385 codec_decoder
, // encode/decode
386 h323AndSIPCoderControls
, // codec controls
388 PluginCodec_H323Codec_nonStandard
, // h323CapabilityType
389 &ilbc13k3Cap
// h323CapabilityData
394 PLUGIN_CODEC_VERSION_OPTIONS
, // codec API version
395 &licenseInfo
, // license information
397 PluginCodec_MediaTypeAudio
| // audio codec
398 PluginCodec_InputTypeRaw
| // raw input data
399 PluginCodec_OutputTypeRaw
| // raw output data
400 PluginCodec_RTPTypeShared
| // share RTP code
401 PluginCodec_RTPTypeDynamic
, // dynamic RTP type
403 iLBC15k2
, // text decription
404 L16Desc
, // source format
405 iLBC15k2
, // destination format
407 (void *)NULL
, // user data
409 8000, // samples per second
410 SPEED_20MS
, // raw bits per second
411 20000, // nanoseconds per frame
412 BLOCKL_20MS
, // samples per frame
413 NO_OF_BYTES_20MS
, // bytes per frame
414 1, // recommended number of frames per packet
415 1, // maximum number of frames per packe
416 0, // IANA RTP payload code
417 sdpILBC
, // RTP payload name
419 create_encoder
, // create codec function
420 destroy_context
, // destroy codec
421 codec_encoder
, // encode/decode
422 h323CoderControls
, // codec controls
424 PluginCodec_H323Codec_nonStandard
, // h323CapabilityType
425 &ilbc15k2Cap
// h323CapabilityData
430 PLUGIN_CODEC_VERSION_OPTIONS
, // codec API version
431 &licenseInfo
, // license information
433 PluginCodec_MediaTypeAudio
| // audio codec
434 PluginCodec_InputTypeRaw
| // raw input data
435 PluginCodec_OutputTypeRaw
| // raw output data
436 PluginCodec_RTPTypeShared
| // share RTP code
437 PluginCodec_RTPTypeDynamic
, // dynamic RTP type
439 iLBC15k2
, // text decription
440 iLBC15k2
, // source format
441 L16Desc
, // destination format
443 (void *)NULL
, // user data
445 8000, // samples per second
446 SPEED_20MS
, // raw bits per second
447 20000, // nanoseconds per frame
448 BLOCKL_20MS
, // samples per frame
449 NO_OF_BYTES_20MS
, // bytes per frame
450 1, // recommended number of frames per packet
451 1, // maximum number of frames per packe
452 0, // IANA RTP payload code
453 sdpILBC
, // RTP payload name
455 create_decoder
, // create codec function
456 destroy_context
, // destroy codec
457 codec_decoder
, // encode/decode
458 h323CoderControls
, // codec controls
460 PluginCodec_H323Codec_nonStandard
, // h323CapabilityType
461 &ilbc15k2Cap
// h323CapabilityData
466 /////////////////////////////////////////////////////////////////////////////
468 PLUGIN_CODEC_IMPLEMENT_ALL("iLBC", iLBCCodecDefn
, PLUGIN_CODEC_VERSION_OPTIONS
)