libosmocodec 1.9.0.196-9975
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);
103
109static inline bool osmo_fr_is_any_sid(const uint8_t *rtp_payload)
110{
111 enum osmo_gsm631_sid_class sidc;
112
113 sidc = osmo_fr_sid_classify(rtp_payload);
114 return sidc != OSMO_GSM631_SID_CLASS_SPEECH;
115}
116
122static inline bool osmo_efr_is_any_sid(const uint8_t *rtp_payload)
123{
124 enum osmo_gsm631_sid_class sidc;
125
126 sidc = osmo_efr_sid_classify(rtp_payload);
127 return sidc != OSMO_GSM631_SID_CLASS_SPEECH;
128}
129
130bool osmo_fr_sid_preen(uint8_t *rtp_payload);
131bool osmo_efr_sid_preen(uint8_t *rtp_payload);
132
133void osmo_fr_sid_reset(uint8_t *rtp_payload);
134void osmo_hr_sid_reset(uint8_t *rtp_payload);
135void osmo_efr_sid_reset(uint8_t *rtp_payload);
136
137int osmo_amr_rtp_enc(uint8_t *payload, uint8_t cmr, enum osmo_amr_type ft,
138 enum osmo_amr_quality bfi);
139int osmo_amr_rtp_dec(const uint8_t *payload, int payload_len, uint8_t *cmr,
140 int8_t *cmi, enum osmo_amr_type *ft,
141 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:109
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:311
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:34
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:122
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:274
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:153
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)