sdp.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  1. /*
  2. * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
  3. * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #ifndef __PJMEDIA_SDP_H__
  20. #define __PJMEDIA_SDP_H__
  21. /**
  22. * @file sdp.h
  23. * @brief SDP header file.
  24. */
  25. #include <pjmedia/types.h>
  26. #include <pj/sock.h>
  27. /**
  28. * @defgroup PJMEDIA_SDP SDP Parsing and Data Structure
  29. * @ingroup PJMEDIA_SESSION
  30. * @brief SDP data structure representation and parsing
  31. * @{
  32. *
  33. * The basic SDP session descriptor and elements are described in header
  34. * file <b><pjmedia/sdp.h></b>. This file contains declaration for
  35. * SDP session descriptor and SDP media descriptor, along with their
  36. * attributes. This file also declares functions to parse SDP message.
  37. */
  38. PJ_BEGIN_DECL
  39. /**
  40. * The PJMEDIA_MAX_SDP_FMT macro defines maximum format in a media line.
  41. */
  42. #ifndef PJMEDIA_MAX_SDP_FMT
  43. # define PJMEDIA_MAX_SDP_FMT 32
  44. #endif
  45. /**
  46. * The PJMEDIA_MAX_SDP_BANDW macro defines maximum bandwidth information
  47. * lines in a media line.
  48. */
  49. #ifndef PJMEDIA_MAX_SDP_BANDW
  50. # define PJMEDIA_MAX_SDP_BANDW 4
  51. #endif
  52. /**
  53. * The PJMEDIA_MAX_SDP_ATTR macro defines maximum SDP attributes in media and
  54. * session descriptor.
  55. */
  56. #ifndef PJMEDIA_MAX_SDP_ATTR
  57. # define PJMEDIA_MAX_SDP_ATTR (PJMEDIA_MAX_SDP_FMT*2 + 4)
  58. #endif
  59. /**
  60. * The PJMEDIA_MAX_SDP_MEDIA macro defines maximum SDP media lines in a
  61. * SDP session descriptor.
  62. */
  63. #ifndef PJMEDIA_MAX_SDP_MEDIA
  64. # define PJMEDIA_MAX_SDP_MEDIA 16
  65. #endif
  66. /* **************************************************************************
  67. * SDP ATTRIBUTES
  68. ***************************************************************************
  69. */
  70. /**
  71. * Generic representation of attribute.
  72. */
  73. struct pjmedia_sdp_attr
  74. {
  75. pj_str_t name; /**< Attribute name. */
  76. pj_str_t value; /**< Attribute value. */
  77. };
  78. /**
  79. * @see pjmedia_sdp_attr
  80. */
  81. typedef struct pjmedia_sdp_attr pjmedia_sdp_attr;
  82. /**
  83. * Create SDP attribute.
  84. *
  85. * @param pool Pool to create the attribute.
  86. * @param name Attribute name.
  87. * @param value Optional attribute value.
  88. *
  89. * @return The new SDP attribute.
  90. */
  91. PJ_DECL(pjmedia_sdp_attr*) pjmedia_sdp_attr_create(pj_pool_t *pool,
  92. const char *name,
  93. const pj_str_t *value);
  94. /**
  95. * Clone attribute
  96. *
  97. * @param pool Pool to be used.
  98. * @param attr The attribute to clone.
  99. *
  100. * @return New attribute as cloned from the attribute.
  101. */
  102. PJ_DECL(pjmedia_sdp_attr*) pjmedia_sdp_attr_clone(pj_pool_t *pool,
  103. const pjmedia_sdp_attr*attr);
  104. /**
  105. * Find the first attribute with the specified type.
  106. *
  107. * @param count Number of attributes in the array.
  108. * @param attr_array Array of attributes.
  109. * @param name Attribute name to find.
  110. * @param fmt Optional string to indicate which payload format
  111. * to find for \a rtpmap and \a fmt attributes. For other
  112. * types of attributes, the value should be NULL.
  113. *
  114. * @return The specified attribute, or NULL if it can't be found.
  115. *
  116. * @see pjmedia_sdp_attr_find2, pjmedia_sdp_media_find_attr,
  117. * pjmedia_sdp_media_find_attr2
  118. */
  119. PJ_DECL(pjmedia_sdp_attr*)
  120. pjmedia_sdp_attr_find(unsigned count,
  121. pjmedia_sdp_attr *const attr_array[],
  122. const pj_str_t *name, const pj_str_t *fmt);
  123. /**
  124. * Find the first attribute with the specified type.
  125. *
  126. * @param count Number of attributes in the array.
  127. * @param attr_array Array of attributes.
  128. * @param name Attribute name to find.
  129. * @param fmt Optional string to indicate which payload format
  130. * to find for \a rtpmap and \a fmt attributes. For other
  131. * types of attributes, the value should be NULL.
  132. *
  133. * @return The specified attribute, or NULL if it can't be found.
  134. *
  135. * @see pjmedia_sdp_attr_find, pjmedia_sdp_media_find_attr,
  136. * pjmedia_sdp_media_find_attr2
  137. */
  138. PJ_DECL(pjmedia_sdp_attr*)
  139. pjmedia_sdp_attr_find2(unsigned count,
  140. pjmedia_sdp_attr *const attr_array[],
  141. const char *name, const pj_str_t *fmt);
  142. /**
  143. * Add a new attribute to array of attributes.
  144. *
  145. * @param count Number of attributes in the array.
  146. * @param attr_array Array of attributes.
  147. * @param attr The attribute to add.
  148. *
  149. * @return PJ_SUCCESS or the error code.
  150. *
  151. * @see pjmedia_sdp_media_add_attr
  152. */
  153. PJ_DECL(pj_status_t) pjmedia_sdp_attr_add(unsigned *count,
  154. pjmedia_sdp_attr *attr_array[],
  155. pjmedia_sdp_attr *attr);
  156. /**
  157. * Remove all attributes with the specified name in array of attributes.
  158. *
  159. * @param count Number of attributes in the array.
  160. * @param attr_array Array of attributes.
  161. * @param name Attribute name to find.
  162. *
  163. * @return Number of attributes removed.
  164. *
  165. * @see pjmedia_sdp_media_remove_all_attr
  166. */
  167. PJ_DECL(unsigned) pjmedia_sdp_attr_remove_all(unsigned *count,
  168. pjmedia_sdp_attr *attr_array[],
  169. const char *name);
  170. /**
  171. * Remove the specified attribute from the attribute array.
  172. *
  173. * @param count Number of attributes in the array.
  174. * @param attr_array Array of attributes.
  175. * @param attr The attribute instance to remove.
  176. *
  177. * @return PJ_SUCCESS when attribute has been removed, or
  178. * PJ_ENOTFOUND when the attribute can not be found.
  179. *
  180. * @see pjmedia_sdp_media_remove_attr
  181. */
  182. PJ_DECL(pj_status_t) pjmedia_sdp_attr_remove(unsigned *count,
  183. pjmedia_sdp_attr *attr_array[],
  184. pjmedia_sdp_attr *attr);
  185. /**
  186. * This structure declares SDP \a rtpmap attribute.
  187. */
  188. struct pjmedia_sdp_rtpmap
  189. {
  190. pj_str_t pt; /**< Payload type. */
  191. pj_str_t enc_name; /**< Encoding name. */
  192. unsigned clock_rate; /**< Clock rate. */
  193. pj_str_t param; /**< Parameter. */
  194. };
  195. /**
  196. * @see pjmedia_sdp_rtpmap
  197. */
  198. typedef struct pjmedia_sdp_rtpmap pjmedia_sdp_rtpmap;
  199. /**
  200. * Convert generic attribute to SDP \a rtpmap. This function allocates
  201. * a new attribute and call #pjmedia_sdp_attr_get_rtpmap().
  202. *
  203. * @param pool Pool used to create the rtpmap attribute.
  204. * @param attr Generic attribute to be converted to rtpmap, which
  205. * name must be "rtpmap".
  206. * @param p_rtpmap Pointer to receive SDP rtpmap attribute.
  207. *
  208. * @return PJ_SUCCESS if the attribute can be successfully
  209. * converted to \a rtpmap type.
  210. *
  211. * @see pjmedia_sdp_attr_get_rtpmap
  212. */
  213. PJ_DECL(pj_status_t) pjmedia_sdp_attr_to_rtpmap(pj_pool_t *pool,
  214. const pjmedia_sdp_attr *attr,
  215. pjmedia_sdp_rtpmap **p_rtpmap);
  216. /**
  217. * Get the rtpmap representation of the same SDP attribute.
  218. *
  219. * @param attr Generic attribute to be converted to rtpmap, which
  220. * name must be "rtpmap". Attribute value must be
  221. * terminated with a NULL, CR, or LF character.
  222. * @param rtpmap SDP \a rtpmap attribute to be initialized.
  223. *
  224. * @return PJ_SUCCESS if the attribute can be successfully
  225. * converted to \a rtpmap attribute.
  226. *
  227. * @see pjmedia_sdp_attr_to_rtpmap
  228. */
  229. PJ_DECL(pj_status_t) pjmedia_sdp_attr_get_rtpmap(const pjmedia_sdp_attr *attr,
  230. pjmedia_sdp_rtpmap *rtpmap);
  231. /**
  232. * Convert \a rtpmap attribute to generic attribute.
  233. *
  234. * @param pool Pool to be used.
  235. * @param rtpmap The \a rtpmap attribute.
  236. * @param p_attr Pointer to receive the generic SDP attribute.
  237. *
  238. * @return PJ_SUCCESS on success.
  239. */
  240. PJ_DECL(pj_status_t)
  241. pjmedia_sdp_rtpmap_to_attr( pj_pool_t *pool,
  242. const pjmedia_sdp_rtpmap *rtpmap,
  243. pjmedia_sdp_attr **p_attr);
  244. /**
  245. * This structure describes SDP \a fmtp attribute.
  246. */
  247. typedef struct pjmedia_sdp_fmtp
  248. {
  249. pj_str_t fmt; /**< Format type. */
  250. pj_str_t fmt_param; /**< Format specific parameter. */
  251. } pjmedia_sdp_fmtp;
  252. /**
  253. * Get the fmtp representation of the same SDP attribute.
  254. *
  255. * @param attr Generic attribute to be converted to fmtp, which
  256. * name must be "fmtp".
  257. * @param fmtp SDP fmtp attribute to be initialized.
  258. *
  259. * @return PJ_SUCCESS on success.
  260. */
  261. PJ_DECL(pj_status_t) pjmedia_sdp_attr_get_fmtp(const pjmedia_sdp_attr *attr,
  262. pjmedia_sdp_fmtp *fmtp);
  263. /**
  264. * This structure describes SDP \a rtcp attribute.
  265. */
  266. typedef struct pjmedia_sdp_rtcp_attr
  267. {
  268. unsigned port; /**< RTCP port number. */
  269. pj_str_t net_type; /**< Optional network type. */
  270. pj_str_t addr_type; /**< Optional address type. */
  271. pj_str_t addr; /**< Optional address. */
  272. } pjmedia_sdp_rtcp_attr;
  273. /**
  274. * Parse a generic SDP attribute to get SDP rtcp attribute values.
  275. *
  276. * @param attr Generic attribute to be converted to rtcp, which
  277. * name must be "rtcp".
  278. * @param rtcp SDP rtcp attribute to be initialized.
  279. *
  280. * @return PJ_SUCCESS on success.
  281. */
  282. PJ_DECL(pj_status_t) pjmedia_sdp_attr_get_rtcp(const pjmedia_sdp_attr *attr,
  283. pjmedia_sdp_rtcp_attr *rtcp);
  284. /**
  285. * Create a=rtcp attribute.
  286. *
  287. * @param pool Pool to create the attribute.
  288. * @param a Socket address.
  289. *
  290. * @return SDP RTCP attribute.
  291. */
  292. PJ_DECL(pjmedia_sdp_attr*) pjmedia_sdp_attr_create_rtcp(pj_pool_t *pool,
  293. const pj_sockaddr *a);
  294. /**
  295. * This structure describes SDP \a ssrc attribute.
  296. */
  297. typedef struct pjmedia_sdp_ssrc_attr
  298. {
  299. pj_uint32_t ssrc; /**< RTP SSRC. */
  300. pj_str_t cname; /**< RTCP CNAME. */
  301. } pjmedia_sdp_ssrc_attr;
  302. /**
  303. * Parse a generic SDP attribute to get SDP ssrc attribute values.
  304. *
  305. * @param attr Generic attribute to be converted to ssrc, which
  306. * name must be "ssrc".
  307. * @param rtcp SDP ssrc attribute to be initialized.
  308. *
  309. * @return PJ_SUCCESS on success.
  310. */
  311. PJ_DECL(pj_status_t) pjmedia_sdp_attr_get_ssrc(const pjmedia_sdp_attr *attr,
  312. pjmedia_sdp_ssrc_attr *rtcp);
  313. /**
  314. * Create a=ssrc attribute.
  315. *
  316. * @param pool Pool to create the attribute.
  317. * @param ssrc SSRC identifier.
  318. * @param cname CNAME.
  319. *
  320. * @return SDP SSRC attribute.
  321. */
  322. PJ_DECL(pjmedia_sdp_attr*) pjmedia_sdp_attr_create_ssrc(pj_pool_t *pool,
  323. pj_uint32_t ssrc,
  324. const pj_str_t *cname);
  325. /* **************************************************************************
  326. * SDP CONNECTION INFO
  327. ****************************************************************************
  328. */
  329. /**
  330. * This structure describes SDP connection info ("c=" line).
  331. */
  332. struct pjmedia_sdp_conn
  333. {
  334. pj_str_t net_type; /**< Network type ("IN"). */
  335. pj_str_t addr_type; /**< Address type ("IP4", "IP6"). */
  336. pj_str_t addr; /**< The address. */
  337. pj_uint8_t ttl; /**< Multicast address TTL */
  338. pj_uint8_t no_addr; /**< Multicast number of addresses */
  339. };
  340. /**
  341. * @see pjmedia_sdp_conn
  342. */
  343. typedef struct pjmedia_sdp_conn pjmedia_sdp_conn;
  344. /**
  345. * Clone connection info.
  346. *
  347. * @param pool Pool to allocate memory for the new connection info.
  348. * @param rhs The connection into to clone.
  349. *
  350. * @return The new connection info.
  351. */
  352. PJ_DECL(pjmedia_sdp_conn*) pjmedia_sdp_conn_clone(pj_pool_t *pool,
  353. const pjmedia_sdp_conn *rhs);
  354. /**
  355. * Compare connection info.
  356. *
  357. * @param conn1 The first connection info to compare.
  358. * @param conn2 The second connection info to compare.
  359. * @param option Comparison option, which should be zero for now.
  360. *
  361. * @return PJ_SUCCESS when both connection info are equal, otherwise
  362. * returns PJMEDIA_SDP_ECONNNOTEQUAL.
  363. */
  364. PJ_DECL(pj_status_t) pjmedia_sdp_conn_cmp(const pjmedia_sdp_conn *conn1,
  365. const pjmedia_sdp_conn *conn2,
  366. unsigned option);
  367. /* **************************************************************************
  368. * SDP BANDWIDTH INFO
  369. ****************************************************************************
  370. */
  371. /**
  372. * This structure describes SDP bandwidth info ("b=" line).
  373. */
  374. typedef struct pjmedia_sdp_bandw
  375. {
  376. pj_str_t modifier; /**< Bandwidth modifier. */
  377. pj_uint32_t value; /**< Bandwidth value. */
  378. } pjmedia_sdp_bandw;
  379. /**
  380. * Clone bandwidth info.
  381. *
  382. * @param pool Pool to allocate memory for the new bandwidth info.
  383. * @param rhs The bandwidth into to clone.
  384. *
  385. * @return The new bandwidth info.
  386. */
  387. PJ_DECL(pjmedia_sdp_bandw*)
  388. pjmedia_sdp_bandw_clone(pj_pool_t *pool, const pjmedia_sdp_bandw *rhs);
  389. /* **************************************************************************
  390. * SDP MEDIA INFO/LINE
  391. ****************************************************************************
  392. */
  393. /**
  394. * This structure describes SDP media descriptor. A SDP media descriptor
  395. * starts with "m=" line and contains the media attributes and optional
  396. * connection line.
  397. */
  398. struct pjmedia_sdp_media
  399. {
  400. /** Media descriptor line ("m=" line) */
  401. struct
  402. {
  403. pj_str_t media; /**< Media type ("audio", "video") */
  404. pj_uint16_t port; /**< Port number. */
  405. unsigned port_count; /**< Port count, used only when >2 */
  406. pj_str_t transport; /**< Transport ("RTP/AVP") */
  407. unsigned fmt_count; /**< Number of formats. */
  408. pj_str_t fmt[PJMEDIA_MAX_SDP_FMT]; /**< Media formats. */
  409. } desc;
  410. pjmedia_sdp_conn *conn; /**< Optional connection info. */
  411. unsigned bandw_count; /**< Number of bandwidth info. */
  412. pjmedia_sdp_bandw *bandw[PJMEDIA_MAX_SDP_BANDW]; /**< Bandwidth info. */
  413. unsigned attr_count; /**< Number of attributes. */
  414. pjmedia_sdp_attr *attr[PJMEDIA_MAX_SDP_ATTR]; /**< Attributes. */
  415. };
  416. /**
  417. * @see pjmedia_sdp_media
  418. */
  419. typedef struct pjmedia_sdp_media pjmedia_sdp_media;
  420. /**
  421. * Print media description to a buffer.
  422. *
  423. * @param media The media description.
  424. * @param buf The buffer.
  425. * @param size The buffer length.
  426. *
  427. * @return The length printed, or -1 if the buffer is too
  428. * short.
  429. */
  430. PJ_DECL(int) pjmedia_sdp_media_print(const pjmedia_sdp_media *media, char *buf, pj_size_t size);
  431. /**
  432. * Clone SDP media description.
  433. *
  434. * @param pool Pool to allocate memory for the new media description.
  435. * @param rhs The media descriptin to clone.
  436. *
  437. * @return New media description.
  438. */
  439. PJ_DECL(pjmedia_sdp_media*)
  440. pjmedia_sdp_media_clone( pj_pool_t *pool,
  441. const pjmedia_sdp_media *rhs);
  442. /**
  443. * Print attribute to a buffer.
  444. *
  445. * @param attr The attribute.
  446. * @param buf The buffer.
  447. * @param size The buffer length.
  448. *
  449. * @return The length printed, or -1 if the buffer is too
  450. * short.
  451. */
  452. PJ_DECL(int) pjmedia_sdp_attr_print(const pjmedia_sdp_attr *attr, char *buf, pj_size_t size);
  453. /**
  454. * Find the first occurence of the specified attribute name in the media
  455. * descriptor. Optionally the format may be specified.
  456. *
  457. * @param m The SDP media description.
  458. * @param name Attribute name to find.
  459. * @param fmt Optional payload type to match in the
  460. * attribute list, when the attribute is \a rtpmap
  461. * or \a fmtp. For other types of SDP attributes, this
  462. * value should be NULL.
  463. *
  464. * @return The first instance of the specified attribute or NULL.
  465. */
  466. PJ_DECL(pjmedia_sdp_attr*)
  467. pjmedia_sdp_media_find_attr(const pjmedia_sdp_media *m,
  468. const pj_str_t *name, const pj_str_t *fmt);
  469. /**
  470. * Find the first occurence of the specified attribute name in the SDP media
  471. * descriptor. Optionally the format may be specified.
  472. *
  473. * @param m The SDP media description.
  474. * @param name Attribute name to find.
  475. * @param fmt Optional payload type to match in the
  476. * attribute list, when the attribute is \a rtpmap
  477. * or \a fmtp. For other types of SDP attributes, this
  478. * value should be NULL.
  479. *
  480. * @return The first instance of the specified attribute or NULL.
  481. */
  482. PJ_DECL(pjmedia_sdp_attr*)
  483. pjmedia_sdp_media_find_attr2(const pjmedia_sdp_media *m,
  484. const char *name, const pj_str_t *fmt);
  485. /**
  486. * Add new attribute to the media descriptor.
  487. *
  488. * @param m The SDP media description.
  489. * @param attr Attribute to add.
  490. *
  491. * @return PJ_SUCCESS or the appropriate error code.
  492. */
  493. PJ_DECL(pj_status_t) pjmedia_sdp_media_add_attr(pjmedia_sdp_media *m,
  494. pjmedia_sdp_attr *attr);
  495. /**
  496. * Remove all attributes with the specified name from the SDP media
  497. * descriptor.
  498. *
  499. * @param m The SDP media description.
  500. * @param name Attribute name to remove.
  501. *
  502. * @return The number of attributes removed.
  503. */
  504. PJ_DECL(unsigned)
  505. pjmedia_sdp_media_remove_all_attr(pjmedia_sdp_media *m,
  506. const char *name);
  507. /**
  508. * Remove the occurence of the specified attribute from the SDP media
  509. * descriptor.
  510. *
  511. * @param m The SDP media descriptor.
  512. * @param attr The attribute to find and remove.
  513. *
  514. * @return PJ_SUCCESS if the attribute can be found and has
  515. * been removed from the array.
  516. */
  517. PJ_DECL(pj_status_t)
  518. pjmedia_sdp_media_remove_attr(pjmedia_sdp_media *m,
  519. pjmedia_sdp_attr *attr);
  520. /**
  521. * Compare two SDP media for equality.
  522. *
  523. * @param sd1 The first SDP media to compare.
  524. * @param sd2 The second SDP media to compare.
  525. * @param option Comparison option, which should be zero for now.
  526. *
  527. * @return PJ_SUCCESS when both SDP medias are equal, or the
  528. * appropriate status code describing which part of
  529. * the descriptors that are not equal.
  530. */
  531. PJ_DECL(pj_status_t) pjmedia_sdp_media_cmp(const pjmedia_sdp_media *sd1,
  532. const pjmedia_sdp_media *sd2,
  533. unsigned option);
  534. /**
  535. * Compare two media transports for compatibility.
  536. *
  537. * @param t1 The first media transport to compare.
  538. * @param t2 The second media transport to compare.
  539. *
  540. * @return PJ_SUCCESS when both media transports are compatible,
  541. * otherwise returns PJMEDIA_SDP_ETPORTNOTEQUAL.
  542. */
  543. PJ_DECL(pj_status_t) pjmedia_sdp_transport_cmp(const pj_str_t *t1,
  544. const pj_str_t *t2);
  545. /**
  546. * Get media transport protocol info, i.e: base transport and profiles,
  547. * from the provided SDP media transport name string.
  548. *
  549. * @param tp The SDP media transport name.
  550. *
  551. * @return Media transport info, combination of transport protocol
  552. * and profile bit flag defined in pjmedia_tp_proto.
  553. */
  554. PJ_DECL(pj_uint32_t) pjmedia_sdp_transport_get_proto(const pj_str_t *tp);
  555. /**
  556. * Deactivate SDP media.
  557. *
  558. * @param pool Memory pool to allocate memory from.
  559. * @param m The SDP media to deactivate.
  560. *
  561. * @return PJ_SUCCESS when SDP media successfully deactivated,
  562. * otherwise appropriate status code returned.
  563. */
  564. PJ_DECL(pj_status_t) pjmedia_sdp_media_deactivate(pj_pool_t *pool,
  565. pjmedia_sdp_media *m);
  566. /**
  567. * Clone SDP media description and deactivate the new SDP media.
  568. *
  569. * @param pool Memory pool to allocate memory for the clone.
  570. * @param rhs The SDP media to clone.
  571. *
  572. * @return New media descrption with deactivated indication.
  573. */
  574. PJ_DECL(pjmedia_sdp_media*) pjmedia_sdp_media_clone_deactivate(
  575. pj_pool_t *pool,
  576. const pjmedia_sdp_media *rhs);
  577. /* **************************************************************************
  578. * SDP SESSION DESCRIPTION
  579. ****************************************************************************
  580. */
  581. /**
  582. * This structure describes SDP session description. A SDP session descriptor
  583. * contains complete information about a session, and normally is exchanged
  584. * with remote media peer using signaling protocol such as SIP.
  585. */
  586. struct pjmedia_sdp_session
  587. {
  588. /** Session origin (o= line) */
  589. struct
  590. {
  591. pj_str_t user; /**< User */
  592. pj_uint_t id; /**< Session ID */
  593. pj_uint_t version; /**< Session version */
  594. pj_str_t net_type; /**< Network type ("IN") */
  595. pj_str_t addr_type; /**< Address type ("IP4", "IP6") */
  596. pj_str_t addr; /**< The address. */
  597. } origin;
  598. pj_str_t name; /**< Subject line (s=) */
  599. pjmedia_sdp_conn *conn; /**< Connection line (c=) */
  600. unsigned bandw_count; /**< Number of bandwidth info (b=) */
  601. pjmedia_sdp_bandw *bandw[PJMEDIA_MAX_SDP_BANDW];
  602. /**< Bandwidth info array (b=) */
  603. /** Session time (t= line) */
  604. struct
  605. {
  606. pj_uint_t start; /**< Start time. */
  607. pj_uint_t stop; /**< Stop time. */
  608. } time;
  609. unsigned attr_count; /**< Number of attributes. */
  610. pjmedia_sdp_attr *attr[PJMEDIA_MAX_SDP_ATTR]; /**< Attributes array. */
  611. unsigned media_count; /**< Number of media. */
  612. pjmedia_sdp_media *media[PJMEDIA_MAX_SDP_MEDIA]; /**< Media array. */
  613. };
  614. /**
  615. * @see pjmedia_sdp_session
  616. */
  617. typedef struct pjmedia_sdp_session pjmedia_sdp_session;
  618. /**
  619. * Parse SDP message.
  620. *
  621. * Note that the input message buffer MUST be NULL terminated and have
  622. * length at least len+1 (len MUST NOT include the NULL terminator).
  623. *
  624. * @param pool The pool to allocate SDP session description.
  625. * @param buf The message buffer, MUST be NULL terminated.
  626. * @param len The length of the message, excluding NULL terminator.
  627. * @param p_sdp Pointer to receive the SDP session descriptor.
  628. *
  629. * @return PJ_SUCCESS if message was successfully parsed into
  630. * SDP session descriptor.
  631. */
  632. PJ_DECL(pj_status_t) pjmedia_sdp_parse( pj_pool_t *pool,
  633. char *buf, pj_size_t len,
  634. pjmedia_sdp_session **p_sdp );
  635. /**
  636. * Print SDP description to a buffer.
  637. *
  638. * @param sdp The SDP session description.
  639. * @param buf The buffer.
  640. * @param size The buffer length.
  641. *
  642. * @return the length printed, or -1 if the buffer is too
  643. * short.
  644. */
  645. PJ_DECL(int) pjmedia_sdp_print( const pjmedia_sdp_session *sdp,
  646. char *buf, pj_size_t size);
  647. /**
  648. * Perform semantic validation for the specified SDP session descriptor.
  649. * This function perform validation beyond just syntactic verification,
  650. * such as to verify the value of network type and address type, check
  651. * the connection line, and verify that \a rtpmap attribute is present
  652. * when dynamic payload type is used.
  653. *
  654. * @param sdp The SDP session descriptor to validate.
  655. *
  656. * @return PJ_SUCCESS on success.
  657. */
  658. PJ_DECL(pj_status_t) pjmedia_sdp_validate(const pjmedia_sdp_session *sdp);
  659. /**
  660. * Perform semantic validation for the specified SDP session descriptor.
  661. * This function perform validation beyond just syntactic verification,
  662. * such as to verify the value of network type and address type, check
  663. * the connection line, and verify that \a rtpmap attribute is present
  664. * when dynamic payload type is used.
  665. *
  666. * @param sdp The SDP session descriptor to validate.
  667. * @param strict Flag whether the check should be strict, i.e: allow
  668. * media without connection line when port is zero.
  669. *
  670. * @return PJ_SUCCESS on success.
  671. */
  672. PJ_DECL(pj_status_t) pjmedia_sdp_validate2(const pjmedia_sdp_session *sdp,
  673. pj_bool_t strict);
  674. /**
  675. * Clone SDP session descriptor.
  676. *
  677. * @param pool The pool used to clone the session.
  678. * @param sdp The SDP session to clone.
  679. *
  680. * @return New SDP session.
  681. */
  682. PJ_DECL(pjmedia_sdp_session*)
  683. pjmedia_sdp_session_clone( pj_pool_t *pool,
  684. const pjmedia_sdp_session *sdp);
  685. /**
  686. * Compare two SDP session for equality.
  687. *
  688. * @param sd1 The first SDP session to compare.
  689. * @param sd2 The second SDP session to compare.
  690. * @param option Must be zero for now.
  691. *
  692. * @return PJ_SUCCESS when both SDPs are equal, or otherwise
  693. * the status code indicates which part of the session
  694. * descriptors are not equal.
  695. */
  696. PJ_DECL(pj_status_t) pjmedia_sdp_session_cmp(const pjmedia_sdp_session *sd1,
  697. const pjmedia_sdp_session *sd2,
  698. unsigned option);
  699. /**
  700. * Add new attribute to the session descriptor.
  701. *
  702. * @param s The SDP session description.
  703. * @param attr Attribute to add.
  704. *
  705. * @return PJ_SUCCESS or the appropriate error code.
  706. */
  707. PJ_DECL(pj_status_t) pjmedia_sdp_session_add_attr(pjmedia_sdp_session *s,
  708. pjmedia_sdp_attr *attr);
  709. PJ_END_DECL
  710. /**
  711. * @}
  712. */
  713. #endif /* __PJMEDIA_SDP_H__ */