Beispiel #1
0
/*
 * List the ports in conference bridge
 */
static void ui_conf_list()
{
    unsigned i, count;
    pjsua_conf_port_id id[PJSUA_MAX_CALLS];

    printf("Conference ports:\n");

    count = PJ_ARRAY_SIZE(id);
    pjsua_enum_conf_ports(id, &count);

    for (i=0; i<count; ++i) {
	char txlist[PJSUA_MAX_CALLS*4+10];
	unsigned j;
	pjsua_conf_port_info info;

	pjsua_conf_get_port_info(id[i], &info);

	txlist[0] = '\0';
	for (j=0; j<info.listener_cnt; ++j) {
	    char s[10];
	    pj_ansi_snprintf(s, sizeof(s), "#%d ", info.listeners[j]);
	    pj_ansi_strcat(txlist, s);
	}
	printf("Port #%02d[%2dKHz/%dms/%d] %20.*s  transmitting to: %s\n",
	       info.slot_id,
	       info.clock_rate/1000,
	       info.samples_per_frame*1000/info.channel_count/info.clock_rate,
	       info.channel_count,
	       (int)info.name.slen,
	       info.name.ptr,
	       txlist);

    }
    puts("");
}
Beispiel #2
0
QVDoorcom::QVDoorcom(QDomElement xml_desc, QString container, QWidget *parent) :
    QVElement(xml_desc,container,parent)
{
    if (w < 1) {
        w = 1;
    }
    if (h < 1) {
        h = 1;
    }
    popup = 0;
    if (instance_count > 0) {
        w = h = 0;
        return;
    }
    instance_count = 1;
    doorcom = this;

    popup = new QVPopupFrame(parent);

    QDomElement e_server = xml_desc.firstChildElement("server");
    QDomElement e_user = xml_desc.firstChildElement("user");
    QDomElement e_password = xml_desc.firstChildElement("password");
    if (e_server.isNull() || e_user.isNull() || e_password.isNull()) {
        qDebug() << "SIP client: insufficient auth info";
        return;
    }

    QString s_server = e_server.text();
    QString s_user = e_user.text();
    QString s_password = e_password.text();

    QDomElement e_caller = xml_desc.firstChildElement("source");
    if (!e_caller.isNull()) {
        accepted_caller = e_caller.text();
    }

    QDomElement e_accept = xml_desc.firstChildElement("accept");
    if (!e_accept.isNull()) {
        code_accept = e_accept.text();
    }

    QDomElement e_hangup = xml_desc.firstChildElement("hangup");
    if (!e_hangup.isNull()) {
        code_hangup = e_hangup.text();
    }

    QDomElement e_dooropen = xml_desc.firstChildElement("dooropen");
    if (!e_dooropen.isNull()) {
        code_dooropen = e_dooropen.text();
    }

    QFile f_doorbell;
    QString s_doorbell_name;
    bool doorbell_ok;
    bell_wav = 0;
    QDomElement e_doorbell = xml_desc.firstChildElement("ringtone");
    if (!e_doorbell.isNull()) {
        s_doorbell_name = findFilePath(e_doorbell.text());
        f_doorbell.setFileName(findFilePath(e_doorbell.text()));
        f_doorbell.open(QIODevice::ReadOnly);
    }
    if (!f_doorbell.isOpen()) {
        f_doorbell.setFileName(":/sounds/doorbell.wav");
        f_doorbell.open(QIODevice::ReadOnly);
    }

#ifndef DOORBELL_WAV
    QByteArray riff = f_doorbell.read(12);
    if (riff.length() < 12) {
        doorbell_ok = false;
    } else {
        if (!riff.startsWith("RIFF") || !riff.endsWith("WAVE")) {
            doorbell_ok = false;
        }
    }

    QByteArray fmthdr = f_doorbell.read(8);
    if (!fmthdr.startsWith("fmt")) {
        doorbell_ok = false;
    }
    uint32_t fmt_len;
    memcpy(&fmt_len,fmthdr.mid(4).data(),4);
    qDebug() << "fmt len" << fmt_len;
    if (fmt_len < 16) {
        doorbell_ok = false;
    }
    QByteArray fmt = f_doorbell.read(fmt_len);
    uint16_t audio_format;
    uint16_t num_channels;
    uint32_t sample_rate;
    uint32_t byte_rate;
    uint16_t block_align;
    uint16_t bits_per_sample;
    uint32_t bell_datalen;

#if (BYTE_ORDER != __LITTLE_ENDIAN)
#error Adapt endianness in __FILE__
#endif

    if (fmt.length() < fmt_len) {
        doorbell_ok = false;
    } else {
        memcpy(&audio_format,fmt.mid(0).data(),2);
        memcpy(&num_channels,fmt.mid(2).data(),2);
        memcpy(&sample_rate,fmt.mid(4).data(),4);
        memcpy(&byte_rate,fmt.mid(8).data(),4);
        memcpy(&block_align,fmt.mid(12).data(),2);
        memcpy(&bits_per_sample,fmt.mid(14).data(),2);
    }

    qDebug() << audio_format << "nch" << num_channels << "samplerate" << sample_rate << "byztera" << byte_rate << "blocka" << block_align << "bps" << bits_per_sample;
    if (audio_format != 0x0001) {
        doorbell_ok = false;
    }

    if (doorbell_ok) {
        QByteArray datahdr = f_doorbell.read(8);
        if (!datahdr.startsWith("data") || (datahdr.length() < 8)) {
            doorbell_ok = false;
        } else {
            memcpy(&bell_datalen,datahdr.mid(4).data(),4);
        }
        if (doorbell_ok && (bell_datalen > 0)) {
            QByteArray data = f_doorbell.read(bell_datalen);
            bell_wav = (char*)malloc(bell_datalen);
            if (bell_wav != 0) {
                memcpy(bell_wav,data.data(),bell_datalen);
            }
        }
    }
#endif

    active_call = -1;

    QObject::connect(this,SIGNAL(incomingCall(int)),this,SLOT(onIncomingCall(int)),Qt::QueuedConnection);
    QObject::connect(this,SIGNAL(callState(int,QString)),this,SLOT(onCallState(int,QString)),Qt::QueuedConnection);
    QObject::connect(this,SIGNAL(callMediaState(int)),this,SLOT(onCallMediaState(int)),Qt::QueuedConnection);

    w_accept = new QVSvgWidget(":/icons/phone_call.svg",popup->content());
    w_hangup = new QVSvgWidget(":/icons/phone_call_end.svg",popup->content());
    w_dooropen = new QVSvgWidget(":/icons/door_open.svg",popup->content());
    QObject::connect(w_accept,SIGNAL(clicked(double,double)),this,SLOT(onAcceptPressed()));
    QObject::connect(w_hangup,SIGNAL(clicked(double,double)),this,SLOT(onHangupPressed()));
    QObject::connect(w_dooropen,SIGNAL(clicked(double,double)),this,SLOT(onDoorOpenPressed()));

    hangup_timer.setSingleShot(true);
    hangup_timer.setInterval(800);
    QObject::connect(&hangup_timer,SIGNAL(timeout()),this,SLOT(onHangupTimer()));

    dtmf_timer.setSingleShot(true);
    dtmf_timer.setInterval(200);
    QObject::connect(&dtmf_timer,SIGNAL(timeout()),this,SLOT(onDTMFTimer()));

    /******* Init PJSUA ********/
    pjsua_acc_id acc_id;
    pj_status_t status;

    /* Create pjsua first! */
    status = pjsua_create();
    if (status != PJ_SUCCESS) {
        qDebug() << "Cannot create PJSUA SIP client, cause:" << status;
        return;
    }

    /* Init pjsua */
    pjsua_config cfg;
    pjsua_logging_config log_cfg;
    pjsua_media_config media_cfg;

    pjsua_config_default(&cfg);
    cfg.cb.on_incoming_call = &on_incoming_call;
    cfg.cb.on_call_media_state = &on_call_media_state;
    cfg.cb.on_call_state = &on_call_state;

    pjsua_logging_config_default(&log_cfg);
    log_cfg.console_level = 1;

    pjsua_media_config_default(&media_cfg);
    media_cfg.clock_rate = 8000;
    media_cfg.ec_tail_len = 0;

    status = pjsua_init(&cfg, &log_cfg, &media_cfg);
    if (status != PJ_SUCCESS) {
        qDebug() << "Cannot init PJSUA SIP client, cause: " << status;
        return;
    }

    /* Add UDP transport. */
    pjsua_transport_config transport_cfg;

    pjsua_transport_config_default(&transport_cfg);
    transport_cfg.port = 5060;
    status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &transport_cfg, NULL);
    if (status != PJ_SUCCESS) {
        qDebug() << "Cannot init PJSUA UDP transport, cause: " << status;
        return;
    }

    /* Initialization is done, now start pjsua */
    status = pjsua_start();
    if (status != PJ_SUCCESS) {
        qDebug() << "Cannot start PJSUA SIP client, cause: " << status;
        return;
    }
    /* Register to SIP server by creating SIP account. */
    pjsua_acc_config acc_cfg;

    pjsua_acc_config_default(&acc_cfg);
    QString s_id = "sip:" + s_user + "@" + s_server;
    QString s_uri = "sip:" + s_server;
    acc_cfg.cred_count = 1;
    acc_cfg.cred_info[0].realm = pj_str(strdup(s_server.toLocal8Bit().data()));
    acc_cfg.cred_info[0].scheme = pj_str("digest");
    acc_cfg.cred_info[0].username = pj_str(strdup(s_user.toLocal8Bit().data()));
    acc_cfg.cred_info[0].data_type = PJSIP_CRED_DATA_PLAIN_PASSWD;
    acc_cfg.cred_info[0].data = pj_str(strdup(s_password.toLocal8Bit().data()));
    acc_cfg.id = pj_str(strdup(s_id.toLocal8Bit().data()));
    acc_cfg.reg_uri = pj_str(strdup(s_uri.toLocal8Bit().data()));
    status = pjsua_acc_add(&acc_cfg, PJ_TRUE, &acc_id);
    if (status != PJ_SUCCESS) {
        qDebug() << "PJSUA auth data invalid, cause: " << status;
        return;
    }

    qDebug() << "PJSUA ports" << pjsua_conf_get_active_ports();
    pjsua_conf_port_info info;
    pjsua_conf_get_port_info (0, &info);
    qDebug() << pj2qstring(info.name);

