Changeset 928


Ignore:
Timestamp:
Feb 3, 2007 5:23:22 PM (17 years ago)
Author:
bennylp
Message:

Added various PJSIP constants to Python module and bugfix in call_hangup()

Location:
pjproject/trunk/pjsip-apps/src/py_pjsua
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip-apps/src/py_pjsua/pjsua_app.py

    r926 r928  
     1# $Id$ 
     2# 
     3# Sample and simple Python script to make and receive calls, and do 
     4# presence and instant messaging/IM using PJSUA-API binding for Python. 
     5# 
     6# Copyright (C) 2003-2007 Benny Prijono <benny@prijono.org> 
     7# 
    18import py_pjsua 
    29import sys 
     
    3037        return "[Call " + `call_id` + " " + ci.remote_info + "]" 
    3138 
    32 # Handler when invite state has changed. 
     39# Callback when call state has changed. 
    3340# 
    3441def on_call_state(call_id, e):   
     
    3643        ci = py_pjsua.call_get_info(call_id) 
    3744        write_log(3, call_name(call_id) + " state = " + `ci.state_text`) 
    38         if ci.state == 6: 
     45        if ci.state == py_pjsua.PJSIP_INV_STATE_DISCONNECTED: 
    3946                g_current_call = py_pjsua.PJSUA_INVALID_ID 
    4047 
    41 # Handler for incoming call 
     48# Callback for incoming call 
    4249# 
    4350def on_incoming_call(acc_id, call_id, rdata): 
    4451        global g_current_call 
    4552        if g_current_call != py_pjsua.PJSUA_INVALID_ID: 
    46                 py_pjsua.call_answer(call_id, 486, "", None) 
     53                # There's call in progress - answer Busy 
     54                py_pjsua.call_answer(call_id, 486, None, None) 
    4755                return 
     56 
    4857        g_current_call = call_id 
    4958        ci = py_pjsua.call_get_info(call_id) 
    50         write_log(3, "Incoming call: " + call_name(call_id)) 
    51         py_pjsua.call_answer(call_id, 200, "", None) 
     59        write_log(3, "*** Incoming call: " + call_name(call_id) + "***") 
     60        write_log(3, "*** Press a to answer or h to hangup  ***"); 
    5261 
    5362         
    54 # Handler when media state has changed (e.g. established or terminated) 
     63# Callback when media state has changed (e.g. established or terminated) 
    5564# 
    5665def on_call_media_state(call_id): 
    5766        ci = py_pjsua.call_get_info(call_id) 
    58         if ci.media_status == 1: 
     67        if ci.media_status == py_pjsua.PJSUA_CALL_MEDIA_ACTIVE: 
    5968                py_pjsua.conf_connect(ci.conf_slot, 0) 
    6069                py_pjsua.conf_connect(0, ci.conf_slot) 
     
    6473 
    6574 
    66 # Handler when account registration state has changed 
     75# Callback when account registration state has changed 
    6776# 
    6877def on_reg_state(acc_id): 
     
    7483 
    7584 
     85# Callback when buddy's presence state has changed 
     86# 
    7687def on_buddy_state(buddy_id): 
    7788        write_log(3, "On Buddy state called") 
     
    8192        else: 
    8293                write_log(3, "Status : " + `buddy_info.status`) 
    83                  
     94 
     95# Callback on incoming pager (MESSAGE) 
     96#                
    8497def on_pager(call_id, strfrom, strto, contact, mime_type, text): 
    8598        write_log(3, "MESSAGE from " + `strfrom` + " : " + `text`) 
    86          
     99 
     100 
     101# Callback on the delivery status of outgoing pager (MESSAGE) 
     102#        
    87103def on_pager_status(call_id, strto, body, user_data, status, reason): 
    88104        write_log(3, "MESSAGE to " + `strto` + " status " + `status` + " reason " + `reason`) 
     105 
    89106 
    90107# Utility: display PJ error and exit 
     
    163180 
    164181        # Create UDP transport 
    165         status, transport_id = py_pjsua.transport_create(1, transport_cfg) 
     182        status, transport_id = \ 
     183            py_pjsua.transport_create(py_pjsua.PJSIP_TRANSPORT_UDP, transport_cfg) 
    166184        if status != 0: 
    167185                py_pjsua.destroy() 
     
    269287 +b   Add buddy 
    270288  m   Make call 
     289  a   Answer current call (if any) 
    271290  h   Hangup current call (if any) 
    272291  i   Send instant message 
     
    305324 
    306325                        # Send the IM! 
    307                         py_pjsua.im_send(g_acc_id, url, "", message, None, 0) 
     326                        py_pjsua.im_send(g_acc_id, url, None, message, None, 0) 
    308327 
    309328                elif choice[0] == "m": 
     
    343362                elif choice[0] == "h": 
    344363                        if g_current_call != py_pjsua.PJSUA_INVALID_ID: 
    345                                 py_pjsua.call_hangup(g_current_call, 603, "", None) 
     364                                py_pjsua.call_hangup(g_current_call, 603, None, None) 
     365                        else: 
     366                                print "No current call" 
     367 
     368                elif choice[0] == "a": 
     369                        if g_current_call != py_pjsua.PJSUA_INVALID_ID: 
     370                                py_pjsua.call_answer(g_current_call, 200, None, None) 
    346371                        else: 
    347372                                print "No current call" 
  • pjproject/trunk/pjsip-apps/src/py_pjsua/py_pjsua.c

    r926 r928  
    11/* $Id$ */ 
    22/*  
    3  * Copyright (C) 2003-2006 Benny Prijono <benny@prijono.org> 
     3 * Copyright (C) 2003-2007 Benny Prijono <benny@prijono.org> 
    44 * 
    55 * This program is free software; you can redistribute it and/or modify 
     
    75117511        return NULL; 
    75127512    } 
    7513     if (sr != Py_None) 
     7513    if (sr == Py_None) 
    75147514    { 
    75157515        reason = NULL; 
     
    83608360{ 
    83618361    PyObject* m = NULL; 
     8362#define ADD_CONSTANT(mod,name)  PyModule_AddIntConstant(mod,#name,name) 
    83628363 
    83638364     
     
    85888589    /* END OF LIB CALL */ 
    85898590 
    8590 #ifdef PJSUA_INVALID_ID 
     8591 
    85918592    /* 
    8592      * Constant to identify invalid ID for all sorts of IDs. 
     8593     * Add various constants. 
    85938594     */ 
    8594     PyModule_AddIntConstant(m, "PJSUA_INVALID_ID", PJSUA_INVALID_ID); 
    8595 #endif 
    8596  
    8597 #ifdef PJSUA_ACC_MAX_PROXIES 
    8598     /* 
    8599      * Maximum proxies in account. 
    8600      */ 
    8601     PyModule_AddIntConstant( 
    8602         m, "PJSUA_ACC_MAX_PROXIES ", PJSUA_ACC_MAX_PROXIES 
    8603     ); 
    8604 #endif 
    8605  
    8606 #ifdef PJSUA_MAX_ACC 
    8607     /* 
    8608      * Maximum account. 
    8609      */ 
    8610     PyModule_AddIntConstant( 
    8611         m, "PJSUA_MAX_ACC", PJSUA_MAX_ACC 
    8612     ); 
    8613 #endif 
    8614  
    8615 #ifdef PJSUA_REG_INTERVAL 
    8616     /* 
    8617      * Default registration interval.. 
    8618      */ 
    8619     PyModule_AddIntConstant( 
    8620         m, "PJSUA_REG_INTERVAL", PJSUA_REG_INTERVAL 
    8621     ); 
    8622 #endif 
    8623  
    8624 #ifdef PJSUA_PUBLISH_EXPIRATION 
    8625     /* 
    8626      * Default PUBLISH expiration 
    8627      */ 
    8628     PyModule_AddIntConstant( 
    8629         m, "PJSUA_PUBLISH_EXPIRATION", PJSUA_PUBLISH_EXPIRATION 
    8630     ); 
    8631 #endif 
    8632          
    8633 #ifdef PJSUA_DEFAULT_ACC_PRIORITY 
    8634     /* 
    8635      * Default account priority. 
    8636      */ 
    8637     PyModule_AddIntConstant( 
    8638         m, "PJSUA_DEFAULT_ACC_PRIORITY", PJSUA_DEFAULT_ACC_PRIORITY 
    8639     ); 
    8640 #endif 
    8641  
    8642 #ifdef PJSUA_MAX_BUDDIES 
    8643     /* 
    8644      * Default account priority. 
    8645      */ 
    8646     PyModule_AddIntConstant( 
    8647         m, "PJSUA_MAX_BUDDIES", PJSUA_MAX_BUDDIES 
    8648     ); 
    8649 #endif 
    8650  
    8651 #ifdef  PJSUA_MAX_CONF_PORTS 
    8652  
    8653     /* 
    8654      * Max ports in the conference bridge. 
    8655      */ 
    8656     PyModule_AddIntConstant( 
    8657         m, "PJSUA_MAX_CONF_PORTS", PJSUA_MAX_CONF_PORTS 
    8658     ); 
    8659  
    8660 #endif 
    8661  
    8662 #ifdef  PJSUA_DEFAULT_CLOCK_RATE   
    8663  
    8664     PyModule_AddIntConstant( 
    8665         m, "PJSUA_DEFAULT_CLOCK_RATE", PJSUA_DEFAULT_CLOCK_RATE 
    8666     ); 
    8667  
    8668 #endif 
    8669  
    8670 #ifdef  PJSUA_DEFAULT_CODEC_QUALITY   
    8671  
    8672     PyModule_AddIntConstant( 
    8673         m, "PJSUA_DEFAULT_CODEC_QUALITY", PJSUA_DEFAULT_CODEC_QUALITY 
    8674     ); 
    8675  
    8676 #endif 
    8677  
    8678 #ifdef  PJSUA_DEFAULT_ILBC_MODE    
    8679  
    8680     PyModule_AddIntConstant( 
    8681         m, "PJSUA_DEFAULT_ILBC_MODE", PJSUA_DEFAULT_ILBC_MODE 
    8682     ); 
    8683  
    8684 #endif 
    8685  
    8686 #ifdef  PJSUA_DEFAULT_EC_TAIL_LEN   
    8687  
    8688     PyModule_AddIntConstant( 
    8689         m, "PJSUA_DEFAULT_EC_TAIL_LEN", PJSUA_DEFAULT_EC_TAIL_LEN 
    8690     ); 
    8691  
    8692 #endif 
    8693  
    8694 #ifdef  PJSUA_MAX_CALLS   
    8695  
    8696     PyModule_AddIntConstant( 
    8697         m, "PJSUA_MAX_CALLS", PJSUA_MAX_CALLS 
    8698     ); 
    8699  
    8700 #endif 
    8701  
    8702 #ifdef  PJSUA_XFER_NO_REQUIRE_REPLACES 
    8703  
    8704     PyModule_AddIntConstant( 
    8705         m, "PJSUA_XFER_NO_REQUIRE_REPLACES", PJSUA_XFER_NO_REQUIRE_REPLACES 
    8706     ); 
    8707 #endif 
    8708  
    8709 } 
     8595 
     8596    /* Call states */ 
     8597    ADD_CONSTANT(m, PJSIP_INV_STATE_NULL); 
     8598    ADD_CONSTANT(m, PJSIP_INV_STATE_CALLING); 
     8599    ADD_CONSTANT(m, PJSIP_INV_STATE_INCOMING); 
     8600    ADD_CONSTANT(m, PJSIP_INV_STATE_EARLY); 
     8601    ADD_CONSTANT(m, PJSIP_INV_STATE_CONNECTING); 
     8602    ADD_CONSTANT(m, PJSIP_INV_STATE_CONFIRMED); 
     8603    ADD_CONSTANT(m, PJSIP_INV_STATE_DISCONNECTED); 
     8604 
     8605    /* Call media status (enum pjsua_call_media_status) */ 
     8606    ADD_CONSTANT(m, PJSUA_CALL_MEDIA_NONE); 
     8607    ADD_CONSTANT(m, PJSUA_CALL_MEDIA_ACTIVE); 
     8608    ADD_CONSTANT(m, PJSUA_CALL_MEDIA_LOCAL_HOLD); 
     8609    ADD_CONSTANT(m, PJSUA_CALL_MEDIA_REMOTE_HOLD); 
     8610 
     8611    /* Buddy status */ 
     8612    ADD_CONSTANT(m, PJSUA_BUDDY_STATUS_UNKNOWN); 
     8613    ADD_CONSTANT(m, PJSUA_BUDDY_STATUS_ONLINE); 
     8614    ADD_CONSTANT(m, PJSUA_BUDDY_STATUS_OFFLINE); 
     8615 
     8616    /* PJSIP transport types (enum pjsip_transport_type_e) */ 
     8617    ADD_CONSTANT(m, PJSIP_TRANSPORT_UNSPECIFIED); 
     8618    ADD_CONSTANT(m, PJSIP_TRANSPORT_UDP); 
     8619    ADD_CONSTANT(m, PJSIP_TRANSPORT_TCP); 
     8620    ADD_CONSTANT(m, PJSIP_TRANSPORT_TLS); 
     8621    ADD_CONSTANT(m, PJSIP_TRANSPORT_SCTP); 
     8622    ADD_CONSTANT(m, PJSIP_TRANSPORT_LOOP); 
     8623    ADD_CONSTANT(m, PJSIP_TRANSPORT_LOOP_DGRAM); 
     8624 
     8625 
     8626    /* Invalid IDs */ 
     8627    ADD_CONSTANT(m, PJSUA_INVALID_ID); 
     8628 
     8629 
     8630    /* Various compile time constants */ 
     8631    ADD_CONSTANT(m, PJSUA_ACC_MAX_PROXIES); 
     8632    ADD_CONSTANT(m, PJSUA_MAX_ACC); 
     8633    ADD_CONSTANT(m, PJSUA_REG_INTERVAL); 
     8634    ADD_CONSTANT(m, PJSUA_PUBLISH_EXPIRATION); 
     8635    ADD_CONSTANT(m, PJSUA_DEFAULT_ACC_PRIORITY); 
     8636    ADD_CONSTANT(m, PJSUA_MAX_BUDDIES); 
     8637    ADD_CONSTANT(m, PJSUA_MAX_CONF_PORTS); 
     8638    ADD_CONSTANT(m, PJSUA_DEFAULT_CLOCK_RATE); 
     8639    ADD_CONSTANT(m, PJSUA_DEFAULT_CODEC_QUALITY); 
     8640    ADD_CONSTANT(m, PJSUA_DEFAULT_ILBC_MODE); 
     8641    ADD_CONSTANT(m, PJSUA_DEFAULT_EC_TAIL_LEN); 
     8642    ADD_CONSTANT(m, PJSUA_MAX_CALLS); 
     8643    ADD_CONSTANT(m, PJSUA_XFER_NO_REQUIRE_REPLACES); 
     8644 
     8645 
     8646#undef ADD_CONSTANT 
     8647} 
Note: See TracChangeset for help on using the changeset viewer.