Loading...
Searching...
No Matches
codec.h
Go to the documentation of this file.
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include <osmocom/core/utils.h>
#include <osmocom/core/bits.h>
/* TS 101318 Chapter 5.1: 260 bits + 4bit sig */
#define GSM_FR_BYTES 33
/* TS 101318 Chapter 5.2: 112 bits, no sig */
#define GSM_HR_BYTES 14
/* TS 101318 Chapter 5.3: 244 bits + 4bit sig */
#define GSM_EFR_BYTES 31
/* Number of bytes of an GSM_HR RTP payload */
#define GSM_HR_BYTES_RTP_RFC5993 (GSM_HR_BYTES + 1)
#define GSM_HR_BYTES_RTP_TS101318 (GSM_HR_BYTES)
extern const uint16_t gsm610_bitorder[]; /* FR */
extern const uint16_t gsm620_unvoiced_bitorder[]; /* HR unvoiced */
extern const uint16_t gsm620_voiced_bitorder[]; /* HR voiced */
extern const uint16_t gsm660_bitorder[]; /* EFR */
extern const uint16_t gsm690_12_2_bitorder[]; /* AMR 12.2 kbits */
extern const uint16_t gsm690_10_2_bitorder[]; /* AMR 10.2 kbits */
extern const uint16_t gsm690_7_95_bitorder[]; /* AMR 7.95 kbits */
extern const uint16_t gsm690_7_4_bitorder[]; /* AMR 7.4 kbits */
extern const uint16_t gsm690_6_7_bitorder[]; /* AMR 6.7 kbits */
extern const uint16_t gsm690_5_9_bitorder[]; /* AMR 5.9 kbits */
extern const uint16_t gsm690_5_15_bitorder[]; /* AMR 5.15 kbits */
extern const uint16_t gsm690_4_75_bitorder[]; /* AMR 4.75 kbits */
extern const uint8_t osmo_gsm611_silence_frame[GSM_FR_BYTES];
extern const uint8_t osmo_gsm620_silence_frame[GSM_HR_BYTES];
extern const uint8_t osmo_gsm620_homing_frame[GSM_HR_BYTES];
extern const uint8_t osmo_gsm660_homing_frame[GSM_EFR_BYTES];
extern const struct value_string osmo_amr_type_names[];
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,
};
static inline const char *osmo_amr_type_name(enum osmo_amr_type type)
{ return get_value_string(osmo_amr_type_names, type); }
enum osmo_amr_quality {
AMR_BAD = 0,
AMR_GOOD = 1
};
extern const uint8_t gsm690_bitlength[AMR_NO_DATA+1];
int osmo_amr_s_to_d(ubit_t *out, const ubit_t *in, uint16_t n_bits, enum osmo_amr_type amr_mode);
int osmo_amr_d_to_s(ubit_t *out, const ubit_t *in, uint16_t n_bits, enum osmo_amr_type amr_mode);
static inline bool osmo_amr_is_speech(enum osmo_amr_type ft)
{
switch (ft) {
case AMR_4_75:
case AMR_5_15:
case AMR_5_90:
case AMR_6_70:
case AMR_7_40:
case AMR_7_95:
case AMR_10_2:
case AMR_12_2:
return true;
default:
return false;
}
}
extern const uint8_t osmo_amr_sbits_per_mode[AMR_NO_DATA+1];
extern const uint8_t osmo_amr_params_per_mode[AMR_NO_DATA+1];
int osmo_amr_param_to_sbits(ubit_t *s_bits, const uint16_t *param,
enum osmo_amr_type mode);
int osmo_amr_sbits_to_param(uint16_t *param, const ubit_t *s_bits,
enum osmo_amr_type mode);
extern const uint16_t osmo_amr_dhf_4_75[];
extern const uint16_t osmo_amr_dhf_5_15[];
extern const uint16_t osmo_amr_dhf_5_90[];
extern const uint16_t osmo_amr_dhf_6_70[];
extern const uint16_t osmo_amr_dhf_7_40[];
extern const uint16_t osmo_amr_dhf_7_95[];
extern const uint16_t osmo_amr_dhf_10_2[];
extern const uint16_t osmo_amr_dhf_12_2[];
/* SID ternary classification per GSM 06.31 & 06.81 section 6.1.1 */
enum osmo_gsm631_sid_class {
OSMO_GSM631_SID_CLASS_SPEECH = 0,
OSMO_GSM631_SID_CLASS_INVALID = 1,
OSMO_GSM631_SID_CLASS_VALID = 2,
};
bool osmo_fr_check_sid(const uint8_t *rtp_payload, size_t payload_len);
bool osmo_hr_check_sid(const uint8_t *rtp_payload, size_t payload_len);
bool osmo_efr_check_sid(const uint8_t *rtp_payload, size_t payload_len);
enum osmo_gsm631_sid_class osmo_fr_sid_classify(const uint8_t *rtp_payload);
enum osmo_gsm631_sid_class osmo_efr_sid_classify(const uint8_t *rtp_payload);
enum osmo_gsm631_sid_class osmo_hr_sid_classify(const uint8_t *rtp_payload,
bool bci_flag,
bool *bfi_from_bci);
static inline bool osmo_fr_is_any_sid(const uint8_t *rtp_payload)
{
enum osmo_gsm631_sid_class sidc;
sidc = osmo_fr_sid_classify(rtp_payload);
return sidc != OSMO_GSM631_SID_CLASS_SPEECH;
}
static inline bool osmo_efr_is_any_sid(const uint8_t *rtp_payload)
{
enum osmo_gsm631_sid_class sidc;
sidc = osmo_efr_sid_classify(rtp_payload);
return sidc != OSMO_GSM631_SID_CLASS_SPEECH;
}
bool osmo_fr_sid_preen(uint8_t *rtp_payload);
bool osmo_efr_sid_preen(uint8_t *rtp_payload);
void osmo_fr_sid_reset(uint8_t *rtp_payload);
void osmo_hr_sid_reset(uint8_t *rtp_payload);
void osmo_efr_sid_reset(uint8_t *rtp_payload);
int osmo_amr_rtp_enc(uint8_t *payload, uint8_t cmr, enum osmo_amr_type ft,
enum osmo_amr_quality bfi);
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);
bits.h
osmo_amr_param_to_sbits
int osmo_amr_param_to_sbits(ubit_t *s_bits, const uint16_t *param, enum osmo_amr_type mode)
Convert AMR codec frame from parameters to s-bits.
Definition gsm690.c:457
osmo_fr_is_any_sid
static bool osmo_fr_is_any_sid(const uint8_t *rtp_payload)
Check if given FR codec frame is any kind of SID, valid or invalid.
Definition codec.h:132
osmo_hr_sid_classify
enum osmo_gsm631_sid_class osmo_hr_sid_classify(const uint8_t *rtp_payload, bool bci_flag, bool *bfi_from_bci)
Definition hr_sid_class.c:115
gsm690_10_2_bitorder
const uint16_t gsm690_10_2_bitorder[]
Definition gsm690.c:73
osmo_amr_params_per_mode
const uint8_t osmo_amr_params_per_mode[AMR_NO_DATA+1]
This table provides the number of distinct codec parameters (groupings of s-bits into 16-bit paramete...
Definition gsm690.c:355
GSM_EFR_BYTES
#define GSM_EFR_BYTES
Definition codec.h:16
osmo_gsm620_homing_frame
const uint8_t osmo_gsm620_homing_frame[GSM_HR_BYTES]
Definition gsm620.c:292
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:334
osmo_fr_sid_preen
bool osmo_fr_sid_preen(uint8_t *rtp_payload)
Preen potentially-SID FR codec frame in RTP format, ensuring that it is either a speech frame or a va...
Definition gsm610.c:442
osmo_amr_dhf_5_15
const uint16_t osmo_amr_dhf_5_15[]
Definition gsm690.c:532
osmo_amr_sbits_per_mode
const uint8_t osmo_amr_sbits_per_mode[AMR_NO_DATA+1]
This table provides the number of s-bits (as defined in TS 26.090 and TS 26.092, clause 7 in each spe...
Definition gsm690.c:335
osmo_amr_sbits_to_param
int osmo_amr_sbits_to_param(uint16_t *param, const ubit_t *s_bits, enum osmo_amr_type mode)
Convert AMR codec frame from s-bits to parameters.
Definition gsm690.c:490
osmo_amr_dhf_7_40
const uint16_t osmo_amr_dhf_7_40[]
Definition gsm690.c:550
osmo_efr_sid_reset
void osmo_efr_sid_reset(uint8_t *rtp_payload)
Reset the SID field of a potentially corrupted, but still valid GSM-EFR SID frame in RTP encoding to ...
Definition gsm660.c:386
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:219
GSM_HR_BYTES
#define GSM_HR_BYTES
Definition codec.h:14
osmo_efr_sid_classify
enum osmo_gsm631_sid_class osmo_efr_sid_classify(const uint8_t *rtp_payload)
Classify potentially-SID EFR codec frame in RTP format according to the rules of GSM 06....
Definition gsm660.c:348
gsm690_7_4_bitorder
const uint16_t gsm690_7_4_bitorder[]
Definition gsm690.c:124
osmo_gsm611_silence_frame
const uint8_t osmo_gsm611_silence_frame[GSM_FR_BYTES]
Definition gsm610.c:305
osmo_efr_sid_preen
bool osmo_efr_sid_preen(uint8_t *rtp_payload)
Preen potentially-SID EFR codec frame in RTP format, ensuring that it is either a speech frame or a v...
Definition gsm660.c:412
osmo_amr_dhf_12_2
const uint16_t osmo_amr_dhf_12_2[]
Definition gsm690.c:570
osmo_gsm620_silence_frame
const uint8_t osmo_gsm620_silence_frame[GSM_HR_BYTES]
Definition gsm620.c:278
gsm690_5_9_bitorder
const uint16_t gsm690_5_9_bitorder[]
Definition gsm690.c:167
gsm690_4_75_bitorder
const uint16_t gsm690_4_75_bitorder[]
Definition gsm690.c:204
osmo_fr_sid_classify
enum osmo_gsm631_sid_class osmo_fr_sid_classify(const uint8_t *rtp_payload)
Classify potentially-SID FR codec frame in RTP format according to the rules of GSM 06....
Definition gsm610.c:385
GSM_FR_BYTES
#define GSM_FR_BYTES
Definition codec.h:12
gsm690_5_15_bitorder
const uint16_t gsm690_5_15_bitorder[]
Definition gsm690.c:186
osmo_amr_dhf_6_70
const uint16_t osmo_amr_dhf_6_70[]
Definition gsm690.c:544
osmo_amr_type_name
static const char * osmo_amr_type_name(enum osmo_amr_type type)
Definition codec.h:59
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:304
osmo_fr_sid_reset
void osmo_fr_sid_reset(uint8_t *rtp_payload)
Reset the SID field and the unused bits of a potentially corrupted, but still valid GSM-FR SID frame ...
Definition gsm610.c:420
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:664
osmo_gsm660_homing_frame
const uint8_t osmo_gsm660_homing_frame[GSM_EFR_BYTES]
Definition gsm660.c:269
osmo_amr_type
osmo_amr_type
Definition codec.h:43
AMR_NO_DATA
@ AMR_NO_DATA
Definition codec.h:56
AMR_4_75
@ AMR_4_75
Definition codec.h:44
AMR_12_2
@ AMR_12_2
Definition codec.h:51
AMR_7_40
@ AMR_7_40
Definition codec.h:48
AMR_10_2
@ AMR_10_2
Definition codec.h:50
AMR_6_70
@ AMR_6_70
Definition codec.h:47
AMR_GSM_EFR_SID
@ AMR_GSM_EFR_SID
Definition codec.h:53
AMR_PDC_EFR_SID
@ AMR_PDC_EFR_SID
Definition codec.h:55
AMR_SID
@ AMR_SID
Definition codec.h:52
AMR_5_90
@ AMR_5_90
Definition codec.h:46
AMR_5_15
@ AMR_5_15
Definition codec.h:45
AMR_7_95
@ AMR_7_95
Definition codec.h:49
AMR_TDMA_EFR_SID
@ AMR_TDMA_EFR_SID
Definition codec.h:54
osmo_hr_sid_reset
void osmo_hr_sid_reset(uint8_t *rtp_payload)
Reset the SID field of a potentially corrupted, but still valid GSM-HR SID frame in TS 101 318 format...
Definition gsm620.c:351
osmo_amr_is_speech
static bool osmo_amr_is_speech(enum osmo_amr_type ft)
Check if given AMR Frame Type is a speech frame.
Definition codec.h:76
osmo_amr_rtp_dec
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.
Definition gsm690.c:616
osmo_gsm631_sid_class
osmo_gsm631_sid_class
Definition codec.h:111
OSMO_GSM631_SID_CLASS_SPEECH
@ OSMO_GSM631_SID_CLASS_SPEECH
Definition codec.h:112
OSMO_GSM631_SID_CLASS_VALID
@ OSMO_GSM631_SID_CLASS_VALID
Definition codec.h:114
OSMO_GSM631_SID_CLASS_INVALID
@ OSMO_GSM631_SID_CLASS_INVALID
Definition codec.h:113
osmo_amr_type_names
const struct value_string osmo_amr_type_names[]
Definition gsm690.c:586
gsm690_7_95_bitorder
const uint16_t gsm690_7_95_bitorder[]
Definition gsm690.c:101
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:278
osmo_amr_dhf_4_75
const uint16_t osmo_amr_dhf_4_75[]
Definition gsm690.c:526
gsm620_unvoiced_bitorder
const uint16_t gsm620_unvoiced_bitorder[]
Definition gsm620.c:32
osmo_amr_dhf_7_95
const uint16_t osmo_amr_dhf_7_95[]
Definition gsm690.c:556
gsm610_bitorder
const uint16_t gsm610_bitorder[]
Definition gsm610.c:36
osmo_efr_is_any_sid
static bool osmo_efr_is_any_sid(const uint8_t *rtp_payload)
Check if given EFR codec frame is any kind of SID, valid or invalid.
Definition codec.h:145
gsm690_12_2_bitorder
const uint16_t gsm690_12_2_bitorder[]
Definition gsm690.c:41
osmo_amr_dhf_10_2
const uint16_t osmo_amr_dhf_10_2[]
Definition gsm690.c:562
gsm690_6_7_bitorder
const uint16_t gsm690_6_7_bitorder[]
Definition gsm690.c:146
osmo_amr_quality
osmo_amr_quality
Definition codec.h:62
AMR_BAD
@ AMR_BAD
Definition codec.h:63
AMR_GOOD
@ AMR_GOOD
Definition codec.h:64
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:309
osmo_efr_check_sid
bool osmo_efr_check_sid(const uint8_t *rtp_payload, size_t payload_len)
Check whether RTP frame contains EFR SID code word according to TS 101 318 §5.3.2.
Definition gsm660.c:297
osmo_amr_dhf_5_90
const uint16_t osmo_amr_dhf_5_90[]
Definition gsm690.c:538
gsm620_voiced_bitorder
const uint16_t gsm620_voiced_bitorder[]
Definition gsm620.c:151
gsm660_bitorder
const uint16_t gsm660_bitorder[]
Definition gsm660.c:38
ubit_t
uint8_t ubit_t
get_value_string
const char * get_value_string(const struct value_string *vs, uint32_t val)
mode
uint8_t mode
type
uint8_t type
value_string
utils.h