1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
#ifndef _RTPLIB_H_
#define _RTPLIB_H_
#include <stdint.h>
#include <stdbool.h>
#include "str.h"
#include "containers.h"
typedef const struct codec_def_s codec_def_t;
struct rtp_header {
unsigned char v_p_x_cc;
unsigned char m_pt;
uint16_t seq_num;
uint32_t timestamp;
uint32_t ssrc;
uint32_t csrc[];
} __attribute__ ((packed));
enum evs_bw {
EVS_BW_NB = 0,
EVS_BW_WB = 1,
EVS_BW_SWB = 2,
EVS_BW_FB = 3,
__EVS_BW_MAX,
EVS_BW_UNSPEC = -1,
};
union codec_format_options {
struct {
int interleaving;
unsigned int mode_set; // bitfield
int mode_change_period;
unsigned int octet_aligned:1;
unsigned int crc:1;
unsigned int robust_sorting:1;
unsigned int mode_change_neighbor:1;
} amr;
struct {
int mode;
} ilbc;
struct {
// EVS options
unsigned int min_br, max_br;
unsigned int min_br_send, max_br_send;
unsigned int min_br_recv, max_br_recv;
enum evs_bw min_bw, max_bw;
enum evs_bw min_bw_send, max_bw_send;
enum evs_bw min_bw_recv, max_bw_recv;
// AMR options
unsigned int mode_set; // bitfield
int mode_change_period;
// bit field options
unsigned int hf_only:1;
unsigned int amr_io:1;
unsigned int no_dtx:1;
unsigned int no_dtx_recv:1;
int cmr:2; // -1, 0, 1
// AMR bit options
unsigned int mode_change_neighbor:1;
} evs;
struct {
// 0 = default, 1 = set, -1 = not set (0)
int stereo_recv:2;
int stereo_send:2;
int fec_recv:2;
int fec_send:2;
// these are parsed out but ignored
int cbr:2;
int usedtx:2;
int maxplaybackrate;
int sprop_maxcapturerate;
int maxaveragebitrate;
int minptime; // obsolete
} opus;
};
struct rtp_codec_format {
union codec_format_options parsed;
bool fmtp_parsed:1; // set if fmtp string was successfully parsed
};
struct rtp_payload_type;
TYPED_GQUEUE(rtp_pt, struct rtp_payload_type)
G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(rtp_pt_q, rtp_pt_q_clear)
struct rtp_payload_type {
int payload_type;
int reverse_payload_type;
str encoding_with_params; // "opus/48000/2"
str encoding_with_full_params; // "opus/48000/1"
str encoding; // "opus"
unsigned int clock_rate; // 48000
str encoding_parameters; // "2"
int channels; // 2
str format_parameters; // value of a=fmtp
str codec_opts; // extra codec-specific options
GQueue rtcp_fb; // a=rtcp-fb:...
int ptime; // default from RFC
int bitrate;
codec_def_t *codec_def;
rtp_pt_list *prefs_link; // link in `codec_prefs` list
struct rtp_codec_format format; // parsed out fmtp
unsigned int for_transcoding:1;
unsigned int accepted:1;
unsigned int removed:1;
};
extern const struct rtp_payload_type rfc_rtp_payload_types[];
extern const int num_rfc_rtp_payload_types;
int rtp_payload(struct rtp_header **out, str *p, const str *s);
int rtp_padding(const struct rtp_header *header, str *payload);
const struct rtp_payload_type *rtp_get_rfc_payload_type(unsigned int type);
const struct rtp_payload_type *rtp_get_rfc_codec(const str *codec);
// if not `exact` then also returns true if `a` is compatible with `b`
// matches all params
__attribute__((nonnull(1, 2)))
bool rtp_payload_type_eq_exact(const struct rtp_payload_type *a, const struct rtp_payload_type *b);
__attribute__((nonnull(1, 2)))
bool rtp_payload_type_eq_compat(const struct rtp_payload_type *a, const struct rtp_payload_type *b);
// matches only basic params but not payload type number
__attribute__((nonnull(1, 2)))
bool rtp_payload_type_fmt_eq_nf(const struct rtp_payload_type *a, const struct rtp_payload_type *b);
// matches only basic params and payload type number
__attribute__((nonnull(1, 2)))
bool rtp_payload_type_eq_nf(const struct rtp_payload_type *, const struct rtp_payload_type *);
// matches all params except payload type number
__attribute__((nonnull(1, 2)))
int rtp_payload_type_fmt_cmp(const struct rtp_payload_type *a, const struct rtp_payload_type *b);
__attribute__((nonnull(1, 2)))
bool rtp_payload_type_fmt_eq_exact(const struct rtp_payload_type *a, const struct rtp_payload_type *b);
__attribute__((nonnull(1, 2)))
bool rtp_payload_type_fmt_eq_compat(const struct rtp_payload_type *a, const struct rtp_payload_type *b);
#endif
|