libosmocodec 1.11.0.4-1b755
Osmocom codec library
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules
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];
37extern const uint8_t osmo_gsm620_silence_frame[GSM_HR_BYTES];
38extern const uint8_t osmo_gsm620_homing_frame[GSM_HR_BYTES];
39extern const uint8_t osmo_gsm660_homing_frame[GSM_EFR_BYTES];
40
41extern const struct value_string osmo_amr_type_names[];
42
57};
58
59static inline const char *osmo_amr_type_name(enum osmo_amr_type type)
61
64 AMR_GOOD = 1
65};
66
67extern const uint8_t gsm690_bitlength[AMR_NO_DATA+1];
68
69int osmo_amr_s_to_d(ubit_t *out, const ubit_t *in, uint16_t n_bits, enum osmo_amr_type amr_mode);
70int osmo_amr_d_to_s(ubit_t *out, const ubit_t *in, uint16_t n_bits, enum osmo_amr_type amr_mode);
71
76static inline bool osmo_amr_is_speech(enum osmo_amr_type ft)
77{
78 switch (ft) {
79 case AMR_4_75:
80 case AMR_5_15:
81 case AMR_5_90:
82 case AMR_6_70:
83 case AMR_7_40:
84 case AMR_7_95:
85 case AMR_10_2:
86 case AMR_12_2:
87 return true;
88 default:
89 return false;
90 }
91}
92
93/* SID ternary classification per GSM 06.31 & 06.81 section 6.1.1 */
98};
99
100bool osmo_fr_check_sid(const uint8_t *rtp_payload, size_t payload_len);
101bool osmo_hr_check_sid(const uint8_t *rtp_payload, size_t payload_len);
102bool osmo_efr_check_sid(const uint8_t *rtp_payload, size_t payload_len);
103
104enum osmo_gsm631_sid_class osmo_fr_sid_classify(const uint8_t *rtp_payload);
105enum osmo_gsm631_sid_class osmo_efr_sid_classify(const uint8_t *rtp_payload);
106enum osmo_gsm631_sid_class osmo_hr_sid_classify(const uint8_t *rtp_payload,
107 bool bci_flag,
108 bool *bfi_from_bci);
109
115static inline bool osmo_fr_is_any_sid(const uint8_t *rtp_payload)
116{
117 enum osmo_gsm631_sid_class sidc;
118
119 sidc = osmo_fr_sid_classify(rtp_payload);
120 return sidc != OSMO_GSM631_SID_CLASS_SPEECH;
121}
122
128static inline bool osmo_efr_is_any_sid(const uint8_t *rtp_payload)
129{
130 enum osmo_gsm631_sid_class sidc;
131
132 sidc = osmo_efr_sid_classify(rtp_payload);
133 return sidc != OSMO_GSM631_SID_CLASS_SPEECH;
134}
135
136bool osmo_fr_sid_preen(uint8_t *rtp_payload);
137bool osmo_efr_sid_preen(uint8_t *rtp_payload);
138
139void osmo_fr_sid_reset(uint8_t *rtp_payload);
140void osmo_hr_sid_reset(uint8_t *rtp_payload);
141void osmo_efr_sid_reset(uint8_t *rtp_payload);
142
143int osmo_amr_rtp_enc(uint8_t *payload, uint8_t cmr, enum osmo_amr_type ft,
144 enum osmo_amr_quality bfi);
145int osmo_amr_rtp_dec(const uint8_t *payload, int payload_len, uint8_t *cmr,
146 int8_t *cmi, enum osmo_amr_type *ft,
147 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:115
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
#define GSM_EFR_BYTES
Definition: codec.h:16
const uint8_t osmo_gsm620_homing_frame[GSM_HR_BYTES]
Definition: gsm620.c:292
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:386
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
#define GSM_HR_BYTES
Definition: codec.h:14
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
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:412
const uint8_t osmo_gsm620_silence_frame[GSM_HR_BYTES]
Definition: gsm620.c:278
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:59
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
const uint8_t osmo_gsm660_homing_frame[GSM_EFR_BYTES]
Definition: gsm660.c:269
osmo_amr_type
Definition: codec.h:43
@ AMR_NO_DATA
Definition: codec.h:56
@ AMR_4_75
Definition: codec.h:44
@ AMR_12_2
Definition: codec.h:51
@ AMR_7_40
Definition: codec.h:48
@ AMR_10_2
Definition: codec.h:50
@ AMR_6_70
Definition: codec.h:47
@ AMR_GSM_EFR_SID
Definition: codec.h:53
@ AMR_PDC_EFR_SID
Definition: codec.h:55
@ AMR_SID
Definition: codec.h:52
@ AMR_5_90
Definition: codec.h:46
@ AMR_5_15
Definition: codec.h:45
@ AMR_7_95
Definition: codec.h:49
@ AMR_TDMA_EFR_SID
Definition: codec.h:54
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
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
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:94
@ OSMO_GSM631_SID_CLASS_SPEECH
Definition: codec.h:95
@ OSMO_GSM631_SID_CLASS_VALID
Definition: codec.h:97
@ OSMO_GSM631_SID_CLASS_INVALID
Definition: codec.h:96
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:128
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:62
@ AMR_BAD
Definition: codec.h:63
@ AMR_GOOD
Definition: codec.h:64
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
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
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)