1
/* $Id: sdp_neg.h 3664 2011-07-19 03:42:28Z nanang $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
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.
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.
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
20
#ifndef __PJMEDIA_SDP_NEG_H__
21
#define __PJMEDIA_SDP_NEG_H__
26
* @brief SDP negotiator header file.
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)
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
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.
44
* \section sdpneg_state_dia SDP Negotiator State Diagram
46
* The following diagram describes the state transition diagram of the
51
* modify_local_offer()
52
* create_w_local_offer() +-------------+ send_local_offer()
53
* ----------------------->| LOCAL_OFFER |<-----------------------
54
* | +-------------+______ |
55
* | | \______ cancel() |
56
* | set_remote_answer() | \______ |
58
* +--+---+ +-----------+ negotiate() +-~----+
59
* | NULL | | WAIT_NEGO |-------------------->| DONE |
60
* +------+ +-----------+ +------+
62
* | set_local_answer() | |
64
* | +--------------+ set_remote_offer() |
65
* ----------------------->| REMOTE_OFFER |<----------------------
66
* create_w_remote_offer() +--------------+
72
* \section sdpneg_offer_answer SDP Offer/Answer Model with Negotiator
74
* \subsection sdpneg_create_offer Creating Initial Offer
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().
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.
86
* Application can then send the initial SDP offer that it creates to
87
* remote peer using signaling protocol such as SIP.
90
* \subsection sdpneg_subseq_offer Generating Subsequent Offer
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).
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.
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.
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().
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.
113
* \subsection sdpneg_receive_offer Receiving Initial Offer
115
* Application receives an offer in the incoming request from remote to
116
* establish multimedia session, such as incoming INVITE message with SDP
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.
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
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().
131
* The section @ref sdpneg_create_answer describes the case when
132
* application is ready to create a SDP answer.
135
* \subsection sdpneg_subseq_offer Receiving Subsequent Offer
137
* Application passes subsequent SDP offer received from remote by
138
* calling #pjmedia_sdp_neg_set_remote_offer().
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).
145
* \subsection sdpneg_recv_answer Receiving SDP Answer
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.
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
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.
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().
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.
173
* Regardless of the return status of the #pjmedia_sdp_neg_negotiate(),
174
* the negotiator state will move to PJMEDIA_SDP_NEG_STATE_DONE.
177
* \subsection sdpneg_cancel_offer Cancelling an Offer
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:
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
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.
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.
200
* \subsection sdpneg_create_answer Generating SDP Answer
202
* After remote offer has been set in the negotiator, application can
203
* request the SDP negotiator to generate appropriate answer based on local
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.
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.
219
* After local SDP capability has been acquired, application can create
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
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
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.
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
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
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.
255
* Regardless of the return status of the #pjmedia_sdp_neg_negotiate(),
256
* the negotiator state will move to PJMEDIA_SDP_NEG_STATE_DONE.
261
#include <pjmedia/sdp.h>
266
* This enumeration describes SDP negotiation state.
268
enum pjmedia_sdp_neg_state
271
* This is the state of SDP negoator before it is initialized.
273
PJMEDIA_SDP_NEG_STATE_NULL,
276
* This state occurs when SDP negotiator has sent our offer to remote and
277
* it is waiting for answer.
279
PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER,
282
* This state occurs when SDP negotiator has received offer from remote
283
* and currently waiting for local answer.
285
PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER,
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.
293
PJMEDIA_SDP_NEG_STATE_WAIT_NEGO,
296
* This state occurs when SDP negotiation has completed, either
297
* successfully or not.
299
PJMEDIA_SDP_NEG_STATE_DONE
304
* @see pjmedia_sdp_neg_state
306
typedef enum pjmedia_sdp_neg_state pjmedia_sdp_neg_state;
310
* Opaque declaration of SDP negotiator.
312
typedef struct pjmedia_sdp_neg pjmedia_sdp_neg;
316
* Get the state string description of the specified state.
318
* @param state Negotiator state.
320
* @return String description of the state.
322
PJ_DECL(const char*) pjmedia_sdp_neg_state_str(pjmedia_sdp_neg_state state);
326
* Create the SDP negotiator with local offer. The SDP negotiator then
327
* will move to PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER state, where it waits
328
* until it receives answer from remote. When SDP answer from remote is
329
* received, application must call #pjmedia_sdp_neg_set_remote_answer().
331
* After calling this function, application should send the local SDP offer
332
* to remote party using signaling protocol such as SIP and wait for SDP
335
* @param pool Pool to allocate memory. The pool's lifetime needs
336
* to be valid for the duration of the negotiator.
337
* @param local The initial local capability.
338
* @param p_neg Pointer to receive the negotiator instance.
340
* @return PJ_SUCCESS on success, or the appropriate error
344
pjmedia_sdp_neg_create_w_local_offer( pj_pool_t *pool,
345
const pjmedia_sdp_session *local,
346
pjmedia_sdp_neg **p_neg);
349
* Initialize the SDP negotiator with remote offer, and optionally
350
* specify the initial local capability, if known. Application normally
351
* calls this function when it receives initial offer from remote.
353
* If local media capability is specified, this capability will be set as
354
* initial local capability of the negotiator, and after this function is
355
* called, the SDP negotiator state will move to state
356
* PJMEDIA_SDP_NEG_STATE_WAIT_NEGO, and the negotiation function can be
359
* If local SDP is not specified, the negotiator will not have initial local
360
* capability, and after this function is called the negotiator state will
361
* move to PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER state. Application MUST supply
362
* local answer later with #pjmedia_sdp_neg_set_local_answer(), before
363
* calling the negotiation function.
365
* @param pool Pool to allocate memory. The pool's lifetime needs
366
* to be valid for the duration of the negotiator.
367
* @param initial Optional initial local capability.
368
* @param remote The remote offer.
369
* @param p_neg Pointer to receive the negotiator instance.
371
* @return PJ_SUCCESS on success, or the appropriate error
375
pjmedia_sdp_neg_create_w_remote_offer(pj_pool_t *pool,
376
const pjmedia_sdp_session *initial,
377
const pjmedia_sdp_session *remote,
378
pjmedia_sdp_neg **p_neg);
381
* This specifies the behavior of the SDP negotiator when responding to an
382
* offer, whether it should rather use the codec preference as set by
383
* remote, or should it rather use the codec preference as specified by
386
* For example, suppose incoming call has codec order "8 0 3", while
387
* local codec order is "3 0 8". If remote codec order is preferable,
388
* the selected codec will be 8, while if local codec order is preferable,
389
* the selected codec will be 3.
391
* By default, the value in PJMEDIA_SDP_NEG_PREFER_REMOTE_CODEC_ORDER will
394
* @param neg The SDP negotiator instance.
395
* @param prefer_remote If non-zero, the negotiator will use the codec
396
* order as specified in remote offer. If zero, it
397
* will prefer to use the local codec order.
400
pjmedia_sdp_neg_set_prefer_remote_codec_order(pjmedia_sdp_neg *neg,
401
pj_bool_t prefer_remote);
405
* Get SDP negotiator state.
407
* @param neg The SDP negotiator instance.
409
* @return The negotiator state.
411
PJ_DECL(pjmedia_sdp_neg_state)
412
pjmedia_sdp_neg_get_state( pjmedia_sdp_neg *neg );
415
* Get the currently active local SDP. Application can only call this
416
* function after negotiation has been done, or otherwise there won't be
417
* active SDPs. Calling this function will not change the state of the
420
* @param neg The SDP negotiator instance.
421
* @param local Pointer to receive the local active SDP.
423
* @return PJ_SUCCESS if local active SDP is present.
426
pjmedia_sdp_neg_get_active_local( pjmedia_sdp_neg *neg,
427
const pjmedia_sdp_session **local);
430
* Get the currently active remote SDP. Application can only call this
431
* function after negotiation has been done, or otherwise there won't be
432
* active SDPs. Calling this function will not change the state of the
435
* @param neg The SDP negotiator instance.
436
* @param remote Pointer to receive the remote active SDP.
438
* @return PJ_SUCCESS if remote active SDP is present.
441
pjmedia_sdp_neg_get_active_remote( pjmedia_sdp_neg *neg,
442
const pjmedia_sdp_session **remote);
446
* Determine whether remote sent answer (as opposed to offer) on the
447
* last negotiation. This function can only be called in state
448
* PJMEDIA_SDP_NEG_STATE_DONE.
450
* @param neg The SDP negotiator instance.
452
* @return Non-zero if it was remote who sent answer,
453
* otherwise zero if it was local who supplied
457
pjmedia_sdp_neg_was_answer_remote(pjmedia_sdp_neg *neg);
461
* Get the current remote SDP offer or answer. Application can only
462
* call this function in state PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER or
463
* PJMEDIA_SDP_NEG_STATE_WAIT_NEGO, or otherwise there won't be remote
464
* SDP offer/answer. Calling this function will not change the state
467
* @param neg The SDP negotiator instance.
468
* @param remote Pointer to receive the current remote offer or
471
* @return PJ_SUCCESS if the negotiator currently has
472
* remote offer or answer.
475
pjmedia_sdp_neg_get_neg_remote( pjmedia_sdp_neg *neg,
476
const pjmedia_sdp_session **remote);
480
* Get the current local SDP offer or answer. Application can only
481
* call this function in state PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER or
482
* PJMEDIA_SDP_NEG_STATE_WAIT_NEGO, or otherwise there won't be local
483
* SDP offer/answer. Calling this function will not change the state
486
* @param neg The SDP negotiator instance.
487
* @param local Pointer to receive the current local offer or
490
* @return PJ_SUCCESS if the negotiator currently has
491
* local offer or answer.
494
pjmedia_sdp_neg_get_neg_local( pjmedia_sdp_neg *neg,
495
const pjmedia_sdp_session **local);
498
* Modify local session with a new SDP and treat this as a new offer.
499
* This function can only be called in state PJMEDIA_SDP_NEG_STATE_DONE.
500
* After calling this function, application can send the SDP as offer
501
* to remote party, using signaling protocol such as SIP.
502
* The negotiator state will move to PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER,
503
* where it waits for SDP answer from remote.
505
* @param pool Pool to allocate memory. The pool's lifetime needs
506
* to be valid for the duration of the negotiator.
507
* @param neg The SDP negotiator instance.
508
* @param local The new local SDP.
510
* @return PJ_SUCCESS on success, or the appropriate
514
pjmedia_sdp_neg_modify_local_offer( pj_pool_t *pool,
515
pjmedia_sdp_neg *neg,
516
const pjmedia_sdp_session *local);
519
* This function can only be called in PJMEDIA_SDP_NEG_STATE_DONE state.
520
* Application calls this function to retrieve currently active
521
* local SDP, and then send the SDP to remote as an offer. The negotiator
522
* state will then move to PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER, where it waits
523
* for SDP answer from remote.
525
* When SDP answer has been received from remote, application must call
526
* #pjmedia_sdp_neg_set_remote_answer().
528
* @param pool Pool to allocate memory. The pool's lifetime needs
529
* to be valid for the duration of the negotiator.
530
* @param neg The SDP negotiator instance.
531
* @param offer Pointer to receive active local SDP to be
534
* @return PJ_SUCCESS if local offer can be created.
537
pjmedia_sdp_neg_send_local_offer( pj_pool_t *pool,
538
pjmedia_sdp_neg *neg,
539
const pjmedia_sdp_session **offer);
542
* This function can only be called in PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER
543
* state, i.e. after application calls #pjmedia_sdp_neg_send_local_offer()
544
* function. Application calls this function when it receives SDP answer
545
* from remote. After this function is called, the negotiator state will
546
* move to PJMEDIA_SDP_NEG_STATE_WAIT_NEGO, and application can call the
547
* negotiation function #pjmedia_sdp_neg_negotiate().
549
* @param pool Pool to allocate memory. The pool's lifetime needs
550
* to be valid for the duration of the negotiator.
551
* @param neg The SDP negotiator instance.
552
* @param remote The remote answer.
554
* @return PJ_SUCCESS on success.
557
pjmedia_sdp_neg_set_remote_answer( pj_pool_t *pool,
558
pjmedia_sdp_neg *neg,
559
const pjmedia_sdp_session *remote);
564
* This function can only be called in PJMEDIA_SDP_NEG_STATE_DONE state.
565
* Application calls this function when it receives SDP offer from remote.
566
* After this function is called, the negotiator state will move to
567
* PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER, and application MUST call the
568
* #pjmedia_sdp_neg_set_local_answer() to set local answer before it can
569
* call the negotiation function.
571
* @param pool Pool to allocate memory. The pool's lifetime needs
572
* to be valid for the duration of the negotiator.
573
* @param neg The SDP negotiator instance.
574
* @param remote The remote offer.
576
* @return PJ_SUCCESS on success.
579
pjmedia_sdp_neg_set_remote_offer( pj_pool_t *pool,
580
pjmedia_sdp_neg *neg,
581
const pjmedia_sdp_session *remote);
586
* This function can only be called in PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER
587
* state, i.e. after application calls #pjmedia_sdp_neg_set_remote_offer()
588
* function. After this function is called, the negotiator state will
589
* move to PJMEDIA_SDP_NEG_STATE_WAIT_NEGO, and application can call the
590
* negotiation function #pjmedia_sdp_neg_negotiate().
592
* @param pool Pool to allocate memory. The pool's lifetime needs
593
* to be valid for the duration of the negotiator.
594
* @param neg The SDP negotiator instance.
595
* @param local Optional local answer. If negotiator has initial
596
* local capability, application can specify NULL on
597
* this argument; in this case, the negotiator will
598
* create answer by by negotiating remote offer with
599
* initial local capability. If negotiator doesn't have
600
* initial local capability, application MUST specify
603
* @return PJ_SUCCESS on success.
606
pjmedia_sdp_neg_set_local_answer( pj_pool_t *pool,
607
pjmedia_sdp_neg *neg,
608
const pjmedia_sdp_session *local);
612
* Call this function when the negotiator is in PJMEDIA_SDP_NEG_STATE_WAIT_NEGO
613
* state to see if it was local who is answering the offer (instead of
616
* @param neg The negotiator.
618
* @return PJ_TRUE if it is local is answering an offer, PJ_FALSE
619
* if remote has answered local offer.
621
PJ_DECL(pj_bool_t) pjmedia_sdp_neg_has_local_answer(pjmedia_sdp_neg *neg);
625
* Cancel any pending offer, whether the offer is initiated by local or
626
* remote, and move negotiator state back to previous stable state
627
* (PJMEDIA_SDP_NEG_STATE_DONE). The negotiator must be in
628
* PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER or PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER
631
* @param neg The negotiator.
633
* @return PJ_SUCCESS or the appropriate error code.
635
PJ_DECL(pj_status_t) pjmedia_sdp_neg_cancel_offer(pjmedia_sdp_neg *neg);
639
* Negotiate local and remote answer. Before calling this function, the
640
* SDP negotiator must be in PJMEDIA_SDP_NEG_STATE_WAIT_NEGO state.
641
* After calling this function, the negotiator state will move to
642
* PJMEDIA_SDP_NEG_STATE_DONE regardless whether the negotiation has
643
* been successfull or not.
645
* If the negotiation succeeds (i.e. the return value is PJ_SUCCESS),
646
* the active local and remote SDP will be replaced with the new SDP
647
* from the negotiation process.
649
* If the negotiation fails, the active local and remote SDP will not
652
* @param pool Pool to allocate memory. The pool's lifetime needs
653
* to be valid for the duration of the negotiator.
654
* @param neg The SDP negotiator instance.
655
* @param allow_asym Should be zero.
657
* @return PJ_SUCCESS when there is at least one media
658
* is actuve common in both offer and answer, or
659
* failure code when negotiation has failed.
661
PJ_DECL(pj_status_t) pjmedia_sdp_neg_negotiate( pj_pool_t *pool,
662
pjmedia_sdp_neg *neg,
663
pj_bool_t allow_asym);
667
* Enumeration of customized SDP format matching option flags. See
668
* #pjmedia_sdp_neg_register_fmt_match_cb() for more info.
670
typedef enum pjmedia_sdp_neg_fmt_match_flag
673
* In generating answer, the SDP fmtp in the answer candidate may need
674
* to be modified by the customized SDP format matching callback to
675
* achieve flexible SDP negotiation, e.g: AMR fmtp 'octet-align' field
676
* can be adjusted with the offer when the codec implementation support
677
* both packetization modes octet-aligned and bandwidth-efficient.
679
PJMEDIA_SDP_NEG_FMT_MATCH_ALLOW_MODIFY_ANSWER = 1,
681
} pjmedia_sdp_neg_fmt_match_flag;
685
* The declaration of customized SDP format matching callback. See
686
* #pjmedia_sdp_neg_register_fmt_match_cb() for more info.
688
* @param pool The memory pool.
689
* @param offer The SDP media offer.
690
* @param o_fmt_idx Index of the format in the SDP media offer.
691
* @param answer The SDP media answer.
692
* @param a_fmt_idx Index of the format in the SDP media answer.
693
* @param option The format matching option, see
694
* #pjmedia_sdp_neg_fmt_match_flag.
696
* @return PJ_SUCCESS when the formats in offer and answer match.
698
typedef pj_status_t (*pjmedia_sdp_neg_fmt_match_cb)(pj_pool_t *pool,
699
pjmedia_sdp_media *offer,
701
pjmedia_sdp_media *answer,
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.
716
* To unregister the callback of specific format, just call this function with
717
* parameter #cb set to NULL.
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.
725
* @return PJ_SUCCESS on success.
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);
733
* Match format in the SDP media offer and answer. The matching mechanism
734
* will be done by comparing the encoding name and clock rate, and if the
735
* custom format matching callback for the specified format is registered,
736
* see #pjmedia_sdp_neg_register_fmt_match_cb(), it will be called for more
737
* detail verification, e.g: format parameters specified in SDP fmtp.
739
* @param pool The memory pool.
740
* @param offer The SDP media offer.
741
* @param o_fmt_idx Index of the format in the SDP media offer.
742
* @param answer The SDP media answer.
743
* @param a_fmt_idx Index of the format in the SDP media answer.
744
* @param option The format matching option, see
745
* #pjmedia_sdp_neg_fmt_match_flag.
747
* @return PJ_SUCCESS when the formats in offer and answer match.
749
PJ_DECL(pj_status_t) pjmedia_sdp_neg_fmt_match( pj_pool_t *pool,
750
pjmedia_sdp_media *offer,
752
pjmedia_sdp_media *answer,
764
#endif /* __PJMEDIA_SDP_NEG_H__ */