2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
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.
11 #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_FIX_INTERFACE_ISACFIX_H_
12 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_FIX_INTERFACE_ISACFIX_H_
15 * Define the fixpoint numeric formats
17 #include "webrtc/typedefs.h"
24 #if defined(__cplusplus)
29 /**************************************************************************
30 * WebRtcIsacfix_AssignSize(...)
32 * Functions used when malloc is not allowed
33 * Output the number of bytes needed to allocate for iSAC struct.
37 int16_t WebRtcIsacfix_AssignSize(int *sizeinbytes);
39 /**************************************************************************
40 * WebRtcIsacfix_Assign(...)
42 * Functions used when malloc is not allowed, it
43 * places a struct at the given address.
46 * - *ISAC_main_inst : a pointer to the coder instance.
47 * - ISACFIX_inst_Addr : address of the memory where a space is
50 * Return value : 0 - Ok
54 int16_t WebRtcIsacfix_Assign(ISACFIX_MainStruct **inst,
55 void *ISACFIX_inst_Addr);
57 /****************************************************************************
58 * WebRtcIsacfix_Create(...)
60 * This function creates an ISAC instance, which will contain the state
61 * information for one coding/decoding channel.
64 * - *ISAC_main_inst : a pointer to the coder instance.
66 * Return value : 0 - Ok
70 int16_t WebRtcIsacfix_Create(ISACFIX_MainStruct **ISAC_main_inst);
73 /****************************************************************************
74 * WebRtcIsacfix_Free(...)
76 * This function frees the ISAC instance created at the beginning.
79 * - ISAC_main_inst : a ISAC instance.
81 * Return value : 0 - Ok
85 int16_t WebRtcIsacfix_Free(ISACFIX_MainStruct *ISAC_main_inst);
88 /****************************************************************************
89 * WebRtcIsacfix_EncoderInit(...)
91 * This function initializes an ISAC instance prior to the encoder calls.
94 * - ISAC_main_inst : ISAC instance.
95 * - CodingMode : 0 - Bit rate and frame length are automatically
96 * adjusted to available bandwidth on
97 * transmission channel.
98 * 1 - User sets a frame length and a target bit
99 * rate which is taken as the maximum short-term
102 * Return value : 0 - Ok
106 int16_t WebRtcIsacfix_EncoderInit(ISACFIX_MainStruct *ISAC_main_inst,
110 /****************************************************************************
111 * WebRtcIsacfix_Encode(...)
113 * This function encodes 10ms frame(s) and inserts it into a package.
114 * Input speech length has to be 160 samples (10ms). The encoder buffers those
115 * 10ms frames until it reaches the chosen Framesize (480 or 960 samples
116 * corresponding to 30 or 60 ms frames), and then proceeds to the encoding.
119 * - ISAC_main_inst : ISAC instance.
120 * - speechIn : input speech vector.
123 * - encoded : the encoded data vector
125 * Return value : >0 - Length (in bytes) of coded data
126 * 0 - The buffer didn't reach the chosen framesize
127 * so it keeps buffering speech samples.
131 int16_t WebRtcIsacfix_Encode(ISACFIX_MainStruct *ISAC_main_inst,
132 const int16_t *speechIn,
137 /****************************************************************************
138 * WebRtcIsacfix_EncodeNb(...)
140 * This function encodes 10ms narrow band (8 kHz sampling) frame(s) and inserts
141 * it into a package. Input speech length has to be 80 samples (10ms). The encoder
142 * interpolates into wide-band (16 kHz sampling) buffers those
143 * 10ms frames until it reaches the chosen Framesize (480 or 960 wide-band samples
144 * corresponding to 30 or 60 ms frames), and then proceeds to the encoding.
146 * The function is enabled if WEBRTC_ISAC_FIX_NB_CALLS_ENABLED is defined
149 * - ISAC_main_inst : ISAC instance.
150 * - speechIn : input speech vector.
153 * - encoded : the encoded data vector
155 * Return value : >0 - Length (in bytes) of coded data
156 * 0 - The buffer didn't reach the chosen framesize
157 * so it keeps buffering speech samples.
162 #ifdef WEBRTC_ISAC_FIX_NB_CALLS_ENABLED
163 int16_t WebRtcIsacfix_EncodeNb(ISACFIX_MainStruct *ISAC_main_inst,
164 const int16_t *speechIn,
166 #endif // WEBRTC_ISAC_FIX_NB_CALLS_ENABLED
170 /****************************************************************************
171 * WebRtcIsacfix_DecoderInit(...)
173 * This function initializes an ISAC instance prior to the decoder calls.
176 * - ISAC_main_inst : ISAC instance.
183 int16_t WebRtcIsacfix_DecoderInit(ISACFIX_MainStruct *ISAC_main_inst);
186 /****************************************************************************
187 * WebRtcIsacfix_UpdateBwEstimate1(...)
189 * This function updates the estimate of the bandwidth.
192 * - ISAC_main_inst : ISAC instance.
193 * - encoded : encoded ISAC frame(s).
194 * - packet_size : size of the packet.
195 * - rtp_seq_number : the RTP number of the packet.
196 * - arr_ts : the arrival time of the packet (from NetEq)
199 * Return value : 0 - Ok
203 int16_t WebRtcIsacfix_UpdateBwEstimate1(ISACFIX_MainStruct *ISAC_main_inst,
204 const uint8_t* encoded,
206 uint16_t rtp_seq_number,
209 /****************************************************************************
210 * WebRtcIsacfix_UpdateBwEstimate(...)
212 * This function updates the estimate of the bandwidth.
215 * - ISAC_main_inst : ISAC instance.
216 * - encoded : encoded ISAC frame(s).
217 * - packet_size : size of the packet.
218 * - rtp_seq_number : the RTP number of the packet.
219 * - send_ts : the send time of the packet from RTP header,
221 * - arr_ts : the arrival time of the packet (from NetEq)
224 * Return value : 0 - Ok
228 int16_t WebRtcIsacfix_UpdateBwEstimate(ISACFIX_MainStruct *ISAC_main_inst,
229 const uint8_t* encoded,
231 uint16_t rtp_seq_number,
235 /****************************************************************************
236 * WebRtcIsacfix_Decode(...)
238 * This function decodes an ISAC frame. Output speech length
239 * will be a multiple of 480 samples: 480 or 960 samples,
240 * depending on the framesize (30 or 60 ms).
243 * - ISAC_main_inst : ISAC instance.
244 * - encoded : encoded ISAC frame(s)
245 * - len : bytes in encoded vector
248 * - decoded : The decoded vector
250 * Return value : >0 - number of samples in decoded vector
254 int16_t WebRtcIsacfix_Decode(ISACFIX_MainStruct *ISAC_main_inst,
255 const uint8_t* encoded,
258 int16_t *speechType);
261 /****************************************************************************
262 * WebRtcIsacfix_DecodeNb(...)
264 * This function decodes a ISAC frame in narrow-band (8 kHz sampling).
265 * Output speech length will be a multiple of 240 samples: 240 or 480 samples,
266 * depending on the framesize (30 or 60 ms).
268 * The function is enabled if WEBRTC_ISAC_FIX_NB_CALLS_ENABLED is defined
271 * - ISAC_main_inst : ISAC instance.
272 * - encoded : encoded ISAC frame(s)
273 * - len : bytes in encoded vector
276 * - decoded : The decoded vector
278 * Return value : >0 - number of samples in decoded vector
282 #ifdef WEBRTC_ISAC_FIX_NB_CALLS_ENABLED
283 int16_t WebRtcIsacfix_DecodeNb(ISACFIX_MainStruct *ISAC_main_inst,
284 const uint16_t *encoded,
287 int16_t *speechType);
288 #endif // WEBRTC_ISAC_FIX_NB_CALLS_ENABLED
291 /****************************************************************************
292 * WebRtcIsacfix_DecodePlcNb(...)
294 * This function conducts PLC for ISAC frame(s) in narrow-band (8kHz sampling).
295 * Output speech length will be "240*noOfLostFrames" samples
296 * that equevalent of "30*noOfLostFrames" millisecond.
298 * The function is enabled if WEBRTC_ISAC_FIX_NB_CALLS_ENABLED is defined
301 * - ISAC_main_inst : ISAC instance.
302 * - noOfLostFrames : Number of PLC frames (240 sample=30ms) to produce
303 * NOTE! Maximum number is 2 (480 samples = 60ms)
306 * - decoded : The decoded vector
308 * Return value : >0 - number of samples in decoded PLC vector
312 #ifdef WEBRTC_ISAC_FIX_NB_CALLS_ENABLED
313 int16_t WebRtcIsacfix_DecodePlcNb(ISACFIX_MainStruct *ISAC_main_inst,
315 int16_t noOfLostFrames);
316 #endif // WEBRTC_ISAC_FIX_NB_CALLS_ENABLED
321 /****************************************************************************
322 * WebRtcIsacfix_DecodePlc(...)
324 * This function conducts PLC for ISAC frame(s) in wide-band (16kHz sampling).
325 * Output speech length will be "480*noOfLostFrames" samples
326 * that is equevalent of "30*noOfLostFrames" millisecond.
329 * - ISAC_main_inst : ISAC instance.
330 * - noOfLostFrames : Number of PLC frames (480sample = 30ms)
332 * NOTE! Maximum number is 2 (960 samples = 60ms)
335 * - decoded : The decoded vector
337 * Return value : >0 - number of samples in decoded PLC vector
341 int16_t WebRtcIsacfix_DecodePlc(ISACFIX_MainStruct *ISAC_main_inst,
343 int16_t noOfLostFrames );
346 /****************************************************************************
347 * WebRtcIsacfix_ReadFrameLen(...)
349 * This function returns the length of the frame represented in the packet.
352 * - encoded : Encoded bitstream
353 * - encoded_len_bytes : Length of the bitstream in bytes.
356 * - frameLength : Length of frame in packet (in samples)
360 int16_t WebRtcIsacfix_ReadFrameLen(const uint8_t* encoded,
361 int encoded_len_bytes,
362 int16_t* frameLength);
364 /****************************************************************************
365 * WebRtcIsacfix_Control(...)
367 * This function sets the limit on the short-term average bit rate and the
368 * frame length. Should be used only in Instantaneous mode.
371 * - ISAC_main_inst : ISAC instance.
372 * - rate : limit on the short-term average bit rate,
373 * in bits/second (between 10000 and 32000)
374 * - framesize : number of milliseconds per frame (30 or 60)
376 * Return value : 0 - ok
380 int16_t WebRtcIsacfix_Control(ISACFIX_MainStruct *ISAC_main_inst,
386 /****************************************************************************
387 * WebRtcIsacfix_ControlBwe(...)
389 * This function sets the initial values of bottleneck and frame-size if
390 * iSAC is used in channel-adaptive mode. Through this API, users can
391 * enforce a frame-size for all values of bottleneck. Then iSAC will not
392 * automatically change the frame-size.
396 * - ISAC_main_inst : ISAC instance.
397 * - rateBPS : initial value of bottleneck in bits/second
398 * 10000 <= rateBPS <= 32000 is accepted
399 * - frameSizeMs : number of milliseconds per frame (30 or 60)
400 * - enforceFrameSize : 1 to enforce the given frame-size through out
401 * the adaptation process, 0 to let iSAC change
402 * the frame-size if required.
404 * Return value : 0 - ok
408 int16_t WebRtcIsacfix_ControlBwe(ISACFIX_MainStruct *ISAC_main_inst,
411 int16_t enforceFrameSize);
415 /****************************************************************************
416 * WebRtcIsacfix_version(...)
418 * This function returns the version number.
421 * - version : Pointer to character string
425 void WebRtcIsacfix_version(char *version);
428 /****************************************************************************
429 * WebRtcIsacfix_GetErrorCode(...)
431 * This function can be used to check the error code of an iSAC instance. When
432 * a function returns -1 a error code will be set for that instance. The
433 * function below extract the code of the last error that occured in the
434 * specified instance.
437 * - ISAC_main_inst : ISAC instance
439 * Return value : Error code
442 int16_t WebRtcIsacfix_GetErrorCode(ISACFIX_MainStruct *ISAC_main_inst);
445 /****************************************************************************
446 * WebRtcIsacfix_GetUplinkBw(...)
448 * This function return iSAC send bitrate
451 * - ISAC_main_inst : iSAC instance
453 * Return value : <0 Error code
457 int32_t WebRtcIsacfix_GetUplinkBw(ISACFIX_MainStruct *ISAC_main_inst);
460 /****************************************************************************
461 * WebRtcIsacfix_SetMaxPayloadSize(...)
463 * This function sets a limit for the maximum payload size of iSAC. The same
464 * value is used both for 30 and 60 msec packets.
465 * The absolute max will be valid until next time the function is called.
466 * NOTE! This function may override the function WebRtcIsacfix_SetMaxRate()
469 * - ISAC_main_inst : iSAC instance
470 * - maxPayloadBytes : maximum size of the payload in bytes
471 * valid values are between 100 and 400 bytes
474 * Return value : 0 if sucessful
475 * -1 if error happens
478 int16_t WebRtcIsacfix_SetMaxPayloadSize(ISACFIX_MainStruct *ISAC_main_inst,
479 int16_t maxPayloadBytes);
482 /****************************************************************************
483 * WebRtcIsacfix_SetMaxRate(...)
485 * This function sets the maximum rate which the codec may not exceed for a
486 * singel packet. The maximum rate is set in bits per second.
487 * The codec has an absolute maximum rate of 53400 bits per second (200 bytes
489 * It is possible to set a maximum rate between 32000 and 53400 bits per second.
491 * The rate limit is valid until next time the function is called.
493 * NOTE! Packet size will never go above the value set if calling
494 * WebRtcIsacfix_SetMaxPayloadSize() (default max packet size is 400 bytes).
497 * - ISAC_main_inst : iSAC instance
498 * - maxRateInBytes : maximum rate in bits per second,
499 * valid values are 32000 to 53400 bits
501 * Return value : 0 if sucessful
502 * -1 if error happens
505 int16_t WebRtcIsacfix_SetMaxRate(ISACFIX_MainStruct *ISAC_main_inst,
508 /****************************************************************************
509 * WebRtcIsacfix_CreateInternal(...)
511 * This function creates the memory that is used to store data in the encoder
514 * - *ISAC_main_inst : a pointer to the coder instance.
516 * Return value : 0 - Ok
520 int16_t WebRtcIsacfix_CreateInternal(ISACFIX_MainStruct *ISAC_main_inst);
523 /****************************************************************************
524 * WebRtcIsacfix_FreeInternal(...)
526 * This function frees the internal memory for storing encoder data.
529 * - ISAC_main_inst : an ISAC instance.
531 * Return value : 0 - Ok
535 int16_t WebRtcIsacfix_FreeInternal(ISACFIX_MainStruct *ISAC_main_inst);
538 /****************************************************************************
539 * WebRtcIsacfix_GetNewBitStream(...)
541 * This function returns encoded data, with the recieved bwe-index in the
542 * stream. It should always return a complete packet, i.e. only called once
543 * even for 60 msec frames
546 * - ISAC_main_inst : ISAC instance.
547 * - bweIndex : index of bandwidth estimate to put in new bitstream
548 * - scale : factor for rate change (0.4 ~=> half the rate, 1 no change).
551 * - encoded : the encoded data vector
553 * Return value : >0 - Length (in bytes) of coded data
557 int16_t WebRtcIsacfix_GetNewBitStream(ISACFIX_MainStruct *ISAC_main_inst,
563 /****************************************************************************
564 * WebRtcIsacfix_GetDownLinkBwIndex(...)
566 * This function returns index representing the Bandwidth estimate from
567 * other side to this side.
570 * - ISAC_main_inst : iSAC struct
573 * - rateIndex : Bandwidth estimate to transmit to other side.
577 int16_t WebRtcIsacfix_GetDownLinkBwIndex(ISACFIX_MainStruct* ISAC_main_inst,
581 /****************************************************************************
582 * WebRtcIsacfix_UpdateUplinkBw(...)
584 * This function takes an index representing the Bandwidth estimate from
585 * this side to other side and updates BWE.
588 * - ISAC_main_inst : iSAC struct
589 * - rateIndex : Bandwidth estimate from other side.
593 int16_t WebRtcIsacfix_UpdateUplinkBw(ISACFIX_MainStruct* ISAC_main_inst,
597 /****************************************************************************
598 * WebRtcIsacfix_ReadBwIndex(...)
600 * This function returns the index of the Bandwidth estimate from the bitstream.
603 * - encoded : Encoded bitstream
604 * - encoded_len_bytes : Length of the bitstream in bytes.
607 * - rateIndex : Bandwidth estimate in bitstream
611 int16_t WebRtcIsacfix_ReadBwIndex(const uint8_t* encoded,
612 int encoded_len_bytes,
616 /****************************************************************************
617 * WebRtcIsacfix_GetNewFrameLen(...)
619 * This function return the next frame length (in samples) of iSAC.
622 * -ISAC_main_inst : iSAC instance
624 * Return value : frame lenght in samples
627 int16_t WebRtcIsacfix_GetNewFrameLen(ISACFIX_MainStruct *ISAC_main_inst);
630 #if defined(__cplusplus)
636 #endif /* WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_FIX_INTERFACE_ISACFIX_H_ */