Ignore:
Timestamp:
Feb 26, 2006 9:23:45 PM (18 years ago)
Author:
bennylp
Message:

Major redesign in pjsua: call is indexed by number, multiple accounts, configurable max-calls, more auto-xxx features, fixed bugs in save_settings(), etc.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsua/pjsua.h

    r223 r236  
    4848 * Max buddies in buddy list. 
    4949 */ 
    50 #define PJSUA_MAX_BUDDIES   32 
     50#ifndef PJSUA_MAX_BUDDIES 
     51#   define PJSUA_MAX_BUDDIES        32 
     52#endif 
     53 
    5154 
    5255/** 
    5356 * Max simultaneous calls. 
    5457 */ 
    55 #define PJSUA_MAX_CALLS     8 
     58#ifndef PJSUA_MAX_CALLS 
     59#   define PJSUA_MAX_CALLS          256 
     60#endif 
     61 
     62 
     63/** 
     64 * Aditional ports to be allocated in the conference ports for non-call 
     65 * streams. 
     66 */ 
     67#define PJSUA_CONF_MORE_PORTS       2 
     68 
     69 
     70/** 
     71 * Maximum accounts. 
     72 */ 
     73#ifndef PJSUA_MAX_ACC 
     74#   define PJSUA_MAX_ACC            8 
     75#endif 
     76 
     77 
     78/** 
     79 * Maximum credentials. 
     80 */ 
     81#ifndef PJSUA_MAX_CRED 
     82#   define PJSUA_MAX_CRED           PJSUA_MAX_ACC 
     83#endif 
    5684 
    5785 
    5886/**  
    59  * Structure to be attached to all dialog.  
     87 * Structure to be attached to invite dialog.  
    6088 * Given a dialog "dlg", application can retrieve this structure 
    6189 * by accessing dlg->mod_data[pjsua.mod.id]. 
    6290 */ 
    63 struct pjsua_inv_data 
     91struct pjsua_call 
    6492{ 
    65     PJ_DECL_LIST_MEMBER(struct pjsua_inv_data); 
    66  
     93    unsigned             index;     /**< Index in pjsua array.              */ 
    6794    pjsip_inv_session   *inv;       /**< The invite session.                */ 
     95    int                  acc_index; /**< Account index being used.          */ 
    6896    pjmedia_session     *session;   /**< The media session.                 */ 
    6997    unsigned             conf_slot; /**< Slot # in conference bridge.       */ 
    70     unsigned             call_slot; /**< RTP media index in med_sock_use[]  */ 
    7198    pjsip_evsub         *xfer_sub;  /**< Xfer server subscription, if this 
    7299                                         call was triggered by xfer.        */ 
     100    pjmedia_sock_info    skinfo;    /**< Preallocated media sockets.        */ 
     101 
     102    void                *app_data;  /**< Application data.                  */ 
    73103}; 
     104 
     105typedef struct pjsua_call pjsua_call; 
    74106 
    75107 
     
    80112{ 
    81113    pj_str_t             uri;       /**< Buddy URI                      */ 
     114    int                  acc_index; /**< Which account to use.          */ 
    82115    pj_bool_t            monitor;   /**< Should we monitor?             */ 
    83116    pjsip_evsub         *sub;       /**< Buddy presence subscription    */ 
     
    101134 
    102135 
     136/** 
     137 * Account 
     138 */ 
     139struct pjsua_acc 
     140{ 
     141    int              index;         /**< Index in accounts array.       */ 
     142    pj_str_t         local_uri;     /**< Uri in From: header.           */ 
     143    pj_str_t         user_part;     /**< User part of local URI.        */ 
     144    pj_str_t         host_part;     /**< Host part of local URI.        */ 
     145    pj_str_t         contact_uri;   /**< Uri in Contact: header.        */ 
     146 
     147    pj_str_t         reg_uri;       /**< Registrar URI.                 */ 
     148    pjsip_regc      *regc;          /**< Client registration session.   */ 
     149    pj_int32_t       reg_timeout;   /**< Default timeout.               */ 
     150    pj_timer_entry   reg_timer;     /**< Registration timer.            */ 
     151    pj_status_t      reg_last_err;  /**< Last registration error.       */ 
     152    int              reg_last_code; /**< Last status last register.     */ 
     153 
     154    pj_str_t         proxy;         /**< Proxy URL.                     */ 
     155    pjsip_route_hdr  route_set;     /**< Route set.                     */ 
     156 
     157    pj_bool_t        online_status; /**< Our online status.             */ 
     158    pjsua_srv_pres   pres_srv_list; /**< Server subscription list.      */ 
     159 
     160    void            *app_data;      /**< Application data.              */ 
     161}; 
     162 
     163 
     164typedef struct pjsua_acc pjsua_acc; 
     165 
    103166 
    104167/* PJSUA application variables. */ 
     
    106169{ 
    107170    /* Control: */ 
    108  
    109171    pj_caching_pool  cp;            /**< Global pool factory.           */ 
    110172    pjsip_endpoint  *endpt;         /**< Global endpoint.               */ 
     
    114176 
    115177    /* Media:  */ 
    116  
    117178    pjmedia_endpt   *med_endpt;     /**< Media endpoint.                */ 
    118     unsigned         max_ports;     /**< Max ports in conf.             */ 
    119179    pjmedia_conf    *mconf;         /**< Media conference.              */ 
    120180    pj_bool_t        null_audio;    /**< Null audio flag.               */ 
    121181    char            *wav_file;      /**< WAV file name to play.         */ 
    122182    unsigned         wav_slot;      /**< WAV player slot in bridge      */ 
     183    pj_bool_t        auto_play;     /**< Auto play file for calls?      */ 
     184    pj_bool_t        auto_loop;     /**< Auto loop RTP stream?          */ 
     185    pj_bool_t        auto_conf;     /**< Auto put to conference?        */ 
     186 
    123187 
    124188    /* User Agent behaviour: */ 
    125  
    126189    int              auto_answer;   /**< Automatically answer in calls. */ 
    127190 
    128  
    129     /* Since we support simultaneous calls, we need to have multiple 
    130      * RTP sockets. 
    131      */ 
    132     pjmedia_sock_info med_sock_info[PJSUA_MAX_CALLS]; 
    133     pj_bool_t         med_sock_use[PJSUA_MAX_CALLS]; 
    134  
    135     /* User info: */ 
    136  
    137     pj_str_t         local_uri;     /**< Uri in From: header.           */ 
    138     pj_str_t         contact_uri;   /**< Uri in Contact: header.        */ 
    139  
    140     /* Proxy URLs: */ 
    141  
    142     pj_str_t         proxy; 
    143     pj_str_t         outbound_proxy; 
    144     pjsip_route_hdr  route_set; 
    145  
    146  
    147     /* Registration: */ 
    148  
    149     pj_str_t         registrar_uri; 
    150     pjsip_regc      *regc; 
    151     pj_int32_t       reg_timeout; 
    152     pj_timer_entry   regc_timer; 
    153     pj_status_t      regc_last_err; /**< Last registration error.       */ 
    154     int              regc_last_code;/**< Last status last register.     */ 
     191    /* Account: */ 
     192    int              acc_cnt;       /**< Number of client registrations */ 
     193    pjsua_acc        acc[PJSUA_MAX_ACC];    /** Client regs array.      */ 
    155194 
    156195 
    157196    /* Authentication credentials: */ 
    158197 
    159     unsigned         cred_count; 
    160     pjsip_cred_info  cred_info[4]; 
     198    int              cred_count;    /**< Number of credentials.         */ 
     199    pjsip_cred_info  cred_info[10]; /**< Array of credentials.          */ 
    161200 
    162201 
    163202    /* Threading (optional): */ 
    164  
    165203    int              thread_cnt;    /**< Thread count.                  */ 
    166204    pj_thread_t     *threads[8];    /**< Thread instances.              */ 
     
    168206 
    169207    /* Transport (UDP): */ 
    170  
    171208    pj_uint16_t      sip_port;      /**< SIP signaling port.            */ 
    172209    pj_sock_t        sip_sock;      /**< SIP UDP socket.                */ 
    173210    pj_sockaddr_in   sip_sock_name; /**< Public/STUN UDP socket addr.   */ 
    174211 
     212    pj_str_t         outbound_proxy;/**< Outbound proxy.                */ 
    175213 
    176214 
    177215    /* STUN: */ 
    178  
    179216    pj_str_t         stun_srv1; 
    180217    int              stun_port1; 
     
    183220 
    184221 
    185     /* Logging: */ 
    186      
     222    /* Logging: */     
    187223    int              log_level;     /**< Logging verbosity.             */ 
    188224    int              app_log_level; /**< stdout log verbosity.          */ 
     
    191227 
    192228 
    193     /* List of invite sessions: */ 
    194  
    195     struct pjsua_inv_data inv_list; 
     229    /* PJSUA Calls: */ 
     230    int              max_calls;     /**< Max nb of calls.               */ 
     231    int              call_cnt;      /**< Number of calls.               */ 
     232    pjsua_call       calls[PJSUA_MAX_CALLS];    /** Calls array.        */ 
    196233 
    197234 
    198235    /* SIMPLE and buddy status: */ 
    199  
    200     pj_bool_t       online_status;  /**< Out online status.             */ 
    201     pjsua_srv_pres  pres_srv_list;  /**< Server subscription list.      */ 
    202  
    203     unsigned        buddy_cnt; 
    204     pjsua_buddy     buddies[PJSUA_MAX_BUDDIES]; 
     236    int              buddy_cnt; 
     237    pjsua_buddy      buddies[PJSUA_MAX_BUDDIES]; 
    205238}; 
    206239 
     
    256289 
    257290 
    258 /***************************************************************************** 
    259  * PJSUA Invite session API (defined in pjsua_inv.c). 
    260  */ 
     291/** 
     292 * Find account for incoming request. 
     293 */ 
     294int pjsua_find_account_for_incoming(pjsip_rx_data *rdata); 
     295 
     296 
     297/** 
     298 * Find account for outgoing request. 
     299 */ 
     300int pjsua_find_account_for_outgoing(const pj_str_t *url); 
     301 
     302 
     303/***************************************************************************** 
     304 * PJSUA Call API (defined in pjsua_call.c). 
     305 */ 
     306 
     307/** 
     308 * Init pjsua call module. 
     309 */ 
     310pj_status_t pjsua_call_init(void); 
    261311 
    262312/** 
    263313 * Make outgoing call. 
    264314 */ 
    265 pj_status_t pjsua_invite(const char *cstr_dest_uri, 
    266                          struct pjsua_inv_data **p_inv_data); 
     315pj_status_t pjsua_make_call(int acc_index, 
     316                            const char *cstr_dest_uri, 
     317                            int *p_call_index); 
    267318 
    268319 
     
    270321 * Handle incoming invite request. 
    271322 */ 
    272 pj_bool_t pjsua_inv_on_incoming(pjsip_rx_data *rdata); 
    273  
     323pj_bool_t pjsua_call_on_incoming(pjsip_rx_data *rdata); 
     324 
     325 
     326/** 
     327 * Answer call. 
     328 */ 
     329void pjsua_call_answer(int call_index, int code); 
    274330 
    275331/** 
    276332 * Hangup call. 
    277333 */ 
    278 void pjsua_inv_hangup(struct pjsua_inv_data *inv_session, int code); 
     334void pjsua_call_hangup(int call_index, int code); 
    279335 
    280336 
     
    282338 * Put call on-hold. 
    283339 */ 
    284 void pjsua_inv_set_hold(struct pjsua_inv_data *inv_session); 
     340void pjsua_call_set_hold(int call_index); 
    285341 
    286342 
     
    288344 * Send re-INVITE (to release hold). 
    289345 */ 
    290 void pjsua_inv_reinvite(struct pjsua_inv_data *inv_session); 
     346void pjsua_call_reinvite(int call_index); 
    291347 
    292348 
     
    294350 * Transfer call. 
    295351 */ 
    296 void pjsua_inv_xfer_call(struct pjsua_inv_data *inv_session, 
    297                          const char *dest); 
    298  
    299  
    300 /** 
    301  * Callback to be called by session when invite session's state has changed. 
    302  */ 
    303 void pjsua_inv_on_state_changed(pjsip_inv_session *inv, pjsip_event *e); 
    304  
    305  
    306 /** 
    307  * Callback to be called by session when outgoing dialog has forked. 
    308  * This function will create a forked dialog. 
    309  */ 
    310 void pjsua_inv_on_new_session(pjsip_inv_session *inv, pjsip_event *e); 
    311  
    312  
    313 /** 
    314  * Callback to be called when SDP offer/answer negotiation has just completed 
    315  * in the session. This function will start/update media if negotiation 
    316  * has succeeded. 
    317  */ 
    318 void pjsua_inv_on_media_update(pjsip_inv_session *inv, pj_status_t status); 
    319  
    320 /** 
    321  * Callback called when invite session received new offer. 
    322  */ 
    323 void pjsua_inv_on_rx_offer( pjsip_inv_session *inv, 
    324                             const pjmedia_sdp_session *offer); 
    325  
    326 /** 
    327  * Callback to receive transaction state inside invite session or dialog 
    328  * (e.g. REFER, MESSAGE). 
    329  */ 
    330 void pjsua_inv_on_tsx_state_changed(pjsip_inv_session *inv, 
    331                                     pjsip_transaction *tsx, 
    332                                     pjsip_event *e); 
     352void pjsua_call_xfer(int call_index, const char *dest); 
     353 
    333354 
    334355/** 
     
    347368 * @param app_callback  Optional callback 
    348369 */ 
    349 pj_status_t pjsua_regc_init(void); 
     370pj_status_t pjsua_regc_init(int acc_index); 
    350371 
    351372/** 
     
    353374 * this will start unregistration process. 
    354375 */ 
    355 void pjsua_regc_update(pj_bool_t renew); 
     376void pjsua_regc_update(int acc_index, pj_bool_t renew); 
    356377 
    357378 
     
    370391 * Refresh both presence client and server subscriptions. 
    371392 */ 
    372 void pjsua_pres_refresh(void); 
     393void pjsua_pres_refresh(int acc_index); 
    373394 
    374395/** 
     
    393414 * Notify UI when invite state has changed. 
    394415 */ 
    395 void pjsua_ui_inv_on_state_changed(pjsip_inv_session *inv, pjsip_event *e); 
     416void pjsua_ui_inv_on_state_changed(int call_index, pjsip_event *e); 
    396417 
    397418/** 
    398419 * Notify UI when registration status has changed. 
    399420 */ 
    400 void pjsua_ui_regc_on_state_changed(int code); 
     421void pjsua_ui_regc_on_state_changed(int acc_index); 
    401422 
    402423 
     
    418439 */ 
    419440pj_status_t pjsua_load_settings(const char *filename); 
     441 
     442/** 
     443 * Dump settings. 
     444 */ 
     445int pjsua_dump_settings(char *buf, pj_size_t max); 
    420446 
    421447/** 
Note: See TracChangeset for help on using the changeset viewer.