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