Updated pjsua_app.py Python sample application to the new changes in Python module (thanks Gideon Klompje)

git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@1438 74dad513-b988-da41-8d7b-12977e46ad98
This commit is contained in:
Benny Prijono 2007-09-17 15:44:47 +00:00
parent 6e374780c5
commit d7ea605849
3 changed files with 31 additions and 28 deletions

View file

@ -19,8 +19,8 @@ C_LOG_LEVEL = 4
# STUN config. # STUN config.
# Set C_STUN_HOST to the address:port of the STUN server to enable STUN # Set C_STUN_HOST to the address:port of the STUN server to enable STUN
# #
#C_STUN_HOST = "" C_STUN_HOST = ""
C_STUN_HOST = "192.168.0.2" #C_STUN_HOST = "192.168.0.2"
#C_STUN_HOST = "stun.iptel.org:3478" #C_STUN_HOST = "stun.iptel.org:3478"
# SIP port # SIP port
@ -267,12 +267,16 @@ def add_account():
acc_cfg = py_pjsua.acc_config_default() acc_cfg = py_pjsua.acc_config_default()
acc_cfg.id = "sip:" + acc_username + "@" + acc_domain acc_cfg.id = "sip:" + acc_username + "@" + acc_domain
acc_cfg.reg_uri = "sip:" + acc_domain acc_cfg.reg_uri = "sip:" + acc_domain
acc_cfg.cred_count = 1
acc_cfg.cred_info[0].realm = acc_domain cred_info = py_pjsua.Pjsip_Cred_Info()
acc_cfg.cred_info[0].scheme = "digest" cred_info.realm = "*"
acc_cfg.cred_info[0].username = acc_username cred_info.scheme = "digest"
acc_cfg.cred_info[0].data_type = 0 cred_info.username = acc_username
acc_cfg.cred_info[0].data = acc_passwd cred_info.data_type = 0
cred_info.data = acc_passwd
acc_cfg.cred_info.append(1)
acc_cfg.cred_info[0] = cred_info
# Add new SIP account # Add new SIP account
status, acc_id = py_pjsua.acc_add(acc_cfg, 1) status, acc_id = py_pjsua.acc_add(acc_cfg, 1)
@ -338,8 +342,8 @@ def conf_list():
info = None info = None
info = py_pjsua.conf_get_port_info(port) info = py_pjsua.conf_get_port_info(port)
txlist = "" txlist = ""
for i in range(info.listener_cnt): for listener in info.listeners:
txlist = txlist + "#" + `info.listeners[i]` + " " txlist = txlist + "#" + `listener` + " "
print "Port #" + `info.slot_id` + "[" + `(info.clock_rate/1000)` + "KHz/" + `(info.samples_per_frame * 1000 / info.clock_rate)` + "ms] " + info.name + " transmitting to: " + txlist print "Port #" + `info.slot_id` + "[" + `(info.clock_rate/1000)` + "KHz/" + `(info.samples_per_frame * 1000 / info.clock_rate)` + "ms] " + info.name + " transmitting to: " + txlist

View file

