sdp_neg.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822
  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_NEG_H__
  20. #define __PJMEDIA_SDP_NEG_H__
  21. /**
  22. * @file sdp_neg.h
  23. * @brief SDP negotiator header file.
  24. */
  25. /**
  26. * @defgroup PJMEDIA_SDP_NEG SDP Negotiation State Machine (Offer/Answer Model, RFC 3264)
  27. * @ingroup PJMEDIA_SESSION
  28. * @brief SDP Negotiation State Machine (Offer/Answer Model, RFC 3264)
  29. * @{
  30. *
  31. * The header file <b><pjmedia/sdp_neg.h></b> contains the declaration
  32. * of SDP offer and answer negotiator. SDP offer and answer model is described
  33. * in RFC 3264 <b>"An Offer/Answer Model with Session Description Protocol
  34. * (SDP)"</b>.
  35. *
  36. * The SDP negotiator is represented with opaque type \a pjmedia_sdp_neg.
  37. * This structure contains negotiation state and several SDP session
  38. * descriptors currently being used in the negotiation.
  39. *
  40. *
  41. * \section sdpneg_state_dia SDP Negotiator State Diagram
  42. *
  43. * The following diagram describes the state transition diagram of the
  44. * SDP negotiator.
  45. *
  46. * <pre>
  47. *
  48. * modify_local_offer()
  49. * create_w_local_offer() +-------------+ send_local_offer()
  50. * ----------------------->| LOCAL_OFFER |<-----------------------
  51. * | +-------------+______ |
  52. * | | \_____________ |
  53. * | set_remote_answer() | cancel_offer() \ |
  54. * | V v |
  55. * +--+---+ +-----------+ negotiate() +-~----+
  56. * | NULL | | WAIT_NEGO |-------------------->| DONE |
  57. * +------+ +-----------+ +------+
  58. * | A ______________________^ |
  59. * | set_local_answer() | / cancel_offer() |
  60. * | | / |
  61. * | +--------------+ set_remote_offer() |
  62. * ----------------------->| REMOTE_OFFER |<----------------------
  63. * create_w_remote_offer() +--------------+
  64. *
  65. * </pre>
  66. *
  67. *
  68. *
  69. * \section sdpneg_offer_answer SDP Offer/Answer Model with Negotiator
  70. *
  71. * \subsection sdpneg_create_offer Creating Initial Offer
  72. *
  73. * Application creates an offer by manualy building the SDP session descriptor
  74. * (pjmedia_sdp_session), or request PJMEDIA endpoint (pjmedia_endpt) to
  75. * create SDP session descriptor based on capabilities that present in the
  76. * endpoint by calling #pjmedia_endpt_create_sdp().
  77. *
  78. * Application then creates SDP negotiator instance by calling
  79. * #pjmedia_sdp_neg_create_w_local_offer(), passing the SDP offer in the
  80. * function arguments. The SDP negotiator keeps a copy of current local offer,
  81. * and update its state to PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER.
  82. *
  83. * Application can then send the initial SDP offer that it creates to
  84. * remote peer using signaling protocol such as SIP.
  85. *
  86. *
  87. * \subsection sdpneg_generate_offer Generating Subsequent Offer
  88. *
  89. * The negotiator can only create subsequent offer after it has finished
  90. * the negotiation process of previous offer/answer session (i.e. the
  91. * negotiator state is PJMEDIA_SDP_NEG_STATE_DONE).
  92. *
  93. * If any previous negotiation process was successfull (i.e. the return
  94. * value of #pjmedia_sdp_neg_negotiate() was PJ_SUCCESS), the negotiator
  95. * keeps both active local and active remote SDP.
  96. *
  97. * If application does not want send modified offer, it can just send
  98. * the active local SDP as the offer. In this case, application calls
  99. * #pjmedia_sdp_neg_send_local_offer() to get the active local SDP.
  100. *
  101. * If application wants to modify it's local offer, it MUST inform
  102. * the negotiator about the modified SDP by calling
  103. * #pjmedia_sdp_neg_modify_local_offer().
  104. *
  105. * In both cases, the negotiator will internally create a copy of the offer,
  106. * and move it's state to PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER, where it
  107. * waits until application passes the remote answer.
  108. *
  109. *
  110. * \subsection sdpneg_receive_offer Receiving Initial Offer
  111. *
  112. * Application receives an offer in the incoming request from remote to
  113. * establish multimedia session, such as incoming INVITE message with SDP
  114. * body.
  115. *
  116. * Initially, when the initial offer is received, application creates the
  117. * SDP negotiator by calling #pjmedia_sdp_neg_create_w_remote_offer(),
  118. * specifying the remote SDP offer in one of the argument.
  119. *
  120. * At this stage, application may or may not ready to create an answer.
  121. * For example, a SIP B2BUA needs to make outgoing call and receive SDP
  122. * from the outgoing call leg in order to create a SDP answer to the
  123. * incoming call leg.
  124. *
  125. * If application is not ready to create an answer, it passes NULL as
  126. * the local SDP when it calls #pjmedia_sdp_neg_create_w_remote_offer().
  127. *
  128. * The section @ref sdpneg_create_answer describes the case when
  129. * application is ready to create a SDP answer.
  130. *
  131. *
  132. * \subsection sdpneg_subseq_offer Receiving Subsequent Offer
  133. *
  134. * Application passes subsequent SDP offer received from remote by
  135. * calling #pjmedia_sdp_neg_set_remote_offer().
  136. *
  137. * The negotiator can only receive subsequent offer after it has finished
  138. * the negotiation process of previous offer/answer session (i.e. the
  139. * negotiator state is PJMEDIA_SDP_NEG_STATE_DONE).
  140. *
  141. *
  142. * \subsection sdpneg_recv_answer Receiving SDP Answer
  143. *
  144. * When application receives SDP answer from remote, it informs the
  145. * negotiator by calling #pjmedia_sdp_neg_set_remote_answer(). The
  146. * negotiator validates the answer (#pjmedia_sdp_validate()), and if
  147. * succeeds, it moves it's state to PJMEDIA_SDP_NEG_STATE_WAIT_NEGO.
  148. *
  149. * Application then instruct the negotiator to negotiate the remote
  150. * answer by calling #pjmedia_sdp_neg_negotiate(). The purpose of
  151. * this negotiation is to verify remote answer, and update the initial
  152. * offer according to the answer. For example, the initial offer may
  153. * specify that a stream is \a sendrecv, while the answer specifies
  154. * that remote stream is \a inactive. In this case, the negotiator
  155. * will update the stream in the local active media as \a inactive
  156. * too.
  157. *
  158. * If #pjmedia_sdp_neg_negotiate() returns PJ_SUCCESS, the negotiator will
  159. * keep the updated local answer and remote answer internally. These two
  160. * SDPs are called active local SDP and active remote SDP, as it describes
  161. * currently active session.
  162. *
  163. * Application can retrieve the active local SDP by calling
  164. * #pjmedia_sdp_neg_get_active_local(), and active remote SDP by calling
  165. * #pjmedia_sdp_neg_get_active_remote().
  166. *
  167. * If #pjmedia_sdp_neg_negotiate() returns failure (i.e. not PJ_SUCCESS),
  168. * it WILL NOT update its active local and active remote SDP.
  169. *
  170. * Regardless of the return status of the #pjmedia_sdp_neg_negotiate(),
  171. * the negotiator state will move to PJMEDIA_SDP_NEG_STATE_DONE.
  172. *
  173. *
  174. * \subsection sdpneg_cancel_offer Cancelling an Offer
  175. *
  176. * In other case, after an offer is generated (negotiator state is in
  177. * PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER), the answer may not be received, and
  178. * application wants the negotiator to reset itself to its previous state.
  179. * Consider this example:
  180. *
  181. * - media has been established, and negotiator state is
  182. * PJMEDIA_SDP_NEG_STATE_DONE.
  183. * - application generates a new offer for re-INVITE, so in this case
  184. * it would either call #pjmedia_sdp_neg_send_local_offer() or
  185. * #pjmedia_sdp_neg_modify_local_offer()
  186. * - the negotiator state moves to PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER
  187. * - the re-INVITE was rejected with an error
  188. *
  189. * Since an answer is not received, it is necessary to reset the negotiator
  190. * state back to PJMEDIA_SDP_NEG_STATE_DONE so that the negotiator can
  191. * create or receive new offer.
  192. *
  193. * This can be accomplished by calling #pjmedia_sdp_neg_cancel_offer(),
  194. * to reset the negotiator state back to PJMEDIA_SDP_NEG_STATE_DONE. In
  195. * this case, both active local and active remote will not be modified.
  196. *
  197. * \subsection sdpneg_create_answer Generating SDP Answer
  198. *
  199. * After remote offer has been set in the negotiator, application can
  200. * request the SDP negotiator to generate appropriate answer based on local
  201. * capability.
  202. *
  203. * To do this, first the application MUST have an SDP describing its local
  204. * capabilities. This SDP can be built manually, or application can generate
  205. * SDP to describe local media endpoint capability by calling
  206. * #pjmedia_endpt_create_sdp(). When the application is a SIP B2BUA,
  207. * application can treat the SDP received from the outgoing call leg as if
  208. * it was it's local capability.
  209. *
  210. * The local SDP session descriptor DOES NOT have to match the SDP offer.
  211. * For example, it can have more or less media lines than the offer, or
  212. * their order may be different than the offer. The negotiator is capable
  213. * to match and reorder local SDP according to remote offer, and create
  214. * an answer that is suitable for the offer.
  215. *
  216. * After local SDP capability has been acquired, application can create
  217. * a SDP answer.
  218. *
  219. * If application does not already have the negotiator instance, it creates
  220. * one by calling #pjmedia_sdp_neg_create_w_remote_offer(), specifying
  221. * both remote SDP offer and local SDP as the arguments. The SDP negotiator
  222. * validates both remote and local SDP by calling #pjmedia_sdp_validate(),
  223. * and if both SDPs are valid, the negotiator state will move to
  224. * PJMEDIA_SDP_NEG_STATE_WAIT_NEGO where it is ready to negotiate the
  225. * offer and answer.
  226. *
  227. * If application already has the negotiator instance, it sets the local
  228. * SDP in the negotiator by calling #pjmedia_sdp_neg_set_local_answer().
  229. * The SDP negotiator then validates local SDP (#pjmedia_sdp_validate() ),
  230. * and if it is valid, the negotiator state will move to
  231. * PJMEDIA_SDP_NEG_STATE_WAIT_NEGO where it is ready to negotiate the
  232. * offer and answer.
  233. *
  234. * After the SDP negotiator state has moved to PJMEDIA_SDP_NEG_STATE_WAIT_NEGO,
  235. * application calls #pjmedia_sdp_neg_negotiate() to instruct the SDP
  236. * negotiator to negotiate both offer and answer. This function returns
  237. * PJ_SUCCESS if an answer can be generated AND at least one media stream
  238. * is active in the session.
  239. *
  240. * If #pjmedia_sdp_neg_negotiate() returns PJ_SUCCESS, the negotiator will
  241. * keep the remote offer and local answer internally. These two SDPs are
  242. * called active local SDP and active remote SDP, as it describes currently
  243. * active session.
  244. *
  245. * Application can retrieve the active local SDP by calling
  246. * #pjmedia_sdp_neg_get_active_local(), and send this SDP to remote as the
  247. * SDP answer.
  248. *
  249. * If #pjmedia_sdp_neg_negotiate() returns failure (i.e. not PJ_SUCCESS),
  250. * it WILL NOT update its active local and active remote SDP.
  251. *
  252. * Regardless of the return status of the #pjmedia_sdp_neg_negotiate(),
  253. * the negotiator state will move to PJMEDIA_SDP_NEG_STATE_DONE.
  254. *
  255. *
  256. */
  257. #include <pjmedia/sdp.h>
  258. PJ_BEGIN_DECL
  259. /**
  260. * This enumeration describes SDP negotiation state.
  261. */
  262. enum pjmedia_sdp_neg_state
  263. {
  264. /**
  265. * This is the state of SDP negoator before it is initialized.
  266. */
  267. PJMEDIA_SDP_NEG_STATE_NULL,
  268. /**
  269. * This state occurs when SDP negotiator has sent our offer to remote and
  270. * it is waiting for answer.
  271. */
  272. PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER,
  273. /**
  274. * This state occurs when SDP negotiator has received offer from remote
  275. * and currently waiting for local answer.
  276. */
  277. PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER,
  278. /**
  279. * This state occurs when an offer (either local or remote) has been
  280. * provided with answer. The SDP negotiator is ready to negotiate both
  281. * session descriptors. Application can call #pjmedia_sdp_neg_negotiate()
  282. * immediately to begin negotiation process.
  283. */
  284. PJMEDIA_SDP_NEG_STATE_WAIT_NEGO,
  285. /**
  286. * This state occurs when SDP negotiation has completed, either
  287. * successfully or not.
  288. */
  289. PJMEDIA_SDP_NEG_STATE_DONE
  290. };
  291. /**
  292. * @see pjmedia_sdp_neg_state
  293. */
  294. typedef enum pjmedia_sdp_neg_state pjmedia_sdp_neg_state;
  295. /**
  296. * Opaque declaration of SDP negotiator.
  297. */
  298. typedef struct pjmedia_sdp_neg pjmedia_sdp_neg;
  299. /**
  300. * Flags to be given to pjmedia_sdp_neg_modify_local_offer2().
  301. */
  302. typedef enum pjmedia_mod_offer_flag
  303. {
  304. /**
  305. * Allow media type in the SDP to be changed.
  306. * When generating a new offer, in the case that a media line doesn't match
  307. * the active SDP, the new media line will be considered to replace the
  308. * existing media at the same position.
  309. */
  310. PJMEDIA_SDP_NEG_ALLOW_MEDIA_CHANGE = 1
  311. } pjmedia_mod_offer_flag;
  312. /**
  313. * Get the state string description of the specified state.
  314. *
  315. * @param state Negotiator state.
  316. *
  317. * @return String description of the state.
  318. */
  319. PJ_DECL(const char*) pjmedia_sdp_neg_state_str(pjmedia_sdp_neg_state state);
  320. /**
  321. * Create the SDP negotiator with local offer. The SDP negotiator then
  322. * will move to PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER state, where it waits
  323. * until it receives answer from remote. When SDP answer from remote is
  324. * received, application must call #pjmedia_sdp_neg_set_remote_answer().
  325. *
  326. * After calling this function, application should send the local SDP offer
  327. * to remote party using signaling protocol such as SIP and wait for SDP
  328. * answer.
  329. *
  330. * @param pool Pool to allocate memory. The pool's lifetime needs
  331. * to be valid for the duration of the negotiator.
  332. * @param local The initial local capability.
  333. * @param p_neg Pointer to receive the negotiator instance.
  334. *
  335. * @return PJ_SUCCESS on success, or the appropriate error
  336. * code.
  337. */
  338. PJ_DECL(pj_status_t)
  339. pjmedia_sdp_neg_create_w_local_offer( pj_pool_t *pool,
  340. const pjmedia_sdp_session *local,
  341. pjmedia_sdp_neg **p_neg);
  342. /**
  343. * Initialize the SDP negotiator with remote offer, and optionally
  344. * specify the initial local capability, if known. Application normally
  345. * calls this function when it receives initial offer from remote.
  346. *
  347. * If local media capability is specified, this capability will be set as
  348. * initial local capability of the negotiator, and after this function is
  349. * called, the SDP negotiator state will move to state
  350. * PJMEDIA_SDP_NEG_STATE_WAIT_NEGO, and the negotiation function can be
  351. * called.
  352. *
  353. * If local SDP is not specified, the negotiator will not have initial local
  354. * capability, and after this function is called the negotiator state will
  355. * move to PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER state. Application MUST supply
  356. * local answer later with #pjmedia_sdp_neg_set_local_answer(), before
  357. * calling the negotiation function.
  358. *
  359. * @param pool Pool to allocate memory. The pool's lifetime needs
  360. * to be valid for the duration of the negotiator.
  361. * @param initial Optional initial local capability.
  362. * @param remote The remote offer.
  363. * @param p_neg Pointer to receive the negotiator instance.
  364. *
  365. * @return PJ_SUCCESS on success, or the appropriate error
  366. * code.
  367. */
  368. PJ_DECL(pj_status_t)
  369. pjmedia_sdp_neg_create_w_remote_offer(pj_pool_t *pool,
  370. const pjmedia_sdp_session *initial,
  371. const pjmedia_sdp_session *remote,
  372. pjmedia_sdp_neg **p_neg);
  373. /**
  374. * This specifies the behavior of the SDP negotiator when responding to an
  375. * offer, whether it should rather use the codec preference as set by
  376. * remote, or should it rather use the codec preference as specified by
  377. * local endpoint.
  378. *
  379. * For example, suppose incoming call has codec order "8 0 3", while
  380. * local codec order is "3 0 8". If remote codec order is preferable,
  381. * the selected codec will be 8, while if local codec order is preferable,
  382. * the selected codec will be 3.
  383. *
  384. * By default, the value in PJMEDIA_SDP_NEG_PREFER_REMOTE_CODEC_ORDER will
  385. * be used.
  386. *
  387. * @param neg The SDP negotiator instance.
  388. * @param prefer_remote If non-zero, the negotiator will use the codec
  389. * order as specified in remote offer. If zero, it
  390. * will prefer to use the local codec order.
  391. */
  392. PJ_DECL(pj_status_t)
  393. pjmedia_sdp_neg_set_prefer_remote_codec_order(pjmedia_sdp_neg *neg,
  394. pj_bool_t prefer_remote);
  395. /**
  396. * This specifies the behavior of the SDP negotiator when responding to an
  397. * offer, whether it should answer with multiple formats or not.
  398. *
  399. * By default, the value in PJMEDIA_SDP_NEG_ANSWER_MULTIPLE_CODECS will
  400. * be used.
  401. *
  402. * @param neg The SDP negotiator instance.
  403. * @param answer_multiple
  404. * If non-zero, the negotiator will respond with
  405. * multiple formats. If zero only a single format
  406. * will be returned.
  407. */
  408. PJ_DECL(pj_status_t)
  409. pjmedia_sdp_neg_set_answer_multiple_codecs(pjmedia_sdp_neg *neg,
  410. pj_bool_t answer_multiple);
  411. /**
  412. * Get SDP negotiator state.
  413. *
  414. * @param neg The SDP negotiator instance.
  415. *
  416. * @return The negotiator state.
  417. */
  418. PJ_DECL(pjmedia_sdp_neg_state)
  419. pjmedia_sdp_neg_get_state( pjmedia_sdp_neg *neg );
  420. /**
  421. * Get the currently active local SDP. Application can only call this
  422. * function after negotiation has been done, or otherwise there won't be
  423. * active SDPs. Calling this function will not change the state of the
  424. * negotiator.
  425. *
  426. * @param neg The SDP negotiator instance.
  427. * @param local Pointer to receive the local active SDP.
  428. *
  429. * @return PJ_SUCCESS if local active SDP is present.
  430. */
  431. PJ_DECL(pj_status_t)
  432. pjmedia_sdp_neg_get_active_local( pjmedia_sdp_neg *neg,
  433. const pjmedia_sdp_session **local);
  434. /**
  435. * Get the currently active remote SDP. Application can only call this
  436. * function after negotiation has been done, or otherwise there won't be
  437. * active SDPs. Calling this function will not change the state of the
  438. * negotiator.
  439. *
  440. * @param neg The SDP negotiator instance.
  441. * @param remote Pointer to receive the remote active SDP.
  442. *
  443. * @return PJ_SUCCESS if remote active SDP is present.
  444. */
  445. PJ_DECL(pj_status_t)
  446. pjmedia_sdp_neg_get_active_remote( pjmedia_sdp_neg *neg,
  447. const pjmedia_sdp_session **remote);
  448. /**
  449. * Determine whether remote sent answer (as opposed to offer) on the
  450. * last negotiation. This function can only be called in state
  451. * PJMEDIA_SDP_NEG_STATE_DONE.
  452. *
  453. * @param neg The SDP negotiator instance.
  454. *
  455. * @return Non-zero if it was remote who sent answer,
  456. * otherwise zero if it was local who supplied
  457. * answer.
  458. */
  459. PJ_DECL(pj_bool_t)
  460. pjmedia_sdp_neg_was_answer_remote(pjmedia_sdp_neg *neg);
  461. /**
  462. * Get the current remote SDP offer or answer. Application can only
  463. * call this function in state PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER or
  464. * PJMEDIA_SDP_NEG_STATE_WAIT_NEGO, or otherwise there won't be remote
  465. * SDP offer/answer. Calling this function will not change the state
  466. * of the negotiator.
  467. *
  468. * @param neg The SDP negotiator instance.
  469. * @param remote Pointer to receive the current remote offer or
  470. * answer.
  471. *
  472. * @return PJ_SUCCESS if the negotiator currently has
  473. * remote offer or answer.
  474. */
  475. PJ_DECL(pj_status_t)
  476. pjmedia_sdp_neg_get_neg_remote( pjmedia_sdp_neg *neg,
  477. const pjmedia_sdp_session **remote);
  478. /**
  479. * Get the current local SDP offer or answer. Application can only
  480. * call this function in state PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER or
  481. * PJMEDIA_SDP_NEG_STATE_WAIT_NEGO, or otherwise there won't be local
  482. * SDP offer/answer. Calling this function will not change the state
  483. * of the negotiator.
  484. *
  485. * @param neg The SDP negotiator instance.
  486. * @param local Pointer to receive the current local offer or
  487. * answer.
  488. *
  489. * @return PJ_SUCCESS if the negotiator currently has
  490. * local offer or answer.
  491. */
  492. PJ_DECL(pj_status_t)
  493. pjmedia_sdp_neg_get_neg_local( pjmedia_sdp_neg *neg,
  494. const pjmedia_sdp_session **local);
  495. /**
  496. * Modify local session with a new SDP and treat this as a new offer.
  497. * This function can only be called in state PJMEDIA_SDP_NEG_STATE_DONE.
  498. * After calling this function, application can send the SDP as offer
  499. * to remote party, using signaling protocol such as SIP.
  500. * The negotiator state will move to PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER,
  501. * where it waits for SDP answer from remote. See also
  502. * #pjmedia_sdp_neg_modify_local_offer2()
  503. *
  504. * @param pool Pool to allocate memory. The pool's lifetime needs
  505. * to be valid for the duration of the negotiator.
  506. * @param neg The SDP negotiator instance.
  507. * @param local The new local SDP.
  508. *
  509. * @return PJ_SUCCESS on success, or the appropriate
  510. * error code.
  511. */
  512. PJ_DECL(pj_status_t)
  513. pjmedia_sdp_neg_modify_local_offer( pj_pool_t *pool,
  514. pjmedia_sdp_neg *neg,
  515. const pjmedia_sdp_session *local);
  516. /**
  517. * Modify local session with a new SDP and treat this as a new offer.
  518. * This function can only be called in state PJMEDIA_SDP_NEG_STATE_DONE.
  519. * After calling this function, application can send the SDP as offer
  520. * to remote party, using signaling protocol such as SIP.
  521. * The negotiator state will move to PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER,
  522. * where it waits for SDP answer from remote.
  523. *
  524. * @param pool Pool to allocate memory. The pool's lifetime needs
  525. * to be valid for the duration of the negotiator.
  526. * @param neg The SDP negotiator instance.
  527. * @param flags Bitmask from pjmedia_mod_offer_flag.
  528. * @param local The new local SDP.
  529. *
  530. * @return PJ_SUCCESS on success, or the appropriate
  531. * error code.
  532. */
  533. PJ_DECL(pj_status_t)
  534. pjmedia_sdp_neg_modify_local_offer2( pj_pool_t *pool,
  535. pjmedia_sdp_neg *neg,
  536. unsigned flags,
  537. const pjmedia_sdp_session *local);
  538. /**
  539. * This function can only be called in PJMEDIA_SDP_NEG_STATE_DONE state.
  540. * Application calls this function to retrieve currently active
  541. * local SDP, and then send the SDP to remote as an offer. The negotiator
  542. * state will then move to PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER, where it waits
  543. * for SDP answer from remote.
  544. *
  545. * When SDP answer has been received from remote, application must call
  546. * #pjmedia_sdp_neg_set_remote_answer().
  547. *
  548. * @param pool Pool to allocate memory. The pool's lifetime needs
  549. * to be valid for the duration of the negotiator.
  550. * @param neg The SDP negotiator instance.
  551. * @param offer Pointer to receive active local SDP to be
  552. * offered to remote.
  553. *
  554. * @return PJ_SUCCESS if local offer can be created.
  555. */
  556. PJ_DECL(pj_status_t)
  557. pjmedia_sdp_neg_send_local_offer( pj_pool_t *pool,
  558. pjmedia_sdp_neg *neg,
  559. const pjmedia_sdp_session **offer);
  560. /**
  561. * This function can only be called in PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER
  562. * state, i.e. after application calls #pjmedia_sdp_neg_send_local_offer()
  563. * function. Application calls this function when it receives SDP answer
  564. * from remote. After this function is called, the negotiator state will
  565. * move to PJMEDIA_SDP_NEG_STATE_WAIT_NEGO, and application can call the
  566. * negotiation function #pjmedia_sdp_neg_negotiate().
  567. *
  568. * @param pool Pool to allocate memory. The pool's lifetime needs
  569. * to be valid for the duration of the negotiator.
  570. * @param neg The SDP negotiator instance.
  571. * @param remote The remote answer.
  572. *
  573. * @return PJ_SUCCESS on success.
  574. */
  575. PJ_DECL(pj_status_t)
  576. pjmedia_sdp_neg_set_remote_answer( pj_pool_t *pool,
  577. pjmedia_sdp_neg *neg,
  578. const pjmedia_sdp_session *remote);
  579. /**
  580. * This function can only be called in PJMEDIA_SDP_NEG_STATE_DONE state.
  581. * Application calls this function when it receives SDP offer from remote.
  582. * After this function is called, the negotiator state will move to
  583. * PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER, and application MUST call the
  584. * #pjmedia_sdp_neg_set_local_answer() to set local answer before it can
  585. * call the negotiation function.
  586. *
  587. * @param pool Pool to allocate memory. The pool's lifetime needs
  588. * to be valid for the duration of the negotiator.
  589. * @param neg The SDP negotiator instance.
  590. * @param remote The remote offer.
  591. *
  592. * @return PJ_SUCCESS on success.
  593. */
  594. PJ_DECL(pj_status_t)
  595. pjmedia_sdp_neg_set_remote_offer( pj_pool_t *pool,
  596. pjmedia_sdp_neg *neg,
  597. const pjmedia_sdp_session *remote);
  598. /**
  599. * This function can only be called in PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER
  600. * state, i.e. after application calls #pjmedia_sdp_neg_set_remote_offer()
  601. * function. After this function is called, the negotiator state will
  602. * move to PJMEDIA_SDP_NEG_STATE_WAIT_NEGO, and application can call the
  603. * negotiation function #pjmedia_sdp_neg_negotiate().
  604. *
  605. * @param pool Pool to allocate memory. The pool's lifetime needs
  606. * to be valid for the duration of the negotiator.
  607. * @param neg The SDP negotiator instance.
  608. * @param local Optional local answer. If negotiator has initial
  609. * local capability, application can specify NULL on
  610. * this argument; in this case, the negotiator will
  611. * create answer by by negotiating remote offer with
  612. * initial local capability. If negotiator doesn't have
  613. * initial local capability, application MUST specify
  614. * local answer here.
  615. *
  616. * @return PJ_SUCCESS on success.
  617. */
  618. PJ_DECL(pj_status_t)
  619. pjmedia_sdp_neg_set_local_answer( pj_pool_t *pool,
  620. pjmedia_sdp_neg *neg,
  621. const pjmedia_sdp_session *local);
  622. /**
  623. * Call this function when the negotiator is in PJMEDIA_SDP_NEG_STATE_WAIT_NEGO
  624. * state to see if it was local who is answering the offer (instead of
  625. * remote).
  626. *
  627. * @param neg The negotiator.
  628. *
  629. * @return PJ_TRUE if it is local is answering an offer, PJ_FALSE
  630. * if remote has answered local offer.
  631. */
  632. PJ_DECL(pj_bool_t) pjmedia_sdp_neg_has_local_answer(pjmedia_sdp_neg *neg);
  633. /**
  634. * Cancel any pending offer, whether the offer is initiated by local or
  635. * remote, and move negotiator state back to previous stable state
  636. * (PJMEDIA_SDP_NEG_STATE_DONE). The negotiator must be in
  637. * PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER or PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER
  638. * state.
  639. *
  640. * @param neg The negotiator.
  641. *
  642. * @return PJ_SUCCESS or the appropriate error code.
  643. */
  644. PJ_DECL(pj_status_t) pjmedia_sdp_neg_cancel_offer(pjmedia_sdp_neg *neg);
  645. /**
  646. * Negotiate local and remote answer. Before calling this function, the
  647. * SDP negotiator must be in PJMEDIA_SDP_NEG_STATE_WAIT_NEGO state.
  648. * After calling this function, the negotiator state will move to
  649. * PJMEDIA_SDP_NEG_STATE_DONE regardless whether the negotiation has
  650. * been successfull or not.
  651. *
  652. * If the negotiation succeeds (i.e. the return value is PJ_SUCCESS),
  653. * the active local and remote SDP will be replaced with the new SDP
  654. * from the negotiation process.
  655. *
  656. * If the negotiation fails, the active local and remote SDP will not
  657. * change.
  658. *
  659. * @param pool Pool to allocate memory. The pool's lifetime needs
  660. * to be valid for the duration of the negotiator.
  661. * @param neg The SDP negotiator instance.
  662. * @param allow_asym Should be zero.
  663. *
  664. * @return PJ_SUCCESS when there is at least one media
  665. * is actuve common in both offer and answer, or
  666. * failure code when negotiation has failed.
  667. */
  668. PJ_DECL(pj_status_t) pjmedia_sdp_neg_negotiate( pj_pool_t *pool,
  669. pjmedia_sdp_neg *neg,
  670. pj_bool_t allow_asym);
  671. /**
  672. * Enumeration of customized SDP format matching option flags. See
  673. * #pjmedia_sdp_neg_register_fmt_match_cb() for more info.
  674. */
  675. typedef enum pjmedia_sdp_neg_fmt_match_flag
  676. {
  677. /**
  678. * In generating answer, the SDP fmtp in the answer candidate may need
  679. * to be modified by the customized SDP format matching callback to
  680. * achieve flexible SDP negotiation, e.g: AMR fmtp 'octet-align' field
  681. * can be adjusted with the offer when the codec implementation support
  682. * both packetization modes octet-aligned and bandwidth-efficient.
  683. */
  684. PJMEDIA_SDP_NEG_FMT_MATCH_ALLOW_MODIFY_ANSWER = 1,
  685. } pjmedia_sdp_neg_fmt_match_flag;
  686. /**
  687. * The declaration of customized SDP format matching callback. See
  688. * #pjmedia_sdp_neg_register_fmt_match_cb() for more info.
  689. *
  690. * @param pool The memory pool.
  691. * @param offer The SDP media offer.
  692. * @param o_fmt_idx Index of the format in the SDP media offer.
  693. * @param answer The SDP media answer.
  694. * @param a_fmt_idx Index of the format in the SDP media answer.
  695. * @param option The format matching option, see
  696. * #pjmedia_sdp_neg_fmt_match_flag.
  697. *
  698. * @return PJ_SUCCESS when the formats in offer and answer match.
  699. */
  700. typedef pj_status_t (*pjmedia_sdp_neg_fmt_match_cb)(pj_pool_t *pool,
  701. pjmedia_sdp_media *offer,
  702. unsigned o_fmt_idx,
  703. pjmedia_sdp_media *answer,
  704. unsigned a_fmt_idx,
  705. unsigned option);
  706. /**
  707. * Register customized SDP format matching callback function for the specified
  708. * format. The customized SDP format matching is needed when the format
  709. * identification in a media stream session cannot be simply determined by
  710. * encoding name and clock rate, but also involves one or more format specific
  711. * parameters, which are specified in SDP fmtp attribute. For example,
  712. * an H.264 video stream is also identified by profile, level, and
  713. * packetization-mode parameters. As those parameters are format specifics,
  714. * the negotiation must be done by the format or codec implementation.
  715. *
  716. * To unregister the callback of specific format, just call this function with
  717. * parameter cb set to NULL.
  718. *
  719. * @param fmt_name The format name, e.g: "H.264", "AMR", "G7221". Note
  720. * that the string buffer must remain valid until the
  721. * callback is unregistered.
  722. * @param cb The customized SDP format negotiation callback or
  723. * NULL to unregister the specified format callback.
  724. *
  725. * @return PJ_SUCCESS on success.
  726. */
  727. PJ_DECL(pj_status_t) pjmedia_sdp_neg_register_fmt_match_cb(
  728. const pj_str_t *fmt_name,
  729. pjmedia_sdp_neg_fmt_match_cb cb);
  730. /**
  731. * Match format in the SDP media offer and answer. The matching mechanism
  732. * will be done by comparing the encoding name, clock rate, and encoding
  733. * parameters (if any), and if the custom format matching callback
  734. * for the specified format is registered, see
  735. * #pjmedia_sdp_neg_register_fmt_match_cb(), it will be called for
  736. * more detail verification, e.g: format parameters specified in SDP fmtp.
  737. *
  738. * @param pool The memory pool.
  739. * @param offer The SDP media offer.
  740. * @param o_fmt_idx Index of the format in the SDP media offer.
  741. * @param answer The SDP media answer.
  742. * @param a_fmt_idx Index of the format in the SDP media answer.
  743. * @param option The format matching option, see
  744. * #pjmedia_sdp_neg_fmt_match_flag.
  745. *
  746. * @return PJ_SUCCESS when the formats in offer and answer match.
  747. */
  748. PJ_DECL(pj_status_t) pjmedia_sdp_neg_fmt_match( pj_pool_t *pool,
  749. pjmedia_sdp_media *offer,
  750. unsigned o_fmt_idx,
  751. pjmedia_sdp_media *answer,
  752. unsigned a_fmt_idx,
  753. unsigned option);
  754. PJ_END_DECL
  755. /**
  756. * @}
  757. */
  758. #endif /* __PJMEDIA_SDP_NEG_H__ */