⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 py_pjsua.c

📁 基于sip协议的网络电话源码
💻 C
📖 第 1 页 / 共 5 页
字号:
    obj->max_media_ports = cfg.max_media_ports;    obj->no_vad = cfg.no_vad;    obj->ptime = cfg.ptime;    obj->quality = cfg.quality;    obj->rx_drop_pct = cfg.rx_drop_pct;    obj->thread_cnt = cfg.thread_cnt;    obj->tx_drop_pct = cfg.tx_drop_pct;    return (PyObject *)obj;}/* * py_pjsua_msg_data_init * !modified @ 051206 */static PyObject *py_pjsua_msg_data_init(PyObject *pSelf, PyObject *pArgs){    msg_data_Object *obj;    pjsua_msg_data msg;        if (!PyArg_ParseTuple(pArgs, ""))    {        return NULL;    }    pjsua_msg_data_init(&msg);    obj = (msg_data_Object *)msg_data_new(&msg_data_Type, NULL, NULL);    Py_XDECREF(obj->content_type);    obj->content_type = PyString_FromStringAndSize(        msg.content_type.ptr, msg.content_type.slen    );    Py_XDECREF(obj->msg_body);    obj->msg_body = PyString_FromStringAndSize(        msg.msg_body.ptr, msg.msg_body.slen    );    translate_hdr_rev((pjsip_generic_string_hdr *)&msg.hdr_list,obj->hdr_list);        return (PyObject *)obj;}/* * py_pjsua_reconfigure_logging */static PyObject *py_pjsua_reconfigure_logging(PyObject *pSelf, PyObject *pArgs){    PyObject * logObj;    logging_config_Object *log;    pjsua_logging_config cfg;    pj_status_t status;    if (!PyArg_ParseTuple(pArgs, "O", &logObj))    {        return NULL;    }    if (logObj != Py_None)     {        log = (logging_config_Object *)logObj;        cfg.msg_logging = log->msg_logging;        cfg.level = log->level;        cfg.console_level = log->console_level;        cfg.decor = log->decor;        cfg.log_filename.ptr = PyString_AsString(log->log_filename);        cfg.log_filename.slen = strlen(cfg.log_filename.ptr);        Py_XDECREF(obj_log_cb);        obj_log_cb = log->cb;        Py_INCREF(obj_log_cb);        cfg.cb = &cb_log_cb;        status = pjsua_reconfigure_logging(&cfg);    } else {        status = pjsua_reconfigure_logging(NULL);    }    return Py_BuildValue("i",status);}/* * py_pjsua_pool_create */static PyObject *py_pjsua_pool_create(PyObject *pSelf, PyObject *pArgs){    pj_size_t init_size;    pj_size_t increment;    const char * name;    pj_pool_t *p;    pj_pool_Object *pool;    if (!PyArg_ParseTuple(pArgs, "sII", &name, &init_size, &increment))    {        return NULL;    }        p = pjsua_pool_create(name, init_size, increment);    pool = (pj_pool_Object *)PyType_GenericNew(&pj_pool_Type, NULL, NULL);    pool->pool = p;    return (PyObject *)pool;}/* * py_pjsua_get_pjsip_endpt */static PyObject *py_pjsua_get_pjsip_endpt(PyObject *pSelf, PyObject *pArgs){    pjsip_endpoint_Object *endpt;    pjsip_endpoint *e;    if (!PyArg_ParseTuple(pArgs, ""))    {        return NULL;    }    e = pjsua_get_pjsip_endpt();    endpt = (pjsip_endpoint_Object *)PyType_GenericNew(        &pjsip_endpoint_Type, NULL, NULL    );    endpt->endpt = e;    return (PyObject *)endpt;}/* * py_pjsua_get_pjmedia_endpt */static PyObject *py_pjsua_get_pjmedia_endpt(PyObject *pSelf, PyObject *pArgs){    pjmedia_endpt_Object *endpt;    pjmedia_endpt *e;    if (!PyArg_ParseTuple(pArgs, ""))    {        return NULL;    }    e = pjsua_get_pjmedia_endpt();    endpt = (pjmedia_endpt_Object *)PyType_GenericNew(        &pjmedia_endpt_Type, NULL, NULL    );    endpt->endpt = e;    return (PyObject *)endpt;}/* * py_pjsua_get_pool_factory */static PyObject *py_pjsua_get_pool_factory(PyObject *pSelf, PyObject *pArgs){    pj_pool_factory_Object *pool;    pj_pool_factory *p;    if (!PyArg_ParseTuple(pArgs, ""))    {        return NULL;    }    p = pjsua_get_pool_factory();    pool = (pj_pool_factory_Object *)PyType_GenericNew(        &pj_pool_factory_Type, NULL, NULL    );    pool->pool_fact = p;    return (PyObject *)pool;}/* * py_pjsua_perror */static PyObject *py_pjsua_perror(PyObject *pSelf, PyObject *pArgs){    const char *sender;    const char *title;    pj_status_t status;    if (!PyArg_ParseTuple(pArgs, "ssi", &sender, &title, &status))    {        return NULL;    }	    pjsua_perror(sender, title, status);    Py_INCREF(Py_None);    return Py_None;}/* * py_pjsua_create */static PyObject *py_pjsua_create(PyObject *pSelf, PyObject *pArgs){    pj_status_t status;    if (!PyArg_ParseTuple(pArgs, ""))    {        return NULL;    }    status = pjsua_create();        if (status == PJ_SUCCESS)     {	status = pj_thread_local_alloc(&thread_id);	if (status == PJ_SUCCESS)	    status = pj_thread_local_set(thread_id, (void*)1);    }    return Py_BuildValue("i",status);}/* * py_pjsua_init */static PyObject *py_pjsua_init(PyObject *pSelf, PyObject *pArgs){    pj_status_t status;    PyObject * ua_cfgObj;    config_Object * ua_cfg;    PyObject * log_cfgObj;    logging_config_Object * log_cfg;    PyObject * media_cfgObj;    media_config_Object * media_cfg;    pjsua_config cfg_ua;    pjsua_config * p_cfg_ua;    pjsua_logging_config cfg_log;    pjsua_logging_config * p_cfg_log;    pjsua_media_config cfg_media;    pjsua_media_config * p_cfg_media;    unsigned i;    if (!PyArg_ParseTuple(pArgs, "OOO", &ua_cfgObj, &log_cfgObj,&media_cfgObj))    {        return NULL;    }        pjsua_config_default(&cfg_ua);    pjsua_logging_config_default(&cfg_log);    pjsua_media_config_default(&cfg_media);    if (ua_cfgObj != Py_None)     {	ua_cfg = (config_Object *)ua_cfgObj;        cfg_ua.cred_count = ua_cfg->cred_count;        for (i = 0; i < 4; i++)	{            cfg_ua.cred_info[i] = ua_cfg->cred_info[i];	}        cfg_ua.max_calls = ua_cfg->max_calls;        for (i = 0; i < PJSUA_ACC_MAX_PROXIES; i++)	{            cfg_ua.outbound_proxy[i] = ua_cfg->outbound_proxy[i];	}    	g_obj_callback = ua_cfg->cb;    	Py_INCREF(g_obj_callback);    	cfg_ua.cb.on_call_state = &cb_on_call_state;    	cfg_ua.cb.on_incoming_call = &cb_on_incoming_call;    	cfg_ua.cb.on_call_media_state = &cb_on_call_media_state;    	cfg_ua.cb.on_call_transfer_request = &cb_on_call_transfer_request;    	cfg_ua.cb.on_call_transfer_status = &cb_on_call_transfer_status;    	cfg_ua.cb.on_call_replace_request = &cb_on_call_replace_request;    	cfg_ua.cb.on_call_replaced = &cb_on_call_replaced;    	cfg_ua.cb.on_reg_state = &cb_on_reg_state;    	cfg_ua.cb.on_buddy_state = &cb_on_buddy_state;    	cfg_ua.cb.on_pager = &cb_on_pager;    	cfg_ua.cb.on_pager_status = &cb_on_pager_status;    	cfg_ua.cb.on_typing = &cb_on_typing;        cfg_ua.outbound_proxy_cnt = ua_cfg->outbound_proxy_cnt;        cfg_ua.thread_cnt = ua_cfg->thread_cnt;        cfg_ua.user_agent.ptr = PyString_AsString(ua_cfg->user_agent);        cfg_ua.user_agent.slen = strlen(cfg_ua.user_agent.ptr);        p_cfg_ua = &cfg_ua;    } else {        p_cfg_ua = NULL;    }    if (log_cfgObj != Py_None)     {        log_cfg = (logging_config_Object *)log_cfgObj;        cfg_log.msg_logging = log_cfg->msg_logging;        cfg_log.level = log_cfg->level;        cfg_log.console_level = log_cfg->console_level;        cfg_log.decor = log_cfg->decor;        cfg_log.log_filename.ptr = PyString_AsString(log_cfg->log_filename);        cfg_log.log_filename.slen = strlen(cfg_log.log_filename.ptr);        Py_XDECREF(obj_log_cb);        obj_log_cb = log_cfg->cb;        Py_INCREF(obj_log_cb);        cfg_log.cb = &cb_log_cb;        p_cfg_log = &cfg_log;    } else {        p_cfg_log = NULL;    }    if (media_cfgObj != Py_None)     {        media_cfg = (media_config_Object *)media_cfgObj;        cfg_media.clock_rate = media_cfg->clock_rate;        cfg_media.ec_options = media_cfg->ec_options;        cfg_media.ec_tail_len = media_cfg->ec_tail_len;        cfg_media.has_ioqueue = media_cfg->has_ioqueue;        cfg_media.ilbc_mode = media_cfg->ilbc_mode;        cfg_media.max_media_ports = media_cfg->max_media_ports;        cfg_media.no_vad = media_cfg->no_vad;        cfg_media.ptime = media_cfg->ptime;        cfg_media.quality = media_cfg->quality;        cfg_media.rx_drop_pct = media_cfg->rx_drop_pct;        cfg_media.thread_cnt = media_cfg->thread_cnt;        cfg_media.tx_drop_pct = media_cfg->tx_drop_pct;	    p_cfg_media = &cfg_media;    } else {        p_cfg_media = NULL;    }    status = pjsua_init(p_cfg_ua, p_cfg_log, p_cfg_media);    return Py_BuildValue("i",status);}/* * py_pjsua_start */static PyObject *py_pjsua_start(PyObject *pSelf, PyObject *pArgs){    pj_status_t status;    if (!PyArg_ParseTuple(pArgs, ""))    {        return NULL;    }    status = pjsua_start();        return Py_BuildValue("i",status);}/* * py_pjsua_destroy */static PyObject *py_pjsua_destroy(PyObject *pSelf, PyObject *pArgs){    pj_status_t status;    if (!PyArg_ParseTuple(pArgs, ""))    {        return NULL;    }    status = pjsua_destroy();        return Py_BuildValue("i",status);}/* * py_pjsua_handle_events */static PyObject *py_pjsua_handle_events(PyObject *pSelf, PyObject *pArgs){    int ret;    unsigned msec;    if (!PyArg_ParseTuple(pArgs, "i", &msec))    {        return NULL;    }    /* Since handle_events() will block, we must wrap it with ALLOW_THREADS     * construct, or otherwise many Python blocking functions (such as     * time.sleep(), readline(), etc.) may hang/block indefinitely.     * See http://www.python.org/doc/current/api/threads.html for more info.     */    Py_BEGIN_ALLOW_THREADS    ret = pjsua_handle_events(msec);    Py_END_ALLOW_THREADS        return Py_BuildValue("i",ret);}/* * py_pjsua_verify_sip_url */static PyObject *py_pjsua_verify_sip_url(PyObject *pSelf, PyObject *pArgs){    pj_status_t status;    const char *url;    if (!PyArg_ParseTuple(pArgs, "s", &url))    {        return NULL;    }    status = pjsua_verify_sip_url(url);        return Py_BuildValue("i",status);}/* * function doc */static char pjsua_thread_register_doc[] =    "int py_pjsua.thread_register(string name, int[] desc)";static char pjsua_perror_doc[] =    "void py_pjsua.perror (string sender, string title, int status) "    "Display error message for the specified error code. Parameters: "    "sender: The log sender field;  "    "title: Message title for the error; "    "status: Status code.";static char pjsua_create_doc[] =    "int py_pjsua.create (void) "    "Instantiate pjsua application. Application "    "must call this function before calling any other functions, to make sure "    "that the underlying libraries are properly initialized. Once this "    "function has returned success, application must call pjsua_destroy() "    "before quitting.";static char pjsua_init_doc[] =    "int py_pjsua.init (py_pjsua.Config ua_cfg, "        "py_pjsua.Logging_Config log_cfg, py_pjsua.Media_Config media_cfg) "    "Initialize pjsua with the specified settings. All the settings are "    "optional, and the default values will be used when the config is not "    "specified. Parameters: "    "ua_cfg : User agent configuration;  "    "log_cfg : Optional logging configuration; "    "media_cfg : Optional media configuration.";static char pjsua_start_doc[] =    "int py_pjsua.start (void) "    "Application is recommended to call this function after all "    "initialization is done, so that the library can do additional checking "    "set up additional";static char pjsua_destroy_doc[] =    "int py_pjsua.destroy (void) "    "Destroy pjsua This function must be called once PJSUA is created. To "    "make it easier for application, application may call this function "    "several times with no danger.";static char pjsua_handle_events_doc[] =    "int py_pjsua.handle_events (int msec_timeout) "    "Poll pjsua for events, and if necessary block the caller thread for the "    "specified maximum interval (in miliseconds) Parameters: "    "msec_timeout: Maximum time to wait, in miliseconds. "    "Returns: The number of events that have been handled during the poll. "    "Negative value indicates error, and application can retrieve the error "    "as (err = -return_value).";static char pjsua_verify_sip_url_doc[] =    "int py_pjsua.verify_sip_url (string c_url) "    "Verify that valid SIP url is given Parameters: "    "c_url: The URL, as NULL terminated string.";static char pjsua_pool_create_doc[] =    "py_pjsua.PJ_Pool py_pjsua.pool_create (string name, int init_size, "                                            "int increment) "    "Create memory pool Parameters: "    "name: Optional pool name; "    "init_size: Initial size of the pool;  "    "increment: Increment size.";static char pjsua_get_pjsip_endpt_doc[] =    "py_pjsua.PJSIP_Endpoint py_pjsua.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -