libosmocodec 1.10.0.27-aec32
Osmocom codec library
codec.h
Go to the documentation of this file.
1
3#pragma once
4
5#include <stdint.h>
6#include <stdbool.h>
7
9#include <osmocom/core/bits.h>
10
11/* TS 101318 Chapter 5.1: 260 bits + 4bit sig */
12#define GSM_FR_BYTES 33
13/* TS 101318 Chapter 5.2: 112 bits, no sig */
14#define GSM_HR_BYTES 14
15/* TS 101318 Chapter 5.3: 244 bits + 4bit sig */
16#define GSM_EFR_BYTES 31
17
18/* Number of bytes of an GSM_HR RTP payload */
19#define GSM_HR_BYTES_RTP_RFC5993 (GSM_HR_BYTES + 1)
20#define GSM_HR_BYTES_RTP_TS101318 (GSM_HR_BYTES)
21
22extern const uint16_t gsm610_bitorder[]; /* FR */
23extern const uint16_t gsm620_unvoiced_bitorder[]; /* HR unvoiced */
24extern const uint16_t gsm620_voiced_bitorder[]; /* HR voiced */
25extern const uint16_t gsm660_bitorder[]; /* EFR */
26
27extern const uint16_t gsm690_12_2_bitorder[]; /* AMR 12.2 kbits */
28extern const uint16_t gsm690_10_2_bitorder[]; /* AMR 10.2 kbits */
29extern const uint16_t gsm690_7_95_bitorder[]; /* AMR 7.95 kbits */
30extern const uint16_t gsm690_7_4_bitorder[]; /* AMR 7.4 kbits */
31extern const uint16_t gsm690_6_7_bitorder[]; /* AMR 6.7 kbits */
32extern const uint16_t gsm690_5_9_bitorder[]; /* AMR 5.9 kbits */
33extern const uint16_t gsm690_5_15_bitorder[]; /* AMR 5.15 kbits */
34extern const uint16_t gsm690_4_75_bitorder[]; /* AMR 4.75 kbits */
35
36extern const uint8_t osmo_gsm611_silence_frame[GSM_FR_BYTES];
37
38extern const struct value_string osmo_amr_type_names[];
39
54};
55
56static inline const char *osmo_amr_type_name(enum osmo_amr_type type)
58
61 AMR_GOOD = 1
62};
63
64extern const uint8_t gsm690_bitlength[AMR_NO_DATA+1];
65
66int osmo_amr_s_to_d(ubit_t *out, const ubit_t *in, uint16_t n_bits, enum osmo_amr_type amr_mode);
67int osmo_amr_d_to_s(ubit_t *out, const ubit_t *in, uint16_t n_bits, enum osmo_amr_type amr_mode);
68
73static inline bool osmo_amr_is_speech(enum osmo_amr_type ft)
74{
75 switch (ft) {
76 case AMR_4_75:
77 case AMR_5_15:
78 case AMR_5_90:
79 case AMR_6_70:
80 case AMR_7_40:
81 case AMR_7_95:
82 case AMR_10_2:
83 case AMR_12_2:
84 return true;
85 default:
86 return false;
87 }
88}
89
90/* SID ternary classification per GSM 06.31 & 06.81 section 6.1.1 */
95};
96
97bool osmo_fr_check_sid(const uint8_t *rtp_payload, size_t payload_len);
98bool osmo_hr_check_sid(const uint8_t *rtp_payload, size_t payload_len);
99bool osmo_efr_check_sid(const uint8_t *rtp_payload, size_t payload_len);
100
101enum osmo_gsm631_sid_class osmo_fr_sid_classify(const uint8_t *rtp_payload);
102enum osmo_gsm631_sid_class osmo_efr_sid_classify(const uint8_t *rtp_payload);
103enum osmo_gsm631_sid_class osmo_hr_sid_classify(const uint8_t *rtp_payload,
104 bool bci_flag,
105 bool *bfi_from_bci);
106
112static inline bool osmo_fr_is_any_sid(const uint8_t *rtp_payload)
113{
114 enum osmo_gsm631_sid_class sidc;
115
116 sidc = osmo_fr_sid_classify(rtp_payload);
117 return sidc != OSMO_GSM631_SID_CLASS_SPEECH;
118}
119
125static inline bool osmo_efr_is_any_sid(const uint8_t *rtp_payload)
126{
127 enum osmo_gsm631_sid_class sidc;
128
129 sidc = osmo_efr_sid_classify(rtp_payload);
130 return sidc != OSMO_GSM631_SID_CLASS_SPEECH;
131}
132
133bool osmo_fr_sid_preen(uint8_t *rtp_payload);
134bool osmo_efr_sid_preen(uint8_t *rtp_payload);
135
136void osmo_fr_sid_reset(uint8_t *rtp_payload);
137void osmo_hr_sid_reset(uint8_t *rtp_payload);
138void osmo_efr_sid_reset(uint8_t *rtp_payload);
139
140int osmo_amr_rtp_enc(uint8_t *payload, uint8_t cmr, enum osmo_amr_type ft,
141 enum osmo_amr_quality bfi);
142int osmo_amr_rtp_dec(const uint8_t *payload, int payload_len, uint8_t *cmr,
143 int8_t *cmi, enum osmo_amr_type *ft,
144 enum osmo_amr_quality *bfi, int8_t *sti);
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:112
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
const uint16_t gsm690_10_2_bitorder[]
Definition: gsm690.c:73
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
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
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:371
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
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:333
const uint16_t gsm690_7_4_bitorder[]
Definition: gsm690.c:124
const uint8_t osmo_gsm611_silence_frame[GSM_FR_BYTES]
Definition: gsm610.c:305
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:397
const uint16_t gsm690_5_9_bitorder[]
Definition: gsm690.c:167
const uint16_t gsm690_4_75_bitorder[]
Definition: gsm690.c:204
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
#define GSM_FR_BYTES
Definition: codec.h:12
const uint16_t gsm690_5_15_bitorder[]
Definition: gsm690.c:186
static const char * osmo_amr_type_name(enum osmo_amr_type type)
Definition: codec.h:56
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
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
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:408
osmo_amr_type
Definition: codec.h:40
@ AMR_NO_DATA
Definition: codec.h:53
@ AMR_4_75
Definition: codec.h:41
@ AMR_12_2
Definition: codec.h:48
@ AMR_7_40
Definition: codec.h:45
@ AMR_10_2
Definition: codec.h:47
@ AMR_6_70
Definition: codec.h:44
@ AMR_GSM_EFR_SID
Definition: codec.h:50
@ AMR_PDC_EFR_SID
Definition: codec.h:52
@ AMR_SID
Definition: codec.h:49
@ AMR_5_90
Definition: codec.h:43
@ AMR_5_15
Definition: codec.h:42
@ AMR_7_95
Definition: codec.h:46
@ AMR_TDMA_EFR_SID
Definition: codec.h:51
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:320
static bool osmo_amr_is_speech(enum osmo_amr_type ft)
Check if given AMR Frame Type is a speech frame.
Definition: codec.h:73
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:360
osmo_gsm631_sid_class
Definition: codec.h:91
@ OSMO_GSM631_SID_CLASS_SPEECH
Definition: codec.h:92
@ OSMO_GSM631_SID_CLASS_VALID
Definition: codec.h:94
@ OSMO_GSM631_SID_CLASS_INVALID
Definition: codec.h:93
const struct value_string osmo_amr_type_names[]
Definition: gsm690.c:330
const uint16_t gsm690_7_95_bitorder[]
Definition: gsm690.c:101
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
const uint16_t gsm620_unvoiced_bitorder[]
Definition: gsm620.c:32
const uint16_t gsm610_bitorder[]
Definition: gsm610.c:36
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:125
const uint16_t gsm690_12_2_bitorder[]
Definition: gsm690.c:41
const uint16_t gsm690_6_7_bitorder[]
Definition: gsm690.c:146
osmo_amr_quality
Definition: codec.h:59
@ AMR_BAD
Definition: codec.h:60
@ AMR_GOOD
Definition: codec.h:61
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:278
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:282
const uint16_t gsm620_voiced_bitorder[]
Definition: gsm620.c:151
const uint16_t gsm660_bitorder[]
Definition: gsm660.c:38
enum osmo_sub_auth_type type
uint8_t ubit_t
const char * get_value_string(const struct value_string *vs, uint32_t val)