1 /**
2  * @file re_sdp.h  Interface to Session Description Protocol (SDP)
3  *
4  * Copyright (C) 2010 Creytiv.com
5  */
6 
7 
8 enum {
9 	SDP_VERSION = 0
10 };
11 
12 /** SDP Direction */
13 enum sdp_dir {
14 	SDP_INACTIVE = 0,
15 	SDP_RECVONLY = 1,
16 	SDP_SENDONLY = 2,
17 	SDP_SENDRECV = 3,
18 };
19 
20 /** SDP Bandwidth type */
21 enum sdp_bandwidth {
22 	SDP_BANDWIDTH_MIN = 0,
23 	SDP_BANDWIDTH_CT = 0,  /**< [kbit/s] Conference Total         */
24 	SDP_BANDWIDTH_AS,      /**< [kbit/s] Application Specific     */
25 	SDP_BANDWIDTH_RS,      /**< [bit/s] RTCP Senders (RFC 3556)   */
26 	SDP_BANDWIDTH_RR,      /**< [bit/s] RTCP Receivers (RFC 3556) */
27 	SDP_BANDWIDTH_TIAS,    /**< [bit/s] Transport Independent Application
28 				  Specific Maximum (RFC 3890) */
29 	SDP_BANDWIDTH_MAX,
30 };
31 
32 
33 struct sdp_format;
34 
35 typedef int(sdp_media_enc_h)(struct mbuf *mb, bool offer, void *arg);
36 typedef int(sdp_fmtp_enc_h)(struct mbuf *mb, const struct sdp_format *fmt,
37 			    bool offer, void *data);
38 typedef bool(sdp_fmtp_cmp_h)(const char *params1, const char *params2,
39 			     void *data);
40 typedef bool(sdp_format_h)(struct sdp_format *fmt, void *arg);
41 typedef bool(sdp_attr_h)(const char *name, const char *value, void *arg);
42 
43 /** SDP Format */
44 struct sdp_format {
45 	struct le le;
46 	char *id;
47 	char *params;
48 	char *rparams;
49 	char *name;
50 	sdp_fmtp_enc_h *ench;
51 	sdp_fmtp_cmp_h *cmph;
52 	void *data;
53 	bool ref;
54 	bool sup;
55 	int pt;
56 	uint32_t srate;
57 	uint8_t ch;
58 };
59 
60 
61 /* session */
62 struct sdp_session;
63 
64 int  sdp_session_alloc(struct sdp_session **sessp, const struct sa *laddr);
65 void sdp_session_set_laddr(struct sdp_session *sess, const struct sa *laddr);
66 void sdp_session_set_lbandwidth(struct sdp_session *sess,
67 				enum sdp_bandwidth type, int32_t bw);
68 int  sdp_session_set_lattr(struct sdp_session *sess, bool replace,
69 			   const char *name, const char *value, ...);
70 void sdp_session_del_lattr(struct sdp_session *sess, const char *name);
71 int32_t sdp_session_lbandwidth(const struct sdp_session *sess,
72 			       enum sdp_bandwidth type);
73 int32_t sdp_session_rbandwidth(const struct sdp_session *sess,
74 			       enum sdp_bandwidth type);
75 const char *sdp_session_rattr(const struct sdp_session *sess,
76 			      const char *name);
77 const char *sdp_session_rattr_apply(const struct sdp_session *sess,
78 				    const char *name,
79 				    sdp_attr_h *attrh, void *arg);
80 const struct list *sdp_session_medial(const struct sdp_session *sess,
81 				      bool local);
82 int  sdp_session_debug(struct re_printf *pf, const struct sdp_session *sess);
83 
84 
85 /* media */
86 struct sdp_media;
87 
88 int  sdp_media_add(struct sdp_media **mp, struct sdp_session *sess,
89 		   const char *name, uint16_t port, const char *proto);
90 int  sdp_media_set_alt_protos(struct sdp_media *m, unsigned protoc, ...);
91 void sdp_media_set_encode_handler(struct sdp_media *m, sdp_media_enc_h *ench,
92 				  void *arg);
93 void sdp_media_set_fmt_ignore(struct sdp_media *m, bool fmt_ignore);
94 void sdp_media_set_disabled(struct sdp_media *m, bool disabled);
95 void sdp_media_set_lport(struct sdp_media *m, uint16_t port);
96 void sdp_media_set_laddr(struct sdp_media *m, const struct sa *laddr);
97 void sdp_media_set_lbandwidth(struct sdp_media *m, enum sdp_bandwidth type,
98 			      int32_t bw);
99 void sdp_media_set_lport_rtcp(struct sdp_media *m, uint16_t port);
100 void sdp_media_set_laddr_rtcp(struct sdp_media *m, const struct sa *laddr);
101 void sdp_media_set_ldir(struct sdp_media *m, enum sdp_dir dir);
102 int  sdp_media_set_lattr(struct sdp_media *m, bool replace,
103 			 const char *name, const char *value, ...);
104 void sdp_media_del_lattr(struct sdp_media *m, const char *name);
105 const char *sdp_media_proto(const struct sdp_media *m);
106 uint16_t sdp_media_rport(const struct sdp_media *m);
107 const struct sa *sdp_media_raddr(const struct sdp_media *m);
108 const struct sa *sdp_media_laddr(const struct sdp_media *m);
109 void sdp_media_raddr_rtcp(const struct sdp_media *m, struct sa *raddr);
110 int32_t sdp_media_rbandwidth(const struct sdp_media *m,
111 			     enum sdp_bandwidth type);
112 enum sdp_dir sdp_media_ldir(const struct sdp_media *m);
113 enum sdp_dir sdp_media_rdir(const struct sdp_media *m);
114 enum sdp_dir sdp_media_dir(const struct sdp_media *m);
115 const struct sdp_format *sdp_media_lformat(const struct sdp_media *m, int pt);
116 const struct sdp_format *sdp_media_rformat(const struct sdp_media *m,
117 					   const char *name);
118 struct sdp_format *sdp_media_format(const struct sdp_media *m,
119 				    bool local, const char *id,
120 				    int pt, const char *name,
121 				    int32_t srate, int8_t ch);
122 struct sdp_format *sdp_media_format_apply(const struct sdp_media *m,
123 					  bool local, const char *id,
124 					  int pt, const char *name,
125 					  int32_t srate, int8_t ch,
126 					  sdp_format_h *fmth, void *arg);
127 const struct list *sdp_media_format_lst(const struct sdp_media *m, bool local);
128 const char *sdp_media_rattr(const struct sdp_media *m, const char *name);
129 const char *sdp_media_session_rattr(const struct sdp_media *m,
130 				    const struct sdp_session *sess,
131 				    const char *name);
132 const char *sdp_media_rattr_apply(const struct sdp_media *m, const char *name,
133 				  sdp_attr_h *attrh, void *arg);
134 const char *sdp_media_name(const struct sdp_media *m);
135 int  sdp_media_debug(struct re_printf *pf, const struct sdp_media *m);
136 
137 
138 /* format */
139 int  sdp_format_add(struct sdp_format **fmtp, struct sdp_media *m,
140 		    bool prepend, const char *id, const char *name,
141 		    uint32_t srate, uint8_t ch, sdp_fmtp_enc_h *ench,
142 		    sdp_fmtp_cmp_h *cmph, void *data, bool ref,
143 		    const char *params, ...);
144 int  sdp_format_set_params(struct sdp_format *fmt, const char *params, ...);
145 bool sdp_format_cmp(const struct sdp_format *fmt1,
146 		    const struct sdp_format *fmt2);
147 int  sdp_format_debug(struct re_printf *pf, const struct sdp_format *fmt);
148 
149 
150 /* encode/decode */
151 int sdp_encode(struct mbuf **mbp, struct sdp_session *sess, bool offer);
152 int sdp_decode(struct sdp_session *sess, struct mbuf *mb, bool offer);
153 
154 
155 /* strings */
156 const char *sdp_dir_name(enum sdp_dir dir);
157 const char *sdp_bandwidth_name(enum sdp_bandwidth type);
158 
159 
160 extern const char sdp_attr_fmtp[];
161 extern const char sdp_attr_maxptime[];
162 extern const char sdp_attr_ptime[];
163 extern const char sdp_attr_rtcp[];
164 extern const char sdp_attr_rtpmap[];
165 
166 extern const char sdp_media_audio[];
167 extern const char sdp_media_video[];
168 extern const char sdp_media_text[];
169 
170 extern const char sdp_proto_rtpavp[];
171 extern const char sdp_proto_rtpsavp[];
172 
173 
174 /* utility functions */
175 
176 /** RTP Header Extensions, as defined in RFC 5285 */
177 struct sdp_extmap {
178 	struct pl name;
179 	struct pl attrs;
180 	enum sdp_dir dir;
181 	bool dir_set;
182 	uint32_t id;
183 };
184 
185 int sdp_extmap_decode(struct sdp_extmap *ext, const char *val);
186