libosmocodec 1.7.0.118-5c7e
Osmocom codec library
Loading...
Searching...
No Matches
codec.h File Reference
#include <stdint.h>
#include <stdbool.h>
#include <osmocom/core/utils.h>
#include <osmocom/core/bits.h>

Go to the source code of this file.

Macros

#define GSM_FR_BYTES   33
 
#define GSM_HR_BYTES   14
 
#define GSM_EFR_BYTES   31
 

Enumerations

enum  osmo_amr_type {
  AMR_4_75 = 0 ,
  AMR_5_15 = 1 ,
  AMR_5_90 = 2 ,
  AMR_6_70 = 3 ,
  AMR_7_40 = 4 ,
  AMR_7_95 = 5 ,
  AMR_10_2 = 6 ,
  AMR_12_2 = 7 ,
  AMR_SID = 8 ,
  AMR_GSM_EFR_SID = 9 ,
  AMR_TDMA_EFR_SID = 10 ,
  AMR_PDC_EFR_SID = 11 ,
  AMR_NO_DATA = 15
}
 
enum  osmo_amr_quality {
  AMR_BAD = 0 ,
  AMR_GOOD = 1
}
 

Functions

static const char * osmo_amr_type_name (enum osmo_amr_type type)
 
int osmo_amr_s_to_d (ubit_t *out, const ubit_t *in, uint16_t n_bits, enum osmo_amr_type amr_mode)
 Convert from S-bits (codec output) to d-bits.
 
int osmo_amr_d_to_s (ubit_t *out, const ubit_t *in, uint16_t n_bits, enum osmo_amr_type amr_mode)
 Convert from d-bits to s-bits (codec input).
 
static bool osmo_amr_is_speech (enum osmo_amr_type ft)
 Check if given AMR Frame Type is a speech frame.
 
bool osmo_fr_check_sid (const uint8_t *rtp_payload, size_t payload_len)
 Check whether RTP frame contains FR SID code word according to TS 101 318 §5.1.2.
 
bool osmo_hr_check_sid (const uint8_t *rtp_payload, size_t payload_len)
 Check whether RTP frame contains HR SID code word according to TS 101 318 §5.2.2.
 
int osmo_amr_rtp_enc (uint8_t *payload, uint8_t cmr, enum osmo_amr_type ft, enum osmo_amr_quality bfi)
 Encode various AMR parameters from RTP payload (RFC 4867)
 
int osmo_amr_rtp_dec (const uint8_t *payload, int payload_len, uint8_t *cmr, int8_t *cmi, enum osmo_amr_type *ft, enum osmo_amr_quality *bfi, int8_t *sti)
 Decode various AMR parameters from RTP payload (RFC 4867) acording to 3GPP TS 26.101.
 

Variables

const uint16_t gsm610_bitorder []
 
const uint16_t gsm620_unvoiced_bitorder []
 
const uint16_t gsm620_voiced_bitorder []
 
const uint16_t gsm660_bitorder []
 
const uint16_t gsm690_12_2_bitorder []
 
const uint16_t gsm690_10_2_bitorder []
 
const uint16_t gsm690_7_95_bitorder []
 
const uint16_t gsm690_7_4_bitorder []
 
const uint16_t gsm690_6_7_bitorder []
 
const uint16_t gsm690_5_9_bitorder []
 
const uint16_t gsm690_5_15_bitorder []
 
const uint16_t gsm690_4_75_bitorder []
 
const struct value_string osmo_amr_type_names []
 
const uint8_t gsm690_bitlength [AMR_NO_DATA+1]
 These constants refer to the length of one "AMR core frame" as per TS 26.101 Section 4.2.2 / Table 2.
 

Macro Definition Documentation

◆ GSM_EFR_BYTES

#define GSM_EFR_BYTES   31

◆ GSM_FR_BYTES

#define GSM_FR_BYTES   33

◆ GSM_HR_BYTES

#define GSM_HR_BYTES   14

Enumeration Type Documentation

◆ osmo_amr_quality

Enumerator
AMR_BAD 
AMR_GOOD 

◆ osmo_amr_type

Enumerator
AMR_4_75 
AMR_5_15 
AMR_5_90 
AMR_6_70 
AMR_7_40 
AMR_7_95 
AMR_10_2 
AMR_12_2 
AMR_SID 
AMR_GSM_EFR_SID 
AMR_TDMA_EFR_SID 
AMR_PDC_EFR_SID 
AMR_NO_DATA 

Function Documentation

◆ osmo_amr_d_to_s()

int osmo_amr_d_to_s ( ubit_t out,
const ubit_t in,
uint16_t  n_bits,
enum osmo_amr_type  amr_mode 
)

Convert from d-bits to s-bits (codec input).

Parameters
[out]outuser-provided output buffer for generated unpacked s-bits
[in]ininput buffer for unpacked d-bits
[in]n_bitsnumber of bits (in both in and out)
[in]AMRmode (0..7)

References ARRAY_SIZE, ts26101_reorder_table::len, n, ts26101_reorder_table::s_to_d, and ts26101_reorder_tables.

◆ osmo_amr_is_speech()

static bool osmo_amr_is_speech ( enum osmo_amr_type  ft)
inlinestatic

Check if given AMR Frame Type is a speech frame.

Parameters
[in]ftAMR Frame Type
Returns
true if AMR with given Frame Type contains voice, false otherwise

References AMR_10_2, AMR_12_2, AMR_4_75, AMR_5_15, AMR_5_90, AMR_6_70, AMR_7_40, and AMR_7_95.

◆ osmo_amr_rtp_dec()

int osmo_amr_rtp_dec ( const uint8_t *  rtppayload,
int  payload_len,
uint8_t *  cmr,
int8_t *  cmi,
enum osmo_amr_type ft,
enum osmo_amr_quality bfi,
int8_t *  sti 
)

Decode various AMR parameters from RTP payload (RFC 4867) acording to 3GPP TS 26.101.

Parameters
[in]rtppayloadPayload from RTP packet
[in]payload_lenlength of rtppayload
[out]cmrAMR Codec Mode Request, not filled if NULL
[out]cmiAMR Codec Mode Indicator, -1 if not applicable for this type, not filled if NULL
[out]ftAMR Frame Type, not filled if NULL
[out]bfiAMR Bad Frame Indicator, not filled if NULL
[out]stiAMR SID Type Indicator, -1 if not applicable for this type, not filled if NULL
Returns
length of AMR data or negative value on error

References amr_len_by_ft, AMR_SID, ENOTSUP, and type.

◆ osmo_amr_rtp_enc()

int osmo_amr_rtp_enc ( uint8_t *  payload,
uint8_t  cmr,
enum osmo_amr_type  ft,
enum osmo_amr_quality  bfi 
)

Encode various AMR parameters from RTP payload (RFC 4867)

Parameters
[out]payloadPayload for RTP packet, contains speech data (if any) except for have 2 first bytes where header will be built
[in]cmrAMR codec Mode Request
[in]ftAMR Frame Type
[in]bfiAMR Bad Frame Indicator
Returns
length of AMR data (header + ToC + speech data) or negative value on error

Note: only octet-aligned mode is supported so the header occupies 2 full bytes. Optional interleaving header is not supported.

References amr_len_by_ft, and ENOTSUP.

◆ osmo_amr_s_to_d()

int osmo_amr_s_to_d ( ubit_t out,
const ubit_t in,
uint16_t  n_bits,
enum osmo_amr_type  amr_mode 
)

Convert from S-bits (codec output) to d-bits.

Parameters
[out]outuser-provided output buffer for generated unpacked d-bits
[in]ininput buffer for unpacked s-bits
[in]n_bitsnumber of bits (in both in and out)
[in]AMRmode (0..7)

References ARRAY_SIZE, ts26101_reorder_table::len, n, ts26101_reorder_table::s_to_d, and ts26101_reorder_tables.

◆ osmo_amr_type_name()

static const char * osmo_amr_type_name ( enum osmo_amr_type  type)
inlinestatic

◆ osmo_fr_check_sid()

bool osmo_fr_check_sid ( const uint8_t *  rtp_payload,
size_t  payload_len 
)

Check whether RTP frame contains FR SID code word according to TS 101 318 §5.1.2.

Parameters
[in]rtp_payloadBuffer with RTP payload
[in]payload_lenLength of payload
Returns
true if code word is found, false otherwise

References ARRAY_SIZE, bitvec_get_bit_pos(), bitvec::data, bitvec::data_len, and ZERO.

Referenced by conceal_frame().

◆ osmo_hr_check_sid()

bool osmo_hr_check_sid ( const uint8_t *  rtp_payload,
size_t  payload_len 
)

Check whether RTP frame contains HR SID code word according to TS 101 318 §5.2.2.

Parameters
[in]rtp_payloadBuffer with RTP payload
[in]payload_lenLength of payload
Returns
true if code word is found, false otherwise

References bitvec_get_bit_pos(), bitvec::cur_bit, bitvec::data, bitvec::data_len, and ONE.

Variable Documentation

◆ gsm610_bitorder

const uint16_t gsm610_bitorder[]
extern

◆ gsm620_unvoiced_bitorder

const uint16_t gsm620_unvoiced_bitorder[]
extern

◆ gsm620_voiced_bitorder

const uint16_t gsm620_voiced_bitorder[]
extern

◆ gsm660_bitorder

const uint16_t gsm660_bitorder[]
extern

◆ gsm690_10_2_bitorder

const uint16_t gsm690_10_2_bitorder[]
extern

◆ gsm690_12_2_bitorder

const uint16_t gsm690_12_2_bitorder[]
extern

◆ gsm690_4_75_bitorder

const uint16_t gsm690_4_75_bitorder[]
extern

◆ gsm690_5_15_bitorder

const uint16_t gsm690_5_15_bitorder[]
extern

◆ gsm690_5_9_bitorder

const uint16_t gsm690_5_9_bitorder[]
extern

◆ gsm690_6_7_bitorder

const uint16_t gsm690_6_7_bitorder[]
extern

◆ gsm690_7_4_bitorder

const uint16_t gsm690_7_4_bitorder[]
extern

◆ gsm690_7_95_bitorder

const uint16_t gsm690_7_95_bitorder[]
extern

◆ gsm690_bitlength

const uint8_t gsm690_bitlength[AMR_NO_DATA+1]
extern

These constants refer to the length of one "AMR core frame" as per TS 26.101 Section 4.2.2 / Table 2.

◆ osmo_amr_type_names

const struct value_string osmo_amr_type_names[]
extern

Referenced by osmo_amr_type_name().