Home | History | Annotate | Download | only in g722
      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_G722_G722_INTERFACE_H_
     12 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_G722_G722_INTERFACE_H_
     13 
     14 #include "webrtc/typedefs.h"
     15 
     16 /*
     17  * Solution to support multiple instances
     18  */
     19 
     20 typedef struct WebRtcG722EncInst    G722EncInst;
     21 typedef struct WebRtcG722DecInst    G722DecInst;
     22 
     23 /*
     24  * Comfort noise constants
     25  */
     26 
     27 #define G722_WEBRTC_SPEECH     1
     28 #define G722_WEBRTC_CNG        2
     29 
     30 #ifdef __cplusplus
     31 extern "C" {
     32 #endif
     33 
     34 
     35 /****************************************************************************
     36  * WebRtcG722_CreateEncoder(...)
     37  *
     38  * Create memory used for G722 encoder
     39  *
     40  * Input:
     41  *     - G722enc_inst         : G722 instance for encoder
     42  *
     43  * Return value               :  0 - Ok
     44  *                              -1 - Error
     45  */
     46 int16_t WebRtcG722_CreateEncoder(G722EncInst **G722enc_inst);
     47 
     48 
     49 /****************************************************************************
     50  * WebRtcG722_EncoderInit(...)
     51  *
     52  * This function initializes a G722 instance
     53  *
     54  * Input:
     55  *     - G722enc_inst         : G722 instance, i.e. the user that should receive
     56  *                             be initialized
     57  *
     58  * Return value               :  0 - Ok
     59  *                              -1 - Error
     60  */
     61 
     62 int16_t WebRtcG722_EncoderInit(G722EncInst *G722enc_inst);
     63 
     64 
     65 /****************************************************************************
     66  * WebRtcG722_FreeEncoder(...)
     67  *
     68  * Free the memory used for G722 encoder
     69  *
     70  * Input:
     71  *     - G722enc_inst         : G722 instance for encoder
     72  *
     73  * Return value               :  0 - Ok
     74  *                              -1 - Error
     75  */
     76 int WebRtcG722_FreeEncoder(G722EncInst *G722enc_inst);
     77 
     78 
     79 
     80 /****************************************************************************
     81  * WebRtcG722_Encode(...)
     82  *
     83  * This function encodes G722 encoded data.
     84  *
     85  * Input:
     86  *     - G722enc_inst         : G722 instance, i.e. the user that should encode
     87  *                              a packet
     88  *     - speechIn             : Input speech vector
     89  *     - len                  : Samples in speechIn
     90  *
     91  * Output:
     92  *        - encoded           : The encoded data vector
     93  *
     94  * Return value               : Length (in bytes) of coded data
     95  */
     96 
     97 size_t WebRtcG722_Encode(G722EncInst* G722enc_inst,
     98                          const int16_t* speechIn,
     99                          size_t len,
    100                          uint8_t* encoded);
    101 
    102 
    103 /****************************************************************************
    104  * WebRtcG722_CreateDecoder(...)
    105  *
    106  * Create memory used for G722 encoder
    107  *
    108  * Input:
    109  *     - G722dec_inst         : G722 instance for decoder
    110  *
    111  * Return value               :  0 - Ok
    112  *                              -1 - Error
    113  */
    114 int16_t WebRtcG722_CreateDecoder(G722DecInst **G722dec_inst);
    115 
    116 /****************************************************************************
    117  * WebRtcG722_DecoderInit(...)
    118  *
    119  * This function initializes a G722 instance
    120  *
    121  * Input:
    122  *     - inst      : G722 instance
    123  */
    124 
    125 void WebRtcG722_DecoderInit(G722DecInst* inst);
    126 
    127 /****************************************************************************
    128  * WebRtcG722_FreeDecoder(...)
    129  *
    130  * Free the memory used for G722 decoder
    131  *
    132  * Input:
    133  *     - G722dec_inst         : G722 instance for decoder
    134  *
    135  * Return value               :  0 - Ok
    136  *                              -1 - Error
    137  */
    138 
    139 int WebRtcG722_FreeDecoder(G722DecInst *G722dec_inst);
    140 
    141 
    142 /****************************************************************************
    143  * WebRtcG722_Decode(...)
    144  *
    145  * This function decodes a packet with G729 frame(s). Output speech length
    146  * will be a multiple of 80 samples (80*frames/packet).
    147  *
    148  * Input:
    149  *     - G722dec_inst       : G722 instance, i.e. the user that should decode
    150  *                            a packet
    151  *     - encoded            : Encoded G722 frame(s)
    152  *     - len                : Bytes in encoded vector
    153  *
    154  * Output:
    155  *        - decoded         : The decoded vector
    156  *      - speechType        : 1 normal, 2 CNG (Since G722 does not have its own
    157  *                            DTX/CNG scheme it should always return 1)
    158  *
    159  * Return value             : Samples in decoded vector
    160  */
    161 
    162 size_t WebRtcG722_Decode(G722DecInst *G722dec_inst,
    163                          const uint8_t* encoded,
    164                          size_t len,
    165                          int16_t *decoded,
    166                          int16_t *speechType);
    167 
    168 /****************************************************************************
    169  * WebRtcG722_Version(...)
    170  *
    171  * Get a string with the current version of the codec
    172  */
    173 
    174 int16_t WebRtcG722_Version(char *versionStr, short len);
    175 
    176 
    177 #ifdef __cplusplus
    178 }
    179 #endif
    180 
    181 
    182 #endif /* WEBRTC_MODULES_AUDIO_CODING_CODECS_G722_G722_INTERFACE_H_ */
    183