//    pjsua_conf_adjust_tx_level(0,0.0);

    pj_caching_pool_init(&pj_cpool, &pj_pool_factory_default_policy, 0);
    pj_pool = pjsua_pool_create("qvisu", 8192, 8192);

#ifndef DOORBELL_WAV
    if (doorbell_ok && (bell_wav != 0)) {
        status = pjmedia_mem_player_create(pj_pool,
                                           bell_wav,
                                           bell_datalen,
                                           sample_rate,
                                           num_channels,
                                           16384,
                                           bits_per_sample,
                                           0,//PJMEDIA_MEM_NO_LOOP,
                                           &bell_file_port);

        qDebug() << "Bell memory player" << status;

        status = pjsua_conf_add_port(pj_pool,bell_file_port,&bell_port_id);
        qDebug() << "bell file add status" << status << "id" << bell_port_id;

        status = pjmedia_mem_player_set_eof_cb 	(bell_file_port,
                                                 0,
                                                 &on_file_played);

    } else {
        bell_file_port = 0;
    }
#else
    qDebug() << "Doorbell file" << s_doorbell_name;
    if (s_doorbell_name.isEmpty()) {
        bell_file_port = 0;
    } else {
        /* Create file media port for doorbell from the WAV file */
        status = pjmedia_wav_player_port_create(pj_pool,	/* memory pool	    */
                                                strdup(s_doorbell_name.toUtf8().data()),	/* file to play	    */
                                                20,	/* ptime.	    */
                                                PJMEDIA_FILE_NO_LOOP,	/* flags	    */
                                                0,	/* default buffer   */
                                                &bell_file_port/* returned port    */
                                                );
        if (status != PJ_SUCCESS) {
            qDebug() << "Cannot open wav file" << status;
            bell_file_port = 0;
        }
    }

    if (bell_file_port != 0) {
        status = pjsua_conf_add_port(pj_pool,bell_file_port,&bell_port_id);
        qDebug() << "bell file add status" << status << "id" << bell_port_id;

        status = pjmedia_wav_player_set_eof_cb 	(bell_file_port,
                                                 0,
                                                 &on_file_played);
        if (status != PJ_SUCCESS) {
            qDebug() << "Cannot register callback";
            bell_file_port = 0;
        }
    }
#endif
}