~ubuntu-branches/ubuntu/maverick/sflphone/maverick

« back to all changes in this revision

Viewing changes to sflphone-common/libs/pjproject/pjmedia/include/pjmedia/sdp_neg.h

  • Committer: Bazaar Package Importer
  • Author(s): Francois Marier
  • Date: 2010-06-03 15:59:46 UTC
  • Revision ID: james.westby@ubuntu.com-20100603155946-ybe8d8o8zx8lp0m8
Tags: upstream-0.9.8.3
ImportĀ upstreamĀ versionĀ 0.9.8.3

Show diffs side-by-side

added added

removed removed

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