libosmocodec  1.4.0
Osmocom codec library
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

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. More...
 
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). More...
 
static bool osmo_amr_is_speech (enum osmo_amr_type ft)
 Check if given AMR Frame Type is a speech frame. More...
 
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. More...
 
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. More...
 
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) More...
 
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. More...
 

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. More...
 

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_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 ARRAY_SIZE, bitvec_get_uint(), bitvec::cur_bit, bitvec::data, bitvec::data_len, and mask().

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
AMR_12_2
@ AMR_12_2
Definition: codec.h:42
bitvec_read_field
uint64_t bitvec_read_field(struct bitvec *bv, unsigned int *read_index, unsigned int len)
gsm690_5_15_bitorder
const uint16_t gsm690_5_15_bitorder[103]
Definition: gsm690.c:190
osmo_ecu_fr_state::subsequent_lost_frame
bool subsequent_lost_frame
Definition: ecu.h:11
reduce_xmaxcr_all
static bool reduce_xmaxcr_all(struct bitvec *frame_bitvec)
Reduce all XMAXC fields in the frame.
Definition: ecu_fr.c:65
AMR_SID
@ AMR_SID
Definition: codec.h:43
bitvec::data
uint8_t * data
GSM_FR_BYTES
#define GSM_FR_BYTES
Definition: codec.h:12
osmo_ecu_frame_out
int osmo_ecu_frame_out(struct osmo_ecu_state *st, uint8_t *frame_out)
generate output data for a substitute/erroneous frame.
Definition: ecu.c:94
gsm690_7_4_bitorder
const uint16_t gsm690_7_4_bitorder[148]
Definition: gsm690.c:128
mask
static uint16_t mask(const uint8_t msb)
Definition: gsm620.c:271
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.
Definition: gsm690.c:282
gsm690_7_95_bitorder
const uint16_t gsm690_7_95_bitorder[159]
Definition: gsm690.c:105
gsm620_voiced_bitorder
const uint16_t gsm620_voiced_bitorder[112]
Definition: gsm620.c:156
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.
Definition: gsm620.c:283
osmo_ecu_state::codec
enum osmo_ecu_codec codec
Definition: ecu.h:48
osmo_amr_type_names
const struct value_string osmo_amr_type_names[]
Definition: gsm690.c:334
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.
Definition: gsm610.c:309
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.
Definition: gsm690.c:364
ecu_fr_init
static struct osmo_ecu_state * ecu_fr_init(void *ctx, enum osmo_ecu_codec codec)
Definition: ecu_fr.c:172
bitvec_get_bit_pos
enum bit_value bitvec_get_bit_pos(const struct bitvec *bv, unsigned int bitnr)
osmo_amr_type
osmo_amr_type
Definition: codec.h:34
len
static size_t len(const char *str)
bitvec_pack
unsigned int bitvec_pack(const struct bitvec *bv, uint8_t *buffer)
ZERO
ZERO
n
write Write running configuration to or terminal n Write configuration to the copy running config startup Copy configuration n Copy running config to n Copy running config to startup write Write running configuration to or terminal n Write to terminal n
gsm690_bitlength
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....
Definition: gsm690.c:223
utils.h
ts26101_reorder_table
Definition: gsm690.c:235
bitvec_free
void bitvec_free(struct bitvec *bv)
bitvec::data_len
unsigned int data_len
osmo_ecu_destroy
void osmo_ecu_destroy(struct osmo_ecu_state *st)
destroy an ECU instance
Definition: ecu.c:62
osmo_ecu_fr_state::frame_backup
uint8_t frame_backup[GSM_FR_BYTES]
Definition: ecu.h:12
gsm690_6_7_bitorder
const uint16_t gsm690_6_7_bitorder[134]
Definition: gsm690.c:150
osmo_ecu_state::data
uint8_t data[0]
Definition: ecu.h:49
reduce_xmaxcr
static bool reduce_xmaxcr(struct bitvec *frame_bitvec, const unsigned int index)
Reduce the XMAXC field.
Definition: ecu_fr.c:42
gsm690_10_2_bitorder
const uint16_t gsm690_10_2_bitorder[204]
Definition: gsm690.c:77
GSM610_RTP_XMAXC00
@ GSM610_RTP_XMAXC00
Definition: gsm610_bits.h:59
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.
Definition: gsm610.c:309
codec.h
osmo_ecu_frame_in
int osmo_ecu_frame_in(struct osmo_ecu_state *st, bool bfi, const uint8_t *frame, unsigned int frame_bytes)
process a received frame a substitute/erroneous frame.
Definition: ecu.c:80
osmo_ecu_register
int osmo_ecu_register(const struct osmo_ecu_ops *ops, enum osmo_ecu_codec codec)
register an ECU implementation for a given codec
Definition: ecu.c:108
AMR_7_95
@ AMR_7_95
Definition: codec.h:40
g_ecu_ops
static const struct osmo_ecu_ops * g_ecu_ops[_NUM_OSMO_ECU_CODECS]
Definition: ecu.c:43
conceal_frame
static int conceal_frame(uint8_t *frame)
Definition: ecu_fr.c:78
AMR_NO_DATA
@ AMR_NO_DATA
Definition: codec.h:47
AMR_4_75
@ AMR_4_75
Definition: codec.h:35
AMR_PDC_EFR_SID
@ AMR_PDC_EFR_SID
Definition: codec.h:46
GSM610_RTP_XMAXC30
@ GSM610_RTP_XMAXC30
Definition: gsm610_bits.h:227
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)
Definition: gsm690.c:412
gsm620_unvoiced_bitorder
const uint16_t gsm620_unvoiced_bitorder[112]
Definition: gsm620.c:37
AMR_5_15
@ AMR_5_15
Definition: codec.h:36
osmo_ecu_fr_reset
void osmo_ecu_fr_reset(struct osmo_ecu_fr_state *state, const uint8_t *frame)
To be called when a good frame is received.
Definition: ecu_fr.c:133
gsm690_5_9_bitorder
const uint16_t gsm690_5_9_bitorder[118]
Definition: gsm690.c:171
gsm690_4_75_bitorder
const uint16_t gsm690_4_75_bitorder[95]
Definition: gsm690.c:208
osmo_ecu_fr_state
Definition: ecu.h:10
GSM610_XMAXC_REDUCE
#define GSM610_XMAXC_REDUCE
Definition: ecu_fr.c:35
osmo_ecu_fr_conceal
int osmo_ecu_fr_conceal(struct osmo_ecu_fr_state *state, uint8_t *frame)
To be called when a bad frame is received.
Definition: ecu_fr.c:147
bitvec.h
AMR_6_70
@ AMR_6_70
Definition: codec.h:38
__attribute__
static __attribute__((constructor))
Definition: ecu_fr.c:214
talloc.h
if
if(vty->type==VTY_SHELL_SERV)
osmo_ecu_state
Definition: ecu.h:47
bitvec_write_field
int bitvec_write_field(struct bitvec *bv, unsigned int *write_index, uint64_t val, unsigned int len)
bitvec_alloc
struct bitvec * bitvec_alloc(unsigned int size, TALLOC_CTX *ctx)
osmo_ecu_ops::destroy
void(* destroy)(struct osmo_ecu_state *)
Definition: ecu.h:67
osmo_ecu_ops::init
struct osmo_ecu_state *(* init)(void *ctx, enum osmo_ecu_codec codec)
Definition: ecu.h:66
AMR_7_40
@ AMR_7_40
Definition: codec.h:39
bitvec
gsm690_12_2_bitorder
const uint16_t gsm690_12_2_bitorder[244]
Definition: gsm690.c:45
ts26101_reorder_table::len
uint8_t len
size of table
Definition: gsm690.c:239
AMR_5_90
@ AMR_5_90
Definition: codec.h:37
value_string
ts26101_reorder_table::s_to_d
const uint16_t * s_to_d
Table as per TS 26.101 Annex B to compute d-bits from s-bits.
Definition: gsm690.c:237
gsm660_bitorder
const uint16_t gsm660_bitorder[260]
Definition: gsm660.c:38
gsm610_bits.h
osmo_ecu_codec
osmo_ecu_codec
Definition: ecu.h:20
ubit_t
uint8_t ubit_t
type
enum osmo_sub_auth_type type
ARRAY_SIZE
#define ARRAY_SIZE(x)
GSM610_RTP_XMAXC20
@ GSM610_RTP_XMAXC20
Definition: gsm610_bits.h:171
amr_len_by_ft
static const uint8_t amr_len_by_ft[16]
Definition: gsm690.c:330
ecu.h
AMR_TDMA_EFR_SID
@ AMR_TDMA_EFR_SID
Definition: codec.h:45
osmo_ecu_ops::frame_in
int(* frame_in)(struct osmo_ecu_state *st, bool bfi, const uint8_t *frame, unsigned int frame_bytes)
Definition: ecu.h:68
GSM610_RTP_XMAXC10
@ GSM610_RTP_XMAXC10
Definition: gsm610_bits.h:115
ts26101_reorder_tables
static const struct ts26101_reorder_table ts26101_reorder_tables[8]
Definition: gsm690.c:242
osmo_ecu_init
struct osmo_ecu_state * osmo_ecu_init(void *ctx, enum osmo_ecu_codec codec)
initialize an ECU instance for given codec.
Definition: ecu.c:52
osmo_ecu_register
int osmo_ecu_register(const struct osmo_ecu_ops *ops, enum osmo_ecu_codec codec)
register an ECU implementation for a given codec
Definition: ecu.c:108
ecu_fr_frame_in
static int ecu_fr_frame_in(struct osmo_ecu_state *st, bool bfi, const uint8_t *frame, unsigned int frame_bytes)
Definition: ecu_fr.c:187
ecu_fr_frame_out
static int ecu_fr_frame_out(struct osmo_ecu_state *st, uint8_t *frame_out)
Definition: ecu_fr.c:198
bitvec::cur_bit
unsigned int cur_bit
bits.h
osmo_ecu_ops::frame_out
int(* frame_out)(struct osmo_ecu_state *st, uint8_t *frame_out)
Definition: ecu.h:70
bitvec_get_uint
int bitvec_get_uint(struct bitvec *bv, unsigned int num_bits)
AMR_10_2
@ AMR_10_2
Definition: codec.h:41
osmo_amr_quality
osmo_amr_quality
Definition: codec.h:50
osmo_ecu_ops_fr
static const struct osmo_ecu_ops osmo_ecu_ops_fr
Definition: ecu_fr.c:208
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).
Definition: gsm690.c:308
OSMO_ECU_CODEC_FR
@ OSMO_ECU_CODEC_FR
Definition: ecu.h:22
gsm610_bitorder
const uint16_t gsm610_bitorder[260]
Definition: gsm610.c:40
AMR_GSM_EFR_SID
@ AMR_GSM_EFR_SID
Definition: codec.h:44
GSM610_XMAXC_LEN
#define GSM610_XMAXC_LEN
Definition: ecu_fr.c:36
osmo_ecu_ops
Definition: ecu.h:65
ENOTSUP
#define ENOTSUP
_NUM_OSMO_ECU_CODECS
@ _NUM_OSMO_ECU_CODECS
Definition: ecu.h:25
bitvec_unpack
unsigned int bitvec_unpack(struct bitvec *bv, const uint8_t *buffer)