@ -2403,7 +2403,6 @@ typedef struct
unsigned channel_count; unsigned channel_count;
unsigned samples_per_frame; unsigned samples_per_frame;
unsigned bits_per_sample; unsigned bits_per_sample;
unsigned listener_cnt;
PyListObject * listeners; PyListObject * listeners;
} PyObj_pjsua_conf_port_info; } PyObj_pjsua_conf_port_info;
@ -2443,7 +2442,7 @@ static PyObject * conf_port_info_new(PyTypeObject *type, PyObject *args,
return NULL; return NULL;
} }
self->listeners = (PyListObject *)PyList_New(PJSUA_MAX_CONF_PORTS); self->listeners = (PyListObject *)PyList_New(0);
if (self->listeners == NULL) if (self->listeners == NULL)
{ {
Py_DECREF(self); Py_DECREF(self);
@ -2488,11 +2487,6 @@ static PyMemberDef conf_port_info_members[] =
offsetof(PyObj_pjsua_conf_port_info, bits_per_sample), 0, offsetof(PyObj_pjsua_conf_port_info, bits_per_sample), 0,
"Bits per sample" "Bits per sample"
}, },
{
"listener_cnt", T_INT,
offsetof(PyObj_pjsua_conf_port_info, listener_cnt), 0,
"Number of listeners in the array."
},
{ {
"listeners", T_OBJECT_EX, "listeners", T_OBJECT_EX,
offsetof(PyObj_pjsua_conf_port_info, listeners), 0, offsetof(PyObj_pjsua_conf_port_info, listeners), 0,
@ -3166,7 +3160,7 @@ static PyObject *py_pjsua_conf_get_port_info
PyObj_pjsua_conf_port_info * obj; PyObj_pjsua_conf_port_info * obj;
pjsua_conf_port_info info; pjsua_conf_port_info info;
int status; int status;
int i; unsigned i;
PJ_UNUSED_ARG(pSelf); PJ_UNUSED_ARG(pSelf);
@ -3182,12 +3176,12 @@ static PyObject *py_pjsua_conf_get_port_info
obj->bits_per_sample = info.bits_per_sample; obj->bits_per_sample = info.bits_per_sample;
obj->channel_count = info.bits_per_sample; obj->channel_count = info.bits_per_sample;
obj->clock_rate = info.clock_rate; obj->clock_rate = info.clock_rate;
obj->listener_cnt = info.listener_cnt;
obj->name = PyString_FromStringAndSize(info.name.ptr, info.name.slen); obj->name = PyString_FromStringAndSize(info.name.ptr, info.name.slen);
obj->samples_per_frame = info.samples_per_frame; obj->samples_per_frame = info.samples_per_frame;
obj->slot_id = info.slot_id; obj->slot_id = info.slot_id;
for (i = 0; i < PJSUA_MAX_CONF_PORTS; i++) { obj->listeners = (PyListObject *)PyList_New(info.listener_cnt);
for (i = 0; i < info.listener_cnt; i++) {
PyObject * item = Py_BuildValue("i",info.listeners[i]); PyObject * item = Py_BuildValue("i",info.listeners[i]);
PyList_SetItem((PyObject *)obj->listeners, i, item); PyList_SetItem((PyObject *)obj->listeners, i, item);
} }

View file

@ -28,8 +28,13 @@ PJ_INLINE(pj_str_t) PyString_to_pj_str(const PyObject *obj)
{ {
pj_str_t str; pj_str_t str;
str.ptr = PyString_AS_STRING(obj); if (obj) {
str.slen = PyString_GET_SIZE(obj); str.ptr = PyString_AS_STRING(obj);
str.slen = PyString_GET_SIZE(obj);
} else {
str.ptr = NULL;
str.slen = 0;
}
return str; return str;
} }
@ -1905,25 +1910,25 @@ static void PyObj_pjsua_acc_config_import(PyObj_pjsua_acc_config *obj,
obj->force_contact = PyString_FromStringAndSize(cfg->force_contact.ptr, obj->force_contact = PyString_FromStringAndSize(cfg->force_contact.ptr,
cfg->force_contact.slen); cfg->force_contact.slen);
Py_XDECREF(obj->proxy); Py_XDECREF(obj->proxy);
obj->proxy = (PyListObject *)PyList_New(8); obj->proxy = (PyListObject *)PyList_New(0);
for (i=0; i<cfg->proxy_cnt; ++i) { for (i=0; i<cfg->proxy_cnt; ++i) {
PyObject * str; PyObject * str;
str = PyString_FromStringAndSize(cfg->proxy[i].ptr, str = PyString_FromStringAndSize(cfg->proxy[i].ptr,
cfg->proxy[i].slen); cfg->proxy[i].slen);
PyList_SetItem((PyObject *)obj->proxy, i, str); PyList_Append((PyObject *)obj->proxy, str);
} }
obj->reg_timeout = cfg->reg_timeout; obj->reg_timeout = cfg->reg_timeout;
Py_XDECREF(obj->cred_info); Py_XDECREF(obj->cred_info);
obj->cred_info = (PyListObject *)PyList_New(8); obj->cred_info = (PyListObject *)PyList_New(0);
for (i=0; i<cfg->cred_count; ++i) { for (i=0; i<cfg->cred_count; ++i) {
PyObj_pjsip_cred_info * ci; PyObj_pjsip_cred_info * ci;
ci = (PyObj_pjsip_cred_info *) ci = (PyObj_pjsip_cred_info *)
PyObj_pjsip_cred_info_new(&PyTyp_pjsip_cred_info,NULL,NULL); PyObj_pjsip_cred_info_new(&PyTyp_pjsip_cred_info,NULL,NULL);
PyObj_pjsip_cred_info_import(ci, &cfg->cred_info[i]); PyObj_pjsip_cred_info_import(ci, &cfg->cred_info[i]);
PyList_SetItem((PyObject *)obj->cred_info, i, (PyObject *)ci); PyList_Append((PyObject *)obj->cred_info, (PyObject *)ci);
} }
obj->transport_id = cfg->transport_id; obj->transport_id = cfg->transport_id;
@ -1991,12 +1996,12 @@ static PyObject * PyObj_pjsua_acc_config_new(PyTypeObject *type,
Py_DECREF(self); Py_DECREF(self);
return NULL; return NULL;
} }
self->proxy = (PyListObject *)PyList_New(8); self->proxy = (PyListObject *)PyList_New(0);
if (self->proxy == NULL) { if (self->proxy == NULL) {
Py_DECREF(self); Py_DECREF(self);
return NULL; return NULL;
} }
self->cred_info = (PyListObject *)PyList_New(8); self->cred_info = (PyListObject *)PyList_New(0);
if (self->cred_info == NULL) { if (self->cred_info == NULL) {
Py_DECREF(self); Py_DECREF(self);
return NULL; return NULL;